diff --git a/admin/classes/tcpdf/fonts/utils/makefont.php b/admin/classes/tcpdf/fonts/utils/makefont.php index 546d13bbf52..18fea335fe8 100644 --- a/admin/classes/tcpdf/fonts/utils/makefont.php +++ b/admin/classes/tcpdf/fonts/utils/makefont.php @@ -57,7 +57,7 @@ */ function MakeFont($fontfile, $fmfile, $embedded=true, $enc='cp1252', $patch=array()) { //Generate a font definition file - set_magic_quotes_runtime(0); + @set_magic_quotes_runtime(0); ini_set('auto_detect_line_endings', '1'); if (!file_exists($fontfile)) { die('Error: file not found: '.$fontfile); diff --git a/admin/classes/tcpdf/tcpdf.php b/admin/classes/tcpdf/tcpdf.php index 11753cf3a86..3a967e7e97c 100644 --- a/admin/classes/tcpdf/tcpdf.php +++ b/admin/classes/tcpdf/tcpdf.php @@ -35,16 +35,16 @@ // // Main features: // * no external libraries are required for the basic functions; -// * supports all ISO page formats; +// * supports all ISO page formats; // * supports custom page formats, margins and units of measure; -// * supports UTF-8 Unicode and Right-To-Left languages; +// * supports UTF-8 Unicode and Right-To-Left languages; // * supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts; // * supports document encryption; // * includes methods to publish some XHTML code; // * includes graphic (geometric) and transformation methods; // * includes Javascript and forms support; -// * includes a method to print various barcode formats: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS; -// * includes methods to set Bookmarks and print a Table of Content; +// * includes a method to print various barcode formats: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS; +// * includes methods to set Bookmarks and print a Table of Content; // * includes methods to move and delete pages; // * includes methods for automatic page header and footer management; // * supports automatic page break; @@ -55,8 +55,8 @@ // * supports clipping masks; // * supports Grayscale, RGB, CMYK, Spot Colors and Transparencies; // * supports several annotations, including links, text and file attachments; -// * supports page compression (requires zlib extension); -// * supports text hyphenation. +// * supports page compression (requires zlib extension); +// * supports text hyphenation. // * supports transactions to UNDO commands. // // ----------------------------------------------------------- @@ -81,10 +81,10 @@ // Moritz Wagner and Andreas Wurmser for graphic functions. // Andrew Whitehead for core fonts support. // Esteban Jo�l Mar�n for OpenType font conversion. -// Teus Hagen for several suggestions and fixes. -// Yukihiro Nakadaira for CID-0 CJK fonts fixes. -// Kosmas Papachristos for some CSS improvements. -// Marcel Partap for some fixes. +// Teus Hagen for several suggestions and fixes. +// Yukihiro Nakadaira for CID-0 CJK fonts fixes. +// Kosmas Papachristos for some CSS improvements. +// Marcel Partap for some fixes. // Won Kyu Park for several suggestions, fixes and patches. // Anyone that has reported a bug or sent a suggestion. //============================================================+ @@ -94,29 +94,29 @@ * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.
*

TCPDF main features are:

* * Tools to encode your unicode fonts are on fonts/utils directory.

@@ -133,18 +133,18 @@ * main configuration file */ require_once(dirname(__FILE__).'/config/tcpdf_config.php'); - + // includes some support files /** * unicode data */ -require_once(dirname(__FILE__).'/unicode_data.php'); +require_once(dirname(__FILE__).'/unicode_data.php'); /** * html colors table */ -require_once(dirname(__FILE__).'/htmlcolors.php'); +require_once(dirname(__FILE__).'/htmlcolors.php'); if (!class_exists('TCPDF', false)) { /** @@ -290,7 +290,7 @@ class TCPDF { * @var cell internal padding * @access protected */ - //protected + //protected public $cMargin; /** @@ -503,13 +503,13 @@ class TCPDF { * @var alias for total number of pages * @access protected */ - protected $AliasNbPages = '{nb}'; + protected $AliasNbPages = '{nb}'; /** * @var alias for page number * @access protected */ - protected $AliasNumPage = '{pnb}'; + protected $AliasNumPage = '{pnb}'; /** * @var right-bottom corner X coordinate of inserted image @@ -785,13 +785,13 @@ class TCPDF { * @access protected * @since 2.0.000 (2008-01-02) */ - protected $last_rc4_key_c; + protected $last_rc4_key_c; /** * RC4 padding * @access protected */ - protected $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; + protected $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; /** * RC4 encryption key @@ -1045,226 +1045,226 @@ class TCPDF { * @access protected * @since 4.0.021 (2008-08-24) */ - protected $htmlvspace = 0; + protected $htmlvspace = 0; /** * Array of Spot colors * @access protected * @since 4.0.024 (2008-09-12) */ - protected $spot_colors = array(); + protected $spot_colors = array(); /** * Symbol used for HTML unordered list items - * @access protected + * @access protected * @since 4.0.028 (2008-09-26) - */ - protected $lisymbol = ''; + */ + protected $lisymbol = ''; /** * String used to mark the beginning and end of EPS image blocks - * @access protected + * @access protected * @since 4.1.000 (2008-10-18) - */ - protected $epsmarker = 'x#!#EPS#!#x'; + */ + protected $epsmarker = 'x#!#EPS#!#x'; /** * Array of transformation matrix - * @access protected + * @access protected * @since 4.2.000 (2008-10-29) - */ - protected $transfmatrix = array(); + */ + protected $transfmatrix = array(); /** * Booklet mode for double-sided pages - * @access protected + * @access protected * @since 4.2.000 (2008-10-29) - */ - protected $booklet = false; + */ + protected $booklet = false; /** * Epsilon value used for float calculations - * @access protected + * @access protected * @since 4.2.000 (2008-10-29) - */ - protected $feps = 0.001; + */ + protected $feps = 0.001; /** * Array used for custom vertical spaces for HTML tags - * @access protected + * @access protected * @since 4.2.001 (2008-10-30) - */ - protected $tagvspaces = array(); + */ + protected $tagvspaces = array(); /** - * @var HTML PARSER: custom indent amount for lists. + * @var HTML PARSER: custom indent amount for lists. * Negative value means disabled. - * @access protected + * @access protected * @since 4.2.007 (2008-11-12) */ - protected $customlistindent = -1; + protected $customlistindent = -1; /** * @var if true keeps the border open for the cell sides that cross the page. - * @access protected + * @access protected * @since 4.2.010 (2008-11-14) */ - protected $opencell = true; - + protected $opencell = true; + /** * @var array of files to embedd - * @access protected + * @access protected * @since 4.4.000 (2008-12-07) */ - protected $embeddedfiles = array(); - + protected $embeddedfiles = array(); + /** * @var boolean true when inside html pre tag - * @access protected + * @access protected * @since 4.4.001 (2008-12-08) */ - protected $premode = false; - + protected $premode = false; + /** - * Array used to store positions of graphics transformation blocks inside the page buffer. + * Array used to store positions of graphics transformation blocks inside the page buffer. * keys are the page numbers * @access protected * @since 4.4.002 (2008-12-09) */ - protected $transfmrk = array(); - + protected $transfmrk = array(); + /** * Default color for html links * @access protected * @since 4.4.003 (2008-12-09) */ - protected $htmlLinkColorArray = array(0, 0, 255); - + protected $htmlLinkColorArray = array(0, 0, 255); + /** * Default font style to add to html links * @access protected * @since 4.4.003 (2008-12-09) */ - protected $htmlLinkFontStyle = 'U'; - + protected $htmlLinkFontStyle = 'U'; + /** * Counts the number of pages. * @access protected * @since 4.5.000 (2008-12-31) */ - protected $numpages = 0; - + protected $numpages = 0; + /** * Array containing page lenghts in bytes. * @access protected * @since 4.5.000 (2008-12-31) */ - protected $pagelen = array(); - + protected $pagelen = array(); + /** * Counts the number of pages. * @access protected * @since 4.5.000 (2008-12-31) */ - protected $numimages = 0; - + protected $numimages = 0; + /** * Store the image keys. * @access protected * @since 4.5.000 (2008-12-31) */ - protected $imagekeys = array(); - + protected $imagekeys = array(); + /** * Lenght of the buffer in bytes. * @access protected * @since 4.5.000 (2008-12-31) */ - protected $bufferlen = 0; - + protected $bufferlen = 0; + /** * If true enables disk caching. * @access protected * @since 4.5.000 (2008-12-31) */ - protected $diskcache = false; - + protected $diskcache = false; + /** * Counts the number of fonts. * @access protected * @since 4.5.000 (2009-01-02) */ - protected $numfonts = 0; - + protected $numfonts = 0; + /** * Store the font keys. * @access protected * @since 4.5.000 (2009-01-02) */ - protected $fontkeys = array(); - + protected $fontkeys = array(); + /** * Store the fage status (true when opened, false when closed). * @access protected * @since 4.5.000 (2009-01-02) */ - protected $pageopen = array(); + protected $pageopen = array(); /** * Default monospaced font * @access protected * @since 4.5.025 (2009-03-10) */ - protected $default_monospaced_font = 'courier'; - + protected $default_monospaced_font = 'courier'; + /** * Used to store a cloned copy of the current class object * @access protected * @since 4.5.029 (2009-03-19) - */ - protected $objcopy; - - /** + */ + protected $objcopy; + + /** * Array used to store the lenghts of cache files * @access protected * @since 4.5.029 (2009-03-19) - */ - protected $cache_file_lenght = array(); - - /** + */ + protected $cache_file_lenght = array(); + + /** * Table header content to be repeated on each new page * @access protected * @since 4.5.030 (2009-03-20) - */ - protected $thead = ''; - - /** + */ + protected $thead = ''; + + /** * Margins used for table header. * @access protected * @since 4.5.030 (2009-03-20) - */ - protected $theadMargins = array(); - - /** + */ + protected $theadMargins = array(); + + /** * Cache array for UTF8StringToArray() method. * @access protected * @since 4.5.037 (2009-04-07) - */ - protected $cache_UTF8StringToArray = array(); - - /** + */ + protected $cache_UTF8StringToArray = array(); + + /** * Maximum size of cache array used for UTF8StringToArray() method. * @access protected * @since 4.5.037 (2009-04-07) - */ - protected $cache_maxsize_UTF8StringToArray = 8; - - /** + */ + protected $cache_maxsize_UTF8StringToArray = 8; + + /** * Current size of cache array used for UTF8StringToArray() method. * @access protected * @since 4.5.037 (2009-04-07) - */ - protected $cache_size_UTF8StringToArray = 0; + */ + protected $cache_size_UTF8StringToArray = 0; /** * If true enables document signing @@ -1278,21 +1278,21 @@ class TCPDF { * @access protected * @since 4.6.005 (2009-04-24) */ - protected $signature_data = array(); + protected $signature_data = array(); /** * Signature max lenght * @access protected * @since 4.6.005 (2009-04-24) */ - protected $signature_max_lenght = 5120; + protected $signature_max_lenght = 5120; /** * Regular expression used to find blank characters used for word-wrapping. * @access protected * @since 4.6.006 (2009-04-28) */ - protected $re_spaces = '/[\s\p{Z}\p{Lo}]/'; + protected $re_spaces = '/[\s\p{Z}\p{Lo}]/'; //------------------------------------------------------------ // METHODS @@ -1306,7 +1306,7 @@ class TCPDF { * @param string $orientation page orientation. Possible values are (case insensitive): * @param string $unit User measure unit. Possible values are:
A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit). - * @param boolean $unicode TRUE means that the input text is unicode (default = true) + * @param boolean $unicode TRUE means that the input text is unicode (default = true) * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower). * @param String $encoding charset encoding; default is UTF-8 * @access public @@ -1316,8 +1316,8 @@ public function __construct($orientation='P', $unit='mm', $format='A4', $unicode if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) { $this->internal_encoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); - } - // set disk caching + } + // set disk caching $this->diskcache = $diskcache ? true : false; // set language direction $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false; @@ -1326,7 +1326,7 @@ public function __construct($orientation='P', $unit='mm', $format='A4', $unicode $this->_dochecks(); //Initialization of properties $this->isunicode = $unicode; - $this->page = 0; + $this->page = 0; $this->transfmrk[0] = array(); $this->pagedim = array(); $this->n = 2; @@ -1400,7 +1400,7 @@ public function __construct($orientation='P', $unit='mm', $format='A4', $unicode $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0); $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255); $this->extgstates = array(); - // user's rights + // user's rights $this->sign = false; $this->ur = false; $this->ur_document = '/FullSave'; @@ -1410,19 +1410,19 @@ public function __construct($orientation='P', $unit='mm', $format='A4', $unicode // set default JPEG quality $this->jpeg_quality = 75; // initialize some settings - $this->utf8Bidi(array(''), ''); - // set default font - $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt); - // check if PCRE Unicode support is enabled - if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) { - // PCRE unicode support is turned ON - // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator. - // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants. - // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between. - $this->re_spaces = '/[\s\p{Z}\p{Lo}]/'; - } else { - // PCRE unicode support is turned OFF - $this->re_spaces = '/[\s]/'; + $this->utf8Bidi(array(''), ''); + // set default font + $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt); + // check if PCRE Unicode support is enabled + if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) { + // PCRE unicode support is turned ON + // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator. + // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants. + // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between. + $this->re_spaces = '/[\s\p{Z}\p{Lo}]/'; + } else { + // PCRE unicode support is turned OFF + $this->re_spaces = '/[\s]/'; } } @@ -1435,8 +1435,8 @@ public function __destruct() { // restore internal encoding if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) { mb_internal_encoding($this->internal_encoding); - } - // unset all class variables + } + // unset all class variables $this->_destroy(true); } @@ -1449,7 +1449,7 @@ public function __destruct() { public function setPageUnit($unit) { //Set scale factor switch (strtolower($unit)) { - // points + // points case 'px': case 'pt': { $this->k = 1; @@ -1674,68 +1674,68 @@ public function setImageScale($scale) { */ public function getImageScale() { return $this->imgscale; - } + } /** - * Returns an array of page dimensions: - * + * Returns an array of page dimensions: + * * @param int $pagenum page number (empty = current page) * @return array of page dimensions. * @author Nicola Asuni * @access public * @since 4.5.027 (2009-03-16) */ - public function getPageDimensions($pagenum='') { - if (empty($pagenum)) { - $pagenum = $this->page; - } - return $this->pagedim[$pagenum]; - } + public function getPageDimensions($pagenum='') { + if (empty($pagenum)) { + $pagenum = $this->page; + } + return $this->pagedim[$pagenum]; + } /** - * Returns the page width in units. + * Returns the page width in units. * @param int $pagenum page number (empty = current page) * @return int page width. * @author Nicola Asuni * @access public - * @since 1.5.2 + * @since 1.5.2 * @see getPageDimensions() */ - public function getPageWidth($pagenum='') { - if (empty($pagenum)) { - return $this->w; + public function getPageWidth($pagenum='') { + if (empty($pagenum)) { + return $this->w; } return $this->pagedim[$pagenum]['w']; } /** - * Returns the page height in units. + * Returns the page height in units. * @param int $pagenum page number (empty = current page) * @return int page height. * @author Nicola Asuni * @access public - * @since 1.5.2 + * @since 1.5.2 * @see getPageDimensions() */ - public function getPageHeight($pagenum='') { - if (empty($pagenum)) { - return $this->h; + public function getPageHeight($pagenum='') { + if (empty($pagenum)) { + return $this->h; } return $this->pagedim[$pagenum]['h']; } /** - * Returns the page break margin. + * Returns the page break margin. * @param int $pagenum page number (empty = current page) * @return int page break margin. * @author Nicola Asuni * @access public - * @since 1.5.2 + * @since 1.5.2 * @see getPageDimensions() */ - public function getBreakMargin($pagenum='') { - if (empty($pagenum)) { - return $this->bMargin; + public function getBreakMargin($pagenum='') { + if (empty($pagenum)) { + return $this->bMargin; } return $this->pagedim[$pagenum]['bm']; } @@ -2003,14 +2003,14 @@ public function SetCreator($creator) { * @since 1.0 */ public function Error($msg) { - // unset all class variables - $this->_destroy(true); + // unset all class variables + $this->_destroy(true); // exit program and print error die('TCPDF ERROR: '.$msg); } /** - * This method begins the generation of the PDF document. + * This method begins the generation of the PDF document. * It is not necessary to call it explicitly because AddPage() does it automatically. * Note: no page is created by this method * @access public @@ -2023,8 +2023,8 @@ public function Open() { } /** - * Terminates the PDF document. - * It is not necessary to call this method explicitly because Output() does it automatically. + * Terminates the PDF document. + * It is not necessary to call this method explicitly because Output() does it automatically. * If the document contains no page, AddPage() is called to prevent from getting an invalid document. * @access public * @since 1.0 @@ -2040,8 +2040,8 @@ public function Close() { // close page $this->endPage(); // close document - $this->_enddoc(); - // unset all class variables (except critical ones) + $this->_enddoc(); + // unset all class variables (except critical ones) $this->_destroy(false); } @@ -2054,13 +2054,13 @@ public function Close() { * @see getPage(), lastpage(), getNumPages() */ public function setPage($pnum, $resetmargins=false) { - if ($pnum == $this->page) { - return; - } - if (($pnum > 0) AND ($pnum <= $this->numpages)) { - $this->state = 2; - // save current graphic settings - //$gvars = $this->getGraphicVars(); + if ($pnum == $this->page) { + return; + } + if (($pnum > 0) AND ($pnum <= $this->numpages)) { + $this->state = 2; + // save current graphic settings + //$gvars = $this->getGraphicVars(); $oldpage = $this->page; $this->page = $pnum; $this->wPt = $this->pagedim[$this->page]['w']; @@ -2068,25 +2068,25 @@ public function setPage($pnum, $resetmargins=false) { $this->w = $this->wPt / $this->k; $this->h = $this->hPt / $this->k; $this->tMargin = $this->pagedim[$this->page]['tm']; - $this->bMargin = $this->pagedim[$this->page]['bm']; + $this->bMargin = $this->pagedim[$this->page]['bm']; $this->original_lMargin = $this->pagedim[$this->page]['olm']; $this->original_rMargin = $this->pagedim[$this->page]['orm']; $this->AutoPageBreak = $this->pagedim[$this->page]['pb']; $this->CurOrientation = $this->pagedim[$this->page]['or']; - $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin); - // restore graphic settings + $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin); + // restore graphic settings //$this->setGraphicVars($gvars); if ($resetmargins) { $this->lMargin = $this->pagedim[$this->page]['olm']; $this->rMargin = $this->pagedim[$this->page]['orm']; $this->SetY($this->tMargin); - } else { - // account for booklet mode - if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) { - $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm']; - $this->lMargin += $deltam; - $this->rMargin -= $deltam; - } + } else { + // account for booklet mode + if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) { + $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm']; + $this->lMargin += $deltam; + $this->rMargin -= $deltam; + } } } else { $this->Error('Wrong page number on setPage() function.'); @@ -2094,7 +2094,7 @@ public function setPage($pnum, $resetmargins=false) { } /** - * Reset pointer to the last document page. + * Reset pointer to the last document page. * @param boolean $resetmargins if true reset left, right, top margins and Y position. * @access public * @since 2.0.000 (2008-01-04) @@ -2132,85 +2132,85 @@ public function getNumPages() { * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards. * @param string $orientation page orientation. Possible values are (case insensitive): * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit). - * @access public + * @access public * @since 1.0 * @see startPage(), endPage() */ - public function AddPage($orientation='', $format='') { + public function AddPage($orientation='', $format='') { if (!isset($this->original_lMargin)) { $this->original_lMargin = $this->lMargin; } if (!isset($this->original_rMargin)) { $this->original_rMargin = $this->rMargin; - } - // terminate previous page - $this->endPage(); - // start new page + } + // terminate previous page + $this->endPage(); + // start new page $this->startPage($orientation, $format); - } - + } + /** - * Terminate the current page + * Terminate the current page * @access protected - * @since 4.2.010 (2008-11-14) + * @since 4.2.010 (2008-11-14) * @see startPage(), AddPage() */ - protected function endPage() { + protected function endPage() { // check if page is already closed if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) { return; - } - $this->InFooter = true; + } + $this->InFooter = true; // print page footer $this->setFooter(); // close page - $this->_endpage(); - // mark page as closed - $this->pageopen[$this->page] = false; + $this->_endpage(); + // mark page as closed + $this->pageopen[$this->page] = false; $this->InFooter = false; - } - + } + /** * Starts a new page to the document. The page must be closed using the endPage() function. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards. * @param string $orientation page orientation. Possible values are (case insensitive): - * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit). - * @access protected + * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit). + * @access protected * @since 4.2.010 (2008-11-14) * @see endPage(), AddPage() */ - protected function startPage($orientation='', $format='') { + protected function startPage($orientation='', $format='') { if ($this->numpages > $this->page) { // this page has been already added - $this->setPage($this->page + 1); + $this->setPage($this->page + 1); $this->SetY($this->tMargin); return; - } + } // start a new page if ($this->state == 0) { $this->Open(); - } - ++$this->numpages; + } + ++$this->numpages; $this->swapMargins($this->booklet); - // save current graphic settings + // save current graphic settings $gvars = $this->getGraphicVars(); // start new page - $this->_beginpage($orientation, $format); - // mark page as open + $this->_beginpage($orientation, $format); + // mark page as open $this->pageopen[$this->page] = true; // restore graphic settings - $this->setGraphicVars($gvars); - // mark this point + $this->setGraphicVars($gvars); + // mark this point $this->setPageMark(); // print page header $this->setHeader(); - // restore graphic settings + // restore graphic settings $this->setGraphicVars($gvars); // mark this point - $this->setPageMark(); - // print table header (if any) + $this->setPageMark(); + // print table header (if any) $this->setTableHeader(); - } + } /** * Set start-writing mark on current page for multicell borders and fills. @@ -2389,11 +2389,11 @@ public function Footer() { $this->Ln($line_width); $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right'])/3); $this->write1DBarcode($barcode, 'C128B', $this->GetX(), $cur_y + $line_width, $barcode_width, (($this->getFooterMargin() / 3) - $line_width), 0.3, '', ''); - } - if (empty($this->pagegroups)) { - $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); + } + if (empty($this->pagegroups)) { + $pagenumtxt = $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(); } else { - $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias(); + $pagenumtxt = $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias(); } $this->SetY($cur_y); //Print page number @@ -2412,11 +2412,11 @@ public function Footer() { * @since 4.0.012 (2008-07-24) */ protected function setHeader() { - if ($this->print_header) { + if ($this->print_header) { $lasth = $this->lasth; $this->_out('q'); $this->rMargin = $this->original_rMargin; - $this->lMargin = $this->original_lMargin; + $this->lMargin = $this->original_lMargin; $this->cMargin = 0; //set current position if ($this->rtl) { @@ -2432,7 +2432,7 @@ protected function setHeader() { } else { $this->SetXY($this->original_lMargin, $this->tMargin); } - $this->_out('Q'); + $this->_out('Q'); $this->lasth = $lasth; } } @@ -2442,18 +2442,18 @@ protected function setHeader() { * @access protected * @since 4.0.012 (2008-07-24) */ - protected function setFooter() { - //Page footer - // save current graphic settings + protected function setFooter() { + //Page footer + // save current graphic settings $gvars = $this->getGraphicVars(); // mark this point - $this->footerpos[$this->page] = $this->pagelen[$this->page]; + $this->footerpos[$this->page] = $this->pagelen[$this->page]; $this->_out("\n"); if ($this->print_footer) { - $lasth = $this->lasth; + $lasth = $this->lasth; $this->_out('q'); $this->rMargin = $this->original_rMargin; - $this->lMargin = $this->original_lMargin; + $this->lMargin = $this->original_lMargin; $this->cMargin = 0; //set current position $footer_y = $this->h - $this->footer_margin; @@ -2470,43 +2470,43 @@ protected function setFooter() { } else { $this->SetXY($this->original_lMargin, $this->tMargin); } - $this->_out('Q'); + $this->_out('Q'); $this->lasth = $lasth; - } - // restore graphic settings - $this->setGraphicVars($gvars); + } + // restore graphic settings + $this->setGraphicVars($gvars); // calculate footer lenght $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1; } - + /** * This method is used to render the table header on new page (if any). * @access protected * @since 4.5.030 (2009-03-25) */ - protected function setTableHeader() { - if (isset($this->theadMargins['top'])) { - // restore the original top-margin - $this->tMargin = $this->theadMargins['top']; - $this->pagedim[$this->page]['tm'] = $this->tMargin; - $this->y = $this->tMargin; - } - if (!$this->empty_string($this->thead)) { - // set margins - $this->lMargin = $this->pagedim[$this->page]['olm']; - $this->rMargin = $this->pagedim[$this->page]['orm']; - $this->cMargin = $this->theadMargins['cmargin']; - // print table header - $this->writeHTML($this->thead, false, false, false, false, ''); - // set new top margin to skip the table headers - if (!isset($this->theadMargins['top'])) { - $this->theadMargins['top'] = $this->tMargin; - } - $this->tMargin = $this->y; - $this->pagedim[$this->page]['tm'] = $this->tMargin; - $this->lasth = 0; - } - } + protected function setTableHeader() { + if (isset($this->theadMargins['top'])) { + // restore the original top-margin + $this->tMargin = $this->theadMargins['top']; + $this->pagedim[$this->page]['tm'] = $this->tMargin; + $this->y = $this->tMargin; + } + if (!$this->empty_string($this->thead)) { + // set margins + $this->lMargin = $this->pagedim[$this->page]['olm']; + $this->rMargin = $this->pagedim[$this->page]['orm']; + $this->cMargin = $this->theadMargins['cmargin']; + // print table header + $this->writeHTML($this->thead, false, false, false, false, ''); + // set new top margin to skip the table headers + if (!isset($this->theadMargins['top'])) { + $this->theadMargins['top'] = $this->tMargin; + } + $this->tMargin = $this->y; + $this->pagedim[$this->page]['tm'] = $this->tMargin; + $this->lasth = 0; + } + } /** * Returns the current page number. @@ -2517,8 +2517,8 @@ protected function setTableHeader() { */ public function PageNo() { return $this->page; - } - + } + /** * Defines a new spot color. * It can be expressed in RGB components or gray scale. @@ -2531,12 +2531,12 @@ public function PageNo() { * @since 4.0.024 (2008-09-12) * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor() */ - public function AddSpotColor($name, $c, $m, $y, $k) { - if (!isset($this->spot_colors[$name])) { - $i = 1 + count($this->spot_colors); - $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k); - } - } + public function AddSpotColor($name, $c, $m, $y, $k) { + if (!isset($this->spot_colors[$name])) { + $i = 1 + count($this->spot_colors); + $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k); + } + } /** * Defines the color used for all drawing operations (lines, rectangles and cell borders). @@ -2598,7 +2598,7 @@ public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1) { if ($this->page > 0) { $this->_out($this->DrawColor); } - } + } /** * Defines the spot color used for all drawing operations (lines, rectangles and cell borders). @@ -2608,15 +2608,15 @@ public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1) { * @since 4.0.024 (2008-09-12) * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor() */ - public function SetDrawSpotColor($name, $tint=100) { - if (!isset($this->spot_colors[$name])) { - $this->Error('Undefined spot color: '.$name); - } - $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], $tint/100); + public function SetDrawSpotColor($name, $tint=100) { + if (!isset($this->spot_colors[$name])) { + $this->Error('Undefined spot color: '.$name); + } + $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], $tint/100); if ($this->page > 0) { $this->_out($this->DrawColor); - } - } + } + } /** * Defines the color used for all filling operations (filled rectangles and cell backgrounds). @@ -2682,7 +2682,7 @@ public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1) { if ($this->page > 0) { $this->_out($this->FillColor); } - } + } /** * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds). @@ -2692,16 +2692,16 @@ public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1) { * @since 4.0.024 (2008-09-12) * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor() */ - public function SetFillSpotColor($name, $tint=100) { - if (!isset($this->spot_colors[$name])) { - $this->Error('Undefined spot color: '.$name); - } - $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint/100); - $this->ColorFlag = ($this->FillColor != $this->TextColor); + public function SetFillSpotColor($name, $tint=100) { + if (!isset($this->spot_colors[$name])) { + $this->Error('Undefined spot color: '.$name); + } + $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint/100); + $this->ColorFlag = ($this->FillColor != $this->TextColor); if ($this->page > 0) { $this->_out($this->FillColor); - } - } + } + } /** * Defines the color used for text. It can be expressed in RGB components or gray scale. @@ -2763,7 +2763,7 @@ public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1) { $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4); } $this->ColorFlag = ($this->FillColor != $this->TextColor); - } + } /** * Defines the spot color used for text. @@ -2773,15 +2773,15 @@ public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1) { * @since 4.0.024 (2008-09-12) * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor() */ - public function SetTextSpotColor($name, $tint=100) { - if (!isset($this->spot_colors[$name])) { - $this->Error('Undefined spot color: '.$name); - } - $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint/100); - $this->ColorFlag = ($this->FillColor != $this->TextColor); + public function SetTextSpotColor($name, $tint=100) { + if (!isset($this->spot_colors[$name])) { + $this->Error('Undefined spot color: '.$name); + } + $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint/100); + $this->ColorFlag = ($this->FillColor != $this->TextColor); if ($this->page > 0) { $this->_out($this->TextColor); - } + } } /** @@ -2837,22 +2837,22 @@ public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0) * @access public * @since 2.4.000 (2008-03-06) */ - public function GetCharWidth($char) { - if ($char == 173) { - // SHY character will not be printed - return (0); + public function GetCharWidth($char) { + if ($char == 173) { + // SHY character will not be printed + return (0); } $cw = &$this->CurrentFont['cw']; if (isset($cw[$char])) { $w = $cw[$char]; - } elseif (isset($this->CurrentFont['dw'])) { + } elseif (isset($this->CurrentFont['dw'])) { // default width $w = $this->CurrentFont['dw']; - } elseif (isset($cw[32])) { - // default width + } elseif (isset($cw[32])) { + // default width $dw = $cw[32]; - } else { - $w = 600; + } else { + $w = 600; } return ($w * $this->FontSize / 1000); } @@ -2913,7 +2913,7 @@ public function AddFont($family, $style='', $fontfile='') { if (($family == 'symbol') OR ($family == 'zapfdingbats')) { $style = ''; } - $tempstyle = strtoupper($style); + $tempstyle = strtoupper($style); $style = ''; // underline if (strpos($tempstyle, 'U') !== false) { @@ -2926,94 +2926,94 @@ public function AddFont($family, $style='', $fontfile='') { $this->linethrough = true; } else { $this->linethrough = false; - } + } // bold if (strpos($tempstyle, 'B') !== false) { $style .= 'B'; - } + } // oblique if (strpos($tempstyle, 'I') !== false) { $style .= 'I'; - } + } $bistyle = $style; - $fontkey = $family.$style; + $fontkey = $family.$style; $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : ''); - $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style); - // check if the font has been already added + $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style); + // check if the font has been already added if ($this->getFontBuffer($fontkey) !== false) { return $fontdata; - } + } if (isset($type)) { unset($type); } if (isset($cw)) { unset($cw); - } - // get specified font directory (if any) - $fontdir = ''; - if (!$this->empty_string($fontfile)) { - $fontdir = dirname($fontfile); - if ($this->empty_string($fontdir) OR ($fontdir == '.')) { - $fontdir = ''; - } else { - $fontdir .= '/'; - } - } - // search and include font file - if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) { - // build a standard filenames for specified font - $fontfile1 = str_replace(' ', '', $family).strtolower($style).'.php'; - $fontfile2 = str_replace(' ', '', $family).'.php'; - // search files on various directories - if (file_exists($fontdir.$fontfile1)) { - $fontfile = $fontdir.$fontfile1; - } elseif (file_exists($this->_getfontpath().$fontfile1)) { - $fontfile = $this->_getfontpath().$fontfile1; - } elseif (file_exists($fontfile1)) { - $fontfile = $fontfile1; - } elseif (file_exists($fontdir.$fontfile2)) { - $fontfile = $fontdir.$fontfile2; - } elseif (file_exists($this->_getfontpath().$fontfile2)) { - $fontfile = $this->_getfontpath().$fontfile2; - } else { - $fontfile = $fontfile2; - } - } - // include font file - if (file_exists($fontfile)) { - include($fontfile); - } else { - $this->Error('Could not include font definition file: '.$family.''); - } + } + // get specified font directory (if any) + $fontdir = ''; + if (!$this->empty_string($fontfile)) { + $fontdir = dirname($fontfile); + if ($this->empty_string($fontdir) OR ($fontdir == '.')) { + $fontdir = ''; + } else { + $fontdir .= '/'; + } + } + // search and include font file + if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) { + // build a standard filenames for specified font + $fontfile1 = str_replace(' ', '', $family).strtolower($style).'.php'; + $fontfile2 = str_replace(' ', '', $family).'.php'; + // search files on various directories + if (file_exists($fontdir.$fontfile1)) { + $fontfile = $fontdir.$fontfile1; + } elseif (file_exists($this->_getfontpath().$fontfile1)) { + $fontfile = $this->_getfontpath().$fontfile1; + } elseif (file_exists($fontfile1)) { + $fontfile = $fontfile1; + } elseif (file_exists($fontdir.$fontfile2)) { + $fontfile = $fontdir.$fontfile2; + } elseif (file_exists($this->_getfontpath().$fontfile2)) { + $fontfile = $this->_getfontpath().$fontfile2; + } else { + $fontfile = $fontfile2; + } + } + // include font file + if (file_exists($fontfile)) { + include($fontfile); + } else { + $this->Error('Could not include font definition file: '.$family.''); + } // check font parameters if ((!isset($type)) OR (!isset($cw))) { $this->Error('The font definition file has a bad format: '.$fontfile.''); - } + } if (!isset($file)) { $file = ''; - } + } if (!isset($enc)) { $enc = ''; - } - if (!isset($dw) OR $this->empty_string($dw)) { - // set default width - if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) { - $dw = $desc['MissingWidth']; + } + if (!isset($dw) OR $this->empty_string($dw)) { + // set default width + if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) { + $dw = $desc['MissingWidth']; } elseif (isset($cw[32])) { - $dw = $cw[32]; - } else { - $dw = 600; + $dw = $cw[32]; + } else { + $dw = 600; } } ++$this->numfonts; // register CID font (all styles at once) - if ($type == 'cidfont0') { + if ($type == 'cidfont0') { $file = ''; // not embedded $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic'); - $sname = $name.$styles[$bistyle]; + $sname = $name.$styles[$bistyle]; if ((strpos($bistyle, 'B') !== false) AND (isset($desc['StemV'])) AND ($desc['StemV'] == 70)) { $desc['StemV'] = 120; - } + } $this->setFontBuffer($fontkey, array('i' => $this->numfonts, 'type' => $type, 'name' => $sname, 'desc' => $desc, 'cidinfo' => $cidinfo, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc)); } elseif ($type == 'core') { $this->setFontBuffer($fontkey, array('i' => $this->numfonts, 'type' => 'core', 'name' => $this->CoreFonts[$fontkey], 'up' => -100, 'ut' => 50, 'cw' => $cw, 'dw' => $dw)); @@ -3037,7 +3037,7 @@ public function AddFont($family, $style='', $fontfile='') { if ($d == 0) { $d = $nb + 1; $this->diffs[$d] = $diff; - } + } $this->setFontSubBuffer($fontkey, 'diff', $d); } if (!$this->empty_string($file)) { @@ -3058,13 +3058,13 @@ public function AddFont($family, $style='', $fontfile='') { * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:
* @param string $family Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive): It is also possible to pass an empty string. In that case, the current family is retained. * @param string $style Font style. Possible values are (case insensitive): or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined. - * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12 + * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12 * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces. * @access public * @since 1.0 * @see AddFont(), SetFontSize() */ - public function SetFont($family, $style='', $size=0, $fontfile='') { + public function SetFont($family, $style='', $size=0, $fontfile='') { //Select a font; size given in points if ($size == 0) { $size = $this->FontSizePt; @@ -3102,16 +3102,16 @@ public function SetFontSize($size) { $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); } } - + /** * Defines the default monospaced font. * @param string $font Font name. * @access public * @since 4.5.025 */ - public function SetDefaultMonospacedFont($font) { - $this->default_monospaced_font = $font; - } + public function SetDefaultMonospacedFont($font) { + $this->default_monospaced_font = $font; + } /** * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.
@@ -3153,7 +3153,7 @@ public function SetLink($link, $y=0, $page=-1) { * @param float $y Ordinate of the upper-left corner of the rectangle * @param float $w Width of the rectangle * @param float $h Height of the rectangle - * @param mixed $link URL or identifier returned by AddLink() + * @param mixed $link URL or identifier returned by AddLink() * @param int $spaces number of spaces on the text to link * @access public * @since 1.5 @@ -3171,84 +3171,84 @@ public function Link($x, $y, $w, $h, $link, $spaces=0) { * @param float $w Width of the rectangle * @param float $h Height of the rectangle * @param string $text annotation text or alternate content - * @param array $opt array of options (see section 8.4 of PDF reference 1.7). + * @param array $opt array of options (see section 8.4 of PDF reference 1.7). * @param int $spaces number of spaces on the text to link * @access public * @since 4.0.018 (2008-08-06) */ - public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) { - // recalculate coordinates to account for graphic transformations - if (isset($this->transfmatrix)) { - $maxid = count($this->transfmatrix) - 1; - for ($i=$maxid; $i >= 0; $i--) { - $ctm = $this->transfmatrix[$i]; - if (isset($ctm['a'])) { - $x = $x * $this->k; - $y = ($this->h - $y) * $this->k; - $w = $w * $this->k; - $h = $h * $this->k; - // top left - $xt = $x; - $yt = $y; - $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; - $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; - // top right - $xt = $x + $w; - $yt = $y; - $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; - $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; - // bottom left - $xt = $x; - $yt = $y - $h; - $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; - $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; - // bottom right - $xt = $x + $w; - $yt = $y - $h; - $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; - $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; - // new coordinates (rectangle area) - $x = min($x1, $x2, $x3, $x4); - $y = max($y1, $y2, $y3, $y4); - $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k; - $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k; - $x = $x / $this->k; - $y = $this->h - ($y / $this->k); - } - } - } - $this->PageAnnots[$this->page][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces); - if (($opt['Subtype'] == 'FileAttachment') AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']) AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) { - $this->embeddedfiles[basename($opt['FS'])] = array('file' => $opt['FS'], 'n' => (count($this->embeddedfiles) + 100000)); - } - } - + public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) { + // recalculate coordinates to account for graphic transformations + if (isset($this->transfmatrix)) { + $maxid = count($this->transfmatrix) - 1; + for ($i=$maxid; $i >= 0; $i--) { + $ctm = $this->transfmatrix[$i]; + if (isset($ctm['a'])) { + $x = $x * $this->k; + $y = ($this->h - $y) * $this->k; + $w = $w * $this->k; + $h = $h * $this->k; + // top left + $xt = $x; + $yt = $y; + $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; + $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; + // top right + $xt = $x + $w; + $yt = $y; + $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; + $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; + // bottom left + $xt = $x; + $yt = $y - $h; + $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; + $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; + // bottom right + $xt = $x + $w; + $yt = $y - $h; + $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e']; + $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f']; + // new coordinates (rectangle area) + $x = min($x1, $x2, $x3, $x4); + $y = max($y1, $y2, $y3, $y4); + $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k; + $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k; + $x = $x / $this->k; + $y = $this->h - ($y / $this->k); + } + } + } + $this->PageAnnots[$this->page][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces); + if (($opt['Subtype'] == 'FileAttachment') AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']) AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) { + $this->embeddedfiles[basename($opt['FS'])] = array('file' => $opt['FS'], 'n' => (count($this->embeddedfiles) + 100000)); + } + } + /** * Embedd the attached files. - * @since 4.4.000 (2008-12-07) + * @since 4.4.000 (2008-12-07) * @access protected * @see Annotation() */ - protected function _putEmbeddedFiles() { - reset($this->embeddedfiles); - foreach ($this->embeddedfiles as $filename => $filedata) { - $data = file_get_contents($filedata['file']); - $filter = ''; - if ($this->compress) { - $data = gzcompress($data); - $filter = ' /Filter /FlateDecode'; - } + protected function _putEmbeddedFiles() { + reset($this->embeddedfiles); + foreach ($this->embeddedfiles as $filename => $filedata) { + $data = file_get_contents($filedata['file']); + $filter = ''; + if ($this->compress) { + $data = gzcompress($data); + $filter = ' /Filter /FlateDecode'; + } $this->offsets[$filedata['n']] = $this->bufferlen; $this->_out($filedata['n'].' 0 obj'); - $this->_out('<>'); + $this->_out('<>'); $this->_putstream($data); - $this->_out('endobj'); - } - } + $this->_out('endobj'); + } + } /** - * Prints a character string. - * The origin is on the left of the first charcter, on the baseline. + * Prints a character string. + * The origin is on the left of the first charcter, on the baseline. * This method allows to place a string precisely on the page. * @param float $x Abscissa of the origin * @param float $y Ordinate of the origin @@ -3256,7 +3256,7 @@ protected function _putEmbeddedFiles() { * @param int $stroke outline size in points (0 = disable) * @param boolean $clip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation). * @access public - * @since 1.0 + * @since 1.0 * @deprecated deprecated since version 4.3.005 (2008-11-25) * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell() */ @@ -3306,37 +3306,37 @@ public function AcceptPageBreak() { /** * Add page if needed. - * @param float $h Cell height. Default value: 0. - * @param mixed $y starting y position, leave empty for current position. + * @param float $h Cell height. Default value: 0. + * @param mixed $y starting y position, leave empty for current position. * @return boolean true in case of page break, false otherwise. * @since 3.2.000 (2008-07-01) * @access protected */ protected function checkPageBreak($h=0, $y='') { - if ($this->empty_string($y)) { - $y = $this->y; - } + if ($this->empty_string($y)) { + $y = $this->y; + } if ((($y + $h) > $this->PageBreakTrigger) AND (!$this->InFooter) AND ($this->AcceptPageBreak())) { //Automatic page break $x = $this->x; $this->AddPage($this->CurOrientation); - $this->y = $this->tMargin; - $oldpage = $this->page - 1; - if ($this->rtl) { - if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) { - $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']); - } else { - $this->x = $x; - } - } else { - if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) { - $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']); - } else { - $this->x = $x; - } - } + $this->y = $this->tMargin; + $oldpage = $this->page - 1; + if ($this->rtl) { + if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) { + $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']); + } else { + $this->x = $x; + } + } else { + if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) { + $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']); + } else { + $this->x = $x; + } + } return true; - } + } return false; } @@ -3352,7 +3352,7 @@ protected function checkPageBreak($h=0, $y='') { * @param string $align Allows to center or align the text. Possible values are: * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. * @param mixed $link URL or identifier returned by AddLink(). - * @param int $stretch stretch carachter mode: + * @param int $stretch stretch carachter mode: * @param boolean $ignore_min_height if true ignore automatic minimum height value. * @access public * @since 1.0 @@ -3367,31 +3367,31 @@ public function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $l $this->checkPageBreak($h); $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height)); } - + /** * Removes SHY characters from text. - * @param string $txt input string - * @return string without SHY characters. - * @access public + * @param string $txt input string + * @return string without SHY characters. + * @access public * @since (4.5.019) 2009-02-28 */ - public function removeSHY($txt='') { - /* - * Unicode Data - * Name : SOFT HYPHEN, commonly abbreviated as SHY - * HTML Entity (decimal): ­ - * HTML Entity (hex): ­ - * HTML Entity (named): ­ - * How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173] - * UTF-8 (hex): 0xC2 0xAD (c2ad) - * UTF-8 character: chr(194).chr(173) - */ - $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt); - if (!$this->isunicode) { - $txt = preg_replace('/([\\xad]{1})/', '', $txt); - } - return $txt; - } + public function removeSHY($txt='') { + /* + * Unicode Data + * Name : SOFT HYPHEN, commonly abbreviated as SHY + * HTML Entity (decimal): ­ + * HTML Entity (hex): ­ + * HTML Entity (named): ­ + * How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173] + * UTF-8 (hex): 0xC2 0xAD (c2ad) + * UTF-8 character: chr(194).chr(173) + */ + $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt); + if (!$this->isunicode) { + $txt = preg_replace('/([\\xad]{1})/', '', $txt); + } + return $txt; + } /** * Returns the PDF string code to print a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.
@@ -3404,20 +3404,20 @@ public function removeSHY($txt='') { * @param string $align Allows to center or align the text. Possible values are: * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. * @param mixed $link URL or identifier returned by AddLink(). - * @param int $stretch stretch carachter mode: + * @param int $stretch stretch carachter mode: * @param boolean $ignore_min_height if true ignore automatic minimum height value. * @access protected * @since 1.0 * @see Cell() */ - protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false) { - $txt = $this->removeSHY($txt); - $rs = ''; //string to be returned + protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false) { + $txt = $this->removeSHY($txt); + $rs = ''; //string to be returned if (!$ignore_min_height) { $min_cell_height = $this->FontSize * $this->cell_height_ratio; if ($h < $min_cell_height) { $h = $min_cell_height; - } + } } $k = $this->k; if ($this->empty_string($w) OR ($w <= 0)) { @@ -3441,7 +3441,7 @@ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $ } $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $this->y) * $k), ($w * $k), (-$h * $k), $op); } - if (is_string($border)) { + if (is_string($border)) { $lm = ($this->LineWidth / 2); $x = $this->x; $y = $this->y; @@ -3594,7 +3594,7 @@ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $ $rs .= ' BT 100 Tz ET'; } } - // reset word spacing + // reset word spacing if (!(($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) AND ($align == 'J')) { $rs .= ' BT 0 Tw ET'; } @@ -3616,7 +3616,7 @@ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $ } else { $this->x += $w; } - } + } $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n"; $rs = $gstyles.$rs; return $rs; @@ -3637,8 +3637,8 @@ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $ * @param int $y y position in user units * @param boolean $reseth if true reset the last cell height (default true). * @param int $stretch stretch carachter mode: - * @param boolean $ishtml set to true if $txt is HTML content (default = false). - * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width. + * @param boolean $ishtml set to true if $txt is HTML content (default = false). + * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width. * @param float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false. * @return int Return the number of cells or 1 for html mode. * @access public @@ -3681,8 +3681,8 @@ public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $ } else { $this->SetLeftMargin($this->x); $this->SetRightMargin($this->w - $this->x - $w); - } - $starty = $this->y; + } + $starty = $this->y; if ($autopadding) { // Adjust internal padding if ($this->cMargin < ($this->LineWidth / 2)) { @@ -3693,7 +3693,7 @@ public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $ $this->y += $this->LineWidth / 2; } // add top padding - $this->y += $this->cMargin; + $this->y += $this->cMargin; } if ($ishtml) { // ******* Write HTML text @@ -3702,54 +3702,54 @@ public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $ } else { // ******* Write text $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, false, $maxh); - } + } if ($autopadding) { // add bottom padding $this->y += $this->cMargin; // Add bottom space if needed if (($this->lasth - $this->FontSize) < $this->LineWidth) { $this->y += $this->LineWidth / 2; - } + } } // Get end-of-text Y position $currentY = $this->y; // get latest page number - $endpage = $this->page; + $endpage = $this->page; // check if a new page has been created if ($endpage > $startpage) { // design borders around HTML cells. for ($page=$startpage; $page <= $endpage; ++$page) { - $this->setPage($page); + $this->setPage($page); if ($page == $startpage) { - $this->y = $starty; // put cursor at the beginning of cell on the first page - $h = $this->getPageHeight() - $starty - $this->getBreakMargin(); + $this->y = $starty; // put cursor at the beginning of cell on the first page + $h = $this->getPageHeight() - $starty - $this->getBreakMargin(); $cborder = $this->getBorderMode($border, $position='start'); } elseif ($page == $endpage) { $this->y = $this->tMargin; // put cursor at the beginning of last page - $h = $currentY - $this->tMargin; + $h = $currentY - $this->tMargin; $cborder = $this->getBorderMode($border, $position='end'); } else { $this->y = $this->tMargin; // put cursor at the beginning of the current page - $h = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin(); + $h = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin(); $cborder = $this->getBorderMode($border, $position='middle'); - } + } $nx = $x; - // account for margin changes - if ($page > $startpage) { - if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { - $nx = $x + ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { - $nx = $x + ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); - } - } - $this->SetX($nx); - $ccode = $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, false); - if ($cborder OR $fill) { + // account for margin changes + if ($page > $startpage) { + if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { + $nx = $x + ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); + } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) { + $nx = $x + ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); + } + } + $this->SetX($nx); + $ccode = $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, false); + if ($cborder OR $fill) { $pagebuff = $this->getPageBuffer($this->page); $pstart = substr($pagebuff, 0, $this->intmrk[$this->page]); $pend = substr($pagebuff, $this->intmrk[$this->page]); $this->setPageBuffer($this->page, $pstart.$ccode."\n".$pend); - $this->intmrk[$this->page] += strlen($ccode."\n"); + $this->intmrk[$this->page] += strlen($ccode."\n"); } } } else { @@ -3757,24 +3757,24 @@ public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $ // put cursor at the beginning of text $this->SetY($y); $this->SetX($x); - // design a cell around the text - $ccode = $this->getCellCode($w, $h, '', $border, 1, '', $fill, '', 0, true); - if ($border OR $fill) { - if (end($this->transfmrk[$this->page]) !== false) { - $pagemarkkey = key($this->transfmrk[$this->page]); - $pagemark = &$this->transfmrk[$this->page][$pagemarkkey]; - } elseif ($this->InFooter) { - $pagemark = &$this->footerpos[$this->page]; - } else { - $pagemark = &$this->intmrk[$this->page]; - } + // design a cell around the text + $ccode = $this->getCellCode($w, $h, '', $border, 1, '', $fill, '', 0, true); + if ($border OR $fill) { + if (end($this->transfmrk[$this->page]) !== false) { + $pagemarkkey = key($this->transfmrk[$this->page]); + $pagemark = &$this->transfmrk[$this->page][$pagemarkkey]; + } elseif ($this->InFooter) { + $pagemark = &$this->footerpos[$this->page]; + } else { + $pagemark = &$this->intmrk[$this->page]; + } $pagebuff = $this->getPageBuffer($this->page); $pstart = substr($pagebuff, 0, $pagemark); $pend = substr($pagebuff, $pagemark); $this->setPageBuffer($this->page, $pstart.$ccode."\n".$pend); - $pagemark += strlen($ccode."\n"); + $pagemark += strlen($ccode."\n"); } - } + } // Get end-of-cell Y position $currentY = $this->GetY(); // restore original margin values @@ -3794,120 +3794,120 @@ public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $ } return $nl; } - - /** - * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages) - * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:or a string containing some or all of the following characters (in any order): - * @param string multicell position: 'start', 'middle', 'end' - * @return border mode - * @access protected - * @since 4.4.002 (2008-12-09) - */ - protected function getBorderMode($border, $position='start') { - if ((!$this->opencell) AND ($border == 1)) { - return 1; - } - $cborder = ''; - switch ($position) { - case 'start': { - if ($border == 1) { - $cborder = 'LTR'; - } else { - if (!(false === strpos($border, 'L'))) { - $cborder .= 'L'; - } - if (!(false === strpos($border, 'T'))) { - $cborder .= 'T'; - } - if (!(false === strpos($border, 'R'))) { - $cborder .= 'R'; - } - if ((!$this->opencell) AND (!(false === strpos($border, 'B')))) { - $cborder .= 'B'; - } - } - break; - } - case 'middle': { - if ($border == 1) { - $cborder = 'LR'; - } else { - if (!(false === strpos($border, 'L'))) { - $cborder .= 'L'; - } - if ((!$this->opencell) AND (!(false === strpos($border, 'T')))) { - $cborder .= 'T'; - } - if (!(false === strpos($border, 'R'))) { - $cborder .= 'R'; - } - if ((!$this->opencell) AND (!(false === strpos($border, 'B')))) { - $cborder .= 'B'; - } - } - break; - } - case 'end': { - if ($border == 1) { - $cborder = 'LRB'; - } else { - if (!(false === strpos($border, 'L'))) { - $cborder .= 'L'; - } - if ((!$this->opencell) AND (!(false === strpos($border, 'T')))) { - $cborder .= 'T'; - } - if (!(false === strpos($border, 'R'))) { - $cborder .= 'R'; - } - if (!(false === strpos($border, 'B'))) { - $cborder .= 'B'; - } - } - break; - } - default: { - $cborder = $border; - break; - } - } - return $cborder; - } - + + /** + * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages) + * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:or a string containing some or all of the following characters (in any order): + * @param string multicell position: 'start', 'middle', 'end' + * @return border mode + * @access protected + * @since 4.4.002 (2008-12-09) + */ + protected function getBorderMode($border, $position='start') { + if ((!$this->opencell) AND ($border == 1)) { + return 1; + } + $cborder = ''; + switch ($position) { + case 'start': { + if ($border == 1) { + $cborder = 'LTR'; + } else { + if (!(false === strpos($border, 'L'))) { + $cborder .= 'L'; + } + if (!(false === strpos($border, 'T'))) { + $cborder .= 'T'; + } + if (!(false === strpos($border, 'R'))) { + $cborder .= 'R'; + } + if ((!$this->opencell) AND (!(false === strpos($border, 'B')))) { + $cborder .= 'B'; + } + } + break; + } + case 'middle': { + if ($border == 1) { + $cborder = 'LR'; + } else { + if (!(false === strpos($border, 'L'))) { + $cborder .= 'L'; + } + if ((!$this->opencell) AND (!(false === strpos($border, 'T')))) { + $cborder .= 'T'; + } + if (!(false === strpos($border, 'R'))) { + $cborder .= 'R'; + } + if ((!$this->opencell) AND (!(false === strpos($border, 'B')))) { + $cborder .= 'B'; + } + } + break; + } + case 'end': { + if ($border == 1) { + $cborder = 'LRB'; + } else { + if (!(false === strpos($border, 'L'))) { + $cborder .= 'L'; + } + if ((!$this->opencell) AND (!(false === strpos($border, 'T')))) { + $cborder .= 'T'; + } + if (!(false === strpos($border, 'R'))) { + $cborder .= 'R'; + } + if (!(false === strpos($border, 'B'))) { + $cborder .= 'B'; + } + } + break; + } + default: { + $cborder = $border; + break; + } + } + return $cborder; + } + /** * This method returns the estimated number of lines required to print the text. * @param string $txt text to print - * @param float $w width of cell. If 0, they extend up to the right margin of the page. + * @param float $w width of cell. If 0, they extend up to the right margin of the page. * @return int Return the estimated number of lines. * @access public * @since 4.5.011 */ - public function getNumLines($txt, $w=0) { - $lines = 0; + public function getNumLines($txt, $w=0) { + $lines = 0; if ($this->empty_string($w) OR ($w <= 0)) { if ($this->rtl) { $w = $this->x - $this->lMargin; } else { $w = $this->w - $this->rMargin - $this->x; } - } - // max column width - $wmax = $w - (2 * $this->cMargin); + } + // max column width + $wmax = $w - (2 * $this->cMargin); // remove carriage returns - $txt = str_replace("\r", '', $txt); - // remove last newline (if any) - if (substr($txt,-1) == "\n") { - $txt = substr($txt, 0, -1); - } - // divide text in blocks - $txtblocks = explode("\n", $txt); - // for each block; - foreach ($txtblocks as $block) { - // estimate the number of lines - $lines += $this->empty_string($block) ? 1 : (ceil($this->GetStringWidth($block) / $wmax)); - } - return $lines; - } + $txt = str_replace("\r", '', $txt); + // remove last newline (if any) + if (substr($txt,-1) == "\n") { + $txt = substr($txt, 0, -1); + } + // divide text in blocks + $txtblocks = explode("\n", $txt); + // for each block; + foreach ($txtblocks as $block) { + // estimate the number of lines + $lines += $this->empty_string($block) ? 1 : (ceil($this->GetStringWidth($block) / $wmax)); + } + return $lines; + } /** * This method prints text from the current position.
@@ -3918,17 +3918,17 @@ public function getNumLines($txt, $w=0) { * @param string $align Allows to center or align the text. Possible values are: * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line. * @param int $stretch stretch carachter mode: - * @param boolean $firstline if true prints only the first line and return the remaining string. - * @param boolean $firstblock if true the string is the starting of a line. + * @param boolean $firstline if true prints only the first line and return the remaining string. + * @param boolean $firstblock if true the string is the starting of a line. * @param float $maxh maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. * @return mixed Return the number of cells or the remaining string if $firstline = true. * @access public * @since 1.5 */ - public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0) { - if (strlen($txt) == 0) { - $txt = ' '; - } + public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0) { + if (strlen($txt) == 0) { + $txt = ' '; + } // remove carriage returns $s = str_replace("\r", '', $txt); // check if string contains arabic text @@ -3936,30 +3936,30 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $arabic = true; } else { $arabic = false; - } + } // check if string contains RTL text if ($arabic OR $this->tmprtl OR preg_match(K_RE_PATTERN_RTL, $txt)) { $rtlmode = true; - } else { - $rtlmode = false; - } - // get a char width + } else { + $rtlmode = false; + } + // get a char width $chrwidth = $this->GetCharWidth('.'); // get array of unicode values - $chars = $this->UTF8StringToArray($s); - // get array of chars + $chars = $this->UTF8StringToArray($s); + // get array of chars $uchars = $this->UTF8ArrayToUniArray($chars); // get the number of characters - $nb = count($chars); - // replacement for SHY character (minus symbol) - $shy_replacement = 45; - $shy_replacement_char = $this->unichr($shy_replacement); - // widht for SHY replacement + $nb = count($chars); + // replacement for SHY character (minus symbol) + $shy_replacement = 45; + $shy_replacement_char = $this->unichr($shy_replacement); + // widht for SHY replacement $shy_replacement_width = $this->GetCharWidth($shy_replacement); // store current position $prevx = $this->x; - $prevy = $this->y; - // max Y + $prevy = $this->y; + // max Y $maxy = $this->y + $maxh - $h - (2 * $this->cMargin); // calculate remaining line width ($w) if ($this->rtl) { @@ -3968,22 +3968,22 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $w = $this->w - $this->rMargin - $this->x; } // max column width - $wmax = $w - (2 * $this->cMargin); - if (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax)) { - // a single character do not fit on column - return ''; + $wmax = $w - (2 * $this->cMargin); + if (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax)) { + // a single character do not fit on column + return ''; } $i = 0; // character position $j = 0; // current starting position - $sep = -1; // position of the last blank space + $sep = -1; // position of the last blank space $shy = false; // true if the last blank is a soft hypen (SHY) $l = 0; // current string lenght $nl = 0; //number of lines $linebreak = false; // for each character - while ($i < $nb) { - if (($maxh > 0) AND ($this->y >= $maxy) ) { - $firstline = true; + while ($i < $nb) { + if (($maxh > 0) AND ($this->y >= $maxy) ) { + $firstline = true; } //Get the current character $c = $chars[$i]; @@ -3997,15 +3997,15 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc } } else { $talign = $align; - } + } $tmpstr = $this->UniArrSubString($uchars, $j, $i); if ($firstline) { - $startx = $this->x; - $tmparr = array_slice($chars, $j, $i); + $startx = $this->x; + $tmparr = array_slice($chars, $j, $i); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); - } - $linew = $this->GetArrStringWidth($tmparr); + $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + } + $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); if ($this->rtl) { $this->endlinex = $startx - $linew; @@ -4015,10 +4015,10 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $w = $linew; $tmpcmargin = $this->cMargin; if ($maxh == 0) { - $this->cMargin = 0; + $this->cMargin = 0; } } - $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch); + $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch); unset($tmpstr); if ($firstline) { $this->cMargin = $tmpcmargin; @@ -4027,32 +4027,32 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc ++$nl; $j = $i + 1; $l = 0; - $sep = -1; - $shy = false; - // account for margin changes - if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) { - // AcceptPageBreak() may be overriden on extended classed to include margin changes - $this->AcceptPageBreak(); + $sep = -1; + $shy = false; + // account for margin changes + if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) { + // AcceptPageBreak() may be overriden on extended classed to include margin changes + $this->AcceptPageBreak(); } $w = $this->getRemainingWidth(); $wmax = $w - (2 * $this->cMargin); - } else { - // 160 is the non-breaking space. - // 173 is SHY (Soft Hypen). - // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator. - // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants. - // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between. + } else { + // 160 is the non-breaking space. + // 173 is SHY (Soft Hypen). + // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator. + // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants. + // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between. if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces, $this->unichr($c)))) { // update last blank space position - $sep = $i; - // check if is a SHY - if ($c == 173) { - $shy = true; - } else { - $shy = false; + $sep = $i; + // check if is a SHY + if ($c == 173) { + $shy = true; + } else { + $shy = false; } } - // update string length + // update string length if ((($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) AND ($arabic)) { // with bidirectional algorithm some chars may be changed affecting the line length // *** very slow *** @@ -4066,22 +4066,22 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc // check if the line was already started if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth))) OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $chrwidth)))) { - // print a void cell and go to next line + // print a void cell and go to next line $this->Cell($w, $h, '', 0, 1); - $linebreak = true; + $linebreak = true; if ($firstline) { return ($this->UniArrSubString($uchars, $j)); } } else { - // truncate the word because do not fit on column + // truncate the word because do not fit on column $tmpstr = $this->UniArrSubString($uchars, $j, $i); if ($firstline) { - $startx = $this->x; - $tmparr = array_slice($chars, $j, $i); + $startx = $this->x; + $tmparr = array_slice($chars, $j, $i); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); - } - $linew = $this->GetArrStringWidth($tmparr); + $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + } + $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); if ($this->rtl) { $this->endlinex = $startx - $linew; @@ -4091,10 +4091,10 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $w = $linew; $tmpcmargin = $this->cMargin; if ($maxh == 0) { - $this->cMargin = 0; + $this->cMargin = 0; } } - $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch); + $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch); unset($tmpstr); if ($firstline) { $this->cMargin = $tmpcmargin; @@ -4104,35 +4104,35 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc --$i; } } else { - // word wrapping - if ($this->rtl AND (!$firstblock)) { - $endspace = 1; - } else { - $endspace = 0; - } - if ($shy) { - // add hypen (minus symbol) at the end of the line - $shy_width = $shy_replacement_width; + // word wrapping + if ($this->rtl AND (!$firstblock)) { + $endspace = 1; + } else { + $endspace = 0; + } + if ($shy) { + // add hypen (minus symbol) at the end of the line + $shy_width = $shy_replacement_width; if ($this->rtl) { - $shy_char_left = $shy_replacement_char; + $shy_char_left = $shy_replacement_char; $shy_char_right = ''; - } else { + } else { $shy_char_left = ''; $shy_char_right = $shy_replacement_char; - } - } else { - $shy_width = 0; - $shy_char_left = ''; - $shy_char_right = ''; - } + } + } else { + $shy_width = 0; + $shy_char_left = ''; + $shy_char_right = ''; + } $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace)); if ($firstline) { - $startx = $this->x; - $tmparr = array_slice($chars, $j, ($sep + $endspace)); + $startx = $this->x; + $tmparr = array_slice($chars, $j, ($sep + $endspace)); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); - } - $linew = $this->GetArrStringWidth($tmparr); + $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + } + $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); if ($this->rtl) { $this->endlinex = $startx - $linew - $shy_width; @@ -4140,28 +4140,28 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $this->endlinex = $startx + $linew + $shy_width; } $w = $linew; - $tmpcmargin = $this->cMargin; + $tmpcmargin = $this->cMargin; if ($maxh == 0) { - $this->cMargin = 0; + $this->cMargin = 0; } - } + } // print the line - $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch); + $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch); unset($tmpstr); - if ($firstline) { + if ($firstline) { // return the remaining text $this->cMargin = $tmpcmargin; return ($this->UniArrSubString($uchars, ($sep + $endspace))); } $i = $sep; - $sep = -1; + $sep = -1; $shy = false; $j = ($i+1); - } - // account for margin changes - if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) { - // AcceptPageBreak() may be overriden on extended classed to include margin changes - $this->AcceptPageBreak(); + } + // account for margin changes + if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) { + // AcceptPageBreak() may be overriden on extended classed to include margin changes + $this->AcceptPageBreak(); } $w = $this->getRemainingWidth(); $wmax = $w - (2 * $this->cMargin); @@ -4203,15 +4203,15 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $w = $l; break; } - } + } $tmpstr = $this->UniArrSubString($uchars, $j, $nb); if ($firstline) { - $startx = $this->x; - $tmparr = array_slice($chars, $j, $nb); + $startx = $this->x; + $tmparr = array_slice($chars, $j, $nb); if ($rtlmode) { - $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); - } - $linew = $this->GetArrStringWidth($tmparr); + $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl); + } + $linew = $this->GetArrStringWidth($tmparr); unset($tmparr); if ($this->rtl) { $this->endlinex = $startx - $linew; @@ -4219,12 +4219,12 @@ public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretc $this->endlinex = $startx + $linew; } $w = $linew; - $tmpcmargin = $this->cMargin; + $tmpcmargin = $this->cMargin; if ($maxh == 0) { - $this->cMargin = 0; + $this->cMargin = 0; } } - $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch); + $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch); unset($tmpstr); if ($firstline) { $this->cMargin = $tmpcmargin; @@ -4279,7 +4279,7 @@ public function UTF8ArrSubString($strarr, $start='', $end='') { * @param int $start the starting element of $strarr. * @param int $end first element that will not be returned. * @return Return part of a string - * @access public + * @access public * @since 4.5.037 (2009-04-07) */ public function UniArrSubString($uniarr, $start='', $end='') { @@ -4288,7 +4288,7 @@ public function UniArrSubString($uniarr, $start='', $end='') { } if (strlen($end) == 0) { $end = count($uniarr); - } + } $string = ''; for ($i=$start; $i < $end; ++$i) { $string .= $uniarr[$i]; @@ -4300,7 +4300,7 @@ public function UniArrSubString($uniarr, $start='', $end='') { * Convert an array of UTF8 values to array of unicode characters * @param string $ta The input array of UTF8 values. * @return Return array of unicode characters - * @access public + * @access public * @since 4.5.037 (2009-04-07) */ public function UTF8ArrayToUniArray($ta) { @@ -4356,11 +4356,11 @@ public function unichr($c) { * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be: * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library). * @param int $dpi dot-per-inch resolution used on resize - * @param string $palign Allows to center or align the image on the current line. Possible values are: - * @param boolean $ismask true if this image is a mask, false otherwise - * @param mixed $imgmask image object returned by this function or false - * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:or a string containing some or all of the following characters (in any order): - * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box. + * @param string $palign Allows to center or align the image on the current line. Possible values are: + * @param boolean $ismask true if this image is a mask, false otherwise + * @param mixed $imgmask image object returned by this function or false + * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:or a string containing some or all of the following characters (in any order): + * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box. * @return image information * @access public * @since 1.1 @@ -4371,18 +4371,18 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig } if ($y === '') { $y = $this->y; - } - // get image dimensions - $imsize = @getimagesize($file); - if ($imsize === FALSE) { - // encode spaces on filename - $file = str_replace(' ', '%20', $file); - $imsize = @getimagesize($file); - if ($imsize === FALSE) { - $this->Error('[Image] No such file or directory in '.$file); - } - } - // get original image width and height in pixels + } + // get image dimensions + $imsize = @getimagesize($file); + if ($imsize === FALSE) { + // encode spaces on filename + $file = str_replace(' ', '%20', $file); + $imsize = @getimagesize($file); + if ($imsize === FALSE) { + $this->Error('[Image] No such file or directory in '.$file); + } + } + // get original image width and height in pixels list($pixw, $pixh) = $imsize; // calculate image width and height on document if (($w <= 0) AND ($h <= 0)) { @@ -4393,13 +4393,13 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig $w = $h * $pixw / $pixh; } elseif ($h <= 0) { $h = $w * $pixh / $pixw; - } elseif ($fitbox AND ($w > 0) AND ($h > 0)) { - // scale image dimensions proportionally to fit within the ($w, $h) box - if ((($w * $pixh) / ($h * $pixw)) < 1) { - $h = $w * $pixh / $pixw; - } else { - $w = $h * $pixw / $pixh; - } + } elseif ($fitbox AND ($w > 0) AND ($h > 0)) { + // scale image dimensions proportionally to fit within the ($w, $h) box + if ((($w * $pixh) / ($h * $pixw)) < 1) { + $h = $w * $pixh / $pixw; + } else { + $w = $h * $pixw / $pixh; + } } // calculate new minimum dimensions in pixels $neww = round($w * $this->k * $dpi / $this->dpi); @@ -4424,22 +4424,22 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig $type = 'jpeg'; } $mqr = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); + @set_magic_quotes_runtime(0); // Specific image handlers $mtd = '_parse'.$type; // GD image handler function $gdfunction = 'imagecreatefrom'.$type; $info = false; - if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) { + if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) { // TCPDF image functions - $info = $this->$mtd($file); - if ($info == 'pngalpha') { - return $this->ImagePngAlpha($file, $x, $y, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign); + $info = $this->$mtd($file); + if ($info == 'pngalpha') { + return $this->ImagePngAlpha($file, $x, $y, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign); } } if (!$info) { if (function_exists($gdfunction)) { - // GD library + // GD library $img = $gdfunction($file); if ($resize) { $imgr = imagecreatetruecolor($neww, $newh); @@ -4451,42 +4451,42 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig } elseif (extension_loaded('imagick')) { // ImageMagick library $img = new Imagick(); - $img->readImage($file); + $img->readImage($file); if ($resize) { - $img->resizeImage($neww, $newh, 10, 1, false); - } - $img->setCompressionQuality($this->jpeg_quality); - $img->setImageFormat('jpeg'); + $img->resizeImage($neww, $newh, 10, 1, false); + } + $img->setCompressionQuality($this->jpeg_quality); + $img->setImageFormat('jpeg'); $tempname = tempnam(K_PATH_CACHE, 'jpg_'); $img->writeImage($tempname); $info = $this->_parsejpeg($tempname); unlink($tempname); $img->destroy(); - } else { - return; + } else { + return; } } if ($info === false) { //If false, we cannot process image return; } - set_magic_quotes_runtime($mqr); - if ($ismask) { - // force grayscale - $info['cs'] = 'DeviceGray'; + @set_magic_quotes_runtime($mqr); + if ($ismask) { + // force grayscale + $info['cs'] = 'DeviceGray'; } - $info['i'] = $this->numimages + 1; - if ($imgmask !== false) { - $info['masked'] = $imgmask; + $info['i'] = $this->numimages + 1; + if ($imgmask !== false) { + $info['masked'] = $imgmask; } // add image to document $this->setImageBuffer($file, $info); } else { $info = $this->getImageBuffer($file); } - // Check whether we need a new page first as this does not fit - if ($this->checkPageBreak($h, $y)) { - $y = $this->GetY() + $this->cMargin; + // Check whether we need a new page first as this does not fit + if ($this->checkPageBreak($h, $y)) { + $y = $this->GetY() + $this->cMargin; } // set bottomcoordinates $this->img_rb_y = $y + $h; @@ -4519,23 +4519,23 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig // set right side coordinate $this->img_rb_x = $ximg + $w; } - } - if ($ismask) { - // embed hidden, ouside the canvas - $xkimg = ($this->pagedim[$this->page]['w'] + 10); - } else { - $xkimg = $ximg * $this->k; + } + if ($ismask) { + // embed hidden, ouside the canvas + $xkimg = ($this->pagedim[$this->page]['w'] + 10); + } else { + $xkimg = $ximg * $this->k; } $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i'])); - if (!empty($border)) { - $bx = $x; - $by = $y; - $this->x = $ximg; - $this->y = $y; - $this->Cell($w, $h, '', $border, 0, '', 0, '', 0); - $this->x = $bx; - $this->y = $by; - } + if (!empty($border)) { + $bx = $x; + $by = $y; + $this->x = $ximg; + $this->y = $y; + $this->Cell($w, $h, '', $border, 0, '', 0, '', 0); + $this->x = $bx; + $this->y = $by; + } if ($link) { $this->Link($ximg, $y, $w, $h, $link, 0); } @@ -4564,7 +4564,7 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig break; } } - $this->endlinex = $this->img_rb_x; + $this->endlinex = $this->img_rb_x; return $info['i']; } @@ -4637,7 +4637,7 @@ protected function _parsepng($file) { $bpc = ord(fread($f, 1)); if ($bpc > 8) { //$this->Error('16-bit depth not supported: '.$file); - fclose($f); + fclose($f); return false; } $ct = ord(fread($f, 1)); @@ -4647,24 +4647,24 @@ protected function _parsepng($file) { $colspace = 'DeviceRGB'; } elseif ($ct == 3) { $colspace = 'Indexed'; - } else { + } else { // alpha channel - fclose($f); + fclose($f); return 'pngalpha'; } if (ord(fread($f, 1)) != 0) { //$this->Error('Unknown compression method: '.$file); - fclose($f); + fclose($f); return false; } if (ord(fread($f, 1)) != 0) { //$this->Error('Unknown filter method: '.$file); - fclose($f); + fclose($f); return false; } if (ord(fread($f, 1)) != 0) { //$this->Error('Interlacing not supported: '.$file); - fclose($f); + fclose($f); return false; } fread($f, 4); @@ -4706,35 +4706,35 @@ protected function _parsepng($file) { } while ($n); if (($colspace == 'Indexed') AND (empty($pal))) { //$this->Error('Missing palette in '.$file); - fclose($f); + fclose($f); return false; } fclose($f); return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data); - } - + } + /** - * Binary-safe and URL-safe file read. + * Binary-safe and URL-safe file read. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached. * @param resource $handle - * @param int $length - * @return Returns the read string or FALSE in case of error. + * @param int $length + * @return Returns the read string or FALSE in case of error. * @author Nicola Asuni * @access protected * @since 4.5.027 (2009-03-16) - */ - protected function rfread($handle, $length) { - $data = fread($handle, $length); - if ($data === false) { - return false; - } - $rest = $length - strlen($data); - if ($rest > 0) { - $data .= $this->rfread($handle, $rest); - } - return $data; - } - + */ + protected function rfread($handle, $length) { + $data = fread($handle, $length); + if ($data === false) { + return false; + } + $rest = $length - strlen($data); + if ($rest > 0) { + $data .= $this->rfread($handle, $rest); + } + return $data; + } + /** * Extract info from a PNG image with alpha channel using the GD library. * @param string $file Name of the file containing the image. @@ -4747,58 +4747,58 @@ protected function rfread($handle, $length) { * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be: * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library). * @param int $dpi dot-per-inch resolution used on resize - * @param string $palign Allows to center or align the image on the current line. Possible values are: + * @param string $palign Allows to center or align the image on the current line. Possible values are: * @author Valentin Schmidt, Nicola Asuni * @access protected - * @since 4.3.007 (2008-12-04) + * @since 4.3.007 (2008-12-04) * @see Image() */ - protected function ImagePngAlpha($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='') { - // get image size - list($wpx, $hpx) = getimagesize($file); - // generate images - $img = imagecreatefrompng($file); - $imgalpha = imagecreate($wpx, $hpx); - // generate gray scale pallete - for ($c = 0; $c < 256; ++$c) { - ImageColorAllocate($imgalpha, $c, $c, $c); - } - // extract alpha channel - for ($xpx = 0; $xpx < $wpx; ++$xpx) { - for ($ypx = 0; $ypx < $hpx; ++$ypx) { - $colorindex = imagecolorat($img, $xpx, $ypx); - $col = imagecolorsforindex($img, $colorindex); - imagesetpixel($imgalpha, $xpx, $ypx, $this->getGDgamma((127 - $col['alpha']) * 255 / 127)); - } - } - // create temp alpha file - $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_'); - imagepng($imgalpha, $tempfile_alpha); - imagedestroy($imgalpha); - // extract image without alpha channel - $imgplain = imagecreatetruecolor($wpx, $hpx); - imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx); - // create temp image file - $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_'); - imagepng($imgplain, $tempfile_plain); - imagedestroy($imgplain); - // embed mask image - $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false); - // embed image, masked with previously embedded mask - $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask); - // remove temp files - unlink($tempfile_alpha); - unlink($tempfile_plain); - } - + protected function ImagePngAlpha($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='') { + // get image size + list($wpx, $hpx) = getimagesize($file); + // generate images + $img = imagecreatefrompng($file); + $imgalpha = imagecreate($wpx, $hpx); + // generate gray scale pallete + for ($c = 0; $c < 256; ++$c) { + ImageColorAllocate($imgalpha, $c, $c, $c); + } + // extract alpha channel + for ($xpx = 0; $xpx < $wpx; ++$xpx) { + for ($ypx = 0; $ypx < $hpx; ++$ypx) { + $colorindex = imagecolorat($img, $xpx, $ypx); + $col = imagecolorsforindex($img, $colorindex); + imagesetpixel($imgalpha, $xpx, $ypx, $this->getGDgamma((127 - $col['alpha']) * 255 / 127)); + } + } + // create temp alpha file + $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_'); + imagepng($imgalpha, $tempfile_alpha); + imagedestroy($imgalpha); + // extract image without alpha channel + $imgplain = imagecreatetruecolor($wpx, $hpx); + imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx); + // create temp image file + $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_'); + imagepng($imgplain, $tempfile_plain); + imagedestroy($imgplain); + // embed mask image + $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false); + // embed image, masked with previously embedded mask + $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask); + // remove temp files + unlink($tempfile_alpha); + unlink($tempfile_plain); + } + /** * Correct the gamma value to be used with GD library * @param float $v the gamma value to be corrected * @access protected * @since 4.3.007 (2008-12-04) - */ - protected function getGDgamma($v) { - return (pow(($v / 255), 2.2) * 255); + */ + protected function getGDgamma($v) { + return (pow(($v / 255), 2.2) * 255); } /** @@ -4892,43 +4892,43 @@ public function SetX($x) { } else { $this->x = $this->w + $x; } - } - if ($this->x < 0) { - $this->x = 0; - } - if ($this->x > $this->w) { - $this->x = $this->w; + } + if ($this->x < 0) { + $this->x = 0; + } + if ($this->x > $this->w) { + $this->x = $this->w; } } /** * Moves the current abscissa back to the left margin and sets the ordinate. * If the passed value is negative, it is relative to the bottom of the page. - * @param float $y The value of the ordinate. + * @param float $y The value of the ordinate. * @param bool $resetx if true (default) reset the X position. * @access public * @since 1.0 * @see GetX(), GetY(), SetY(), SetXY() */ - public function SetY($y, $resetx=true) { + public function SetY($y, $resetx=true) { if ($resetx) { - //reset x + //reset x if ($this->rtl) { $this->x = $this->w - $this->rMargin; } else { $this->x = $this->lMargin; - } + } } if ($y >= 0) { $this->y = $y; } else { $this->y = $this->h + $y; - } - if ($this->y < 0) { - $this->y = 0; - } - if ($this->y > $this->h) { - $this->y = $this->h; + } + if ($this->y < 0) { + $this->y = 0; + } + if ($this->y > $this->h) { + $this->y = $this->h; } } @@ -4968,70 +4968,70 @@ public function Output($name='doc.pdf', $dest='I') { $dest = $dest ? 'D' : 'F'; } $dest = strtoupper($dest); - if ($dest != 'F') { - $name = preg_replace('/[\s]+/', '_', $name); + if ($dest != 'F') { + $name = preg_replace('/[\s]+/', '_', $name); $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name); - } - if ($this->sign) { - // *** apply digital signature to the document *** - // get the document content - $pdfdoc = $this->getBuffer(); - // remove last newline - $pdfdoc = substr($pdfdoc, 0, -1); - // Remove the original buffer - if (isset($this->diskcache) AND $this->diskcache) { - // remove buffer file from cache - unlink($this->buffer); - } - unset($this->buffer); - // remove filler space - $tmppos = strpos($pdfdoc, '/ByteRange[0 ********** ********** **********]') + 58; - $pdfdoc = substr($pdfdoc, 0, $tmppos).substr($pdfdoc, $tmppos + $this->signature_max_lenght); - // define the ByteRange - $byte_range = array(); - $byte_range[0] = 0; - $byte_range[1] = $tmppos - 1; - $byte_range[2] = $byte_range[1] + $this->signature_max_lenght; - $byte_range[3] = strlen($pdfdoc) - $byte_range[1]; - // replace the ByteRange - $byterange = sprintf('/ByteRange[0 %010u %010u %010u]', $byte_range[1], $byte_range[2], $byte_range[3]); - $pdfdoc = str_replace('/ByteRange[0 ********** ********** **********]', $byterange, $pdfdoc); - // write the document to a temporary folder + } + if ($this->sign) { + // *** apply digital signature to the document *** + // get the document content + $pdfdoc = $this->getBuffer(); + // remove last newline + $pdfdoc = substr($pdfdoc, 0, -1); + // Remove the original buffer + if (isset($this->diskcache) AND $this->diskcache) { + // remove buffer file from cache + unlink($this->buffer); + } + unset($this->buffer); + // remove filler space + $tmppos = strpos($pdfdoc, '/ByteRange[0 ********** ********** **********]') + 58; + $pdfdoc = substr($pdfdoc, 0, $tmppos).substr($pdfdoc, $tmppos + $this->signature_max_lenght); + // define the ByteRange + $byte_range = array(); + $byte_range[0] = 0; + $byte_range[1] = $tmppos - 1; + $byte_range[2] = $byte_range[1] + $this->signature_max_lenght; + $byte_range[3] = strlen($pdfdoc) - $byte_range[1]; + // replace the ByteRange + $byterange = sprintf('/ByteRange[0 %010u %010u %010u]', $byte_range[1], $byte_range[2], $byte_range[3]); + $pdfdoc = str_replace('/ByteRange[0 ********** ********** **********]', $byterange, $pdfdoc); + // write the document to a temporary folder $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_'); $f = fopen($tempdoc, 'wb'); if (!$f) { $this->Error('Unable to create temporary file: '.$tempdoc); - } + } $pdfdoc_lenght = strlen($pdfdoc); fwrite($f, $pdfdoc, $pdfdoc_lenght); - fclose($f); - // get digital signature. - // IS THE FOLLOWING PROCEDURE CORRECT? - $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_'); + fclose($f); + // get digital signature. + // IS THE FOLLOWING PROCEDURE CORRECT? + $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_'); if (empty($this->signature_data['extracerts'])) { openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED); } else { openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']); - } - unlink($tempdoc); - // read signature - $signature = file_get_contents($tempsign, false, null, $pdfdoc_lenght); - unlink($tempsign); - // extract signature - $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13)); - $tmparr = explode("\n\n", $signature); - $signature = $tmparr[1]; - unset($tmparr); - // decode signature - $signature = base64_decode(trim($signature)); - // convert signature to hex - $signature = current(unpack('H*', $signature)); - $signature = str_pad($signature, $this->signature_max_lenght, '0'); - // Add signature to the document - $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).$signature.substr($pdfdoc, (0 - $byte_range[3])); - $this->diskcache = false; - $this->buffer = &$pdfdoc; - $this->bufferlen = strlen($pdfdoc); + } + unlink($tempdoc); + // read signature + $signature = file_get_contents($tempsign, false, null, $pdfdoc_lenght); + unlink($tempsign); + // extract signature + $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13)); + $tmparr = explode("\n\n", $signature); + $signature = $tmparr[1]; + unset($tmparr); + // decode signature + $signature = base64_decode(trim($signature)); + // convert signature to hex + $signature = current(unpack('H*', $signature)); + $signature = str_pad($signature, $this->signature_max_lenght, '0'); + // Add signature to the document + $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).$signature.substr($pdfdoc, (0 - $byte_range[3])); + $this->diskcache = false; + $this->buffer = &$pdfdoc; + $this->bufferlen = strlen($pdfdoc); } switch($dest) { case 'I': { @@ -5071,7 +5071,7 @@ public function Output($name='doc.pdf', $dest='I') { // force download dialog header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream', false); - header('Content-Type: application/download', false); + header('Content-Type: application/download', false); header('Content-Type: application/pdf', false); // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="'.basename($name).'";'); @@ -5106,21 +5106,21 @@ public function Output($name='doc.pdf', $dest='I') { break; } case 'F': { - // Save PDF to a local file - if ($this->diskcache) { - copy($this->buffer, $name); + // Save PDF to a local file + if ($this->diskcache) { + copy($this->buffer, $name); } else { $f = fopen($name, 'wb'); if (!$f) { $this->Error('Unable to create output file: '.$name); } fwrite($f, $this->getBuffer(), $this->bufferlen); - fclose($f); + fclose($f); } break; } - case 'S': { - // Returns PDF as a string + case 'S': { + // Returns PDF as a string return $this->getBuffer(); } default: { @@ -5128,37 +5128,37 @@ public function Output($name='doc.pdf', $dest='I') { } } return ''; - } - + } + /** - * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache. - * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables. + * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache. + * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables. * @param boolean $preserve_objcopy if true preserves the objcopy variable - * @access public + * @access public * @since 4.5.016 (2009-02-24) */ - public function _destroy($destroyall=false, $preserve_objcopy=false) { - if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) { - // remove buffer file from cache - unlink($this->buffer); - } - foreach (array_keys(get_object_vars($this)) as $val) { - if ($destroyall OR ( - ($val != 'internal_encoding') - AND ($val != 'state') - AND ($val != 'bufferlen') - AND ($val != 'buffer') - AND ($val != 'diskcache') + public function _destroy($destroyall=false, $preserve_objcopy=false) { + if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) { + // remove buffer file from cache + unlink($this->buffer); + } + foreach (array_keys(get_object_vars($this)) as $val) { + if ($destroyall OR ( + ($val != 'internal_encoding') + AND ($val != 'state') + AND ($val != 'bufferlen') + AND ($val != 'buffer') + AND ($val != 'diskcache') AND ($val != 'sign') - AND ($val != 'signature_data') - AND ($val != 'signature_max_lenght') - )) { - if (!$preserve_objcopy OR ($val != 'objcopy')) { - unset($this->$val); - } - } + AND ($val != 'signature_data') + AND ($val != 'signature_max_lenght') + )) { + if (!$preserve_objcopy OR ($val != 'objcopy')) { + unset($this->$val); + } + } } - } + } /** * Check for locale-related bug @@ -5193,7 +5193,7 @@ protected function _getfontpath() { */ protected function _putpages() { $nb = $this->numpages; - if (!empty($this->AliasNbPages)) { + if (!empty($this->AliasNbPages)) { $nbs = $this->formatPageNumber($nb); $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font $alias_a = $this->_escape($this->AliasNbPages); @@ -5204,7 +5204,7 @@ protected function _putpages() { $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl)); $alias_cu = $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}', false, $this->tmprtl)); } - } + } if (!empty($this->AliasNumPage)) { $alias_pa = $this->_escape($this->AliasNumPage); $alias_pau = $this->_escape('{'.$this->AliasNumPage.'}'); @@ -5214,20 +5214,20 @@ protected function _putpages() { $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl)); $alias_pcu = $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}', false, $this->tmprtl)); } - } + } $pagegroupnum = 0; $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; - for ($n=1; $n <= $nb; ++$n) { - $temppage = $this->getPageBuffer($n); - if (!empty($this->pagegroups)) { - if(isset($this->newpagegroup[$n])) { - $pagegroupnum = 0; - } + for ($n=1; $n <= $nb; ++$n) { + $temppage = $this->getPageBuffer($n); + if (!empty($this->pagegroups)) { + if(isset($this->newpagegroup[$n])) { + $pagegroupnum = 0; + } ++$pagegroupnum; - foreach ($this->pagegroups as $k => $v) { - // replace total pages group numbers + foreach ($this->pagegroups as $k => $v) { + // replace total pages group numbers $vs = $this->formatPageNumber($v); - $vu = $this->UTF8ToUTF16BE($vs, false); + $vu = $this->UTF8ToUTF16BE($vs, false); $alias_ga = $this->_escape($k); $alias_gau = $this->_escape('{'.$k.'}'); if ($this->isunicode) { @@ -5243,11 +5243,11 @@ protected function _putpages() { $temppage = str_replace($alias_gb, $vs, $temppage); $temppage = str_replace($alias_gc, $vs, $temppage); } - $temppage = str_replace($alias_ga, $vs, $temppage); - // replace page group numbers + $temppage = str_replace($alias_ga, $vs, $temppage); + // replace page group numbers $pvs = $this->formatPageNumber($pagegroupnum); - $pvu = $this->UTF8ToUTF16BE($pvs, false); - $pk = str_replace('{nb', '{pnb', $k); + $pvu = $this->UTF8ToUTF16BE($pvs, false); + $pk = str_replace('{nb', '{pnb', $k); $alias_pga = $this->_escape($pk); $alias_pgau = $this->_escape('{'.$pk.'}'); if ($this->isunicode) { @@ -5265,32 +5265,32 @@ protected function _putpages() { } $temppage = str_replace($alias_pga, $pvs, $temppage); } - } - if (!empty($this->AliasNbPages)) { - // replace total pages number - $temppage = str_replace($alias_au, $nbu, $temppage); + } + if (!empty($this->AliasNbPages)) { + // replace total pages number + $temppage = str_replace($alias_au, $nbu, $temppage); if ($this->isunicode) { $temppage = str_replace($alias_bu, $nbu, $temppage); $temppage = str_replace($alias_cu, $nbu, $temppage); $temppage = str_replace($alias_b, $nbs, $temppage); $temppage = str_replace($alias_c, $nbs, $temppage); - } - $temppage = str_replace($alias_a, $nbs, $temppage); - } - if (!empty($this->AliasNumPage)) { - // replace page number + } + $temppage = str_replace($alias_a, $nbs, $temppage); + } + if (!empty($this->AliasNumPage)) { + // replace page number $pnbs = $this->formatPageNumber($n); - $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font - $temppage = str_replace($alias_pau, $pnbu, $temppage); + $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font + $temppage = str_replace($alias_pau, $pnbu, $temppage); if ($this->isunicode) { $temppage = str_replace($alias_pbu, $pnbu, $temppage); $temppage = str_replace($alias_pcu, $pnbu, $temppage); $temppage = str_replace($alias_pb, $pnbs, $temppage); $temppage = str_replace($alias_pc, $pnbs, $temppage); - } - $temppage = str_replace($alias_pa, $pnbs, $temppage); - } - $temppage = str_replace($this->epsmarker, '', $temppage); + } + $temppage = str_replace($alias_pa, $pnbs, $temppage); + } + $temppage = str_replace($this->epsmarker, '', $temppage); //$this->setPageBuffer($n, $temppage); //Page $this->_newobj(); @@ -5306,10 +5306,10 @@ protected function _putpages() { $this->_newobj(); $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); $this->_putstream($p); - $this->_out('endobj'); - if ($this->diskcache) { - // remove temporary files - unlink($this->pages[$n]); + $this->_out('endobj'); + if ($this->diskcache) { + // remove temporary files + unlink($this->pages[$n]); } } //Pages root @@ -5328,7 +5328,7 @@ protected function _putpages() { } /** - * Output Page Annotations. + * Output Page Annotations. * !!! THIS FUNCTION IS NOT YET COMPLETED !!! * See section 8.4 of PDF reference. * @param int $n page number @@ -5341,12 +5341,12 @@ protected function _putannots($n) { $annots = '/Annots ['; foreach ($this->PageAnnots[$n] as $key => $pl) { $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER); - $a = $pl['x'] * $this->k; + $a = $pl['x'] * $this->k; $b = $this->pagedim[$n]['h'] - ($pl['y'] * $this->k); $c = $pl['w'] * $this->k; $d = $pl['h'] * $this->k; $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b-$d); - $annots .= "\n"; + $annots .= "\n"; $annots .= '<_datastring($pl['txt']).'>>'; - } else { + } else { // internal link $l = $this->links[$pl['txt']]; $annots .= sprintf(' /Dest [%d 0 R /XYZ 0 %.2F null]', (1 + (2 * $l[0])), ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k))); @@ -5615,35 +5615,35 @@ protected function _putannots($n) { case 'popup': { break; } - case 'fileattachment': { - if (!isset($pl['opt']['fs'])) { - break; - } - $filename = basename($pl['opt']['fs']); - if (isset($this->embeddedfiles[$filename]['n'])) { - $annots .= ' /FS <_datastring($filename).' /EF <embeddedfiles[$filename]['n'].' 0 R>> >>'; + case 'fileattachment': { + if (!isset($pl['opt']['fs'])) { + break; + } + $filename = basename($pl['opt']['fs']); + if (isset($this->embeddedfiles[$filename]['n'])) { + $annots .= ' /FS <_datastring($filename).' /EF <embeddedfiles[$filename]['n'].' 0 R>> >>'; $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag'); if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { $annots .= ' /Name /'.$pl['opt']['name']; } else { $annots .= ' /Name /PushPin'; - } + } } break; } - case 'sound': { - if (!isset($pl['opt']['sound'])) { - break; - } - $filename = basename($pl['opt']['sound']); - if (isset($this->embeddedfiles[$filename]['n'])) { - // ... TO BE COMPLETED ... + case 'sound': { + if (!isset($pl['opt']['sound'])) { + break; + } + $filename = basename($pl['opt']['sound']); + if (isset($this->embeddedfiles[$filename]['n'])) { + // ... TO BE COMPLETED ... $iconsapp = array('Speaker', 'Mic'); if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) { $annots .= ' /Name /'.$pl['opt']['name']; } else { $annots .= ' /Name /Speaker'; - } + } } break; } @@ -5653,11 +5653,11 @@ protected function _putannots($n) { case 'widget': { if (isset($pl['opt']['h'])) { $annots .= ' /H '.intval($pl['opt']['h']); - } - if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk']))) { - $annots .= ' /MK <<'; - // ... TO BE COMPLETED ... - $annots .= '>>'; + } + if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk']))) { + $annots .= ' /MK <<'; + // ... TO BE COMPLETED ... + $annots .= '>>'; } break; } @@ -5682,7 +5682,7 @@ protected function _putannots($n) { } $annots .= '>>'; - } + } $annots .= "\n]"; $this->_out($annots); } @@ -5701,20 +5701,20 @@ protected function _putfonts() { $this->_out('endobj'); } $mqr = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - foreach ($this->FontFiles as $file => $info) { - // search and get font file to embedd - $fontdir = $info['fontdir']; - $file = strtolower($file); - $fontfile = ''; - // search files on various directories - if (file_exists($fontdir.$file)) { - $fontfile = $fontdir.$file; - } elseif (file_exists($this->_getfontpath().$file)) { - $fontfile = $this->_getfontpath().$file; - } elseif (file_exists($file)) { - $fontfile = $file; - } + @set_magic_quotes_runtime(0); + foreach ($this->FontFiles as $file => $info) { + // search and get font file to embedd + $fontdir = $info['fontdir']; + $file = strtolower($file); + $fontfile = ''; + // search files on various directories + if (file_exists($fontdir.$file)) { + $fontfile = $fontdir.$file; + } elseif (file_exists($this->_getfontpath().$file)) { + $fontfile = $this->_getfontpath().$file; + } elseif (file_exists($file)) { + $fontfile = $file; + } if (!$this->empty_string($fontfile)) { $font = file_get_contents($fontfile); $compressed = (substr($file, -2) == '.z'); @@ -5728,8 +5728,8 @@ protected function _putfonts() { //Strip second binary header $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6)); } - } - $this->_newobj(); + } + $this->_newobj(); $this->FontFiles[$file]['n'] = $this->n; $this->_out('<_out('>>'); $this->_putstream($font); - $this->_out('endobj'); + $this->_out('endobj'); } } - set_magic_quotes_runtime($mqr); + @set_magic_quotes_runtime($mqr); foreach ($this->fontkeys as $k) { - //Font objects - $this->setFontSubBuffer($k, 'n', $this->n + 1); + //Font objects + $this->setFontSubBuffer($k, 'n', $this->n + 1); $font = $this->getFontBuffer($k); $type = $font['type']; $name = $font['name']; @@ -5792,7 +5792,7 @@ protected function _putfonts() { //Descriptor $this->_newobj(); $s = '< $v) { + foreach ($font['desc'] as $k => $v) { $s .= ' /'.$k.' '.$v.''; } if (!$this->empty_string($font['file'])) { @@ -5809,109 +5809,109 @@ protected function _putfonts() { $this->$mtd($font); } } - } + } /** - * Outputs font widths - * @parameter array $font font data - * @parameter int $cidoffset offset for CID values + * Outputs font widths + * @parameter array $font font data + * @parameter int $cidoffset offset for CID values * @author Nicola Asuni * @access protected * @since 4.4.000 (2008-12-07) - */ - protected function _putfontwidths($font, $cidoffset=0) { - ksort($font['cw']); - $rangeid = 0; - $range = array(); - $prevcid = -2; - $prevwidth = -1; - $interval = false; - // for each character - foreach ($font['cw'] as $cid => $width) { - $cid -= $cidoffset; - if ($width != $font['dw']) { - if ($cid == ($prevcid + 1)) { - // consecutive CID - if ($width == $prevwidth) { - if ($width == $range[$rangeid][0]) { - $range[$rangeid][] = $width; - } else { - array_pop($range[$rangeid]); - // new range - $rangeid = $prevcid; - $range[$rangeid] = array(); - $range[$rangeid][] = $prevwidth; - $range[$rangeid][] = $width; - } - $interval = true; - $range[$rangeid]['interval'] = true; - } else { - if ($interval) { - // new range - $rangeid = $cid; - $range[$rangeid] = array(); - $range[$rangeid][] = $width; - } else { - $range[$rangeid][] = $width; - } - $interval = false; - } - } else { - // new range - $rangeid = $cid; - $range[$rangeid] = array(); - $range[$rangeid][] = $width; - $interval = false; - } - $prevcid = $cid; - $prevwidth = $width; - } - } - // optimize ranges - $prevk = -1; - $nextk = -1; - $prevint = false; - foreach ($range as $k => $ws) { - $cws = count($ws); - if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) { - if (isset($range[$k]['interval'])) { - unset($range[$k]['interval']); - } - $range[$prevk] = array_merge($range[$prevk], $range[$k]); - unset($range[$k]); - } else { - $prevk = $k; - } - $nextk = $k + $cws; - if (isset($ws['interval'])) { - if ($cws > 3) { - $prevint = true; - } else { - $prevint = false; - } - unset($range[$k]['interval']); - --$nextk; - } else { - $prevint = false; - } - } - // output data - $w = ''; - foreach ($range as $k => $ws) { - if (count(array_count_values($ws)) == 1) { - // interval mode is more compact - $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0]; - } else { + */ + protected function _putfontwidths($font, $cidoffset=0) { + ksort($font['cw']); + $rangeid = 0; + $range = array(); + $prevcid = -2; + $prevwidth = -1; + $interval = false; + // for each character + foreach ($font['cw'] as $cid => $width) { + $cid -= $cidoffset; + if ($width != $font['dw']) { + if ($cid == ($prevcid + 1)) { + // consecutive CID + if ($width == $prevwidth) { + if ($width == $range[$rangeid][0]) { + $range[$rangeid][] = $width; + } else { + array_pop($range[$rangeid]); + // new range + $rangeid = $prevcid; + $range[$rangeid] = array(); + $range[$rangeid][] = $prevwidth; + $range[$rangeid][] = $width; + } + $interval = true; + $range[$rangeid]['interval'] = true; + } else { + if ($interval) { + // new range + $rangeid = $cid; + $range[$rangeid] = array(); + $range[$rangeid][] = $width; + } else { + $range[$rangeid][] = $width; + } + $interval = false; + } + } else { + // new range + $rangeid = $cid; + $range[$rangeid] = array(); + $range[$rangeid][] = $width; + $interval = false; + } + $prevcid = $cid; + $prevwidth = $width; + } + } + // optimize ranges + $prevk = -1; + $nextk = -1; + $prevint = false; + foreach ($range as $k => $ws) { + $cws = count($ws); + if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) { + if (isset($range[$k]['interval'])) { + unset($range[$k]['interval']); + } + $range[$prevk] = array_merge($range[$prevk], $range[$k]); + unset($range[$k]); + } else { + $prevk = $k; + } + $nextk = $k + $cws; + if (isset($ws['interval'])) { + if ($cws > 3) { + $prevint = true; + } else { + $prevint = false; + } + unset($range[$k]['interval']); + --$nextk; + } else { + $prevint = false; + } + } + // output data + $w = ''; + foreach ($range as $k => $ws) { + if (count(array_count_values($ws)) == 1) { + // interval mode is more compact + $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0]; + } else { // range mode - $w .= ' '.$k.' [ '.implode(' ', $ws).' ]'; + $w .= ' '.$k.' [ '.implode(' ', $ws).' ]'; } - } - $this->_out('/W ['.$w.' ]'); - } + } + $this->_out('/W ['.$w.' ]'); + } /** * Adds unicode fonts.
- * Based on PDF Reference 1.3 (section 5) + * Based on PDF Reference 1.3 (section 5) * @parameter array $font font data * @access protected * @author Nicola Asuni @@ -5924,8 +5924,8 @@ protected function _puttruetypeunicode($font) { $this->_out('<_out('/Subtype /Type0'); $this->_out('/BaseFont /'.$font['name'].''); - $this->_out('/Encoding /Identity-H'); //The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values. - $this->_out('/ToUnicode /Identity-H'); + $this->_out('/Encoding /Identity-H'); //The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values. + $this->_out('/ToUnicode /Identity-H'); $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]'); $this->_out('>>'); $this->_out('endobj'); @@ -5934,14 +5934,14 @@ protected function _puttruetypeunicode($font) { $this->_newobj(); $this->_out('<_out('/Subtype /CIDFontType2'); - $this->_out('/BaseFont /'.$font['name'].''); - // A dictionary containing entries that define the character collection of the CIDFont. - $cidinfo = '/Registry '.$this->_datastring('Adobe'); - $cidinfo .= ' /Ordering '.$this->_datastring('Identity'); + $this->_out('/BaseFont /'.$font['name'].''); + // A dictionary containing entries that define the character collection of the CIDFont. + $cidinfo = '/Registry '.$this->_datastring('Adobe'); + $cidinfo .= ' /Ordering '.$this->_datastring('Identity'); $cidinfo .= ' /Supplement 0'; $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>'); $this->_out('/FontDescriptor '.($this->n + 1).' 0 R'); - $this->_out('/DW '.$font['dw'].''); // default width + $this->_out('/DW '.$font['dw'].''); // default width $this->_putfontwidths($font, 0); $this->_out('/CIDToGIDMap '.($this->n + 2).' 0 R'); $this->_out('>>'); @@ -5953,32 +5953,32 @@ protected function _puttruetypeunicode($font) { $this->_out('/FontName /'.$font['name']); foreach ($font['desc'] as $key => $value) { $this->_out('/'.$key.' '.$value); - } + } $fontdir = ''; if (!$this->empty_string($font['file'])) { // A stream containing a TrueType font - $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R'); + $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R'); $fontdir = $this->FontFiles[$font['file']]['fontdir']; } $this->_out('>>'); - $this->_out('endobj'); - $this->_newobj(); - if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) { + $this->_out('endobj'); + $this->_newobj(); + if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) { // Embed CIDToGIDMap - // A specification of the mapping from CIDs to glyph indices - // search and get CTG font file to embedd - $ctgfile = strtolower($font['ctg']); - // search and get ctg font file to embedd - $fontfile = ''; - // search files on various directories - if (file_exists($fontdir.$ctgfile)) { - $fontfile = $fontdir.$ctgfile; - } elseif (file_exists($this->_getfontpath().$ctgfile)) { - $fontfile = $this->_getfontpath().$ctgfile; - } elseif (file_exists($ctgfile)) { - $fontfile = $ctgfile; - } - if ($this->empty_string($fontfile)) { + // A specification of the mapping from CIDs to glyph indices + // search and get CTG font file to embedd + $ctgfile = strtolower($font['ctg']); + // search and get ctg font file to embedd + $fontfile = ''; + // search files on various directories + if (file_exists($fontdir.$ctgfile)) { + $fontfile = $fontdir.$ctgfile; + } elseif (file_exists($this->_getfontpath().$ctgfile)) { + $fontfile = $this->_getfontpath().$ctgfile; + } elseif (file_exists($ctgfile)) { + $fontfile = $ctgfile; + } + if ($this->empty_string($fontfile)) { $this->Error('Font file not found: '.$ctgfile); } $size = filesize($fontfile); @@ -5990,10 +5990,10 @@ protected function _puttruetypeunicode($font) { $this->_out('/Filter /FlateDecode'); } $this->_out('>>'); - $this->_putstream(file_get_contents($fontfile)); - } + $this->_putstream(file_get_contents($fontfile)); + } $this->_out('endobj'); - } + } /** * Output CID-0 fonts. @@ -6002,30 +6002,30 @@ protected function _puttruetypeunicode($font) { * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira * @since 3.2.000 (2008-06-23) */ - protected function _putcidfont0($font) { - $cidoffset = 31; - if (isset($font['cidinfo']['uni2cid'])) { - // convert unicode to cid. - $uni2cid = $font['cidinfo']['uni2cid']; - $cw = array(); - foreach ($font['cw'] as $uni => $width) { - if (isset($uni2cid[$uni])) { - $cw[($uni2cid[$uni] + $cidoffset)] = $width; - } elseif ($uni < 256) { - $cw[$uni] = $width; - } // else unknown character - } - $font = array_merge($font, array('cw' => $cw)); + protected function _putcidfont0($font) { + $cidoffset = 31; + if (isset($font['cidinfo']['uni2cid'])) { + // convert unicode to cid. + $uni2cid = $font['cidinfo']['uni2cid']; + $cw = array(); + foreach ($font['cw'] as $uni => $width) { + if (isset($uni2cid[$uni])) { + $cw[($uni2cid[$uni] + $cidoffset)] = $width; + } elseif ($uni < 256) { + $cw[$uni] = $width; + } // else unknown character + } + $font = array_merge($font, array('cw' => $cw)); } $name = $font['name']; $enc = $font['enc']; if ($enc) { $longname = $name.'-'.$enc; - } else { - $longname = $name; + } else { + $longname = $name; } $this->_newobj(); - $this->_out('<_out('<_out('/BaseFont /'.$longname); $this->_out('/Subtype /Type0'); if ($enc) { @@ -6037,21 +6037,21 @@ protected function _putcidfont0($font) { $this->_newobj(); $this->_out('<_out('/BaseFont /'.$name); - $this->_out('/Subtype /CIDFontType0'); - $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry']); - $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']); + $this->_out('/Subtype /CIDFontType0'); + $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry']); + $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']); $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement']; $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>'); $this->_out('/FontDescriptor '.($this->n + 1).' 0 R'); - $this->_out('/DW '.$font['dw']); + $this->_out('/DW '.$font['dw']); $this->_putfontwidths($font, $cidoffset); $this->_out('>>'); $this->_out('endobj'); $this->_newobj(); $s = '< $v) { - if ($k != 'Style') { - $s .= ' /'.$k.' '.$v.''; + foreach ($font['desc'] as $k => $v) { + if ($k != 'Style') { + $s .= ' /'.$k.' '.$v.''; } } $this->_out($s.'>>'); @@ -6063,8 +6063,8 @@ protected function _putcidfont0($font) { * @access protected */ protected function _putimages() { - $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; - foreach ($this->imagekeys as $file) { + $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; + foreach ($this->imagekeys as $file) { $info = $this->getImageBuffer($file); $this->_newobj(); $this->setImageSubBuffer($file, 'n', $this->n); @@ -6092,7 +6092,7 @@ protected function _putimages() { } if (isset($info['trns']) AND is_array($info['trns'])) { $trns=''; - $count_info = count($info['trns']); + $count_info = count($info['trns']); for ($i=0; $i < $count_info; ++$i) { $trns .= $info['trns'][$i].' '.$info['trns'][$i].' '; } @@ -6110,24 +6110,24 @@ protected function _putimages() { $this->_out('endobj'); } } - } - + } + /** * Output Spot Colors Resources. - * @access protected + * @access protected * @since 4.0.024 (2008-09-12) */ - protected function _putspotcolors() { - foreach ($this->spot_colors as $name => $color) { - $this->_newobj(); - $this->spot_colors[$name]['n'] = $this->n; - $this->_out('[/Separation /'.str_replace(' ', '#20', $name)); - $this->_out('/DeviceCMYK <<'); - $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] '); - $this->_out(sprintf('/C1 [%.4F %.4F %.4F %.4F] ', $color['c']/100, $color['m']/100, $color['y']/100, $color['k']/100)); - $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]'); - $this->_out('endobj'); - } + protected function _putspotcolors() { + foreach ($this->spot_colors as $name => $color) { + $this->_newobj(); + $this->spot_colors[$name]['n'] = $this->n; + $this->_out('[/Separation /'.str_replace(' ', '#20', $name)); + $this->_out('/DeviceCMYK <<'); + $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] '); + $this->_out(sprintf('/C1 [%.4F %.4F %.4F %.4F] ', $color['c']/100, $color['m']/100, $color['y']/100, $color['k']/100)); + $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]'); + $this->_out('endobj'); + } } /** @@ -6135,7 +6135,7 @@ protected function _putspotcolors() { * @access protected */ protected function _putxobjectdict() { - foreach ($this->imagekeys as $file) { + foreach ($this->imagekeys as $file) { $info = $this->getImageBuffer($file); $this->_out('/I'.$info['i'].' '.$info['n'].' 0 R'); } @@ -6148,7 +6148,7 @@ protected function _putxobjectdict() { protected function _putresourcedict() { $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); $this->_out('/Font <<'); - foreach ($this->fontkeys as $fontkey) { + foreach ($this->fontkeys as $fontkey) { $font = $this->getFontBuffer($fontkey); $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); } @@ -6171,26 +6171,26 @@ protected function _putresourcedict() { $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R'); } $this->_out('>>'); - } - // spot colors - if (isset($this->spot_colors) AND (count($this->spot_colors) > 0)) { - $this->_out('/ColorSpace <<'); - foreach ($this->spot_colors as $color) { - $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R'); - } - $this->_out('>>'); } - } + // spot colors + if (isset($this->spot_colors) AND (count($this->spot_colors) > 0)) { + $this->_out('/ColorSpace <<'); + foreach ($this->spot_colors as $color) { + $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R'); + } + $this->_out('>>'); + } + } /** * Output Resources. * @access protected */ - protected function _putresources() { + protected function _putresources() { $this->_putextgstates(); $this->_putocg(); $this->_putfonts(); - $this->_putimages(); + $this->_putimages(); $this->_putspotcolors(); $this->_putshaders(); //Resource dictionary @@ -6201,7 +6201,7 @@ protected function _putresources() { $this->_out('>>'); $this->_out('endobj'); $this->_putjavascript(); - $this->_putbookmarks(); + $this->_putbookmarks(); $this->_putEmbeddedFiles(); // encryption if ($this->encrypted) { @@ -6266,11 +6266,11 @@ protected function _putcatalog() { } if (isset($this->l['a_meta_language'])) { $this->_out('/Lang /'.$this->l['a_meta_language']); - } + } $this->_out('/Names <<'); if (!$this->empty_string($this->javascript)) { $this->_out('/JavaScript '.($this->n_js).' 0 R'); - } + } $this->_out('>>'); if (count($this->outlines) > 0) { $this->_out('/Outlines '.$this->OutlineRoot.' 0 R'); @@ -6279,7 +6279,7 @@ protected function _putcatalog() { $this->_putviewerpreferences(); $p = $this->n_ocg_print.' 0 R'; $v = $this->n_ocg_view.' 0 R'; - $as = '<> <>'; + $as = '<> <>'; $this->_out('/OCProperties <>>>'); } @@ -6382,7 +6382,7 @@ protected function _putheader() { * @access protected */ protected function _enddoc() { - $this->state = 1; + $this->state = 1; $this->_putheader(); $this->_putpages(); $this->_putresources(); @@ -6395,8 +6395,8 @@ protected function _enddoc() { //Catalog $this->_newobj(); $this->_out('<<'); - $this->_putcatalog(); - $this->_putcertification(); + $this->_putcatalog(); + $this->_putcertification(); $this->_putuserrights(); $this->_out('>>'); $this->_out('endobj'); @@ -6407,12 +6407,12 @@ protected function _enddoc() { $this->_out('0000000000 65535 f '); for ($i=1; $i <= $this->n; ++$i) { $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i])); - } - if (isset($this->embeddedfiles) AND count($this->embeddedfiles) > 0) { - $this->_out('100000 '.count($this->embeddedfiles)); - foreach ($this->embeddedfiles as $filename => $filedata) { - $this->_out(sprintf('%010d 00000 n ', $this->offsets[$filedata['n']])); - } + } + if (isset($this->embeddedfiles) AND count($this->embeddedfiles) > 0) { + $this->_out('100000 '.count($this->embeddedfiles)); + foreach ($this->embeddedfiles as $filename => $filedata) { + $this->_out(sprintf('%010d 00000 n ', $this->offsets[$filedata['n']])); + } } //Trailer $this->_out('trailer'); @@ -6422,17 +6422,17 @@ protected function _enddoc() { $this->_out('startxref'); $this->_out($o); $this->_out('%%EOF'); - $this->state = 3; // end-of-doc - if ($this->diskcache) { - // remove temporary files used for images - foreach ($this->imagekeys as $key) { - // remove temporary files - unlink($this->images[$key]); - } - foreach ($this->fontkeys as $key) { - // remove temporary files - unlink($this->fonts[$key]); - } + $this->state = 3; // end-of-doc + if ($this->diskcache) { + // remove temporary files used for images + foreach ($this->imagekeys as $key) { + // remove temporary files + unlink($this->images[$key]); + } + foreach ($this->fontkeys as $key) { + // remove temporary files + unlink($this->fonts[$key]); + } } } @@ -6444,8 +6444,8 @@ protected function _enddoc() { */ protected function _beginpage($orientation='', $format='') { ++$this->page; - $this->setPageBuffer($this->page, ''); - // initialize array for graphics tranformation positions inside a page buffer + $this->setPageBuffer($this->page, ''); + // initialize array for graphics tranformation positions inside a page buffer $this->transfmrk[$this->page] = array(); $this->state = 2; if ($this->empty_string($orientation)) { @@ -6533,7 +6533,7 @@ protected function _dolinethrough($x, $y, $txt) { protected function _freadint($f) { $a = unpack('Ni', fread($f, 4)); return $a['i']; - } + } /** * Add "\" before "\", "(" and ")" @@ -6544,7 +6544,7 @@ protected function _freadint($f) { protected function _escape($s) { // the chr(13) substitution fixes the Bugs item #1421290. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r')); - } + } /** * Format a date string for meta information @@ -6557,7 +6557,7 @@ protected function _datastring($s) { $s = $this->_RC4($this->_objectkey($this->n), $s); } return '('. $this->_escape($s).')'; - } + } /** * Format a text string for meta information @@ -6569,7 +6569,7 @@ protected function _textstring($s) { if ($this->isunicode) { //Convert string to UTF-16BE $s = $this->UTF8ToUTF16BE($s, true); - } + } return $this->_datastring($s); } @@ -6589,7 +6589,7 @@ protected function _escapetext($s) { } } return $this->_escape($s); - } + } /** * Output a stream. @@ -6610,20 +6610,20 @@ protected function _putstream($s) { * @param string $s string to output. * @access protected */ - protected function _out($s) { + protected function _out($s) { if ($this->state == 2) { if ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) { - // puts data before page footer + // puts data before page footer $pagebuff = $this->getPageBuffer($this->page); $page = substr($pagebuff, 0, -$this->footerlen[$this->page]); $footer = substr($pagebuff, -$this->footerlen[$this->page]); - $this->setPageBuffer($this->page, $page.$s."\n".$footer); - // update footer position + $this->setPageBuffer($this->page, $page.$s."\n".$footer); + // update footer position $this->footerpos[$this->page] += strlen($s."\n"); } else { $this->setPageBuffer($this->page, $s."\n", true); } - } else { + } else { $this->setBuffer($s."\n"); } } @@ -6662,25 +6662,25 @@ protected function _out($s) { * @author Nicola Asuni * @since 1.53.0.TC005 (2005-01-05) */ - protected function UTF8StringToArray($str) { - if (isset($this->cache_UTF8StringToArray['_'.$str])) { - // return cached value - return($this->cache_UTF8StringToArray['_'.$str]); - } - // check cache size - if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) { - // remove first element - array_shift($this->cache_UTF8StringToArray); - } - ++$this->cache_size_UTF8StringToArray; + protected function UTF8StringToArray($str) { + if (isset($this->cache_UTF8StringToArray['_'.$str])) { + // return cached value + return($this->cache_UTF8StringToArray['_'.$str]); + } + // check cache size + if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) { + // remove first element + array_shift($this->cache_UTF8StringToArray); + } + ++$this->cache_size_UTF8StringToArray; if (!$this->isunicode) { // split string into array of equivalent codes $strarr = array(); $strlen = strlen($str); for ($i=0; $i < $strlen; ++$i) { $strarr[] = ord($str{$i}); - } - // insert new value on cache + } + // insert new value on cache $this->cache_UTF8StringToArray['_'.$str] = $strarr; return $strarr; } @@ -6737,8 +6737,8 @@ protected function UTF8StringToArray($str) { $bytes = array(); $numbytes = 1; } - } - // insert new value on cache + } + // insert new value on cache $this->cache_UTF8StringToArray['_'.$str] = $unicode; return $unicode; } @@ -6769,23 +6769,23 @@ protected function UTF8ToUTF16BE($str, $setbom=true) { * @access protected * @since 3.2.000 (2008-06-23) */ - protected function UTF8ToLatin1($str) { - global $utf8tolatin; + protected function UTF8ToLatin1($str) { + global $utf8tolatin; if (!$this->isunicode) { return $str; // string is not in unicode } $outstr = ''; // string to be returned $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values - foreach ($unicode as $char) { - if ($char < 256) { - $outstr .= chr($char); - } elseif (array_key_exists($char, $utf8tolatin)) { - // map from UTF-8 - $outstr .= chr($utf8tolatin[$char]); - } elseif ($char == 0xFFFD) { - // skip - } else { - $outstr .= '?'; + foreach ($unicode as $char) { + if ($char < 256) { + $outstr .= chr($char); + } elseif (array_key_exists($char, $utf8tolatin)) { + // map from UTF-8 + $outstr .= chr($utf8tolatin[$char]); + } elseif ($char == 0xFFFD) { + // skip + } else { + $outstr .= '?'; } } return $outstr; @@ -6914,41 +6914,41 @@ public function getPDFData() { $this->Close(); } return $this->buffer; - } + } /** * Output anchor link. * @param string $url link URL or internal link (i.e.: <a href="#23">link to page 23</a>) * @param string $name link name * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. - * @param boolean $firstline if true prints only the first line and return the remaining string. - * @param array $color array of RGB text color + * @param boolean $firstline if true prints only the first line and return the remaining string. + * @param array $color array of RGB text color * @param string $style font style (U, D, B, I) * @return the number of cells used or the remaining text if $firstline = true; * @access public */ public function addHtmlLink($url, $name, $fill=0, $firstline=false, $color='', $style=-1) { - if (!$this->empty_string($url) AND ($url{0} == '#')) { - // convert url to internal link - $page = intval(substr($url, 1)); - $url = $this->AddLink(); - $this->SetLink($url, 0, $page); - } - // store current settings - $prevcolor = $this->fgcolor; - $prevstyle = $this->FontStyle; + if (!$this->empty_string($url) AND ($url{0} == '#')) { + // convert url to internal link + $page = intval(substr($url, 1)); + $url = $this->AddLink(); + $this->SetLink($url, 0, $page); + } + // store current settings + $prevcolor = $this->fgcolor; + $prevstyle = $this->FontStyle; if (empty($color)) { - $this->SetTextColorArray($this->htmlLinkColorArray); - } else { - $this->SetTextColorArray($color); - } + $this->SetTextColorArray($this->htmlLinkColorArray); + } else { + $this->SetTextColorArray($color); + } if ($style == -1) { - $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle); - } else { - $this->SetFont('', $this->FontStyle.$style); + $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle); + } else { + $this->SetFont('', $this->FontStyle.$style); } - $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline); - // restore settings + $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline); + // restore settings $this->SetFont('', $prevstyle); $this->SetTextColorArray($prevcolor); return $ret; @@ -6961,18 +6961,18 @@ public function addHtmlLink($url, $name, $fill=0, $firstline=false, $color='', $ * @access public */ public function convertHTMLColorToDec($color='#FFFFFF') { - global $webcolor; - $returncolor = false; + global $webcolor; + $returncolor = false; $color = preg_replace('/[\s]*/', '', $color); // remove extra spaces $color = strtolower($color); if (strlen($color) == 0) { return false; - } - if (substr($color, 0, 3) == 'rgb') { - $codes = substr($color, 4); - $codes = str_replace(')', '', $codes); - $returncolor = explode(',', $codes, 3); - return $returncolor; + } + if (substr($color, 0, 3) == 'rgb') { + $codes = substr($color, 4); + $codes = str_replace(')', '', $codes); + $returncolor = explode(',', $codes, 3); + return $returncolor; } if (substr($color, 0, 1) != '#') { // decode color name @@ -7010,7 +7010,7 @@ public function convertHTMLColorToDec($color='#FFFFFF') { * Converts pixels to User's Units. * @param int $px pixels * @return float value in user's unit - * @access public + * @access public * @see setImageScale(), getImageScale() */ public function pixelsToUnits($px) { @@ -7029,7 +7029,7 @@ public function unhtmlentities($text_to_convert) { } // ENCRYPTION METHODS ---------------------------------- - // SINCE 2.0.000 (2008-01-02) + // SINCE 2.0.000 (2008-01-02) /** * Compute encryption key depending on object number where the encrypted data is stored @@ -7205,7 +7205,7 @@ public function SetProtection($permissions=array(), $user_pass='', $owner_pass=n * @see StartTransform(), StopTransform() */ public function StartTransform() { - $this->_out('q'); + $this->_out('q'); $this->transfmrk[$this->page][] = $this->pagelen[$this->page]; } @@ -7218,10 +7218,10 @@ public function StartTransform() { * @see StartTransform(), StopTransform() */ public function StopTransform() { - $this->_out('Q'); - if (isset($this->transfmatrix)) { - array_pop($this->transfmatrix); - } + $this->_out('Q'); + if (isset($this->transfmatrix)) { + array_pop($this->transfmatrix); + } array_pop($this->transfmrk[$this->page]); } /** @@ -7497,13 +7497,13 @@ public function Skew($angle_x, $angle_y, $x='', $y='') { * @see StartTransform(), StopTransform() */ protected function Transform($tm) { - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); - // store transformation matrix - $this->transfmatrix[] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]); - // update tranformation mark - if (end($this->transfmrk[$this->page]) !== false) { - $key = key($this->transfmrk[$this->page]); - $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page]; + $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); + // store transformation matrix + $this->transfmatrix[] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]); + // update tranformation mark + if (end($this->transfmrk[$this->page]) !== false) { + $key = key($this->transfmrk[$this->page]); + $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page]; } } @@ -7745,12 +7745,12 @@ public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_col break; } case 'CNZ': { - $op = 'W n'; + $op = 'W n'; $this->_outRect($x, $y, $w, $h, $op); break; } case 'CEO': { - $op = 'W* n'; + $op = 'W* n'; $this->_outRect($x, $y, $w, $h, $op); break; } @@ -8361,7 +8361,7 @@ protected function utf8StrRev($str, $setbom=false, $forcertl=false) { /** * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/). - * @param array $ta array of characters composing the string. + * @param array $ta array of characters composing the string. * @param string $str string to process * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR * @return string @@ -8374,10 +8374,10 @@ protected function utf8Bidi($ta, $str='', $forcertl=false) { // paragraph embedding level $pel = 0; // max level - $maxlevel = 0; + $maxlevel = 0; if ($this->empty_string($str)) { // create string from array - $str = $this->UTF8ArrSubString($ta); + $str = $this->UTF8ArrSubString($ta); } // check if string contains arabic text if (preg_match(K_RE_PATTERN_ARABIC, $str)) { @@ -8391,7 +8391,7 @@ protected function utf8Bidi($ta, $str='', $forcertl=false) { } // get number of chars - $numchars = count($ta); + $numchars = count($ta); if ($forcertl == 'R') { $pel = 1; @@ -8919,7 +8919,7 @@ protected function utf8Bidi($ta, $str='', $forcertl=false) { $ordarray = array(); for ($i=0; $i < $numchars; ++$i) { $ordarray[] = $chardata[$i]['char']; - } + } return $ordarray; } @@ -8930,30 +8930,30 @@ protected function utf8Bidi($ta, $str='', $forcertl=false) { * Adds a bookmark. * @param string $txt bookmark description. * @param int $level bookmark level (minimum value is 0). - * @param float $y Ordinate of the boorkmark position (default = -1 = current position). + * @param float $y Ordinate of the boorkmark position (default = -1 = current position). * @param int $page target page number (leave empty for current page). * @access public * @author Olivier Plathey, Nicola Asuni * @since 2.1.002 (2008-02-12) */ public function Bookmark($txt, $level=0, $y=-1, $page='') { - if ($level < 0) { - $level = 0; - } - if (isset($this->outlines[0])) { - $lastoutline = end($this->outlines); - $maxlevel = $lastoutline['l'] + 1; - } else { - $maxlevel = 0; - } - if ($level > $maxlevel) { - $level = $maxlevel; - } + if ($level < 0) { + $level = 0; + } + if (isset($this->outlines[0])) { + $lastoutline = end($this->outlines); + $maxlevel = $lastoutline['l'] + 1; + } else { + $maxlevel = 0; + } + if ($level > $maxlevel) { + $level = $maxlevel; + } if ($y == -1) { $y = $this->GetY(); - } - if (empty($page)) { - $page = $this->PageNo(); + } + if (empty($page)) { + $page = $this->PageNo(); } $this->outlines[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page); } @@ -9041,9 +9041,9 @@ public function IncludeJS($script) { protected function _putjavascript() { if (empty($this->javascript)) { return; - } - // the following two lines are uded to avoid form fields duplication after saving - $js1 = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1); + } + // the following two lines are uded to avoid form fields duplication after saving + $js1 = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1); $js2 = "getField('tcpdfdocsaved').value = 'saved';"; $this->_newobj(); $this->n_js = $this->n; @@ -9090,11 +9090,11 @@ protected function _JScolor($color) { * @author Denis Van Nuffelen, Nicola Asuni * @since 2.1.002 (2008-02-12) */ - protected function _addfield($type, $name, $x, $y, $w, $h, $prop) { + protected function _addfield($type, $name, $x, $y, $w, $h, $prop) { if ($this->rtl) { $x = $x - $w; - } - // the followind avoid fields duplication after saving the document + } + // the followind avoid fields duplication after saving the document $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {"; $k = $this->k; $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n"; @@ -9106,12 +9106,12 @@ protected function _addfield($type, $name, $x, $y, $w, $h, $prop) { $val = "'".$val."'"; } $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n"; - } + } if ($this->rtl) { $this->x -= $w; } else { - $this->x += $w; - } + $this->x += $w; + } $this->javascript .= '}'; } @@ -9235,30 +9235,30 @@ public function Button($name, $w, $h, $caption, $action, $prop=array()) { // END JAVASCRIPT - FORMS ------------------------------ /* - * Enable Write permissions for PDF Reader. + * Enable Write permissions for PDF Reader. * WARNING: This works only using the Adobe private key with the setSignature() method. * @access protected * @author Nicola Asuni * @since 2.9.000 (2008-03-26) */ - protected function _putuserrights() { + protected function _putuserrights() { if ((!$this->sign) OR (isset($this->signature_data['cert_type']) AND ($this->signature_data['cert_type'] > 0))) { return; } $this->_out('/Perms'); $this->_out('<<'); $this->_out('/UR3'); - $this->_out('<<'); - $this->_out('/Type/Sig'); - $this->_out('/Filter/Adobe.PPKLite'); - $this->_out('/SubFilter/adbe.pkcs7.detached'); - $this->_out('/ByteRange[0 ********** ********** **********]'); - $this->_out('/Contents<>'.str_repeat(' ', $this->signature_max_lenght)); - if ($this->ur) { - $this->_out('/Reference'); - $this->_out('['); - $this->_out('<<'); - $this->_out('/Type/SigRef'); + $this->_out('<<'); + $this->_out('/Type/Sig'); + $this->_out('/Filter/Adobe.PPKLite'); + $this->_out('/SubFilter/adbe.pkcs7.detached'); + $this->_out('/ByteRange[0 ********** ********** **********]'); + $this->_out('/Contents<>'.str_repeat(' ', $this->signature_max_lenght)); + if ($this->ur) { + $this->_out('/Reference'); + $this->_out('['); + $this->_out('<<'); + $this->_out('/Type/SigRef'); $this->_out('/TransformMethod/UR3'); $this->_out('/TransformParams'); $this->_out('<<'); @@ -9278,36 +9278,36 @@ protected function _putuserrights() { } $this->_out('>>'); $this->_out('>>'); - $this->_out(']'); - } + $this->_out(']'); + } $this->_out('/M '.$this->_datastring('D:'.date('YmdHisO'))); $this->_out('>>'); $this->_out('>>'); } - + /* * Add certification signature (DocMDP) * @access protected * @author Nicola Asuni * @since 4.6.008 (2009-05-07) */ - protected function _putcertification() { + protected function _putcertification() { if ((!$this->sign) OR (isset($this->signature_data['cert_type']) AND ($this->signature_data['cert_type'] <= 0))) { return; } $this->_out('/Perms'); $this->_out('<<'); $this->_out('/DocMDP'); - $this->_out('<<'); - $this->_out('/Type/Sig'); - $this->_out('/Filter/Adobe.PPKLite'); - $this->_out('/SubFilter/adbe.pkcs7.detached'); - $this->_out('/ByteRange[0 ********** ********** **********]'); - $this->_out('/Contents<>'.str_repeat(' ', $this->signature_max_lenght)); - $this->_out('/Reference'); - $this->_out('['); - $this->_out('<<'); - $this->_out('/Type/SigRef'); + $this->_out('<<'); + $this->_out('/Type/Sig'); + $this->_out('/Filter/Adobe.PPKLite'); + $this->_out('/SubFilter/adbe.pkcs7.detached'); + $this->_out('/ByteRange[0 ********** ********** **********]'); + $this->_out('/Contents<>'.str_repeat(' ', $this->signature_max_lenght)); + $this->_out('/Reference'); + $this->_out('['); + $this->_out('<<'); + $this->_out('/Type/SigRef'); $this->_out('/TransformMethod/DocMDP'); $this->_out('/TransformParams'); $this->_out('<<'); @@ -9316,26 +9316,26 @@ protected function _putcertification() { $this->_out('/P '.$this->signature_data['cert_type'].''); $this->_out('>>'); $this->_out('>>'); - $this->_out(']'); - $this->_out('/M '.$this->_datastring('D:'.date('YmdHisO'))); + $this->_out(']'); + $this->_out('/M '.$this->_datastring('D:'.date('YmdHisO'))); if (isset($this->signature_data['info']['Name']) AND !$this->empty_string($this->signature_data['info']['Name'])) { $this->_out('/Name '.$this->_textstring($this->signature_data['info']['Name']).''); - } + } if (isset($this->signature_data['info']['Location']) AND !$this->empty_string($this->signature_data['info']['Location'])) { $this->_out('/Location '.$this->_textstring($this->signature_data['info']['Location']).''); - } + } if (isset($this->signature_data['info']['Reason']) AND !$this->empty_string($this->signature_data['info']['Reason'])) { $this->_out('/Reason '.$this->_textstring($this->signature_data['info']['Reason']).''); - } + } if (isset($this->signature_data['info']['ContactInfo']) AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) { $this->_out('/ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo']).''); } $this->_out('>>'); $this->_out('>>'); - } + } /* - * Set User's Rights for PDF Reader + * Set User's Rights for PDF Reader * WARNING: This works only using the Adobe private key with the setSignature() method!. * Check the PDF Reference 8.7.1 Transform Methods, * Table 8.105 Entries in the UR transform parameters dictionary @@ -9359,55 +9359,55 @@ public function setUserRights( $this->ur_annots = $annots; $this->ur_form = $form; $this->ur_signature = $signature; - } - + } + /* - * Enable document signature (requires the OpenSSL Library). - * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader. - * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://') - * @param mixed $private_key private key (string or filename prefixed with 'file://') - * @param string $private_key_password password + * Enable document signature (requires the OpenSSL Library). + * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader. + * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://') + * @param mixed $private_key private key (string or filename prefixed with 'file://') + * @param string $private_key_password password * @param string $extracerts specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used. - * @param int $cert_type The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature. - * @parm array $info array of option information: Name, Location, Reason, ContactInfo. + * @param int $cert_type The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature. + * @parm array $info array of option information: Name, Location, Reason, ContactInfo. * @access public * @author Nicola Asuni * @since 4.6.005 (2009-04-24) */ - public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) { - // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.pem -out tcpdf.pem - $this->sign = true; - $this->signature_data = array(); - if (strlen($signing_cert) == 0) { - $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.pem'; - } - if (strlen($private_key) == 0) { - $private_key = $signing_cert; - } - $this->signature_data['signcert'] = $signing_cert; - $this->signature_data['privkey'] = $private_key; - $this->signature_data['password'] = $private_key_password; - $this->signature_data['extracerts'] = $extracerts; - $this->signature_data['cert_type'] = $cert_type; + public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) { + // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.pem -out tcpdf.pem + $this->sign = true; + $this->signature_data = array(); + if (strlen($signing_cert) == 0) { + $signing_cert = 'file://'.dirname(__FILE__).'/tcpdf.pem'; + } + if (strlen($private_key) == 0) { + $private_key = $signing_cert; + } + $this->signature_data['signcert'] = $signing_cert; + $this->signature_data['privkey'] = $private_key; + $this->signature_data['password'] = $private_key_password; + $this->signature_data['extracerts'] = $extracerts; + $this->signature_data['cert_type'] = $cert_type; $this->signature_data['info'] = array(); - } + } /* * Create a new page group. - * NOTE: call this function before calling AddPage() + * NOTE: call this function before calling AddPage() * @param int $page starting group page (leave empty for next page). * @access public * @since 3.0.000 (2008-03-27) */ - public function startPageGroup($page='') { - if (empty($page)) { - $page = $this->page + 1; + public function startPageGroup($page='') { + if (empty($page)) { + $page = $this->page + 1; } $this->newpagegroup[$page] = true; } - + /** - * Defines an alias for the total number of pages. + * Defines an alias for the total number of pages. * It will be substituted as the document is closed. * @param string $alias The alias. * @access public @@ -9426,15 +9426,15 @@ public function AliasNbPages($alias='{nb}') { * @since 4.0.018 (2008-08-08) * @see AliasNbPages(), PageNo(), Footer() */ - public function getAliasNbPages() { + public function getAliasNbPages() { if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { return '{'.$this->AliasNbPages.'}'; } return $this->AliasNbPages; - } - + } + /** - * Defines an alias for the page number. + * Defines an alias for the page number. * It will be substituted as the document is closed. * @param string $alias The alias. * @access public @@ -9454,12 +9454,12 @@ public function AliasNumPage($alias='{pnb}') { * @since 4.5.000 (2009-01-02) * @see AliasNbPages(), PageNo(), Footer() */ - public function getAliasNumPage() { + public function getAliasNumPage() { if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { return '{'.$this->AliasNumPage.'}'; } return $this->AliasNumPage; - } + } /* * Return the current page in the group. @@ -9469,16 +9469,16 @@ public function getAliasNumPage() { */ public function getGroupPageNo() { return $this->pagegroups[$this->currpagegroup]; - } - + } + /** - * Returns the current group page number formatted as a string. + * Returns the current group page number formatted as a string. * @access public - * @since 4.3.003 (2008-11-18) + * @since 4.3.003 (2008-11-18) * @see PaneNo(), formatPageNumber() - */ - public function getGroupPageNoFormatted() { - return $this->formatPageNumber($this->getGroupPageNo()); + */ + public function getGroupPageNoFormatted() { + return $this->formatPageNumber($this->getGroupPageNo()); } /* @@ -9489,12 +9489,12 @@ public function getGroupPageNoFormatted() { * @access public * @since 3.0.000 (2008-03-27) */ - public function getPageGroupAlias() { + public function getPageGroupAlias() { if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { return '{'.$this->currpagegroup.'}'; } return $this->currpagegroup; - } + } /* * Return the alias for the page number on the current page group @@ -9504,46 +9504,46 @@ public function getPageGroupAlias() { * @access public * @since 4.5.000 (2009-01-02) */ - public function getPageNumGroupAlias() { + public function getPageNumGroupAlias() { if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { return '{'.str_replace('{nb', '{pnb', $this->currpagegroup).'}'; } return str_replace('{nb', '{pnb', $this->currpagegroup); - } - + } + /** - * Format the page numbers. + * Format the page numbers. * This method can be overriden for custom formats. - * @param int $num page number + * @param int $num page number * @access protected * @since 4.2.005 (2008-11-06) */ - protected function formatPageNumber($num) { - return number_format((float)$num, 0, '', '.'); - } - + protected function formatPageNumber($num) { + return number_format((float)$num, 0, '', '.'); + } + /** - * Format the page numbers on the Table Of Content. + * Format the page numbers on the Table Of Content. * This method can be overriden for custom formats. - * @param int $num page number + * @param int $num page number * @access protected - * @since 4.5.001 (2009-01-04) + * @since 4.5.001 (2009-01-04) * @see addTOC() */ - protected function formatTOCPageNumber($num) { - return number_format((float)$num, 0, '', '.'); - } - + protected function formatTOCPageNumber($num) { + return number_format((float)$num, 0, '', '.'); + } + /** - * Returns the current page number formatted as a string. + * Returns the current page number formatted as a string. * @access public - * @since 4.2.005 (2008-11-06) + * @since 4.2.005 (2008-11-06) * @see PaneNo(), formatPageNumber() */ - public function PageNoFormatted() { - return $this->formatPageNumber($this->PageNo()); - } - + public function PageNoFormatted() { + return $this->formatPageNumber($this->PageNo()); + } + /* * Put visibility settings. * @access protected @@ -9828,11 +9828,11 @@ public function CoonsPatchMesh($x, $y, $w, $h, $col1=array(), $col2=array(), $co } $bpcd = 65535; //16 BitsPerCoordinate //build the data stream - $this->gradients[$n]['stream'] = ''; + $this->gradients[$n]['stream'] = ''; $count_patch = count($patch_array); for ($i=0; $i < $count_patch; ++$i) { $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit - $count_points = count($patch_array[$i]['points']); + $count_points = count($patch_array[$i]['points']); for ($j=0; $j < $count_points; ++$j) { //each point as 16 bit $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd; @@ -9845,7 +9845,7 @@ public function CoonsPatchMesh($x, $y, $w, $h, $col1=array(), $col2=array(), $co $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256)); $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256)); } - $count_cols = count($patch_array[$i]['colors']); + $count_cols = count($patch_array[$i]['colors']); for ($j=0; $j < $count_cols; ++$j) { //each color component as 8 bit $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']); @@ -10058,7 +10058,7 @@ public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) { * @param mixed $link URL or identifier returned by AddLink(). * @param boolean useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be: - * @param string $palign Allows to center or align the image on the current line. Possible values are: + * @param string $palign Allows to center or align the image on the current line. Possible values are: * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:or a string containing some or all of the following characters (in any order): * @author Valentin Schmidt, Nicola Asuni * @since 3.1.000 (2008-06-09) @@ -10070,8 +10070,8 @@ public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBounding } if ($y === '') { $y = $this->y; - } - $k = $this->k; + } + $k = $this->k; $data = file_get_contents($file); if ($data === false) { $this->Error('EPS file not found: '.$file); @@ -10133,10 +10133,10 @@ public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBounding $w = ($x2 - $x1) / $k; $h = ($y2 - $y1) / $k; } - } - // Check whether we need a new page first as this does not fit - if ($this->checkPageBreak($h, $y)) { - $y = $this->GetY() + $this->cMargin; + } + // Check whether we need a new page first as this does not fit + if ($this->checkPageBreak($h, $y)) { + $y = $this->GetY() + $this->cMargin; } // set bottomcoordinates $this->img_rb_y = $y + $h; @@ -10185,8 +10185,8 @@ public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBounding if (isset($scale_x)) { $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y))); } - // handle pc/unix/mac line endings - preg_match('/[\r\n]+/s', $data, $regs); + // handle pc/unix/mac line endings + preg_match('/[\r\n]+/s', $data, $regs); $lines = explode($regs[0], $data); $u=0; $cnt = count($lines); @@ -10278,15 +10278,15 @@ public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBounding } } // restore previous graphic state - $this->_out($this->epsmarker.'Q'); - if (!empty($border)) { - $bx = $x; - $by = $y; - $this->x = $x; - $this->y = $y; - $this->Cell($w, $h, '', $border, 0, '', 0, '', 0); - $this->x = $bx; - $this->y = $by; + $this->_out($this->epsmarker.'Q'); + if (!empty($border)) { + $bx = $x; + $by = $y; + $this->x = $x; + $this->y = $y; + $this->Cell($w, $h, '', $border, 0, '', 0, '', 0); + $this->x = $bx; + $this->y = $by; } if ($link) { $this->Link($ximg, $y, $w, $h, $link, 0); @@ -10356,10 +10356,10 @@ public function getBarcode() { public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres=0.4, $style='', $align='') { if ($this->empty_string($code)) { return; - } - require_once(dirname(__FILE__).'/barcodes.php'); - // save current graphic settings - $gvars = $this->getGraphicVars(); + } + require_once(dirname(__FILE__).'/barcodes.php'); + // save current graphic settings + $gvars = $this->getGraphicVars(); // create new barcode object $barcodeobj = new TCPDFBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); @@ -10428,8 +10428,8 @@ public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres=0 if ($this->empty_string($h) OR ($h <= 0)) { $h = 10 + $extraspace; } - if ($this->checkPageBreak($h)) { - $y = $this->y; + if ($this->checkPageBreak($h)) { + $y = $this->y; } // maximum bar heigth $barh = $h - $extraspace; @@ -10503,7 +10503,7 @@ public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres=0 } // restore original direction $this->rtl = $tempRTL; - // restore previous settings + // restore previous settings $this->setGraphicVars($gvars); // set bottomcoordinates $this->img_rb_y = $y + $h; @@ -10590,8 +10590,8 @@ public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) $newstyle['stretchtext'] = 4; } $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, ''); - } - + } + /** * Print 2D Barcode. * @param string $code code to print @@ -10609,10 +10609,10 @@ public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='') { if ($this->empty_string($code)) { return; - } - require_once(dirname(__FILE__).'/2dbarcodes.php'); - // save current graphic settings - $gvars = $this->getGraphicVars(); + } + require_once(dirname(__FILE__).'/2dbarcodes.php'); + // save current graphic settings + $gvars = $this->getGraphicVars(); // create new barcode object $barcodeobj = new TCPDF2DBarcode($code, $type); $arrcode = $barcodeobj->getBarcodeArray(); @@ -10633,7 +10633,7 @@ public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style= $style['border'] = false; } // set foreground color - $this->SetDrawColorArray($style['fgcolor']); + $this->SetDrawColorArray($style['fgcolor']); if ($this->empty_string($x)) { $x = $this->GetX(); } @@ -10643,24 +10643,24 @@ public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style= if ($this->empty_string($y)) { $y = $this->GetY(); } - if ($this->empty_string($w) OR ($w <= 0)) { + if ($this->empty_string($w) OR ($w <= 0)) { if ($this->rtl) { $w = $x - $this->lMargin; } else { $w = $this->w - $this->rMargin - $x; } - } - if ($this->empty_string($h) OR ($h <= 0)) { - // 2d barcodes are square by default + } + if ($this->empty_string($h) OR ($h <= 0)) { + // 2d barcodes are square by default $h = $w; } - if ($this->checkPageBreak($h)) { - $y = $this->y; - } + if ($this->checkPageBreak($h)) { + $y = $this->y; + } // calculate barcode size (excluding padding) - $bw = $w - (2 * $style['padding']); - $bh = $h - (2 * $style['padding']); - // calculate starting coordinates + $bw = $w - (2 * $style['padding']); + $bh = $h - (2 * $style['padding']); + // calculate starting coordinates if ($this->rtl) { $xpos = $x - $w; } else { @@ -10668,9 +10668,9 @@ public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style= } $xpos += $style['padding']; $ypos = $y + $style['padding']; - // barcode is always printed in LTR direction + // barcode is always printed in LTR direction $tempRTL = $this->rtl; - $this->rtl = false; + $this->rtl = false; // print background color if ($style['bgcolor']) { $this->Rect($x, $y, $w, $h, 'DF', '', $style['bgcolor']); @@ -10678,29 +10678,29 @@ public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style= $this->Rect($x, $y, $w, $h, 'D'); } // print barcode cells - if ($arrcode !== false) { - $rows = $arrcode['num_rows']; - $cols = $arrcode['num_cols']; - // calculate dimension of single barcode cell - $cw = $bw / $cols; - $ch = $bh / $rows; + if ($arrcode !== false) { + $rows = $arrcode['num_rows']; + $cols = $arrcode['num_cols']; + // calculate dimension of single barcode cell + $cw = $bw / $cols; + $ch = $bh / $rows; // for each row - for ($r = 0; $r < $rows; ++$r) { - $xr = $xpos; + for ($r = 0; $r < $rows; ++$r) { + $xr = $xpos; // for each column for ($c = 0; $c < $cols; ++$c) { if ($arrcode['bcode'][$r][$c] == 1) { // draw a single barcode cell $this->Rect($xr, $ypos, $cw, $ch, 'F', array(), $style['fgcolor']); } - $xr += $cw; - } + $xr += $cw; + } $ypos += $ch; } } // restore original direction $this->rtl = $tempRTL; - // restore previous settings + // restore previous settings $this->setGraphicVars($gvars); // set bottomcoordinates $this->img_rb_y = $y + $h; @@ -10786,7 +10786,7 @@ public function getOriginalMargins() { /** * Returns the current font size. - * @return current font size + * @return current font size * @access public * @since 3.2.000 (2008-06-23) */ @@ -10796,33 +10796,33 @@ public function getFontSize() { /** * Returns the current font size in points unit. - * @return current font size in points unit + * @return current font size in points unit * @access public * @since 3.2.000 (2008-06-23) */ public function getFontSizePt() { return $this->FontSizePt; - } - + } + /** * Returns the current font family name. - * @return string current font family name + * @return string current font family name * @access public * @since 4.3.008 (2008-12-05) */ public function getFontFamily() { return $this->FontFamily; } - + /** * Returns the current font style. - * @return string current font style + * @return string current font style * @access public * @since 4.3.008 (2008-12-05) */ public function getFontStyle() { return $this->FontStyle; - } + } /** * Prints a cell (rectangular area) with optional borders, background color and html text string. @@ -10838,7 +10838,7 @@ public function getFontStyle() { Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. * @param boolean $reseth if true reset the last cell height (default true). - * @param string $align Allows to center or align the text. Possible values are: + * @param string $align Allows to center or align the text. Possible values are: * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width. * @access public * @uses MultiCell() @@ -10858,36 +10858,36 @@ public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill= */ protected function getHtmlDomArray($html) { // remove all unsupported tags (the line below lists all supported tags) - $html = strip_tags($html, '



      • '); - //replace some blank characters - $html = preg_replace('/



        '); + //replace some blank characters + $html = preg_replace('/
        ]*)>[\n\r\t]+/', '<\\1\\2>', $html);
        -			$html = preg_replace('@(\r\n|\r)@', "\n", $html);
        +			$html = preg_replace('@(\r\n|\r)@', "\n", $html);
         			$repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
        -			$html = strtr($html, $repTable);
        -			$offset = 0;
        -			while (($offset < strlen($html)) AND ($pos = strpos($html, '
        ', $offset)) !== false) { - $html_a = substr($html, 0, $offset); - $html_b = substr($html, $offset, ($pos - $offset + 6)); - while (preg_match("']*)>(.*?)\n(.*?)'si", $html_b)) { + $html = strtr($html, $repTable); + $offset = 0; + while (($offset < strlen($html)) AND ($pos = strpos($html, '', $offset)) !== false) { + $html_a = substr($html, 0, $offset); + $html_b = substr($html, $offset, ($pos - $offset + 6)); + while (preg_match("']*)>(.*?)\n(.*?)'si", $html_b)) { // preserve newlines on
         tag
         					$html_b = preg_replace("']*)>(.*?)\n(.*?)
        'si", "\\2
        \\3", $html_b); - } - $html = $html_a.$html_b.substr($html, $pos + 6); - $offset = strlen($html_a.$html_b); - } + } + $html = $html_a.$html_b.substr($html, $pos + 6); + $offset = strlen($html_a.$html_b); + } $html = str_replace("\n", ' ', $html); // remove extra spaces from code $html = preg_replace('/[\s]+<\/(table|tr|td|th|ul|ol|li)>/', '', $html); - $html = preg_replace('/[\s]+<(tr|td|th|ul|ol|li|br)/', '<\\1', $html); - $html = preg_replace('/<\/(table|tr|td|th|blockquote|dd|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|ul|p)>[\s]+<', $html); - $html = preg_replace('/<\/(td|th)>/', '', $html); - $html = preg_replace('/<\/table>([\s]*)/', '
      ', $html); - $html = preg_replace('/]*)>/xi', '', $html); - $html = preg_replace('/[\s]+<', $html); + $html = preg_replace('/<\/(td|th)>/', '', $html); + $html = preg_replace('/<\/table>([\s]*)/', '', $html); + $html = preg_replace('/]*)>/xi', '', $html); + $html = preg_replace('/FontSizePt; $dom[$key]['bgcolor'] = false; $dom[$key]['fgcolor'] = $this->fgcolor; - $dom[$key]['align'] = ''; - $dom[$key]['listtype'] = ''; + $dom[$key]['align'] = ''; + $dom[$key]['listtype'] = ''; $thead = false; // true when we are inside the THEAD tag ++$key; $level = array(); array_push($level, 0); // root while ($elkey < $maxel) { $dom[$key] = array(); - $element = $a[$elkey]; + $element = $a[$elkey]; $dom[$key]['elkey'] = $elkey; if (preg_match($tagpattern, $element)) { // html tag $element = substr($element, 1, -1); // get tag name preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag); - $tagname = strtolower($tag[1]); - // check if we are inside a table header - if ($tagname == 'thead') { - if ($element{0} == '/') { - $thead = false; - } else { - $thead = true; - } - ++$elkey; - continue; - } - $dom[$key]['tag'] = true; - $dom[$key]['value'] = $tagname; + $tagname = strtolower($tag[1]); + // check if we are inside a table header + if ($tagname == 'thead') { + if ($element{0} == '/') { + $thead = false; + } else { + $thead = true; + } + ++$elkey; + continue; + } + $dom[$key]['tag'] = true; + $dom[$key]['value'] = $tagname; if ($element{0} == '/') { // closing html tag $dom[$key]['opening'] = false; @@ -10947,32 +10947,32 @@ protected function getHtmlDomArray($html) { $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize']; $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor']; $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor']; - $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align']; - if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) { - $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype']; + $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align']; + if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) { + $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype']; } // set the number of columns in table tag if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) { $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols']; } if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) { - $dom[($dom[$key]['parent'])]['content'] = ''; + $dom[($dom[$key]['parent'])]['content'] = ''; for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) { $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']]; } $key = $i; - } - // store header rows on a new table - if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] == true)) { - if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) { - $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']]; - } - for ($i = $dom[$key]['parent']; $i <= $key; ++$i) { - $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']]; - } - } - if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) { - $dom[($dom[$key]['parent'])]['thead'] .= ''; + } + // store header rows on a new table + if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] == true)) { + if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) { + $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']]; + } + for ($i = $dom[$key]['parent']; $i <= $key; ++$i) { + $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']]; + } + } + if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) { + $dom[($dom[$key]['parent'])]['thead'] .= ''; } } else { // opening html tag @@ -10985,16 +10985,16 @@ protected function getHtmlDomArray($html) { } else { $dom[$key]['self'] = true; } - // copy some values from parent + // copy some values from parent $parentkey = 0; - if ($key > 0) { + if ($key > 0) { $parentkey = $dom[$key]['parent']; $dom[$key]['fontname'] = $dom[$parentkey]['fontname']; $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle']; $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize']; $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor']; $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor']; - $dom[$key]['align'] = $dom[$parentkey]['align']; + $dom[$key]['align'] = $dom[$parentkey]['align']; $dom[$key]['listtype'] = $dom[$parentkey]['listtype']; } // get attributes @@ -11005,7 +11005,7 @@ protected function getHtmlDomArray($html) { } // split style attributes if (isset($dom[$key]['attribute']['style'])) { - // get style attributes + // get style attributes preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER); $dom[$key]['style'] = array(); // reset style attribute array while (list($id, $name) = each($style_array[1])) { @@ -11017,66 +11017,66 @@ protected function getHtmlDomArray($html) { if (isset($dom[$key]['style']['font-family'])) { $fontslist = split(',', strtolower($dom[$key]['style']['font-family'])); foreach ($fontslist as $font) { - $font = trim(strtolower($font)); + $font = trim(strtolower($font)); if (in_array($font, $this->fontlist) OR in_array($font, $this->fontkeys)) { $dom[$key]['fontname'] = $font; break; } } } - } - // list-style-type - if (isset($dom[$key]['style']['list-style-type'])) { - $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type'])); - if ($dom[$key]['listtype'] == 'inherit') { - $dom[$key]['listtype'] = $dom[$parentkey]['listtype']; - } + } + // list-style-type + if (isset($dom[$key]['style']['list-style-type'])) { + $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type'])); + if ($dom[$key]['listtype'] == 'inherit') { + $dom[$key]['listtype'] = $dom[$parentkey]['listtype']; + } } // font size if (isset($dom[$key]['style']['font-size'])) { - $fsize = trim($dom[$key]['style']['font-size']); - switch ($fsize) { - // absolute-size - case 'xx-small': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4; - break; - } - case 'x-small': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3; - break; - } - case 'small': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2; - break; - } - case 'medium': { - $dom[$key]['fontsize'] = $dom[0]['fontsize']; - break; - } - case 'large': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2; - break; - } - case 'x-large': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4; - break; - } - case 'xx-large': { - $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6; - break; - } - // relative-size - case 'smaller': { - $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3; - break; - } - case 'larger': { - $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3; - break; - } - default: { - $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true); - } + $fsize = trim($dom[$key]['style']['font-size']); + switch ($fsize) { + // absolute-size + case 'xx-small': { + $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4; + break; + } + case 'x-small': { + $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3; + break; + } + case 'small': { + $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2; + break; + } + case 'medium': { + $dom[$key]['fontsize'] = $dom[0]['fontsize']; + break; + } + case 'large': { + $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2; + break; + } + case 'x-large': { + $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4; + break; + } + case 'xx-large': { + $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6; + break; + } + // relative-size + case 'smaller': { + $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3; + break; + } + case 'larger': { + $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3; + break; + } + default: { + $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true); + } } } // font style @@ -11085,28 +11085,28 @@ protected function getHtmlDomArray($html) { } if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) { $dom[$key]['fontstyle'] .= '"I'; - } - // font color - if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) { - $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']); - } - // background color - if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) { - $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']); - } - // text-decoration - if (isset($dom[$key]['style']['text-decoration'])) { - $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration'])); - foreach ($decors as $dec) { - $dec = trim($dec); - if (!$this->empty_string($dec)) { - if ($dec{0} == 'u') { - $dom[$key]['fontstyle'] .= 'U'; - } elseif ($dec{0} == 'l') { - $dom[$key]['fontstyle'] .= 'D'; - } - } - } + } + // font color + if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) { + $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']); + } + // background color + if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) { + $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']); + } + // text-decoration + if (isset($dom[$key]['style']['text-decoration'])) { + $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration'])); + foreach ($decors as $dec) { + $dec = trim($dec); + if (!$this->empty_string($dec)) { + if ($dec{0} == 'u') { + $dom[$key]['fontstyle'] .= 'U'; + } elseif ($dec{0} == 'l') { + $dom[$key]['fontstyle'] .= 'D'; + } + } + } } // check for width attribute if (isset($dom[$key]['style']['width'])) { @@ -11119,7 +11119,7 @@ protected function getHtmlDomArray($html) { // check for text alignment if (isset($dom[$key]['style']['text-align'])) { $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0}); - } + } // check for border attribute if (isset($dom[$key]['style']['border'])) { $dom[$key]['attribute']['border'] = $dom[$key]['style']['border']; @@ -11152,9 +11152,9 @@ protected function getHtmlDomArray($html) { $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']); } } - } + } // force natural alignment for lists - if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl')) + if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl')) AND (!isset($dom[$key]['align']) OR $this->empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) { if ($this->rtl) { $dom[$key]['align'] = 'R'; @@ -11170,15 +11170,15 @@ protected function getHtmlDomArray($html) { } if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) { $dom[$key]['fontstyle'] .= 'I'; - } + } if ($dom[$key]['value'] == 'u') { $dom[$key]['fontstyle'] .= 'U'; - } + } if ($dom[$key]['value'] == 'del') { $dom[$key]['fontstyle'] .= 'D'; - } - if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) { - $dom[$key]['fontname'] = $this->default_monospaced_font; + } + if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) { + $dom[$key]['fontname'] = $this->default_monospaced_font; } if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) { $headsize = (4 - intval($dom[$key]['value']{1})) * 2; @@ -11187,7 +11187,7 @@ protected function getHtmlDomArray($html) { } if (($dom[$key]['value'] == 'table')) { $dom[$key]['rows'] = 0; // number of rows - $dom[$key]['trids'] = array(); // IDs of TR elements + $dom[$key]['trids'] = array(); // IDs of TR elements $dom[$key]['thead'] = ''; // table header rows } if (($dom[$key]['value'] == 'tr')) { @@ -11195,11 +11195,11 @@ protected function getHtmlDomArray($html) { // store the number of rows on table element ++$dom[($dom[$key]['parent'])]['rows']; // store the TR elements IDs on table element - array_push($dom[($dom[$key]['parent'])]['trids'], $key); - if ($thead) { - $dom[$key]['thead'] = true; - } else { - $dom[$key]['thead'] = false; + array_push($dom[($dom[$key]['parent'])]['trids'], $key); + if ($thead) { + $dom[$key]['thead'] = true; + } else { + $dom[$key]['thead'] = false; } } if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) { @@ -11237,15 +11237,15 @@ protected function getHtmlDomArray($html) { $dom[$key]['tag'] = false; $dom[$key]['value'] = stripslashes($this->unhtmlentities($element)); $dom[$key]['parent'] = end($level); - } + } ++$elkey; ++$key; } return $dom; - } + } /** - * Allows to preserve some HTML formatting (limited support).
      + * Allows to preserve some HTML formatting (limited support).
      * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting. * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul * @param string $html text to display @@ -11256,12 +11256,12 @@ protected function getHtmlDomArray($html) { * @param string $align Allows to center or align the text. Possible values are:
      • L : left align
      • C : center
      • R : right align
      • '' : empty string : left for LTR or right for RTL
      * @access public */ - public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') { + public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') { $gvars = $this->getGraphicVars(); - // store current values - $prevPage = $this->page; + // store current values + $prevPage = $this->page; $prevlMargin = $this->lMargin; - $prevrMargin = $this->rMargin; + $prevrMargin = $this->rMargin; $curfontname = $this->FontFamily; $curfontstyle = $this->FontStyle; $curfontsize = $this->FontSizePt; @@ -11269,24 +11269,24 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $minstartliney = $this->y; $yshift = 0; $startlinepage = $this->page; - $newline = true; - $loop = 0; - $curpos = 0; - $blocktags = array('blockquote','br','dd','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','ul','tcpdf'); - $this->premode = false; - if (isset($this->PageAnnots[$this->page])) { - $pask = count($this->PageAnnots[$this->page]); - } else { - $pask = 0; + $newline = true; + $loop = 0; + $curpos = 0; + $blocktags = array('blockquote','br','dd','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','ul','tcpdf'); + $this->premode = false; + if (isset($this->PageAnnots[$this->page])) { + $pask = count($this->PageAnnots[$this->page]); + } else { + $pask = 0; } if (isset($this->footerlen[$this->page])) { $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page]; } else { $this->footerpos[$this->page] = $this->pagelen[$this->page]; - } + } $startlinepos = $this->footerpos[$this->page]; $lalign = $align; - $plalign = $align; + $plalign = $align; if ($this->rtl) { $w = $this->x - $this->lMargin; } else { @@ -11299,11 +11299,11 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal } else { $this->x += $this->cMargin; } - } - if ($this->customlistindent >= 0) { - $this->listindent = $this->customlistindent; + } + if ($this->customlistindent >= 0) { + $this->listindent = $this->customlistindent; } else { - $this->listindent = $this->GetStringWidth('0000'); + $this->listindent = $this->GetStringWidth('0000'); } $this->listnum = 0; if (($this->empty_string($this->lasth)) OR ($reseth)) { @@ -11314,60 +11314,60 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $maxel = count($dom); $key = 0; while ($key < $maxel) { - if ($dom[$key]['tag'] OR ($key == 0)) { - if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) { - $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L'; - } - // vertically align image in line - if ((!$this->newline) - AND ($dom[$key]['value'] == 'img') - AND (isset($dom[$key]['attribute']['height'])) - AND ($dom[$key]['attribute']['height'] > 0)) { - // get image height - $imgh = $this->getHTMLUnitToUnits($dom[$key]['attribute']['height'], $this->lasth, 'px'); - if (!$this->InFooter) { - // check for page break - $this->checkPageBreak($imgh); - } - if ($this->page > $startlinepage) { - // fix lines splitted over two pages - if (isset($this->footerlen[$startlinepage])) { + if ($dom[$key]['tag'] OR ($key == 0)) { + if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) { + $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L'; + } + // vertically align image in line + if ((!$this->newline) + AND ($dom[$key]['value'] == 'img') + AND (isset($dom[$key]['attribute']['height'])) + AND ($dom[$key]['attribute']['height'] > 0)) { + // get image height + $imgh = $this->getHTMLUnitToUnits($dom[$key]['attribute']['height'], $this->lasth, 'px'); + if (!$this->InFooter) { + // check for page break + $this->checkPageBreak($imgh); + } + if ($this->page > $startlinepage) { + // fix lines splitted over two pages + if (isset($this->footerlen[$startlinepage])) { $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; - } - // line to be moved one page forward - $pagebuff = $this->getPageBuffer($startlinepage); - $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos)); - $tstart = substr($pagebuff, 0, $startlinepos); - $tend = substr($this->getPageBuffer($startlinepage), $curpos); - // remove line start from previous page - $this->setPageBuffer($startlinepage, $tstart.''.$tend); - $pagebuff = $this->getPageBuffer($this->page); - $tstart = substr($pagebuff, 0, $this->intmrk[$this->page]); - $tend = substr($pagebuff, $this->intmrk[$this->page]); - // add line start to current page - $yshift = $minstartliney - $this->y; - $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k)); - $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend); + } + // line to be moved one page forward + $pagebuff = $this->getPageBuffer($startlinepage); + $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos)); + $tstart = substr($pagebuff, 0, $startlinepos); + $tend = substr($this->getPageBuffer($startlinepage), $curpos); + // remove line start from previous page + $this->setPageBuffer($startlinepage, $tstart.''.$tend); + $pagebuff = $this->getPageBuffer($this->page); + $tstart = substr($pagebuff, 0, $this->intmrk[$this->page]); + $tend = substr($pagebuff, $this->intmrk[$this->page]); + // add line start to current page + $yshift = $minstartliney - $this->y; + $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k)); + $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend); // shift the annotations and links if (isset($this->PageAnnots[$startlinepage])) { foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) { - if ($pak >= $pask) { - $this->PageAnnots[$this->page][] = $pac; - unset($this->PageAnnots[$startlinepage][$pak]); + if ($pak >= $pask) { + $this->PageAnnots[$this->page][] = $pac; + unset($this->PageAnnots[$startlinepage][$pak]); $npak = count($this->PageAnnots[$this->page]) - 1; $this->PageAnnots[$this->page][$npak]['y'] -= $yshift; } } - } - $startlinepos = $this->intmrk[$this->page]; - $startlinepage = $this->page; - $startliney = $this->y; - } - + } + $startlinepos = $this->intmrk[$this->page]; + $startlinepage = $this->page; + $startliney = $this->y; + } + $this->y += (($curfontsize / $this->k) - $imgh); - $minstartliney = min($this->y, $minstartliney); - - } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize'])) { + $minstartliney = min($this->y, $minstartliney); + + } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize'])) { // account for different font size $pfontname = $curfontname; $pfontstyle = $curfontstyle; @@ -11375,45 +11375,45 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $fontname = isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname; $fontstyle = isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle; $fontsize = isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize; - if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)) { - $this->SetFont($fontname, $fontstyle, $fontsize); + if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)) { + $this->SetFont($fontname, $fontstyle, $fontsize); $this->lasth = $this->FontSize * $this->cell_height_ratio; - if (is_numeric($fontsize) AND ($fontsize > 0) - AND is_numeric($curfontsize) AND ($curfontsize > 0) - AND ($fontsize != $curfontsize) AND (!$this->newline) - AND ($key < ($maxel - 1)) - ) { - if ((!$this->newline) AND ($this->page > $startlinepage)) { - // fix lines splitted over two pages - if (isset($this->footerlen[$startlinepage])) { + if (is_numeric($fontsize) AND ($fontsize > 0) + AND is_numeric($curfontsize) AND ($curfontsize > 0) + AND ($fontsize != $curfontsize) AND (!$this->newline) + AND ($key < ($maxel - 1)) + ) { + if ((!$this->newline) AND ($this->page > $startlinepage)) { + // fix lines splitted over two pages + if (isset($this->footerlen[$startlinepage])) { $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; - } - // line to be moved one page forward - $pagebuff = $this->getPageBuffer($startlinepage); - $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos)); - $tstart = substr($pagebuff, 0, $startlinepos); - $tend = substr($this->getPageBuffer($startlinepage), $curpos); - // remove line start from previous page - $this->setPageBuffer($startlinepage, $tstart.''.$tend); - $pagebuff = $this->getPageBuffer($this->page); - $tstart = substr($pagebuff, 0, $this->intmrk[$this->page]); - $tend = substr($pagebuff, $this->intmrk[$this->page]); - // add line start to current page - $yshift = $minstartliney - $this->y; - $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k)); - $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend); + } + // line to be moved one page forward + $pagebuff = $this->getPageBuffer($startlinepage); + $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos)); + $tstart = substr($pagebuff, 0, $startlinepos); + $tend = substr($this->getPageBuffer($startlinepage), $curpos); + // remove line start from previous page + $this->setPageBuffer($startlinepage, $tstart.''.$tend); + $pagebuff = $this->getPageBuffer($this->page); + $tstart = substr($pagebuff, 0, $this->intmrk[$this->page]); + $tend = substr($pagebuff, $this->intmrk[$this->page]); + // add line start to current page + $yshift = $minstartliney - $this->y; + $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k)); + $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend); // shift the annotations and links if (isset($this->PageAnnots[$startlinepage])) { foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) { - if ($pak >= $pask) { - $this->PageAnnots[$this->page][] = $pac; - unset($this->PageAnnots[$startlinepage][$pak]); + if ($pak >= $pask) { + $this->PageAnnots[$this->page][] = $pac; + unset($this->PageAnnots[$startlinepage][$pak]); $npak = count($this->PageAnnots[$this->page]) - 1; $this->PageAnnots[$this->page][$npak]['y'] -= $yshift; } } - } - } + } + } $this->y += (($curfontsize - $fontsize) / $this->k); $minstartliney = min($this->y, $minstartliney); } @@ -11421,11 +11421,11 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $curfontstyle = $fontstyle; $curfontsize = $fontsize; } - } - if (($plalign == 'J') AND (in_array($dom[$key]['value'], $blocktags))) { - $plalign = ''; - } - // get current position on page buffer + } + if (($plalign == 'J') AND (in_array($dom[$key]['value'], $blocktags))) { + $plalign = ''; + } + // get current position on page buffer $curpos = $this->pagelen[$startlinepage]; if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) { $this->SetFillColorArray($dom[$key]['bgcolor']); @@ -11444,22 +11444,22 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal } } // align lines - if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) { + if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) { $newline = true; - // we are at the beginning of a new line + // we are at the beginning of a new line if (isset($startlinex)) { $yshift = $minstartliney - $startliney; if (($yshift > 0) OR ($this->page > $startlinepage)) { $yshift = 0; } if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl))))) OR ($yshift < 0)) { - // the last line must be shifted to be aligned as requested - $linew = abs($this->endlinex - $startlinex); + // the last line must be shifted to be aligned as requested + $linew = abs($this->endlinex - $startlinex); $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos); if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) { $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; $midpos = min($opentagpos, $this->footerpos[$startlinepage]); - } elseif (isset($opentagpos)) { + } elseif (isset($opentagpos)) { $midpos = $opentagpos; } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) { $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage]; @@ -11473,16 +11473,16 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal } else { $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos); $pend = ''; - } - // calculate shifting amount - $tw = $w; + } + // calculate shifting amount + $tw = $w; if ($this->lMargin != $prevlMargin) { - $tw += ($prevlMargin - $this->lMargin); + $tw += ($prevlMargin - $this->lMargin); } if ($this->rMargin != $prevrMargin) { - $tw += ($prevrMargin - $this->rMargin); + $tw += ($prevrMargin - $this->rMargin); } - $mdiff = abs($tw - $linew); + $mdiff = abs($tw - $linew); $t_x = 0; if ($plalign == 'C') { if ($this->rtl) { @@ -11497,169 +11497,169 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal // left alignment on RTL document $t_x = -$mdiff; } elseif (($plalign == 'J') AND ($plalign == $lalign)) { - // Justification - if ($this->rtl OR $this->tmprtl) { + // Justification + if ($this->rtl OR $this->tmprtl) { $t_x = $this->lMargin - $this->endlinex; - } - $no = 0; - $ns = 0; - $pmidtemp = $pmid; - // escape special characters - $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp); - $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp); - // search spaces - if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) { - $maxkk = count($lnstring[1]) - 1; - for ($kk=0; $kk <= $maxkk; ++$kk) { - // restore special characters - $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]); - $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]); - if ($kk == $maxkk) { - if ($this->rtl OR $this->tmprtl) { - $tvalue = ltrim($lnstring[1][$kk]); - } else { - $tvalue = rtrim($lnstring[1][$kk]); - } - } else { - $tvalue = $lnstring[1][$kk]; - } - // count spaces on line - $no += substr_count($lnstring[1][$kk], chr(32)); - $ns += substr_count($tvalue, chr(32)); - } - if ($this->rtl OR $this->tmprtl) { + } + $no = 0; + $ns = 0; + $pmidtemp = $pmid; + // escape special characters + $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp); + $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp); + // search spaces + if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) { + $maxkk = count($lnstring[1]) - 1; + for ($kk=0; $kk <= $maxkk; ++$kk) { + // restore special characters + $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]); + $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]); + if ($kk == $maxkk) { + if ($this->rtl OR $this->tmprtl) { + $tvalue = ltrim($lnstring[1][$kk]); + } else { + $tvalue = rtrim($lnstring[1][$kk]); + } + } else { + $tvalue = $lnstring[1][$kk]; + } + // count spaces on line + $no += substr_count($lnstring[1][$kk], chr(32)); + $ns += substr_count($tvalue, chr(32)); + } + if ($this->rtl OR $this->tmprtl) { $t_x = $this->lMargin - $this->endlinex - (($no - $ns - 1) * $this->GetStringWidth(chr(32))); - } - // calculate additional space to add to each space - $spacewidth = (($tw - $linew + (($no - $ns) * $this->GetStringWidth(chr(32)))) / ($ns?$ns:1)) * $this->k; - $spacewidthu = ($tw - $linew + ($no * $this->GetStringWidth(chr(32)))) / ($ns?$ns:1) / $this->FontSize / $this->k; - $nsmax = $ns; - $ns = 0; - reset($lnstring); - $offset = 0; - $strcount = 0; - $prev_epsposbeg = 0; - global $spacew; - while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) { - if ($this->rtl OR $this->tmprtl) { + } + // calculate additional space to add to each space + $spacewidth = (($tw - $linew + (($no - $ns) * $this->GetStringWidth(chr(32)))) / ($ns?$ns:1)) * $this->k; + $spacewidthu = ($tw - $linew + ($no * $this->GetStringWidth(chr(32)))) / ($ns?$ns:1) / $this->FontSize / $this->k; + $nsmax = $ns; + $ns = 0; + reset($lnstring); + $offset = 0; + $strcount = 0; + $prev_epsposbeg = 0; + global $spacew; + while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) { + if ($this->rtl OR $this->tmprtl) { $spacew = ($spacewidth * ($nsmax - $ns)); - } else { - $spacew = ($spacewidth * $ns); - } - $offset = $strpiece[2][1] + strlen($strpiece[2][0]); - $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset); - $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q'); - if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) - OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) { - // shift EPS images - $trx = sprintf('1 0 0 1 %.3F 0 cm', $spacew); - $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6)); - $pmid_b = substr($pmid, 0, $epsposbeg); - $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg)); - $pmid_e = substr($pmid, $epsposend); - $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e; - $offset = $epsposend; - continue; - } - $prev_epsposbeg = $epsposbeg; - $currentxpos = 0; - // shift blocks of code - switch ($strpiece[2][0]) { - case 'Td': - case 'cm': - case 'm': - case 'l': { - // get current X position - preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); - $currentxpos = $xmatches[1]; - if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) { - if ($strcount == $maxkk) { - if ($this->rtl OR $this->tmprtl) { + } else { + $spacew = ($spacewidth * $ns); + } + $offset = $strpiece[2][1] + strlen($strpiece[2][0]); + $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset); + $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q'); + if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) + OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) { + // shift EPS images + $trx = sprintf('1 0 0 1 %.3F 0 cm', $spacew); + $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6)); + $pmid_b = substr($pmid, 0, $epsposbeg); + $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg)); + $pmid_e = substr($pmid, $epsposend); + $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e; + $offset = $epsposend; + continue; + } + $prev_epsposbeg = $epsposbeg; + $currentxpos = 0; + // shift blocks of code + switch ($strpiece[2][0]) { + case 'Td': + case 'cm': + case 'm': + case 'l': { + // get current X position + preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); + $currentxpos = $xmatches[1]; + if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) { + if ($strcount == $maxkk) { + if ($this->rtl OR $this->tmprtl) { $tvalue = $lnstring[1][$strcount]; } else { $tvalue = rtrim($lnstring[1][$strcount]); - } - } else { - $tvalue = $lnstring[1][$strcount]; - } - $ns += substr_count($tvalue, chr(32)); - ++$strcount; - } - if ($this->rtl OR $this->tmprtl) { + } + } else { + $tvalue = $lnstring[1][$strcount]; + } + $ns += substr_count($tvalue, chr(32)); + ++$strcount; + } + if ($this->rtl OR $this->tmprtl) { $spacew = ($spacewidth * ($nsmax - $ns)); - } - // justify block - $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', - create_function('$matches', 'global $spacew; - $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew)); - return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1); - break; - } - case 're': { - // get current X position - preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); - $currentxpos = $xmatches[1]; - // justify block - $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', - create_function('$matches', 'global $spacew; - $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew)); - return "".$newx." ".$matches[2]." ".$matches[3]." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1); - break; - } - case 'c': { - // get current X position - preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); - $currentxpos = $xmatches[1]; - // justify block - $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', - create_function('$matches', 'global $spacew; - $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew)); - $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew)); - $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew)); - return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1); - break; - } - } - // shift the annotations and links + } + // justify block + $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', + create_function('$matches', 'global $spacew; + $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew)); + return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1); + break; + } + case 're': { + // get current X position + preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); + $currentxpos = $xmatches[1]; + // justify block + $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', + create_function('$matches', 'global $spacew; + $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew)); + return "".$newx." ".$matches[2]." ".$matches[3]." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1); + break; + } + case 'c': { + // get current X position + preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches); + $currentxpos = $xmatches[1]; + // justify block + $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', + create_function('$matches', 'global $spacew; + $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew)); + $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew)); + $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew)); + return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1); + break; + } + } + // shift the annotations and links if (isset($this->PageAnnots[$this->page])) { foreach ($this->PageAnnots[$this->page] as $pak => $pac) { - if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) { - $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k); - $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k); + if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) { + $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k); + $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k); break; } } - } - } // end of while - // remove markers - $pmid = str_replace('x*#!#*x', '', $pmid); - if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { - // multibyte characters - $spacew = $spacewidthu; - $pmidtemp = $pmid; - // escape special characters - $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp); - $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp); - $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x", - create_function('$matches', 'global $spacew; - $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]); - $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]); - return "[(".str_replace(chr(0).chr(32), ") ".(-2830 * $spacew)." (", $matches[1]).")]";'), $pmidtemp); - $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend); - $endlinepos = strlen($pstart."\n".$pmid."\n"); - } else { - // non-unicode (single-byte characters) - $rs = sprintf("%.3F Tw", $spacewidth); - $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid); - $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend); - $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n"); - } + } + } // end of while + // remove markers + $pmid = str_replace('x*#!#*x', '', $pmid); + if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { + // multibyte characters + $spacew = $spacewidthu; + $pmidtemp = $pmid; + // escape special characters + $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp); + $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp); + $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x", + create_function('$matches', 'global $spacew; + $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]); + $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]); + return "[(".str_replace(chr(0).chr(32), ") ".(-2830 * $spacew)." (", $matches[1]).")]";'), $pmidtemp); + $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend); + $endlinepos = strlen($pstart."\n".$pmid."\n"); + } else { + // non-unicode (single-byte characters) + $rs = sprintf("%.3F Tw", $spacewidth); + $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid); + $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend); + $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n"); + } } - } // end of J + } // end of J if (($t_x != 0) OR ($yshift < 0)) { // shift the line $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k)); - $this->setPageBuffer($startlinepage, $pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend); + $this->setPageBuffer($startlinepage, $pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend); $endlinepos = strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n"); // shift the annotations and links if (isset($this->PageAnnots[$this->page])) { @@ -11673,9 +11673,9 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $this->y -= $yshift; } } - } - $this->newline = false; - $pbrk = $this->checkPageBreak($this->lasth); + } + $this->newline = false; + $pbrk = $this->checkPageBreak($this->lasth); $this->SetFont($fontname, $fontstyle, $fontsize); if ($wfill) { $this->SetFillColorArray($this->bgcolor); @@ -11690,36 +11690,36 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal } else { if (isset($this->footerlen[$this->page])) { $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page]; - } else { + } else { $this->footerpos[$this->page] = $this->pagelen[$this->page]; - } + } $startlinepos = $this->footerpos[$this->page]; } - $plalign = $lalign; - if (isset($this->PageAnnots[$this->page])) { - $pask = count($this->PageAnnots[$this->page]); - } else { - $pask = 0; + $plalign = $lalign; + if (isset($this->PageAnnots[$this->page])) { + $pask = count($this->PageAnnots[$this->page]); + } else { + $pask = 0; } } if (isset($opentagpos)) { unset($opentagpos); } if ($dom[$key]['tag']) { - if ($dom[$key]['opening']) { - if ($dom[$key]['value'] == 'table') { + if ($dom[$key]['opening']) { + if ($dom[$key]['value'] == 'table') { if ($this->rtl) { $wtmp = $this->x - $this->lMargin; } else { $wtmp = $this->w - $this->rMargin - $this->x; - } - $wtmp -= (2 * $this->cMargin); + } + $wtmp -= (2 * $this->cMargin); // calculate cell width if (isset($dom[$key]['width'])) { $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px'); } else { $table_width = $wtmp; - } + } } // table content is handled in a special way if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) { @@ -11727,7 +11727,7 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $table_el = $dom[$trid]['parent']; if (!isset($dom[$table_el]['cols'])) { $dom[$table_el]['cols'] = $trid['cols']; - } + } $oldmargin = $this->cMargin; if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) { $currentcmargin = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px'); @@ -11746,19 +11746,19 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $cellspacingx = $cellspacing; } $colspan = $dom[$key]['attribute']['colspan']; - $wtmp = ($colspan * ($table_width / $dom[$table_el]['cols'])); + $wtmp = ($colspan * ($table_width / $dom[$table_el]['cols'])); if (isset($dom[$key]['width'])) { $cellw = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px'); } else { $cellw = $wtmp; - } - if (isset($dom[$key]['height'])) { + } + if (isset($dom[$key]['height'])) { // minimum cell height $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px'); } else { $cellh = 0; } - $cellw -= $cellspacing; + $cellw -= $cellspacing; if (isset($dom[$key]['content'])) { $cell_content = $dom[$key]['content']; } else { @@ -11779,7 +11779,7 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $dom[$trid]['starty'] = $this->y; } else { $this->y = $dom[$trid]['starty']; - } + } if (!isset($dom[$trid]['startx'])) { $dom[$trid]['startx'] = $this->x; } @@ -11790,42 +11790,42 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $rowspan = 1; } // skip row-spanned cells started on the previous rows - if (isset($dom[$table_el]['rowspans'])) { - $rsk = 0; - $rskmax = count($dom[$table_el]['rowspans']); - while ($rsk < $rskmax) { - $trwsp = $dom[$table_el]['rowspans'][$rsk]; - $rsstartx = $trwsp['startx']; - $rsendx = $trwsp['endx']; - // account for margin changes - if ($trwsp['startpage'] < $this->page) { - if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) { - $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']); - $rsstartx -= $dl; - $rsendx -= $dl; - } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) { - $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']); - $rsstartx += $dl; - $rsendx += $dl; - } + if (isset($dom[$table_el]['rowspans'])) { + $rsk = 0; + $rskmax = count($dom[$table_el]['rowspans']); + while ($rsk < $rskmax) { + $trwsp = $dom[$table_el]['rowspans'][$rsk]; + $rsstartx = $trwsp['startx']; + $rsendx = $trwsp['endx']; + // account for margin changes + if ($trwsp['startpage'] < $this->page) { + if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) { + $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']); + $rsstartx -= $dl; + $rsendx -= $dl; + } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) { + $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']); + $rsstartx += $dl; + $rsendx += $dl; + } } - if (($trwsp['rowspan'] > 0) - AND ($rsstartx > ($this->x - $cellspacing - $currentcmargin - $this->feps)) - AND ($rsstartx < ($this->x + $cellspacing + $currentcmargin + $this->feps)) - AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page))) { + if (($trwsp['rowspan'] > 0) + AND ($rsstartx > ($this->x - $cellspacing - $currentcmargin - $this->feps)) + AND ($rsstartx < ($this->x + $cellspacing + $currentcmargin + $this->feps)) + AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page))) { // set the starting X position of the current cell - $this->x = $rsendx + $cellspacingx; - if (($trwsp['rowspan'] == 1) - AND (isset($dom[$trid]['endy'])) - AND (isset($dom[$trid]['endpage'])) - AND ($trwsp['endpage'] == $dom[$trid]['endpage'])) { - // set ending Y position for row - $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']); - $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy']; - } + $this->x = $rsendx + $cellspacingx; + if (($trwsp['rowspan'] == 1) + AND (isset($dom[$trid]['endy'])) + AND (isset($dom[$trid]['endpage'])) + AND ($trwsp['endpage'] == $dom[$trid]['endpage'])) { + // set ending Y position for row + $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']); + $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy']; + } $rsk = 0; - } else { - ++$rsk; + } else { + ++$rsk; } } } @@ -11833,9 +11833,9 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal if ($rowspan > 1) { if (isset($this->footerlen[$this->page])) { $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page]; - } else { + } else { $this->footerpos[$this->page] = $this->pagelen[$this->page]; - } + } $trintmrkpos = $this->footerpos[$this->page]; $trsid = array_push($dom[$table_el]['rowspans'], array('trid' => $trid, 'rowspan' => $rowspan, 'mrowspan' => $rowspan, 'colspan' => $colspan, 'startpage' => $this->page, 'startx' => $this->x, 'starty' => $this->y, 'intmrkpos' => $trintmrkpos)); } @@ -11846,15 +11846,15 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal // push background colors if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) { $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor']; - } - $prevLastH = $this->lasth; + } + $prevLastH = $this->lasth; // ****** write the cell content ****** - $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true); - $this->lasth = $prevLastH; + $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true); + $this->lasth = $prevLastH; $this->cMargin = $oldmargin; $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x; - // update the end of row position - if ($rowspan <= 1) { + // update the end of row position + if ($rowspan <= 1) { if (isset($dom[$trid]['endy'])) { if ($this->page == $dom[$trid]['endpage']) { $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']); @@ -11863,29 +11863,29 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal } } else { $dom[$trid]['endy'] = $this->y; - } + } if (isset($dom[$trid]['endpage'])) { $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']); } else { $dom[$trid]['endpage'] = $this->page; - } - } else { + } + } else { // account for row-spanned cells $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x; $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y; $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page; } - if (isset($dom[$table_el]['rowspans'])) { + if (isset($dom[$table_el]['rowspans'])) { // update endy and endpage on rowspanned cells foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) { - if ($trwsp['rowspan'] > 0) { - if (isset($dom[$trid]['endpage'])) { - if ($trwsp['endpage'] == $dom[$trid]['endpage']) { + if ($trwsp['rowspan'] > 0) { + if (isset($dom[$trid]['endpage'])) { + if ($trwsp['endpage'] == $dom[$trid]['endpage']) { $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']); - } elseif ($trwsp['endpage'] < $dom[$trid]['endpage']) { + } elseif ($trwsp['endpage'] < $dom[$trid]['endpage']) { $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy']; $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage']; - } else { + } else { $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm']; } } @@ -11895,14 +11895,14 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $this->x += ($cellspacingx / 2); } else { // opening tag (or self-closing tag) - if (!isset($opentagpos)) { + if (!isset($opentagpos)) { if (!$this->InFooter) { if (isset($this->footerlen[$this->page])) { $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page]; } else { $this->footerpos[$this->page] = $this->pagelen[$this->page]; - } - $opentagpos = $this->footerpos[$this->page]; + } + $opentagpos = $this->footerpos[$this->page]; } } $this->openHTMLTagHandler($dom, $key, $cell); @@ -11916,7 +11916,7 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal if (!$this->empty_string($this->lispacer)) { $this->SetFont($pfontname, $pfontstyle, $pfontsize); $this->lasth = $this->FontSize * $this->cell_height_ratio; - $minstartliney = $this->y; + $minstartliney = $this->y; $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize); $this->SetFont($curfontname, $curfontstyle, $curfontsize); $this->lasth = $this->FontSize * $this->cell_height_ratio; @@ -11926,35 +11926,35 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal } } // text - $this->htmlvspace = 0; - if ((!$this->premode) AND ($this->rtl OR $this->tmprtl)) { - // reverse spaces order - $len1 = strlen($dom[$key]['value']); - $lsp = $len1 - strlen(ltrim($dom[$key]['value'])); - $rsp = $len1 - strlen(rtrim($dom[$key]['value'])); - $tmpstr = ''; - if ($rsp > 0) { - $tmpstr .= substr($dom[$key]['value'], -$rsp); - } - $tmpstr .= trim($dom[$key]['value']); - if ($lsp > 0) { - $tmpstr .= substr($dom[$key]['value'], 0, $lsp); - } - $dom[$key]['value'] = $tmpstr; - } - if ($newline) { + $this->htmlvspace = 0; + if ((!$this->premode) AND ($this->rtl OR $this->tmprtl)) { + // reverse spaces order + $len1 = strlen($dom[$key]['value']); + $lsp = $len1 - strlen(ltrim($dom[$key]['value'])); + $rsp = $len1 - strlen(rtrim($dom[$key]['value'])); + $tmpstr = ''; + if ($rsp > 0) { + $tmpstr .= substr($dom[$key]['value'], -$rsp); + } + $tmpstr .= trim($dom[$key]['value']); + if ($lsp > 0) { + $tmpstr .= substr($dom[$key]['value'], 0, $lsp); + } + $dom[$key]['value'] = $tmpstr; + } + if ($newline) { if (!$this->premode) { - if (($this->rtl OR $this->tmprtl)) { - $dom[$key]['value'] = rtrim($dom[$key]['value']); + if (($this->rtl OR $this->tmprtl)) { + $dom[$key]['value'] = rtrim($dom[$key]['value']); } else { $dom[$key]['value'] = ltrim($dom[$key]['value']); - } + } } - $newline = false; + $newline = false; $firstblock = true; - } else { - $firstblock = false; - } + } else { + $firstblock = false; + } $strrest = ''; if (!empty($this->HREF) AND (isset($this->HREF['url']))) { // HTML
      Link @@ -11976,18 +11976,18 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $this->x += $this->cMargin; } } - if ($strrest == $dom[$key]['value']) { - // used to avoid infinite loop - ++$loop; - } else { - $loop = 0; - } - $dom[$key]['value'] = ltrim($strrest); - if ($loop < 3) { - --$key; + if ($strrest == $dom[$key]['value']) { + // used to avoid infinite loop + ++$loop; + } else { + $loop = 0; + } + $dom[$key]['value'] = ltrim($strrest); + if ($loop < 3) { + --$key; } - } else { - $loop = 0; + } else { + $loop = 0; } } ++$key; @@ -12021,12 +12021,12 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $pend = ''; } // calculate shifting amount - $tw = $w; + $tw = $w; if ($this->lMargin != $prevlMargin) { - $tw += ($prevlMargin - $this->lMargin); + $tw += ($prevlMargin - $this->lMargin); } if ($this->rMargin != $prevrMargin) { - $tw += ($prevrMargin - $this->rMargin); + $tw += ($prevrMargin - $this->rMargin); } $mdiff = abs($tw - $linew); if ($plalign == 'C') { @@ -12043,12 +12043,12 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal $t_x = -$mdiff; } else { $t_x = 0; - } + } if (($t_x != 0) OR ($yshift < 0)) { // shift the line - $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k)); - $this->setPageBuffer($startlinepage, $pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend); - $endlinepos = strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n"); + $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k)); + $this->setPageBuffer($startlinepage, $pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend); + $endlinepos = strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n"); // shift the annotations and links if (isset($this->PageAnnots[$this->page])) { foreach ($this->PageAnnots[$this->page] as $pak => $pac) { @@ -12065,11 +12065,11 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) { $this->Ln($this->lasth); } - // restore previous values - $this->setGraphicVars($gvars); - if ($this->page > $prevPage) { + // restore previous values + $this->setGraphicVars($gvars); + if ($this->page > $prevPage) { $this->lMargin = $this->pagedim[$this->page]['olm']; - $this->rMargin = $this->pagedim[$this->page]['orm']; + $this->rMargin = $this->pagedim[$this->page]['orm']; } unset($dom); } @@ -12083,7 +12083,7 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal */ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { $tag = $dom[$key]; - $parent = $dom[($dom[$key]['parent'])]; + $parent = $dom[($dom[$key]['parent'])]; $firstorlast = ($key == 1); // check for text direction attribute if (isset($tag['attribute']['dir'])) { @@ -12093,26 +12093,26 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { } //Opening tag switch($tag['value']) { - case 'table': { - $cp = 0; + case 'table': { + $cp = 0; $cs = 0; - $dom[$key]['rowspans'] = array(); - if (!$this->empty_string($dom[$key]['thead'])) { - // set table header - $this->thead = $dom[$key]['thead']; - if (!isset($this->theadMargins) OR (empty($this->theadMargins))) { - $this->theadMargins = array(); - $this->theadMargins['cmargin'] = $this->cMargin; - } - } - if (isset($tag['attribute']['cellpadding'])) { + $dom[$key]['rowspans'] = array(); + if (!$this->empty_string($dom[$key]['thead'])) { + // set table header + $this->thead = $dom[$key]['thead']; + if (!isset($this->theadMargins) OR (empty($this->theadMargins))) { + $this->theadMargins = array(); + $this->theadMargins['cmargin'] = $this->cMargin; + } + } + if (isset($tag['attribute']['cellpadding'])) { $cp = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px'); $this->oldcMargin = $this->cMargin; $this->cMargin = $cp; - } - if (isset($tag['attribute']['cellspacing'])) { + } + if (isset($tag['attribute']['cellspacing'])) { $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px'); - } + } $this->checkPageBreak((2 * $cp) + (2 * $cs) + $this->lasth); break; } @@ -12124,7 +12124,7 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { case 'hr': { $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], false); $this->htmlvspace = 0; - $wtmp = $this->w - $this->lMargin - $this->rMargin; + $wtmp = $this->w - $this->lMargin - $this->rMargin; if ((isset($tag['attribute']['width'])) AND ($tag['attribute']['width'] != '')) { $hrWidth = $this->getHTMLUnitToUnits($tag['attribute']['width'], $wtmp, 'px'); } else { @@ -12138,37 +12138,37 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { $this->addHTMLVertSpace(1, $cell, '', !isset($dom[($key + 1)]), $tag['value'], false); break; } - case 'a': { + case 'a': { if (array_key_exists('href', $tag['attribute'])) { - $this->HREF['url'] = $tag['attribute']['href']; - } - $this->HREF['color'] = $this->htmlLinkColorArray; - $this->HREF['style'] = $this->htmlLinkFontStyle; - if (array_key_exists('style', $tag['attribute'])) { - // get style attributes + $this->HREF['url'] = $tag['attribute']['href']; + } + $this->HREF['color'] = $this->htmlLinkColorArray; + $this->HREF['style'] = $this->htmlLinkFontStyle; + if (array_key_exists('style', $tag['attribute'])) { + // get style attributes preg_match_all('/([^;:\s]*):([^;]*)/', $tag['attribute']['style'], $style_array, PREG_PATTERN_ORDER); $astyle = array(); while (list($id, $name) = each($style_array[1])) { - $name = strtolower($name); + $name = strtolower($name); $astyle[$name] = trim($style_array[2][$id]); - } - if (isset($astyle['color'])) { - $this->HREF['color'] = $this->convertHTMLColorToDec($astyle['color']); - } - if (isset($astyle['text-decoration'])) { - $this->HREF['style'] = ''; - $decors = explode(' ', strtolower($astyle['text-decoration'])); - foreach ($decors as $dec) { - $dec = trim($dec); - if (!$this->empty_string($dec)) { - if ($dec{0} == 'u') { - $this->HREF['style'] .= 'U'; - } elseif ($dec{0} == 'l') { - $this->HREF['style'] .= 'D'; - } - } - } - } + } + if (isset($astyle['color'])) { + $this->HREF['color'] = $this->convertHTMLColorToDec($astyle['color']); + } + if (isset($astyle['text-decoration'])) { + $this->HREF['style'] = ''; + $decors = explode(' ', strtolower($astyle['text-decoration'])); + foreach ($decors as $dec) { + $dec = trim($dec); + if (!$this->empty_string($dec)) { + if ($dec{0} == 'u') { + $this->HREF['style'] .= 'U'; + } elseif ($dec{0} == 'l') { + $this->HREF['style'] .= 'D'; + } + } + } + } } break; } @@ -12178,7 +12178,7 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { if ($tag['attribute']['src'][0] == '/') { $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src']; } - $tag['attribute']['src'] = urldecode($tag['attribute']['src']); + $tag['attribute']['src'] = urldecode($tag['attribute']['src']); $tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']); if (!isset($tag['attribute']['width'])) { $tag['attribute']['width'] = 0; @@ -12186,8 +12186,8 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { if (!isset($tag['attribute']['height'])) { $tag['attribute']['height'] = 0; } - //if (!isset($tag['attribute']['align'])) { - // the only alignment supported is "bottom" + //if (!isset($tag['attribute']['align'])) { + // the only alignment supported is "bottom" // further development is required for other modes. $tag['attribute']['align'] = 'bottom'; //} @@ -12212,44 +12212,44 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { $fileinfo = pathinfo($tag['attribute']['src']); if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) { $type = strtolower($fileinfo['extension']); - } - $prevy = $this->y; - $xpos = $this->GetX(); - if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == ' ')) { + } + $prevy = $this->y; + $xpos = $this->GetX(); + if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == ' ')) { if ($this->rtl) { $xpos += $this->GetStringWidth(' '); } else { $xpos -= $this->GetStringWidth(' '); - } - } - $imglink = ''; - if (isset($this->HREF['url']) AND !$this->empty_string($this->HREF['url'])) { - $imglink = $this->HREF['url']; - if ($imglink{0} == '#') { - // convert url to internal link - $page = intval(substr($imglink, 1)); - $imglink = $this->AddLink(); - $this->SetLink($imglink, 0, $page); - } - } - $border = 0; - if (isset($tag['attribute']['border']) AND !empty($tag['attribute']['border'])) { - // currently only support 1 (frame) or a combination of 'LTRB' + } + } + $imglink = ''; + if (isset($this->HREF['url']) AND !$this->empty_string($this->HREF['url'])) { + $imglink = $this->HREF['url']; + if ($imglink{0} == '#') { + // convert url to internal link + $page = intval(substr($imglink, 1)); + $imglink = $this->AddLink(); + $this->SetLink($imglink, 0, $page); + } + } + $border = 0; + if (isset($tag['attribute']['border']) AND !empty($tag['attribute']['border'])) { + // currently only support 1 (frame) or a combination of 'LTRB' $border = $tag['attribute']['border']; - } - $iw = ''; - if (isset($tag['attribute']['width'])) { - $iw = $this->getHTMLUnitToUnits($tag['attribute']['width'], 1, 'px', false); - } - $ih = ''; - if (isset($tag['attribute']['height'])) { - $ih = $this->getHTMLUnitToUnits($tag['attribute']['height'], 1, 'px', false); + } + $iw = ''; + if (isset($tag['attribute']['width'])) { + $iw = $this->getHTMLUnitToUnits($tag['attribute']['width'], 1, 'px', false); + } + $ih = ''; + if (isset($tag['attribute']['height'])) { + $ih = $this->getHTMLUnitToUnits($tag['attribute']['height'], 1, 'px', false); } if (($type == 'eps') OR ($type == 'ai')) { $this->ImageEps($tag['attribute']['src'], $xpos, $this->GetY(), $iw, $ih, $imglink, true, $align, '', $border); } else { $this->Image($tag['attribute']['src'], $xpos, $this->GetY(), $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border); - } + } switch($align) { case 'T': { $this->y = $prevy; @@ -12268,7 +12268,7 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { break; } case 'dl': { - ++$this->listnum; + ++$this->listnum; $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], false); break; } @@ -12286,56 +12286,56 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { break; } case 'ul': - case 'ol': { - $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], false); + case 'ol': { + $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], false); $this->htmlvspace = 0; ++$this->listnum; if ($tag['value'] == 'ol') { $this->listordered[$this->listnum] = true; } else { $this->listordered[$this->listnum] = false; - } - if (isset($tag['attribute']['start'])) { - $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1; + } + if (isset($tag['attribute']['start'])) { + $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1; } else { - $this->listcount[$this->listnum] = 0; + $this->listcount[$this->listnum] = 0; } if ($this->rtl) { $this->rMargin += $this->listindent; } else { $this->lMargin += $this->listindent; - } - $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], false); + } + $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], false); $this->htmlvspace = 0; break; } - case 'li': { - $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], false); - if ($this->listordered[$this->listnum]) { - // ordered item - if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) { - $this->lispacer = $parent['attribute']['type']; - } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) { - $this->lispacer = $parent['listtype']; - } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) { - $this->lispacer = $this->lisymbol; - } else { - $this->lispacer = '#'; - } + case 'li': { + $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], false); + if ($this->listordered[$this->listnum]) { + // ordered item + if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) { + $this->lispacer = $parent['attribute']['type']; + } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) { + $this->lispacer = $parent['listtype']; + } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) { + $this->lispacer = $this->lisymbol; + } else { + $this->lispacer = '#'; + } ++$this->listcount[$this->listnum]; if (isset($tag['attribute']['value'])) { $this->listcount[$this->listnum] = intval($tag['attribute']['value']); } - } else { - // unordered item - if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) { - $this->lispacer = $parent['attribute']['type']; - } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) { - $this->lispacer = $parent['listtype']; - } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) { - $this->lispacer = $this->lisymbol; - } else { - $this->lispacer = '!'; + } else { + // unordered item + if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) { + $this->lispacer = $parent['attribute']['type']; + } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) { + $this->lispacer = $parent['listtype']; + } elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) { + $this->lispacer = $this->lisymbol; + } else { + $this->lispacer = '!'; } } break; @@ -12349,7 +12349,7 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { $this->addHTMLVertSpace(2, $cell, '', $firstorlast, $tag['value'], false); break; } - case 'br': { + case 'br': { $this->Ln('', $cell); break; } @@ -12360,9 +12360,9 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { case 'p': { $this->addHTMLVertSpace(2, $cell, '', $firstorlast, $tag['value'], false); break; - } + } case 'pre': { - $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], false); + $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], false); $this->premode = true; break; } @@ -12382,21 +12382,21 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { case 'h6': { $this->addHTMLVertSpace(1, $cell, ($tag['fontsize'] * 1.5) / $this->k, $firstorlast, $tag['value'], false); break; - } - case 'tcpdf': { - // NOT HTML: used to call TCPDF methods + } + case 'tcpdf': { + // NOT HTML: used to call TCPDF methods if (isset($tag['attribute']['method'])) { - $tcpdf_method = $tag['attribute']['method']; - if (method_exists($this, $tcpdf_method)) { - if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) { - eval('$params = array('.$tag['attribute']['params'].');'); - call_user_func_array(array($this, $tcpdf_method), $params); - } else { - $this->$tcpdf_method(); - } - $this->newline = true; - } - } + $tcpdf_method = $tag['attribute']['method']; + if (method_exists($this, $tcpdf_method)) { + if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) { + eval('$params = array('.$tag['attribute']['params'].');'); + call_user_func_array(array($this, $tcpdf_method), $params); + } else { + $this->$tcpdf_method(); + } + $this->newline = true; + } + } } default: { break; @@ -12413,20 +12413,20 @@ protected function openHTMLTagHandler(&$dom, $key, $cell=false) { */ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $tag = $dom[$key]; - $parent = $dom[($dom[$key]['parent'])]; - $firstorlast = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker'))); + $parent = $dom[($dom[$key]['parent'])]; + $firstorlast = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker'))); $in_table_head = false; //Closing tag switch($tag['value']) { case 'tr': { - $table_el = $dom[($dom[$key]['parent'])]['parent']; - if(!isset($parent['endy'])) { - $dom[($dom[$key]['parent'])]['endy'] = $this->y; - $parent['endy'] = $this->y; - } - if(!isset($parent['endpage'])) { - $dom[($dom[$key]['parent'])]['endpage'] = $this->page; - $parent['endpage'] = $this->page; + $table_el = $dom[($dom[$key]['parent'])]['parent']; + if(!isset($parent['endy'])) { + $dom[($dom[$key]['parent'])]['endy'] = $this->y; + $parent['endy'] = $this->y; + } + if(!isset($parent['endpage'])) { + $dom[($dom[$key]['parent'])]['endpage'] = $this->page; + $parent['endpage'] = $this->page; } // update row-spanned cells if (isset($dom[$table_el]['rowspans'])) { @@ -12440,20 +12440,20 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage']; } } - } - // report new endy and endpage to the rowspanned cells + } + // report new endy and endpage to the rowspanned cells foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) { if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) { - $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']); - $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage']; - $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']); + $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']); + $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage']; + $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']); $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy']; } - } - // update remaining rowspanned cells + } + // update remaining rowspanned cells foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) { if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) { - $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage']; + $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage']; $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy']; } } @@ -12465,19 +12465,19 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $this->y += $cellspacing; } $this->Ln(0, $cell); - $this->x = $parent['startx']; - // account for booklet mode - if ($this->page > $parent['startpage']) { - if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) { - $this->x += ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']); - } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) { - $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']); - } - } - break; - } - case 'tablehead': - // closing tag used for the thead part + $this->x = $parent['startx']; + // account for booklet mode + if ($this->page > $parent['startpage']) { + if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) { + $this->x += ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']); + } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) { + $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']); + } + } + break; + } + case 'tablehead': + // closing tag used for the thead part $in_table_head = true; case 'table': { // draw borders @@ -12487,39 +12487,39 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $border = 1; } else { $border = 0; - } - // fix bottom line alignment of last line before page break - foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) { - // update row-spanned cells - if (isset($dom[($dom[$key]['parent'])]['rowspans'])) { - foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) { - if ($trwsp['trid'] == $trkey) { - $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1; - } - if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0)) { - $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey; - } - } - } - if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) { - $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm']; - $dom[$prevtrkey]['endy'] = $pgendy; - // update row-spanned cells - if (isset($dom[($dom[$key]['parent'])]['rowspans'])) { - foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) { - if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] == 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) { - $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy; - $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1; - } - } - } - } - $prevtrkey = $trkey; - $table_el = $dom[($dom[$key]['parent'])]; + } + // fix bottom line alignment of last line before page break + foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) { + // update row-spanned cells + if (isset($dom[($dom[$key]['parent'])]['rowspans'])) { + foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) { + if ($trwsp['trid'] == $trkey) { + $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1; + } + if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0)) { + $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey; + } + } + } + if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) { + $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm']; + $dom[$prevtrkey]['endy'] = $pgendy; + // update row-spanned cells + if (isset($dom[($dom[$key]['parent'])]['rowspans'])) { + foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) { + if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] == 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) { + $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy; + $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1; + } + } + } + } + $prevtrkey = $trkey; + $table_el = $dom[($dom[$key]['parent'])]; } // for each row foreach ($table_el['trids'] as $j => $trkey) { - $parent = $dom[$trkey]; + $parent = $dom[$trkey]; // for each cell on the row foreach ($parent['cellpos'] as $k => $cellpos) { if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) { @@ -12532,22 +12532,22 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $endy = $parent['endy']; $startpage = $parent['startpage']; $endpage = $parent['endpage']; - } + } if ($endpage > $startpage) { // design borders around HTML cells. for ($page=$startpage; $page <= $endpage; ++$page) { $this->setPage($page); if ($page == $startpage) { - $this->y = $parent['starty']; // put cursor at the beginning of row on the first page - $ch = $this->getPageHeight() - $parent['starty'] - $this->getBreakMargin(); + $this->y = $parent['starty']; // put cursor at the beginning of row on the first page + $ch = $this->getPageHeight() - $parent['starty'] - $this->getBreakMargin(); $cborder = $this->getBorderMode($border, $position='start'); } elseif ($page == $endpage) { $this->y = $this->tMargin; // put cursor at the beginning of last page - $ch = $endy - $this->tMargin; + $ch = $endy - $this->tMargin; $cborder = $this->getBorderMode($border, $position='end'); } else { $this->y = $this->tMargin; // put cursor at the beginning of the current page - $ch = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin(); + $ch = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin(); $cborder = $this->getBorderMode($border, $position='middle'); } if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) { @@ -12556,27 +12556,27 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { } else { $fill = false; } - $cw = abs($cellpos['endx'] - $cellpos['startx']); - $this->x = $cellpos['startx']; - // account for margin changes - if ($page > $startpage) { - if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { - $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) AND ($this->pagedim[$page]['lm'] != $this->pagedim[$startpage]['olm'])) { - $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); - } + $cw = abs($cellpos['endx'] - $cellpos['startx']); + $this->x = $cellpos['startx']; + // account for margin changes + if ($page > $startpage) { + if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) { + $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']); + } elseif ((!$this->rtl) AND ($this->pagedim[$page]['lm'] != $this->pagedim[$startpage]['olm'])) { + $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']); + } } // design a cell around the text - $ccode = $this->FillColor."\n".$this->getCellCode($cw, $ch, '', $cborder, 1, '', $fill, '', 0, true); - if ($cborder OR $fill) { + $ccode = $this->FillColor."\n".$this->getCellCode($cw, $ch, '', $cborder, 1, '', $fill, '', 0, true); + if ($cborder OR $fill) { $pagebuff = $this->getPageBuffer($this->page); $pstart = substr($pagebuff, 0, $this->intmrk[$this->page]); $pend = substr($pagebuff, $this->intmrk[$this->page]); $this->setPageBuffer($this->page, $pstart.$ccode."\n".$pend); - $this->intmrk[$this->page] += strlen($ccode."\n"); + $this->intmrk[$this->page] += strlen($ccode."\n"); } } - } else { + } else { $this->setPage($startpage); if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) { $this->SetFillColorArray($cellpos['bgcolor']); @@ -12585,25 +12585,25 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $fill = false; } $this->x = $cellpos['startx']; - $this->y = $parent['starty']; - $cw = abs($cellpos['endx'] - $cellpos['startx']); + $this->y = $parent['starty']; + $cw = abs($cellpos['endx'] - $cellpos['startx']); $ch = $endy - $parent['starty']; // design a cell around the text - $ccode = $this->FillColor."\n".$this->getCellCode($cw, $ch, '', $border, 1, '', $fill, '', 0, true); - if ($border OR $fill) { - if (end($this->transfmrk[$this->page]) !== false) { - $pagemarkkey = key($this->transfmrk[$this->page]); - $pagemark = &$this->transfmrk[$this->page][$pagemarkkey]; - } elseif ($this->InFooter) { - $pagemark = &$this->footerpos[$this->page]; - } else { - $pagemark = &$this->intmrk[$this->page]; - } + $ccode = $this->FillColor."\n".$this->getCellCode($cw, $ch, '', $border, 1, '', $fill, '', 0, true); + if ($border OR $fill) { + if (end($this->transfmrk[$this->page]) !== false) { + $pagemarkkey = key($this->transfmrk[$this->page]); + $pagemark = &$this->transfmrk[$this->page][$pagemarkkey]; + } elseif ($this->InFooter) { + $pagemark = &$this->footerpos[$this->page]; + } else { + $pagemark = &$this->intmrk[$this->page]; + } $pagebuff = $this->getPageBuffer($this->page); $pstart = substr($pagebuff, 0, $pagemark); $pend = substr($pagebuff, $pagemark); $this->setPageBuffer($this->page, $pstart.$ccode."\n".$pend); - $pagemark += strlen($ccode."\n"); + $pagemark += strlen($ccode."\n"); } } } @@ -12612,29 +12612,29 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $this->y += $cellspacing; } $this->Ln(0, $cell); - $this->x = $parent['startx']; - if ($endpage > $startpage) { - if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) { - $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']); - } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) { - $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']); - } + $this->x = $parent['startx']; + if ($endpage > $startpage) { + if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) { + $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']); + } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) { + $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']); + } } } - if (!$in_table_head) { - // we are not inside a thead section + if (!$in_table_head) { + // we are not inside a thead section if (isset($parent['cellpadding'])) { $this->cMargin = $this->oldcMargin; - } - $this->lasth = $this->FontSize * $this->cell_height_ratio; - if (!empty($this->theadMargins)) { - // restore top margin - $this->tMargin = $this->theadMargins['top']; - $this->pagedim[$this->page]['tm'] = $this->tMargin; - } - // reset table header - $this->thead = ''; - $this->theadMargins = array(); + } + $this->lasth = $this->FontSize * $this->cell_height_ratio; + if (!empty($this->theadMargins)) { + // restore top margin + $this->tMargin = $this->theadMargins['top']; + $this->pagedim[$this->page]['tm'] = $this->tMargin; + } + // reset table header + $this->thead = ''; + $this->theadMargins = array(); } break; } @@ -12666,9 +12666,9 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { case 'p': { $this->addHTMLVertSpace(2, $cell, '', $firstorlast, $tag['value'], true); break; - } + } case 'pre': { - $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], true); + $this->addHTMLVertSpace(1, $cell, '', $firstorlast, $tag['value'], true); $this->premode = false; break; } @@ -12681,7 +12681,7 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { break; } case 'dt': { - $this->lispacer = ''; + $this->lispacer = ''; $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], true); break; } @@ -12691,7 +12691,7 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { $this->rMargin -= $this->listindent; } else { $this->lMargin -= $this->listindent; - } + } $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], true); break; } @@ -12712,7 +12712,7 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { break; } case 'li': { - $this->lispacer = ''; + $this->lispacer = ''; $this->addHTMLVertSpace(0, $cell, '', $firstorlast, $tag['value'], true); break; } @@ -12736,24 +12736,24 @@ protected function closeHTMLTagHandler(&$dom, $key, $cell=false) { * Add vertical spaces if needed. * @param int $n number of spaces to add * @param boolean $cell if true add the default cMargin space to each new line (default false). - * @param string $h The height of the break. By default, the value equals the height of the last printed cell. - * @param boolean $firstorlast if true do not print additional empty lines. - * @param string $tag HTML tag to which this space will be applied + * @param string $h The height of the break. By default, the value equals the height of the last printed cell. + * @param boolean $firstorlast if true do not print additional empty lines. + * @param string $tag HTML tag to which this space will be applied * @param boolean $closing true if this space will be applied to a closing tag, false otherwise * @access protected */ protected function addHTMLVertSpace($n, $cell=false, $h='', $firstorlast=false, $tag='', $closing=false) { - if ($firstorlast) { + if ($firstorlast) { $this->Ln(0, $cell); - $this->htmlvspace = 0; - return; - } - if (isset($this->tagvspaces[$tag][intval($closing)]['n'])) { - $n = $this->tagvspaces[$tag][intval($closing)]['n']; - } - if (isset($this->tagvspaces[$tag][intval($closing)]['h'])) { - $h = $this->tagvspaces[$tag][intval($closing)]['h']; - } + $this->htmlvspace = 0; + return; + } + if (isset($this->tagvspaces[$tag][intval($closing)]['n'])) { + $n = $this->tagvspaces[$tag][intval($closing)]['n']; + } + if (isset($this->tagvspaces[$tag][intval($closing)]['h'])) { + $h = $this->tagvspaces[$tag][intval($closing)]['h']; + } if (is_string($h)) { $vsize = $n * $this->lasth; } else { @@ -12768,424 +12768,424 @@ protected function addHTMLVertSpace($n, $cell=false, $h='', $firstorlast=false, /** * Set the default bullet to be used as LI bullet symbol * @param string $symbol character or string to be used (legal values are: '' = automatic, '!' = auto bullet, '#' = auto numbering, 'disc', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek') - * @access public + * @access public * @since 4.0.028 (2008-09-26) */ - public function setLIsymbol($symbol='!') { - $symbol = strtolower($symbol); - switch ($symbol) { - case '!' : - case '#' : - case 'disc' : - case 'disc' : - case 'circle' : - case 'square' : - case '1': - case 'decimal': - case 'decimal-leading-zero': - case 'i': - case 'lower-roman': - case 'I': - case 'upper-roman': - case 'a': - case 'lower-alpha': - case 'lower-latin': - case 'A': - case 'upper-alpha': - case 'upper-latin': - case 'lower-greek': { - $this->lisymbol = $symbol; - break; - } - default : { - $this->lisymbol = ''; - } - } - } + public function setLIsymbol($symbol='!') { + $symbol = strtolower($symbol); + switch ($symbol) { + case '!' : + case '#' : + case 'disc' : + case 'disc' : + case 'circle' : + case 'square' : + case '1': + case 'decimal': + case 'decimal-leading-zero': + case 'i': + case 'lower-roman': + case 'I': + case 'upper-roman': + case 'a': + case 'lower-alpha': + case 'lower-latin': + case 'A': + case 'upper-alpha': + case 'upper-latin': + case 'lower-greek': { + $this->lisymbol = $symbol; + break; + } + default : { + $this->lisymbol = ''; + } + } + } /** * Set the booklet mode for double-sided pages. * @param boolean $booklet true set the booklet mode on, fals eotherwise. * @param float $inner Inner page margin. - * @param float $outer Outer page margin. + * @param float $outer Outer page margin. * @access public * @since 4.2.000 (2008-10-29) */ public function SetBooklet($booklet=true, $inner=-1, $outer=-1) { - $this->booklet = $booklet; + $this->booklet = $booklet; if ($inner >= 0) { $this->lMargin = $inner; - } + } if ($outer >= 0) { $this->rMargin = $outer; } - } + } /** * Swap the left and right margins. - * @param boolean $reverse if true swap left and right margins. + * @param boolean $reverse if true swap left and right margins. * @access protected * @since 4.2.000 (2008-10-29) - */ - protected function swapMargins($reverse=true) { - if ($reverse) { - // swap left and right margins - $mtemp = $this->original_lMargin; - $this->original_lMargin = $this->original_rMargin; - $this->original_rMargin = $mtemp; - $deltam = $this->original_lMargin - $this->original_rMargin; - $this->lMargin += $deltam; - $this->rMargin -= $deltam; - } - } - - /** - * Set the vertical spaces for HTML tags. - * The array must have the following structure (example): - * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1))); - * The first array level contains the tag names, - * the second level contains 0 for opening tags or 1 for closing tags, - * the third level contains the vertical space unit (h) and the number spaces to add (n). + */ + protected function swapMargins($reverse=true) { + if ($reverse) { + // swap left and right margins + $mtemp = $this->original_lMargin; + $this->original_lMargin = $this->original_rMargin; + $this->original_rMargin = $mtemp; + $deltam = $this->original_lMargin - $this->original_rMargin; + $this->lMargin += $deltam; + $this->rMargin -= $deltam; + } + } + + /** + * Set the vertical spaces for HTML tags. + * The array must have the following structure (example): + * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1))); + * The first array level contains the tag names, + * the second level contains 0 for opening tags or 1 for closing tags, + * the third level contains the vertical space unit (h) and the number spaces to add (n). * If the h parameter is not specified, default values are used. - * @param array $tagvs array of tags and relative vertical spaces. + * @param array $tagvs array of tags and relative vertical spaces. * @access public * @since 4.2.001 (2008-10-30) */ - public function setHtmlVSpace($tagvs) { - $this->tagvspaces = $tagvs; - } - + public function setHtmlVSpace($tagvs) { + $this->tagvspaces = $tagvs; + } + /** - * Set custom width for list indentation. - * @param float $width width of the indentation. Use negative value to disable it. - * @access public + * Set custom width for list indentation. + * @param float $width width of the indentation. Use negative value to disable it. + * @access public * @since 4.2.007 (2008-11-12) */ - public function setListIndentWidth($width) { - return $this->customlistindent = floatval($width); - } - + public function setListIndentWidth($width) { + return $this->customlistindent = floatval($width); + } + /** - * Set the top/bottom cell sides to be open or closed when the cell cross the page. - * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page. - * @access public + * Set the top/bottom cell sides to be open or closed when the cell cross the page. + * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page. + * @access public * @since 4.2.010 (2008-11-14) */ - public function setOpenCell($isopen) { - $this->opencell = $isopen; - } - + public function setOpenCell($isopen) { + $this->opencell = $isopen; + } + /** - * Set the color and font style for HTML links. - * @param array $color RGB array of colors - * @param string $fontstyle additional font styles to add - * @access public + * Set the color and font style for HTML links. + * @param array $color RGB array of colors + * @param string $fontstyle additional font styles to add + * @access public * @since 4.4.003 (2008-12-09) */ - public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') { - $this->htmlLinkColorArray = $color; - $this->htmlLinkFontStyle = $fontstyle; - } - + public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') { + $this->htmlLinkColorArray = $color; + $this->htmlLinkFontStyle = $fontstyle; + } + /** - * convert html string containing value and unit of measure to user's units or points. - * @param string $htmlval string containing values and unit - * @param string $refsize reference value in points - * @param string $defaultunit default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt). - * @param boolean $point if true returns points, otherwise returns value in user's units - * @return float value in user's unit or point if $points=true - * @access public + * convert html string containing value and unit of measure to user's units or points. + * @param string $htmlval string containing values and unit + * @param string $refsize reference value in points + * @param string $defaultunit default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt). + * @param boolean $point if true returns points, otherwise returns value in user's units + * @return float value in user's unit or point if $points=true + * @access public * @since 4.4.004 (2008-12-10) - */ - public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) { - $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt'); - $retval = 0; - $value = 0; - $unit = 'px'; - $k = $this->k; - if ($points) { - $k = 1; - } - if (in_array($defaultunit, $supportedunits)) { - $unit = $defaultunit; - } - if (is_numeric($htmlval)) { - $value = floatval($htmlval); - } elseif (preg_match('/([0-9\.]+)/', $htmlval, $mnum)) { - $value = floatval($mnum[1]); - if (preg_match('/([a-z%]+)/', $htmlval, $munit)) { - if (in_array($munit[1], $supportedunits)) { - $unit = $munit[1]; - } - } - } - switch ($unit) { - // percentage - case '%': { - $retval = (($value * $refsize) / 100); - break; - } - // relative-size - case 'em': { - $retval = ($value * $refsize); - break; - } - case 'ex': { - $retval = $value * ($refsize / 2); - break; - } - // absolute-size - case 'in': { - $retval = ($value * $this->dpi) / $k; - break; - } - case 'cm': { - $retval = ($value / 2.54 * $this->dpi) / $k; - break; - } - case 'mm': { - $retval = ($value / 25.4 * $this->dpi) / $k; - break; - } - case 'pc': { - // one pica is 12 points - $retval = ($value * 12) / $k; - break; - } - case 'pt': { - $retval = $value / $k; - break; - } - case 'px': { - $retval = $this->pixelsToUnits($value); - break; - } - } - return $retval; - } - - /** - * Returns the Roman representation of an integer number - * @param int number to convert - * @return string roman representation of the specified number - * @access public + */ + public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) { + $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt'); + $retval = 0; + $value = 0; + $unit = 'px'; + $k = $this->k; + if ($points) { + $k = 1; + } + if (in_array($defaultunit, $supportedunits)) { + $unit = $defaultunit; + } + if (is_numeric($htmlval)) { + $value = floatval($htmlval); + } elseif (preg_match('/([0-9\.]+)/', $htmlval, $mnum)) { + $value = floatval($mnum[1]); + if (preg_match('/([a-z%]+)/', $htmlval, $munit)) { + if (in_array($munit[1], $supportedunits)) { + $unit = $munit[1]; + } + } + } + switch ($unit) { + // percentage + case '%': { + $retval = (($value * $refsize) / 100); + break; + } + // relative-size + case 'em': { + $retval = ($value * $refsize); + break; + } + case 'ex': { + $retval = $value * ($refsize / 2); + break; + } + // absolute-size + case 'in': { + $retval = ($value * $this->dpi) / $k; + break; + } + case 'cm': { + $retval = ($value / 2.54 * $this->dpi) / $k; + break; + } + case 'mm': { + $retval = ($value / 25.4 * $this->dpi) / $k; + break; + } + case 'pc': { + // one pica is 12 points + $retval = ($value * 12) / $k; + break; + } + case 'pt': { + $retval = $value / $k; + break; + } + case 'px': { + $retval = $this->pixelsToUnits($value); + break; + } + } + return $retval; + } + + /** + * Returns the Roman representation of an integer number + * @param int number to convert + * @return string roman representation of the specified number + * @access public * @since 4.4.004 (2008-12-10) - */ - public function intToRoman($number) { - $roman = ''; - while ($number >= 1000) { - $roman .= 'M'; - $number -= 1000; - } - while ($number >= 900) { - $roman .= 'CM'; - $number -= 900; - } - while ($number >= 500) { - $roman .= 'D'; - $number -= 500; - } - while ($number >= 400) { - $roman .= 'CD'; - $number -= 400; - } - while ($number >= 100) { - $roman .= 'C'; - $number -= 100; - } - while ($number >= 90) { - $roman .= 'XC'; - $number -= 90; - } - while ($number >= 50) { - $roman .= 'L'; - $number -= 50; - } - while ($number >= 40) { - $roman .= 'XL'; - $number -= 40; - } - while ($number >= 10) { - $roman .= 'X'; - $number -= 10; - } - while ($number >= 9) { - $roman .= 'IX'; - $number -= 9; - } - while ($number >= 5) { - $roman .= 'V'; - $number -= 5; - } - while ($number >= 4) { - $roman .= 'IV'; - $number -= 4; - } - while ($number >= 1) { - $roman .= 'I'; - --$number; - } - return $roman; - } - - /** - * Output an HTML list bullet or ordered item symbol - * @param int $listdepth list nesting level - * @param string $listtype type of list - * @param float $size current font size - * @access protected + */ + public function intToRoman($number) { + $roman = ''; + while ($number >= 1000) { + $roman .= 'M'; + $number -= 1000; + } + while ($number >= 900) { + $roman .= 'CM'; + $number -= 900; + } + while ($number >= 500) { + $roman .= 'D'; + $number -= 500; + } + while ($number >= 400) { + $roman .= 'CD'; + $number -= 400; + } + while ($number >= 100) { + $roman .= 'C'; + $number -= 100; + } + while ($number >= 90) { + $roman .= 'XC'; + $number -= 90; + } + while ($number >= 50) { + $roman .= 'L'; + $number -= 50; + } + while ($number >= 40) { + $roman .= 'XL'; + $number -= 40; + } + while ($number >= 10) { + $roman .= 'X'; + $number -= 10; + } + while ($number >= 9) { + $roman .= 'IX'; + $number -= 9; + } + while ($number >= 5) { + $roman .= 'V'; + $number -= 5; + } + while ($number >= 4) { + $roman .= 'IV'; + $number -= 4; + } + while ($number >= 1) { + $roman .= 'I'; + --$number; + } + return $roman; + } + + /** + * Output an HTML list bullet or ordered item symbol + * @param int $listdepth list nesting level + * @param string $listtype type of list + * @param float $size current font size + * @access protected * @since 4.4.004 (2008-12-10) - */ - protected function putHtmlListBullet($listdepth, $listtype='', $size=10) { - $size /= $this->k; - $fill = ''; - $color = $this->fgcolor; - $width = 0; - $textitem = ''; + */ + protected function putHtmlListBullet($listdepth, $listtype='', $size=10) { + $size /= $this->k; + $fill = ''; + $color = $this->fgcolor; + $width = 0; + $textitem = ''; $tmpx = $this->x; - $lspace = $this->GetStringWidth(' '); - if ($listtype == '!') { - // set default list type for unordered list - $deftypes = array('disc', 'circle', 'square'); - $listtype = $deftypes[($listdepth - 1) % 3]; - } elseif ($listtype == '#') { - // set default list type for ordered list - $listtype = 'decimal'; - } - switch ($listtype) { - // unordered types - case 'none': { - break; - } - case 'disc': { - $fill = 'F'; - } - case 'circle': { - $fill .= 'D'; - $r = $size / 6; - $lspace += (2 * $r); + $lspace = $this->GetStringWidth(' '); + if ($listtype == '!') { + // set default list type for unordered list + $deftypes = array('disc', 'circle', 'square'); + $listtype = $deftypes[($listdepth - 1) % 3]; + } elseif ($listtype == '#') { + // set default list type for ordered list + $listtype = 'decimal'; + } + switch ($listtype) { + // unordered types + case 'none': { + break; + } + case 'disc': { + $fill = 'F'; + } + case 'circle': { + $fill .= 'D'; + $r = $size / 6; + $lspace += (2 * $r); if ($this->rtl) { $this->x = $this->w - $this->x - $lspace; } else { $this->x -= $lspace; - } - $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, $fill, array('color'=>$color), $color, 8); - break; - } - case 'square': { - $l = $size / 3; - $lspace += $l; + } + $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, $fill, array('color'=>$color), $color, 8); + break; + } + case 'square': { + $l = $size / 3; + $lspace += $l; if ($this->rtl) { $this->x = $this->w - $this->x - $lspace; } else { $this->x -= $lspace; - } - $this->Rect($this->x, ($this->y + (($this->lasth - $l)/ 2)), $l, $l, 'F', array(), $color); - break; - } - // ordered types - - // $this->listcount[$this->listnum]; - // $textitem - case '1': - case 'decimal': { - $textitem = $this->listcount[$this->listnum]; - break; - } - case 'decimal-leading-zero': { - $textitem = sprintf("%02d", $this->listcount[$this->listnum]); - break; - } - case 'i': - case 'lower-roman': { - $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum])); - break; - } - case 'I': - case 'upper-roman': { - $textitem = $this->intToRoman($this->listcount[$this->listnum]); - break; - } - case 'a': - case 'lower-alpha': - case 'lower-latin': { - $textitem = chr(97 + $this->listcount[$this->listnum] - 1); - break; - } - case 'A': - case 'upper-alpha': - case 'upper-latin': { - $textitem = chr(65 + $this->listcount[$this->listnum] - 1); - break; - } - case 'lower-greek': { - $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1); - break; - } - /* - // Types to be implemented (special handling) - case 'hebrew': { - break; - } - case 'armenian': { - break; - } - case 'georgian': { - break; - } - case 'cjk-ideographic': { - break; - } - case 'hiragana': { - break; - } - case 'katakana': { - break; - } - case 'hiragana-iroha': { - break; - } - case 'katakana-iroha': { - break; - } - */ - default: { - $textitem = $this->listcount[$this->listnum]; - } - } - if (!$this->empty_string($textitem)) { - // print ordered item + } + $this->Rect($this->x, ($this->y + (($this->lasth - $l)/ 2)), $l, $l, 'F', array(), $color); + break; + } + // ordered types + + // $this->listcount[$this->listnum]; + // $textitem + case '1': + case 'decimal': { + $textitem = $this->listcount[$this->listnum]; + break; + } + case 'decimal-leading-zero': { + $textitem = sprintf("%02d", $this->listcount[$this->listnum]); + break; + } + case 'i': + case 'lower-roman': { + $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum])); + break; + } + case 'I': + case 'upper-roman': { + $textitem = $this->intToRoman($this->listcount[$this->listnum]); + break; + } + case 'a': + case 'lower-alpha': + case 'lower-latin': { + $textitem = chr(97 + $this->listcount[$this->listnum] - 1); + break; + } + case 'A': + case 'upper-alpha': + case 'upper-latin': { + $textitem = chr(65 + $this->listcount[$this->listnum] - 1); + break; + } + case 'lower-greek': { + $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1); + break; + } + /* + // Types to be implemented (special handling) + case 'hebrew': { + break; + } + case 'armenian': { + break; + } + case 'georgian': { + break; + } + case 'cjk-ideographic': { + break; + } + case 'hiragana': { + break; + } + case 'katakana': { + break; + } + case 'hiragana-iroha': { + break; + } + case 'katakana-iroha': { + break; + } + */ + default: { + $textitem = $this->listcount[$this->listnum]; + } + } + if (!$this->empty_string($textitem)) { + // print ordered item if ($this->rtl) { $textitem = '.'.$textitem; } else { $textitem = $textitem.'.'; - } - $lspace += $this->GetStringWidth($textitem); + } + $lspace += $this->GetStringWidth($textitem); if ($this->rtl) { $this->x += $lspace; } else { $this->x -= $lspace; - } - $this->Write($this->lasth, $textitem, '', false, '', false, 0, false); - } + } + $this->Write($this->lasth, $textitem, '', false, '', false, 0, false); + } $this->x = $tmpx; - $this->lispacer = ''; - } - + $this->lispacer = ''; + } + /** - * Returns current graphic variables as array. - * @return array graphic variables + * Returns current graphic variables as array. + * @return array graphic variables * @access protected * @since 4.2.010 (2008-11-14) */ - protected function getGraphicVars() { - $grapvars = array( + protected function getGraphicVars() { + $grapvars = array( 'FontFamily' => $this->FontFamily, 'FontStyle' => $this->FontStyle, 'FontSizePt' => $this->FontSizePt, 'rMargin' => $this->rMargin, 'lMargin' => $this->lMargin, - 'cMargin' => $this->cMargin, + 'cMargin' => $this->cMargin, 'LineWidth' => $this->LineWidth, 'linestyleWidth' => $this->linestyleWidth, 'linestyleCap' => $this->linestyleCap, @@ -13194,28 +13194,28 @@ protected function getGraphicVars() { 'DrawColor' => $this->DrawColor, 'FillColor' => $this->FillColor, 'TextColor' => $this->TextColor, - 'ColorFlag' => $this->ColorFlag, + 'ColorFlag' => $this->ColorFlag, 'bgcolor' => $this->bgcolor, - 'fgcolor' => $this->fgcolor, - 'htmlvspace' => $this->htmlvspace, - 'lasth' => $this->lasth - ); - return $grapvars; - } - + 'fgcolor' => $this->fgcolor, + 'htmlvspace' => $this->htmlvspace, + 'lasth' => $this->lasth + ); + return $grapvars; + } + /** - * Set graphic variables. - * @param $gvars array graphic variables + * Set graphic variables. + * @param $gvars array graphic variables * @access protected * @since 4.2.010 (2008-11-14) */ - protected function setGraphicVars($gvars) { + protected function setGraphicVars($gvars) { $this->FontFamily = $gvars['FontFamily']; $this->FontStyle = $gvars['FontStyle']; $this->FontSizePt = $gvars['FontSizePt']; $this->rMargin = $gvars['rMargin']; $this->lMargin = $gvars['lMargin']; - $this->cMargin = $gvars['cMargin']; + $this->cMargin = $gvars['cMargin']; $this->LineWidth = $gvars['LineWidth']; $this->linestyleWidth = $gvars['linestyleWidth']; $this->linestyleCap = $gvars['linestyleCap']; @@ -13224,637 +13224,637 @@ protected function setGraphicVars($gvars) { $this->DrawColor = $gvars['DrawColor']; $this->FillColor = $gvars['FillColor']; $this->TextColor = $gvars['TextColor']; - $this->ColorFlag = $gvars['ColorFlag']; + $this->ColorFlag = $gvars['ColorFlag']; $this->bgcolor = $gvars['bgcolor']; - $this->fgcolor = $gvars['fgcolor']; - $this->htmlvspace = $gvars['htmlvspace']; - //$this->lasth = $gvars['lasth']; + $this->fgcolor = $gvars['fgcolor']; + $this->htmlvspace = $gvars['htmlvspace']; + //$this->lasth = $gvars['lasth']; $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.''); if (!$this->empty_string($this->FontFamily)) { $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt); - } - } - + } + } + /** * Returns a temporary filename for caching object on filesystem. * @param string $prefix prefix to add to filename * return string filename. - * @access protected + * @access protected * @since 4.5.000 (2008-12-31) */ protected function getObjFilename($name) { return tempnam(K_PATH_CACHE, $name.'_'); - } - + } + /** - * Writes data to a temporary file on filesystem. - * @param string $file file name - * @param mixed $data data to write on file - * @param boolean $append if true append data, false replace. + * Writes data to a temporary file on filesystem. + * @param string $file file name + * @param mixed $data data to write on file + * @param boolean $append if true append data, false replace. * @access protected * @since 4.5.000 (2008-12-31) */ - protected function writeDiskCache($filename, $data, $append=false) { - if ($append) { - $fmode = 'ab+'; - } else { - $fmode = 'wb+'; - } - $f = @fopen($filename, $fmode); - if (!$f) { - $this->Error('Unable to write cache file: '.$filename); - } else { - fwrite($f, $data); - fclose($f); - } - // update file lenght (needed for transactions) - if (!isset($this->cache_file_lenght['_'.$filename])) { - $this->cache_file_lenght['_'.$filename] = strlen($data); - } else { - $this->cache_file_lenght['_'.$filename] += strlen($data); - } - } - + protected function writeDiskCache($filename, $data, $append=false) { + if ($append) { + $fmode = 'ab+'; + } else { + $fmode = 'wb+'; + } + $f = @fopen($filename, $fmode); + if (!$f) { + $this->Error('Unable to write cache file: '.$filename); + } else { + fwrite($f, $data); + fclose($f); + } + // update file lenght (needed for transactions) + if (!isset($this->cache_file_lenght['_'.$filename])) { + $this->cache_file_lenght['_'.$filename] = strlen($data); + } else { + $this->cache_file_lenght['_'.$filename] += strlen($data); + } + } + /** - * Read data from a temporary file on filesystem. - * @param string $file file name - * @return mixed retrieved data + * Read data from a temporary file on filesystem. + * @param string $file file name + * @return mixed retrieved data * @access protected * @since 4.5.000 (2008-12-31) */ - protected function readDiskCache($filename) { - return file_get_contents($filename); - } - + protected function readDiskCache($filename) { + return file_get_contents($filename); + } + /** - * Set buffer content (always append data). - * @param string $data data + * Set buffer content (always append data). + * @param string $data data * @access protected * @since 4.5.000 (2009-01-02) */ - protected function setBuffer($data) { - $this->bufferlen += strlen($data); - if ($this->diskcache) { - if (!isset($this->buffer) OR $this->empty_string($this->buffer)) { - $this->buffer = $this->getObjFilename('buffer'); - } - $this->writeDiskCache($this->buffer, $data, true); - } else { - $this->buffer .= $data; - } - } - + protected function setBuffer($data) { + $this->bufferlen += strlen($data); + if ($this->diskcache) { + if (!isset($this->buffer) OR $this->empty_string($this->buffer)) { + $this->buffer = $this->getObjFilename('buffer'); + } + $this->writeDiskCache($this->buffer, $data, true); + } else { + $this->buffer .= $data; + } + } + /** - * Get buffer content. - * @return string buffer content + * Get buffer content. + * @return string buffer content * @access protected * @since 4.5.000 (2009-01-02) */ - protected function getBuffer() { - if ($this->diskcache) { - return $this->readDiskCache($this->buffer); - } else { - return $this->buffer; - } - } - + protected function getBuffer() { + if ($this->diskcache) { + return $this->readDiskCache($this->buffer); + } else { + return $this->buffer; + } + } + /** - * Set page buffer content. - * @param int $page page number - * @param string $data page data - * @param boolean $append if true append data, false replace. + * Set page buffer content. + * @param int $page page number + * @param string $data page data + * @param boolean $append if true append data, false replace. * @access protected * @since 4.5.000 (2008-12-31) */ - protected function setPageBuffer($page, $data, $append=false) { - if ($this->diskcache) { - if (!isset($this->pages[$page])) { - $this->pages[$page] = $this->getObjFilename('page'.$page); - } - $this->writeDiskCache($this->pages[$page], $data, $append); - } else { - if ($append) { - $this->pages[$page] .= $data; - } else { - $this->pages[$page] = $data; - } - } - if ($append AND isset($this->pagelen[$page])) { - $this->pagelen[$page] += strlen($data); - } else { - $this->pagelen[$page] = strlen($data); - } - } - + protected function setPageBuffer($page, $data, $append=false) { + if ($this->diskcache) { + if (!isset($this->pages[$page])) { + $this->pages[$page] = $this->getObjFilename('page'.$page); + } + $this->writeDiskCache($this->pages[$page], $data, $append); + } else { + if ($append) { + $this->pages[$page] .= $data; + } else { + $this->pages[$page] = $data; + } + } + if ($append AND isset($this->pagelen[$page])) { + $this->pagelen[$page] += strlen($data); + } else { + $this->pagelen[$page] = strlen($data); + } + } + /** - * Get page buffer content. - * @param int $page page number - * @return string page buffer content or false in case of error + * Get page buffer content. + * @param int $page page number + * @return string page buffer content or false in case of error * @access protected * @since 4.5.000 (2008-12-31) */ - protected function getPageBuffer($page) { - if ($this->diskcache) { - return $this->readDiskCache($this->pages[$page]); - } elseif (isset($this->pages[$page])) { - return $this->pages[$page]; - } - return false; - } - + protected function getPageBuffer($page) { + if ($this->diskcache) { + return $this->readDiskCache($this->pages[$page]); + } elseif (isset($this->pages[$page])) { + return $this->pages[$page]; + } + return false; + } + /** - * Set image buffer content. - * @param string $image image key - * @param array $data image data + * Set image buffer content. + * @param string $image image key + * @param array $data image data * @access protected * @since 4.5.000 (2008-12-31) */ - protected function setImageBuffer($image, $data) { - if ($this->diskcache) { - if (!isset($this->images[$image])) { - $this->images[$image] = $this->getObjFilename('image'.$image); - } - $this->writeDiskCache($this->images[$image], serialize($data)); - } else { - $this->images[$image] = $data; - } - if (!in_array($image, $this->imagekeys)) { - $this->imagekeys[] = $image; - } - ++$this->numimages; - } - + protected function setImageBuffer($image, $data) { + if ($this->diskcache) { + if (!isset($this->images[$image])) { + $this->images[$image] = $this->getObjFilename('image'.$image); + } + $this->writeDiskCache($this->images[$image], serialize($data)); + } else { + $this->images[$image] = $data; + } + if (!in_array($image, $this->imagekeys)) { + $this->imagekeys[] = $image; + } + ++$this->numimages; + } + /** - * Set image buffer content. - * @param string $image image key - * @param string $key image sub-key - * @param array $data image data + * Set image buffer content. + * @param string $image image key + * @param string $key image sub-key + * @param array $data image data * @access protected * @since 4.5.000 (2008-12-31) */ - protected function setImageSubBuffer($image, $key, $data) { - if (!isset($this->images[$image])) { - $this->setImageBuffer($image, array()); - } - if ($this->diskcache) { - $tmpimg = $this->getImageBuffer($image); - $tmpimg[$key] = $data; - $this->writeDiskCache($this->images[$image], serialize($tmpimg)); - } else { - $this->images[$image][$key] = $data; - } - } - + protected function setImageSubBuffer($image, $key, $data) { + if (!isset($this->images[$image])) { + $this->setImageBuffer($image, array()); + } + if ($this->diskcache) { + $tmpimg = $this->getImageBuffer($image); + $tmpimg[$key] = $data; + $this->writeDiskCache($this->images[$image], serialize($tmpimg)); + } else { + $this->images[$image][$key] = $data; + } + } + /** - * Get page buffer content. - * @param string $image image key - * @return string image buffer content or false in case of error + * Get page buffer content. + * @param string $image image key + * @return string image buffer content or false in case of error * @access protected * @since 4.5.000 (2008-12-31) */ - protected function getImageBuffer($image) { - if ($this->diskcache AND isset($this->images[$image])) { - return unserialize($this->readDiskCache($this->images[$image])); - } elseif (isset($this->images[$image])) { - return $this->images[$image]; - } - return false; - } - + protected function getImageBuffer($image) { + if ($this->diskcache AND isset($this->images[$image])) { + return unserialize($this->readDiskCache($this->images[$image])); + } elseif (isset($this->images[$image])) { + return $this->images[$image]; + } + return false; + } + /** - * Set font buffer content. - * @param string $font font key - * @param array $data font data + * Set font buffer content. + * @param string $font font key + * @param array $data font data * @access protected * @since 4.5.000 (2009-01-02) */ - protected function setFontBuffer($font, $data) { - if ($this->diskcache) { - if (!isset($this->fonts[$font])) { - $this->fonts[$font] = $this->getObjFilename('font'); - } - $this->writeDiskCache($this->fonts[$font], serialize($data)); - } else { - $this->fonts[$font] = $data; - } - if (!in_array($font, $this->fontkeys)) { - $this->fontkeys[] = $font; - } - } - + protected function setFontBuffer($font, $data) { + if ($this->diskcache) { + if (!isset($this->fonts[$font])) { + $this->fonts[$font] = $this->getObjFilename('font'); + } + $this->writeDiskCache($this->fonts[$font], serialize($data)); + } else { + $this->fonts[$font] = $data; + } + if (!in_array($font, $this->fontkeys)) { + $this->fontkeys[] = $font; + } + } + /** - * Set font buffer content. - * @param string $font font key - * @param string $key font sub-key - * @param array $data font data + * Set font buffer content. + * @param string $font font key + * @param string $key font sub-key + * @param array $data font data * @access protected * @since 4.5.000 (2009-01-02) */ - protected function setFontSubBuffer($font, $key, $data) { - if (!isset($this->fonts[$font])) { - $this->setFontBuffer($font, array()); - } - if ($this->diskcache) { - $tmpfont = $this->getFontBuffer($font); - $tmpfont[$key] = $data; - $this->writeDiskCache($this->fonts[$font], serialize($tmpfont)); - } else { - $this->fonts[$font][$key] = $data; - } - } - + protected function setFontSubBuffer($font, $key, $data) { + if (!isset($this->fonts[$font])) { + $this->setFontBuffer($font, array()); + } + if ($this->diskcache) { + $tmpfont = $this->getFontBuffer($font); + $tmpfont[$key] = $data; + $this->writeDiskCache($this->fonts[$font], serialize($tmpfont)); + } else { + $this->fonts[$font][$key] = $data; + } + } + /** - * Get font buffer content. - * @param string $font font key - * @return string font buffer content or false in case of error + * Get font buffer content. + * @param string $font font key + * @return string font buffer content or false in case of error * @access protected * @since 4.5.000 (2009-01-02) */ - protected function getFontBuffer($font) { - if ($this->diskcache AND isset($this->fonts[$font])) { - return unserialize($this->readDiskCache($this->fonts[$font])); - } elseif (isset($this->fonts[$font])) { - return $this->fonts[$font]; - } - return false; - } - + protected function getFontBuffer($font) { + if ($this->diskcache AND isset($this->fonts[$font])) { + return unserialize($this->readDiskCache($this->fonts[$font])); + } elseif (isset($this->fonts[$font])) { + return $this->fonts[$font]; + } + return false; + } + /** - * Move a page to a previous position. - * @param int $frompage number of the source page - * @param int $topage number of the destination page (must be less than $frompage) - * @return true in case of success, false in case of error. + * Move a page to a previous position. + * @param int $frompage number of the source page + * @param int $topage number of the destination page (must be less than $frompage) + * @return true in case of success, false in case of error. * @access public * @since 4.5.000 (2009-01-02) */ - public function movePage($frompage, $topage) { - if (($frompage > $this->numpages) OR ($frompage <= $topage)) { - return false; - } - if ($frompage == $this->page) { - // close the page before moving it - $this->endPage(); - } - // move all page-related states - $tmppage = $this->pages[$frompage]; - $tmppagedim = $this->pagedim[$frompage]; - $tmppagelen = $this->pagelen[$frompage]; - $tmpintmrk = $this->intmrk[$frompage]; - if (isset($this->footerpos[$frompage])) { - $tmpfooterpos = $this->footerpos[$frompage]; - } - if (isset($this->footerlen[$frompage])) { - $tmpfooterlen = $this->footerlen[$frompage]; - } - if (isset($this->transfmrk[$frompage])) { - $tmptransfmrk = $this->transfmrk[$frompage]; - } - if (isset($this->PageAnnots[$frompage])) { - $tmpannots = $this->PageAnnots[$frompage]; - } - if (isset($this->newpagegroup[$frompage])) { - $tmpnewpagegroup = $this->newpagegroup[$frompage]; - } - for ($i = $frompage; $i > $topage; --$i) { - $j = $i - 1; - // shift pages down - $this->pages[$i] = $this->pages[$j]; - $this->pagedim[$i] = $this->pagedim[$j]; - $this->pagelen[$i] = $this->pagelen[$j]; - $this->intmrk[$i] = $this->intmrk[$j]; - if (isset($this->footerpos[$j])) { - $this->footerpos[$i] = $this->footerpos[$j]; - } elseif (isset($this->footerpos[$i])) { - unset($this->footerpos[$i]); - } - if (isset($this->footerlen[$j])) { - $this->footerlen[$i] = $this->footerlen[$j]; - } elseif (isset($this->footerlen[$i])) { - unset($this->footerlen[$i]); - } - if (isset($this->transfmrk[$j])) { - $this->transfmrk[$i] = $this->transfmrk[$j]; - } elseif (isset($this->transfmrk[$i])) { - unset($this->transfmrk[$i]); - } - if (isset($this->PageAnnots[$j])) { - $this->PageAnnots[$i] = $this->PageAnnots[$j]; - } elseif (isset($this->PageAnnots[$i])) { - unset($this->PageAnnots[$i]); - } - if (isset($this->newpagegroup[$j])) { - $this->newpagegroup[$i] = $this->newpagegroup[$j]; - } elseif (isset($this->newpagegroup[$i])) { - unset($this->newpagegroup[$i]); - } - } - $this->pages[$topage] = $tmppage; - $this->pagedim[$topage] = $tmppagedim; - $this->pagelen[$topage] = $tmppagelen; - $this->intmrk[$topage] = $tmpintmrk; - if (isset($tmpfooterpos)) { - $this->footerpos[$topage] = $tmpfooterpos; - } elseif (isset($this->footerpos[$topage])) { - unset($this->footerpos[$topage]); - } - if (isset($tmpfooterlen)) { - $this->footerlen[$topage] = $tmpfooterlen; - } elseif (isset($this->footerlen[$topage])) { - unset($this->footerlen[$topage]); - } - if (isset($tmptransfmrk)) { - $this->transfmrk[$topage] = $tmptransfmrk; - } elseif (isset($this->transfmrk[$topage])) { - unset($this->transfmrk[$topage]); - } - if (isset($tmpannots)) { - $this->PageAnnots[$topage] = $tmpannots; - } elseif (isset($this->PageAnnots[$topage])) { - unset($this->PageAnnots[$topage]); - } - if (isset($tmpnewpagegroup)) { - $this->newpagegroup[$topage] = $tmpnewpagegroup; - } elseif (isset($this->newpagegroup[$topage])) { - unset($this->newpagegroup[$topage]); - } - // adjust outlines - $tmpoutlines = $this->outlines; - foreach ($tmpoutlines as $key => $outline) { - if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) { - $this->outlines[$key]['p'] = $outline['p'] + 1; - } elseif ($outline['p'] == $frompage) { - $this->outlines[$key]['p'] = $topage; - } - } - // adjust links - $tmplinks = $this->links; - foreach ($tmplinks as $key => $link) { - if (($link[0] >= $topage) AND ($link[0] < $frompage)) { - $this->links[$key][0] = $link[0] + 1; - } elseif ($link[0] == $frompage) { - $this->links[$key][0] = $topage; - } - } - // adjust javascript - $tmpjavascript = $this->javascript; - global $jfrompage, $jtopage; - $jfrompage = $frompage; - $jtopage = $topage; - $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', - create_function('$matches', 'global $jfrompage, $jtopage; - $pagenum = intval($matches[3]) + 1; - if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) { - $newpage = ($pagenum + 1); - } elseif ($pagenum == $jfrompage) { - $newpage = $jtopage; - } else { - $newpage = $pagenum; - } - --$newpage; - return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); - // return to last page - $this->lastPage(true); - return true; - } - + public function movePage($frompage, $topage) { + if (($frompage > $this->numpages) OR ($frompage <= $topage)) { + return false; + } + if ($frompage == $this->page) { + // close the page before moving it + $this->endPage(); + } + // move all page-related states + $tmppage = $this->pages[$frompage]; + $tmppagedim = $this->pagedim[$frompage]; + $tmppagelen = $this->pagelen[$frompage]; + $tmpintmrk = $this->intmrk[$frompage]; + if (isset($this->footerpos[$frompage])) { + $tmpfooterpos = $this->footerpos[$frompage]; + } + if (isset($this->footerlen[$frompage])) { + $tmpfooterlen = $this->footerlen[$frompage]; + } + if (isset($this->transfmrk[$frompage])) { + $tmptransfmrk = $this->transfmrk[$frompage]; + } + if (isset($this->PageAnnots[$frompage])) { + $tmpannots = $this->PageAnnots[$frompage]; + } + if (isset($this->newpagegroup[$frompage])) { + $tmpnewpagegroup = $this->newpagegroup[$frompage]; + } + for ($i = $frompage; $i > $topage; --$i) { + $j = $i - 1; + // shift pages down + $this->pages[$i] = $this->pages[$j]; + $this->pagedim[$i] = $this->pagedim[$j]; + $this->pagelen[$i] = $this->pagelen[$j]; + $this->intmrk[$i] = $this->intmrk[$j]; + if (isset($this->footerpos[$j])) { + $this->footerpos[$i] = $this->footerpos[$j]; + } elseif (isset($this->footerpos[$i])) { + unset($this->footerpos[$i]); + } + if (isset($this->footerlen[$j])) { + $this->footerlen[$i] = $this->footerlen[$j]; + } elseif (isset($this->footerlen[$i])) { + unset($this->footerlen[$i]); + } + if (isset($this->transfmrk[$j])) { + $this->transfmrk[$i] = $this->transfmrk[$j]; + } elseif (isset($this->transfmrk[$i])) { + unset($this->transfmrk[$i]); + } + if (isset($this->PageAnnots[$j])) { + $this->PageAnnots[$i] = $this->PageAnnots[$j]; + } elseif (isset($this->PageAnnots[$i])) { + unset($this->PageAnnots[$i]); + } + if (isset($this->newpagegroup[$j])) { + $this->newpagegroup[$i] = $this->newpagegroup[$j]; + } elseif (isset($this->newpagegroup[$i])) { + unset($this->newpagegroup[$i]); + } + } + $this->pages[$topage] = $tmppage; + $this->pagedim[$topage] = $tmppagedim; + $this->pagelen[$topage] = $tmppagelen; + $this->intmrk[$topage] = $tmpintmrk; + if (isset($tmpfooterpos)) { + $this->footerpos[$topage] = $tmpfooterpos; + } elseif (isset($this->footerpos[$topage])) { + unset($this->footerpos[$topage]); + } + if (isset($tmpfooterlen)) { + $this->footerlen[$topage] = $tmpfooterlen; + } elseif (isset($this->footerlen[$topage])) { + unset($this->footerlen[$topage]); + } + if (isset($tmptransfmrk)) { + $this->transfmrk[$topage] = $tmptransfmrk; + } elseif (isset($this->transfmrk[$topage])) { + unset($this->transfmrk[$topage]); + } + if (isset($tmpannots)) { + $this->PageAnnots[$topage] = $tmpannots; + } elseif (isset($this->PageAnnots[$topage])) { + unset($this->PageAnnots[$topage]); + } + if (isset($tmpnewpagegroup)) { + $this->newpagegroup[$topage] = $tmpnewpagegroup; + } elseif (isset($this->newpagegroup[$topage])) { + unset($this->newpagegroup[$topage]); + } + // adjust outlines + $tmpoutlines = $this->outlines; + foreach ($tmpoutlines as $key => $outline) { + if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) { + $this->outlines[$key]['p'] = $outline['p'] + 1; + } elseif ($outline['p'] == $frompage) { + $this->outlines[$key]['p'] = $topage; + } + } + // adjust links + $tmplinks = $this->links; + foreach ($tmplinks as $key => $link) { + if (($link[0] >= $topage) AND ($link[0] < $frompage)) { + $this->links[$key][0] = $link[0] + 1; + } elseif ($link[0] == $frompage) { + $this->links[$key][0] = $topage; + } + } + // adjust javascript + $tmpjavascript = $this->javascript; + global $jfrompage, $jtopage; + $jfrompage = $frompage; + $jtopage = $topage; + $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', + create_function('$matches', 'global $jfrompage, $jtopage; + $pagenum = intval($matches[3]) + 1; + if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) { + $newpage = ($pagenum + 1); + } elseif ($pagenum == $jfrompage) { + $newpage = $jtopage; + } else { + $newpage = $pagenum; + } + --$newpage; + return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); + // return to last page + $this->lastPage(true); + return true; + } + /** - * Remove the specified page. - * @param int $page page to remove - * @return true in case of success, false in case of error. + * Remove the specified page. + * @param int $page page to remove + * @return true in case of success, false in case of error. * @access public * @since 4.6.004 (2009-04-23) */ - public function deletePage($page) { - if ($page > $this->numpages) { - return false; - } - // delete current page - unset($this->pages[$page]); - unset($this->pagedim[$page]); - unset($this->pagelen[$page]); - unset($this->intmrk[$page]); - if (isset($this->footerpos[$page])) { - unset($this->footerpos[$page]); - } - if (isset($this->footerlen[$page])) { - unset($this->footerlen[$page]); - } - if (isset($this->transfmrk[$page])) { - unset($this->transfmrk[$page]); - } - if (isset($this->PageAnnots[$page])) { - unset($this->PageAnnots[$page]); - } - if (isset($this->newpagegroup[$page])) { - unset($this->newpagegroup[$page]); - } - if (isset($this->pageopen[$page])) { - unset($this->pageopen[$page]); - } - // update remaining pages - for ($i = $page; $i < $this->numpages; ++$i) { - $j = $i + 1; - // shift pages - $this->pages[$i] = $this->pages[$j]; - $this->pagedim[$i] = $this->pagedim[$j]; - $this->pagelen[$i] = $this->pagelen[$j]; - $this->intmrk[$i] = $this->intmrk[$j]; - if (isset($this->footerpos[$j])) { - $this->footerpos[$i] = $this->footerpos[$j]; - } elseif (isset($this->footerpos[$i])) { - unset($this->footerpos[$i]); - } - if (isset($this->footerlen[$j])) { - $this->footerlen[$i] = $this->footerlen[$j]; - } elseif (isset($this->footerlen[$i])) { - unset($this->footerlen[$i]); - } - if (isset($this->transfmrk[$j])) { - $this->transfmrk[$i] = $this->transfmrk[$j]; - } elseif (isset($this->transfmrk[$i])) { - unset($this->transfmrk[$i]); - } - if (isset($this->PageAnnots[$j])) { - $this->PageAnnots[$i] = $this->PageAnnots[$j]; - } elseif (isset($this->PageAnnots[$i])) { - unset($this->PageAnnots[$i]); - } - if (isset($this->newpagegroup[$j])) { - $this->newpagegroup[$i] = $this->newpagegroup[$j]; - } elseif (isset($this->newpagegroup[$i])) { - unset($this->newpagegroup[$i]); - } - if (isset($this->pageopen[$j])) { - $this->pageopen[$i] = $this->pageopen[$j]; - } elseif (isset($this->pageopen[$i])) { - unset($this->pageopen[$i]); - } - } - // remove last page - unset($this->pages[$this->numpages]); - unset($this->pagedim[$this->numpages]); - unset($this->pagelen[$this->numpages]); - unset($this->intmrk[$this->numpages]); - if (isset($this->footerpos[$this->numpages])) { - unset($this->footerpos[$this->numpages]); - } - if (isset($this->footerlen[$this->numpages])) { - unset($this->footerlen[$this->numpages]); - } - if (isset($this->transfmrk[$this->numpages])) { - unset($this->transfmrk[$this->numpages]); - } - if (isset($this->PageAnnots[$this->numpages])) { - unset($this->PageAnnots[$this->numpages]); - } - if (isset($this->newpagegroup[$this->numpages])) { - unset($this->newpagegroup[$this->numpages]); - } - if (isset($this->pageopen[$this->numpages])) { - unset($this->pageopen[$this->numpages]); - } - --$this->numpages; - $this->page = $this->numpages; - // adjust outlines - $tmpoutlines = $this->outlines; - foreach ($tmpoutlines as $key => $outline) { - if ($outline['p'] > $page) { - $this->outlines[$key]['p'] = $outline['p'] - 1; - } elseif ($outline['p'] == $page) { - unset($this->outlines[$key]); - } - } - // adjust links - $tmplinks = $this->links; - foreach ($tmplinks as $key => $link) { - if ($link[0] > $page) { - $this->links[$key][0] = $link[0] - 1; - } elseif ($link[0] == $page) { - unset($this->links[$key]); - } - } - // adjust javascript - $tmpjavascript = $this->javascript; - global $jpage; - $jpage = $page; - $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', - create_function('$matches', 'global $jpage; - $pagenum = intval($matches[3]) + 1; - if ($pagenum >= $jpage) { - $newpage = ($pagenum - 1); - } elseif ($pagenum == $jpage) { - $newpage = 1; - } else { - $newpage = $pagenum; - } - --$newpage; - return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); - // return to last page - $this->lastPage(true); - return true; - } - - /** - * Output a Table of Content Index (TOC). - * You can override this method to achieve different styles. - * @param int $page page number where this TOC should be inserted (leave empty for current page). - * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment). + public function deletePage($page) { + if ($page > $this->numpages) { + return false; + } + // delete current page + unset($this->pages[$page]); + unset($this->pagedim[$page]); + unset($this->pagelen[$page]); + unset($this->intmrk[$page]); + if (isset($this->footerpos[$page])) { + unset($this->footerpos[$page]); + } + if (isset($this->footerlen[$page])) { + unset($this->footerlen[$page]); + } + if (isset($this->transfmrk[$page])) { + unset($this->transfmrk[$page]); + } + if (isset($this->PageAnnots[$page])) { + unset($this->PageAnnots[$page]); + } + if (isset($this->newpagegroup[$page])) { + unset($this->newpagegroup[$page]); + } + if (isset($this->pageopen[$page])) { + unset($this->pageopen[$page]); + } + // update remaining pages + for ($i = $page; $i < $this->numpages; ++$i) { + $j = $i + 1; + // shift pages + $this->pages[$i] = $this->pages[$j]; + $this->pagedim[$i] = $this->pagedim[$j]; + $this->pagelen[$i] = $this->pagelen[$j]; + $this->intmrk[$i] = $this->intmrk[$j]; + if (isset($this->footerpos[$j])) { + $this->footerpos[$i] = $this->footerpos[$j]; + } elseif (isset($this->footerpos[$i])) { + unset($this->footerpos[$i]); + } + if (isset($this->footerlen[$j])) { + $this->footerlen[$i] = $this->footerlen[$j]; + } elseif (isset($this->footerlen[$i])) { + unset($this->footerlen[$i]); + } + if (isset($this->transfmrk[$j])) { + $this->transfmrk[$i] = $this->transfmrk[$j]; + } elseif (isset($this->transfmrk[$i])) { + unset($this->transfmrk[$i]); + } + if (isset($this->PageAnnots[$j])) { + $this->PageAnnots[$i] = $this->PageAnnots[$j]; + } elseif (isset($this->PageAnnots[$i])) { + unset($this->PageAnnots[$i]); + } + if (isset($this->newpagegroup[$j])) { + $this->newpagegroup[$i] = $this->newpagegroup[$j]; + } elseif (isset($this->newpagegroup[$i])) { + unset($this->newpagegroup[$i]); + } + if (isset($this->pageopen[$j])) { + $this->pageopen[$i] = $this->pageopen[$j]; + } elseif (isset($this->pageopen[$i])) { + unset($this->pageopen[$i]); + } + } + // remove last page + unset($this->pages[$this->numpages]); + unset($this->pagedim[$this->numpages]); + unset($this->pagelen[$this->numpages]); + unset($this->intmrk[$this->numpages]); + if (isset($this->footerpos[$this->numpages])) { + unset($this->footerpos[$this->numpages]); + } + if (isset($this->footerlen[$this->numpages])) { + unset($this->footerlen[$this->numpages]); + } + if (isset($this->transfmrk[$this->numpages])) { + unset($this->transfmrk[$this->numpages]); + } + if (isset($this->PageAnnots[$this->numpages])) { + unset($this->PageAnnots[$this->numpages]); + } + if (isset($this->newpagegroup[$this->numpages])) { + unset($this->newpagegroup[$this->numpages]); + } + if (isset($this->pageopen[$this->numpages])) { + unset($this->pageopen[$this->numpages]); + } + --$this->numpages; + $this->page = $this->numpages; + // adjust outlines + $tmpoutlines = $this->outlines; + foreach ($tmpoutlines as $key => $outline) { + if ($outline['p'] > $page) { + $this->outlines[$key]['p'] = $outline['p'] - 1; + } elseif ($outline['p'] == $page) { + unset($this->outlines[$key]); + } + } + // adjust links + $tmplinks = $this->links; + foreach ($tmplinks as $key => $link) { + if ($link[0] > $page) { + $this->links[$key][0] = $link[0] - 1; + } elseif ($link[0] == $page) { + unset($this->links[$key]); + } + } + // adjust javascript + $tmpjavascript = $this->javascript; + global $jpage; + $jpage = $page; + $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', + create_function('$matches', 'global $jpage; + $pagenum = intval($matches[3]) + 1; + if ($pagenum >= $jpage) { + $newpage = ($pagenum - 1); + } elseif ($pagenum == $jpage) { + $newpage = 1; + } else { + $newpage = $pagenum; + } + --$newpage; + return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript); + // return to last page + $this->lastPage(true); + return true; + } + + /** + * Output a Table of Content Index (TOC). + * You can override this method to achieve different styles. + * @param int $page page number where this TOC should be inserted (leave empty for current page). + * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment). * @param string $filler string used to fill the space between text and page number. * @access public * @author Nicola Asuni * @since 4.5.000 (2009-01-02) */ public function addTOC($page='', $numbersfont='', $filler='.') { - $fontsize = $this->FontSizePt; + $fontsize = $this->FontSizePt; $fontfamily = $this->FontFamily; - $fontstyle = $this->FontStyle; - $w = $this->w - $this->lMargin - $this->rMargin; - $spacer = $this->GetStringWidth(' ') * 4; - $page_first = $this->getPage(); - $lmargin = $this->lMargin; - $rmargin = $this->rMargin; - $x_start = $this->GetX(); - if ($this->empty_string($numbersfont)) { - $numbersfont = $this->default_monospaced_font; - } - if ($this->empty_string($filler)) { - $filler = ' '; - } - if ($this->empty_string($page)) { - $gap = ' '; - } else { - $gap = ''; - } - foreach ($this->outlines as $key => $outline) { - if ($this->rtl) { - $aligntext = 'R'; - $alignnum = 'L'; - } else { - $aligntext = 'L'; - $alignnum = 'R'; - } - if ($outline['l'] == 0) { - $this->SetFont($fontfamily, $fontstyle.'B', $fontsize); - } else { - $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']); - } - $indent = ($spacer * $outline['l']); - if ($this->rtl) { - $this->rMargin += $indent; - $this->x -= $indent; - } else { - $this->lMargin += $indent; - $this->x += $indent; - } - $link = $this->AddLink(); - $this->SetLink($link, 0, $outline['p']); - // write the text - $this->Write(0, $outline['t'], $link, 0, $aligntext, false, 0, false, false, 0); - $this->SetFont($numbersfont, $fontstyle, $fontsize); - if ($this->empty_string($page)) { - $pagenum = $outline['p']; - } else { - // placemark to be replaced with the correct number - $pagenum = '{#'.($outline['p']).'}'; + $fontstyle = $this->FontStyle; + $w = $this->w - $this->lMargin - $this->rMargin; + $spacer = $this->GetStringWidth(' ') * 4; + $page_first = $this->getPage(); + $lmargin = $this->lMargin; + $rmargin = $this->rMargin; + $x_start = $this->GetX(); + if ($this->empty_string($numbersfont)) { + $numbersfont = $this->default_monospaced_font; + } + if ($this->empty_string($filler)) { + $filler = ' '; + } + if ($this->empty_string($page)) { + $gap = ' '; + } else { + $gap = ''; + } + foreach ($this->outlines as $key => $outline) { + if ($this->rtl) { + $aligntext = 'R'; + $alignnum = 'L'; + } else { + $aligntext = 'L'; + $alignnum = 'R'; + } + if ($outline['l'] == 0) { + $this->SetFont($fontfamily, $fontstyle.'B', $fontsize); + } else { + $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']); + } + $indent = ($spacer * $outline['l']); + if ($this->rtl) { + $this->rMargin += $indent; + $this->x -= $indent; + } else { + $this->lMargin += $indent; + $this->x += $indent; + } + $link = $this->AddLink(); + $this->SetLink($link, 0, $outline['p']); + // write the text + $this->Write(0, $outline['t'], $link, 0, $aligntext, false, 0, false, false, 0); + $this->SetFont($numbersfont, $fontstyle, $fontsize); + if ($this->empty_string($page)) { + $pagenum = $outline['p']; + } else { + // placemark to be replaced with the correct number + $pagenum = '{#'.($outline['p']).'}'; if (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0')) { $pagenum = '{'.$pagenum.'}'; - } - } - $numwidth = $this->GetStringWidth($pagenum); - if ($this->rtl) { - $tw = $this->x - $this->lMargin; - } else { - $tw = $this->w - $this->rMargin - $this->x; - } - $fw = $tw - $numwidth - $this->GetStringWidth(' '); - $numfills = floor($fw / $this->GetStringWidth($filler)); - if ($numfills > 0) { - $rowfill = str_repeat($filler, $numfills); - } else { - $rowfill = ''; - } - if ($this->rtl) { - $pagenum = $pagenum.$gap.$rowfill.' '; - } else { - $pagenum = ' '.$rowfill.$gap.$pagenum; - } + } + } + $numwidth = $this->GetStringWidth($pagenum); + if ($this->rtl) { + $tw = $this->x - $this->lMargin; + } else { + $tw = $this->w - $this->rMargin - $this->x; + } + $fw = $tw - $numwidth - $this->GetStringWidth(' '); + $numfills = floor($fw / $this->GetStringWidth($filler)); + if ($numfills > 0) { + $rowfill = str_repeat($filler, $numfills); + } else { + $rowfill = ''; + } + if ($this->rtl) { + $pagenum = $pagenum.$gap.$rowfill.' '; + } else { + $pagenum = ' '.$rowfill.$gap.$pagenum; + } // write the number - //$this->SetX($x_start); - $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0); - $this->SetX($x_start); - $this->lMargin = $lmargin; - $this->rMargin = $rmargin; - } - $page_last = $this->getPage(); - $numpages = $page_last - $page_first + 1; - if (!$this->empty_string($page)) { - for ($p = $page_first; $p <= $page_last; ++$p) { - // get page data - $temppage = $this->getPageBuffer($p); - for ($n = 1; $n <= $this->numpages; ++$n) { - // update page numbers - $k = '{#'.$n.'}'; - $ku = '{'.$k.'}'; + //$this->SetX($x_start); + $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0); + $this->SetX($x_start); + $this->lMargin = $lmargin; + $this->rMargin = $rmargin; + } + $page_last = $this->getPage(); + $numpages = $page_last - $page_first + 1; + if (!$this->empty_string($page)) { + for ($p = $page_first; $p <= $page_last; ++$p) { + // get page data + $temppage = $this->getPageBuffer($p); + for ($n = 1; $n <= $this->numpages; ++$n) { + // update page numbers + $k = '{#'.$n.'}'; + $ku = '{'.$k.'}'; $alias_a = $this->_escape($k); $alias_au = $this->_escape('{'.$k.'}'); if ($this->isunicode) { @@ -13862,25 +13862,25 @@ public function addTOC($page='', $numbersfont='', $filler='.') { $alias_bu = $this->_escape($this->UTF8ToLatin1($ku)); $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl)); $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl)); - } - if ($n >= $page) { - $np = $n + $numpages; - } else { - $np = $n; - } - $ns = $this->formatTOCPageNumber($np); - $nu = $ns; - $sdiff = strlen($k) - strlen($ns) - 1; - $sdiffu = strlen($ku) - strlen($ns) - 1; - $sfill = str_repeat($filler, $sdiff); - $sfillu = str_repeat($filler, $sdiffu); - if ($this->rtl) { - $ns = $ns.' '.$sfill; - $nu = $nu.' '.$sfillu; - } else { - $ns = $sfill.' '.$ns; - $nu = $sfillu.' '.$nu; - } + } + if ($n >= $page) { + $np = $n + $numpages; + } else { + $np = $n; + } + $ns = $this->formatTOCPageNumber($np); + $nu = $ns; + $sdiff = strlen($k) - strlen($ns) - 1; + $sdiffu = strlen($ku) - strlen($ns) - 1; + $sfill = str_repeat($filler, $sdiff); + $sfillu = str_repeat($filler, $sdiffu); + if ($this->rtl) { + $ns = $ns.' '.$sfill; + $nu = $nu.' '.$sfillu; + } else { + $ns = $sfill.' '.$ns; + $nu = $sfillu.' '.$nu; + } $nu = $this->UTF8ToUTF16BE($nu, false); $temppage = str_replace($alias_au, $nu, $temppage); if ($this->isunicode) { @@ -13889,92 +13889,92 @@ public function addTOC($page='', $numbersfont='', $filler='.') { $temppage = str_replace($alias_b, $ns, $temppage); $temppage = str_replace($alias_c, $ns, $temppage); } - $temppage = str_replace($alias_a, $ns, $temppage); - } - // save changes - $this->setPageBuffer($p, $temppage); - } - // move pages - for ($i = 0; $i < $numpages; ++$i) { - $this->movePage($page_last, $page); - } - } + $temppage = str_replace($alias_a, $ns, $temppage); + } + // save changes + $this->setPageBuffer($p, $temppage); + } + // move pages + for ($i = 0; $i < $numpages; ++$i) { + $this->movePage($page_last, $page); + } + } $this->SetFont($fontfamily, $fontstyle, $fontsize); - } - + } + /** - * Stores a copy of the current TCPDF object used for undo operation. + * Stores a copy of the current TCPDF object used for undo operation. * @access public * @since 4.5.029 (2009-03-19) - */ - public function startTransaction() { - if (isset($this->objcopy)) { - // remove previous copy - $this->commitTransaction(); - } - // clone current object - $this->objcopy = $this->objclone($this); - } - - /** - * Delete the copy of the current TCPDF object used for undo operation. + */ + public function startTransaction() { + if (isset($this->objcopy)) { + // remove previous copy + $this->commitTransaction(); + } + // clone current object + $this->objcopy = $this->objclone($this); + } + + /** + * Delete the copy of the current TCPDF object used for undo operation. * @access public * @since 4.5.029 (2009-03-19) - */ - public function commitTransaction() { - if (isset($this->objcopy)) { - $this->objcopy->_destroy(true, true); - unset($this->objcopy); - } - } - - /** - * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction(). + */ + public function commitTransaction() { + if (isset($this->objcopy)) { + $this->objcopy->_destroy(true, true); + unset($this->objcopy); + } + } + + /** + * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction(). * @return TCPDF object. * @access public * @since 4.5.029 (2009-03-19) - */ - public function rollbackTransaction() { - if (isset($this->objcopy)) { - if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) { - // truncate files to previous values - foreach ($this->objcopy->cache_file_lenght as $file => $lenght) { - $file = substr($file, 1); - $handle = fopen($file, 'r+'); - ftruncate($handle, $lenght); - } - } - $this->_destroy(true, true); - return $this->objcopy; - } - return $this; - } - - /** - * Creates a copy of a class object - * @param object $object class object to be cloned - * @return cloned object - * @access public - * @since 4.5.029 (2009-03-19) - */ - public function objclone($object) { - return @clone($object); - } - - /** - * Determine whether a string is empty. - * @param srting $str string to be checked - * @return boolean true if string is empty - * @access public - * @since 4.5.044 (2009-04-16) - */ - public function empty_string($str) { - return (is_null($str) OR (is_string($str) AND (strlen($str) == 0))); - } + */ + public function rollbackTransaction() { + if (isset($this->objcopy)) { + if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) { + // truncate files to previous values + foreach ($this->objcopy->cache_file_lenght as $file => $lenght) { + $file = substr($file, 1); + $handle = fopen($file, 'r+'); + ftruncate($handle, $lenght); + } + } + $this->_destroy(true, true); + return $this->objcopy; + } + return $this; + } + + /** + * Creates a copy of a class object + * @param object $object class object to be cloned + * @return cloned object + * @access public + * @since 4.5.029 (2009-03-19) + */ + public function objclone($object) { + return @clone($object); + } + + /** + * Determine whether a string is empty. + * @param srting $str string to be checked + * @return boolean true if string is empty + * @access public + * @since 4.5.044 (2009-04-16) + */ + public function empty_string($str) { + return (is_null($str) OR (is_string($str) AND (strlen($str) == 0))); + } } // END OF TCPDF CLASS } //============================================================+ // END OF FILE //============================================================+ -?> +?> diff --git a/admin/update/upgrade-postgres.php b/admin/update/upgrade-postgres.php index b3d6591958f..90e01bd6828 100644 --- a/admin/update/upgrade-postgres.php +++ b/admin/update/upgrade-postgres.php @@ -253,7 +253,7 @@ function upgrade_survey_tables139() function upgrade_question_attributes142() { global $modifyoutput,$dbprefix, $connect; - $attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 "; + $attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 "; $questionids = db_select_column($attributequery); foreach ($questionids as $questionid) { diff --git a/classes/adodb/adodb-xmlschema.inc.php b/classes/adodb/adodb-xmlschema.inc.php index b2f0ddc5ca4..ff1de9a6ef2 100644 --- a/classes/adodb/adodb-xmlschema.inc.php +++ b/classes/adodb/adodb-xmlschema.inc.php @@ -1304,7 +1304,7 @@ class adoSchema { function adoSchema( &$db ) { // Initialize the environment $this->mgq = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); + @set_magic_quotes_runtime(0); $this->db = $db; $this->debug = $this->db->debug; @@ -2193,7 +2193,7 @@ function getSQL( $format = NULL, $sqlArray = NULL ) { * @deprecated adoSchema now cleans up automatically. */ function Destroy() { - set_magic_quotes_runtime( $this->mgq ); + @set_magic_quotes_runtime( $this->mgq ); unset( $this ); } } diff --git a/classes/adodb/adodb-xmlschema03.inc.php b/classes/adodb/adodb-xmlschema03.inc.php index cbd49b9d859..085a98d27f8 100644 --- a/classes/adodb/adodb-xmlschema03.inc.php +++ b/classes/adodb/adodb-xmlschema03.inc.php @@ -1408,7 +1408,7 @@ class adoSchema { function adoSchema( &$db ) { // Initialize the environment $this->mgq = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); + @set_magic_quotes_runtime(0); $this->db = $db; $this->debug = $this->db->debug; @@ -2374,7 +2374,7 @@ function getSQL( $format = NULL, $sqlArray = NULL ) { * @deprecated adoSchema now cleans up automatically. */ function Destroy() { - set_magic_quotes_runtime( $this->mgq ); + @set_magic_quotes_runtime( $this->mgq ); unset( $this ); } } diff --git a/classes/phpmailer/class.phpmailer.php b/classes/phpmailer/class.phpmailer.php index ac3dd23ff08..230453d9145 100644 --- a/classes/phpmailer/class.phpmailer.php +++ b/classes/phpmailer/class.phpmailer.php @@ -1467,11 +1467,11 @@ function get_magic_quotes() { } if (PHP_VERSION < 6) { $magic_quotes = get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); + @set_magic_quotes_runtime(0); } $file_buffer = file_get_contents($path); $file_buffer = $this->EncodeString($file_buffer, $encoding); - if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } + if (PHP_VERSION < 6) { @set_magic_quotes_runtime($magic_quotes); } return $file_buffer; } catch (Exception $e) { $this->SetError($e->getMessage());