Source for file ParserPDF.inc
Documentation is available at ParserPDF.inc
* This class handles the XML-based CezPDF markup language created to allow
* templates for the PDFdefaultConverter
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2002-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @copyright 2002-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: ParserPDF.inc 238276 2007-06-22 14:58:30Z ashnazg $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
/** when <text> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_EVENT_TEXT', 600);
/** when <text> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_STATE_TEXT', 700);
/** used for parsing stuff between <text> */
define('PHPDOCUMENTOR_PDF_EVENT_CONTENT', 601);
/** used for parsing stuff between <text> */
define('PHPDOCUMENTOR_PDF_STATE_CONTENT', 701);
/** when <font> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_EVENT_FONT', 602);
/** when <font> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_STATE_FONT', 702);
/** when <newpage/> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_EVENT_NEWPAGE', 603);
/** when <newpage/> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_STATE_NEWPAGE', 703);
/** when <pdffunction> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_EVENT_PDFFUNCTION', 604);
/** when <pdffunction> is found in an ezText input */
define('PHPDOCUMENTOR_PDF_STATE_PDFFUNCTION', 704);
* Mapping of event constants to events handler function names
PHPDOCUMENTOR_PDF_EVENT_TEXT =>
'handleText',
PHPDOCUMENTOR_PDF_EVENT_FONT =>
'handleFont',
PHPDOCUMENTOR_PDF_EVENT_NEWPAGE =>
'handleNewPage',
PARSER_EVENT_QUOTE =>
'handleQuote',
PARSER_EVENT_NOEVENTS =>
'defaultHandler',
PHPDOCUMENTOR_PDF_EVENT_CONTENT =>
'handleContent',
PHPDOCUMENTOR_PDF_EVENT_PDFFUNCTION =>
'handlePDFfunction',
* Sets up the wordparser for this class
* Parse text for PDFParser XML tags, and add the text to the PDF file
* @param string text to parse for PDFParser XML tags
* @param string full path to the font directory
* @param boolean determines whether output is saved in a variable or
* added directly to the output
* @staticvar integer used for recursion limiting if a handler for an event is not found
function parse ($parse_data,$fontdir,&$pdf,$debug=
false)
// initialize variables so E_ALL error_reporting doesn't complain
$this->p_vars['event_stack'] =
new EventStack;
$this->p_flags['reset_quote_data'] =
true;
$this->p_vars['options'] =
false;
$this->p_vars['font_dir'] =
$fontdir;
$this->p_vars['text_size'] =
false;
$this->p_vars['pdf'] =
&$pdf;
$this->wp->setup($parse_data);
$this->wp->setWhitespace(true);
$pevent =
$this->p_vars['event_stack']->getEvent();
$this->p_vars['last_pevent'] =
$lpevent;
if ($this->p_vars['last_pevent'] !=
$pevent)
// its a new event so the word parser needs to be reconfigured
$this->p_vars['last_word'] =
$word;
$word =
$this->wp->getWord();
if (PHPDOCUMENTOR_DEBUG ==
true)
echo
"----------------\n";
echo
"LAST: |" .
$this->p_vars['last_word'] .
"|\n";
// echo "INDEX: ".$this->p_vars['curpar']."\n";
echo
$this->wp->getPos() .
" WORD: |".
$word.
"|\n\n";
if (isset
($this->eventHandlers[$pevent]))
$handle =
$this->eventHandlers[$pevent];
$this->$handle($word, $pevent);
debug('WARNING: possible error, no ParserPDFParser handler for event number '.
$pevent);
die("FATAL ERROR, recursion limit reached");
} while (!($word ===
false));
$fp =
fopen("C:/Documents and Settings/Owner/Desktop/pdfsource.txt", "a");
* @param integer event constant
function defaultHandler($word, $pevent)
* @tutorial ParserPDF.cls#tags.newpage
function handleNewPage($word, $pevent)
$this->p_vars['event_stack']->popEvent();
$this->p_vars['pdf']->ezNewPage($this->_debug);
* @tutorial ParserPDF.cls#tags.text
function handleText($word, $pevent)
$this->p_flags['textcolor'] =
false;
if (($a =
$this->p_vars['savecolor']) !=
$this->p_vars['pdf']->getColor())
$this->p_vars['pdf']->setColor($a['r'],$a['g'],$a['b']);
if ($this->p_vars['last_word'] ==
'<text')
$this->p_flags['paramval'] =
false;
$this->p_flags['textcolor'] =
false;
$this->p_vars['curparam'] =
false;
$this->p_vars['savecolor'] =
$this->p_vars['pdf']->getColor();
$this->p_vars['options'] =
array();
unset
($this->p_vars['quote_data']);
if (!$this->p_flags['paramval'])
// debug('set paramval '.$this->p_vars['curparam']);
$this->p_flags['paramval'] =
true;
$this->p_vars['curparam'] =
trim($word);
if ($this->p_vars['curparam'] ==
'size')
$this->p_vars['text_size'] = (int)
$this->p_vars['quote_data'];
$this->p_flags['paramval'] =
false;
$this->p_vars['curparam'] =
false;
$this->p_vars['curparam'] =
trim($word);
unset
($this->p_vars['quote_data']);
} elseif ($this->p_vars['curparam'] ==
'color')
if ($a =
$this->p_vars['pdf']->validHTMLColor($this->p_vars['quote_data']))
$this->p_flags['textcolor'] =
true;
$this->p_vars['pdf']->setHTMLColor($a);
if ($this->p_vars['quote_data'] === (string)(int)
$this->p_vars['quote_data']) $this->p_vars['quote_data'] = (int)
$this->p_vars['quote_data'];
// debug('added '.$this->p_vars['curparam'].' = '.$this->p_vars['quote_data']);
$this->p_vars['options'][$this->p_vars['curparam']] =
$this->p_vars['quote_data'];
$this->p_flags['paramval'] =
false;
$this->p_vars['curparam'] =
false;
$this->p_vars['curparam'] =
trim($word);
unset
($this->p_vars['quote_data']);
* @tutorial ParserPDF.cls#tags.font
function handleFont($word, $pevent)
if ($this->p_vars['last_word'] ==
'<font')
$this->p_flags['paramval'] =
false;
$this->p_vars['curparam'] =
false;
unset
($this->p_vars['quote_data']);
if (!$this->p_flags['paramval'])
//debug('set paramval '.$this->p_vars['curparam']);
$this->p_flags['paramval'] =
true;
$this->p_vars['curparam'] =
trim($word);
if ($this->p_vars['curparam'] ==
'face')
//debug('set face to '.$this->p_vars['font_dir'] . $this->p_vars['quote_data'] . '.afm');
$this->p_vars['pdf']->selectFont($this->p_vars['font_dir'] .
$this->p_vars['quote_data'] .
'.afm');
$this->p_flags['paramval'] =
false;
$this->p_vars['curparam'] =
false;
unset
($this->p_vars['quote_data']);
* @tutorial ParserPDF.cls#tags.pdffunction
function handlePDFFunction($word, $pevent)
if ($this->p_vars['last_word'] ==
'<pdffunction:')
$this->p_flags['paramval'] =
$this->p_flags['curparam'] =
false;
$this->p_flags['returnval'] =
false;
$this->p_vars['funcname'] =
trim($word);
// debug("funcname is $word");
$this->p_vars['options'] =
array();
unset
($this->p_vars['quote_data']);
if (!$this->p_flags['paramval'])
{ // call function, no parameters
$func =
$this->p_vars['funcname'];
if (count($this->p_vars['options']))
// fancy_debug("calling function $func",$this->p_vars['options']);
// debug("calling function $func");
$a =
$this->p_vars['pdf']->$func();
if ($this->p_flags['returnval'])
// debug("setting returnvar ".$this->p_vars['return_varname']);
$this->tempvars[$this->p_vars['return_varname']] =
$a;
// debug('set paramval '.$this->p_vars['curparam']);
$this->p_flags['paramval'] =
true;
$this->p_vars['curparam'] =
trim($word);
if ($this->p_vars['last_word'] ==
'=')
{ // check to see if we should use a tempvar from a previous return
$a =
$this->p_vars['pdf']->$a;
// debug("set option to $word");
$this->p_vars['options'][] =
$a;
$this->p_flags['paramval'] =
false;
unset
($this->p_vars['quote_data']);
if (!isset
($this->tempvars[substr(trim($word),1)]))
// debug("set option to $word");
$this->p_vars['options'][] =
$a;
$this->p_flags['paramval'] =
false;
unset
($this->p_vars['quote_data']);
if ($this->p_vars['quote_data'] === (string)(int)
$this->p_vars['quote_data'])
$this->p_vars['quote_data'] = (int)
$this->p_vars['quote_data'];
if ($this->p_vars['curparam'] ==
'return')
// debug("param is return");
$this->p_vars['return_varname'] =
$this->p_vars['quote_data'];
$this->p_flags['returnval'] =
true;
// fancy_debug("set option to arg",$this->p_vars['quote_data']);
$this->p_vars['options'][] =
$this->p_vars['quote_data'];
$this->p_flags['paramval'] =
false;
unset
($this->p_vars['quote_data']);
{ // call function, with parameters
$func =
$this->p_vars['funcname'];
if (count($this->p_vars['options']))
// fancy_debug("calling function $func",$this->p_vars['options']);
if ($func ==
'ezImage') {
// set padding to 5, width to 0, resize to none
$this->p_vars['options'][] =
5;
$this->p_vars['options'][] =
0;
$this->p_vars['options'][] =
'none';
// debug("calling function $func");
$a =
$this->p_vars['pdf']->$func();
if ($this->p_flags['returnval'])
// debug("setting returnvar ".$this->p_vars['return_varname']);
$this->tempvars[$this->p_vars['return_varname']] =
$a;
* Adds content to the <text> tag
function handleContent($word, $pevent)
if (!isset
($this->p_vars['content'])) return;
$this->p_vars['pdf']->_ezText($this->p_vars['content'],$this->p_vars['text_size'],$this->p_vars['options']);
unset
($this->p_vars['content']);
$this->wp->backupPos($word);
if (!isset
($this->p_vars['content'])) return;
$this->p_vars['pdf']->_ezText($this->p_vars['content'],$this->p_vars['text_size'],$this->p_vars['options']);
unset
($this->p_vars['content']);
if (!isset
($this->p_vars['content'])) $this->p_vars['content'] =
'';
if (isset
($this->p_vars['quote_data']))
$this->p_vars['content'] .=
$this->p_vars['quote_data'];
unset
($this->p_vars['quote_data']);
$this->p_vars['content'] .=
$word;
* setup the parser tokens, and the pushEvent/popEvent arrays
* @see $tokens, $pushEvent, $popEvent
$this->tokens[STATE_NOEVENTS] =
array("<text","<font","<newpage />","<newpage/>",'<pdffunction:','"');
// For each event word to event mapings
##########################
##########################
##########################
##########################
##########################
* Return the name of the parser event
if (isset
($lookup[$value]))