com-tecnick-tcpdf
[ class tree: com-tecnick-tcpdf ] [ index: com-tecnick-tcpdf ] [ all elements ]

Source for file tcpdf.php

Documentation is available at tcpdf.php

  1. <?php
  2. //============================================================+
  3. // File name   : tcpdf.php
  4. // Begin       : 2002-08-03
  5. // Last Update : 2009-09-30
  6. // Author      : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version     : 4.8.009
  8. // License     : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. //     ----------------------------------------------------------------------------
  10. //  Copyright (C) 2002-2009  Nicola Asuni - Tecnick.com S.r.l.
  11. //     
  12. //     This program is free software: you can redistribute it and/or modify
  13. //     it under the terms of the GNU Lesser General Public License as published by
  14. //     the Free Software Foundation, either version 2.1 of the License, or
  15. //     (at your option) any later version.
  16. //     
  17. //     This program is distributed in the hope that it will be useful,
  18. //     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. //     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. //     GNU Lesser General Public License for more details.
  21. //     
  22. //     You should have received a copy of the GNU Lesser General Public License
  23. //     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24. //     
  25. //     See LICENSE.TXT file for more information.
  26. //  ----------------------------------------------------------------------------
  27. //
  28. // Description : This is a PHP class for generating PDF documents without 
  29. //               requiring external extensions.
  30. //
  31. // NOTE:
  32. // This class was originally derived in 2002 from the Public 
  33. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org), 
  34. // but now is almost entirely rewritten.
  35. //
  36. // Main features:
  37. //  * no external libraries are required for the basic functions;
  38. //     * supports all ISO page formats;
  39. //     * supports custom page formats, margins and units of measure;
  40. //     * supports UTF-8 Unicode and Right-To-Left languages;
  41. //     * supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  42. //     * supports document encryption;
  43. //     * includes methods to publish some XHTML code, including forms;
  44. //     * includes graphic (geometric) and transformation methods;
  45. //     * includes Javascript and Forms support;
  46. //     * 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;
  47. //     * includes methods to set Bookmarks and print a Table of Content;
  48. //     * includes methods to move and delete pages;
  49. //     * includes methods for automatic page header and footer management;
  50. //     * supports automatic page break;
  51. //     * supports automatic page numbering and page groups;
  52. //     * supports automatic line break and text justification;
  53. //     * supports JPEG and PNG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)
  54. //     * supports stroke and clipping mode for text;
  55. //     * supports clipping masks;
  56. //     * supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  57. //     * supports several annotations, including links, text and file attachments;
  58. //     * supports page compression (requires zlib extension);
  59. //  * supports text hyphenation.
  60. //  * supports transactions to UNDO commands.
  61. //  * supports signature certifications.
  62. //
  63. // -----------------------------------------------------------
  64. // THANKS TO:
  65. // 
  66. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  67. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  68. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  69. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  70. // dullus for text Justification.
  71. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  72. // Patrick Benny for text stretch suggestion on Cell().
  73. // Johannes Güntert for JavaScript support.
  74. // Denis Van Nuffelen for Dynamic Form.
  75. // Jacek Czekaj for multibyte justification
  76. // Anthony Ferrara for the reintroduction of legacy image methods.
  77. // Sourceforge user 1707880 (hucste) for line-trough mode.
  78. // Larry Stanbery for page groups.
  79. // Martin Hall-May for transparency.
  80. // Aaron C. Spike for Polycurve method.
  81. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  82. // Moritz Wagner and Andreas Wurmser for graphic functions.
  83. // Andrew Whitehead for core fonts support.
  84. // Esteban Joël Marín for OpenType font conversion.
  85. // Teus Hagen for several suggestions and fixes.
  86. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  87. // Kosmas Papachristos for some CSS improvements.
  88. // Marcel Partap for some fixes.
  89. // Won Kyu Park for several suggestions, fixes and patches.
  90. // Anyone that has reported a bug or sent a suggestion.
  91. //============================================================+
  92.  
  93. /**
  94.  * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  95.  * 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.<br>
  96.  * <h3>TCPDF main features are:</h3>
  97.  * <ul>
  98. * <li>no external libraries are required for the basic functions;</li>
  99. * <li>supports all ISO page formats;</li>
  100. * <li>supports custom page formats, margins and units of measure;</li>
  101. * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  102. * <li>supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  103. * <li>supports document encryption;</li>
  104. * <li>includes methods to publish some XHTML code, including forms;</li>
  105. * <li>includes graphic (geometric) and transformation methods;</li>
  106. * <li>includes Javascript and Forms support;</li>
  107. * <li>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;</li>
  108. * <li>includes methods to set Bookmarks and print a Table of Content;</li>
  109. * <li>includes methods to move and delete pages;</li>
  110. * <li>includes methods for automatic page header and footer management;</li>
  111. * <li>supports automatic page break;</li>
  112. * <li>supports automatic page numbering and page groups;</li>
  113. * <li>supports automatic line break and text justification;</li>
  114. * <li>supports JPEG and PNG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
  115. * <li>supports stroke and clipping mode for text;</li>
  116. * <li>supports clipping masks;</li>
  117. * <li>supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  118. * <li>supports several annotations, including links, text and file attachments;</li>
  119. * <li>supports page compression (requires zlib extension);</li>
  120. * <li>supports text hyphenation.</li>
  121. * <li>supports transactions to UNDO commands.</li>
  122. * <li>supports signature certifications.</li>
  123.  * </ul>
  124.  * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  125.  * @package com.tecnick.tcpdf
  126.  * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  127.  * @author Nicola Asuni
  128.  * @copyright 2002-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  129.  * @link http://www.tcpdf.org
  130.  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  131.  * @version 4.8.009
  132.  */
  133.  
  134. /**
  135.  * main configuration file
  136.  */
  137. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  138.  
  139. // includes some support files
  140.  
  141. /**
  142.  * unicode data
  143.  */
  144. require_once(dirname(__FILE__).'/unicode_data.php');
  145.  
  146. /**
  147.  * html colors table
  148.  */
  149. require_once(dirname(__FILE__).'/htmlcolors.php');
  150.  
  151. if (!class_exists('TCPDF'false)) {
  152.     /**
  153.      * define default PDF document producer
  154.      */ 
  155.     define('PDF_PRODUCER''TCPDF 4.8.009 (http://www.tcpdf.org)');
  156.     
  157.     /**
  158.     * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  159.     * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  160.     * @name TCPDF
  161.     * @package com.tecnick.tcpdf
  162.     * @version 4.8.009
  163.     * @author Nicola Asuni - info@tecnick.com
  164.     * @link http://www.tcpdf.org
  165.     * @license http://www.gnu.org/copyleft/lesser.html LGPL
  166.     */
  167.     class TCPDF {
  168.         
  169.         // protected or Protected properties
  170.  
  171.         /**
  172.         * @var current page number
  173.         * @access protected
  174.         */
  175.         protected $page;
  176.         
  177.         /**
  178.         * @var current object number
  179.         * @access protected
  180.         */
  181.         protected $n;
  182.  
  183.         /**
  184.         * @var array of object offsets
  185.         * @access protected
  186.         */
  187.         protected $offsets;
  188.  
  189.         /**
  190.         * @var buffer holding in-memory PDF
  191.         * @access protected
  192.         */
  193.         protected $buffer;
  194.  
  195.         /**
  196.         * @var array containing pages
  197.         * @access protected
  198.         */
  199.         protected $pages = array();
  200.  
  201.         /**
  202.         * @var current document state
  203.         * @access protected
  204.         */
  205.         protected $state;
  206.  
  207.         /**
  208.         * @var compression flag
  209.         * @access protected
  210.         */
  211.         protected $compress;
  212.         
  213.         /**
  214.         * @var current page orientation (P = Portrait, L = Landscape)
  215.         * @access protected
  216.         */
  217.         protected $CurOrientation;
  218.  
  219.         /**
  220.         * @var array that stores page dimensions and graphic status.<ul><li>$this->pagedim[$this->page]['w'] => page_width_in_points</li><li>$this->pagedim[$this->page]['h'] => height in points</li><li>$this->pagedim[$this->page]['wk'] => page_width_in_points</li><li>$this->pagedim[$this->page]['hk'] => height</li><li>$this->pagedim[$this->page]['tm'] => top_margin</li><li>$this->pagedim[$this->page]['bm'] => bottom_margin</li><li>$this->pagedim[$this->page]['lm'] => left_margin</li><li>$this->pagedim[$this->page]['rm'] => right_margin</li><li>$this->pagedim[$this->page]['pb'] => auto_page_break</li><li>$this->pagedim[$this->page]['or'] => page_orientation</li><li>$this->pagedim[$this->page]['olm'] => original_left_margin</li><li>$this->pagedim[$this->page]['orm'] => original_right_margin</li></ul>
  221.         * @access protected
  222.         */
  223.         protected $pagedim = array();
  224.  
  225.         /**
  226.         * @var scale factor (number of points in user unit)
  227.         * @access protected
  228.         */
  229.         protected $k;
  230.  
  231.         /**
  232.         * @var width of page format in points
  233.         * @access protected
  234.         */
  235.         protected $fwPt;
  236.  
  237.         /**
  238.         * @var height of page format in points
  239.         * @access protected
  240.         */
  241.         protected $fhPt;
  242.  
  243.         /**
  244.         * @var current width of page in points
  245.         * @access protected
  246.         */
  247.         protected $wPt;
  248.  
  249.         /**
  250.         * @var current height of page in points
  251.         * @access protected
  252.         */
  253.         protected $hPt;
  254.  
  255.         /**
  256.         * @var current width of page in user unit
  257.         * @access protected
  258.         */
  259.         protected $w;
  260.  
  261.         /**
  262.         * @var current height of page in user unit
  263.         * @access protected
  264.         */
  265.         protected $h;
  266.  
  267.         /**
  268.         * @var left margin
  269.         * @access protected
  270.         */
  271.         protected $lMargin;
  272.  
  273.         /**
  274.         * @var top margin
  275.         * @access protected
  276.         */
  277.         protected $tMargin;
  278.  
  279.         /**
  280.         * @var right margin
  281.         * @access protected
  282.         */
  283.         protected $rMargin;
  284.  
  285.         /**
  286.         * @var page break margin
  287.         * @access protected
  288.         */
  289.         protected $bMargin;
  290.  
  291.         /**
  292.         * @var cell internal padding
  293.         * @access protected
  294.         */
  295.         //protected
  296.         public $cMargin;
  297.         
  298.         /**
  299.         * @var cell internal padding (previous value)
  300.         * @access protected
  301.         */
  302.         protected $oldcMargin;
  303.  
  304.         /**
  305.         * @var current horizontal position in user unit for cell positioning
  306.         * @access protected
  307.         */
  308.         protected $x;
  309.  
  310.         /**
  311.         * @var current vertical position in user unit for cell positioning
  312.         * @access protected
  313.         */
  314.         protected $y;
  315.  
  316.         /**
  317.         * @var height of last cell printed
  318.         * @access protected
  319.         */
  320.         protected $lasth;
  321.  
  322.         /**
  323.         * @var line width in user unit
  324.         * @access protected
  325.         */
  326.         protected $LineWidth;
  327.  
  328.         /**
  329.         * @var array of standard font names
  330.         * @access protected
  331.         */
  332.         protected $CoreFonts;
  333.  
  334.         /**
  335.         * @var array of used fonts
  336.         * @access protected
  337.         */
  338.         protected $fonts = array();
  339.  
  340.         /**
  341.         * @var array of font files
  342.         * @access protected
  343.         */
  344.         protected $FontFiles = array();
  345.  
  346.         /**
  347.         * @var array of encoding differences
  348.         * @access protected
  349.         */
  350.         protected $diffs = array();
  351.  
  352.         /**
  353.         * @var array of used images
  354.         * @access protected
  355.         */
  356.         protected $images = array();
  357.  
  358.         /**
  359.         * @var array of Annotations in pages
  360.         * @access protected
  361.         */
  362.         protected $PageAnnots = array();
  363.  
  364.         /**
  365.         * @var array of internal links
  366.         * @access protected
  367.         */
  368.         protected $links = array();
  369.  
  370.         /**
  371.         * @var current font family
  372.         * @access protected
  373.         */
  374.         protected $FontFamily;
  375.  
  376.         /**
  377.         * @var current font style
  378.         * @access protected
  379.         */
  380.         protected $FontStyle;
  381.         
  382.         /**
  383.         * @var current font ascent (distance between font top and baseline)
  384.         * @access protected
  385.         * @since 2.8.000 (2007-03-29)
  386.         */
  387.         protected $FontAscent;
  388.         
  389.         /**
  390.         * @var current font descent (distance between font bottom and baseline)
  391.         * @access protected
  392.         * @since 2.8.000 (2007-03-29)
  393.         */
  394.         protected $FontDescent;
  395.  
  396.         /**
  397.         * @var underlining flag
  398.         * @access protected
  399.         */
  400.         protected $underline;
  401.  
  402.         /**
  403.         * @var current font info
  404.         * @access protected
  405.         */
  406.         protected $CurrentFont;
  407.  
  408.         /**
  409.         * @var current font size in points
  410.         * @access protected
  411.         */
  412.         protected $FontSizePt;
  413.  
  414.         /**
  415.         * @var current font size in user unit
  416.         * @access protected
  417.         */
  418.         protected $FontSize;
  419.  
  420.         /**
  421.         * @var commands for drawing color
  422.         * @access protected
  423.         */
  424.         protected $DrawColor;
  425.  
  426.         /**
  427.         * @var commands for filling color
  428.         * @access protected
  429.         */
  430.         protected $FillColor;
  431.  
  432.         /**
  433.         * @var commands for text color
  434.         * @access protected
  435.         */
  436.         protected $TextColor;
  437.  
  438.         /**
  439.         * @var indicates whether fill and text colors are different
  440.         * @access protected
  441.         */
  442.         protected $ColorFlag;
  443.  
  444.         /**
  445.         * @var automatic page breaking
  446.         * @access protected
  447.         */
  448.         protected $AutoPageBreak;
  449.  
  450.         /**
  451.         * @var threshold used to trigger page breaks
  452.         * @access protected
  453.         */
  454.         protected $PageBreakTrigger;
  455.  
  456.         /**
  457.         * @var flag set when processing footer
  458.         * @access protected
  459.         */
  460.         protected $InFooter = false;
  461.  
  462.         /**
  463.         * @var zoom display mode
  464.         * @access protected
  465.         */
  466.         protected $ZoomMode;
  467.  
  468.         /**
  469.         * @var layout display mode
  470.         * @access protected
  471.         */
  472.         protected $LayoutMode;
  473.  
  474.         /**
  475.         * @var title 
  476.         * @access protected
  477.         */
  478.         protected $title = '';
  479.  
  480.         /**
  481.         * @var subject 
  482.         * @access protected
  483.         */
  484.         protected $subject = '';
  485.  
  486.         /**
  487.         * @var author 
  488.         * @access protected
  489.         */
  490.         protected $author = '';
  491.  
  492.         /**
  493.         * @var keywords 
  494.         * @access protected
  495.         */
  496.         protected $keywords = '';
  497.  
  498.         /**
  499.         * @var creator 
  500.         * @access protected
  501.         */
  502.         protected $creator = '';
  503.  
  504.         /**
  505.         * @var alias for total number of pages
  506.         * @access protected
  507.         */
  508.         protected $AliasNbPages = '{nb}';
  509.         
  510.         /**
  511.         * @var alias for page number
  512.         * @access protected
  513.         */
  514.         protected $AliasNumPage = '{pnb}';
  515.         
  516.         /**
  517.         * @var right-bottom corner X coordinate of inserted image
  518.         * @since 2002-07-31
  519.         * @author Nicola Asuni
  520.         * @access protected
  521.         */
  522.         protected $img_rb_x;
  523.  
  524.         /**
  525.         * @var right-bottom corner Y coordinate of inserted image
  526.         * @since 2002-07-31
  527.         * @author Nicola Asuni
  528.         * @access protected
  529.         */
  530.         protected $img_rb_y;
  531.  
  532.         /**
  533.         * @var adjusting factor to convert pixels to user units.
  534.         * @since 2004-06-14
  535.         * @author Nicola Asuni
  536.         * @access protected
  537.         */
  538.         protected $imgscale = 1;
  539.  
  540.         /**
  541.         * @var boolean set to true when the input text is unicode (require unicode fonts)
  542.         * @since 2005-01-02
  543.         * @author Nicola Asuni
  544.         * @access protected
  545.         */
  546.         protected $isunicode = false;
  547.  
  548.         /**
  549.         * @var PDF version
  550.         * @since 1.5.3
  551.         * @access protected
  552.         */
  553.         protected $PDFVersion = '1.7';
  554.         
  555.         
  556.         // ----------------------
  557.         
  558.         /**
  559.          * @var Minimum distance between header and top page margin.
  560.          * @access protected
  561.          */
  562.         protected $header_margin;
  563.         
  564.         /**
  565.          * @var Minimum distance between footer and bottom page margin.
  566.          * @access protected
  567.          */
  568.         protected $footer_margin;
  569.         
  570.         /**
  571.          * @var original left margin value
  572.          * @access protected
  573.          * @since 1.53.0.TC013
  574.          */
  575.         protected $original_lMargin;
  576.         
  577.         /**
  578.          * @var original right margin value
  579.          * @access protected
  580.          * @since 1.53.0.TC013
  581.          */
  582.         protected $original_rMargin;
  583.             
  584.         /**
  585.          * @var Header font.
  586.          * @access protected
  587.          */
  588.         protected $header_font;
  589.         
  590.         /**
  591.          * @var Footer font.
  592.          * @access protected
  593.          */
  594.         protected $footer_font;
  595.         
  596.         /**
  597.          * @var Language templates.
  598.          * @access protected
  599.          */
  600.         protected $l;
  601.         
  602.         /**
  603.          * @var Barcode to print on page footer (only if set).
  604.          * @access protected
  605.          */
  606.         protected $barcode = false;
  607.         
  608.         /**
  609.          * @var If true prints header
  610.          * @access protected
  611.          */
  612.         protected $print_header = true;
  613.         
  614.         /**
  615.          * @var If true prints footer.
  616.          * @access protected
  617.          */
  618.         protected $print_footer = true;
  619.             
  620.         /**
  621.          * @var Header image logo.
  622.          * @access protected
  623.          */
  624.         protected $header_logo = '';
  625.         
  626.         /**
  627.          * @var Header image logo width in mm.
  628.          * @access protected
  629.          */
  630.         protected $header_logo_width = 30;
  631.         
  632.         /**
  633.          * @var String to print as title on document header.
  634.          * @access protected
  635.          */
  636.         protected $header_title = '';
  637.         
  638.         /**
  639.          * @var String to print on document header.
  640.          * @access protected
  641.          */
  642.         protected $header_string = '';
  643.         
  644.         /**
  645.          * @var Default number of columns for html table.
  646.          * @access protected
  647.          */
  648.         protected $default_table_columns = 4;
  649.         
  650.         
  651.         // variables for html parser
  652.         
  653.         /**
  654.          * @var HTML PARSER: array to store current link and rendering styles.
  655.          * @access protected
  656.          */
  657.         protected $HREF = array();
  658.         
  659.         /**
  660.          * @var store a list of available fonts on filesystem.
  661.          * @access protected
  662.          */
  663.         protected $fontlist = array();
  664.         
  665.         /**
  666.          * @var current foreground color
  667.          * @access protected
  668.          */
  669.         protected $fgcolor;
  670.                         
  671.         /**
  672.          * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  673.          * @access protected
  674.          */
  675.         protected $listordered = array();
  676.         
  677.         /**
  678.          * @var HTML PARSER: array count list items on nested lists.
  679.          * @access protected
  680.          */
  681.         protected $listcount = array();
  682.         
  683.         /**
  684.          * @var HTML PARSER: current list nesting level.
  685.          * @access protected
  686.          */
  687.         protected $listnum = 0;
  688.         
  689.         /**
  690.          * @var HTML PARSER: indent amount for lists.
  691.          * @access protected
  692.          */
  693.         protected $listindent;
  694.         
  695.         /**
  696.          * @var current background color
  697.          * @access protected
  698.          */
  699.         protected $bgcolor;
  700.         
  701.         /**
  702.          * @var Store temporary font size in points.
  703.          * @access protected
  704.          */
  705.         protected $tempfontsize = 10;
  706.         
  707.         /**
  708.          * @var spacer for LI tags.
  709.          * @access protected
  710.          */
  711.         protected $lispacer = '';
  712.         
  713.         /**
  714.          * @var default encoding
  715.          * @access protected
  716.          * @since 1.53.0.TC010
  717.          */
  718.         protected $encoding = 'UTF-8';
  719.         
  720.         /**
  721.          * @var PHP internal encoding
  722.          * @access protected
  723.          * @since 1.53.0.TC016
  724.          */
  725.         protected $internal_encoding;
  726.         
  727.         /**
  728.          * @var indicates if the document language is Right-To-Left
  729.          * @access protected
  730.          * @since 2.0.000
  731.          */
  732.         protected $rtl = false;
  733.         
  734.         /**
  735.          * @var used to force RTL or LTR string inversion
  736.          * @access protected
  737.          * @since 2.0.000
  738.          */
  739.         protected $tmprtl = false;
  740.         
  741.         // --- Variables used for document encryption:
  742.         
  743.         /**
  744.          * Indicates whether document is protected
  745.          * @access protected
  746.          * @since 2.0.000 (2008-01-02)
  747.          */
  748.         protected $encrypted;
  749.         
  750.         /**
  751.          * U entry in pdf document
  752.          * @access protected
  753.          * @since 2.0.000 (2008-01-02)
  754.          */
  755.         protected $Uvalue;
  756.         
  757.         /**
  758.          * O entry in pdf document
  759.          * @access protected
  760.          * @since 2.0.000 (2008-01-02)
  761.          */
  762.         protected $Ovalue;
  763.         
  764.         /**
  765.          * P entry in pdf document
  766.          * @access protected
  767.          * @since 2.0.000 (2008-01-02)
  768.          */
  769.         protected $Pvalue;
  770.         
  771.         /**
  772.          * encryption object id
  773.          * @access protected
  774.          * @since 2.0.000 (2008-01-02)
  775.          */
  776.         protected $enc_obj_id;
  777.         
  778.         /**
  779.          * last RC4 key encrypted (cached for optimisation)
  780.          * @access protected
  781.          * @since 2.0.000 (2008-01-02)
  782.          */
  783.         protected $last_rc4_key;
  784.         
  785.         /**
  786.          * last RC4 computed key
  787.          * @access protected
  788.          * @since 2.0.000 (2008-01-02)
  789.          */
  790.         protected $last_rc4_key_c;
  791.         
  792.         /**
  793.          * RC4 padding
  794.          * @access protected
  795.          */
  796.         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";
  797.         
  798.         /**
  799.          * RC4 encryption key
  800.          * @access protected
  801.          */
  802.         protected $encryption_key;
  803.         
  804.         // --- bookmark ---
  805.         
  806.         /**
  807.          * Outlines for bookmark
  808.          * @access protected
  809.          * @since 2.1.002 (2008-02-12)
  810.          */
  811.         protected $outlines = array();
  812.         
  813.         /**
  814.          * Outline root for bookmark
  815.          * @access protected
  816.          * @since 2.1.002 (2008-02-12)
  817.          */
  818.         protected $OutlineRoot;
  819.         
  820.         
  821.         // --- javascript and form ---
  822.         
  823.         /**
  824.          * javascript code
  825.          * @access protected
  826.          * @since 2.1.002 (2008-02-12)
  827.          */
  828.         protected $javascript = '';
  829.         
  830.         /**
  831.          * javascript counter
  832.          * @access protected
  833.          * @since 2.1.002 (2008-02-12)
  834.          */
  835.         protected $n_js;
  836.  
  837.         /**
  838.          * line trough state
  839.          * @access protected
  840.          * @since 2.8.000 (2008-03-19)
  841.          */
  842.         protected $linethrough;
  843.  
  844.         // --- Variables used for User's Rights ---
  845.         // See PDF reference chapter 8.7 Digital Signatures
  846.  
  847.         /**
  848.          * If true enables user's rights on PDF reader
  849.          * @access protected
  850.          * @since 2.9.000 (2008-03-26)
  851.          */
  852.         protected $ur;
  853.  
  854.         /**
  855.          * Names specifying additional document-wide usage rights for the document.
  856.          * @access protected
  857.          * @since 2.9.000 (2008-03-26)
  858.          */
  859.         protected $ur_document;
  860.  
  861.         /**
  862.          * Names specifying additional annotation-related usage rights for the document.
  863.          * @access protected
  864.          * @since 2.9.000 (2008-03-26)
  865.          */
  866.         protected $ur_annots;
  867.  
  868.         /**
  869.          * Names specifying additional form-field-related usage rights for the document.
  870.          * @access protected
  871.          * @since 2.9.000 (2008-03-26)
  872.          */
  873.         protected $ur_form;
  874.  
  875.         /**
  876.          * Names specifying additional signature-related usage rights for the document.
  877.          * @access protected
  878.          * @since 2.9.000 (2008-03-26)
  879.          */
  880.         protected $ur_signature;
  881.  
  882.         /**
  883.          * Dot Per Inch Document Resolution (do not change)
  884.          * @access protected
  885.          * @since 3.0.000 (2008-03-27)
  886.          */
  887.         protected $dpi = 72;
  888.         
  889.         /**
  890.          * Array of page numbers were a new page group was started
  891.          * @access protected
  892.          * @since 3.0.000 (2008-03-27)
  893.          */
  894.         protected $newpagegroup = array();
  895.         
  896.         /**
  897.          * Contains the number of pages of the groups
  898.          * @access protected
  899.          * @since 3.0.000 (2008-03-27)
  900.          */
  901.         protected $pagegroups;
  902.         
  903.         /**
  904.          * Contains the alias of the current page group
  905.          * @access protected
  906.          * @since 3.0.000 (2008-03-27)
  907.          */
  908.         protected $currpagegroup
  909.         
  910.         /**
  911.          * Restrict the rendering of some elements to screen or printout.
  912.          * @access protected
  913.          * @since 3.0.000 (2008-03-27)
  914.          */
  915.         protected $visibility = 'all';
  916.         
  917.         /**
  918.          * Print visibility.
  919.          * @access protected
  920.          * @since 3.0.000 (2008-03-27)
  921.          */
  922.         protected $n_ocg_print;
  923.         
  924.         /**
  925.          * View visibility.
  926.          * @access protected
  927.          * @since 3.0.000 (2008-03-27)
  928.          */
  929.         protected $n_ocg_view;
  930.         
  931.         /**
  932.          * Array of transparency objects and parameters.
  933.          * @access protected
  934.          * @since 3.0.000 (2008-03-27)
  935.          */
  936.         protected $extgstates;
  937.         
  938.         /**
  939.          * Set the default JPEG compression quality (1-100)
  940.          * @access protected
  941.          * @since 3.0.000 (2008-03-27)
  942.          */
  943.         protected $jpeg_quality;
  944.         
  945.         /**
  946.          * Default cell height ratio.
  947.          * @access protected
  948.          * @since 3.0.014 (2008-05-23)
  949.          */
  950.         protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  951.         
  952.         /**
  953.          * PDF viewer preferences.
  954.          * @access protected
  955.          * @since 3.1.000 (2008-06-09)
  956.          */
  957.         protected $viewer_preferences;
  958.         
  959.         /**
  960.          * A name object specifying how the document should be displayed when opened.
  961.          * @access protected
  962.          * @since 3.1.000 (2008-06-09)
  963.          */
  964.         protected $PageMode;
  965.         
  966.         /**
  967.          * Array for storing gradient information.
  968.          * @access protected
  969.          * @since 3.1.000 (2008-06-09)
  970.          */
  971.         protected $gradients = array();
  972.         
  973.         /**
  974.          * Array used to store positions inside the pages buffer.
  975.          * keys are the page numbers
  976.          * @access protected
  977.          * @since 3.2.000 (2008-06-26)
  978.          */
  979.         protected $intmrk = array();
  980.         
  981.         /**
  982.          * Array used to store content positions inside the pages buffer.
  983.          * keys are the page numbers
  984.          * @access protected
  985.          * @since 4.6.021 (2009-07-20)
  986.          */
  987.         protected $cntmrk = array();
  988.         
  989.         /**
  990.          * Array used to store footer positions of each page.
  991.          * @access protected
  992.          * @since 3.2.000 (2008-07-01)
  993.          */
  994.         protected $footerpos = array();
  995.         
  996.         
  997.         /**
  998.          * Array used to store footer lenght of each page.
  999.          * @access protected
  1000.          * @since 4.0.014 (2008-07-29)
  1001.          */
  1002.         protected $footerlen = array();
  1003.         
  1004.         /**
  1005.          * True if a newline is created.
  1006.          * @access protected
  1007.          * @since 3.2.000 (2008-07-01)
  1008.          */
  1009.         protected $newline = true;
  1010.         
  1011.         /**
  1012.          * End position of the latest inserted line
  1013.          * @access protected
  1014.          * @since 3.2.000 (2008-07-01)
  1015.          */
  1016.         protected $endlinex = 0;
  1017.         
  1018.         /**
  1019.          * PDF string for last line width
  1020.          * @access protected
  1021.          * @since 4.0.006 (2008-07-16)
  1022.          */
  1023.         protected $linestyleWidth = '';
  1024.         
  1025.         /**
  1026.          * PDF string for last line width
  1027.          * @access protected
  1028.          * @since 4.0.006 (2008-07-16)
  1029.          */
  1030.         protected $linestyleCap = '0 J';
  1031.         
  1032.         /**
  1033.          * PDF string for last line width
  1034.          * @access protected
  1035.          * @since 4.0.006 (2008-07-16)
  1036.          */
  1037.         protected $linestyleJoin = '0 j';
  1038.         
  1039.         /**
  1040.          * PDF string for last line width
  1041.          * @access protected
  1042.          * @since 4.0.006 (2008-07-16)
  1043.          */
  1044.         protected $linestyleDash = '[] 0 d';
  1045.         
  1046.         /**
  1047.          * True if marked-content sequence is open
  1048.          * @access protected
  1049.          * @since 4.0.013 (2008-07-28)
  1050.          */
  1051.         protected $openMarkedContent = false;
  1052.         
  1053.         /**
  1054.          * Count the latest inserted vertical spaces on HTML
  1055.          * @access protected
  1056.          * @since 4.0.021 (2008-08-24)
  1057.          */
  1058.         protected $htmlvspace = 0;
  1059.         
  1060.         /**
  1061.          * Array of Spot colors
  1062.          * @access protected
  1063.          * @since 4.0.024 (2008-09-12)
  1064.          */
  1065.         protected $spot_colors = array();
  1066.         
  1067.         /**
  1068.          * Symbol used for HTML unordered list items
  1069.          * @access protected
  1070.          * @since 4.0.028 (2008-09-26)
  1071.          */
  1072.         protected $lisymbol = '';
  1073.         
  1074.         /**
  1075.          * String used to mark the beginning and end of EPS image blocks
  1076.          * @access protected
  1077.          * @since 4.1.000 (2008-10-18)
  1078.          */
  1079.         protected $epsmarker = 'x#!#EPS#!#x';
  1080.         
  1081.         /**
  1082.          * Array of transformation matrix
  1083.          * @access protected
  1084.          * @since 4.2.000 (2008-10-29)
  1085.          */
  1086.         protected $transfmatrix = array();
  1087.  
  1088.         /**
  1089.          * Current key for transformation matrix
  1090.          * @access protected
  1091.          * @since 4.8.005 (2009-09-17)
  1092.          */
  1093.         protected $transfmatrix_key = 0;
  1094.  
  1095.         /**
  1096.          * Booklet mode for double-sided pages
  1097.          * @access protected
  1098.          * @since 4.2.000 (2008-10-29)
  1099.          */
  1100.         protected $booklet = false;
  1101.         
  1102.         /**
  1103.          * Epsilon value used for float calculations
  1104.          * @access protected
  1105.          * @since 4.2.000 (2008-10-29)
  1106.          */
  1107.         protected $feps = 0.005;
  1108.         
  1109.         /**
  1110.          * Array used for custom vertical spaces for HTML tags
  1111.          * @access protected
  1112.          * @since 4.2.001 (2008-10-30)
  1113.          */
  1114.         protected $tagvspaces = array();
  1115.         
  1116.         /**
  1117.          * @var HTML PARSER: custom indent amount for lists.
  1118.          *  Negative value means disabled.
  1119.          * @access protected
  1120.          * @since 4.2.007 (2008-11-12)
  1121.          */
  1122.         protected $customlistindent = -1;
  1123.         
  1124.         /**
  1125.          * @var if true keeps the border open for the cell sides that cross the page.
  1126.          * @access protected
  1127.          * @since 4.2.010 (2008-11-14)
  1128.          */
  1129.         protected $opencell = true;
  1130.  
  1131.         /**
  1132.          * @var array of files to embedd
  1133.          * @access protected
  1134.          * @since 4.4.000 (2008-12-07)
  1135.          */
  1136.         protected $embeddedfiles = array();
  1137.  
  1138.         /**
  1139.          * @var boolean true when inside html pre tag
  1140.          * @access protected
  1141.          * @since 4.4.001 (2008-12-08)
  1142.          */
  1143.         protected $premode = false;
  1144.  
  1145.         /**
  1146.          * Array used to store positions of graphics transformation blocks inside the page buffer.
  1147.          * keys are the page numbers
  1148.          * @access protected
  1149.          * @since 4.4.002 (2008-12-09)
  1150.          */
  1151.         protected $transfmrk = array();
  1152.  
  1153.         /**
  1154.          * Default color for html links
  1155.          * @access protected
  1156.          * @since 4.4.003 (2008-12-09)
  1157.          */
  1158.         protected $htmlLinkColorArray = array(00255);
  1159.  
  1160.         /**
  1161.          * Default font style to add to html links
  1162.          * @access protected
  1163.          * @since 4.4.003 (2008-12-09)
  1164.          */
  1165.         protected $htmlLinkFontStyle = 'U';
  1166.  
  1167.         /**
  1168.          * Counts the number of pages.
  1169.          * @access protected
  1170.          * @since 4.5.000 (2008-12-31)
  1171.          */
  1172.         protected $numpages = 0;
  1173.  
  1174.         /**
  1175.          * Array containing page lenghts in bytes.
  1176.          * @access protected
  1177.          * @since 4.5.000 (2008-12-31)
  1178.          */
  1179.         protected $pagelen = array();
  1180.  
  1181.         /**
  1182.          * Counts the number of pages.
  1183.          * @access protected
  1184.          * @since 4.5.000 (2008-12-31)
  1185.          */
  1186.         protected $numimages = 0;
  1187.  
  1188.         /**
  1189.          * Store the image keys.
  1190.          * @access protected
  1191.          * @since 4.5.000 (2008-12-31)
  1192.          */
  1193.         protected $imagekeys = array();
  1194.  
  1195.         /**
  1196.          * Lenght of the buffer in bytes.
  1197.          * @access protected
  1198.          * @since 4.5.000 (2008-12-31)
  1199.          */
  1200.         protected $bufferlen = 0;
  1201.  
  1202.         /**
  1203.          * If true enables disk caching.
  1204.          * @access protected
  1205.          * @since 4.5.000 (2008-12-31)
  1206.          */
  1207.         protected $diskcache = false;
  1208.  
  1209.         /**
  1210.          * Counts the number of fonts.
  1211.          * @access protected
  1212.          * @since 4.5.000 (2009-01-02)
  1213.          */
  1214.         protected $numfonts = 0;
  1215.  
  1216.         /**
  1217.          * Store the font keys.
  1218.          * @access protected
  1219.          * @since 4.5.000 (2009-01-02)
  1220.          */
  1221.         protected $fontkeys = array();
  1222.         
  1223.         /**
  1224.          * Store the font object IDs.
  1225.          * @access protected
  1226.          * @since 4.8.001 (2009-09-09)
  1227.          */
  1228.         protected $font_obj_ids = array();
  1229.  
  1230.         /**
  1231.          * Store the fage status (true when opened, false when closed).
  1232.          * @access protected
  1233.          * @since 4.5.000 (2009-01-02)
  1234.          */
  1235.         protected $pageopen = array();
  1236.         
  1237.         /**
  1238.          * Default monospaced font
  1239.          * @access protected
  1240.          * @since 4.5.025 (2009-03-10)
  1241.          */
  1242.         protected $default_monospaced_font = 'courier';
  1243.  
  1244.         /**
  1245.          * Used to store a cloned copy of the current class object
  1246.          * @access protected
  1247.          * @since 4.5.029 (2009-03-19)
  1248.          */
  1249.         protected $objcopy;
  1250.  
  1251.         /**
  1252.          * Array used to store the lenghts of cache files
  1253.          * @access protected
  1254.          * @since 4.5.029 (2009-03-19)
  1255.          */
  1256.         protected $cache_file_lenght = array();
  1257.  
  1258.         /**
  1259.          * Table header content to be repeated on each new page
  1260.          * @access protected
  1261.          * @since 4.5.030 (2009-03-20)
  1262.          */
  1263.         protected $thead = '';
  1264.  
  1265.         /**
  1266.          * Margins used for table header.
  1267.          * @access protected
  1268.          * @since 4.5.030 (2009-03-20)
  1269.          */
  1270.         protected $theadMargins = array();
  1271.  
  1272.         /**
  1273.          * Cache array for UTF8StringToArray() method.
  1274.          * @access protected
  1275.          * @since 4.5.037 (2009-04-07)
  1276.          */
  1277.         protected $cache_UTF8StringToArray = array();
  1278.  
  1279.         /**
  1280.          * Maximum size of cache array used for UTF8StringToArray() method.
  1281.          * @access protected
  1282.          * @since 4.5.037 (2009-04-07)
  1283.          */
  1284.         protected $cache_maxsize_UTF8StringToArray = 8;
  1285.  
  1286.         /**
  1287.          * Current size of cache array used for UTF8StringToArray() method.
  1288.          * @access protected
  1289.          * @since 4.5.037 (2009-04-07)
  1290.          */
  1291.         protected $cache_size_UTF8StringToArray = 0;
  1292.  
  1293.         /**
  1294.          * If true enables document signing
  1295.          * @access protected
  1296.          * @since 4.6.005 (2009-04-24)
  1297.          */
  1298.         protected $sign = false;
  1299.  
  1300.         /**
  1301.          * Signature data
  1302.          * @access protected
  1303.          * @since 4.6.005 (2009-04-24)
  1304.          */
  1305.         protected $signature_data = array();
  1306.  
  1307.         /**
  1308.          * Signature max lenght
  1309.          * @access protected
  1310.          * @since 4.6.005 (2009-04-24)
  1311.          */
  1312.         protected $signature_max_lenght = 11742;
  1313.  
  1314.         /**
  1315.          * Regular expression used to find blank characters used for word-wrapping.
  1316.          * @access protected
  1317.          * @since 4.6.006 (2009-04-28)
  1318.          */
  1319.         protected $re_spaces = '/[\s]/';
  1320.  
  1321.         /**
  1322.          * Signature object ID
  1323.          * @access protected
  1324.          * @since 4.6.022 (2009-06-23)
  1325.          */
  1326.         protected $sig_obj_id = 0;
  1327.  
  1328.         /**
  1329.          * ByteRange placemark used during signature process.
  1330.          * @access protected
  1331.          * @since 4.6.028 (2009-08-25)
  1332.          */
  1333.         protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1334.  
  1335.         /**
  1336.          * Placemark used during signature process.
  1337.          * @access protected
  1338.          * @since 4.6.028 (2009-08-25)
  1339.          */
  1340.         protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1341.  
  1342.         /**
  1343.          * ID of page objects
  1344.          * @access protected
  1345.          * @since 4.7.000 (2009-08-29)
  1346.          */
  1347.         protected $page_obj_id = array();
  1348.  
  1349.         /**
  1350.          * Start ID for embedded file objects
  1351.          * @access protected
  1352.          * @since 4.7.000 (2009-08-29)
  1353.          */
  1354.         protected $embedded_start_obj_id = 100000;
  1355.  
  1356.         /**
  1357.          * Start ID for annotation objects
  1358.          * @access protected
  1359.          * @since 4.7.000 (2009-08-29)
  1360.          */
  1361.         protected $annots_start_obj_id = 200000;
  1362.         
  1363.         /**
  1364.          * Max ID of annotation object
  1365.          * @access protected
  1366.          * @since 4.7.000 (2009-08-29)
  1367.          */
  1368.         protected $annot_obj_id = 200000;
  1369.         
  1370.         /**
  1371.          * Current ID of annotation object
  1372.          * @access protected
  1373.          * @since 4.8.003 (2009-09-15)
  1374.          */
  1375.         protected $curr_annot_obj_id = 200000;
  1376.         
  1377.         /**
  1378.          * List of form annotations IDs
  1379.          * @access protected
  1380.          * @since 4.8.000 (2009-09-07)
  1381.          */
  1382.         protected $form_obj_id = array();
  1383.         
  1384.         /*
  1385.          * Deafult Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. Annotation options can be directly specified using the 'aopt' entry.
  1386.          * @access protected
  1387.          * @since 4.8.000 (2009-09-07)
  1388.          */
  1389.         protected $default_form_prop = array('lineWidth'=>1'borderStyle'=>'solid''fillColor'=>array(255255255)'strokeColor'=>array(128128128));
  1390.  
  1391.         /**
  1392.          * Javascript objects array
  1393.          * @access protected
  1394.          * @since 4.8.000 (2009-09-07)
  1395.          */
  1396.         protected $js_objects = array();
  1397.  
  1398.         /**
  1399.          * Start ID for javascript objects
  1400.          * @access protected
  1401.          * @since 4.8.000 (2009-09-07)
  1402.          */
  1403.         protected $js_start_obj_id = 300000;
  1404.         
  1405.         /**
  1406.          * Current ID of javascript object
  1407.          * @access protected
  1408.          * @since 4.8.000 (2009-09-07)
  1409.          */
  1410.         protected $js_obj_id = 300000;
  1411.         
  1412.         /**
  1413.          * Current form action (used during XHTML rendering)
  1414.          * @access protected
  1415.          * @since 4.8.000 (2009-09-07)
  1416.          */
  1417.         protected $form_action = '';
  1418.  
  1419.         /**
  1420.          * Current form encryption type (used during XHTML rendering)
  1421.          * @access protected
  1422.          * @since 4.8.000 (2009-09-07)
  1423.          */
  1424.         protected $form_enctype = 'application/x-www-form-urlencoded';
  1425.  
  1426.         /**
  1427.          * Current method to submit forms.
  1428.          * @access protected
  1429.          * @since 4.8.000 (2009-09-07)
  1430.          */
  1431.         protected $form_mode = 'post';
  1432.  
  1433.         /**
  1434.          * Start ID for appearance streams XObjects
  1435.          * @access protected
  1436.          * @since 4.8.001 (2009-09-09)
  1437.          */
  1438.         protected $apxo_start_obj_id = 400000;
  1439.         
  1440.         /**
  1441.          * Current ID of appearance streams XObjects
  1442.          * @access protected
  1443.          * @since 4.8.001 (2009-09-09)
  1444.          */
  1445.         protected $apxo_obj_id = 400000;
  1446.         
  1447.         /**
  1448.          * List of fonts used on form fields (fontname => fontkey).
  1449.          * @access protected
  1450.          * @since 4.8.001 (2009-09-09)
  1451.          */
  1452.         protected $annotation_fonts = array();
  1453.         
  1454.         /**
  1455.          * List of radio buttons parent objects.
  1456.          * @access protected
  1457.          * @since 4.8.001 (2009-09-09)
  1458.          */
  1459.         protected $radiobutton_groups = array();
  1460.         
  1461.         /**
  1462.          * List of radio group objects IDs
  1463.          * @access protected
  1464.          * @since 4.8.001 (2009-09-09)
  1465.          */
  1466.         protected $radio_groups = array();
  1467.         
  1468.         /**
  1469.          * Text indentation value (used for text-indent CSS attribute)
  1470.          * @access protected
  1471.          * @since 4.8.006 (2009-09-23)
  1472.          */
  1473.         protected $textindent = 0;
  1474.         
  1475.         /**
  1476.          * Store page number when startTransaction() is called.
  1477.          * @access protected
  1478.          * @since 4.8.006 (2009-09-23)
  1479.          */
  1480.         protected $start_transaction_page = 0;
  1481.         
  1482.         //------------------------------------------------------------
  1483.         // METHODS
  1484.         //------------------------------------------------------------
  1485.  
  1486.         /**
  1487.          * This is the class constructor.
  1488.          * It allows to set up the page format, the orientation and
  1489.          * the measure unit used in all the methods (except for the font sizes).
  1490.          * @since 1.0
  1491.          * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1492.          * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />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.
  1493.          * @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).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1494.          * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1495.          * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1496.          * @param String $encoding charset encoding; default is UTF-8
  1497.          * @access public
  1498.          */
  1499.         public function __construct($orientation='P'$unit='mm'$format='A4'$unicode=true$encoding='UTF-8'$diskcache=false{
  1500.             /* Set internal character encoding to ASCII */
  1501.             if (function_exists('mb_internal_encoding'AND mb_internal_encoding()) {
  1502.                 $this->internal_encoding = mb_internal_encoding();
  1503.                 mb_internal_encoding('ASCII');
  1504.             }
  1505.             // set disk caching
  1506.             $this->diskcache = $diskcache true false;
  1507.             // set language direction
  1508.             $this->rtl = false;
  1509.             $this->tmprtl = false;
  1510.             //Some checks
  1511.             $this->_dochecks();
  1512.             //Initialization of properties
  1513.             $this->isunicode = $unicode;
  1514.             $this->page = 0;
  1515.             $this->transfmrk[0array();
  1516.             $this->pagedim = array();
  1517.             $this->n = 2;
  1518.             $this->buffer = '';
  1519.             $this->pages = array();
  1520.             $this->state = 0;
  1521.             $this->fonts = array();
  1522.             $this->FontFiles = array();
  1523.             $this->diffs = array();
  1524.             $this->images = array();
  1525.             $this->links = array();
  1526.             $this->gradients = array();
  1527.             $this->InFooter = false;
  1528.             $this->lasth = 0;
  1529.             $this->FontFamily = 'helvetica';
  1530.             $this->FontStyle = '';
  1531.             $this->FontSizePt = 12;
  1532.             $this->underline = false;
  1533.             $this->linethrough = false;
  1534.             $this->DrawColor = '0 G';
  1535.             $this->FillColor = '0 g';
  1536.             $this->TextColor = '0 g';
  1537.             $this->ColorFlag = false;
  1538.             // encryption values
  1539.             $this->encrypted = false;
  1540.             $this->last_rc4_key = '';
  1541.             $this->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";
  1542.             //Standard Unicode fonts
  1543.             $this->CoreFonts = array(
  1544.                 'courier'=>'Courier',
  1545.                 'courierB'=>'Courier-Bold',
  1546.                 'courierI'=>'Courier-Oblique',
  1547.                 'courierBI'=>'Courier-BoldOblique',
  1548.                 'helvetica'=>'Helvetica',
  1549.                 'helveticaB'=>'Helvetica-Bold',
  1550.                 'helveticaI'=>'Helvetica-Oblique',
  1551.                 'helveticaBI'=>'Helvetica-BoldOblique',
  1552.                 'times'=>'Times-Roman',
  1553.                 'timesB'=>'Times-Bold',
  1554.                 'timesI'=>'Times-Italic',
  1555.                 'timesBI'=>'Times-BoldItalic',
  1556.                 'symbol'=>'Symbol',
  1557.                 'zapfdingbats'=>'ZapfDingbats'
  1558.             );
  1559.             //Set scale factor
  1560.             $this->setPageUnit($unit);
  1561.             // set page format and orientation
  1562.             $this->setPageFormat($format$orientation);
  1563.             //Page margins (1 cm)
  1564.             $margin 28.35 $this->k;
  1565.             $this->SetMargins($margin$margin);
  1566.             //Interior cell margin
  1567.             $this->cMargin = $margin 10;
  1568.             //Line width (0.2 mm)
  1569.             $this->LineWidth = 0.57 $this->k;
  1570.             $this->linestyleWidth = sprintf('%.2F w'($this->LineWidth * $this->k));
  1571.             $this->linestyleCap = '0 J';
  1572.             $this->linestyleJoin = '0 j';
  1573.             $this->linestyleDash = '[] 0 d';
  1574.             //Automatic page break
  1575.             $this->SetAutoPageBreak(true($margin));
  1576.             //Full width display mode
  1577.             $this->SetDisplayMode('fullwidth');
  1578.             //Compression
  1579.             $this->SetCompression(true);
  1580.             //Set default PDF version number
  1581.             $this->PDFVersion = '1.7';
  1582.             $this->encoding = $encoding;
  1583.             $this->HREF = array();
  1584.             $this->getFontsList();
  1585.             $this->fgcolor = array('R' => 0'G' => 0'B' => 0);
  1586.             $this->bgcolor = array('R' => 255'G' => 255'B' => 255);
  1587.             $this->extgstates = array();
  1588.             // user's rights
  1589.             $this->sign = false;
  1590.             $this->ur = false;
  1591.             $this->ur_document = '/FullSave';
  1592.             $this->ur_annots = '/Create/Delete/Modify/Copy/Import/Export';
  1593.             $this->ur_form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1594.             $this->ur_signature = '/Modify';            
  1595.             // set default JPEG quality
  1596.             $this->jpeg_quality = 75;
  1597.             // initialize some settings
  1598.             $this->utf8Bidi(array('')'');
  1599.             // set default font
  1600.             $this->SetFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  1601.             // check if PCRE Unicode support is enabled
  1602.             if ($this->isunicode AND (@preg_match('/\pL/u''a'== 1)) {
  1603.                 // PCRE unicode support is turned ON
  1604.                 // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1605.                 // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1606.                 // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1607.                 //$this->re_spaces = '/[\s\p{Z}\p{Lo}]/u';
  1608.                 $this->re_spaces = '/[\s\p{Z}]/u';
  1609.             else {
  1610.                 // PCRE unicode support is turned OFF
  1611.                 $this->re_spaces = '/[\s]/';
  1612.             }
  1613.             $this->annot_obj_id = $this->annots_start_obj_id;
  1614.             $this->curr_annot_obj_id = $this->annots_start_obj_id;
  1615.             $this->apxo_obj_id = $this->apxo_start_obj_id;
  1616.             $this->js_obj_id = $this->js_start_obj_id;
  1617.             $this->default_form_prop = array('lineWidth'=>1'borderStyle'=>'solid''fillColor'=>array(255255255)'strokeColor'=>array(128128128));
  1618.         }
  1619.         
  1620.         /**
  1621.          * Default destructor.
  1622.          * @access public
  1623.          * @since 1.53.0.TC016
  1624.          */
  1625.         public function __destruct({
  1626.             // restore internal encoding
  1627.             if (isset($this->internal_encodingAND !empty($this->internal_encoding)) {
  1628.                 mb_internal_encoding($this->internal_encoding);
  1629.             }
  1630.             // unset all class variables
  1631.             $this->_destroy(true);
  1632.         }
  1633.         
  1634.         /**
  1635.          * Set the units of measure for the document.
  1636.          * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />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.
  1637.          * @access public
  1638.          * @since 3.0.015 (2008-06-06)
  1639.          */
  1640.         public function setPageUnit($unit{
  1641.         //Set scale factor
  1642.             switch (strtolower($unit)) {
  1643.                 // points
  1644.                 case 'px':
  1645.                 case 'pt'{
  1646.                     $this->k = 1;
  1647.                     break;
  1648.                 }
  1649.                 // millimeters
  1650.                 case 'mm'{
  1651.                     $this->k = $this->dpi / 25.4;
  1652.                     break;
  1653.                 }
  1654.                 // centimeters
  1655.                 case 'cm'{
  1656.                     $this->k = $this->dpi / 2.54;
  1657.                     break;
  1658.                 }
  1659.                 // inches
  1660.                 case 'in'{
  1661.                     $this->k = $this->dpi;
  1662.                     break;
  1663.                 }
  1664.                 // unsupported unit
  1665.                 default {
  1666.                     $this->Error('Incorrect unit: '.$unit);
  1667.                     break;
  1668.                 }
  1669.             }
  1670.             if (isset($this->CurOrientation)) {
  1671.                     $this->setPageOrientation($this->CurOrientation);
  1672.             }
  1673.         }
  1674.         
  1675.         /**
  1676.         * Set the page format
  1677.         * @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).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1678.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1679.         * @access public
  1680.         * @since 3.0.015 (2008-06-06)
  1681.         */
  1682.         public function setPageFormat($format$orientation='P'{
  1683.             //Page format
  1684.             if (is_string($format)) {
  1685.                 // Page formats (45 standard ISO paper formats and 4 american common formats).
  1686.                 // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  1687.                 switch (strtoupper($format)) {
  1688.                     case '4A0'{$format array(4767.87,6740.79)break;}
  1689.                     case '2A0'{$format array(3370.39,4767.87)break;}
  1690.                     case 'A0'{$format array(2383.94,3370.39)break;}
  1691.                     case 'A1'{$format array(1683.78,2383.94)break;}
  1692.                     case 'A2'{$format array(1190.55,1683.78)break;}
  1693.                     case 'A3'{$format array(841.89,1190.55)break;}
  1694.                     case 'A4'default{$format array(595.28,841.89)break;}
  1695.                     case 'A5'{$format array(419.53,595.28)break;}
  1696.                     case 'A6'{$format array(297.64,419.53)break;}
  1697.                     case 'A7'{$format array(209.76,297.64)break;}
  1698.                     case 'A8'{$format array(147.40,209.76)break;}
  1699.                     case 'A9'{$format array(104.88,147.40)break;}
  1700.                     case 'A10'{$format array(73.70,104.88)break;}
  1701.                     case 'B0'{$format array(2834.65,4008.19)break;}
  1702.                     case 'B1'{$format array(2004.09,2834.65)break;}
  1703.                     case 'B2'{$format array(1417.32,2004.09)break;}
  1704.                     case 'B3'{$format array(1000.63,1417.32)break;}
  1705.                     case 'B4'{$format array(708.66,1000.63)break;}
  1706.                     case 'B5'{$format array(498.90,708.66)break;}
  1707.                     case 'B6'{$format array(354.33,498.90)break;}
  1708.                     case 'B7'{$format array(249.45,354.33)break;}
  1709.                     case 'B8'{$format array(175.75,249.45)break;}
  1710.                     case 'B9'{$format array(124.72,175.75)break;}
  1711.                     case 'B10'{$format array(87.87,124.72)break;}
  1712.                     case 'C0'{$format array(2599.37,3676.54)break;}
  1713.                     case 'C1'{$format array(1836.85,2599.37)break;}
  1714.                     case 'C2'{$format array(1298.27,1836.85)break;}
  1715.                     case 'C3'{$format array(918.43,1298.27)break;}
  1716.                     case 'C4'{$format array(649.13,918.43)break;}
  1717.                     case 'C5'{$format array(459.21,649.13)break;}
  1718.                     case 'C6'{$format array(323.15,459.21)break;}
  1719.                     case 'C7'{$format array(229.61,323.15)break;}
  1720.                     case 'C8'{$format array(161.57,229.61)break;}
  1721.                     case 'C9'{$format array(113.39,161.57)break;}
  1722.                     case 'C10'{$format array(79.37,113.39)break;}
  1723.                     case 'RA0'{$format array(2437.80,3458.27)break;}
  1724.                     case 'RA1'{$format array(1729.13,2437.80)break;}
  1725.                     case 'RA2'{$format array(1218.90,1729.13)break;}
  1726.                     case 'RA3'{$format array(864.57,1218.90)break;}
  1727.                     case 'RA4'{$format array(609.45,864.57)break;}
  1728.                     case 'SRA0'{$format array(2551.18,3628.35)break;}
  1729.                     case 'SRA1'{$format array(1814.17,2551.18)break;}
  1730.                     case 'SRA2'{$format array(1275.59,1814.17)break;}
  1731.                     case 'SRA3'{$format array(907.09,1275.59)break;}
  1732.                     case 'SRA4'{$format array(637.80,907.09)break;}
  1733.                     case 'LETTER'{$format array(612.00,792.00)break;}
  1734.                     case 'LEGAL'{$format array(612.00,1008.00)break;}
  1735.                     case 'EXECUTIVE'{$format array(521.86,756.00)break;}
  1736.                     case 'FOLIO'{$format array(612.00,936.00)break;}
  1737.                 }
  1738.                 $this->fwPt = $format[0];
  1739.                 $this->fhPt = $format[1];
  1740.             else {
  1741.                 $this->fwPt = $format[0$this->k;
  1742.                 $this->fhPt = $format[1$this->k;
  1743.             }
  1744.             $this->setPageOrientation($orientation);
  1745.         }
  1746.         
  1747.         /**
  1748.         * Set page orientation.
  1749.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1750.         * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1751.         * @param float $bottommargin bottom margin of the page.
  1752.         * @access public
  1753.         * @since 3.0.015 (2008-06-06)
  1754.         */
  1755.         public function setPageOrientation($orientation$autopagebreak=''$bottommargin=''{
  1756.             $orientation strtoupper($orientation);
  1757.             if (($orientation == 'P'OR ($orientation == 'PORTRAIT')) {
  1758.                 $this->CurOrientation = 'P';
  1759.                 $this->wPt = $this->fwPt;
  1760.                 $this->hPt = $this->fhPt;
  1761.             elseif (($orientation == 'L'OR ($orientation == 'LANDSCAPE')) {
  1762.                 $this->CurOrientation = 'L';
  1763.                 $this->wPt = $this->fhPt;
  1764.                 $this->hPt = $this->fwPt;
  1765.             else {
  1766.                 $this->Error('Incorrect orientation: '.$orientation);
  1767.             }
  1768.             $this->w = $this->wPt / $this->k;
  1769.             $this->h = $this->hPt / $this->k;
  1770.             if ($this->empty_string($autopagebreak)) {
  1771.                 if (isset($this->AutoPageBreak)) {
  1772.                     $autopagebreak $this->AutoPageBreak;
  1773.                 else {
  1774.                     $autopagebreak true;
  1775.                 }
  1776.             }
  1777.             if ($this->empty_string($bottommargin)) {
  1778.                 if (isset($this->bMargin)) {
  1779.                     $bottommargin $this->bMargin;
  1780.                 else {
  1781.                     // default value = 2 cm
  1782.                     $bottommargin 28.35 $this->k;
  1783.                 }
  1784.             }
  1785.             $this->SetAutoPageBreak($autopagebreak$bottommargin);
  1786.             // store page dimensions
  1787.             $this->pagedim[$this->pagearray('w' => $this->wPt'h' => $this->hPt'wk' => $this->w'hk' => $this->h'tm' => $this->tMargin'bm' => $bottommargin'lm' => $this->lMargin'rm' => $this->rMargin'pb' => $autopagebreak'or' => $this->CurOrientation'olm' => $this->original_lMargin'orm' => $this->original_rMargin);
  1788.         }
  1789.         
  1790.         /**
  1791.          * Set regular expression to detect withespaces or word separators.
  1792.          * @param string $re regular expression (leave empty for default).
  1793.          * @access public
  1794.          * @since 4.6.016 (2009-06-15)
  1795.          */
  1796.         public function setSpacesRE($re='/[\s]/'{
  1797.             // if PCRE unicode support is turned ON:
  1798.             //     \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1799.             //     \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1800.             //     \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1801.             $this->re_spaces = $re;
  1802.         }
  1803.             
  1804.         /**
  1805.          * Enable or disable Right-To-Left language mode
  1806.          * @param Boolean $enable if true enable Right-To-Left language mode.
  1807.          * @param Boolean $resetx if true reset the X position on direction change.
  1808.          * @access public
  1809.         * @since 2.0.000 (2008-01-03)
  1810.          */
  1811.         public function setRTL($enable$resetx=true{
  1812.             $enable $enable true false;
  1813.             $resetx ($resetx AND ($enable != $this->rtl));
  1814.             $this->rtl = $enable;
  1815.             $this->tmprtl = false;
  1816.             if ($resetx{
  1817.                 $this->Ln(0);
  1818.             }
  1819.         }
  1820.         
  1821.         /**
  1822.          * Return the RTL status
  1823.          * @return boolean 
  1824.          * @access public
  1825.          * @since 4.0.012 (2008-07-24)
  1826.          */
  1827.         public function getRTL({
  1828.             return $this->rtl;
  1829.         }
  1830.         
  1831.         /**
  1832.         * Force temporary RTL language direction
  1833.         * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  1834.         * @access public
  1835.         * @since 2.1.000 (2008-01-09)
  1836.         */
  1837.         public function setTempRTL($mode{
  1838.             switch ($mode{
  1839.                 case false:
  1840.                 case 'L':
  1841.                 case 'R'{
  1842.                     $this->tmprtl = $mode;
  1843.                 }
  1844.             }
  1845.         }
  1846.         
  1847.         /**
  1848.         * Set the last cell height.
  1849.         * @param float $h cell height.
  1850.         * @author Nicola Asuni
  1851.         * @access public
  1852.         * @since 1.53.0.TC034
  1853.         */
  1854.         public function setLastH($h{
  1855.             $this->lasth = $h;
  1856.         }
  1857.         
  1858.         /**
  1859.         * Get the last cell height.
  1860.         * @return last cell height
  1861.         * @access public
  1862.         * @since 4.0.017 (2008-08-05)
  1863.         */
  1864.         public function getLastH({
  1865.             return $this->lasth;
  1866.         }
  1867.         
  1868.         /**
  1869.         * Set the adjusting factor to convert pixels to user units.
  1870.         * @param float $scale adjusting factor to convert pixels to user units.
  1871.         * @author Nicola Asuni
  1872.         * @access public
  1873.         * @since 1.5.2
  1874.         */
  1875.         public function setImageScale($scale{
  1876.             $this->imgscale = $scale;
  1877.         }
  1878.  
  1879.         /**
  1880.         * Returns the adjusting factor to convert pixels to user units.
  1881.         * @return float adjusting factor to convert pixels to user units.
  1882.         * @author Nicola Asuni
  1883.         * @access public
  1884.         * @since 1.5.2
  1885.         */
  1886.         public function getImageScale({
  1887.             return $this->imgscale;
  1888.         }
  1889.                 
  1890.         /**
  1891.         * Returns an array of page dimensions:
  1892.         * <ul><li>$this->pagedim[$this->page]['w'] => page_width_in_points</li><li>$this->pagedim[$this->page]['h'] => height in points</li><li>$this->pagedim[$this->page]['wk'] => page_width_in_points</li><li>$this->pagedim[$this->page]['hk'] => height</li><li>$this->pagedim[$this->page]['tm'] => top_margin</li><li>$this->pagedim[$this->page]['bm'] => bottom_margin</li><li>$this->pagedim[$this->page]['lm'] => left_margin</li><li>$this->pagedim[$this->page]['rm'] => right_margin</li><li>$this->pagedim[$this->page]['pb'] => auto_page_break</li><li>$this->pagedim[$this->page]['or'] => page_orientation</li><li>$this->pagedim[$this->page]['olm'] => original_left_margin</li><li>$this->pagedim[$this->page]['orm'] => original_right_margin</li></ul>
  1893.         * @param int $pagenum page number (empty = current page)
  1894.         * @return array of page dimensions.
  1895.         * @author Nicola Asuni
  1896.         * @access public
  1897.         * @since 4.5.027 (2009-03-16)
  1898.         */
  1899.         public function getPageDimensions($pagenum=''{
  1900.             if (empty($pagenum)) {
  1901.                 $pagenum $this->page;
  1902.             }
  1903.             return $this->pagedim[$pagenum];
  1904.         }
  1905.         
  1906.         /**
  1907.         * Returns the page width in units.
  1908.         * @param int $pagenum page number (empty = current page)
  1909.         * @return int page width.
  1910.         * @author Nicola Asuni
  1911.         * @access public
  1912.         * @since 1.5.2
  1913.         * @see getPageDimensions()
  1914.         */
  1915.         public function getPageWidth($pagenum=''{
  1916.             if (empty($pagenum)) {
  1917.                 return $this->w;
  1918.             }
  1919.             return $this->pagedim[$pagenum]['w'];
  1920.         }
  1921.  
  1922.         /**
  1923.         * Returns the page height in units.
  1924.         * @param int $pagenum page number (empty = current page)
  1925.         * @return int page height.
  1926.         * @author Nicola Asuni
  1927.         * @access public
  1928.         * @since 1.5.2
  1929.         * @see getPageDimensions()
  1930.         */
  1931.         public function getPageHeight($pagenum=''{
  1932.             if (empty($pagenum)) {
  1933.                 return $this->h;
  1934.             }
  1935.             return $this->pagedim[$pagenum]['h'];
  1936.         }
  1937.  
  1938.         /**
  1939.         * Returns the page break margin.
  1940.         * @param int $pagenum page number (empty = current page)
  1941.         * @return int page break margin.
  1942.         * @author Nicola Asuni
  1943.         * @access public
  1944.         * @since 1.5.2
  1945.         * @see getPageDimensions()
  1946.         */
  1947.         public function getBreakMargin($pagenum=''{
  1948.             if (empty($pagenum)) {
  1949.                 return $this->bMargin;
  1950.             }
  1951.             return $this->pagedim[$pagenum]['bm'];
  1952.         }
  1953.  
  1954.         /**
  1955.         * Returns the scale factor (number of points in user unit).
  1956.         * @return int scale factor.
  1957.         * @author Nicola Asuni
  1958.         * @access public
  1959.         * @since 1.5.2
  1960.         */
  1961.         public function getScaleFactor({
  1962.             return $this->k;
  1963.         }
  1964.  
  1965.         /**
  1966.         * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  1967.         * @param float $left Left margin.
  1968.         * @param float $top Top margin.
  1969.         * @param float $right Right margin. Default value is the left one.
  1970.         * @access public
  1971.         * @since 1.0
  1972.         * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  1973.         */
  1974.         public function SetMargins($left$top$right=-1{
  1975.             //Set left, top and right margins
  1976.             $this->lMargin = $left;
  1977.             $this->tMargin = $top;
  1978.             if ($right == -1{
  1979.                 $right $left;
  1980.             }
  1981.             $this->rMargin = $right;
  1982.         }
  1983.  
  1984.         /**
  1985.         * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
  1986.         * @param float $margin The margin.
  1987.         * @access public
  1988.         * @since 1.4
  1989.         * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1990.         */
  1991.         public function SetLeftMargin($margin{
  1992.             //Set left margin
  1993.             $this->lMargin=$margin;
  1994.             if (($this->page > 0AND ($this->x < $margin)) {
  1995.                 $this->x = $margin;
  1996.             }
  1997.         }
  1998.  
  1999.         /**
  2000.         * Defines the top margin. The method can be called before creating the first page.
  2001.         * @param float $margin The margin.
  2002.         * @access public
  2003.         * @since 1.5
  2004.         * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2005.         */
  2006.         public function SetTopMargin($margin{
  2007.             //Set top margin
  2008.             $this->tMargin=$margin;
  2009.             if (($this->page > 0AND ($this->y < $margin)) {
  2010.                 $this->y = $margin;
  2011.             }
  2012.         }
  2013.  
  2014.         /**
  2015.         * Defines the right margin. The method can be called before creating the first page.
  2016.         * @param float $margin The margin.
  2017.         * @access public
  2018.         * @since 1.5
  2019.         * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2020.         */
  2021.         public function SetRightMargin($margin{
  2022.             $this->rMargin=$margin;
  2023.             if (($this->page > 0AND ($this->x > ($this->w - $margin))) {
  2024.                 $this->x = $this->w - $margin;
  2025.             }
  2026.         }
  2027.  
  2028.         /**
  2029.         * Set the internal Cell padding.
  2030.         * @param float $pad internal padding.
  2031.         * @access public
  2032.         * @since 2.1.000 (2008-01-09)
  2033.         * @see Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2034.         */
  2035.         public function SetCellPadding($pad{
  2036.             $this->cMargin = $pad;
  2037.         }
  2038.  
  2039.         /**
  2040.         * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
  2041.         * @param boolean $auto Boolean indicating if mode should be on or off.
  2042.         * @param float $margin Distance from the bottom of the page.
  2043.         * @access public
  2044.         * @since 1.0
  2045.         * @see Cell(), MultiCell(), AcceptPageBreak()
  2046.         */
  2047.         public function SetAutoPageBreak($auto$margin=0{
  2048.             //Set auto page break mode and triggering margin
  2049.             $this->AutoPageBreak = $auto;
  2050.             $this->bMargin = $margin;
  2051.             $this->PageBreakTrigger = $this->h - $margin;
  2052.         }
  2053.  
  2054.         /**
  2055.         * Defines the way the document is to be displayed by the viewer.
  2056.         * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  2057.         * @param string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  2058.         * @param string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  2059.         * @access public
  2060.         * @since 1.2
  2061.         */
  2062.         public function SetDisplayMode($zoom$layout='SinglePage'$mode='UseNone'{
  2063.             //Set display mode in viewer
  2064.             if (($zoom == 'fullpage'OR ($zoom == 'fullwidth'OR ($zoom == 'real'OR ($zoom == 'default'OR (!is_string($zoom))) {
  2065.                 $this->ZoomMode = $zoom;
  2066.             else {
  2067.                 $this->Error('Incorrect zoom display mode: '.$zoom);
  2068.             }
  2069.             switch ($layout{
  2070.                 case 'default':
  2071.                 case 'single':
  2072.                 case 'SinglePage'{
  2073.                     $this->LayoutMode = 'SinglePage';
  2074.                     break;
  2075.                 }
  2076.                 case 'continuous':
  2077.                 case 'OneColumn'{
  2078.                     $this->LayoutMode = 'OneColumn';
  2079.                     break;
  2080.                 }
  2081.                 case 'two':
  2082.                 case 'TwoColumnLeft'{
  2083.                     $this->LayoutMode = 'TwoColumnLeft';
  2084.                     break;
  2085.                 }
  2086.                 case 'TwoColumnRight'{
  2087.                     $this->LayoutMode = 'TwoColumnRight';
  2088.                     break;
  2089.                 }
  2090.                 case 'TwoPageLeft'{
  2091.                     $this->LayoutMode = 'TwoPageLeft';
  2092.                     break;
  2093.                 }
  2094.                 case 'TwoPageRight'{
  2095.                     $this->LayoutMode = 'TwoPageRight';
  2096.                     break;
  2097.                 }
  2098.                 default{
  2099.                     $this->LayoutMode = 'SinglePage';
  2100.                 }
  2101.             }
  2102.             switch ($mode{
  2103.                 case 'UseNone'{
  2104.                     $this->PageMode = 'UseNone';
  2105.                     break;
  2106.                 }
  2107.                 case 'UseOutlines'{
  2108.                     $this->PageMode = 'UseOutlines';
  2109.                     break;
  2110.                 }
  2111.                 case 'UseThumbs'{
  2112.                     $this->PageMode = 'UseThumbs';
  2113.                     break;
  2114.                 }
  2115.                 case 'FullScreen'{
  2116.                     $this->PageMode = 'FullScreen';
  2117.                     break;
  2118.                 }
  2119.                 case 'UseOC'{
  2120.                     $this->PageMode = 'UseOC';
  2121.                     break;
  2122.                 }
  2123.                 case ''{
  2124.                     $this->PageMode = 'UseAttachments';
  2125.                     break;
  2126.                 }
  2127.                 default{
  2128.                     $this->PageMode = 'UseNone';
  2129.                 }
  2130.             }
  2131.         }
  2132.  
  2133.         /**
  2134.         * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
  2135.         * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2136.         * @param boolean $compress Boolean indicating if compression must be enabled.
  2137.         * @access public
  2138.         * @since 1.4
  2139.         */
  2140.         public function SetCompression($compress{
  2141.             //Set page compression
  2142.             if (function_exists('gzcompress')) {
  2143.                 $this->compress = $compress;
  2144.             else {
  2145.                 $this->compress = false;
  2146.             }
  2147.         }
  2148.  
  2149.         /**
  2150.         * Defines the title of the document.
  2151.         * @param string $title The title.
  2152.         * @access public
  2153.         * @since 1.2
  2154.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2155.         */
  2156.         public function SetTitle($title{
  2157.             //Title of document
  2158.             $this->title = $title;
  2159.         }
  2160.  
  2161.         /**
  2162.         * Defines the subject of the document.
  2163.         * @param string $subject The subject.
  2164.         * @access public
  2165.         * @since 1.2
  2166.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2167.         */
  2168.         public function SetSubject($subject{
  2169.             //Subject of document
  2170.             $this->subject = $subject;
  2171.         }
  2172.  
  2173.         /**
  2174.         * Defines the author of the document.
  2175.         * @param string $author The name of the author.
  2176.         * @access public
  2177.         * @since 1.2
  2178.         * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2179.         */
  2180.         public function SetAuthor($author{
  2181.             //Author of document
  2182.             $this->author = $author;
  2183.         }
  2184.  
  2185.         /**
  2186.         * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2187.         * @param string $keywords The list of keywords.
  2188.         * @access public
  2189.         * @since 1.2
  2190.         * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2191.         */
  2192.         public function SetKeywords($keywords{
  2193.             //Keywords of document
  2194.             $this->keywords = $keywords;
  2195.         }
  2196.  
  2197.         /**
  2198.         * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2199.         * @param string $creator The name of the creator.
  2200.         * @access public
  2201.         * @since 1.2
  2202.         * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2203.         */
  2204.         public function SetCreator($creator{
  2205.             //Creator of document
  2206.             $this->creator = $creator;
  2207.         }
  2208.         
  2209.         /**
  2210.         * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
  2211.         * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  2212.         * @param string $msg The error message
  2213.         * @access public
  2214.         * @since 1.0
  2215.         */
  2216.         public function Error($msg{
  2217.             // unset all class variables
  2218.             $this->_destroy(true);
  2219.             // exit program and print error
  2220.             die('<strong>TCPDF ERROR: </strong>'.$msg);
  2221.         }
  2222.  
  2223.         /**
  2224.         * This method begins the generation of the PDF document.
  2225.         * It is not necessary to call it explicitly because AddPage() does it automatically.
  2226.         * Note: no page is created by this method
  2227.         * @access public
  2228.         * @since 1.0
  2229.         * @see AddPage(), Close()
  2230.         */
  2231.         public function Open({
  2232.             //Begin document
  2233.             $this->state = 1;
  2234.         }
  2235.  
  2236.         /**
  2237.         * Terminates the PDF document.
  2238.         * It is not necessary to call this method explicitly because Output() does it automatically.
  2239.         * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2240.         * @access public
  2241.         * @since 1.0
  2242.         * @see Open(), Output()
  2243.         */
  2244.         public function Close({
  2245.             if ($this->state == 3{
  2246.                 return;
  2247.             }
  2248.             if ($this->page == 0{
  2249.                 $this->AddPage();
  2250.             }
  2251.             // close page
  2252.             $this->endPage();
  2253.             // close document
  2254.             $this->_enddoc();
  2255.             // unset all class variables (except critical ones)
  2256.             $this->_destroy(false);
  2257.         }
  2258.         
  2259.         /**
  2260.         * Move pointer at the specified document page and update page dimensions.
  2261.         * @param int $pnum page number
  2262.         * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2263.         * @access public
  2264.         * @since 2.1.000 (2008-01-07)
  2265.         * @see getPage(), lastpage(), getNumPages()
  2266.         */
  2267.         public function setPage($pnum$resetmargins=false{
  2268.             if ($pnum == $this->page{
  2269.                 return;
  2270.             }
  2271.             if (($pnum 0AND ($pnum <= $this->numpages)) {
  2272.                 $this->state = 2;
  2273.                 // save current graphic settings
  2274.                 //$gvars = $this->getGraphicVars();
  2275.                 $oldpage $this->page;
  2276.                 $this->page = $pnum;
  2277.                 $this->wPt = $this->pagedim[$this->page]['w'];
  2278.                 $this->hPt = $this->pagedim[$this->page]['h'];
  2279.                 $this->w = $this->wPt / $this->k;
  2280.                 $this->h = $this->hPt / $this->k;
  2281.                 $this->tMargin = $this->pagedim[$this->page]['tm'];
  2282.                 $this->bMargin = $this->pagedim[$this->page]['bm'];
  2283.                 $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2284.                 $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2285.                 $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2286.                 $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2287.                 $this->SetAutoPageBreak($this->AutoPageBreak$this->bMargin);
  2288.                 // restore graphic settings
  2289.                 //$this->setGraphicVars($gvars);
  2290.                 if ($resetmargins{
  2291.                     $this->lMargin = $this->pagedim[$this->page]['olm'];
  2292.                     $this->rMargin = $this->pagedim[$this->page]['orm'];
  2293.                     $this->SetY($this->tMargin);
  2294.                 else {
  2295.                     // account for booklet mode
  2296.                     if ($this->pagedim[$this->page]['olm'!= $this->pagedim[$oldpage]['olm']{
  2297.                         $deltam $this->pagedim[$this->page]['olm'$this->pagedim[$this->page]['orm'];
  2298.                         $this->lMargin += $deltam;
  2299.                         $this->rMargin -= $deltam;
  2300.                     }
  2301.                 }
  2302.             else {
  2303.                 $this->Error('Wrong page number on setPage() function.');
  2304.             }
  2305.         }
  2306.         
  2307.         /**
  2308.         * Reset pointer to the last document page.
  2309.         * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2310.         * @access public
  2311.         * @since 2.0.000 (2008-01-04)
  2312.         * @see setPage(), getPage(), getNumPages()
  2313.         */
  2314.         public function lastPage($resetmargins=false{
  2315.             $this->setPage($this->getNumPages()$resetmargins);
  2316.         }
  2317.         
  2318.         /**
  2319.         * Get current document page number.
  2320.         * @return int page number
  2321.         * @access public
  2322.         * @since 2.1.000 (2008-01-07)
  2323.         * @see setPage(), lastpage(), getNumPages()
  2324.         */
  2325.         public function getPage({
  2326.             return $this->page;
  2327.         }
  2328.         
  2329.         
  2330.         /**
  2331.         * Get the total number of insered pages.
  2332.         * @return int number of pages
  2333.         * @access public
  2334.         * @since 2.1.000 (2008-01-07)
  2335.         * @see setPage(), getPage(), lastpage()
  2336.         */
  2337.         public function getNumPages({
  2338.             return $this->numpages;
  2339.         }
  2340.  
  2341.         /**
  2342.         * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled).
  2343.         * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2344.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2345.         * @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).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  2346.         * @access public
  2347.         * @since 1.0
  2348.         * @see startPage(), endPage()
  2349.         */
  2350.         public function AddPage($orientation=''$format=''{
  2351.             if (!isset($this->original_lMargin)) {
  2352.                 $this->original_lMargin = $this->lMargin;
  2353.             }
  2354.             if (!isset($this->original_rMargin)) {
  2355.                 $this->original_rMargin = $this->rMargin;
  2356.             }
  2357.             // terminate previous page
  2358.             $this->endPage();
  2359.             // start new page
  2360.             $this->startPage($orientation$format);
  2361.         }
  2362.  
  2363.         /**
  2364.         * Terminate the current page
  2365.         * @access protected
  2366.         * @since 4.2.010 (2008-11-14)
  2367.         * @see startPage(), AddPage()
  2368.         */
  2369.         protected function endPage({
  2370.             // check if page is already closed
  2371.             if (($this->page == 0OR ($this->numpages > $this->pageOR (!$this->pageopen[$this->page])) {
  2372.                 return;
  2373.             }
  2374.             $this->InFooter = true;
  2375.             // print page footer
  2376.             $this->setFooter();
  2377.             // close page
  2378.             $this->_endpage();
  2379.             // mark page as closed
  2380.             $this->pageopen[$this->pagefalse;
  2381.             $this->InFooter = false;
  2382.         }
  2383.  
  2384.         /**
  2385.         * Starts a new page to the document. The page must be closed using the endPage() function.
  2386.         * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2387.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2388.         * @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).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  2389.         * @access protected
  2390.         * @since 4.2.010 (2008-11-14)
  2391.         * @see endPage(), AddPage()
  2392.         */
  2393.         protected function startPage($orientation=''$format=''{
  2394.             if ($this->numpages > $this->page{
  2395.                 // this page has been already added
  2396.                 $this->setPage($this->page + 1);
  2397.                 $this->SetY($this->tMargin);
  2398.                 return;
  2399.             }
  2400.             // start a new page
  2401.             if ($this->state == 0{
  2402.                 $this->Open();
  2403.             }
  2404.             ++$this->numpages;
  2405.             $this->swapMargins($this->booklet);
  2406.             // save current graphic settings
  2407.             $gvars $this->getGraphicVars();
  2408.             // start new page
  2409.             $this->_beginpage($orientation$format);
  2410.             // mark page as open
  2411.             $this->pageopen[$this->pagetrue;
  2412.             // restore graphic settings
  2413.             $this->setGraphicVars($gvars);
  2414.             // mark this point
  2415.             $this->setPageMark();
  2416.             // print page header
  2417.             $this->setHeader();
  2418.             // restore graphic settings
  2419.             $this->setGraphicVars($gvars);
  2420.             // mark this point
  2421.             $this->setPageMark();
  2422.             // print table header (if any)
  2423.             $this->setTableHeader();
  2424.         }
  2425.             
  2426.         /**
  2427.           * Set start-writing mark on current page for multicell borders and fills.
  2428.           * This function must be called after calling Image() function for a background image.
  2429.           * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2430.           * @access public
  2431.           * @since 4.0.016 (2008-07-30)
  2432.          */
  2433.         public function setPageMark({
  2434.             $this->intmrk[$this->page$this->pagelen[$this->page];
  2435.             $this->setContentMark();
  2436.         }
  2437.         
  2438.         /**
  2439.           * Set start-writing mark on selected page.
  2440.           * @param int $page page number (default is the current page)
  2441.           * @access protected
  2442.           * @since 4.6.021 (2009-07-20)
  2443.          */
  2444.         protected function setContentMark($page=0{
  2445.             if ($page <= 0{
  2446.                 $page $this->page;
  2447.             }
  2448.             if (isset($this->footerlen[$page])) {
  2449.                 $this->cntmrk[$page$this->pagelen[$page$this->footerlen[$page];
  2450.             else {
  2451.                 $this->cntmrk[$page$this->pagelen[$page];
  2452.             }
  2453.         }
  2454.         
  2455.         /**
  2456.           * Set header data.
  2457.          * @param string $ln header image logo
  2458.          * @param string $lw header image logo width in mm
  2459.          * @param string $ht string to print as title on document header
  2460.          * @param string $hs string to print on document header
  2461.          * @access public
  2462.          */
  2463.         public function setHeaderData($ln=''$lw=0$ht=''$hs=''{
  2464.             $this->header_logo = $ln;
  2465.             $this->header_logo_width = $lw;
  2466.             $this->header_title = $ht;
  2467.             $this->header_string = $hs;
  2468.         }
  2469.         
  2470.         /**
  2471.           * Returns header data:
  2472.           * <ul><li>$ret['logo'] = logo image</li><li>$ret['logo_width'] = width of the image logo in user units</li><li>$ret['title'] = header title</li><li>$ret['string'] = header description string</li></ul>
  2473.          * @return array() 
  2474.          * @access public
  2475.          * @since 4.0.012 (2008-07-24)
  2476.          */
  2477.         public function getHeaderData({
  2478.             $ret array();
  2479.             $ret['logo'$this->header_logo;
  2480.             $ret['logo_width'$this->header_logo_width;
  2481.             $ret['title'$this->header_title;
  2482.             $ret['string'$this->header_string;
  2483.             return $ret;
  2484.         }
  2485.         
  2486.         /**
  2487.           * Set header margin.
  2488.          * (minimum distance between header and top page margin)
  2489.          * @param int $hm distance in user units
  2490.          * @access public
  2491.          */
  2492.         public function setHeaderMargin($hm=10{
  2493.             $this->header_margin = $hm;
  2494.         }
  2495.         
  2496.         /**
  2497.           * Returns header margin in user units.
  2498.          * @return float 
  2499.          * @since 4.0.012 (2008-07-24)
  2500.          * @access public
  2501.          */
  2502.         public function getHeaderMargin({
  2503.             return $this->header_margin;
  2504.         }
  2505.         
  2506.         /**
  2507.           * Set footer margin.
  2508.          * (minimum distance between footer and bottom page margin)
  2509.          * @param int $fm distance in user units
  2510.          * @access public
  2511.          */
  2512.         public function setFooterMargin($fm=10{
  2513.             $this->footer_margin = $fm;
  2514.         }
  2515.         
  2516.         /**
  2517.           * Returns footer margin in user units.
  2518.          * @return float 
  2519.          * @since 4.0.012 (2008-07-24)
  2520.          * @access public
  2521.          */
  2522.         public function getFooterMargin({
  2523.             return $this->footer_margin;
  2524.         }
  2525.         /**
  2526.           * Set a flag to print page header.
  2527.          * @param boolean $val set to true to print the page header (default), false otherwise.
  2528.          * @access public
  2529.          */
  2530.         public function setPrintHeader($val=true{
  2531.             $this->print_header = $val;
  2532.         }
  2533.         
  2534.         /**
  2535.           * Set a flag to print page footer.
  2536.          * @param boolean $value set to true to print the page footer (default), false otherwise.
  2537.          * @access public
  2538.          */
  2539.         public function setPrintFooter($val=true{
  2540.             $this->print_footer = $val;
  2541.         }
  2542.         
  2543.         /**
  2544.           * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  2545.          * @return float 
  2546.          * @access public
  2547.          */
  2548.         public function getImageRBX({
  2549.             return $this->img_rb_x;
  2550.         }
  2551.         
  2552.         /**
  2553.           * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  2554.          * @return float 
  2555.          * @access public
  2556.          */
  2557.         public function getImageRBY({
  2558.             return $this->img_rb_y;
  2559.         }
  2560.         
  2561.         /**
  2562.           * This method is used to render the page header.
  2563.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2564.          * @access public
  2565.          */
  2566.         public function Header({
  2567.             $ormargins $this->getOriginalMargins();
  2568.             $headerfont $this->getHeaderFont();
  2569.             $headerdata $this->getHeaderData();
  2570.             if (($headerdata['logo']AND ($headerdata['logo'!= K_BLANK_IMAGE)) {
  2571.                 $this->Image(K_PATH_IMAGES.$headerdata['logo']$this->GetX()$this->getHeaderMargin()$headerdata['logo_width']);
  2572.                 $imgy $this->getImageRBY();
  2573.             else {
  2574.                 $imgy $this->GetY();
  2575.             }
  2576.             $cell_height round(($this->getCellHeightRatio($headerfont[2]$this->getScaleFactor()2);
  2577.             // set starting margin for text data cell
  2578.             if ($this->getRTL()) {
  2579.                 $header_x $ormargins['right'($headerdata['logo_width'1.1);
  2580.             else {
  2581.                 $header_x $ormargins['left'($headerdata['logo_width'1.1);
  2582.             }
  2583.             $this->SetTextColor(000);
  2584.             // header title
  2585.             $this->SetFont($headerfont[0]'B'$headerfont[21);
  2586.             $this->SetX($header_x);            
  2587.             $this->Cell(0$cell_height$headerdata['title']01''0''0);
  2588.             // header string
  2589.             $this->SetFont($headerfont[0]$headerfont[1]$headerfont[2]);
  2590.             $this->SetX($header_x);
  2591.             $this->MultiCell(0$cell_height$headerdata['string']0''01''''true0false);
  2592.             // print an ending header line
  2593.             $this->SetLineStyle(array('width' => 0.85 $this->getScaleFactor()'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));
  2594.             $this->SetY((2.835 $this->getScaleFactor()) max($imgy$this->GetY()));
  2595.             if ($this->getRTL()) {
  2596.                 $this->SetX($ormargins['right']);
  2597.             else {
  2598.                 $this->SetX($ormargins['left']);
  2599.             }
  2600.             $this->Cell(00'''T'0'C');
  2601.         }
  2602.         
  2603.         /**
  2604.           * This method is used to render the page footer.
  2605.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2606.          * @access public
  2607.          */
  2608.         public function Footer({                
  2609.             $cur_y $this->GetY();
  2610.             $ormargins $this->getOriginalMargins();
  2611.             $this->SetTextColor(000);            
  2612.             //set style for cell border
  2613.             $line_width 0.85 $this->getScaleFactor();
  2614.             $this->SetLineStyle(array('width' => $line_width'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));
  2615.             //print document barcode
  2616.             $barcode $this->getBarcode();
  2617.             if (!empty($barcode)) {
  2618.                 $this->Ln($line_width);
  2619.                 $barcode_width round(($this->getPageWidth($ormargins['left'$ormargins['right'])/3);
  2620.                 $this->write1DBarcode($barcode'C128B'$this->GetX()$cur_y $line_width$barcode_width(($this->getFooterMargin(3$line_width)0.3'''');    
  2621.             }
  2622.             if (empty($this->pagegroups)) {
  2623.                 $pagenumtxt $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  2624.             else {
  2625.                 $pagenumtxt $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  2626.             }        
  2627.             $this->SetY($cur_y);
  2628.             //Print page number
  2629.             if ($this->getRTL()) {
  2630.                 $this->SetX($ormargins['right']);
  2631.                 $this->Cell(00$pagenumtxt'T'0'L');
  2632.             else {
  2633.                 $this->SetX($ormargins['left']);
  2634.                 $this->Cell(00$pagenumtxt'T'0'R');
  2635.             }
  2636.         }
  2637.         
  2638.         /**
  2639.           * This method is used to render the page header.
  2640.           * @access protected
  2641.           * @since 4.0.012 (2008-07-24)
  2642.          */
  2643.         protected function setHeader({
  2644.             if ($this->print_header{
  2645.                 $lasth $this->lasth;
  2646.                 $this->_out('q');
  2647.                 $this->rMargin = $this->original_rMargin;
  2648.                 $this->lMargin = $this->original_lMargin;
  2649.                 $this->cMargin = 0;
  2650.                 //set current position
  2651.                 if ($this->rtl{
  2652.                     $this->SetXY($this->original_rMargin$this->header_margin);
  2653.                 else {
  2654.                     $this->SetXY($this->original_lMargin$this->header_margin);
  2655.                 }
  2656.                 $this->SetFont($this->header_font[0]$this->header_font[1]$this->header_font[2]);
  2657.                 $this->Header();
  2658.                 //restore position
  2659.                 if ($this->rtl{
  2660.                     $this->SetXY($this->original_rMargin$this->tMargin);
  2661.                 else {
  2662.                     $this->SetXY($this->original_lMargin$this->tMargin);
  2663.                 }
  2664.                 $this->_out('Q');
  2665.                 $this->lasth = $lasth;
  2666.             }
  2667.         }
  2668.         
  2669.         /**
  2670.           * This method is used to render the page footer.
  2671.           * @access protected
  2672.           * @since 4.0.012 (2008-07-24)
  2673.          */
  2674.         protected function setFooter({
  2675.             //Page footer
  2676.             // save current graphic settings
  2677.             $gvars $this->getGraphicVars();
  2678.             // mark this point
  2679.             $this->footerpos[$this->page$this->pagelen[$this->page];
  2680.             $this->_out("\n");
  2681.             if ($this->print_footer{
  2682.                 $lasth $this->lasth;
  2683.                 $this->_out('q');
  2684.                 $this->rMargin = $this->original_rMargin;
  2685.                 $this->lMargin = $this->original_lMargin;
  2686.                 $this->cMargin = 0;
  2687.                 //set current position
  2688.                 $footer_y $this->h - $this->footer_margin;
  2689.                 if ($this->rtl{
  2690.                     $this->SetXY($this->original_rMargin$footer_y);
  2691.                 else {
  2692.                     $this->SetXY($this->original_lMargin$footer_y);
  2693.                 }
  2694.                 $this->SetFont($this->footer_font[0]$this->footer_font[1]$this->footer_font[2]);
  2695.                 $this->Footer();
  2696.                 //restore position
  2697.                 if ($this->rtl{
  2698.                     $this->SetXY($this->original_rMargin$this->tMargin);
  2699.                 else {
  2700.                     $this->SetXY($this->original_lMargin$this->tMargin);
  2701.                 }
  2702.                 $this->_out('Q');
  2703.                 $this->lasth = $lasth;
  2704.             }
  2705.             // restore graphic settings
  2706.             $this->setGraphicVars($gvars);
  2707.             // calculate footer lenght
  2708.             $this->footerlen[$this->page$this->pagelen[$this->page$this->footerpos[$this->page1;
  2709.         }
  2710.  
  2711.         /**
  2712.           * This method is used to render the table header on new page (if any).
  2713.           * @access protected
  2714.           * @since 4.5.030 (2009-03-25)
  2715.          */
  2716.         protected function setTableHeader({
  2717.             if (isset($this->theadMargins['top'])) {
  2718.                 // restore the original top-margin
  2719.                 $this->tMargin = $this->theadMargins['top'];
  2720.                 $this->pagedim[$this->page]['tm'$this->tMargin;
  2721.                 $this->y = $this->tMargin;
  2722.             }
  2723.             if (!$this->empty_string($this->thead)) {
  2724.                 // set margins
  2725.                 $prev_lMargin $this->lMargin;
  2726.                 $prev_rMargin $this->rMargin;
  2727.                 $this->lMargin = $this->pagedim[$this->page]['olm'];
  2728.                 $this->rMargin = $this->pagedim[$this->page]['orm'];
  2729.                 $this->cMargin = $this->theadMargins['cmargin'];
  2730.                 // print table header
  2731.                 $this->writeHTML($this->theadfalsefalsefalsefalse'');
  2732.                 // set new top margin to skip the table headers
  2733.                 if (!isset($this->theadMargins['top'])) {
  2734.                     $this->theadMargins['top'$this->tMargin;
  2735.                 }
  2736.                 $this->tMargin = $this->y;
  2737.                 $this->pagedim[$this->page]['tm'$this->tMargin;
  2738.                 $this->lasth = 0;
  2739.                 $this->lMargin = $prev_lMargin;
  2740.                 $this->rMargin = $prev_rMargin;
  2741.             }
  2742.         }
  2743.         
  2744.         /**
  2745.         * Returns the current page number.
  2746.         * @return int page number
  2747.         * @access public
  2748.         * @since 1.0
  2749.         * @see AliasNbPages(), getAliasNbPages()
  2750.         */
  2751.         public function PageNo({
  2752.             return $this->page;
  2753.         }
  2754.  
  2755.         /**
  2756.         * Defines a new spot color.
  2757.         * It can be expressed in RGB components or gray scale.
  2758.         * The method can be called before the first page is created and the value is retained from page to page.
  2759.         * @param int $c Cyan color for CMYK. Value between 0 and 255
  2760.         * @param int $m Magenta color for CMYK. Value between 0 and 255
  2761.         * @param int $y Yellow color for CMYK. Value between 0 and 255
  2762.         * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  2763.         * @access public
  2764.         * @since 4.0.024 (2008-09-12)
  2765.         * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2766.         */
  2767.         public function AddSpotColor($name$c$m$y$k{
  2768.             if (!isset($this->spot_colors[$name])) {
  2769.                 $i count($this->spot_colors);
  2770.                 $this->spot_colors[$namearray('i' => $i'c' => $c'm' => $m'y' => $y'k' => $k);
  2771.             }
  2772.         }
  2773.  
  2774.         /**
  2775.         * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  2776.         * It can be expressed in RGB components or gray scale.
  2777.         * The method can be called before the first page is created and the value is retained from page to page.
  2778.         * @param array $color array of colors
  2779.         * @access public
  2780.         * @since 3.1.000 (2008-06-11)
  2781.         * @see SetDrawColor()
  2782.         */
  2783.         public function SetDrawColorArray($color{
  2784.             if (isset($color)) {
  2785.                 $color array_values($color);
  2786.                 $r = isset($color[0]$color[0: -1;
  2787.                 $g = isset($color[1]$color[1: -1;
  2788.                 $b = isset($color[2]$color[2: -1;
  2789.                 $k = isset($color[3]$color[3: -1;
  2790.                 if ($r >= 0{
  2791.                     $this->SetDrawColor($r$g$b$k);
  2792.                 }
  2793.             }
  2794.         }
  2795.  
  2796.         /**
  2797.         * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  2798.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2799.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2800.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2801.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2802.         * @access public
  2803.         * @since 1.3
  2804.         * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  2805.         */
  2806.         public function SetDrawColor($col1=0$col2=-1$col3=-1$col4=-1{
  2807.             // set default values
  2808.             if (!is_numeric($col1)) {
  2809.                 $col1 0;
  2810.             }
  2811.             if (!is_numeric($col2)) {
  2812.                 $col2 = -1;
  2813.             }
  2814.             if (!is_numeric($col3)) {
  2815.                 $col3 = -1;
  2816.             }
  2817.             if (!is_numeric($col4)) {
  2818.                 $col4 = -1;
  2819.             }
  2820.             //Set color for all stroking operations
  2821.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2822.                 // Grey scale
  2823.                 $this->DrawColor = sprintf('%.3F G'$col1/255);
  2824.             elseif ($col4 == -1{
  2825.                 // RGB
  2826.                 $this->DrawColor = sprintf('%.3F %.3F %.3F RG'$col1/255$col2/255$col3/255);
  2827.             else {
  2828.                 // CMYK
  2829.                 $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K'$col1/100$col2/100$col3/100$col4/100);
  2830.             }
  2831.             if ($this->page > 0{
  2832.                 $this->_out($this->DrawColor);
  2833.             }
  2834.         }
  2835.         
  2836.         /**
  2837.         * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  2838.         * @param string $name name of the spot color
  2839.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2840.         * @access public
  2841.         * @since 4.0.024 (2008-09-12)
  2842.         * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2843.         */
  2844.         public function SetDrawSpotColor($name$tint=100{
  2845.             if (!isset($this->spot_colors[$name])) {
  2846.                 $this->Error('Undefined spot color: '.$name);
  2847.             }
  2848.             $this->DrawColor = sprintf('/CS%d CS %.3F SCN'$this->spot_colors[$name]['i']$tint/100);
  2849.             if ($this->page > 0{
  2850.                 $this->_out($this->DrawColor);
  2851.             }
  2852.         }
  2853.         
  2854.         /**
  2855.         * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  2856.         * It can be expressed in RGB components or gray scale.
  2857.         * The method can be called before the first page is created and the value is retained from page to page.
  2858.         * @param array $color array of colors
  2859.         * @access public
  2860.         * @since 3.1.000 (2008-6-11)
  2861.         * @see SetFillColor()
  2862.         */
  2863.         public function SetFillColorArray($color{
  2864.             if (isset($color)) {
  2865.                 $color array_values($color);
  2866.                 $r = isset($color[0]$color[0: -1;
  2867.                 $g = isset($color[1]$color[1: -1;
  2868.                 $b = isset($color[2]$color[2: -1;
  2869.                 $k = isset($color[3]$color[3: -1;
  2870.                 if ($r >= 0{
  2871.                     $this->SetFillColor($r$g$b$k);
  2872.                 }
  2873.             }
  2874.         }
  2875.         
  2876.         /**
  2877.         * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  2878.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2879.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2880.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2881.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2882.         * @access public
  2883.         * @since 1.3
  2884.         * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  2885.         */
  2886.         public function SetFillColor($col1=0$col2=-1$col3=-1$col4=-1{
  2887.             // set default values
  2888.             if (!is_numeric($col1)) {
  2889.                 $col1 0;
  2890.             }
  2891.             if (!is_numeric($col2)) {
  2892.                 $col2 = -1;
  2893.             }
  2894.             if (!is_numeric($col3)) {
  2895.                 $col3 = -1;
  2896.             }
  2897.             if (!is_numeric($col4)) {
  2898.                 $col4 = -1;
  2899.             }
  2900.             //Set color for all filling operations
  2901.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2902.                 // Grey scale
  2903.                 $this->FillColor = sprintf('%.3F g'$col1/255);
  2904.                 $this->bgcolor = array('G' => $col1);
  2905.             elseif ($col4 == -1{
  2906.                 // RGB
  2907.                 $this->FillColor = sprintf('%.3F %.3F %.3F rg'$col1/255$col2/255$col3/255);
  2908.                 $this->bgcolor = array('R' => $col1'G' => $col2'B' => $col3);
  2909.             else {
  2910.                 // CMYK
  2911.                 $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k'$col1/100$col2/100$col3/100$col4/100);
  2912.                 $this->bgcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  2913.             }
  2914.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2915.             if ($this->page > 0{
  2916.                 $this->_out($this->FillColor);
  2917.             }
  2918.         }
  2919.         
  2920.         /**
  2921.         * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  2922.         * @param string $name name of the spot color
  2923.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2924.         * @access public
  2925.         * @since 4.0.024 (2008-09-12)
  2926.         * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  2927.         */
  2928.         public function SetFillSpotColor($name$tint=100{
  2929.             if (!isset($this->spot_colors[$name])) {
  2930.                 $this->Error('Undefined spot color: '.$name);
  2931.             }
  2932.             $this->FillColor = sprintf('/CS%d cs %.3F scn'$this->spot_colors[$name]['i']$tint/100);
  2933.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2934.             if ($this->page > 0{
  2935.                 $this->_out($this->FillColor);
  2936.             }
  2937.         }
  2938.         
  2939.         /**
  2940.         * Defines the color used for text. It can be expressed in RGB components or gray scale.
  2941.         * The method can be called before the first page is created and the value is retained from page to page.
  2942.         * @param array $color array of colors
  2943.         * @access public
  2944.         * @since 3.1.000 (2008-6-11)
  2945.         * @see SetFillColor()
  2946.         */
  2947.         public function SetTextColorArray($color{
  2948.             if (isset($color)) {
  2949.                 $color array_values($color);
  2950.                 $r = isset($color[0]$color[0: -1;
  2951.                 $g = isset($color[1]$color[1: -1;
  2952.                 $b = isset($color[2]$color[2: -1;
  2953.                 $k = isset($color[3]$color[3: -1;
  2954.                 if ($r >= 0{
  2955.                     $this->SetTextColor($r$g$b$k);
  2956.                 }
  2957.             }
  2958.         }
  2959.  
  2960.         /**
  2961.         * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  2962.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2963.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2964.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2965.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2966.         * @access public
  2967.         * @since 1.3
  2968.         * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  2969.         */
  2970.         public function SetTextColor($col1=0$col2=-1$col3=-1$col4=-1{
  2971.             // set default values
  2972.             if (!is_numeric($col1)) {
  2973.                 $col1 0;
  2974.             }
  2975.             if (!is_numeric($col2)) {
  2976.                 $col2 = -1;
  2977.             }
  2978.             if (!is_numeric($col3)) {
  2979.                 $col3 = -1;
  2980.             }
  2981.             if (!is_numeric($col4)) {
  2982.                 $col4 = -1;
  2983.             }
  2984.             //Set color for text
  2985.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2986.                 // Grey scale
  2987.                 $this->TextColor = sprintf('%.3F g'$col1/255);
  2988.                 $this->fgcolor = array('G' => $col1);
  2989.             elseif ($col4 == -1{
  2990.                 // RGB
  2991.                 $this->TextColor = sprintf('%.3F %.3F %.3F rg'$col1/255$col2/255$col3/255);
  2992.                 $this->fgcolor = array('R' => $col1'G' => $col2'B' => $col3);
  2993.             else {
  2994.                 // CMYK
  2995.                 $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k'$col1/100$col2/100$col3/100$col4/100);
  2996.                 $this->fgcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  2997.             }
  2998.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2999.         }
  3000.         
  3001.         /**
  3002.         * Defines the spot color used for text.
  3003.         * @param string $name name of the spot color
  3004.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3005.         * @access public
  3006.         * @since 4.0.024 (2008-09-12)
  3007.         * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3008.         */
  3009.         public function SetTextSpotColor($name$tint=100{
  3010.             if (!isset($this->spot_colors[$name])) {
  3011.                 $this->Error('Undefined spot color: '.$name);
  3012.             }
  3013.             $this->TextColor = sprintf('/CS%d cs %.3F scn'$this->spot_colors[$name]['i']$tint/100);
  3014.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3015.             if ($this->page > 0{
  3016.                 $this->_out($this->TextColor);
  3017.             }
  3018.         }
  3019.  
  3020.         /**
  3021.         * Returns the length of a string in user unit. A font must be selected.<br>
  3022.         * @param string $s The string whose length is to be computed
  3023.         * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  3024.         * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> or any combination. The default value is regular.
  3025.         * @param float $fontsize Font size in points. The default value is the current size.
  3026.         * @return int string length
  3027.         * @author Nicola Asuni
  3028.         * @access public
  3029.         * @since 1.2
  3030.         */
  3031.         public function GetStringWidth($s$fontname=''$fontstyle=''$fontsize=0{
  3032.             return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s)$s$this->tmprtl)$fontname$fontstyle$fontsize);
  3033.         }
  3034.         
  3035.         /**
  3036.         * Returns the string length of an array of chars in user unit. A font must be selected.<br>
  3037.         * @param string $sa The array of chars whose total length is to be computed
  3038.         * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  3039.         * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> or any combination. The default value is regular.
  3040.         * @param float $fontsize Font size in points. The default value is the current size.
  3041.         * @return int string length
  3042.         * @author Nicola Asuni
  3043.         * @access public
  3044.         * @since 2.4.000 (2008-03-06)
  3045.         */
  3046.         public function GetArrStringWidth($sa$fontname=''$fontstyle=''$fontsize=0{
  3047.             // store current values
  3048.             if (!$this->empty_string($fontname)) {
  3049.                 $prev_FontFamily $this->FontFamily;
  3050.                 $prev_FontStyle $this->FontStyle;
  3051.                 $prev_FontSizePt $this->FontSizePt;
  3052.                 $this->SetFont($fontname$fontstyle$fontsize);
  3053.             }
  3054.             $w 0;
  3055.             foreach ($sa as $char{
  3056.                 $w += $this->GetCharWidth($char);
  3057.             }
  3058.             // restore previous values
  3059.             if (!$this->empty_string($fontname)) {
  3060.                 $this->SetFont($prev_FontFamily$prev_FontStyle$prev_FontSizePt);
  3061.             }
  3062.             return $w;
  3063.         }
  3064.         
  3065.         /**
  3066.         * Returns the length of the char in user unit for the current font.
  3067.         * @param int $char The char code whose length is to be returned
  3068.         * @return int char width
  3069.         * @author Nicola Asuni
  3070.         * @access public
  3071.         * @since 2.4.000 (2008-03-06)
  3072.         */
  3073.         public function GetCharWidth($char{
  3074.             if ($char == 173{
  3075.                 // SHY character will not be printed
  3076.                 return (0);
  3077.             }
  3078.             $cw &$this->CurrentFont['cw'];
  3079.             if (isset($cw[$char])) {
  3080.                 $w $cw[$char];
  3081.             elseif (isset($this->CurrentFont['dw'])) {
  3082.                 // default width
  3083.                 $w $this->CurrentFont['dw'];
  3084.             elseif (isset($cw[32])) {
  3085.                 // default width
  3086.                 $dw $cw[32];
  3087.             else {
  3088.                 $w 600;
  3089.             }
  3090.             return ($w $this->FontSize / 1000);
  3091.         }
  3092.         
  3093.         /**
  3094.         * Returns the numbero of characters in a string.
  3095.         * @param string $s The input string.
  3096.         * @return int number of characters
  3097.         * @access public
  3098.         * @since 2.0.0001 (2008-01-07)
  3099.         */
  3100.         public function GetNumChars($s{
  3101.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  3102.                 return count($this->UTF8StringToArray($s));
  3103.             
  3104.             return strlen($s);
  3105.         }
  3106.             
  3107.         /**
  3108.         * Fill the list of available fonts ($this->fontlist).
  3109.         * @access protected
  3110.         * @since 4.0.013 (2008-07-28)
  3111.         */
  3112.         protected function getFontsList({
  3113.             $fontsdir opendir($this->_getfontpath());
  3114.             while (($file readdir($fontsdir)) !== false{
  3115.                 if (substr($file-4== '.php'{
  3116.                     array_push($this->fontliststrtolower(basename($file'.php')));
  3117.                 }
  3118.             }
  3119.             closedir($fontsdir);
  3120.         }
  3121.         
  3122.         /**
  3123.         * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3124.         * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3125.         * The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
  3126.         * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3127.         * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  3128.         * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3129.         * @return array containing the font data, or false in case of error.
  3130.         * @access public
  3131.         * @since 1.5
  3132.         * @see SetFont()
  3133.         */
  3134.         public function AddFont($family$style=''$fontfile=''{
  3135.             if ($this->empty_string($family)) {
  3136.                 if (!$this->empty_string($this->FontFamily)) {
  3137.                     $family $this->FontFamily;
  3138.                 else {
  3139.                     $this->Error('Empty font family');
  3140.                 }
  3141.             }
  3142.             $family strtolower($family);
  3143.             if ((!$this->isunicodeAND ($family == 'arial')) {
  3144.                 $family 'helvetica';
  3145.             }
  3146.             if (($family == 'symbol'OR ($family == 'zapfdingbats')) {
  3147.                 $style '';
  3148.             }
  3149.             $tempstyle strtoupper($style);
  3150.             $style '';
  3151.             // underline
  3152.             if (strpos($tempstyle'U'!== false{
  3153.                 $this->underline = true;
  3154.             else {
  3155.                 $this->underline = false;
  3156.             }
  3157.             // line through (deleted)
  3158.             if (strpos($tempstyle'D'!== false{
  3159.                 $this->linethrough = true;
  3160.             else {
  3161.                 $this->linethrough = false;
  3162.             }
  3163.             // bold
  3164.             if (strpos($tempstyle'B'!== false{
  3165.                 $style .= 'B';
  3166.             }
  3167.             // oblique
  3168.             if (strpos($tempstyle'I'!== false{
  3169.                 $style .= 'I';
  3170.             }
  3171.             $bistyle $style;
  3172.             $fontkey $family.$style;
  3173.             $font_style $style.($this->underline ? 'U' '').($this->linethrough ? 'D' '');
  3174.             $fontdata array('fontkey' => $fontkey'family' => $family'style' => $font_style);
  3175.             // check if the font has been already added
  3176.             if ($this->getFontBuffer($fontkey!== false{
  3177.                 return $fontdata;
  3178.             }
  3179.             if (isset($type)) {
  3180.                 unset($type)
  3181.             }
  3182.             if (isset($cw)) {
  3183.                 unset($cw)
  3184.             }
  3185.             // get specified font directory (if any)
  3186.             $fontdir '';
  3187.             if (!$this->empty_string($fontfile)) {
  3188.                 $fontdir dirname($fontfile);
  3189.                 if ($this->empty_string($fontdirOR ($fontdir == '.')) {
  3190.                     $fontdir '';
  3191.                 else {
  3192.                     $fontdir .= '/';
  3193.                 }
  3194.             }
  3195.             // search and include font file
  3196.             if ($this->empty_string($fontfileOR (!file_exists($fontfile))) {
  3197.                 // build a standard filenames for specified font
  3198.                 $fontfile1 str_replace(' '''$family).strtolower($style).'.php';
  3199.                 $fontfile2 str_replace(' '''$family).'.php';
  3200.                 // search files on various directories
  3201.                 if (file_exists($fontdir.$fontfile1)) {
  3202.                     $fontfile $fontdir.$fontfile1;
  3203.                 elseif (file_exists($this->_getfontpath().$fontfile1)) {
  3204.                     $fontfile $this->_getfontpath().$fontfile1;
  3205.                 elseif (file_exists($fontfile1)) {
  3206.                     $fontfile $fontfile1;
  3207.                 elseif (file_exists($fontdir.$fontfile2)) {
  3208.                     $fontfile $fontdir.$fontfile2;
  3209.                 elseif (file_exists($this->_getfontpath().$fontfile2)) {
  3210.                     $fontfile $this->_getfontpath().$fontfile2;
  3211.                 else {
  3212.                     $fontfile $fontfile2;
  3213.                 }
  3214.             }
  3215.             // include font file
  3216.             if (file_exists($fontfile)) {
  3217.                 include($fontfile);
  3218.             else {
  3219.                 $this->Error('Could not include font definition file: '.$family.'');
  3220.             }
  3221.             // check font parameters
  3222.             if ((!isset($type)) OR (!isset($cw))) {
  3223.                 $this->Error('The font definition file has a bad format: '.$fontfile.'');
  3224.             }
  3225.             // SET default parameters
  3226.             if (!isset($fileOR $this->empty_string($file)) {
  3227.                 $file '';
  3228.             }
  3229.             if (!isset($encOR $this->empty_string($enc)) {
  3230.                 $enc '';
  3231.             }
  3232.             if (!isset($cidinfoOR $this->empty_string($cidinfo)) {
  3233.                 $cidinfo array('Registry'=>'Adobe','Ordering'=>'Identity','Supplement'=>0);
  3234.                 $cidinfo['uni2cid'array();
  3235.             }
  3236.             if (!isset($ctgOR $this->empty_string($ctg)) {
  3237.                 $ctg '';
  3238.             }
  3239.             if (!isset($descOR $this->empty_string($desc)) {
  3240.                 $desc array();
  3241.             }
  3242.             if (!isset($upOR $this->empty_string($up)) {
  3243.                 $up = -100;
  3244.             }
  3245.             if (!isset($utOR $this->empty_string($ut)) {
  3246.                 $ut 50;
  3247.             }
  3248.             if (!isset($cwOR $this->empty_string($cw)) {
  3249.                 $cw array();
  3250.             }
  3251.             if (!isset($dwOR $this->empty_string($dw)) {
  3252.                 // set default width
  3253.                 if (isset($desc['MissingWidth']AND ($desc['MissingWidth'0)) {
  3254.                     $dw $desc['MissingWidth'];
  3255.                 elseif (isset($cw[32])) {
  3256.                     $dw $cw[32];
  3257.                 else {
  3258.                     $dw 600;
  3259.                 }
  3260.             }
  3261.             ++$this->numfonts;            
  3262.             if ($type == 'cidfont0'{
  3263.                 // register CID font (all styles at once)
  3264.                 $styles array('' => '''B' => ',Bold''I' => ',Italic''BI' => ',BoldItalic');
  3265.                 $sname $name.$styles[$bistyle];
  3266.                 if ((strpos($bistyle'B'!== falseAND (isset($desc['StemV'])) AND ($desc['StemV'== 70)) {
  3267.                     $desc['StemV'120;
  3268.                 }
  3269.             elseif ($type == 'core'{
  3270.                 $name $this->CoreFonts[$fontkey];
  3271.             elseif (($type == 'TrueType'OR ($type == 'Type1')) {
  3272.                 // ...
  3273.             elseif ($type == 'TrueTypeUnicode'{
  3274.                 $enc 'Identity-H';
  3275.             else {
  3276.                 $this->Error('Unknow font type: '.$type.'');
  3277.             }
  3278.             $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $name'desc' => $desc'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'enc' => $enc'cidinfo' => $cidinfo'file' => $file'ctg' => $ctg));
  3279.             if (isset($diffAND (!empty($diff))) {
  3280.                 //Search existing encodings
  3281.                 $d 0;
  3282.                 $nb count($this->diffs);
  3283.                 for ($i=1$i <= $nb++$i{
  3284.                     if ($this->diffs[$i== $diff{
  3285.                         $d $i;
  3286.                         break;
  3287.                     }
  3288.                 }
  3289.                 if ($d == 0{
  3290.                     $d $nb 1;
  3291.                     $this->diffs[$d$diff;
  3292.                 }
  3293.                 $this->setFontSubBuffer($fontkey'diff'$d);
  3294.             }
  3295.             if (!$this->empty_string($file)) {
  3296.                 if ((strcasecmp($type,'TrueType'== 0OR (strcasecmp($type'TrueTypeUnicode'== 0)) {
  3297.                     $this->FontFiles[$filearray('length1' => $originalsize'fontdir' => $fontdir);
  3298.                 elseif ($type != 'core'{
  3299.                     $this->FontFiles[$filearray('length1' => $size1'length2' => $size2'fontdir' => $fontdir);
  3300.                 }
  3301.             }
  3302.             return $fontdata;
  3303.         }
  3304.  
  3305.         /**
  3306.         * Sets the font used to print character strings.
  3307.         * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  3308.         * The method can be called before the first page is created and the font is retained from page to page.
  3309.         * If you just wish to change the current font size, it is simpler to call SetFontSize().
  3310.         * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br />
  3311.         * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  3312.         * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> 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.
  3313.         * @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
  3314.         * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3315.         * @access public
  3316.         * @since 1.0
  3317.         * @see AddFont(), SetFontSize()
  3318.         */
  3319.         public function SetFont($family$style=''$size=0$fontfile=''{
  3320.             //Select a font; size given in points
  3321.             if ($size == 0{
  3322.                 $size $this->FontSizePt;
  3323.             }
  3324.             // try to add font (if not already added)
  3325.             $fontdata $this->AddFont($family$style$fontfile);
  3326.             $this->FontFamily = $fontdata['family'];
  3327.             $this->FontStyle = $fontdata['style'];
  3328.             $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  3329.             $this->SetFontSize($size);
  3330.         }
  3331.  
  3332.         /**
  3333.         * Defines the size of the current font.
  3334.         * @param float $size The size (in points)
  3335.         * @access public
  3336.         * @since 1.0
  3337.         * @see SetFont()
  3338.         */
  3339.         public function SetFontSize($size{
  3340.             //Set font size in points
  3341.             $this->FontSizePt = $size;
  3342.             $this->FontSize = $size $this->k;
  3343.             if (isset($this->CurrentFont['desc']['Ascent']AND ($this->CurrentFont['desc']['Ascent'0)) {
  3344.                 $this->FontAscent = $this->CurrentFont['desc']['Ascent'$this->FontSize / 1000;
  3345.             else {
  3346.                 $this->FontAscent = 0.8 $this->FontSize;
  3347.             }
  3348.             if (isset($this->CurrentFont['desc']['Descent']AND ($this->CurrentFont['desc']['Descent'0)) {
  3349.                 $this->FontDescent = - $this->CurrentFont['desc']['Descent'$this->FontSize / 1000;
  3350.             else {
  3351.                 $this->FontDescent = 0.2 $this->FontSize;
  3352.             }
  3353.             if (($this->page > 0AND (isset($this->CurrentFont['i']))) {
  3354.                 $this->_out(sprintf('BT /F%d %.2F Tf ET'$this->CurrentFont['i']$this->FontSizePt));
  3355.             }
  3356.         }
  3357.  
  3358.         /**
  3359.         * Defines the default monospaced font.
  3360.         * @param string $font Font name.
  3361.         * @access public
  3362.         * @since 4.5.025
  3363.         */
  3364.         public function SetDefaultMonospacedFont($font{
  3365.             $this->default_monospaced_font = $font;
  3366.         }
  3367.         
  3368.         /**
  3369.         * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
  3370.         * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  3371.         * @access public
  3372.         * @since 1.5
  3373.         * @see Cell(), Write(), Image(), Link(), SetLink()
  3374.         */
  3375.         public function AddLink({
  3376.             //Create a new internal link
  3377.             $n count($this->links1;
  3378.             $this->links[$narray(00);
  3379.             return $n;
  3380.         }
  3381.  
  3382.         /**
  3383.         * Defines the page and position a link points to.
  3384.         * @param int $link The link identifier returned by AddLink()
  3385.         * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  3386.         * @param int $page Number of target page; -1 indicates the current page. This is the default value
  3387.         * @access public
  3388.         * @since 1.5
  3389.         * @see AddLink()
  3390.         */
  3391.         public function SetLink($link$y=0$page=-1{
  3392.             if ($y == -1{
  3393.                 $y $this->y;
  3394.             }
  3395.             if ($page == -1{
  3396.                 $page $this->page;
  3397.             }
  3398.             $this->links[$linkarray($page$y);
  3399.         }
  3400.  
  3401.         /**
  3402.         * Puts a link on a rectangular area of the page.
  3403.         * Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
  3404.         * @param float $x Abscissa of the upper-left corner of the rectangle
  3405.         * @param float $y Ordinate of the upper-left corner of the rectangle
  3406.         * @param float $w Width of the rectangle
  3407.         * @param float $h Height of the rectangle
  3408.         * @param mixed $link URL or identifier returned by AddLink()
  3409.         * @param int $spaces number of spaces on the text to link
  3410.         * @access public
  3411.         * @since 1.5
  3412.         * @see AddLink(), Annotation(), Cell(), Write(), Image()
  3413.         */
  3414.         public function Link($x$y$w$h$link$spaces=0{
  3415.             $this->Annotation($x$y$w$h$linkarray('Subtype'=>'Link')$spaces);
  3416.         }
  3417.         
  3418.         /**
  3419.         * Puts a markup annotation on a rectangular area of the page.
  3420.         * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  3421.         * @param float $x Abscissa of the upper-left corner of the rectangle
  3422.         * @param float $y Ordinate of the upper-left corner of the rectangle
  3423.         * @param float $w Width of the rectangle
  3424.         * @param float $h Height of the rectangle
  3425.         * @param string $text annotation text or alternate content
  3426.         * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  3427.         * @param int $spaces number of spaces on the text to link
  3428.         * @access public
  3429.         * @since 4.0.018 (2008-08-06)
  3430.         */
  3431.         public function Annotation($x=''$y=''$w$h$text$opt=array('Subtype'=>'Text')$spaces=0{
  3432.             if ($x === ''{
  3433.                 $x $this->x;
  3434.             }
  3435.             if ($y === ''{
  3436.                 $y $this->y;
  3437.             }
  3438.             // recalculate coordinates to account for graphic transformations
  3439.             if (isset($this->transfmatrix)) {
  3440.                 for ($i=$this->transfmatrix_key$i 0--$i{
  3441.                     $maxid count($this->transfmatrix[$i]1;
  3442.                     for ($j=$maxid$j >= 0--$j{
  3443.                         $ctm $this->transfmatrix[$i][$j];
  3444.                         if (isset($ctm['a'])) {
  3445.                             $x $x $this->k;
  3446.                             $y ($this->h - $y$this->k;
  3447.                             $w $w $this->k;
  3448.                             $h $h $this->k;
  3449.                             // top left
  3450.                             $xt $x;
  3451.                             $yt $y;
  3452.                             $x1 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3453.                             $y1 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3454.                             // top right
  3455.                             $xt $x $w;
  3456.                             $yt $y;
  3457.                             $x2 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3458.                             $y2 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3459.                             // bottom left
  3460.                             $xt $x;
  3461.                             $yt $y $h;
  3462.                             $x3 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3463.                             $y3 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3464.                             // bottom right
  3465.                             $xt $x $w;
  3466.                             $yt $y $h;
  3467.                             $x4 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3468.                             $y4 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3469.                             // new coordinates (rectangle area)
  3470.                             $x min($x1$x2$x3$x4);
  3471.                             $y max($y1$y2$y3$y4);
  3472.                             $w (max($x1$x2$x3$x4$x$this->k;
  3473.                             $h ($y min($y1$y2$y3$y4)) $this->k;
  3474.                             $x $x $this->k;
  3475.                             $y $this->h - ($y $this->k);
  3476.                         }
  3477.                     }
  3478.                 }
  3479.             }
  3480.             if ($this->page <= 0{
  3481.                 $page 1;
  3482.             else {
  3483.                 $page $this->page;
  3484.             }
  3485.             if (!isset($this->PageAnnots[$page])) {
  3486.                 $this->PageAnnots[$pagearray();
  3487.             }
  3488.             $this->PageAnnots[$page][array('x' => $x'y' => $y'w' => $w'h' => $h'txt' => $text'opt' => $opt'numspaces' => $spaces);
  3489.             if (($opt['Subtype'== 'FileAttachment'AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  3490.                 $this->embeddedfiles[basename($opt['FS'])array('file' => $opt['FS']'n' => (count($this->embeddedfiles$this->embedded_start_obj_id));
  3491.             }
  3492.             // Add widgets annotation's icons
  3493.             if (isset($opt['mk']['i']AND file_exists($opt['mk']['i'])) {
  3494.                 $this->Image($opt['mk']['i']''''1010''''''false300''falsefalse0falsetrue);
  3495.             }
  3496.             if (isset($opt['mk']['ri']AND file_exists($opt['mk']['ri'])) {
  3497.                 $this->Image($opt['mk']['ri']''''00''''''false300''falsefalse0falsetrue);
  3498.             }
  3499.             if (isset($opt['mk']['ix']AND file_exists($opt['mk']['ix'])) {
  3500.                 $this->Image($opt['mk']['ix']''''00''''''false300''falsefalse0falsetrue);
  3501.             }
  3502.             ++$this->annot_obj_id;
  3503.         }
  3504.  
  3505.         /**
  3506.         * Embedd the attached files.
  3507.         * @since 4.4.000 (2008-12-07)
  3508.         * @access protected
  3509.         * @see Annotation()
  3510.         */
  3511.         protected function _putEmbeddedFiles({
  3512.             reset($this->embeddedfiles);
  3513.             foreach ($this->embeddedfiles as $filename => $filedata{
  3514.                 $data file_get_contents($filedata['file']);
  3515.                 $filter '';
  3516.                 if ($this->compress{
  3517.                     $data gzcompress($data);
  3518.                     $filter ' /Filter /FlateDecode';
  3519.                 }
  3520.                 $this->offsets[$filedata['n']] $this->bufferlen;
  3521.                 $this->_out($filedata['n'].' 0 obj');
  3522.                 $this->_out('<</Type /EmbeddedFile'.$filter.' /Length '.strlen($data).' >>');
  3523.                 $this->_putstream($data);
  3524.                 $this->_out('endobj');
  3525.             }
  3526.         }
  3527.         
  3528.         /**
  3529.         * Prints a character string.
  3530.         * The origin is on the left of the first charcter, on the baseline.
  3531.         * This method allows to place a string precisely on the page.
  3532.         * @param float $x Abscissa of the origin
  3533.         * @param float $y Ordinate of the origin
  3534.         * @param string $txt String to print
  3535.         * @param int $stroke outline size in points (0 = disable)
  3536.         * @param boolean $clip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  3537.         * @access public
  3538.         * @since 1.0
  3539.         * @deprecated deprecated since version 4.3.005 (2008-11-25)
  3540.         * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  3541.         */
  3542.         public function Text($x$y$txt$stroke=0$clip=false{
  3543.             //Output a string
  3544.             if ($this->rtl{
  3545.                 // bidirectional algorithm (some chars may be changed affecting the line length)
  3546.                 $s $this->utf8Bidi($this->UTF8StringToArray($txt)$txt$this->tmprtl);
  3547.                 $l $this->GetArrStringWidth($s);
  3548.                 $xr $this->w - $x $l;
  3549.             else {
  3550.                 $xr $x;
  3551.             }
  3552.             $opt '';
  3553.             if (($stroke 0AND (!$clip)) {
  3554.                 $opt .= '1 Tr '.intval($stroke).' w ';
  3555.             elseif (($stroke 0AND $clip{
  3556.                 $opt .= '5 Tr '.intval($stroke).' w ';
  3557.             elseif ($clip{
  3558.                 $opt .= '7 Tr ';
  3559.             }
  3560.             $s sprintf('BT %.2F %.2F Td %s(%s) Tj ET 0 Tr'$xr $this->k($this->h-$y$this->k$opt$this->_escapetext($txt));
  3561.             if ($this->underline AND ($txt!='')) {
  3562.                 $s .= ' '.$this->_dounderline($xr$y$txt);
  3563.             }
  3564.             if ($this->linethrough AND ($txt!='')) 
  3565.                 $s .= ' '.$this->_dolinethrough($xr$y$txt)
  3566.             }
  3567.             if ($this->ColorFlag AND (!$clip)) {
  3568.                 $s='q '.$this->TextColor.' '.$s.' Q';
  3569.             }
  3570.             $this->_out($s);
  3571.         }
  3572.  
  3573.         /**
  3574.         * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  3575.         * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  3576.         * This method is called automatically and should not be called directly by the application.
  3577.         * @return boolean 
  3578.         * @access public
  3579.         * @since 1.4
  3580.         * @see SetAutoPageBreak()
  3581.         */
  3582.         public function AcceptPageBreak({
  3583.             return $this->AutoPageBreak;
  3584.         }
  3585.         
  3586.         /**
  3587.         * Add page if needed.
  3588.         * @param float $h Cell height. Default value: 0.
  3589.         * @param mixed $y starting y position, leave empty for current position.
  3590.         * @param boolean $addpage if true add a page, otherwise only return the true/false state
  3591.         * @return boolean true in case of page break, false otherwise.
  3592.         * @since 3.2.000 (2008-07-01)
  3593.         * @access protected
  3594.         */
  3595.         protected function checkPageBreak($h=0$y=''$addpage=true{
  3596.             if ($this->empty_string($y)) {
  3597.                 $y $this->y;
  3598.             }
  3599.             if ((($y $h$this->PageBreakTriggerAND (!$this->InFooterAND ($this->AcceptPageBreak())) {
  3600.                 if ($addpage{
  3601.                     //Automatic page break
  3602.                     $x $this->x;
  3603.                     $this->AddPage($this->CurOrientation);
  3604.                     $this->y = $this->tMargin;
  3605.                     $oldpage $this->page - 1;
  3606.                     if ($this->rtl{
  3607.                         if ($this->pagedim[$this->page]['orm'!= $this->pagedim[$oldpage]['orm']{
  3608.                             $this->x = $x ($this->pagedim[$this->page]['orm'$this->pagedim[$oldpage]['orm']);
  3609.                         else {
  3610.                             $this->x = $x;
  3611.                         }
  3612.                     else {
  3613.                         if ($this->pagedim[$this->page]['olm'!= $this->pagedim[$oldpage]['olm']{
  3614.                             $this->x = $x ($this->pagedim[$this->page]['olm'$this->pagedim[$oldpage]['olm']);
  3615.                         else {
  3616.                             $this->x = $x;
  3617.                         }
  3618.                     }
  3619.                 }
  3620.                 return true;
  3621.             }
  3622.             return false;
  3623.         }
  3624.  
  3625.         /**
  3626.         * Prints 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.<br />
  3627.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3628.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3629.         * @param float $h Cell height. Default value: 0.
  3630.         * @param string $txt String to print. Default value: empty string.
  3631.         * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3632.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  3633.         Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3634.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  3635.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3636.         * @param mixed $link URL or identifier returned by AddLink().
  3637.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3638.         * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3639.         * @access public
  3640.         * @since 1.0
  3641.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  3642.         */
  3643.         public function Cell($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''$stretch=0$ignore_min_height=false{
  3644.             //$min_cell_height = $this->FontAscent + $this->FontDescent;
  3645.             $min_cell_height $this->FontSize * $this->cell_height_ratio;
  3646.             if ($h $min_cell_height{
  3647.                 $h $min_cell_height;
  3648.             }
  3649.             $this->checkPageBreak($h);
  3650.             $this->_out($this->getCellCode($w$h$txt$border$ln$align$fill$link$stretch$ignore_min_height));
  3651.         }
  3652.  
  3653.         /**
  3654.         * Removes SHY characters from text.
  3655.         * @param string $txt input string
  3656.         * @return string without SHY characters.
  3657.         * @access public
  3658.         * @since (4.5.019) 2009-02-28
  3659.         */
  3660.         public function removeSHY($txt=''{
  3661.             /*
  3662.             * Unicode Data
  3663.             * Name : SOFT HYPHEN, commonly abbreviated as SHY
  3664.             * HTML Entity (decimal): &#173;
  3665.             * HTML Entity (hex): &#xad;
  3666.             * HTML Entity (named): &shy;
  3667.             * How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
  3668.             * UTF-8 (hex): 0xC2 0xAD (c2ad)
  3669.             * UTF-8 character: chr(194).chr(173)
  3670.             */
  3671.             $txt preg_replace('/([\\xc2]{1}[\\xad]{1})/'''$txt);
  3672.             if (!$this->isunicode{
  3673.                 $txt preg_replace('/([\\xad]{1})/'''$txt);
  3674.             }
  3675.             return $txt;
  3676.         }
  3677.         
  3678.         /**
  3679.         * 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.<br />
  3680.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3681.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3682.         * @param float $h Cell height. Default value: 0.
  3683.         * @param string $txt String to print. Default value: empty string.
  3684.         * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3685.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3686.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  3687.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3688.         * @param mixed $link URL or identifier returned by AddLink().
  3689.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3690.         * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3691.         * @access protected
  3692.         * @since 1.0
  3693.         * @see Cell()
  3694.         */
  3695.         protected function getCellCode($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''$stretch=0$ignore_min_height=false{
  3696.             $txt $this->removeSHY($txt);
  3697.             $rs ''//string to be returned
  3698.             if (!$ignore_min_height{
  3699.                 $min_cell_height $this->FontSize * $this->cell_height_ratio;
  3700.                 if ($h $min_cell_height{
  3701.                     $h $min_cell_height;
  3702.                 }
  3703.             }
  3704.             $k $this->k;
  3705.             if ($this->empty_string($wOR ($w <= 0)) {
  3706.                 if ($this->rtl{
  3707.                     $w $this->x - $this->lMargin;
  3708.                 else {
  3709.                     $w $this->w - $this->rMargin - $this->x;
  3710.                 }
  3711.             }
  3712.             $s '';            
  3713.             if (($fill == 1OR ($border == 1)) {
  3714.                 if ($fill == 1{
  3715.                     $op ($border == 1'B' 'f';
  3716.                 else {
  3717.                     $op 'S';
  3718.                 }
  3719.                 if ($this->rtl{
  3720.                     $xk (($this->x  - $w$k);
  3721.                 else {
  3722.                     $xk ($this->x * $k);
  3723.                 }
  3724.                 $s .= sprintf('%.2F %.2F %.2F %.2F re %s '$xk(($this->h - $this->y$k)($w $k)(-$h $k)$op);
  3725.             }
  3726.             if (is_string($border)) {
  3727.                 $lm ($this->LineWidth / 2);
  3728.                 $x $this->x;
  3729.                 $y $this->y;
  3730.                 if (strpos($border,'L'!== false{
  3731.                     if ($this->rtl{
  3732.                         $xk ($x $w$k;
  3733.                     else {
  3734.                         $xk $x $k;
  3735.                     }
  3736.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - $y $lm$k)$xk(($this->h - ($y $h $lm)) $k));
  3737.                 }
  3738.                 if (strpos($border,'T'!== false{
  3739.                     if ($this->rtl{
  3740.                         $xk ($x $w $lm$k;
  3741.                         $xwk ($x $lm$k;
  3742.                     else {
  3743.                         $xk ($x $lm$k;
  3744.                         $xwk ($x $w $lm$k;
  3745.                     }
  3746.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - $y$k)$xwk(($this->h - $y$k));
  3747.                 }
  3748.                 if (strpos($border,'R'!== false{
  3749.                     if ($this->rtl{
  3750.                         $xk $x $k;
  3751.                     else {
  3752.                         $xk ($x $w$k;
  3753.                     }
  3754.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - $y $lm$k)$xk(($this->h - ($y $h $lm))$k));
  3755.                 }
  3756.                 if (strpos($border,'B'!== false{
  3757.                     if ($this->rtl{
  3758.                         $xk ($x $w $lm$k;
  3759.                         $xwk ($x $lm$k;
  3760.                     else {
  3761.                         $xk ($x $lm$k;
  3762.                         $xwk ($x $w $lm$k;
  3763.                     }
  3764.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - ($y $h)) $k)$xwk(($this->h - ($y $h)) $k));
  3765.                 }
  3766.             }
  3767.             if ($txt != ''{
  3768.                 // text lenght
  3769.                 $width $this->GetStringWidth($txt);
  3770.                 // ratio between cell lenght and text lenght
  3771.                 if ($width <= 0{
  3772.                     $ratio 1;
  3773.                 else {
  3774.                     $ratio ($w ($this->cMargin)) $width;
  3775.                 }
  3776.                 // stretch text if required
  3777.                 if (($stretch 0AND (($ratio 1OR (($ratio 1AND (($stretch 2== 0)))) {
  3778.                     if ($stretch 2{
  3779.                         // spacing
  3780.                         //Calculate character spacing in points
  3781.                         $char_space (($w $width ($this->cMargin)) $this->kmax($this->GetNumChars($txt)-1,1);
  3782.                         //Set character spacing
  3783.                         $rs .= sprintf('BT %.2F Tc ET '$char_space);
  3784.                     else {
  3785.                         // scaling
  3786.                         //Calculate horizontal scaling
  3787.                         $horiz_scale $ratio 100.0;
  3788.                         //Set horizontal scaling
  3789.                         $rs .= sprintf('BT %.2F Tz ET '$horiz_scale);
  3790.                     }
  3791.                     $align '';
  3792.                     $width $w ($this->cMargin);
  3793.                 else {
  3794.                     $stretch == 0;
  3795.                 }
  3796.                 if ($align == 'L'{
  3797.                     if ($this->rtl{
  3798.                         $dx $w $width $this->cMargin;
  3799.                     else {
  3800.                         $dx $this->cMargin;
  3801.                     }
  3802.                 elseif ($align == 'R'{
  3803.                     if ($this->rtl{
  3804.                         $dx $this->cMargin;
  3805.                     else {
  3806.                         $dx $w $width $this->cMargin;
  3807.                     }
  3808.                 elseif ($align == 'C'{
  3809.                     $dx ($w $width2;
  3810.                 elseif ($align == 'J'{
  3811.                     if ($this->rtl{
  3812.                         $dx $w $width $this->cMargin;
  3813.                     else {
  3814.                         $dx $this->cMargin;
  3815.                     }
  3816.                 else {
  3817.                     $dx $this->cMargin;
  3818.                 }
  3819.                 if ($this->ColorFlag{
  3820.                     $s .= 'q '.$this->TextColor.' ';
  3821.                 }
  3822.                 $txt2 $this->_escapetext($txt);
  3823.                 if ($this->rtl{
  3824.                     $xdk ($this->x - $dx $width$k;
  3825.                 else {
  3826.                     $xdk ($this->x + $dx$k;
  3827.                 }
  3828.                 // Justification
  3829.                 if ($align == 'J'{
  3830.                     // count number of spaces
  3831.                     $ns substr_count($txt' ');
  3832.                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  3833.                         // get string width without spaces
  3834.                         $width $this->GetStringWidth(str_replace(' '''$txt));
  3835.                         // calculate average space width
  3836.                         $spacewidth = -1000 ($w $width ($this->cMargin)) ($ns?$ns:1$this->FontSize;
  3837.                         // set word position to be used with TJ operator
  3838.                         $txt2 str_replace(chr(0).' '') '.($spacewidth).' ('$txt2);
  3839.                     else {
  3840.                         // get string width
  3841.                         $width $this->GetStringWidth($txt);
  3842.                         $spacewidth (($w $width ($this->cMargin)) ($ns?$ns:1)) $this->k;
  3843.                         $rs .= sprintf('BT %.3F Tw ET '$spacewidth);
  3844.                     }
  3845.                 }
  3846.                 // calculate approximate position of the font base line
  3847.                 //$basefonty = $this->y + (($h + $this->FontAscent - $this->FontDescent)/2);
  3848.                 $basefonty $this->y + ($h/2($this->FontSize/3);
  3849.                 // print text
  3850.                 $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET'$xdk(($this->h - $basefonty$k)$txt2);
  3851.                 if ($this->rtl{
  3852.                     $xdx $this->x - $dx $width;
  3853.                 else {
  3854.                     $xdx $this->x + $dx;
  3855.                 }
  3856.                 if ($this->underline)  {
  3857.                     $s .= ' '.$this->_dounderlinew($xdx$basefonty$width);
  3858.                 }
  3859.                 if ($this->linethrough
  3860.                     $s .= ' '.$this->_dolinethroughw($xdx$basefonty$width);
  3861.                 }
  3862.                 if ($this->ColorFlag{
  3863.                     $s .= ' Q';
  3864.                 }
  3865.                 if ($link{
  3866.                     $this->Link($xdx$this->y + (($h $this->FontSize)/2)$width$this->FontSize$linksubstr_count($txtchr(32)));
  3867.                 }
  3868.             }
  3869.             // output cell
  3870.             if ($s{
  3871.                 // output cell
  3872.                 $rs .= $s;
  3873.                 // reset text stretching
  3874.                 if ($stretch 2{
  3875.                     //Reset character horizontal spacing
  3876.                     $rs .= ' BT 0 Tc ET';
  3877.                 elseif ($stretch 0{
  3878.                     //Reset character horizontal scaling
  3879.                     $rs .= ' BT 100 Tz ET';
  3880.                 }
  3881.             }
  3882.             // reset word spacing
  3883.             if (!(($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) AND ($align == 'J')) {
  3884.                 $rs .= ' BT 0 Tw ET';
  3885.             }
  3886.             $this->lasth = $h;
  3887.             if ($ln 0{
  3888.                 //Go to the beginning of the next line
  3889.                 $this->y += $h;
  3890.                 if ($ln == 1{
  3891.                     if ($this->rtl{
  3892.                         $this->x = $this->w - $this->rMargin;
  3893.                     else {
  3894.                         $this->x = $this->lMargin;
  3895.                     }
  3896.                 }
  3897.             else {
  3898.                 // go left or right by case
  3899.                 if ($this->rtl{
  3900.                     $this->x -= $w;
  3901.                 else {
  3902.                     $this->x += $w;
  3903.                 }
  3904.             }
  3905.             $gstyles ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  3906.             $rs $gstyles.$rs;
  3907.             return $rs;
  3908.         }
  3909.  
  3910.         /**
  3911.         * This method allows printing text with line breaks.
  3912.         * They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
  3913.         * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  3914.         * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  3915.         * @param float $h Cell minimum height. The cell extends automatically if needed.
  3916.         * @param string $txt String to print
  3917.         * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3918.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  3919.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3920.         * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  3921.         * @param float $x x position in user units
  3922.         * @param float $y y position in user units
  3923.         * @param boolean $reseth if true reset the last cell height (default true).
  3924.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  3925.         * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  3926.         * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  3927.         * @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.
  3928.         * @return int Return the number of cells or 1 for html mode.
  3929.         * @access public
  3930.         * @since 1.3
  3931.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  3932.         */
  3933.         public function MultiCell($w$h$txt$border=0$align='J'$fill=0$ln=1$x=''$y=''$reseth=true$stretch=0$ishtml=false$autopadding=true$maxh=0{    
  3934.             if ($this->empty_string($this->lasthOR $reseth{
  3935.                 //set row height
  3936.                 $this->lasth = $this->FontSize * $this->cell_height_ratio;
  3937.             }
  3938.             if (!$this->empty_string($y)) {
  3939.                 $this->SetY($y);
  3940.             else {
  3941.                 $y $this->GetY();
  3942.             }
  3943.             // check for page break
  3944.             $this->checkPageBreak($h);
  3945.             $y $this->GetY();
  3946.             // get current page number
  3947.             $startpage $this->page;
  3948.             if (!$this->empty_string($x)) {
  3949.                 $this->SetX($x);
  3950.             else {
  3951.                 $x $this->GetX();
  3952.             }
  3953.             if ($this->empty_string($wOR ($w <= 0)) {
  3954.                 if ($this->rtl{
  3955.                     $w $this->x - $this->lMargin;
  3956.                 else {
  3957.                     $w $this->w - $this->rMargin - $this->x;
  3958.                 }
  3959.             }
  3960.             // store original margin values
  3961.             $lMargin $this->lMargin;
  3962.             $rMargin $this->rMargin;
  3963.             if ($this->rtl{
  3964.                 $this->SetRightMargin($this->w - $this->x);
  3965.                 $this->SetLeftMargin($this->x - $w);
  3966.             else {
  3967.                 $this->SetLeftMargin($this->x);
  3968.                 $this->SetRightMargin($this->w - $this->x - $w);
  3969.             }
  3970.             $starty $this->y;
  3971.             if ($autopadding{
  3972.                 // Adjust internal padding
  3973.                 if ($this->cMargin < ($this->LineWidth / 2)) {
  3974.                     $this->cMargin = ($this->LineWidth / 2);
  3975.                 }
  3976.                 // Add top space if needed
  3977.                 if (($this->lasth - $this->FontSize$this->LineWidth{
  3978.                     $this->y += $this->LineWidth / 2;
  3979.                 }
  3980.                 // add top padding
  3981.                 $this->y += $this->cMargin;
  3982.             }
  3983.             if ($ishtml{
  3984.                 // ******* Write HTML text
  3985.                 $this->writeHTML($txttrue0$resethtrue$align);
  3986.                 $nl 1;
  3987.             else {
  3988.                 // ******* Write text
  3989.                 $nl $this->Write($this->lasth$txt''0$aligntrue$stretchfalsefalse$maxh);
  3990.             }
  3991.             if ($autopadding{
  3992.                 // add bottom padding
  3993.                 $this->y += $this->cMargin;
  3994.                 // Add bottom space if needed
  3995.                 if (($this->lasth - $this->FontSize$this->LineWidth{
  3996.                     $this->y += $this->LineWidth / 2;
  3997.                 }
  3998.             }
  3999.             // Get end-of-text Y position
  4000.             $currentY $this->y;
  4001.             // get latest page number
  4002.             $endpage $this->page;
  4003.             // check if a new page has been created
  4004.             if ($endpage $startpage{
  4005.                 // design borders around HTML cells.
  4006.                 for ($page=$startpage$page <= $endpage++$page{
  4007.                     $this->setPage($page);
  4008.                     if ($page == $startpage{
  4009.                         $this->y = $starty// put cursor at the beginning of cell on the first page
  4010.                         $h $this->getPageHeight($starty $this->getBreakMargin();
  4011.                         $cborder $this->getBorderMode($border$position='start');
  4012.                     elseif ($page == $endpage{
  4013.                         $this->y = $this->tMargin// put cursor at the beginning of last page
  4014.                         $h $currentY $this->tMargin;
  4015.                         $cborder $this->getBorderMode($border$position='end');
  4016.                     else {
  4017.                         $this->y = $this->tMargin// put cursor at the beginning of the current page
  4018.                         $h $this->getPageHeight($this->tMargin - $this->getBreakMargin();
  4019.                         $cborder $this->getBorderMode($border$position='middle');
  4020.                     }
  4021.                     $nx $x;
  4022.                     // account for margin changes
  4023.                     if ($page $startpage{
  4024.                         if (($this->rtlAND ($this->pagedim[$page]['orm'!= $this->pagedim[$startpage]['orm'])) {
  4025.                             $nx $x ($this->pagedim[$page]['orm'$this->pagedim[$startpage]['orm']);
  4026.                         elseif ((!$this->rtlAND ($this->pagedim[$page]['olm'!= $this->pagedim[$startpage]['olm'])) {
  4027.                             $nx $x ($this->pagedim[$page]['olm'$this->pagedim[$startpage]['olm']);
  4028.                         }
  4029.                     }
  4030.                     $this->SetX($nx);
  4031.                     $ccode $this->getCellCode($w$h''$cborder1''$fill''0false);
  4032.                     if ($cborder OR $fill{
  4033.                         $pagebuff $this->getPageBuffer($this->page);
  4034.                         $pstart substr($pagebuff0$this->intmrk[$this->page]);
  4035.                         $pend substr($pagebuff$this->intmrk[$this->page]);
  4036.                         $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  4037.                         $this->intmrk[$this->page+= strlen($ccode."\n");
  4038.                     }
  4039.                 }
  4040.             else {
  4041.                 $h max($h($currentY $y));
  4042.                 // put cursor at the beginning of text
  4043.                 $this->SetY($y)
  4044.                 $this->SetX($x);
  4045.                 // design a cell around the text
  4046.                 $ccode $this->getCellCode($w$h''$border1''$fill''0true);
  4047.                 if ($border OR $fill{
  4048.                     if (end($this->transfmrk[$this->page]!== false{
  4049.                         $pagemarkkey key($this->transfmrk[$this->page]);
  4050.                         $pagemark &$this->transfmrk[$this->page][$pagemarkkey];
  4051.                     elseif ($this->InFooter{
  4052.                         $pagemark &$this->footerpos[$this->page];
  4053.                     else {
  4054.                         $pagemark &$this->intmrk[$this->page];
  4055.                     }
  4056.                     $pagebuff $this->getPageBuffer($this->page);
  4057.                     $pstart substr($pagebuff0$pagemark);
  4058.                     $pend substr($pagebuff$pagemark);
  4059.                     $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  4060.                     $pagemark += strlen($ccode."\n");
  4061.                 }
  4062.             }
  4063.             // Get end-of-cell Y position
  4064.             $currentY $this->GetY();
  4065.             // restore original margin values
  4066.             $this->SetLeftMargin($lMargin);
  4067.             $this->SetRightMargin($rMargin);
  4068.             if ($ln 0{
  4069.                 //Go to the beginning of the next line
  4070.                 $this->SetY($currentY);
  4071.                 if ($ln == 2{
  4072.                     $this->SetX($x $w);
  4073.                 }
  4074.             else {
  4075.                 // go left or right by case
  4076.                 $this->setPage($startpage);
  4077.                 $this->y = $y;
  4078.                 $this->SetX($x $w);
  4079.             }
  4080.             $this->setContentMark();
  4081.             return $nl;
  4082.         }
  4083.  
  4084.         /**
  4085.         * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  4086.         * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  4087.         * @param string multicell position: 'start', 'middle', 'end'
  4088.         * @return border mode
  4089.         * @access protected
  4090.         * @since 4.4.002 (2008-12-09)
  4091.         */
  4092.         protected function getBorderMode($border$position='start'{
  4093.             if ((!$this->opencellAND ($border == 1)) {
  4094.                 return 1;
  4095.             }
  4096.             $cborder '';
  4097.             switch ($position{
  4098.                 case 'start'{
  4099.                     if ($border == 1{
  4100.                         $cborder 'LTR';
  4101.                     else {
  4102.                         if (!(false === strpos($border'L'))) {
  4103.                             $cborder .= 'L';
  4104.                         }
  4105.                         if (!(false === strpos($border'T'))) {
  4106.                             $cborder .= 'T';
  4107.                         }
  4108.                         if (!(false === strpos($border'R'))) {
  4109.                             $cborder .= 'R';
  4110.                         }
  4111.                         if ((!$this->opencellAND (!(false === strpos($border'B')))) {
  4112.                             $cborder .= 'B';
  4113.                         }
  4114.                     }
  4115.                     break;
  4116.                 }
  4117.                 case 'middle'{
  4118.                     if ($border == 1{
  4119.                         $cborder 'LR';
  4120.                     else {
  4121.                         if (!(false === strpos($border'L'))) {
  4122.                             $cborder .= 'L';
  4123.                         }
  4124.                         if ((!$this->opencellAND (!(false === strpos($border'T')))) {
  4125.                             $cborder .= 'T';
  4126.                         }
  4127.                         if (!(false === strpos($border'R'))) {
  4128.                             $cborder .= 'R';
  4129.                         }
  4130.                         if ((!$this->opencellAND (!(false === strpos($border'B')))) {
  4131.                             $cborder .= 'B';
  4132.                         }
  4133.                     }
  4134.                     break;
  4135.                 }
  4136.                 case 'end'{
  4137.                     if ($border == 1{
  4138.                         $cborder 'LRB';
  4139.                     else {
  4140.                         if (!(false === strpos($border'L'))) {
  4141.                             $cborder .= 'L';
  4142.                         }
  4143.                         if ((!$this->opencellAND (!(false === strpos($border'T')))) {
  4144.                             $cborder .= 'T';
  4145.                         }
  4146.                         if (!(false === strpos($border'R'))) {
  4147.                             $cborder .= 'R';
  4148.                         }
  4149.                         if (!(false === strpos($border'B'))) {
  4150.                             $cborder .= 'B';
  4151.                         }
  4152.                     }
  4153.                     break;
  4154.                 }
  4155.                 default{
  4156.                     $cborder $border;
  4157.                     break;
  4158.                 }
  4159.             }
  4160.             return $cborder;
  4161.         }
  4162.  
  4163.         /**
  4164.         * This method returns the estimated number of lines required to print the text.
  4165.         * @param string $txt text to print
  4166.         * @param float $w width of cell. If 0, they extend up to the right margin of the page.
  4167.         * @return int Return the estimated number of lines.
  4168.         * @access public
  4169.         * @since 4.5.011
  4170.         */
  4171.         public function getNumLines($txt$w=0{
  4172.             $lines 0;
  4173.             if ($this->empty_string($wOR ($w <= 0)) {
  4174.                 if ($this->rtl{
  4175.                     $w $this->x - $this->lMargin;
  4176.                 else {
  4177.                     $w $this->w - $this->rMargin - $this->x;
  4178.                 }
  4179.             }
  4180.             // max column width
  4181.             $wmax $w ($this->cMargin);
  4182.             // remove carriage returns
  4183.             $txt str_replace("\r"''$txt);
  4184.             // remove last newline (if any)
  4185.             if (substr($txt,-1== "\n"{
  4186.                 $txt substr($txt0-1);
  4187.             }
  4188.             // divide text in blocks
  4189.             $txtblocks explode("\n"$txt);
  4190.             // for each block;
  4191.             foreach ($txtblocks as $block{
  4192.                 // estimate the number of lines
  4193.                 $lines += $this->empty_string($block(ceil($this->GetStringWidth($block$wmax));
  4194.             }
  4195.             return $lines;
  4196.         }
  4197.             
  4198.         /**
  4199.         * This method prints text from the current position.<br />
  4200.         * @param float $h Line height
  4201.         * @param string $txt String to print
  4202.         * @param mixed $link URL or identifier returned by AddLink()
  4203.         * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  4204.         * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  4205.         * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  4206.         * @param int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
  4207.         * @param boolean $firstline if true prints only the first line and return the remaining string.
  4208.         * @param boolean $firstblock if true the string is the starting of a line.
  4209.         * @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.
  4210.         * @return mixed Return the number of cells or the remaining string if $firstline = true.
  4211.         * @access public
  4212.         * @since 1.5
  4213.         */
  4214.         public function Write($h$txt$link=''$fill=0$align=''$ln=false$stretch=0$firstline=false$firstblock=false$maxh=0{
  4215.             if (strlen($txt== 0{
  4216.                 $txt ' ';
  4217.             }
  4218.             // remove carriage returns
  4219.             $s str_replace("\r"''$txt);
  4220.             // check if string contains arabic text
  4221.             if (preg_match(K_RE_PATTERN_ARABIC$s)) {
  4222.                 $arabic true;
  4223.             else {
  4224.                 $arabic false;
  4225.             }
  4226.             // check if string contains RTL text
  4227.             if ($arabic OR $this->tmprtl OR preg_match(K_RE_PATTERN_RTL$txt)) {
  4228.                 $rtlmode true;
  4229.             else {
  4230.                 $rtlmode false;
  4231.             }
  4232.             // get a char width
  4233.             $chrwidth $this->GetCharWidth('.');
  4234.             // get array of unicode values
  4235.             $chars $this->UTF8StringToArray($s);
  4236.             // get array of chars
  4237.             $uchars $this->UTF8ArrayToUniArray($chars);
  4238.             // get the number of characters
  4239.             $nb count($chars);
  4240.             // replacement for SHY character (minus symbol)
  4241.             $shy_replacement 45;
  4242.             $shy_replacement_char $this->unichr($shy_replacement);
  4243.             // widht for SHY replacement
  4244.             $shy_replacement_width $this->GetCharWidth($shy_replacement);
  4245.             // store current position
  4246.             $prevx $this->x;
  4247.             $prevy $this->y;
  4248.             // max Y
  4249.             $maxy $this->y + $maxh $h ($this->cMargin);
  4250.             // calculate remaining line width ($w)
  4251.             if ($this->rtl{
  4252.                 $w $this->x - $this->lMargin;
  4253.             else {
  4254.                 $w $this->w - $this->rMargin - $this->x;
  4255.             }
  4256.             // max column width
  4257.             $wmax $w ($this->cMargin);
  4258.             if ((!$firstlineAND (($chrwidth $wmaxOR ($this->GetCharWidth($chars[0]$wmax))) {
  4259.                 // a single character do not fit on column
  4260.                 return '';
  4261.             }
  4262.             $i 0// character position
  4263.             $j 0// current starting position
  4264.             $sep = -1// position of the last blank space
  4265.             $shy false// true if the last blank is a soft hypen (SHY)
  4266.             $l 0// current string lenght
  4267.             $nl 0//number of lines
  4268.             $linebreak false;
  4269.             // for each character
  4270.             while ($i $nb{
  4271.                 if (($maxh 0AND ($this->y >= $maxy) ) {
  4272.                     $firstline true;
  4273.                 }
  4274.                 //Get the current character
  4275.                 $c $chars[$i];
  4276.                 if ($c == 10// 10 = "\n" = new line
  4277.                     //Explicit line break
  4278.                     if ($align == 'J'{
  4279.                         if ($this->rtl{
  4280.                             $talign 'R';
  4281.                         else {
  4282.                             $talign 'L';
  4283.                         }
  4284.                     else {
  4285.                         $talign $align;
  4286.                     }
  4287.                     $tmpstr $this->UniArrSubString($uchars$j$i);
  4288.                     if ($firstline{
  4289.                         $startx $this->x;
  4290.                         $tmparr array_slice($chars$j$i);
  4291.                         if ($rtlmode{
  4292.                             $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4293.                         }
  4294.                         $linew $this->GetArrStringWidth($tmparr);
  4295.                         unset($tmparr);
  4296.                         if ($this->rtl{
  4297.                             $this->endlinex = $startx $linew;
  4298.                         else {
  4299.                             $this->endlinex = $startx $linew;
  4300.                         }
  4301.                         $w $linew;
  4302.                         $tmpcmargin $this->cMargin;
  4303.                         if ($maxh == 0{
  4304.                             $this->cMargin = 0;
  4305.                         }
  4306.                     }
  4307.                     $this->Cell($w$h$tmpstr01$talign$fill$link$stretch);
  4308.                     unset($tmpstr);
  4309.                     if ($firstline{
  4310.                         $this->cMargin = $tmpcmargin;
  4311.                         return ($this->UniArrSubString($uchars$i));
  4312.                     }
  4313.                     ++$nl;
  4314.                     $j $i 1;
  4315.                     $l 0;
  4316.                     $sep = -1;
  4317.                     $shy false;
  4318.                     // account for margin changes
  4319.                     if ((($this->y + $this->lasth$this->PageBreakTriggerAND (!$this->InFooter)) {
  4320.                         // AcceptPageBreak() may be overriden on extended classed to include margin changes
  4321.                         $this->AcceptPageBreak();
  4322.                     }
  4323.                     $w $this->getRemainingWidth();
  4324.                     $wmax $w ($this->cMargin);
  4325.                 else {
  4326.                     // 160 is the non-breaking space.
  4327.                     // 173 is SHY (Soft Hypen).
  4328.                     // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  4329.                     // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  4330.                     // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  4331.                     if (($c != 160AND (($c == 173OR preg_match($this->re_spaces$this->unichr($c)))) {
  4332.                         // update last blank space position
  4333.                         $sep $i;
  4334.                         // check if is a SHY
  4335.                         if ($c == 173{
  4336.                             $shy true;
  4337.                         else {
  4338.                             $shy false;
  4339.                         }
  4340.                     }
  4341.                     // update string length
  4342.                     if ((($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) AND ($arabic)) {
  4343.                         // with bidirectional algorithm some chars may be changed affecting the line length
  4344.                         // *** very slow ***
  4345.                         $l $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j$i-$j+1)''$this->tmprtl));
  4346.                     else {
  4347.                         $l += $this->GetCharWidth($c);
  4348.                     }
  4349.                     if (($l $wmaxOR ($shy AND (($l $shy_replacement_width$wmax)) ) {
  4350.                         // we have reached the end of column
  4351.                         if ($sep == -1{
  4352.                             // check if the line was already started
  4353.                             if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
  4354.                                 OR ((!$this->rtlAND ($this->x >= ($this->lMargin + $chrwidth)))) {
  4355.                                 // print a void cell and go to next line
  4356.                                 $this->Cell($w$h''01);
  4357.                                 $linebreak true;
  4358.                                 if ($firstline{
  4359.                                     return ($this->UniArrSubString($uchars$j));
  4360.                                 }
  4361.                             else {
  4362.                                 // truncate the word because do not fit on column
  4363.                                 $tmpstr $this->UniArrSubString($uchars$j$i);
  4364.                                 if ($firstline{
  4365.                                     $startx $this->x;
  4366.                                     $tmparr array_slice($chars$j$i);
  4367.                                     if ($rtlmode{
  4368.                                         $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4369.                                     }
  4370.                                     $linew $this->GetArrStringWidth($tmparr);
  4371.                                     unset($tmparr);
  4372.                                     if ($this->rtl{
  4373.                                         $this->endlinex = $startx $linew;
  4374.                                     else {
  4375.                                         $this->endlinex = $startx $linew;
  4376.                                     }
  4377.                                     $w $linew;
  4378.                                     $tmpcmargin $this->cMargin;
  4379.                                     if ($maxh == 0{
  4380.                                         $this->cMargin = 0;
  4381.                                     }
  4382.                                 }
  4383.                                 $this->Cell($w$h$tmpstr01$align$fill$link$stretch);
  4384.                                 unset($tmpstr);
  4385.                                 if ($firstline{
  4386.                                     $this->cMargin = $tmpcmargin;
  4387.                                     return ($this->UniArrSubString($uchars$i));
  4388.                                 }
  4389.                                 $j $i;
  4390.                                 --$i;
  4391.                             }    
  4392.                         else {
  4393.                             // word wrapping
  4394.                             if ($this->rtl AND (!$firstblock)) {
  4395.                                 $endspace 1;
  4396.                             else {
  4397.                                 $endspace 0;
  4398.                             }
  4399.                             if ($shy{
  4400.                                 // add hypen (minus symbol) at the end of the line
  4401.                                 $shy_width $shy_replacement_width;
  4402.                                 if ($this->rtl{
  4403.                                     $shy_char_left $shy_replacement_char;
  4404.                                     $shy_char_right '';
  4405.                                 else {
  4406.                                     $shy_char_left '';
  4407.                                     $shy_char_right $shy_replacement_char;
  4408.                                 }
  4409.                             else {
  4410.                                 $shy_width 0;
  4411.                                 $shy_char_left '';
  4412.                                 $shy_char_right '';
  4413.                             }
  4414.                             $tmpstr $this->UniArrSubString($uchars$j($sep $endspace));
  4415.                             if ($firstline{
  4416.                                 $startx $this->x;
  4417.                                 $tmparr array_slice($chars$j($sep $endspace));
  4418.                                 if ($rtlmode{
  4419.                                     $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4420.                                 }
  4421.                                 $linew $this->GetArrStringWidth($tmparr);
  4422.                                 unset($tmparr);
  4423.                                 if ($this->rtl{
  4424.                                     $this->endlinex = $startx $linew $shy_width;
  4425.                                 else {
  4426.                                     $this->endlinex = $startx $linew $shy_width;
  4427.                                 }
  4428.                                 $w $linew;
  4429.                                 $tmpcmargin $this->cMargin;
  4430.                                 if ($maxh == 0{
  4431.                                     $this->cMargin = 0;
  4432.                                 }
  4433.                             }
  4434.                             // print the line
  4435.                             $this->Cell($w$h$shy_char_left.$tmpstr.$shy_char_right01$align$fill$link$stretch);
  4436.                             unset($tmpstr);
  4437.                             if ($firstline{
  4438.                                 // return the remaining text
  4439.                                 $this->cMargin = $tmpcmargin;
  4440.                                 return ($this->UniArrSubString($uchars($sep $endspace)));
  4441.                             }
  4442.                             $i $sep;
  4443.                             $sep = -1;
  4444.                             $shy false;
  4445.                             $j ($i+1);
  4446.                         }
  4447.                         // account for margin changes
  4448.                         if ((($this->y + $this->lasth$this->PageBreakTriggerAND (!$this->InFooter)) {
  4449.                             // AcceptPageBreak() may be overriden on extended classed to include margin changes
  4450.                             $this->AcceptPageBreak();
  4451.                         }
  4452.                         $w $this->getRemainingWidth();
  4453.                         $wmax $w ($this->cMargin);
  4454.                         if ($linebreak{
  4455.                             $linebreak false;
  4456.                         else {
  4457.                             ++$nl;
  4458.                             $l 0;
  4459.                         }
  4460.                     }
  4461.                 }
  4462.                 ++$i;
  4463.             // end while i < nb
  4464.             // print last substring (if any)
  4465.             if ($l 0{
  4466.                 switch ($align{
  4467.                     case 'J':
  4468.                     case 'C'{
  4469.                         $w $w;
  4470.                         break;
  4471.                     }
  4472.                     case 'L'{
  4473.                         if ($this->rtl{
  4474.                             $w $w;
  4475.                         else {
  4476.                             $w $l;
  4477.                         }
  4478.                         break;
  4479.                     }
  4480.                     case 'R'{
  4481.                         if ($this->rtl{
  4482.                             $w $l;
  4483.                         else {
  4484.                             $w $w;
  4485.                         }
  4486.                         break;
  4487.                     }
  4488.                     default{
  4489.                         $w $l;
  4490.                         break;
  4491.                     }
  4492.                 }
  4493.                 $tmpstr $this->UniArrSubString($uchars$j$nb);
  4494.                 if ($firstline{
  4495.                     $startx $this->x;
  4496.                     $tmparr array_slice($chars$j$nb);
  4497.                     if ($rtlmode{
  4498.                         $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4499.                     }
  4500.                     $linew $this->GetArrStringWidth($tmparr);
  4501.                     unset($tmparr);
  4502.                     if ($this->rtl{
  4503.                         $this->endlinex = $startx $linew;
  4504.                     else {
  4505.                         $this->endlinex = $startx $linew;
  4506.                     }
  4507.                     $w $linew;
  4508.                     $tmpcmargin $this->cMargin;
  4509.                     if ($maxh == 0{
  4510.                         $this->cMargin = 0;
  4511.                     }
  4512.                 }
  4513.                 $this->Cell($w$h$tmpstr0$ln$align$fill$link$stretch);
  4514.                 unset($tmpstr);
  4515.                 if ($firstline{
  4516.                     $this->cMargin = $tmpcmargin;
  4517.                     return ($this->UniArrSubString($uchars$nb));
  4518.                 }
  4519.                 ++$nl;
  4520.             }
  4521.             if ($firstline{
  4522.                 return '';
  4523.             }
  4524.             return $nl;
  4525.         }
  4526.                 
  4527.         /**
  4528.         * Returns the remaining width between the current position and margins.
  4529.         * @return int Return the remaining width
  4530.         * @access protected
  4531.         */
  4532.         protected function getRemainingWidth({
  4533.             if ($this->rtl{
  4534.                 return ($this->x - $this->lMargin);
  4535.             else {
  4536.                 return ($this->w - $this->rMargin - $this->x);
  4537.             }
  4538.         }
  4539.  
  4540.          /**
  4541.         * Extract a slice of the $strarr array and return it as string.
  4542.         * @param string $strarr The input array of characters.
  4543.         * @param int $start the starting element of $strarr.
  4544.         * @param int $end first element that will not be returned.
  4545.         * @return Return part of a string
  4546.         * @access public
  4547.         */
  4548.         public function UTF8ArrSubString($strarr$start=''$end=''{
  4549.             if (strlen($start== 0{
  4550.                 $start 0;
  4551.             }
  4552.             if (strlen($end== 0{
  4553.                 $end count($strarr);
  4554.             }
  4555.             $string '';
  4556.             for ($i=$start$i $end++$i{
  4557.                 $string .= $this->unichr($strarr[$i]);
  4558.             }
  4559.             return $string;
  4560.         }
  4561.  
  4562.          /**
  4563.         * Extract a slice of the $uniarr array and return it as string.
  4564.         * @param string $uniarr The input array of characters.
  4565.         * @param int $start the starting element of $strarr.
  4566.         * @param int $end first element that will not be returned.
  4567.         * @return Return part of a string
  4568.         * @access public
  4569.         * @since 4.5.037 (2009-04-07)
  4570.         */
  4571.         public function UniArrSubString($uniarr$start=''$end=''{
  4572.             if (strlen($start== 0{
  4573.                 $start 0;
  4574.             }
  4575.             if (strlen($end== 0{
  4576.                 $end count($uniarr);
  4577.             }
  4578.             $string '';
  4579.             for ($i=$start$i $end++$i{
  4580.                 $string .= $uniarr[$i];
  4581.             }
  4582.             return $string;
  4583.         }
  4584.  
  4585.          /**
  4586.         * Convert an array of UTF8 values to array of unicode characters
  4587.         * @param string $ta The input array of UTF8 values.
  4588.         * @return Return array of unicode characters
  4589.         * @access public
  4590.         * @since 4.5.037 (2009-04-07)
  4591.         */
  4592.         public function UTF8ArrayToUniArray($ta{
  4593.             return array_map(array($this'unichr')$ta);
  4594.         }
  4595.         
  4596.         /**
  4597.         * Returns the unicode caracter specified by UTF-8 code
  4598.         * @param int $c UTF-8 code
  4599.         * @return Returns the specified character.
  4600.         * @author Miguel Perez, Nicola Asuni
  4601.         * @access public
  4602.         * @since 2.3.000 (2008-03-05)
  4603.         */
  4604.         public function unichr($c{
  4605.             if (!$this->isunicode{
  4606.                 return chr($c);
  4607.             elseif ($c <= 0x7F{
  4608.                 // one byte
  4609.                 return chr($c);
  4610.             elseif ($c <= 0x7FF{
  4611.                 // two bytes
  4612.                 return chr(0xC0 $c >> 6).chr(0x80 $c 0x3F);
  4613.             elseif ($c <= 0xFFFF{
  4614.                 // three bytes
  4615.                 return chr(0xE0 $c >> 12).chr(0x80 $c >> 0x3F).chr(0x80 $c 0x3F);
  4616.             elseif ($c <= 0x10FFFF{
  4617.                 // four bytes
  4618.                 return chr(0xF0 $c >> 18).chr(0x80 $c >> 12 0x3F).chr(0x80 $c >> 0x3F).chr(0x80 $c 0x3F);
  4619.             else {
  4620.                 return '';
  4621.             }
  4622.         }
  4623.         
  4624.         /**
  4625.         * Puts an image in the page.
  4626.         * The upper-left corner must be given.
  4627.         * The dimensions can be specified in different ways:<ul>
  4628.         * <li>explicit width and height (expressed in user unit)</li>
  4629.         * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  4630.         * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  4631.         * Supported formats are JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
  4632.         * The format can be specified explicitly or inferred from the file extension.<br />
  4633.         * It is possible to put a link on the image.<br />
  4634.         * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  4635.         * @param string $file Name of the file containing the image.
  4636.         * @param float $x Abscissa of the upper-left corner.
  4637.         * @param float $y Ordinate of the upper-left corner.
  4638.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4639.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4640.         * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  4641.         * @param mixed $link URL or identifier returned by AddLink().
  4642.         * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  4643.         * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  4644.         * @param int $dpi dot-per-inch resolution used on resize
  4645.         * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  4646.         * @param boolean $ismask true if this image is a mask, false otherwise
  4647.         * @param mixed $imgmask image object returned by this function or false
  4648.         * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  4649.         * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box.
  4650.         * @param boolean $hidden if true do not display the image.
  4651.         * @return image information
  4652.         * @access public
  4653.         * @since 1.1
  4654.         */
  4655.         public function Image($file$x=''$y=''$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''$ismask=false$imgmask=false$border=0$fitbox=false$hidden=false{
  4656.             if ($x === ''{
  4657.                 $x $this->x;
  4658.             }
  4659.             if ($y === ''{
  4660.                 $y $this->y;
  4661.             }
  4662.             // get image dimensions
  4663.             $imsize @getimagesize($file);
  4664.             if ($imsize === FALSE{
  4665.                 // encode spaces on filename
  4666.                 $file str_replace(' ''%20'$file);
  4667.                 $imsize @getimagesize($file);
  4668.                 if ($imsize === FALSE{
  4669.                     $this->Error('[Image] No such file or directory in '.$file);
  4670.                 }
  4671.             }
  4672.             // get original image width and height in pixels
  4673.             list($pixw$pixh$imsize;
  4674.             // calculate image width and height on document
  4675.             if (($w <= 0AND ($h <= 0)) {
  4676.                 // convert image size to document unit
  4677.                 $w $this->pixelsToUnits($pixw);
  4678.                 $h $this->pixelsToUnits($pixh);
  4679.             elseif ($w <= 0{
  4680.                 $w $h $pixw $pixh;
  4681.             elseif ($h <= 0{
  4682.                 $h $w $pixh $pixw;
  4683.             elseif ($fitbox AND ($w 0AND ($h 0)) {
  4684.                 // scale image dimensions proportionally to fit within the ($w, $h) box
  4685.                 if ((($w $pixh($h $pixw)) 1{
  4686.                     $h $w $pixh $pixw;
  4687.                 else {
  4688.                     $w $h $pixw $pixh;
  4689.                 }
  4690.             }
  4691.             // calculate new minimum dimensions in pixels
  4692.             $neww round($w $this->k * $dpi $this->dpi);
  4693.             $newh round($h $this->k * $dpi $this->dpi);
  4694.             // check if resize is necessary (resize is used only to reduce the image)
  4695.             if (($neww $newh>= ($pixw $pixh)) {
  4696.                 $resize false;
  4697.             }
  4698.             // check if image has been already added on document
  4699.             if (!in_array($file$this->imagekeys)) {
  4700.                 //First use of image, get info
  4701.                 if ($type == ''{
  4702.                     $fileinfo pathinfo($file);
  4703.                     if (isset($fileinfo['extension']AND (!$this->empty_string($fileinfo['extension']))) {
  4704.                         $type $fileinfo['extension'];
  4705.                     else {
  4706.                         $this->Error('Image file has no extension and no type was specified: '.$file);
  4707.                     }
  4708.                 }
  4709.                 $type strtolower($type);
  4710.                 if ($type == 'jpg'{
  4711.                     $type 'jpeg';
  4712.                 }
  4713.                 $mqr $this->get_mqr();
  4714.                 $this->set_mqr(false);
  4715.                 // Specific image handlers
  4716.                 $mtd '_parse'.$type;
  4717.                 // GD image handler function
  4718.                 $gdfunction 'imagecreatefrom'.$type;
  4719.                 $info false;
  4720.                 if ((method_exists($this$mtd)) AND (!($resize AND function_exists($gdfunction)))) {
  4721.                     // TCPDF image functions
  4722.                     $info $this->$mtd($file);
  4723.                     if ($info == 'pngalpha'{
  4724.                         return $this->ImagePngAlpha($file$x$y$w$h'PNG'$link$align$resize$dpi$palign);
  4725.                     }
  4726.                 
  4727.                 if (!$info{
  4728.                     if (function_exists($gdfunction)) {
  4729.                         // GD library
  4730.                         $img $gdfunction($file);
  4731.                         if ($resize{
  4732.                             $imgr imagecreatetruecolor($neww$newh);
  4733.                             imagecopyresampled($imgr$img0000$neww$newh$pixw$pixh)
  4734.                             $info $this->_toJPEG($imgr);
  4735.                         else {
  4736.                             $info $this->_toJPEG($img);
  4737.                         }
  4738.                     elseif (extension_loaded('imagick')) {
  4739.                         // ImageMagick library
  4740.                         $img new Imagick();
  4741.                         $img->readImage($file);
  4742.                         if ($resize{
  4743.                             $img->resizeImage($neww$newh101false);
  4744.                         }
  4745.                         $img->setCompressionQuality($this->jpeg_quality);
  4746.                         $img->setImageFormat('jpeg');
  4747.                         $tempname tempnam(K_PATH_CACHE'jpg_');
  4748.                         $img->writeImage($tempname);
  4749.                         $info $this->_parsejpeg($tempname);
  4750.                         unlink($tempname);
  4751.                         $img->destroy();
  4752.                     else {
  4753.                         return;
  4754.                     }
  4755.                 }
  4756.                 if ($info === false{
  4757.                     //If false, we cannot process image
  4758.                     return;
  4759.                 }
  4760.                 $this->set_mqr($mqr);
  4761.                 if ($ismask{
  4762.                     // force grayscale
  4763.                     $info['cs''DeviceGray';
  4764.                 }
  4765.                 $info['i'$this->numimages + 1;
  4766.                 if ($imgmask !== false{
  4767.                     $info['masked'$imgmask;
  4768.                 }
  4769.                 // add image to document
  4770.                 $this->setImageBuffer($file$info);
  4771.             else {
  4772.                 $info $this->getImageBuffer($file);
  4773.             }
  4774.             // Check whether we need a new page first as this does not fit
  4775.             if ($this->checkPageBreak($h$y)) {
  4776.                 $y $this->GetY($this->cMargin;
  4777.             }
  4778.             // set bottomcoordinates
  4779.             $this->img_rb_y = $y $h;
  4780.             // set alignment
  4781.             if ($this->rtl{
  4782.                 if ($palign == 'L'{
  4783.                     $ximg $this->lMargin;
  4784.                     // set right side coordinate
  4785.                     $this->img_rb_x = $ximg $w;
  4786.                 elseif ($palign == 'C'{
  4787.                     $ximg ($this->w - $x $w2;
  4788.                     // set right side coordinate
  4789.                     $this->img_rb_x = $ximg $w;
  4790.                 else {
  4791.                     $ximg $this->w - $x $w;
  4792.                     // set left side coordinate
  4793.                     $this->img_rb_x = $ximg;
  4794.                 }
  4795.             else {
  4796.                 if ($palign == 'R'{
  4797.                     $ximg $this->w - $this->rMargin - $w;
  4798.                     // set left side coordinate
  4799.                     $this->img_rb_x = $ximg;
  4800.                 elseif ($palign == 'C'{
  4801.                     $ximg ($this->w - $x $w2;
  4802.                     // set right side coordinate
  4803.                     $this->img_rb_x = $ximg $w;
  4804.                 else {
  4805.                     $ximg $x;
  4806.                     // set right side coordinate
  4807.                     $this->img_rb_x = $ximg $w;
  4808.                 }
  4809.             }
  4810.             if ($ismask OR $hidden{
  4811.                 // image is not displayed
  4812.                 return $info['i'];
  4813.             }
  4814.             $xkimg $ximg $this->k;
  4815.             $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']));
  4816.             if (!empty($border)) {
  4817.                 $bx $x;
  4818.                 $by $y;
  4819.                 $this->x = $ximg;
  4820.                 $this->y = $y;
  4821.                 $this->Cell($w$h''$border0''0''0);
  4822.                 $this->x = $bx;
  4823.                 $this->y = $by;
  4824.             }
  4825.             if ($link{
  4826.                 $this->Link($ximg$y$w$h$link0);
  4827.             }
  4828.             // set pointer to align the successive text/objects
  4829.             switch($align{
  4830.                 case 'T'{
  4831.                     $this->y = $y;
  4832.                     $this->x = $this->img_rb_x;
  4833.                     break;
  4834.                 }
  4835.                 case 'M'{
  4836.                     $this->y = $y round($h/2);
  4837.                     $this->x = $this->img_rb_x;
  4838.                     break;
  4839.                 }
  4840.                 case 'B'{
  4841.                     $this->y = $this->img_rb_y;
  4842.                     $this->x = $this->img_rb_x;
  4843.                     break;
  4844.                 }
  4845.                 case 'N'{
  4846.                     $this->SetY($this->img_rb_y);
  4847.                     break;
  4848.                 }
  4849.                 default:{
  4850.                     break;
  4851.                 }
  4852.             }
  4853.             $this->endlinex = $this->img_rb_x;
  4854.             return $info['i'];
  4855.         }
  4856.         
  4857.         /**
  4858.          * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  4859.          * @param boolean $mqr FALSE for off, TRUE for on.
  4860.          * @since 4.6.025 (2009-08-17)
  4861.          */
  4862.         public function set_mqr($mqr{
  4863.             if(!defined('PHP_VERSION_ID')) {
  4864.                 $version PHP_VERSION;
  4865.                 define('PHP_VERSION_ID'(($version{010000($version{2100$version{4}));
  4866.             }
  4867.             if (PHP_VERSION_ID 50300{
  4868.                 @set_magic_quotes_runtime($mqr);
  4869.             }
  4870.         }
  4871.         
  4872.         /**
  4873.          * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  4874.          * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  4875.          * @since 4.6.025 (2009-08-17)
  4876.          */
  4877.         public function get_mqr({
  4878.             if(!defined('PHP_VERSION_ID')) {
  4879.                 $version PHP_VERSION;
  4880.                 define('PHP_VERSION_ID'(($version{010000($version{2100$version{4}));
  4881.             }
  4882.             if (PHP_VERSION_ID 50300{
  4883.                 return @get_magic_quotes_runtime();
  4884.             }
  4885.             return 0;
  4886.         }
  4887.                         
  4888.         /**
  4889.         * Convert the loaded php image to a JPEG and then return a structure for the PDF creator.
  4890.         * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  4891.         * @param string $file Image file name.
  4892.         * @param image $image Image object.
  4893.         *  return image JPEG image object.
  4894.         * @access protected
  4895.         */
  4896.         protected function _toJPEG($image{
  4897.             $tempname tempnam(K_PATH_CACHE'jpg_');
  4898.             imagejpeg($image$tempname$this->jpeg_quality);
  4899.             imagedestroy($image);
  4900.             $retvars $this->_parsejpeg($tempname);
  4901.             // tidy up by removing temporary image
  4902.             unlink($tempname);
  4903.             return $retvars;
  4904.         }
  4905.         
  4906.         /**
  4907.         * Extract info from a JPEG file without using the GD library.
  4908.         * @param string $file image file to parse
  4909.         * @return array structure containing the image data
  4910.         * @access protected
  4911.         */
  4912.         protected function _parsejpeg($file{
  4913.             $a getimagesize($file);
  4914.             if (empty($a)) {
  4915.                 $this->Error('Missing or incorrect image file: '.$file);
  4916.             }
  4917.             if ($a[2!= 2{
  4918.                 $this->Error('Not a JPEG file: '.$file);
  4919.             }
  4920.             if ((!isset($a['channels'])) OR ($a['channels'== 3)) {
  4921.                 $colspace 'DeviceRGB';
  4922.             elseif ($a['channels'== 4{
  4923.                 $colspace 'DeviceCMYK';
  4924.             else {
  4925.                 $colspace 'DeviceGray';
  4926.             }
  4927.             $bpc = isset($a['bits']$a['bits'8;
  4928.             $data file_get_contents($file);
  4929.             return array('w' => $a[0]'h' => $a[1]'cs' => $colspace'bpc' => $bpc'f' => 'DCTDecode''data' => $data);
  4930.         }
  4931.  
  4932.         /**
  4933.         * Extract info from a PNG file without using the GD library.
  4934.         * @param string $file image file to parse
  4935.         * @return array structure containing the image data
  4936.         * @access protected
  4937.         */
  4938.         protected function _parsepng($file{
  4939.             $f fopen($file'rb');
  4940.             if ($f === false{
  4941.                 $this->Error('Can\'t open image file: '.$file);
  4942.             }
  4943.             //Check signature
  4944.             if (fread($f8!= chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  4945.                 $this->Error('Not a PNG file: '.$file);
  4946.             }
  4947.             //Read header chunk
  4948.             fread($f4);
  4949.             if (fread($f4!= 'IHDR'{
  4950.                 $this->Error('Incorrect PNG file: '.$file);
  4951.             }
  4952.             $w $this->_freadint($f);
  4953.             $h $this->_freadint($f);
  4954.             $bpc ord(fread($f1));
  4955.             if ($bpc 8{
  4956.                 //$this->Error('16-bit depth not supported: '.$file);
  4957.                 fclose($f);
  4958.                 return false;
  4959.             }
  4960.             $ct ord(fread($f1));
  4961.             if ($ct == 0{
  4962.                 $colspace 'DeviceGray';
  4963.             elseif ($ct == 2{
  4964.                 $colspace 'DeviceRGB';
  4965.             elseif ($ct == 3{
  4966.                 $colspace 'Indexed';
  4967.             else {
  4968.                 // alpha channel
  4969.                 fclose($f);
  4970.                 return 'pngalpha';
  4971.             }
  4972.             if (ord(fread($f1)) != 0{
  4973.                 //$this->Error('Unknown compression method: '.$file);
  4974.                 fclose($f);
  4975.                 return false;
  4976.             }
  4977.             if (ord(fread($f1)) != 0{
  4978.                 //$this->Error('Unknown filter method: '.$file);
  4979.                 fclose($f);
  4980.                 return false;
  4981.             }
  4982.             if (ord(fread($f1)) != 0{
  4983.                 //$this->Error('Interlacing not supported: '.$file);
  4984.                 fclose($f);
  4985.                 return false;
  4986.             }
  4987.             fread($f4);
  4988.             $parms '/DecodeParms <</Predictor 15 /Colors '.($ct==1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  4989.             //Scan chunks looking for palette, transparency and image data
  4990.             $pal '';
  4991.             $trns '';
  4992.             $data '';
  4993.             do {
  4994.                 $n $this->_freadint($f);
  4995.                 $type fread($f4);
  4996.                 if ($type == 'PLTE'{
  4997.                     //Read palette
  4998.                     $pal $this->rfread($f$n);
  4999.                     fread($f4);
  5000.                 elseif ($type == 'tRNS'{
  5001.                     //Read transparency info
  5002.                     $t $this->rfread($f$n);
  5003.                     if ($ct == 0{
  5004.                         $trns array(ord(substr($t11)));
  5005.                     elseif ($ct == 2{
  5006.                         $trns array(ord(substr($t11))ord(substr($t31))ord(substr($t51)));
  5007.                     else {
  5008.                         $pos strpos($tchr(0));
  5009.                         if ($pos !== false{
  5010.                             $trns array($pos);
  5011.                         }
  5012.                     }
  5013.                     fread($f4);
  5014.                 elseif ($type == 'IDAT'{
  5015.                     //Read image data block
  5016.                     $data .= $this->rfread($f$n);
  5017.                     fread($f4);
  5018.                 elseif ($type == 'IEND'{
  5019.                     break;
  5020.                 else {
  5021.                     $this->rfread($f$n 4);
  5022.                 }
  5023.             while ($n);
  5024.             if (($colspace == 'Indexed'AND (empty($pal))) {
  5025.                 //$this->Error('Missing palette in '.$file);
  5026.                 fclose($f);
  5027.                 return false;
  5028.             }
  5029.             fclose($f);
  5030.             return array('w' => $w'h' => $h'cs' => $colspace'bpc' => $bpc'f' => 'FlateDecode''parms' => $parms'pal' => $pal'trns' => $trns'data' => $data);
  5031.         }
  5032.  
  5033.         /**
  5034.         * Binary-safe and URL-safe file read.
  5035.         * 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.
  5036.         * @param resource $handle 
  5037.         * @param int $length 
  5038.         * @return Returns the read string or FALSE in case of error.
  5039.         * @author Nicola Asuni
  5040.         * @access protected
  5041.         * @since 4.5.027 (2009-03-16)
  5042.         */
  5043.         protected function rfread($handle$length{
  5044.             $data fread($handle$length);
  5045.             if ($data === false{
  5046.                 return false;
  5047.             }
  5048.             $rest $length strlen($data);
  5049.             if ($rest 0{
  5050.                 $data .= $this->rfread($handle$rest);
  5051.             }
  5052.             return $data;
  5053.         }
  5054.  
  5055.         /**
  5056.         * Extract info from a PNG image with alpha channel using the GD library.
  5057.         * @param string $file Name of the file containing the image.
  5058.         * @param float $x Abscissa of the upper-left corner.
  5059.         * @param float $y Ordinate of the upper-left corner.
  5060.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5061.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  5062.         * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  5063.         * @param mixed $link URL or identifier returned by AddLink().
  5064.         * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  5065.         * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  5066.         * @param int $dpi dot-per-inch resolution used on resize
  5067.         * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  5068.         * @author Valentin Schmidt, Nicola Asuni
  5069.         * @access protected
  5070.         * @since 4.3.007 (2008-12-04)
  5071.         * @see Image()
  5072.         */
  5073.         protected function ImagePngAlpha($file$x=''$y=''$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''{
  5074.             // get image size
  5075.             list($wpx$hpxgetimagesize($file);
  5076.             // generate images
  5077.             $img imagecreatefrompng($file);
  5078.             $imgalpha imagecreate($wpx$hpx);
  5079.             // generate gray scale pallete
  5080.             for ($c 0$c 256++$c{
  5081.                 ImageColorAllocate($imgalpha$c$c$c);
  5082.             }
  5083.             // extract alpha channel
  5084.             for ($xpx 0$xpx $wpx++$xpx{
  5085.                 for ($ypx 0$ypx $hpx++$ypx{
  5086.                     $colorindex imagecolorat($img$xpx$ypx);
  5087.                     $col imagecolorsforindex($img$colorindex);
  5088.                     imagesetpixel($imgalpha$xpx$ypx$this->getGDgamma((127 $col['alpha']255 127));
  5089.                 }
  5090.             }
  5091.             // create temp alpha file
  5092.             $tempfile_alpha tempnam(K_PATH_CACHE'mska_');
  5093.             imagepng($imgalpha$tempfile_alpha);
  5094.             imagedestroy($imgalpha);
  5095.             // extract image without alpha channel
  5096.             $imgplain imagecreatetruecolor($wpx$hpx);
  5097.             imagecopy($imgplain$img0000$wpx$hpx);
  5098.             // create temp image file
  5099.             $tempfile_plain tempnam(K_PATH_CACHE'mskp_');
  5100.             imagepng($imgplain$tempfile_plain);
  5101.             imagedestroy($imgplain);
  5102.             // embed mask image
  5103.             $imgmask $this->Image($tempfile_alpha$x$y$w$h'PNG'''''$resize$dpi''truefalse);
  5104.             // embed image, masked with previously embedded mask
  5105.             $this->Image($tempfile_plain$x$y$w$h$type$link$align$resize$dpi$palignfalse$imgmask);
  5106.             // remove temp files
  5107.             unlink($tempfile_alpha);
  5108.             unlink($tempfile_plain);
  5109.         }
  5110.  
  5111.         /**
  5112.         * Correct the gamma value to be used with GD library
  5113.         * @param float $v the gamma value to be corrected
  5114.         * @access protected
  5115.         * @since 4.3.007 (2008-12-04)
  5116.         */
  5117.         protected function getGDgamma($v{
  5118.             return (pow(($v 255)2.2255);
  5119.         
  5120.         
  5121.         /**
  5122.         * Performs a line break.
  5123.         * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  5124.         * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  5125.         * @param boolean $cell if true add a cMargin to the x coordinate
  5126.         * @access public
  5127.         * @since 1.0
  5128.         * @see Cell()
  5129.         */
  5130.         public function Ln($h=''$cell=false{
  5131.             //Line feed; default value is last cell height
  5132.             if ($cell{
  5133.                 $cellmargin $this->cMargin;
  5134.             else {
  5135.                 $cellmargin 0;
  5136.             }
  5137.             if ($this->rtl{
  5138.                 $this->x = $this->w - $this->rMargin - $cellmargin;
  5139.             else {
  5140.                 $this->x = $this->lMargin + $cellmargin;
  5141.             }
  5142.             if (is_string($h)) {
  5143.                 $this->y += $this->lasth;
  5144.             else {
  5145.                 $this->y += $h;
  5146.             }
  5147.             $this->newline = true;
  5148.         }
  5149.  
  5150.         /**
  5151.         * Returns the relative X value of current position.
  5152.         * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  5153.         * @return float 
  5154.         * @access public
  5155.         * @since 1.2
  5156.         * @see SetX(), GetY(), SetY()
  5157.         */
  5158.         public function GetX({
  5159.             //Get x position
  5160.             if ($this->rtl{
  5161.                 return ($this->w - $this->x);
  5162.             else {
  5163.                 return $this->x;
  5164.             }
  5165.         }
  5166.         
  5167.         /**
  5168.         * Returns the absolute X value of current position.
  5169.         * @return float 
  5170.         * @access public
  5171.         * @since 1.2
  5172.         * @see SetX(), GetY(), SetY()
  5173.         */
  5174.         public function GetAbsX({
  5175.             return $this->x;
  5176.         }
  5177.         
  5178.         /**
  5179.         * Returns the ordinate of the current position.
  5180.         * @return float 
  5181.         * @access public
  5182.         * @since 1.0
  5183.         * @see SetY(), GetX(), SetX()
  5184.         */
  5185.         public function GetY({
  5186.             //Get y position
  5187.             return $this->y;
  5188.         }
  5189.         
  5190.         /**
  5191.         * Defines the abscissa of the current position.
  5192.         * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  5193.         * @param float $x The value of the abscissa.
  5194.         * @access public
  5195.         * @since 1.2
  5196.         * @see GetX(), GetY(), SetY(), SetXY()
  5197.         */
  5198.         public function SetX($x{
  5199.             //Set x position
  5200.             if ($this->rtl{
  5201.                 if ($x >= 0{
  5202.                     $this->x = $this->w - $x;
  5203.                 else {
  5204.                     $this->x = abs($x);
  5205.                 }
  5206.             else {
  5207.                 if ($x >= 0{
  5208.                     $this->x = $x;
  5209.                 else {
  5210.                     $this->x = $this->w + $x;
  5211.                 }
  5212.             }
  5213.             if ($this->x < 0{
  5214.                 $this->x = 0;
  5215.             }
  5216.             if ($this->x > $this->w{
  5217.                 $this->x = $this->w;
  5218.             }
  5219.         }
  5220.         
  5221.         /**
  5222.         * Moves the current abscissa back to the left margin and sets the ordinate.
  5223.         * If the passed value is negative, it is relative to the bottom of the page.
  5224.         * @param float $y The value of the ordinate.
  5225.         * @param bool $resetx if true (default) reset the X position.
  5226.         * @access public
  5227.         * @since 1.0
  5228.         * @see GetX(), GetY(), SetY(), SetXY()
  5229.         */
  5230.         public function SetY($y$resetx=true{
  5231.             if ($resetx{
  5232.                 //reset x
  5233.                 if ($this->rtl{
  5234.                     $this->x = $this->w - $this->rMargin;
  5235.                 else {
  5236.                     $this->x = $this->lMargin;
  5237.                 }
  5238.             }
  5239.             if ($y >= 0{
  5240.                 $this->y = $y;
  5241.             else {
  5242.                 $this->y = $this->h + $y;
  5243.             }
  5244.             if ($this->y < 0{
  5245.                 $this->y = 0;
  5246.             }
  5247.             if ($this->y > $this->h{
  5248.                 $this->y = $this->h;
  5249.             }
  5250.         }
  5251.         
  5252.         /**
  5253.         * Defines the abscissa and ordinate of the current position.
  5254.         * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  5255.         * @param float $x The value of the abscissa
  5256.         * @param float $y The value of the ordinate
  5257.         * @access public
  5258.         * @since 1.2
  5259.         * @see SetX(), SetY()
  5260.         */
  5261.         public function SetXY($x$y{
  5262.             //Set x and y positions
  5263.             $this->SetY($y);
  5264.             $this->SetX($x);
  5265.         }
  5266.  
  5267.         /**
  5268.         * Send the document to a given destination: string, local file or browser.
  5269.         * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  5270.         * The method first calls Close() if necessary to terminate the document.
  5271.         * @param string $name The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  5272.         * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li></ul>
  5273.         * @access public
  5274.         * @since 1.0
  5275.         * @see Close()
  5276.         */
  5277.         public function Output($name='doc.pdf'$dest='I'{
  5278.             //Output PDF to some destination
  5279.             //Finish document if necessary
  5280.             if ($this->state < 3{
  5281.                 $this->Close();
  5282.             }
  5283.             //Normalize parameters
  5284.             if (is_bool($dest)) {
  5285.                 $dest $dest 'D' 'F';
  5286.             }
  5287.             $dest strtoupper($dest);
  5288.             if ($dest != 'F'{
  5289.                 $name preg_replace('/[\s]+/''_'$name);
  5290.                 $name preg_replace('/[^a-zA-Z0-9_\.-]/'''$name);
  5291.             }
  5292.             if ($this->sign{
  5293.                 // *** apply digital signature to the document ***
  5294.                 // get the document content
  5295.                 $pdfdoc $this->getBuffer();
  5296.                 // remove last newline
  5297.                 $pdfdoc substr($pdfdoc0-1);
  5298.                 // Remove the original buffer
  5299.                 if (isset($this->diskcacheAND $this->diskcache{
  5300.                     // remove buffer file from cache
  5301.                     unlink($this->buffer);
  5302.                 }
  5303.                 unset($this->buffer);
  5304.                 // remove filler space
  5305.                 $byterange_string_len strlen($this->byterange_string);
  5306.                 // define the ByteRange
  5307.                 $byte_range array();
  5308.                 $byte_range[00;
  5309.                 $byte_range[1strpos($pdfdoc$this->byterange_string$byterange_string_len 10;
  5310.                 $byte_range[2$byte_range[1$this->signature_max_lenght + 2;
  5311.                 $byte_range[3strlen($pdfdoc$byte_range[2];
  5312.                 $pdfdoc substr($pdfdoc0$byte_range[1]).substr($pdfdoc$byte_range[2]);
  5313.                 // replace the ByteRange
  5314.                 $byterange sprintf('/ByteRange[0 %u %u %u]'$byte_range[1]$byte_range[2]$byte_range[3]);
  5315.                 $byterange .= str_repeat(' '($byterange_string_len strlen($byterange)));
  5316.                 $pdfdoc str_replace($this->byterange_string$byterange$pdfdoc);
  5317.                 // write the document to a temporary folder
  5318.                 $tempdoc tempnam(K_PATH_CACHE'tmppdf_');
  5319.                 $f fopen($tempdoc'wb');
  5320.                 if (!$f{
  5321.                     $this->Error('Unable to create temporary file: '.$tempdoc);
  5322.                 }
  5323.                 $pdfdoc_lenght strlen($pdfdoc);
  5324.                 fwrite($f$pdfdoc$pdfdoc_lenght);
  5325.                 fclose($f);
  5326.                 // get digital signature via openssl library
  5327.                 $tempsign tempnam(K_PATH_CACHE'tmpsig_');
  5328.                 if (empty($this->signature_data['extracerts'])) {
  5329.                     openssl_pkcs7_sign($tempdoc$tempsign$this->signature_data['signcert']array($this->signature_data['privkey']$this->signature_data['password'])array()PKCS7_BINARY PKCS7_DETACHED);
  5330.                 else {
  5331.                     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']);
  5332.                 }    
  5333.                 unlink($tempdoc);
  5334.                 // read signature
  5335.                 $signature file_get_contents($tempsignfalsenull$pdfdoc_lenght);
  5336.                 unlink($tempsign);
  5337.                 // extract signature
  5338.                 $signature substr($signature(strpos($signature"%%EOF\n\n------"13));
  5339.                 $tmparr explode("\n\n"$signature);
  5340.                 $signature $tmparr[1];
  5341.                 unset($tmparr);
  5342.                 // decode signature
  5343.                 $signature base64_decode(trim($signature));
  5344.                 // convert signature to hex
  5345.                 $signature current(unpack('H*'$signature));
  5346.                 $signature str_pad($signature$this->signature_max_lenght'0');
  5347.                 // Add signature to the document
  5348.                 $pdfdoc substr($pdfdoc0$byte_range[1]).'<'.$signature.'>'.substr($pdfdoc($byte_range[1]));
  5349.                 $this->diskcache = false;
  5350.                 $this->buffer = &$pdfdoc;
  5351.                 $this->bufferlen = strlen($pdfdoc);
  5352.             }
  5353.             switch($dest{
  5354.                 case 'I'{
  5355.                     // Send PDF to the standard output
  5356.                     if (ob_get_contents()) {
  5357.                         $this->Error('Some data has already been output, can\'t send PDF file');
  5358.                     }
  5359.                     if (php_sapi_name(!= 'cli'{
  5360.                         //We send to a browser
  5361.                         header('Content-Type: application/pdf');
  5362.                         if (headers_sent()) {
  5363.                             $this->Error('Some data has already been output to browser, can\'t send PDF file');
  5364.                         }
  5365.                         header('Cache-Control: public, must-revalidate, max-age=0')// HTTP/1.1
  5366.                         header('Pragma: public');
  5367.                         header('Expires: Sat, 26 Jul 1997 05:00:00 GMT')// Date in the past
  5368.                         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');    
  5369.                         header('Content-Length: '.$this->bufferlen);
  5370.                         header('Content-Disposition: inline; filename="'.basename($name).'";');
  5371.                     }
  5372.                     echo $this->getBuffer();
  5373.                     break;
  5374.                 }
  5375.                 case 'D'{
  5376.                     // Download PDF as file
  5377.                     if (ob_get_contents()) {
  5378.                         $this->Error('Some data has already been output, can\'t send PDF file');
  5379.                     }
  5380.                     header('Content-Description: File Transfer');
  5381.                     if (headers_sent()) {
  5382.                         $this->Error('Some data has already been output to browser, can\'t send PDF file');
  5383.                     }
  5384.                     header('Cache-Control: public, must-revalidate, max-age=0')// HTTP/1.1
  5385.                     header('Pragma: public');
  5386.                     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT')// Date in the past
  5387.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  5388.                     // force download dialog
  5389.                     header('Content-Type: application/force-download');
  5390.                     header('Content-Type: application/octet-stream'false);
  5391.                     header('Content-Type: application/download'false);
  5392.                     header('Content-Type: application/pdf'false);
  5393.                     // use the Content-Disposition header to supply a recommended filename
  5394.                     header('Content-Disposition: attachment; filename="'.basename($name).'";');
  5395.                     header('Content-Transfer-Encoding: binary');
  5396.                     header('Content-Length: '.$this->bufferlen);
  5397.                     echo $this->getBuffer();
  5398.                     break;
  5399.                 }
  5400.                 case 'F'{
  5401.                     // Save PDF to a local file
  5402.                     if ($this->diskcache{
  5403.                         copy($this->buffer$name);
  5404.                     else {
  5405.                         $f fopen($name'wb');
  5406.                         if (!$f{
  5407.                             $this->Error('Unable to create output file: '.$name);
  5408.                         }
  5409.                         fwrite($f$this->getBuffer()$this->bufferlen);
  5410.                         fclose($f);
  5411.                     }
  5412.                     break;
  5413.                 }
  5414.                 case 'S'{
  5415.                     // Returns PDF as a string
  5416.                     return $this->getBuffer();
  5417.                 }
  5418.                 default{
  5419.                     $this->Error('Incorrect output destination: '.$dest);
  5420.                 }
  5421.             }
  5422.             return '';
  5423.         }
  5424.  
  5425.         /**
  5426.          * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  5427.          * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  5428.          * @param boolean $preserve_objcopy if true preserves the objcopy variable
  5429.          * @access public
  5430.          * @since 4.5.016 (2009-02-24)
  5431.          */
  5432.         public function _destroy($destroyall=false$preserve_objcopy=false{
  5433.             if ($destroyall AND isset($this->diskcacheAND $this->diskcache AND (!$preserve_objcopyAND (!$this->empty_string($this->buffer))) {
  5434.                 // remove buffer file from cache
  5435.                 unlink($this->buffer);
  5436.             }
  5437.             foreach (array_keys(get_object_vars($this)) as $val{
  5438.                 if ($destroyall OR (
  5439.                     ($val != 'internal_encoding'
  5440.                     AND ($val != 'state'
  5441.                     AND ($val != 'bufferlen'
  5442.                     AND ($val != 'buffer'
  5443.                     AND ($val != 'diskcache')
  5444.                     AND ($val != 'sign')
  5445.                     AND ($val != 'signature_data')
  5446.                     AND ($val != 'signature_max_lenght')
  5447.                     AND ($val != 'byterange_string')
  5448.                     )) {
  5449.                     if (!$preserve_objcopy OR ($val != 'objcopy')) {
  5450.                         unset($this->$val);
  5451.                     }
  5452.                 }
  5453.             }
  5454.         }
  5455.         
  5456.         /**
  5457.         * Check for locale-related bug
  5458.         * @access protected
  5459.         */
  5460.         protected function _dochecks({
  5461.             //Check for locale-related bug
  5462.             if (1.1 == 1{
  5463.                 $this->Error('Don\'t alter the locale before including class file');
  5464.             }
  5465.             //Check for decimal separator
  5466.             if (sprintf('%.1F'1.0!= '1.0'{
  5467.                 setlocale(LC_NUMERIC'C');
  5468.             }
  5469.         }
  5470.  
  5471.         /**
  5472.         * Return fonts path
  5473.         * @return string 
  5474.         * @access protected
  5475.         */
  5476.         protected function _getfontpath({
  5477.             if (!defined('K_PATH_FONTS'AND is_dir(dirname(__FILE__).'/fonts')) {
  5478.                 define('K_PATH_FONTS'dirname(__FILE__).'/fonts/');
  5479.             }
  5480.             return defined('K_PATH_FONTS'K_PATH_FONTS '';
  5481.         }
  5482.         
  5483.         /**
  5484.         * Output pages.
  5485.         * @access protected
  5486.         */
  5487.         protected function _putpages({
  5488.             $nb $this->numpages;
  5489.             if (!empty($this->AliasNbPages)) {
  5490.                 $nbs $this->formatPageNumber($nb);
  5491.                 $nbu $this->UTF8ToUTF16BE($nbsfalse)// replacement for unicode font
  5492.                 $alias_a $this->_escape($this->AliasNbPages);
  5493.                 $alias_au $this->_escape('{'.$this->AliasNbPages.'}');
  5494.                 if ($this->isunicode{
  5495.                     $alias_b $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  5496.                     $alias_bu $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages.'}'));
  5497.                     $alias_c $this->_escape($this->utf8StrRev($this->AliasNbPagesfalse$this->tmprtl));
  5498.                     $alias_cu $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}'false$this->tmprtl));
  5499.                 }
  5500.             }
  5501.             if (!empty($this->AliasNumPage)) {
  5502.                 $alias_pa $this->_escape($this->AliasNumPage);
  5503.                 $alias_pau $this->_escape('{'.$this->AliasNumPage.'}');
  5504.                 if ($this->isunicode{
  5505.                     $alias_pb $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  5506.                     $alias_pbu $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage.'}'));
  5507.                     $alias_pc $this->_escape($this->utf8StrRev($this->AliasNumPagefalse$this->tmprtl));
  5508.                     $alias_pcu $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}'false$this->tmprtl));
  5509.                 }
  5510.             }
  5511.             $pagegroupnum 0;
  5512.             $filter ($this->compress'/Filter /FlateDecode ' '';
  5513.             for ($n=1$n <= $nb++$n{
  5514.                 $temppage $this->getPageBuffer($n);
  5515.                 if (!empty($this->pagegroups)) {
  5516.                     if(isset($this->newpagegroup[$n])) {
  5517.                         $pagegroupnum 0;
  5518.                     }
  5519.                     ++$pagegroupnum;
  5520.                     foreach ($this->pagegroups as $k => $v{
  5521.                         // replace total pages group numbers
  5522.                         $vs $this->formatPageNumber($v);
  5523.                         $vu $this->UTF8ToUTF16BE($vsfalse);
  5524.                         $alias_ga $this->_escape($k);
  5525.                         $alias_gau $this->_escape('{'.$k.'}');
  5526.                         if ($this->isunicode{
  5527.                             $alias_gb $this->_escape($this->UTF8ToLatin1($k));
  5528.                             $alias_gbu $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
  5529.                             $alias_gc $this->_escape($this->utf8StrRev($kfalse$this->tmprtl));
  5530.                             $alias_gcu $this->_escape($this->utf8StrRev('{'.$k.'}'false$this->tmprtl));
  5531.                         }
  5532.                         $temppage str_replace($alias_gau$vu$temppage);
  5533.                         if ($this->isunicode{
  5534.                             $temppage str_replace($alias_gbu$vu$temppage);
  5535.                             $temppage str_replace($alias_gcu$vu$temppage);
  5536.                             $temppage str_replace($alias_gb$vs$temppage);
  5537.                             $temppage str_replace($alias_gc$vs$temppage);
  5538.                         }
  5539.                         $temppage str_replace($alias_ga$vs$temppage);
  5540.                         // replace page group numbers
  5541.                         $pvs $this->formatPageNumber($pagegroupnum);
  5542.                         $pvu $this->UTF8ToUTF16BE($pvsfalse);
  5543.                         $pk str_replace('{nb''{pnb'$k);
  5544.                         $alias_pga $this->_escape($pk);
  5545.                         $alias_pgau $this->_escape('{'.$pk.'}');
  5546.                         if ($this->isunicode{
  5547.                             $alias_pgb $this->_escape($this->UTF8ToLatin1($pk));
  5548.                             $alias_pgbu $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
  5549.                             $alias_pgc $this->_escape($this->utf8StrRev($pkfalse$this->tmprtl));
  5550.                             $alias_pgcu $this->_escape($this->utf8StrRev('{'.$pk.'}'false$this->tmprtl));
  5551.                         }
  5552.                         $temppage str_replace($alias_pgau$pvu$temppage);
  5553.                         if ($this->isunicode{
  5554.                             $temppage str_replace($alias_pgbu$pvu$temppage);
  5555.                             $temppage str_replace($alias_pgcu$pvu$temppage);
  5556.                             $temppage str_replace($alias_pgb$pvs$temppage);
  5557.                             $temppage str_replace($alias_pgc$pvs$temppage);
  5558.                         }
  5559.                         $temppage str_replace($alias_pga$pvs$temppage);
  5560.                     }
  5561.                 }
  5562.                 if (!empty($this->AliasNbPages)) {
  5563.                     // replace total pages number
  5564.                     $temppage str_replace($alias_au$nbu$temppage);
  5565.                     if ($this->isunicode{
  5566.                         $temppage str_replace($alias_bu$nbu$temppage);
  5567.                         $temppage str_replace($alias_cu$nbu$temppage);
  5568.                         $temppage str_replace($alias_b$nbs$temppage);
  5569.                         $temppage str_replace($alias_c$nbs$temppage);
  5570.                     }
  5571.                     $temppage str_replace($alias_a$nbs$temppage);
  5572.                 }
  5573.                 if (!empty($this->AliasNumPage)) {
  5574.                     // replace page number
  5575.                     $pnbs $this->formatPageNumber($n);
  5576.                     $pnbu $this->UTF8ToUTF16BE($pnbsfalse)// replacement for unicode font
  5577.                     $temppage str_replace($alias_pau$pnbu$temppage);
  5578.                     if ($this->isunicode{
  5579.                         $temppage str_replace($alias_pbu$pnbu$temppage);
  5580.                         $temppage str_replace($alias_pcu$pnbu$temppage);
  5581.                         $temppage str_replace($alias_pb$pnbs$temppage);
  5582.                         $temppage str_replace($alias_pc$pnbs$temppage);
  5583.                     }
  5584.                     $temppage str_replace($alias_pa$pnbs$temppage);
  5585.                 }
  5586.                 $temppage str_replace($this->epsmarker''$temppage);
  5587.                 //Page
  5588.                 $this->page_obj_id[$n$this->_newobj();
  5589.                 $this->_out('<</Type /Page');
  5590.                 $this->_out('/Parent 1 0 R');
  5591.                 $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]'$this->pagedim[$n]['w']$this->pagedim[$n]['h']));
  5592.                 $this->_out('/Resources 2 0 R');
  5593.                 $this->_putannotsrefs($n);
  5594.                 $this->_out('/Contents '.($this->n + 1).' 0 R>>');
  5595.                 $this->_out('endobj');
  5596.                 //Page content
  5597.                 $p ($this->compressgzcompress($temppage$temppage;
  5598.                 $this->_newobj();
  5599.                 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  5600.                 $this->_putstream($p);
  5601.                 $this->_out('endobj');
  5602.                 if ($this->diskcache{
  5603.                     // remove temporary files
  5604.                     unlink($this->pages[$n]);
  5605.                 }
  5606.             }
  5607.             //Pages root
  5608.             $this->offsets[1$this->bufferlen;
  5609.             $this->_out('1 0 obj');
  5610.             $this->_out('<</Type /Pages');
  5611.             $this->_out('/Kids [');
  5612.             foreach($this->page_obj_id as $page_obj{
  5613.                 $this->_out($page_obj.' 0 R');
  5614.             }
  5615.             $this->_out(']');
  5616.             $this->_out('/Count '.$nb);
  5617.             $this->_out('>>');
  5618.             $this->_out('endobj');
  5619.         }
  5620.  
  5621.         /**
  5622.         * Output referencees to page annotations
  5623.         * @param int $n page number
  5624.         * @access protected
  5625.         * @author Nicola Asuni
  5626.         * @since 4.7.000 (2008-08-29)
  5627.         */
  5628.         protected function _putannotsrefs($n{
  5629.             if (!(isset($this->PageAnnots[$n]OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  5630.                 return;
  5631.             }
  5632.             $this->_out('/Annots [');
  5633.             if (isset($this->PageAnnots[$n])) {
  5634.                 $num_annots count($this->PageAnnots[$n]);
  5635.                 for ($i 0$i $num_annots++$i{
  5636.                     ++$this->curr_annot_obj_id;
  5637.                     if (!in_array($this->curr_annot_obj_id$this->radio_groups)) {
  5638.                         $this->_out($this->curr_annot_obj_id.' 0 R');
  5639.                     else {
  5640.                         ++$num_annots;
  5641.                     }
  5642.                 }
  5643.             }
  5644.             if (($n==1AND $this->sign AND isset($this->signature_data['cert_type'])) {
  5645.                 // set reference for signature object
  5646.                 $this->_out($this->sig_annot_ref);
  5647.             }
  5648.             $this->_out(']');
  5649.         }
  5650.  
  5651.         /**
  5652.         * Output annotations objects for all pages.
  5653.         * !!! THIS FUNCTION IS NOT YET COMPLETED !!!
  5654.         * See section 12.5 of PDF 32000_2008 reference.
  5655.         * @access protected
  5656.         * @author Nicola Asuni
  5657.         * @since 4.0.018 (2008-08-06)
  5658.         */
  5659.         protected function _putannotsobjs({
  5660.             // reset object counter
  5661.             $this->annot_obj_id = $this->annots_start_obj_id;
  5662.             for ($n=1$n <= $this->numpages++$n{
  5663.                 if (isset($this->PageAnnots[$n])) {
  5664.                     // set page annotations
  5665.                     foreach ($this->PageAnnots[$nas $key => $pl{
  5666.                         // create annotation object for grouping radiobuttons
  5667.                         if (isset($this->radiobutton_groups[$n][$pl['txt']]AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  5668.                             $annots '<<';
  5669.                             $annots .= ' /Type /Annot';
  5670.                             $annots .= ' /Subtype /Widget';
  5671.                             $annots .= ' /T '.$this->_datastring($pl['txt']);
  5672.                             $annots .= ' /FT /Btn';
  5673.                             $annots .= ' /Ff 49152';
  5674.                             $annots .= ' /Kids [';
  5675.                             foreach ($this->radiobutton_groups[$n][$pl['txt']] as $data{
  5676.                                 $annots .= ' '.$data['kid'].' 0 R';
  5677.                                 if ($data['def'!== 'Off'{
  5678.                                     $defval $data['def'];
  5679.                                 }
  5680.                             }
  5681.                             $annots .= ' ]';
  5682.                             if (isset($defval)) {
  5683.                                 $annots .= ' /V /'.$defval;
  5684.                             }
  5685.                             $annots .= ' >>';
  5686.                             ++$this->annot_obj_id;
  5687.                             $this->offsets[$this->annot_obj_id$this->bufferlen;
  5688.                             $this->_out($this->annot_obj_id.' 0 obj');
  5689.                             $this->_out($annots);
  5690.                             $this->_out('endobj');
  5691.                             $this->form_obj_id[$this->annot_obj_id;
  5692.                             // store object id to be used on Parent entry of Kids
  5693.                             $this->radiobutton_groups[$n][$pl['txt']] $this->annot_obj_id;
  5694.                         }
  5695.                         $formfield false;
  5696.                         $pl['opt'array_change_key_case($pl['opt']CASE_LOWER);
  5697.                         $a $pl['x'$this->k;
  5698.                         $b $this->pagedim[$n]['h'(($pl['y'$pl['h'])  $this->k);
  5699.                         $c $pl['w'$this->k;
  5700.                         $d $pl['h'$this->k;
  5701.                         $rect sprintf('%.2F %.2F %.2F %.2F'$a$b$a+$c$b+$d);
  5702.                         // create new annotation object
  5703.                         $annots '<</Type /Annot';
  5704.                         $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  5705.                         $annots .= ' /Rect ['.$rect.']';
  5706.                         $ft array('Btn''Tx''Ch''Sig');
  5707.                         if (isset($pl['opt']['ft']AND in_array($pl['opt']['ft']$ft)) {
  5708.                             $annots .= ' /FT /'.$pl['opt']['ft'];
  5709.                             $formfield true;
  5710.                         }
  5711.                         $annots .= ' /Contents '.$this->_textstring($pl['txt']);
  5712.                         $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  5713.                         $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u'$n$key));
  5714.                         $annots .= ' /M '.$this->_datestring();
  5715.                         if (isset($pl['opt']['f'])) {
  5716.                             $val 0;
  5717.                             if (is_array($pl['opt']['f'])) {
  5718.                                 foreach ($pl['opt']['f'as $f{
  5719.                                     switch (strtolower($f)) {
  5720.                                         case 'invisible'{
  5721.                                             $val += << 0;
  5722.                                             break;
  5723.                                         }
  5724.                                         case 'hidden'{
  5725.                                             $val += << 1;
  5726.                                             break;
  5727.                                         }
  5728.                                         case 'print'{
  5729.                                             $val += << 2;
  5730.                                             break;
  5731.                                         }
  5732.                                         case 'nozoom'{
  5733.                                             $val += << 3;
  5734.                                             break;
  5735.                                         }
  5736.                                         case 'norotate'{
  5737.                                             $val += << 4;
  5738.                                             break;
  5739.                                         }
  5740.                                         case 'noview'{
  5741.                                             $val += << 5;
  5742.                                             break;
  5743.                                         }
  5744.                                         case 'readonly'{
  5745.                                             $val += << 6;
  5746.                                             break;
  5747.                                         }
  5748.                                         case 'locked'{
  5749.                                             $val += << 8;
  5750.                                             break;
  5751.                                         }
  5752.                                         case 'togglenoview'{
  5753.                                             $val += << 9;
  5754.                                             break;
  5755.                                         }
  5756.                                         case 'lockedcontents'{
  5757.                                             $val += << 10;
  5758.                                             break;
  5759.                                         }
  5760.                                         default{
  5761.                                             break;
  5762.                                         }
  5763.                                     }
  5764.                                 }
  5765.                             else {
  5766.                                 $val intval($pl['opt']['f']);
  5767.                             }
  5768.                             $annots .= ' /F '.intval($val);
  5769.                         }
  5770.                         if (isset($pl['opt']['as']AND is_string($pl['opt']['as'])) {
  5771.                             $annots .= ' /AS /'.$pl['opt']['as'];
  5772.                         }
  5773.                         if (isset($pl['opt']['ap'])) {
  5774.                             // appearance stream
  5775.                             $annots .= ' /AP <<';
  5776.                             if (is_array($pl['opt']['ap'])) {
  5777.                                 foreach ($pl['opt']['ap'as $apmode => $apdef{
  5778.                                     // $apmode can be: n = normal; r = rollover; d = down;
  5779.                                     $annots .= ' /'.strtoupper($apmode);
  5780.                                     if (is_array($apdef)) {
  5781.                                         $annots .= ' <<';
  5782.                                         foreach ($apdef as $apstate => $stream{
  5783.                                             // reference to XObject that define the appearance for this mode-state
  5784.                                             $apsobjid $this->_putAPXObject($c$d$stream);
  5785.                                             $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  5786.                                         }
  5787.                                         $annots .= ' >>';
  5788.                                     else {
  5789.                                         // reference to XObject that define the appearance for this mode
  5790.                                         $apsobjid $this->_putAPXObject($c$d$apdef);
  5791.                                         $annots .= ' '.$apsobjid.' 0 R';
  5792.                                     }
  5793.                                 }
  5794.                             else {
  5795.                                 $annots .= $pl['opt']['ap'];
  5796.                             }
  5797.                             $annots .= ' >>';
  5798.                         }
  5799.                         if (isset($pl['opt']['bs']AND (is_array($pl['opt']['bs']))) {
  5800.                             $annots .= ' /BS <<';
  5801.                             $annots .= ' /Type /Border';
  5802.                             if (isset($pl['opt']['bs']['w'])) {
  5803.                                 $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  5804.                             }
  5805.                             $bstyles array('S''D''B''I''U');
  5806.                             if (isset($pl['opt']['bs']['s']AND in_array($pl['opt']['bs']['s']$bstyles)) {
  5807.                                 $annots .= ' /S /'.$pl['opt']['bs']['s'];
  5808.                             }
  5809.                             if (isset($pl['opt']['bs']['d']AND (is_array($pl['opt']['bs']['d']))) {
  5810.                                 $annots .= ' /D [';
  5811.                                 foreach ($pl['opt']['bs']['d'as $cord{
  5812.                                     $annots .= ' '.intval($cord);
  5813.                                 }
  5814.                                 $annots .= ']';
  5815.                             }
  5816.                             $annots .= ' >>';
  5817.                         else {
  5818.                             $annots .= ' /Border [';
  5819.                             if (isset($pl['opt']['border']AND (count($pl['opt']['border']>= 3)) {
  5820.                                 $annots .= intval($pl['opt']['border'][0]).' ';
  5821.                                 $annots .= intval($pl['opt']['border'][1]).' ';
  5822.                                 $annots .= intval($pl['opt']['border'][2]);
  5823.                                 if (isset($pl['opt']['border'][3]AND is_array($pl['opt']['border'][3])) {
  5824.                                     $annots .= ' [';
  5825.                                     foreach ($pl['opt']['border'][3as $dash{
  5826.                                         $annots .= intval($dash).' ';
  5827.                                     }
  5828.                                     $annots .= ']';
  5829.                                 }
  5830.                             else {
  5831.                                 $annots .= '0 0 0';
  5832.                             }
  5833.                             $annots .= ']';
  5834.                         }
  5835.                         if (isset($pl['opt']['be']AND (is_array($pl['opt']['be']))) {
  5836.                             $annots .= ' /BE <<';
  5837.                             $bstyles array('S''C');
  5838.                             if (isset($pl['opt']['be']['s']AND in_array($pl['opt']['be']['s']$markups)) {
  5839.                                 $annots .= ' /S /'.$pl['opt']['bs']['s'];
  5840.                             else {
  5841.                                 $annots .= ' /S /S';
  5842.                             }
  5843.                             if (isset($pl['opt']['be']['i']AND ($pl['opt']['be']['i'>= 0AND ($pl['opt']['be']['i'<= 2)) {
  5844.                                 $annots .= ' /I '.sprintf(" %.4F"$pl['opt']['be']['i']);
  5845.                             }
  5846.                             $annots .= '>>';
  5847.                         }
  5848.                         if (isset($pl['opt']['c']AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  5849.                             $annots .= ' /C [';
  5850.                             foreach ($pl['opt']['c'as $col{
  5851.                                 $col intval($col);
  5852.                                 $color $col <= ($col >= 255 $col 255);
  5853.                                 $annots .= sprintf(" %.4F"$color);
  5854.                             }
  5855.                             $annots .= ']';
  5856.                         }
  5857.                         //$annots .= ' /StructParent ';
  5858.                         //$annots .= ' /OC ';
  5859.                         $markups array('text''freetext''line''square''circle''polygon''polyline''highlight',  'underline''squiggly''strikeout''stamp''caret''ink''fileattachment''sound');
  5860.                         if (in_array(strtolower($pl['opt']['subtype'])$markups)) {
  5861.                             // this is a markup type
  5862.                             if (isset($pl['opt']['t']AND is_string($pl['opt']['t'])) {
  5863.                                 $annots .= ' /T '.$this->_textstring($pl['opt']['t']);
  5864.                             }
  5865.                             //$annots .= ' /Popup ';
  5866.                             if (isset($pl['opt']['ca'])) {
  5867.                                 $annots .= ' /CA '.sprintf("%.4F"floatval($pl['opt']['ca']));
  5868.                             }
  5869.                             if (isset($pl['opt']['rc'])) {
  5870.                                 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc']);
  5871.                             }
  5872.                             $annots .= ' /CreationDate '.$this->_datestring();
  5873.                             //$annots .= ' /IRT ';
  5874.                             if (isset($pl['opt']['subj'])) {
  5875.                                 $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj']);
  5876.                             }
  5877.                             //$annots .= ' /RT ';
  5878.                             //$annots .= ' /IT ';
  5879.                             //$annots .= ' /ExData ';
  5880.                         }
  5881.                         $lineendings array('Square''Circle''Diamond''OpenArrow''ClosedArrow''None''Butt''ROpenArrow''RClosedArrow''Slash');
  5882.                         switch (strtolower($pl['opt']['subtype'])) {
  5883.                             case 'text'{
  5884.                                 if (isset($pl['opt']['open'])) {
  5885.                                     $annots .= ' /Open '(strtolower($pl['opt']['open']== 'true' 'true' 'false');
  5886.                                 }
  5887.                                 $iconsapp array('Comment''Help''Insert''Key''NewParagraph''Note''Paragraph');
  5888.                                 if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  5889.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  5890.                                 else {
  5891.                                     $annots .= ' /Name /Note';
  5892.                                 }
  5893.                                 $statemodels array('Marked''Review');
  5894.                                 if (isset($pl['opt']['statemodel']AND in_array($pl['opt']['statemodel']$statemodels)) {
  5895.                                     $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  5896.                                 else {
  5897.                                     $pl['opt']['statemodel''Marked';
  5898.                                     $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  5899.                                 }
  5900.                                 if ($pl['opt']['statemodel'== 'Marked'{
  5901.                                     $states array('Accepted''Unmarked');
  5902.                                 else {
  5903.                                     $states array('Accepted''Rejected''Cancelled''Completed''None');
  5904.                                 }
  5905.                                 if (isset($pl['opt']['state']AND in_array($pl['opt']['state']$states)) {
  5906.                                     $annots .= ' /State /'.$pl['opt']['state'];
  5907.                                 else {
  5908.                                     if ($pl['opt']['statemodel'== 'Marked'{
  5909.                                         $annots .= ' /State /Unmarked';
  5910.                                     else {
  5911.                                         $annots .= ' /State /None';
  5912.                                     }
  5913.                                 }
  5914.                                 break;
  5915.                             }
  5916.                             case 'link'{
  5917.                                 if(is_string($pl['txt'])) {
  5918.                                     // external URI link
  5919.                                     $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt'])).'>>';
  5920.                                 else {
  5921.                                     // internal link
  5922.                                     $l $this->links[$pl['txt']];
  5923.                                     $annots .= sprintf(' /Dest [%d 0 R /XYZ 0 %.2F null]'(($l[0]))($this->pagedim[$l[0]]['h'($l[1$this->k)));
  5924.                                 }
  5925.                                 $hmodes array('N''I''O''P');
  5926.                                 if (isset($pl['opt']['h']AND in_array($pl['opt']['h']$hmodes)) {
  5927.                                     $annots .= ' /H /'.$pl['opt']['h'];
  5928.                                 else {
  5929.                                     $annots .= ' /H /I';
  5930.                                 }
  5931.                                 //$annots .= ' /PA ';
  5932.                                 //$annots .= ' /Quadpoints ';
  5933.                                 break;
  5934.                             }
  5935.                             case 'freetext'{
  5936.                                 if (isset($pl['opt']['da']AND !empty($pl['opt']['da'])) {
  5937.                                     $annots .= ' /DA ('.$pl['opt']['da'].')';
  5938.                                 }
  5939.                                 if (isset($pl['opt']['q']AND ($pl['opt']['q'>= 0AND ($pl['opt']['q'<= 2)) {
  5940.                                     $annots .= ' /Q '.intval($pl['opt']['q']);
  5941.                                 }
  5942.                                 if (isset($pl['opt']['rc'])) {
  5943.                                     $annots .= ' /RC '.$this->_textstring($pl['opt']['rc']);
  5944.                                 }
  5945.                                 if (isset($pl['opt']['ds'])) {
  5946.                                     $annots .= ' /DS '.$this->_textstring($pl['opt']['ds']);
  5947.                                 }
  5948.                                 if (isset($pl['opt']['cl']AND is_array($pl['opt']['cl'])) {
  5949.                                     $annots .= ' /CL [';
  5950.                                     foreach ($pl['opt']['cl'as $cl{
  5951.                                         $annots .= sprintf("%.4F "$cl $this->k);
  5952.                                     }
  5953.                                     $annots .= ']';
  5954.                                 }
  5955.                                 $tfit array('FreeText''FreeTextCallout''FreeTextTypeWriter');
  5956.                                 if (isset($pl['opt']['it']AND in_array($pl['opt']['it']$tfit)) {
  5957.                                     $annots .= ' /IT '.$pl['opt']['it'];
  5958.                                 }
  5959.                                 if (isset($pl['opt']['rd']AND is_array($pl['opt']['rd'])) {
  5960.                                     $l $pl['opt']['rd'][0$this->k;
  5961.                                     $r $pl['opt']['rd'][1$this->k;
  5962.                                     $t $pl['opt']['rd'][2$this->k;
  5963.                                     $b $pl['opt']['rd'][3$this->k;
  5964.                                     $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F'$l$r$t$b).']';
  5965.                                 }
  5966.                                 if (isset($pl['opt']['le']AND in_array($pl['opt']['le']$lineendings)) {
  5967.                                     $annots .= ' /LE /'.$pl['opt']['le'];
  5968.                                 }
  5969.                                 break;
  5970.                             }
  5971.                             case 'line'{
  5972.                                 break;
  5973.                             }
  5974.                             case 'square'{
  5975.                                 break;
  5976.                             }
  5977.                             case 'circle'{
  5978.                                 break;
  5979.                             }
  5980.                             case 'polygon'{
  5981.                                 break;
  5982.                             }
  5983.                             case 'polyline'{
  5984.                                 break;
  5985.                             }
  5986.                             case 'highlight'{
  5987.                                 break;
  5988.                             }
  5989.                             case 'underline'{
  5990.                                 break;
  5991.                             }
  5992.                             case 'squiggly'{
  5993.                                 break;
  5994.                             }
  5995.                             case 'strikeout'{
  5996.                                 break;
  5997.                             }
  5998.                             case 'stamp'{
  5999.                                 break;
  6000.                             }
  6001.                             case 'caret'{
  6002.                                 break;
  6003.                             }
  6004.                             case 'ink'{
  6005.                                 break;
  6006.                             }
  6007.                             case 'popup'{
  6008.                                 break;
  6009.                             }
  6010.                             case 'fileattachment'{
  6011.                                 if (!isset($pl['opt']['fs'])) {
  6012.                                     break;
  6013.                                 }
  6014.                                 $filename basename($pl['opt']['fs']);
  6015.                                 if (isset($this->embeddedfiles[$filename]['n'])) {
  6016.                                     $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  6017.                                     $iconsapp array('Graph''Paperclip''PushPin''Tag');
  6018.                                     if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  6019.                                         $annots .= ' /Name /'.$pl['opt']['name'];
  6020.                                     else {
  6021.                                         $annots .= ' /Name /PushPin';
  6022.                                     }
  6023.                                 }
  6024.                                 break;
  6025.                             }
  6026.                             case 'sound'{
  6027.                                 if (!isset($pl['opt']['sound'])) {
  6028.                                     break;
  6029.                                 }
  6030.                                 $filename basename($pl['opt']['sound']);
  6031.                                 if (isset($this->embeddedfiles[$filename]['n'])) {
  6032.                                     $annots .= ' /Sound <</Type /Sound';
  6033.                                     // ... TO BE COMPLETED ...
  6034.                                     // /R /C /B /E /CO /CP
  6035.                                     // $annots .= ' /F '.$this->_datastring($filename).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  6036.                                     $iconsapp array('Speaker''Mic');
  6037.                                     if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  6038.                                         $annots .= ' /Name /'.$pl['opt']['name'];
  6039.                                     else {
  6040.                                         $annots .= ' /Name /Speaker';
  6041.                                     }
  6042.                                 }
  6043.                                 break;
  6044.                             }
  6045.                             case 'movie'{
  6046.                                 break;
  6047.                             }
  6048.                             case 'widget'{
  6049.                                 $hmode array('N''I''O''P''T');
  6050.                                 if (isset($pl['opt']['h']AND in_array($pl['opt']['h']$hmode)) {
  6051.                                     $annots .= ' /H /'.$pl['opt']['h'];
  6052.                                 }
  6053.                                  if (isset($pl['opt']['mk']AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  6054.                                      $annots .= ' /MK <<';
  6055.                                      if (isset($pl['opt']['mk']['r'])) {
  6056.                                          $annots .= ' /R '.$pl['opt']['mk']['r'];
  6057.                                      }
  6058.                                      if (isset($pl['opt']['mk']['bc']AND (is_array($pl['opt']['mk']['bc']))) {
  6059.                                          $annots .= ' /BC [';
  6060.                                          foreach($pl['opt']['mk']['bc'AS $col{
  6061.                                              $col intval($col);
  6062.                                             $color $col <= ($col >= 255 $col 255);
  6063.                                              $annots .= ' '.$color;
  6064.                                          }
  6065.                                          $annots .= ']';
  6066.                                      }
  6067.                                      if (isset($pl['opt']['mk']['bg']AND (is_array($pl['opt']['mk']['bg']))) {
  6068.                                          $annots .= ' /BG [';
  6069.                                          foreach($pl['opt']['mk']['bg'AS $col{
  6070.                                              $col intval($col);
  6071.                                             $color $col <= ($col >= 255 $col 255);
  6072.                                              $annots .= ' '.$color;
  6073.                                          }
  6074.                                          $annots .= ']';
  6075.                                      }
  6076.                                      if (isset($pl['opt']['mk']['ca'])) {
  6077.                                          $annots .= ' /CA '.$pl['opt']['mk']['ca'].'';
  6078.                                      }
  6079.                                      if (isset($pl['opt']['mk']['rc'])) {
  6080.                                          $annots .= ' /RC '.$pl['opt']['mk']['ca'].'';
  6081.                                      }
  6082.                                      if (isset($pl['opt']['mk']['ac'])) {
  6083.                                          $annots .= ' /AC '.$pl['opt']['mk']['ca'].'';
  6084.                                      }                                                                      
  6085.                                      if (isset($pl['opt']['mk']['i'])) {
  6086.                                          $info $this->getImageBuffer($pl['opt']['mk']['i']);
  6087.                                          if ($info !== false{
  6088.                                              $annots .= ' /I '.$info['n'].' 0 R';
  6089.                                          }
  6090.                                      }
  6091.                                      if (isset($pl['opt']['mk']['ri'])) {
  6092.                                          $info $this->getImageBuffer($pl['opt']['mk']['ri']);
  6093.                                          if ($info !== false{
  6094.                                              $annots .= ' /RI '.$info['n'].' 0 R';
  6095.                                          }
  6096.                                      }
  6097.                                      if (isset($pl['opt']['mk']['ix'])) {
  6098.                                          $info $this->getImageBuffer($pl['opt']['mk']['ix']);
  6099.                                          if ($info !== false{
  6100.                                              $annots .= ' /IX '.$info['n'].' 0 R';
  6101.                                          }
  6102.                                      }                                     
  6103.                                      if (isset($pl['opt']['mk']['if']AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  6104.                                          $annots .= ' /IF <<';
  6105.                                          $if_sw array('A''B''S''N');
  6106.                                         if (isset($pl['opt']['mk']['if']['sw']AND in_array($pl['opt']['mk']['if']['sw']$if_sw)) {
  6107.                                             $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  6108.                                         }
  6109.                                          $if_s array('A''P');
  6110.                                         if (isset($pl['opt']['mk']['if']['s']AND in_array($pl['opt']['mk']['if']['s']$if_s)) {
  6111.                                             $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  6112.                                         }
  6113.                                         if (isset($pl['opt']['mk']['if']['a']AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  6114.                                             $annots .= ' /A ['.$pl['opt']['mk']['if']['a'][0].' '.$pl['opt']['mk']['if']['a'][1].']';
  6115.                                         }
  6116.                                         if (isset($pl['opt']['mk']['if']['fb']AND ($pl['opt']['mk']['if']['fb'])) {
  6117.                                             $annots .= ' /FB true';
  6118.                                         }
  6119.                                          $annots .= '>>';
  6120.                                      }
  6121.                                      if (isset($pl['opt']['mk']['tp']AND ($pl['opt']['mk']['tp'>= 0AND ($pl['opt']['mk']['tp'<= 6)) {
  6122.                                          $annots .= ' /TP '.$pl['opt']['mk']['tp'];
  6123.                                      else {
  6124.                                          $annots .= ' /TP 0';
  6125.                                      }
  6126.                                      $annots .= '>>';
  6127.                                  // end MK
  6128.                                  // --- Entries for field dictionaries ---
  6129.                                  if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  6130.                                      // set parent
  6131.                                      $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  6132.                                  }
  6133.                                  if (isset($pl['opt']['t']AND is_string($pl['opt']['t'])) {
  6134.                                     $annots .= ' /T '.$this->_datastring($pl['opt']['t']);
  6135.                                 }
  6136.                                 if (isset($pl['opt']['tu']AND is_string($pl['opt']['tu'])) {
  6137.                                     $annots .= ' /TU '.$this->_datastring($pl['opt']['tu']);
  6138.                                 }
  6139.                                 if (isset($pl['opt']['tm']AND is_string($pl['opt']['tm'])) {
  6140.                                     $annots .= ' /TM '.$this->_datastring($pl['opt']['tm']);
  6141.                                 }
  6142.                                 if (isset($pl['opt']['ff'])) {
  6143.                                     if (is_array($pl['opt']['ff'])) {
  6144.                                         // array of bit settings
  6145.                                         $flag 0;
  6146.                                         foreach($pl['opt']['ff'as $val{
  6147.                                             $flag += << ($val 1);
  6148.                                         }
  6149.                                     else {
  6150.                                         $flag intval($pl['opt']['ff']);
  6151.                                     }
  6152.                                     $annots .= ' /Ff '.$flag;
  6153.                                 }
  6154.                                 if (isset($pl['opt']['maxlen'])) {
  6155.                                     $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  6156.                                 }
  6157.                                 if (isset($pl['opt']['v'])) {
  6158.                                     $annots .= ' /V';
  6159.                                     if (is_array($pl['opt']['v'])) {
  6160.                                         foreach ($pl['opt']['v'AS $optval{
  6161.                                             $annots .= ' '.$optval;
  6162.                                         }
  6163.                                     else {
  6164.                                         $annots .= ' '.$this->_textstring($pl['opt']['v']);
  6165.                                     }
  6166.                                 }
  6167.                                 if (isset($pl['opt']['dv']AND is_string($pl['opt']['dv'])) {
  6168.                                     $annots .= ' /DV';
  6169.                                     if (is_array($pl['opt']['dv'])) {
  6170.                                         foreach ($pl['opt']['dv'AS $optval{
  6171.                                             $annots .= ' '.$optval;
  6172.                                         }
  6173.                                     else {
  6174.                                         $annots .= ' '.$this->_textstring($pl['opt']['dv']);
  6175.                                     }
  6176.                                 }
  6177.                                 if (isset($pl['opt']['rv']AND is_string($pl['opt']['rv'])) {
  6178.                                     $annots .= ' /RV';
  6179.                                     if (is_array($pl['opt']['rv'])) {
  6180.                                         foreach ($pl['opt']['rv'AS $optval{
  6181.                                             $annots .= ' '.$optval;
  6182.                                         }
  6183.                                     else {
  6184.                                         $annots .= ' '.$this->_textstring($pl['opt']['rv']);
  6185.                                     }
  6186.                                 }
  6187.                                 if (isset($pl['opt']['a']AND !empty($pl['opt']['a'])) {
  6188.                                     $annots .= ' /A << '.$pl['opt']['a'].' >>';
  6189.                                 }
  6190.                                 if (isset($pl['opt']['aa']AND !empty($pl['opt']['aa'])) {
  6191.                                     $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  6192.                                 }
  6193.                                 if (isset($pl['opt']['da']AND !empty($pl['opt']['da'])) {
  6194.                                     $annots .= ' /DA ('.$pl['opt']['da'].')';
  6195.                                 }
  6196.                                 if (isset($pl['opt']['q']AND ($pl['opt']['q'>= 0AND ($pl['opt']['q'<= 2)) {
  6197.                                     $annots .= ' /Q '.intval($pl['opt']['q']);
  6198.                                 }
  6199.                                 if (isset($pl['opt']['opt']AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  6200.                                      $annots .= ' /Opt [';
  6201.                                      foreach($pl['opt']['opt'AS $copt{
  6202.                                          if (is_array($copt)) {
  6203.                                              $annots .= ' ['.$this->_textstring($copt[0]).' '.$this->_textstring($copt[1]).']';
  6204.                                          else {
  6205.                                              $annots .= ' '.$this->_textstring($copt);
  6206.                                          }
  6207.                                      }
  6208.                                      $annots .= ']';
  6209.                                  }
  6210.                                  if (isset($pl['opt']['ti'])) {
  6211.                                      $annots .= ' /TI '.intval($pl['opt']['ti']);
  6212.                                  }
  6213.                                  if (isset($pl['opt']['i']AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  6214.                                      $annots .= ' /I [';
  6215.                                      foreach($pl['opt']['i'AS $copt{
  6216.                                          $annots .= intval($copt).' ';
  6217.                                      }
  6218.                                      $annots .= ']';
  6219.                                  }
  6220.                                 break;
  6221.                             }
  6222.                             case 'screen'{
  6223.                                 break;
  6224.                             }
  6225.                             case 'printermark'{
  6226.                                 break;
  6227.                             }
  6228.                             case 'trapnet'{
  6229.                                 break;
  6230.                             }
  6231.                             case 'watermark'{
  6232.                                 break;
  6233.                             }
  6234.                             case '3d'{
  6235.                                 break;
  6236.                             }
  6237.                             default{
  6238.                                 break;
  6239.                             }
  6240.                         }
  6241.                         $annots .= '>>';
  6242.                         // create new annotation object
  6243.                         ++$this->annot_obj_id;
  6244.                         $this->offsets[$this->annot_obj_id$this->bufferlen;
  6245.                         $this->_out($this->annot_obj_id.' 0 obj');
  6246.                         $this->_out($annots);
  6247.                         $this->_out('endobj');
  6248.                         if ($formfield AND isset($this->radiobutton_groups[$n][$pl['txt']])) {
  6249.                             // store reference of form object
  6250.                             $this->form_obj_id[$this->annot_obj_id;
  6251.                         }
  6252.                     }
  6253.                 }
  6254.             // end for each page
  6255.         }
  6256.  
  6257.         /**
  6258.         * Put appearance streams XObject used to define annotation's appearance states
  6259.         * @param int $w annotation width
  6260.         * @param int $h annotation height
  6261.         * @param string $stream appearance stream
  6262.         * @return int object ID
  6263.         * @access protected
  6264.         * @since 4.8.001 (2009-09-09)
  6265.         */
  6266.         protected function _putAPXObject($w=0$h=0$stream=''{
  6267.             $stream trim($stream);
  6268.             ++$this->apxo_obj_id;
  6269.             $this->offsets[$this->apxo_obj_id$this->bufferlen;
  6270.             $this->_out($this->apxo_obj_id.' 0 obj');
  6271.             $this->_out('<<');
  6272.             $this->_out('/Type /XObject');
  6273.             $this->_out('/Subtype /Form');
  6274.             $this->_out('/FormType 1');
  6275.             if ($this->compress{
  6276.                 $stream gzcompress($stream);
  6277.                 $this->_out('/Filter /FlateDecode');
  6278.             }
  6279.             $rect sprintf('%.2F %.2F'$w$h);
  6280.             $this->_out('/BBox [0 0 '.$rect.']');
  6281.             $this->_out('/Matrix [1 0 0 1 0 0]');
  6282.             $this->_out('/Resources <</ProcSet [/PDF]>>');
  6283.             $this->_out('/Length '.strlen($stream));
  6284.             $this->_out('>>');
  6285.             $this->_putstream($stream);
  6286.             $this->_out('endobj');
  6287.             return $this->apxo_obj_id;
  6288.         }
  6289.  
  6290.         /**
  6291.         * Output fonts.
  6292.         * @access protected
  6293.         */
  6294.         protected function _putfonts({
  6295.             $nf $this->n;
  6296.             foreach ($this->diffs as $diff{
  6297.                 //Encodings
  6298.                 $this->_newobj();
  6299.                 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  6300.                 $this->_out('endobj');
  6301.             }
  6302.             $mqr $this->get_mqr();
  6303.             $this->set_mqr(false);
  6304.             foreach ($this->FontFiles as $file => $info{
  6305.                 // search and get font file to embedd
  6306.                 $fontdir $info['fontdir'];
  6307.                 $file strtolower($file);
  6308.                 $fontfile '';
  6309.                 // search files on various directories
  6310.                 if (file_exists($fontdir.$file)) {
  6311.                     $fontfile $fontdir.$file;
  6312.                 elseif (file_exists($this->_getfontpath().$file)) {
  6313.                     $fontfile $this->_getfontpath().$file;
  6314.                 elseif (file_exists($file)) {
  6315.                     $fontfile $file;
  6316.                 }
  6317.                 if (!$this->empty_string($fontfile)) {
  6318.                     $font file_get_contents($fontfile);
  6319.                     $compressed (substr($file-2== '.z');
  6320.                     if ((!$compressedAND (isset($info['length2']))) {
  6321.                         $header (ord($font{0}== 128);
  6322.                         if ($header{
  6323.                             //Strip first binary header
  6324.                             $font substr($font6);
  6325.                         }
  6326.                         if ($header AND (ord($font{$info['length1']}== 128)) {
  6327.                             //Strip second binary header
  6328.                             $font substr($font0$info['length1']).substr($font($info['length1'6));
  6329.                         }
  6330.                     }
  6331.                     $this->_newobj();
  6332.                     $this->FontFiles[$file]['n'$this->n;
  6333.                     $this->_out('<</Length '.strlen($font));
  6334.                     if ($compressed{
  6335.                         $this->_out('/Filter /FlateDecode');
  6336.                     }
  6337.                     $this->_out('/Length1 '.$info['length1']);
  6338.                     if (isset($info['length2'])) {
  6339.                         $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  6340.                     }
  6341.                     $this->_out('>>');
  6342.                     $this->_putstream($font);
  6343.                     $this->_out('endobj');
  6344.                 }
  6345.             }
  6346.             $this->set_mqr($mqr);
  6347.             foreach ($this->fontkeys as $k{
  6348.                 //Font objects
  6349.                 $this->setFontSubBuffer($k'n'$this->n + 1);
  6350.                 $font $this->getFontBuffer($k);
  6351.                 $type $font['type'];
  6352.                 $name $font['name'];
  6353.                 if ($type == 'core'{
  6354.                     //Standard font
  6355.                     $obj_id $this->_newobj();
  6356.                     $this->_out('<</Type /Font');
  6357.                     $this->_out('/Subtype /Type1');
  6358.                     $this->_out('/BaseFont /'.$name);
  6359.                     $this->_out('/Name /F'.$font['i']);
  6360.                     if ((strtolower($name!= 'symbol'AND (strtolower($name!= 'zapfdingbats')) {
  6361.                         $this->_out('/Encoding /WinAnsiEncoding');
  6362.                     }
  6363.                     if (strtolower($name== 'helvetica'{
  6364.                         // add default font for annotations
  6365.                         $this->annotation_fonts['helvetica'$k;
  6366.                     }
  6367.                     $this->_out('>>');
  6368.                     $this->_out('endobj');
  6369.                 elseif (($type == 'Type1'OR ($type == 'TrueType')) {
  6370.                     //Additional Type1 or TrueType font
  6371.                     $obj_id $this->_newobj();
  6372.                     $this->_out('<</Type /Font');
  6373.                     $this->_out('/Subtype /'.$type);
  6374.                     $this->_out('/BaseFont /'.$name);
  6375.                     $this->_out('/Name /F'.$font['i']);
  6376.                     $this->_out('/FirstChar 32 /LastChar 255');
  6377.                     $this->_out('/Widths '.($this->n + 1).' 0 R');
  6378.                     $this->_out('/FontDescriptor '.($this->n + 2).' 0 R');
  6379.                     if ($font['enc']{
  6380.                         if (isset($font['diff'])) {
  6381.                             $this->_out('/Encoding '.($nf $font['diff']).' 0 R');
  6382.                         else {
  6383.                             $this->_out('/Encoding /WinAnsiEncoding');
  6384.                         }
  6385.                     }
  6386.                     $this->_out('>>');
  6387.                     $this->_out('endobj');
  6388.                     // Widths
  6389.                     $this->_newobj();
  6390.                     $cw &$font['cw'];
  6391.                     $s '[';
  6392.                     for ($i 32$i 256++$i{
  6393.                         $s .= $cw[$i].' ';
  6394.                     }
  6395.                     $this->_out($s.']');
  6396.                     $this->_out('endobj');
  6397.                     //Descriptor
  6398.                     $this->_newobj();
  6399.                     $s '<</Type /FontDescriptor /FontName /'.$name;
  6400.                     foreach ($font['desc'as $fdk => $fdv{
  6401.                         $s .= ' /'.$fdk.' '.$fdv.'';
  6402.                     }
  6403.                     if (!$this->empty_string($font['file'])) {
  6404.                         $s .= ' /FontFile'.($type == 'Type1' '' '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  6405.                     }
  6406.                     $this->_out($s.'>>');
  6407.                     $this->_out('endobj');
  6408.                 else {
  6409.                     //Allow for additional types
  6410.                     $mtd '_put'.strtolower($type);
  6411.                     if (!method_exists($this$mtd)) {
  6412.                         $this->Error('Unsupported font type: '.$type);
  6413.                     }
  6414.                     $obj_id $this->$mtd($font);
  6415.                 }
  6416.                 // store object ID for current font
  6417.                 $this->font_obj_ids[$k$obj_id;
  6418.             }
  6419.         }
  6420.         
  6421.         /**
  6422.         * Outputs font widths
  6423.         * @parameter array $font font data
  6424.         * @parameter int $cidoffset offset for CID values
  6425.         * @author Nicola Asuni
  6426.         * @access protected
  6427.         * @since 4.4.000 (2008-12-07)
  6428.         */
  6429.         protected function _putfontwidths($font$cidoffset=0{
  6430.             ksort($font['cw']);
  6431.             $rangeid 0;
  6432.             $range array();
  6433.             $prevcid = -2;
  6434.             $prevwidth = -1;
  6435.             $interval false;
  6436.             // for each character
  6437.             foreach ($font['cw'as $cid => $width{
  6438.                 $cid -= $cidoffset;
  6439.                 if ($width != $font['dw']{
  6440.                     if ($cid == ($prevcid 1)) {
  6441.                         // consecutive CID
  6442.                         if ($width == $prevwidth{
  6443.                             if ($width == $range[$rangeid][0]{
  6444.                                 $range[$rangeid][$width;
  6445.                             else {
  6446.                                 array_pop($range[$rangeid]);
  6447.                                 // new range
  6448.                                 $rangeid $prevcid;
  6449.                                 $range[$rangeidarray();
  6450.                                 $range[$rangeid][$prevwidth;
  6451.                                 $range[$rangeid][$width;
  6452.                             }
  6453.                             $interval true;
  6454.                             $range[$rangeid]['interval'true;
  6455.                         else {
  6456.                             if ($interval{
  6457.                                 // new range
  6458.                                 $rangeid $cid;
  6459.                                 $range[$rangeidarray();
  6460.                                 $range[$rangeid][$width;
  6461.                             else {
  6462.                                 $range[$rangeid][$width;
  6463.                             }
  6464.                             $interval false;
  6465.                         }
  6466.                     else {
  6467.                         // new range
  6468.                         $rangeid $cid;
  6469.                         $range[$rangeidarray();
  6470.                         $range[$rangeid][$width;
  6471.                         $interval false;
  6472.                     }
  6473.                     $prevcid $cid;
  6474.                     $prevwidth $width;
  6475.                 }
  6476.             }
  6477.             // optimize ranges
  6478.             $prevk = -1;
  6479.             $nextk = -1;
  6480.             $prevint false;
  6481.             foreach ($range as $k => $ws{
  6482.                 $cws count($ws);
  6483.                 if (($k == $nextkAND (!$previntAND ((!isset($ws['interval'])) OR ($cws 4))) {
  6484.                     if (isset($range[$k]['interval'])) {
  6485.                         unset($range[$k]['interval']);
  6486.                     }
  6487.                     $range[$prevkarray_merge($range[$prevk]$range[$k]);
  6488.                     unset($range[$k]);
  6489.                 else {
  6490.                     $prevk $k;
  6491.                 }
  6492.                 $nextk $k $cws;
  6493.                 if (isset($ws['interval'])) {
  6494.                     if ($cws 3{
  6495.                         $prevint true;
  6496.                     else {
  6497.                         $prevint false;
  6498.                     }
  6499.                     unset($range[$k]['interval']);
  6500.                     --$nextk;
  6501.                 else {
  6502.                     $prevint false;
  6503.                 }
  6504.             }
  6505.             // output data
  6506.             $w '';
  6507.             foreach ($range as $k => $ws{
  6508.                 if (count(array_count_values($ws)) == 1{
  6509.                     // interval mode is more compact
  6510.                     $w .= ' '.$k.' '.($k count($ws1).' '.$ws[0];
  6511.                 else {
  6512.                     // range mode
  6513.                     $w .= ' '.$k.' [ '.implode(' '$ws).' ]';
  6514.                 }
  6515.             }
  6516.             $this->_out('/W ['.$w.' ]');
  6517.         }
  6518.         
  6519.         /**
  6520.         * Adds unicode fonts.<br>
  6521.         * Based on PDF Reference 1.3 (section 5)
  6522.         * @parameter array $font font data
  6523.         * @return int font object ID
  6524.         * @access protected
  6525.         * @author Nicola Asuni
  6526.         * @since 1.52.0.TC005 (2005-01-05)
  6527.         */
  6528.         protected function _puttruetypeunicode($font{
  6529.             // Type0 Font
  6530.             // A composite font composed of other fonts, organized hierarchically
  6531.             $obj_id $this->_newobj();
  6532.             $this->_out('<</Type /Font');
  6533.             $this->_out('/Subtype /Type0');
  6534.             $this->_out('/BaseFont /'.$font['name'].'');
  6535.             $this->_out('/Name /F'.$font['i']);
  6536.             $this->_out('/Encoding /'.$font['enc']);
  6537.             $this->_out('/ToUnicode /Identity-H');
  6538.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  6539.             $this->_out('>>');
  6540.             $this->_out('endobj');
  6541.             // CIDFontType2
  6542.             // A CIDFont whose glyph descriptions are based on TrueType font technology
  6543.             $this->_newobj();
  6544.             $this->_out('<</Type /Font');
  6545.             $this->_out('/Subtype /CIDFontType2');
  6546.             $this->_out('/BaseFont /'.$font['name'].'');
  6547.             // A dictionary containing entries that define the character collection of the CIDFont.
  6548.             $cidinfo '/Registry '.$this->_datastring($font['cidinfo']['Registry']);
  6549.             $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']);
  6550.             $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  6551.             $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  6552.             $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  6553.             $this->_out('/DW '.$font['dw'].'')// default width
  6554.             $this->_putfontwidths($font0);
  6555.             $this->_out('/CIDToGIDMap '.($this->n + 2).' 0 R');
  6556.             $this->_out('>>');
  6557.             $this->_out('endobj');            
  6558.             // Font descriptor
  6559.             // A font descriptor describing the CIDFont default metrics other than its glyph widths
  6560.             $this->_newobj();
  6561.             $this->_out('<</Type /FontDescriptor');
  6562.             $this->_out('/FontName /'.$font['name']);
  6563.             foreach ($font['desc'as $key => $value{
  6564.                 $this->_out('/'.$key.' '.$value);
  6565.             }
  6566.             $fontdir '';
  6567.             if (!$this->empty_string($font['file'])) {
  6568.                 // A stream containing a TrueType font
  6569.                 $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  6570.                 $fontdir $this->FontFiles[$font['file']]['fontdir'];
  6571.             }
  6572.             $this->_out('>>');
  6573.             $this->_out('endobj');
  6574.             $this->_newobj();
  6575.             if (isset($font['ctg']AND (!$this->empty_string($font['ctg']))) {
  6576.                 // Embed CIDToGIDMap
  6577.                 // A specification of the mapping from CIDs to glyph indices
  6578.                 // search and get CTG font file to embedd
  6579.                 $ctgfile strtolower($font['ctg']);
  6580.                 // search and get ctg font file to embedd
  6581.                 $fontfile '';
  6582.                 // search files on various directories
  6583.                 if (file_exists($fontdir.$ctgfile)) {
  6584.                     $fontfile $fontdir.$ctgfile;
  6585.                 elseif (file_exists($this->_getfontpath().$ctgfile)) {
  6586.                     $fontfile $this->_getfontpath().$ctgfile;
  6587.                 elseif (file_exists($ctgfile)) {
  6588.                     $fontfile $ctgfile;
  6589.                 }
  6590.                 if ($this->empty_string($fontfile)) {
  6591.                     $this->Error('Font file not found: '.$ctgfile);
  6592.                 }
  6593.                 $size filesize($fontfile);
  6594.                 $this->_out('<</Length '.$size.'');
  6595.                 if (substr($fontfile-2== '.z'// check file extension
  6596.                     // Decompresses data encoded using the public-domain 
  6597.                     // zlib/deflate compression method, reproducing the 
  6598.                     // original text or binary data
  6599.                     $this->_out('/Filter /FlateDecode');
  6600.                 }
  6601.                 $this->_out('>>');
  6602.                 $this->_putstream(file_get_contents($fontfile));
  6603.             }
  6604.             $this->_out('endobj');
  6605.             return $obj_id;
  6606.         }
  6607.         
  6608.         /**
  6609.          * Output CID-0 fonts.
  6610.          * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  6611.          * @param array $font font data
  6612.          * @return int font object ID
  6613.          * @access protected
  6614.          * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  6615.          * @since 3.2.000 (2008-06-23)
  6616.          */
  6617.         protected function _putcidfont0($font{
  6618.             $cidoffset 0;
  6619.             if (!isset($font['cw'][1])) {
  6620.                 $cidoffset 31;
  6621.             }
  6622.             if (isset($font['cidinfo']['uni2cid'])) {
  6623.                 // convert unicode to cid.
  6624.                 $uni2cid $font['cidinfo']['uni2cid'];
  6625.                 $cw array();
  6626.                 foreach ($font['cw'as $uni => $width{
  6627.                     if (isset($uni2cid[$uni])) {
  6628.                         $cw[($uni2cid[$uni$cidoffset)$width;
  6629.                     elseif ($uni 256{
  6630.                         $cw[$uni$width;
  6631.                     // else unknown character
  6632.                 }
  6633.                 $font array_merge($fontarray('cw' => $cw));
  6634.             }
  6635.             $name $font['name'];
  6636.             $enc $font['enc'];
  6637.             if ($enc{
  6638.                 $longname $name.'-'.$enc;
  6639.             else {
  6640.                 $longname $name;
  6641.             }
  6642.             $obj_id $this->_newobj();
  6643.             $this->_out('<</Type /Font');
  6644.             $this->_out('/Subtype /Type0');
  6645.             $this->_out('/BaseFont /'.$longname);
  6646.             $this->_out('/Name /F'.$font['i']);
  6647.             if ($enc{
  6648.                 $this->_out('/Encoding /'.$enc);
  6649.             }
  6650.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  6651.             $this->_out('>>');
  6652.             $this->_out('endobj');
  6653.             $this->_newobj();
  6654.             $this->_out('<</Type /Font');
  6655.             $this->_out('/Subtype /CIDFontType0');
  6656.             $this->_out('/BaseFont /'.$name);
  6657.             $cidinfo '/Registry '.$this->_datastring($font['cidinfo']['Registry']);
  6658.             $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']);
  6659.             $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  6660.             $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  6661.             $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  6662.             $this->_out('/DW '.$font['dw']);
  6663.             $this->_putfontwidths($font$cidoffset);
  6664.             $this->_out('>>');
  6665.             $this->_out('endobj');
  6666.             $this->_newobj();
  6667.             $s '<</Type /FontDescriptor /FontName /'.$name;
  6668.             foreach ($font['desc'as $k => $v{
  6669.                 if ($k != 'Style'{
  6670.                     $s .= ' /'.$k.' '.$v.'';
  6671.                 }
  6672.             }
  6673.             $this->_out($s.'>>');
  6674.             $this->_out('endobj');
  6675.             return $obj_id;
  6676.         }
  6677.  
  6678.         /**
  6679.          * Output images.
  6680.          * @access protected
  6681.          */
  6682.         protected function _putimages({
  6683.             $filter ($this->compress'/Filter /FlateDecode ' '';
  6684.             foreach ($this->imagekeys as $file{
  6685.                 $info $this->getImageBuffer($file);
  6686.                 $this->_newobj();
  6687.                 $this->setImageSubBuffer($file'n'$this->n);
  6688.                 $this->_out('<</Type /XObject');
  6689.                 $this->_out('/Subtype /Image');
  6690.                 $this->_out('/Width '.$info['w']);
  6691.                 $this->_out('/Height '.$info['h']);
  6692.                 if (isset($info['masked'])) {
  6693.                     $this->_out('/SMask '.($this->n - 1).' 0 R');
  6694.                 }
  6695.                 if ($info['cs'== 'Indexed'{
  6696.                     $this->_out('/ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']31).' '.($this->n + 1).' 0 R]');
  6697.                 else {
  6698.                     $this->_out('/ColorSpace /'.$info['cs']);
  6699.                     if ($info['cs'== 'DeviceCMYK'{
  6700.                         $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  6701.                     }
  6702.                 }
  6703.                 $this->_out('/BitsPerComponent '.$info['bpc']);
  6704.                 if (isset($info['f'])) {
  6705.                     $this->_out('/Filter /'.$info['f']);
  6706.                 }
  6707.                 if (isset($info['parms'])) {
  6708.                     $this->_out($info['parms']);
  6709.                 }
  6710.                 if (isset($info['trns']AND is_array($info['trns'])) {
  6711.                     $trns='';
  6712.                     $count_info count($info['trns']);
  6713.                     for ($i=0$i $count_info++$i{
  6714.                         $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  6715.                     }
  6716.                     $this->_out('/Mask ['.$trns.']');
  6717.                 }
  6718.                 $this->_out('/Length '.strlen($info['data']).'>>');
  6719.                 $this->_putstream($info['data']);
  6720.                 $this->_out('endobj');
  6721.                 //Palette
  6722.                 if ($info['cs'== 'Indexed'{
  6723.                     $this->_newobj();
  6724.                     $pal ($this->compressgzcompress($info['pal']$info['pal'];
  6725.                     $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  6726.                     $this->_putstream($pal);
  6727.                     $this->_out('endobj');
  6728.                 }
  6729.             }
  6730.         }
  6731.  
  6732.         /**
  6733.         * Output Spot Colors Resources.
  6734.         * @access protected
  6735.         * @since 4.0.024 (2008-09-12)
  6736.         */
  6737.         protected function _putspotcolors({
  6738.             foreach ($this->spot_colors as $name => $color{
  6739.                 $this->_newobj();
  6740.                 $this->spot_colors[$name]['n'$this->n;
  6741.                 $this->_out('[/Separation /'.str_replace(' ''#20'$name));
  6742.                 $this->_out('/DeviceCMYK <<');
  6743.                 $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  6744.                 $this->_out(sprintf('/C1 [%.4F %.4F %.4F %.4F] '$color['c']/100$color['m']/100$color['y']/100$color['k']/100));
  6745.                 $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  6746.                 $this->_out('endobj');
  6747.             }
  6748.         }
  6749.  
  6750.         /**
  6751.         * Output object dictionary for images.
  6752.         * @access protected
  6753.         */
  6754.         protected function _putxobjectdict({
  6755.             foreach ($this->imagekeys as $file{
  6756.                 $info $this->getImageBuffer($file);
  6757.                 $this->_out('/I'.$info['i'].' '.$info['n'].' 0 R');
  6758.             }
  6759.         }
  6760.  
  6761.         /**
  6762.         * Output Resources Dictionary.
  6763.         * @access protected
  6764.         */
  6765.         protected function _putresourcedict({
  6766.             $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  6767.             $this->_out('/Font <<');
  6768.             foreach ($this->fontkeys as $fontkey{
  6769.                 $font $this->getFontBuffer($fontkey);
  6770.                 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  6771.             }
  6772.             $this->_out('>>');
  6773.             $this->_out('/XObject <<');
  6774.             $this->_putxobjectdict();
  6775.             $this->_out('>>');
  6776.             // visibility
  6777.             $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R>>');
  6778.             // transparency
  6779.             $this->_out('/ExtGState <<');
  6780.             foreach ($this->extgstates as $k => $extgstate{
  6781.                 $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  6782.             }
  6783.             $this->_out('>>');
  6784.             // gradients
  6785.             if (isset($this->gradientsAND (count($this->gradients0)) {
  6786.                 $this->_out('/Shading <<');
  6787.                 foreach ($this->gradients as $id => $grad{
  6788.                     $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  6789.                 }
  6790.                 $this->_out('>>');
  6791.             }
  6792.             // spot colors
  6793.             if (isset($this->spot_colorsAND (count($this->spot_colors0)) {
  6794.                 $this->_out('/ColorSpace <<');
  6795.                 foreach ($this->spot_colors as $color{
  6796.                     $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  6797.                 }
  6798.                 $this->_out('>>');
  6799.             }
  6800.         }
  6801.         
  6802.         /**
  6803.         * Output Resources.
  6804.         * @access protected
  6805.         */
  6806.         protected function _putresources({
  6807.             $this->_putextgstates();
  6808.             $this->_putocg();
  6809.             $this->_putfonts();
  6810.             $this->_putimages();
  6811.             $this->_putspotcolors();
  6812.             $this->_putshaders();
  6813.             //Resource dictionary
  6814.             $this->offsets[2$this->bufferlen;
  6815.             $this->_out('2 0 obj');
  6816.             $this->_out('<<');
  6817.             $this->_putresourcedict();
  6818.             $this->_out('>>');
  6819.             $this->_out('endobj');
  6820.             $this->_putbookmarks();
  6821.             $this->_putEmbeddedFiles();
  6822.             $this->_putannotsobjs();
  6823.             $this->_putjavascript();
  6824.             // encryption
  6825.             if ($this->encrypted{
  6826.                 $this->_newobj();
  6827.                 $this->enc_obj_id = $this->n;
  6828.                 $this->_out('<<');
  6829.                 $this->_putencryption();
  6830.                 $this->_out('>>');
  6831.                 $this->_out('endobj');
  6832.             }
  6833.         }
  6834.         
  6835.         /**
  6836.         * Adds some Metadata information
  6837.         * (see Chapter 10.2 of PDF Reference)
  6838.         * @access protected
  6839.         */
  6840.         protected function _putinfo({
  6841.             if ($this->empty_string($this->title)) {
  6842.                 $this->title = '?';
  6843.             }
  6844.             $this->_out('/Title '.$this->_textstring($this->title));
  6845.             if ($this->empty_string($this->author)) {
  6846.                 $this->author = '?';
  6847.             }
  6848.             $this->_out('/Author '.$this->_textstring($this->author));
  6849.             if ($this->empty_string($this->subject)) {
  6850.                 $this->subject = '?';
  6851.             }
  6852.             $this->_out('/Subject '.$this->_textstring($this->subject));
  6853.             if ($this->empty_string($this->keywords)) {
  6854.                 $this->keywords = '?';
  6855.             }
  6856.             $this->_out('/Keywords '.$this->_textstring($this->keywords));
  6857.             if ($this->empty_string($this->creator)) {
  6858.                 $this->creator = '?';
  6859.             }
  6860.             $this->_out('/Creator '.$this->_textstring($this->creator));
  6861.             if (defined('PDF_PRODUCER')) {
  6862.                 $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
  6863.             else {
  6864.                 $this->_out('/Producer '.$this->_textstring('TCPDF'));
  6865.             }
  6866.             $this->_out('/CreationDate '.$this->_datestring());
  6867.             $this->_out('/ModDate '.$this->_datestring());    
  6868.         }
  6869.         
  6870.         /**
  6871.         * Output Catalog.
  6872.         * @access protected
  6873.         */
  6874.         protected function _putcatalog({
  6875.             $this->_out('/Type /Catalog');
  6876.             $this->_out('/Pages 1 0 R');
  6877.             if ($this->ZoomMode == 'fullpage'{
  6878.                 $this->_out('/OpenAction [3 0 R /Fit]');
  6879.             elseif ($this->ZoomMode == 'fullwidth'{
  6880.                 $this->_out('/OpenAction [3 0 R /FitH null]');
  6881.             elseif ($this->ZoomMode == 'real'{
  6882.                 $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  6883.             elseif (!is_string($this->ZoomMode)) {
  6884.                 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).']');
  6885.             }            
  6886.             if (isset($this->LayoutModeAND (!$this->empty_string($this->LayoutMode))) {
  6887.                 $this->_out('/PageLayout /'.$this->LayoutMode.'');
  6888.             }
  6889.             if (isset($this->PageModeAND (!$this->empty_string($this->PageMode))) {
  6890.                 $this->_out('/PageMode /'.$this->PageMode);
  6891.             }
  6892.             if (isset($this->l['a_meta_language'])) {
  6893.                 $this->_out('/Lang /'.$this->l['a_meta_language']);
  6894.             }
  6895.             $this->_out('/Names <<');
  6896.             if ((!empty($this->javascript)) OR (!empty($this->js_objects))) {
  6897.                 $this->_out('/JavaScript '.($this->n_js).' 0 R');
  6898.             }
  6899.             $this->_out('>>');            
  6900.             if (count($this->outlines0{
  6901.                 $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  6902.                 $this->_out('/PageMode /UseOutlines');
  6903.             }
  6904.             $this->_putviewerpreferences();
  6905.             $p $this->n_ocg_print.' 0 R';
  6906.             $v $this->n_ocg_view.' 0 R';
  6907.             $as '<</Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print]>> <</Event /View /OCGs ['.$p.' '.$v.'] /Category [/View]>>';
  6908.             $this->_out('/OCProperties <</OCGs ['.$p.' '.$v.'] /D <</ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.']>>>>');
  6909.             // AcroForm
  6910.             if (!empty($this->form_obj_idOR ($this->sign AND isset($this->signature_data['cert_type']))) {
  6911.                 $this->_out('/AcroForm<<');
  6912.                 $objrefs '';
  6913.                 if ($this->sign AND isset($this->signature_data['cert_type'])) {
  6914.                     $objrefs .= $this->sig_obj_id.' 0 R';
  6915.                 }
  6916.                 if (!empty($this->form_obj_id)) {
  6917.                     foreach($this->form_obj_id as $objid{
  6918.                         $objrefs .= ' '.$objid.' 0 R';
  6919.                     }
  6920.                 }
  6921.                 $this->_out('/Fields ['.$objrefs.']');
  6922.                 $this->_out('/NeedAppearances '.(empty($this->form_obj_id)?'false':'true'));
  6923.                 if ($this->sign AND isset($this->signature_data['cert_type'])) {
  6924.                     $this->_out('/SigFlags 3');
  6925.                 }
  6926.                 //$this->_out('/CO ');
  6927.                 if (isset($this->annotation_fontsAND !empty($this->annotation_fonts)) {
  6928.                     $this->_out('/DR <<');
  6929.                     $this->_out('/Font <<');
  6930.                     foreach ($this->annotation_fonts as $font => $fontkey{
  6931.                         $this->_out('/F'.($fontkey 1).' '.$this->font_obj_ids[$font].' 0 R');
  6932.                     }
  6933.                     $this->_out('>>');
  6934.                     $this->_out('>>');
  6935.                 }
  6936.                 $this->_out('/DA (/F'.(array_search('helvetica'$this->fontkeys1).' 0 Tf 0 g)');
  6937.                 $this->_out('/Q '.(($this->rtl)?'2':'0'));
  6938.                 //$this->_out('/XFA ');
  6939.                 $this->_out('>>');
  6940.                 // signatures
  6941.                 if ($this->sign AND isset($this->signature_data['cert_type'])) {
  6942.                     if ($this->signature_data['cert_type'0{
  6943.                         $this->_out('/Perms<</DocMDP '.($this->sig_obj_id + 1).' 0 R>>');
  6944.                     else {
  6945.                         $this->_out('/Perms<</UR3 '.($this->sig_obj_id + 1).' 0 R>>');
  6946.                     }
  6947.                 }
  6948.             }
  6949.         }
  6950.         
  6951.         /**
  6952.         * Output viewer preferences.
  6953.         * @author Nicola asuni
  6954.         * @since 3.1.000 (2008-06-09)
  6955.         * @access protected
  6956.         */
  6957.         protected function _putviewerpreferences({
  6958.             $this->_out('/ViewerPreferences<<');
  6959.             if ($this->rtl{
  6960.                 $this->_out('/Direction /R2L');
  6961.             else {
  6962.                 $this->_out('/Direction /L2R');
  6963.             }
  6964.             if (isset($this->viewer_preferences['HideToolbar']AND ($this->viewer_preferences['HideToolbar'])) {
  6965.                 $this->_out('/HideToolbar true');
  6966.             }
  6967.             if (isset($this->viewer_preferences['HideMenubar']AND ($this->viewer_preferences['HideMenubar'])) {
  6968.                 $this->_out('/HideMenubar true');
  6969.             }
  6970.             if (isset($this->viewer_preferences['HideWindowUI']AND ($this->viewer_preferences['HideWindowUI'])) {
  6971.                 $this->_out('/HideWindowUI true');
  6972.             }
  6973.             if (isset($this->viewer_preferences['FitWindow']AND ($this->viewer_preferences['FitWindow'])) {
  6974.                 $this->_out('/FitWindow true');
  6975.             }
  6976.             if (isset($this->viewer_preferences['CenterWindow']AND ($this->viewer_preferences['CenterWindow'])) {
  6977.                 $this->_out('/CenterWindow true');
  6978.             }
  6979.             if (isset($this->viewer_preferences['DisplayDocTitle']AND ($this->viewer_preferences['DisplayDocTitle'])) {
  6980.                 $this->_out('/DisplayDocTitle true');
  6981.             }
  6982.             if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  6983.                 $this->_out('/NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'].'');
  6984.             }
  6985.             if (isset($this->viewer_preferences['ViewArea'])) {
  6986.                 $this->_out('/ViewArea /'.$this->viewer_preferences['ViewArea']);
  6987.             }
  6988.             if (isset($this->viewer_preferences['ViewClip'])) {
  6989.                 $this->_out('/ViewClip /'.$this->viewer_preferences['ViewClip']);
  6990.             }
  6991.             if (isset($this->viewer_preferences['PrintArea'])) {
  6992.                 $this->_out('/PrintArea /'.$this->viewer_preferences['PrintArea']);
  6993.             }
  6994.             if (isset($this->viewer_preferences['PrintClip'])) {
  6995.                 $this->_out('/PrintClip /'.$this->viewer_preferences['PrintClip']);
  6996.             }
  6997.             if (isset($this->viewer_preferences['PrintScaling'])) {
  6998.                 $this->_out('/PrintScaling /'.$this->viewer_preferences['PrintScaling']);
  6999.             }
  7000.             if (isset($this->viewer_preferences['Duplex']AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
  7001.                 $this->_out('/Duplex /'.$this->viewer_preferences['Duplex']);
  7002.             }
  7003.             if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  7004.                 if ($this->viewer_preferences['PickTrayByPDFSize']{
  7005.                     $this->_out('/PickTrayByPDFSize true');
  7006.                 else {
  7007.                     $this->_out('/PickTrayByPDFSize false');
  7008.                 }
  7009.             }
  7010.             if (isset($this->viewer_preferences['PrintPageRange'])) {
  7011.                 $PrintPageRangeNum '';
  7012.                 foreach ($this->viewer_preferences['PrintPageRange'as $k => $v{
  7013.                     $PrintPageRangeNum .= ' '.($v 1).'';
  7014.                 }
  7015.                 $this->_out('/PrintPageRange ['.substr($PrintPageRangeNum,1).']');
  7016.             }
  7017.             if (isset($this->viewer_preferences['NumCopies'])) {
  7018.                 $this->_out('/NumCopies '.intval($this->viewer_preferences['NumCopies']));
  7019.             }
  7020.             $this->_out('>>');
  7021.         }
  7022.         
  7023.         /**
  7024.         * Output trailer.
  7025.         * @access protected
  7026.         */
  7027.         protected function _puttrailer({
  7028.             $this->_out('/Size '.($this->n + 1));
  7029.             $this->_out('/Root '.$this->n.' 0 R');
  7030.             $this->_out('/Info '.($this->n - 1).' 0 R');
  7031.             if ($this->encrypted{
  7032.                 $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  7033.                 $this->_out('/ID [()()]');
  7034.             }
  7035.         }
  7036.  
  7037.         /**
  7038.         * Output PDF header.
  7039.         * @access protected
  7040.         */
  7041.         protected function _putheader({
  7042.             $this->_out('%PDF-'.$this->PDFVersion);
  7043.         }
  7044.  
  7045.         /**
  7046.         * Output end of document (EOF).
  7047.         * @access protected
  7048.         */
  7049.         protected function _enddoc({
  7050.             $this->state = 1;
  7051.             $this->_putheader();            
  7052.             $this->_putpages();
  7053.             $this->_putresources();
  7054.             // Signature
  7055.             if ($this->sign AND isset($this->signature_data['cert_type'])) {
  7056.                 // widget annotation for signature
  7057.                 $this->sig_obj_id = $this->_newobj();
  7058.                 // --- replace signature ID on the first page ---
  7059.                 // get the document content
  7060.                 $pdfdoc $this->getBuffer();
  7061.                 // Remove the original buffer
  7062.                 if (isset($this->diskcacheAND $this->diskcache{
  7063.                     // remove buffer file from cache
  7064.                     unlink($this->buffer);
  7065.                 }
  7066.                 unset($this->buffer);
  7067.                 $signature_widget_ref sprintf('%u 0 R'$this->sig_obj_id);
  7068.                 $signature_widget_ref .= str_repeat(' '(strlen($this->sig_annot_refstrlen($signature_widget_ref)));
  7069.                 $pdfdoc str_replace($this->sig_annot_ref$signature_widget_ref$pdfdoc);
  7070.                 $this->diskcache = false;
  7071.                 $this->buffer = &$pdfdoc;
  7072.                 $this->bufferlen = strlen($pdfdoc);
  7073.                 // ---
  7074.                 $this->_out('<<');
  7075.                 $this->_out('/Type /Annot /Subtype /Widget /Rect [0 0 0 0]');
  7076.                 $this->_out('/P 3 0 R')// link to first page object
  7077.                 $this->_out('/FT /Sig');
  7078.                 $this->_out('/T '.$this->_textstring('Signature'));
  7079.                 $this->_out('/Ff 0');
  7080.                 $this->_out('/V '.($this->sig_obj_id + 1).' 0 R');
  7081.                 $this->_out('>>');
  7082.                 $this->_out('endobj');
  7083.                 // signature        
  7084.                 $this->_newobj();
  7085.                 $this->_out('<<');
  7086.                 $this->_putsignature();
  7087.                 $this->_out('>>');
  7088.                 $this->_out('endobj');
  7089.             }
  7090.             // Info
  7091.             $this->_newobj();
  7092.             $this->_out('<<');
  7093.             $this->_putinfo();
  7094.             $this->_out('>>');
  7095.             $this->_out('endobj');
  7096.             // Catalog
  7097.             $this->_newobj();
  7098.             $this->_out('<<');
  7099.             $this->_putcatalog();
  7100.             $this->_out('>>');
  7101.             $this->_out('endobj');
  7102.             // Cross-ref
  7103.             $o $this->bufferlen;
  7104.             $this->_out('xref');
  7105.             $this->_out('0 '.($this->n + 1));
  7106.             $this->_out('0000000000 65535 f ');
  7107.             for ($i=1$i <= $this->n++$i{
  7108.                 $this->_out(sprintf('%010d 00000 n '$this->offsets[$i]));
  7109.             }
  7110.             // Embedded Files
  7111.             if (isset($this->embeddedfilesAND count($this->embeddedfiles0{
  7112.                 $this->_out($this->embedded_start_obj_id.' '.count($this->embeddedfiles));
  7113.                 foreach ($this->embeddedfiles as $filename => $filedata{
  7114.                     $this->_out(sprintf('%010d 00000 n '$this->offsets[$filedata['n']]));
  7115.                 }
  7116.             }
  7117.             // Annotation Objects
  7118.             if ($this->annot_obj_id > $this->annots_start_obj_id{
  7119.                 $this->_out(($this->annots_start_obj_id + 1).' '.($this->annot_obj_id - $this->annots_start_obj_id));
  7120.                 for ($i ($this->annots_start_obj_id + 1)$i <= $this->annot_obj_id++$i{
  7121.                     $this->_out(sprintf('%010d 00000 n '$this->offsets[$i]));
  7122.                 }
  7123.             }
  7124.             // Javascript Objects
  7125.             if ($this->js_obj_id > $this->js_start_obj_id{
  7126.                 $this->_out(($this->js_start_obj_id + 1).' '.($this->js_obj_id - $this->js_start_obj_id));
  7127.                 for ($i ($this->js_start_obj_id + 1)$i <= $this->js_obj_id++$i{
  7128.                     $this->_out(sprintf('%010d 00000 n '$this->offsets[$i]));
  7129.                 }
  7130.             }
  7131.             // Appearance streams XObjects
  7132.             if ($this->apxo_obj_id > $this->apxo_start_obj_id{
  7133.                 $this->_out(($this->apxo_start_obj_id + 1).' '.($this->apxo_obj_id - $this->apxo_start_obj_id));
  7134.                 for ($i ($this->apxo_start_obj_id + 1)$i <= $this->apxo_obj_id++$i{
  7135.                     $this->_out(sprintf('%010d 00000 n '$this->offsets[$i]));
  7136.                 }
  7137.             }
  7138.             //Trailer
  7139.             $this->_out('trailer');
  7140.             $this->_out('<<');
  7141.             $this->_puttrailer();
  7142.             $this->_out('>>');
  7143.             $this->_out('startxref');
  7144.             $this->_out($o);
  7145.             $this->_out('%%EOF');
  7146.             $this->state = 3// end-of-doc
  7147.             if ($this->diskcache{
  7148.                 // remove temporary files used for images
  7149.                 foreach ($this->imagekeys as $key{
  7150.                     // remove temporary files
  7151.                     unlink($this->images[$key]);
  7152.                 }
  7153.                 foreach ($this->fontkeys as $key{
  7154.                     // remove temporary files
  7155.                     unlink($this->fonts[$key]);
  7156.                 }
  7157.             }
  7158.         }
  7159.  
  7160.         /**
  7161.         * Initialize a new page.
  7162.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  7163.         * @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).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  7164.         * @access protected
  7165.         */
  7166.         protected function _beginpage($orientation=''$format=''{
  7167.             ++$this->page;
  7168.             $this->setPageBuffer($this->page'');
  7169.             // initialize array for graphics tranformation positions inside a page buffer
  7170.             $this->transfmrk[$this->pagearray();
  7171.             $this->state = 2;
  7172.             if ($this->empty_string($orientation)) {
  7173.                 if (isset($this->CurOrientation)) {
  7174.                     $orientation $this->CurOrientation;
  7175.                 else {
  7176.                     $orientation 'P';
  7177.                 }
  7178.             }
  7179.             if ($this->empty_string($format)) {
  7180.                 $this->setPageOrientation($orientation);
  7181.             else {
  7182.                 $this->setPageFormat($format$orientation);
  7183.             }
  7184.             if ($this->rtl{
  7185.                 $this->x = $this->w - $this->rMargin;
  7186.             else {
  7187.                 $this->x = $this->lMargin;
  7188.             }
  7189.             $this->y = $this->tMargin;
  7190.             if (isset($this->newpagegroup[$this->page])) {
  7191.                 // start a new group
  7192.                 $n sizeof($this->pagegroups1;
  7193.                 $alias '{nb'.$n.'}';
  7194.                 $this->pagegroups[$alias1;
  7195.                 $this->currpagegroup = $alias;
  7196.             elseif ($this->currpagegroup{
  7197.                 ++$this->pagegroups[$this->currpagegroup];
  7198.             }
  7199.         }
  7200.  
  7201.         /**
  7202.         * Mark end of page.
  7203.         * @access protected
  7204.         */
  7205.         protected function _endpage({
  7206.             $this->setVisibility('all');
  7207.             $this->state = 1;
  7208.         }
  7209.  
  7210.         /**
  7211.         * Begin a new object and return the object number.
  7212.         * @return int object number
  7213.         * @access protected
  7214.         */
  7215.         protected function _newobj({
  7216.             ++$this->n;
  7217.             $this->offsets[$this->n$this->bufferlen;
  7218.             $this->_out($this->n.' 0 obj');
  7219.             return $this->n;
  7220.         }
  7221.  
  7222.         /**
  7223.         * Underline text.
  7224.         * @param int $x X coordinate
  7225.         * @param int $y Y coordinate
  7226.         * @param string $txt text to underline
  7227.         * @access protected
  7228.         */
  7229.         protected function _dounderline($x$y$txt{
  7230.             $w $this->GetStringWidth($txt);
  7231.             return $this->_dounderlinew($x$y$w);
  7232.         }
  7233.         
  7234.         /**
  7235.         * Line through text.
  7236.         * @param int $x X coordinate
  7237.         * @param int $y Y coordinate
  7238.         * @param string $txt text to linethrough
  7239.         * @access protected
  7240.         */
  7241.         protected function _dolinethrough($x$y$txt{
  7242.             $w $this->GetStringWidth($txt);
  7243.             return $this->_dolinethroughw($x$y$w);
  7244.         }
  7245.  
  7246.         /**
  7247.         * Underline for rectangular text area.
  7248.         * @param int $x X coordinate
  7249.         * @param int $y Y coordinate
  7250.         * @param int $w width to underline
  7251.         * @access protected
  7252.         * @since 4.8.008 (2009-09-29)
  7253.         */
  7254.         protected function _dounderlinew($x$y$w{
  7255.             $up $this->CurrentFont['up'];
  7256.             $ut $this->CurrentFont['ut'];
  7257.             return sprintf('%.2F %.2F %.2F %.2F re f'$x $this->k($this->h - ($y $up 1000 $this->FontSize)) $this->k$w $this->k-$ut 1000 $this->FontSizePt);
  7258.         }
  7259.         
  7260.         /**
  7261.         * Line through for rectangular text area.
  7262.         * @param int $x X coordinate
  7263.         * @param int $y Y coordinate
  7264.         * @param string $txt text to linethrough
  7265.         * @access protected
  7266.         * @since 4.8.008 (2009-09-29)
  7267.         */
  7268.         protected function _dolinethroughw($x$y$w{
  7269.             $up $this->CurrentFont['up'];
  7270.             $ut $this->CurrentFont['ut'];
  7271.             return sprintf('%.2F %.2F %.2F %.2F re f'$x $this->k($this->h - ($y ($this->FontSize/2$up 1000 $this->FontSize)) $this->k$w $this->k-$ut 1000 $this->FontSizePt);
  7272.         }
  7273.         
  7274.         /**
  7275.         * Read a 4-byte integer from file.
  7276.         * @param string $f file name.
  7277.         * @return 4-byte integer
  7278.         * @access protected
  7279.         */
  7280.         protected function _freadint($f{
  7281.             $a unpack('Ni'fread($f4));
  7282.             return $a['i'];
  7283.         }
  7284.         
  7285.         /**
  7286.         * Add "\" before "\", "(" and ")"
  7287.         * @param string $s string to escape.
  7288.         * @return string escaped string.
  7289.         * @access protected
  7290.         */
  7291.         protected function _escape($s{
  7292.             // the chr(13) substitution fixes the Bugs item #1421290.
  7293.             return strtr($sarray(')' => '\\)''(' => '\\(''\\' => '\\\\'chr(13=> '\r'));
  7294.         }
  7295.         
  7296.         /**
  7297.         * Format a data string for meta information
  7298.         * @param string $s date string to escape.
  7299.         * @return string escaped string.
  7300.         * @access protected
  7301.         */
  7302.         protected function _datastring($s{
  7303.             if ($this->encrypted{
  7304.                 $s $this->_RC4($this->_objectkey($this->n)$s);
  7305.             }
  7306.             return '('$this->_escape($s).')';
  7307.         }
  7308.  
  7309.         /**
  7310.         * Returns a formatted date for meta information
  7311.         * @return string escaped date string.
  7312.         * @access protected
  7313.         * @since 4.6.028 (2009-08-25)
  7314.         */
  7315.         protected function _datestring({
  7316.             $current_time substr_replace(date('YmdHisO')'\''(2)0).'\'';
  7317.             return $this->_datastring('D:'.$current_time);
  7318.         }
  7319.  
  7320.         /**
  7321.         * Format a text string for meta information
  7322.         * @param string $s string to escape.
  7323.         * @return string escaped string.
  7324.         * @access protected
  7325.         */
  7326.         protected function _textstring($s{
  7327.             if ($this->isunicode{
  7328.                 //Convert string to UTF-16BE
  7329.                 $s $this->UTF8ToUTF16BE($strue);
  7330.             }
  7331.             return $this->_datastring($s);
  7332.         }
  7333.                 
  7334.         /**
  7335.         * Format a text string
  7336.         * @param string $s string to escape.
  7337.         * @return string escaped string.
  7338.         * @access protected
  7339.         */
  7340.         protected function _escapetext($s{
  7341.             if ($this->isunicode{
  7342.                 if (($this->CurrentFont['type'== 'core'OR ($this->CurrentFont['type'== 'TrueType'OR ($this->CurrentFont['type'== 'Type1')) {
  7343.                     $s $this->UTF8ToLatin1($s);
  7344.                 else {
  7345.                     //Convert string to UTF-16BE and reverse RTL language
  7346.                     $s $this->utf8StrRev($sfalse$this->tmprtl);
  7347.                 }
  7348.             }
  7349.             return $this->_escape($s);
  7350.         }
  7351.         
  7352.         /**
  7353.         * Output a stream.
  7354.         * @param string $s string to output.
  7355.         * @access protected
  7356.         */
  7357.         protected function _putstream($s{
  7358.             if ($this->encrypted{
  7359.                 $s $this->_RC4($this->_objectkey($this->n)$s);
  7360.             }
  7361.             $this->_out('stream');
  7362.             $this->_out($s);
  7363.             $this->_out('endstream');
  7364.         }
  7365.         
  7366.         /**
  7367.         * Output a string to the document.
  7368.         * @param string $s string to output.
  7369.         * @access protected
  7370.         */
  7371.         protected function _out($s{
  7372.             if ($this->state == 2{
  7373.                 if ((!$this->InFooterAND isset($this->footerlen[$this->page]AND ($this->footerlen[$this->page0)) {
  7374.                     // puts data before page footer
  7375.                     $pagebuff $this->getPageBuffer($this->page);
  7376.                     $page substr($pagebuff0-$this->footerlen[$this->page]);
  7377.                     $footer substr($pagebuff-$this->footerlen[$this->page]);
  7378.                     $this->setPageBuffer($this->page$page.$s."\n".$footer);
  7379.                     // update footer position
  7380.                     $this->footerpos[$this->page+= strlen($s."\n");    
  7381.                 else {
  7382.                     $this->setPageBuffer($this->page$s."\n"true);
  7383.                 }
  7384.             else {
  7385.                 $this->setBuffer($s."\n");
  7386.             }
  7387.         }
  7388.         
  7389.          /**
  7390.          * Converts UTF-8 strings to codepoints array.<br>
  7391.          * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  7392.          * Based on: http://www.faqs.org/rfcs/rfc3629.html
  7393.          * <pre>
  7394.          *       Char. number range  |        UTF-8 octet sequence
  7395.          *       (hexadecimal)    |              (binary)
  7396.          *    --------------------+-----------------------------------------------
  7397.          *    0000 0000-0000 007F | 0xxxxxxx
  7398.          *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  7399.          *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  7400.          *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  7401.          *    ---------------------------------------------------------------------
  7402.          *
  7403.          *   ABFN notation:
  7404.          *   ---------------------------------------------------------------------
  7405.          *   UTF8-octets = *( UTF8-char )
  7406.          *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  7407.          *   UTF8-1      = %x00-7F
  7408.          *   UTF8-2      = %xC2-DF UTF8-tail
  7409.          *
  7410.          *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  7411.          *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  7412.          *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  7413.          *                 %xF4 %x80-8F 2( UTF8-tail )
  7414.          *   UTF8-tail   = %x80-BF
  7415.          *   ---------------------------------------------------------------------
  7416.          * </pre>
  7417.          * @param string $str string to process.
  7418.          * @return array containing codepoints (UTF-8 characters values)
  7419.          * @access protected
  7420.          * @author Nicola Asuni
  7421.          * @since 1.53.0.TC005 (2005-01-05)
  7422.          */
  7423.         protected function UTF8StringToArray($str{
  7424.             if (isset($this->cache_UTF8StringToArray['_'.$str])) {
  7425.                 // return cached value
  7426.                 return($this->cache_UTF8StringToArray['_'.$str]);
  7427.             }
  7428.             // check cache size
  7429.             if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray{
  7430.                 // remove first element
  7431.                 array_shift($this->cache_UTF8StringToArray);
  7432.             }
  7433.             ++$this->cache_size_UTF8StringToArray;
  7434.             if (!$this->isunicode{
  7435.                 // split string into array of equivalent codes
  7436.                 $strarr array();
  7437.                 $strlen strlen($str);
  7438.                 for ($i=0$i $strlen++$i{
  7439.                     $strarr[ord($str{$i});
  7440.                 }
  7441.                 // insert new value on cache
  7442.                 $this->cache_UTF8StringToArray['_'.$str$strarr;
  7443.                 return $strarr;
  7444.             }
  7445.             $unicode array()// array containing unicode values
  7446.             $bytes  array()// array containing single character byte sequences
  7447.             $numbytes  1// number of octetc needed to represent the UTF-8 character
  7448.             $str .= ''// force $str to be a string
  7449.             $length strlen($str);
  7450.             for ($i 0$i $length++$i{
  7451.                 $char ord($str{$i})// get one string character at time
  7452.                 if (count($bytes== 0// get starting octect
  7453.                     if ($char <= 0x7F{
  7454.                         $unicode[$char// use the character "as is" because is ASCII
  7455.                         $numbytes 1;
  7456.                     elseif (($char >> 0x05== 0x06// 2 bytes character (0x06 = 110 BIN)
  7457.                         $bytes[($char 0xC0<< 0x06
  7458.                         $numbytes 2;
  7459.                     elseif (($char >> 0x04== 0x0E// 3 bytes character (0x0E = 1110 BIN)
  7460.                         $bytes[($char 0xE0<< 0x0C
  7461.                         $numbytes 3;
  7462.                     elseif (($char >> 0x03== 0x1E// 4 bytes character (0x1E = 11110 BIN)
  7463.                         $bytes[($char 0xF0<< 0x12
  7464.                         $numbytes 4;
  7465.                     else {
  7466.                         // use replacement character for other invalid sequences
  7467.                         $unicode[0xFFFD;
  7468.                         $bytes array();
  7469.                         $numbytes 1;
  7470.                     }
  7471.                 elseif (($char >> 0x06== 0x02// bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  7472.                     $bytes[$char 0x80;
  7473.                     if (count($bytes== $numbytes{
  7474.                         // compose UTF-8 bytes to a single unicode value
  7475.                         $char $bytes[0];
  7476.                         for ($j 1$j $numbytes++$j{
  7477.                             $char += ($bytes[$j<< (($numbytes $j 10x06));
  7478.                         }
  7479.                         if ((($char >= 0xD800AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  7480.                             /* The definition of UTF-8 prohibits encoding character numbers between
  7481.                             U+D800 and U+DFFF, which are reserved for use with the UTF-16
  7482.                             encoding form (as surrogate pairs) and do not directly represent
  7483.                             characters. */
  7484.                             $unicode[0xFFFD// use replacement character
  7485.                         else {
  7486.                             $unicode[$char// add char to array
  7487.                         }
  7488.                         // reset data for next char
  7489.                         $bytes array()
  7490.                         $numbytes 1;
  7491.                     }
  7492.                 else {
  7493.                     // use replacement character for other invalid sequences
  7494.                     $unicode[0xFFFD;
  7495.                     $bytes array();
  7496.                     $numbytes 1;
  7497.                 }
  7498.             }
  7499.             // insert new value on cache
  7500.             $this->cache_UTF8StringToArray['_'.$str$unicode;
  7501.             return $unicode;
  7502.         }
  7503.         
  7504.         /**
  7505.          * Converts UTF-8 strings to UTF16-BE.<br>
  7506.          * @param string $str string to process.
  7507.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  7508.          * @return string 
  7509.          * @access protected
  7510.          * @author Nicola Asuni
  7511.          * @since 1.53.0.TC005 (2005-01-05)
  7512.          * @uses UTF8StringToArray(), arrUTF8ToUTF16BE()
  7513.          */
  7514.         protected function UTF8ToUTF16BE($str$setbom=true{
  7515.             if (!$this->isunicode{
  7516.                 return $str// string is not in unicode
  7517.             }
  7518.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  7519.             return $this->arrUTF8ToUTF16BE($unicode$setbom);
  7520.         }
  7521.         
  7522.         /**
  7523.          * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  7524.          * @param string $str string to process.
  7525.          * @return string 
  7526.          * @author Andrew Whitehead, Nicola Asuni
  7527.          * @access protected
  7528.          * @since 3.2.000 (2008-06-23)
  7529.          */
  7530.         protected function UTF8ToLatin1($str{
  7531.             global $utf8tolatin;
  7532.             if (!$this->isunicode{
  7533.                 return $str// string is not in unicode
  7534.             }
  7535.             $outstr ''// string to be returned
  7536.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  7537.             foreach ($unicode as $char{
  7538.                 if ($char 256{
  7539.                     $outstr .= chr($char);
  7540.                 elseif (array_key_exists($char$utf8tolatin)) {
  7541.                     // map from UTF-8
  7542.                     $outstr .= chr($utf8tolatin[$char]);
  7543.                 elseif ($char == 0xFFFD{
  7544.                     // skip
  7545.                 else {
  7546.                     $outstr .= '?';
  7547.                 }
  7548.             }
  7549.             return $outstr;
  7550.         }
  7551.  
  7552.         /**
  7553.          * Converts array of UTF-8 characters to UTF16-BE string.<br>
  7554.          * Based on: http://www.faqs.org/rfcs/rfc2781.html
  7555.           * <pre>
  7556.          *   Encoding UTF-16:
  7557.          * 
  7558.           *   Encoding of a single character from an ISO 10646 character value to
  7559.          *    UTF-16 proceeds as follows. Let U be the character number, no greater
  7560.          *    than 0x10FFFF.
  7561.          * 
  7562.          *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  7563.          *       terminate.
  7564.          * 
  7565.          *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  7566.          *       U' must be less than or equal to 0xFFFFF. That is, U' can be
  7567.          *       represented in 20 bits.
  7568.          * 
  7569.          *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  7570.          *       0xDC00, respectively. These integers each have 10 bits free to
  7571.          *       encode the character value, for a total of 20 bits.
  7572.          * 
  7573.          *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  7574.          *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
  7575.          *       bits of W2. Terminate.
  7576.          * 
  7577.          *    Graphically, steps 2 through 4 look like:
  7578.          *    U' = yyyyyyyyyyxxxxxxxxxx
  7579.          *    W1 = 110110yyyyyyyyyy
  7580.          *    W2 = 110111xxxxxxxxxx
  7581.          * </pre>
  7582.          * @param array $unicode array containing UTF-8 unicode values
  7583.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  7584.          * @return string 
  7585.          * @access protected
  7586.          * @author Nicola Asuni
  7587.          * @since 2.1.000 (2008-01-08)
  7588.          * @see UTF8ToUTF16BE()
  7589.          */
  7590.         protected function arrUTF8ToUTF16BE($unicode$setbom=true{
  7591.             $outstr ''// string to be returned
  7592.             if ($setbom{
  7593.                 $outstr .= "\xFE\xFF"// Byte Order Mark (BOM)
  7594.             }
  7595.             foreach ($unicode as $char{
  7596.                 if ($char == 0xFFFD{
  7597.                     $outstr .= "\xFF\xFD"// replacement character
  7598.                 elseif ($char 0x10000{
  7599.                     $outstr .= chr($char >> 0x08);
  7600.                     $outstr .= chr($char 0xFF);
  7601.                 else {
  7602.                     $char -= 0x10000;
  7603.                     $w1 0xD800 ($char >> 0x10);
  7604.                     $w2 0xDC00 ($char 0x3FF);    
  7605.                     $outstr .= chr($w1 >> 0x08);
  7606.                     $outstr .= chr($w1 0xFF);
  7607.                     $outstr .= chr($w2 >> 0x08);
  7608.                     $outstr .= chr($w2 0xFF);
  7609.                 }
  7610.             }
  7611.             return $outstr;
  7612.         }
  7613.         // ====================================================
  7614.         
  7615.         /**
  7616.           * Set header font.
  7617.          * @param array $font font
  7618.          * @access public
  7619.          * @since 1.1
  7620.          */
  7621.         public function setHeaderFont($font{
  7622.             $this->header_font = $font;
  7623.         }
  7624.         
  7625.         /**
  7626.           * Get header font.
  7627.           * @return array() 
  7628.          * @access public
  7629.          * @since 4.0.012 (2008-07-24)
  7630.          */
  7631.         public function getHeaderFont({
  7632.             return $this->header_font;
  7633.         }
  7634.         
  7635.         /**
  7636.           * Set footer font.
  7637.          * @param array $font font
  7638.          * @access public
  7639.          * @since 1.1
  7640.          */
  7641.         public function setFooterFont($font{
  7642.             $this->footer_font = $font;
  7643.         }
  7644.         
  7645.         /**
  7646.           * Get Footer font.
  7647.           * @return array() 
  7648.          * @access public
  7649.          * @since 4.0.012 (2008-07-24)
  7650.          */
  7651.         public function getFooterFont({
  7652.             return $this->footer_font;
  7653.         }
  7654.         
  7655.         /**
  7656.           * Set language array.
  7657.          * @param array $language 
  7658.          * @access public
  7659.          * @since 1.1
  7660.          */
  7661.         public function setLanguageArray($language{
  7662.             $this->l = $language;
  7663.             if (isset($this->l['a_meta_dir'])) {
  7664.                 $this->rtl = $this->l['a_meta_dir']=='rtl' true false;
  7665.             else {
  7666.                 $this->rtl = false;
  7667.             }
  7668.         }
  7669.         
  7670.         /**
  7671.          * Returns the PDF data.
  7672.          * @access public
  7673.          */
  7674.         public function getPDFData({
  7675.             if ($this->state < 3{
  7676.                 $this->Close();
  7677.             }
  7678.             return $this->buffer;
  7679.         }
  7680.                 
  7681.         /**
  7682.          * Output anchor link.
  7683.          * @param string $url link URL or internal link (i.e.: &lt;a href="#23"&gt;link to page 23&lt;/a&gt;)
  7684.          * @param string $name link name
  7685.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  7686.          * @param boolean $firstline if true prints only the first line and return the remaining string.
  7687.          * @param array $color array of RGB text color
  7688.          * @param string $style font style (U, D, B, I)
  7689.          * @return the number of cells used or the remaining text if $firstline = true;
  7690.          * @access public
  7691.          */
  7692.         public function addHtmlLink($url$name$fill=0$firstline=false$color=''$style=-1{
  7693.             if (!$this->empty_string($urlAND ($url{0== '#')) {
  7694.                 // convert url to internal link
  7695.                 $page intval(substr($url1));
  7696.                 $url $this->AddLink();
  7697.                 $this->SetLink($url0$page);
  7698.             }
  7699.             // store current settings
  7700.             $prevcolor $this->fgcolor;
  7701.             $prevstyle $this->FontStyle;
  7702.             if (empty($color)) {
  7703.                 $this->SetTextColorArray($this->htmlLinkColorArray);
  7704.             else {
  7705.                 $this->SetTextColorArray($color);
  7706.             }
  7707.             if ($style == -1{
  7708.                 $this->SetFont(''$this->FontStyle.$this->htmlLinkFontStyle);
  7709.             else {
  7710.                 $this->SetFont(''$this->FontStyle.$style);
  7711.             }
  7712.             $ret $this->Write($this->lasth$name$url$fill''false0$firstline);
  7713.             // restore settings
  7714.             $this->SetFont(''$prevstyle);
  7715.             $this->SetTextColorArray($prevcolor);
  7716.             return $ret;
  7717.         }
  7718.         
  7719.         /**
  7720.          * Returns an associative array (keys: R,G,B) from an html color name or a six-digit or three-digit hexadecimal color representation (i.e. #3FE5AA or #7FF).
  7721.          * @param string $color html color
  7722.          * @return array RGB color or false in case of error.
  7723.          * @access public
  7724.          */        
  7725.         public function convertHTMLColorToDec($color='#FFFFFF'{
  7726.             global $webcolor;
  7727.             $returncolor false;
  7728.             $color preg_replace('/[\s]*/'''$color)// remove extra spaces
  7729.             $color strtolower($color);
  7730.             if (($dotpos strpos($color'.')) !== false{
  7731.                 // remove class parent (i.e.: color.red)
  7732.                 $color substr($color($dotpos 1));
  7733.             }
  7734.             if (strlen($color== 0{
  7735.                 return false;
  7736.             }
  7737.             if (substr($color03== 'rgb'{
  7738.                 $codes substr($color4);
  7739.                 $codes str_replace(')'''$codes);
  7740.                 $returncolor explode(','$codes3);
  7741.                 return $returncolor;
  7742.             }
  7743.             if (substr($color01!= '#'{
  7744.                 // decode color name
  7745.                 if (isset($webcolor[$color])) {
  7746.                     $color_code $webcolor[$color];
  7747.                 else {
  7748.                     return false;
  7749.                 }
  7750.             else {
  7751.                 $color_code substr($color1);
  7752.             }
  7753.             switch (strlen($color_code)) {
  7754.                 case 3{
  7755.                     // three-digit hexadecimal representation
  7756.                     $r substr($color_code01);
  7757.                     $g substr($color_code11);
  7758.                     $b substr($color_code21);
  7759.                     $returncolor['R'hexdec($r.$r);
  7760.                     $returncolor['G'hexdec($g.$g);
  7761.                     $returncolor['B'hexdec($b.$b);
  7762.                     break;
  7763.                 }
  7764.                 case 6{
  7765.                     // six-digit hexadecimal representation
  7766.                     $returncolor['R'hexdec(substr($color_code02));
  7767.                     $returncolor['G'hexdec(substr($color_code22));
  7768.                     $returncolor['B'hexdec(substr($color_code42));
  7769.                     break;
  7770.                 }
  7771.             }
  7772.             return $returncolor;
  7773.         }
  7774.         
  7775.         /**
  7776.          * Converts pixels to User's Units.
  7777.          * @param int $px pixels
  7778.          * @return float value in user's unit
  7779.          * @access public
  7780.          * @see setImageScale(), getImageScale()
  7781.          */
  7782.         public function pixelsToUnits($px{
  7783.             return ($px ($this->imgscale * $this->k));
  7784.         }
  7785.             
  7786.         /**
  7787.          * Reverse function for htmlentities.
  7788.          * Convert entities in UTF-8.
  7789.          * @param $text_to_convert Text to convert.
  7790.          * @return string converted
  7791.          * @access public
  7792.         */
  7793.         public function unhtmlentities($text_to_convert{
  7794.             return html_entity_decode($text_to_convertENT_QUOTES$this->encoding);
  7795.         }
  7796.         
  7797.         // ENCRYPTION METHODS ----------------------------------
  7798.         // SINCE 2.0.000 (2008-01-02)
  7799.         
  7800.         /**
  7801.         * Compute encryption key depending on object number where the encrypted data is stored
  7802.         * @param int $n object number
  7803.         * @access protected
  7804.         * @since 2.0.000 (2008-01-02)
  7805.         */
  7806.         protected function _objectkey($n{
  7807.             return substr($this->_md5_16($this->encryption_key.pack('VXxx'$n))010);
  7808.         }
  7809.         
  7810.         /**
  7811.          * Put encryption on PDF document.
  7812.          * @access protected
  7813.          * @since 2.0.000 (2008-01-02)
  7814.          */
  7815.         protected function _putencryption({
  7816.             $this->_out('/Filter /Standard');
  7817.             $this->_out('/V 1');
  7818.             $this->_out('/R 2');
  7819.             $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  7820.             $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  7821.             $this->_out('/P '.$this->Pvalue);
  7822.         }
  7823.         
  7824.         /**
  7825.         * Returns the input text exrypted using RC4 algorithm and the specified key.
  7826.         * RC4 is the standard encryption algorithm used in PDF format
  7827.         * @param string $key encryption key
  7828.         * @param String $text input text to be encrypted
  7829.         * @return String encrypted text
  7830.         * @access protected
  7831.         * @since 2.0.000 (2008-01-02)
  7832.         * @author Klemen Vodopivec
  7833.         */
  7834.         protected function _RC4($key$text{
  7835.             if ($this->last_rc4_key != $key{
  7836.                 $k str_repeat($key((256 strlen($key)) 1));
  7837.                 $rc4 range(0255);
  7838.                 $j 0;
  7839.                 for ($i 0$i 256++$i{
  7840.                     $t $rc4[$i];
  7841.                     $j ($j $t ord($k{$i})) 256;
  7842.                     $rc4[$i$rc4[$j];
  7843.                     $rc4[$j$t;
  7844.                 }
  7845.                 $this->last_rc4_key = $key;
  7846.                 $this->last_rc4_key_c = $rc4;
  7847.             else {
  7848.                 $rc4 $this->last_rc4_key_c;
  7849.             }
  7850.             $len strlen($text);
  7851.             $a 0;
  7852.             $b 0;
  7853.             $out '';
  7854.             for ($i 0$i $len++$i{
  7855.                 $a ($a 1256;
  7856.                 $t $rc4[$a];
  7857.                 $b ($b $t256;
  7858.                 $rc4[$a$rc4[$b];
  7859.                 $rc4[$b$t;
  7860.                 $k $rc4[($rc4[$a$rc4[$b]256];
  7861.                 $out .= chr(ord($text{$i}$k);
  7862.             }
  7863.             return $out;
  7864.         }
  7865.         
  7866.         /**
  7867.         * Encrypts a string using MD5 and returns it's value as a binary string.
  7868.         * @param string $str input string
  7869.         * @return String MD5 encrypted binary string
  7870.         * @access protected
  7871.         * @since 2.0.000 (2008-01-02)
  7872.         * @author Klemen Vodopivec
  7873.         */
  7874.         protected function _md5_16($str{
  7875.             return pack('H*'md5($str));
  7876.         }
  7877.         
  7878.         /**
  7879.         * Compute O value (used for RC4 encryption)
  7880.         * @param String $user_pass user password
  7881.         * @param String $owner_pass user password
  7882.         * @return String O value
  7883.         * @access protected
  7884.         * @since 2.0.000 (2008-01-02)
  7885.         * @author Klemen Vodopivec
  7886.         */
  7887.         protected function _Ovalue($user_pass$owner_pass{
  7888.             $tmp $this->_md5_16($owner_pass);
  7889.             $owner_RC4_key substr($tmp05);
  7890.             return $this->_RC4($owner_RC4_key$user_pass);
  7891.         }
  7892.         
  7893.         /**
  7894.         * Compute U value (used for RC4 encryption)
  7895.         * @return String U value
  7896.         * @access protected
  7897.         * @since 2.0.000 (2008-01-02)
  7898.         * @author Klemen Vodopivec
  7899.         */
  7900.         protected function _Uvalue({
  7901.             return $this->_RC4($this->encryption_key$this->padding);
  7902.         }
  7903.         
  7904.         /**
  7905.         * Compute encryption key
  7906.         * @param String $user_pass user password
  7907.         * @param String $owner_pass user password
  7908.         * @param String $protection protection type
  7909.         * @access protected
  7910.         * @since 2.0.000 (2008-01-02)
  7911.         * @author Klemen Vodopivec
  7912.         */
  7913.         protected function _generateencryptionkey($user_pass$owner_pass$protection{
  7914.             // Pad passwords
  7915.             $user_pass substr($user_pass.$this->padding032);
  7916.             $owner_pass substr($owner_pass.$this->padding032);
  7917.             // Compute O value
  7918.             $this->Ovalue = $this->_Ovalue($user_pass$owner_pass);
  7919.             // Compute encyption key
  7920.             $tmp $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
  7921.             $this->encryption_key = substr($tmp05);
  7922.             // Compute U value
  7923.             $this->Uvalue = $this->_Uvalue();
  7924.             // Compute P value
  7925.             $this->Pvalue = -(($protection^2551);
  7926.         }
  7927.         
  7928.         /**
  7929.         * Set document protection
  7930.         * The permission array is composed of values taken from the following ones:
  7931.         * - copy: copy text and images to the clipboard
  7932.         * - print: print the document
  7933.         * - modify: modify it (except for annotations and forms)
  7934.         * - annot-forms: add annotations and forms
  7935.         * Remark: the protection against modification is for people who have the full Acrobat product.
  7936.         * If you don't set any password, the document will open as usual. If you set a user password, the PDF viewer will ask for it before displaying the document. The master password, if different from the user one, can be used to get full access.
  7937.         * Note: protecting a document requires to encrypt it, which increases the processing time a lot. This can cause a PHP time-out in some cases, especially if the document contains images or fonts.
  7938.         * @param Array $permissions the set of permissions. Empty by default (only viewing is allowed). (print, modify, copy, annot-forms)
  7939.         * @param String $user_pass user password. Empty by default.
  7940.         * @param String $owner_pass owner password. If not specified, a random value is used.
  7941.         * @access public
  7942.         * @since 2.0.000 (2008-01-02)
  7943.         * @author Klemen Vodopivec
  7944.         */
  7945.         public function SetProtection($permissions=array()$user_pass=''$owner_pass=null{
  7946.             $options array('print' => 4'modify' => 8'copy' => 16'annot-forms' => 32);
  7947.             $protection 192;
  7948.             foreach ($permissions as $permission{
  7949.                 if (!isset($options[$permission])) {
  7950.                     $this->Error('Incorrect permission: '.$permission);
  7951.                 }
  7952.                 $protection += $options[$permission];
  7953.             }
  7954.             if ($owner_pass === null{
  7955.                 $owner_pass uniqid(rand());
  7956.             }
  7957.             $this->encrypted = true;
  7958.             $this->_generateencryptionkey($user_pass$owner_pass$protection);
  7959.         }
  7960.         
  7961.         // END OF ENCRYPTION FUNCTIONS -------------------------
  7962.         
  7963.         // START TRANSFORMATIONS SECTION -----------------------
  7964.         
  7965.         /**
  7966.         * Starts a 2D tranformation saving current graphic state.
  7967.         * This function must be called before scaling, mirroring, translation, rotation and skewing.
  7968.         * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  7969.         * @access public
  7970.         * @since 2.1.000 (2008-01-07)
  7971.         * @see StartTransform(), StopTransform()
  7972.         */
  7973.         public function StartTransform({
  7974.             $this->_out('q');
  7975.             $this->transfmrk[$this->page][$this->pagelen[$this->page];
  7976.             ++$this->transfmatrix_key;
  7977.             $this->transfmatrix[$this->transfmatrix_keyarray();
  7978.         }
  7979.         
  7980.         /**
  7981.         * Stops a 2D tranformation restoring previous graphic state.
  7982.         * This function must be called after scaling, mirroring, translation, rotation and skewing.
  7983.         * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  7984.         * @access public
  7985.         * @since 2.1.000 (2008-01-07)
  7986.         * @see StartTransform(), StopTransform()
  7987.         */
  7988.         public function StopTransform({
  7989.             $this->_out('Q');
  7990.             if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  7991.                 array_pop($this->transfmatrix[$this->transfmatrix_key]);
  7992.                 --$this->transfmatrix_key;
  7993.             }
  7994.             array_pop($this->transfmrk[$this->page]);
  7995.         }
  7996.         /**
  7997.         * Horizontal Scaling.
  7998.         * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  7999.         * @param int $x abscissa of the scaling center. Default is current x position
  8000.         * @param int $y ordinate of the scaling center. Default is current y position
  8001.         * @access public
  8002.         * @since 2.1.000 (2008-01-07)
  8003.         * @see StartTransform(), StopTransform()
  8004.         */
  8005.         public function ScaleX($s_x$x=''$y=''{
  8006.             $this->Scale($s_x100$x$y);
  8007.         }
  8008.         
  8009.         /**
  8010.         * Vertical Scaling.
  8011.         * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  8012.         * @param int $x abscissa of the scaling center. Default is current x position
  8013.         * @param int $y ordinate of the scaling center. Default is current y position
  8014.         * @access public
  8015.         * @since 2.1.000 (2008-01-07)
  8016.         * @see StartTransform(), StopTransform()
  8017.         */
  8018.         public function ScaleY($s_y$x=''$y=''{
  8019.             $this->Scale(100$s_y$x$y);
  8020.         }
  8021.         
  8022.         /**
  8023.         * Vertical and horizontal proportional Scaling.
  8024.         * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  8025.         * @param int $x abscissa of the scaling center. Default is current x position
  8026.         * @param int $y ordinate of the scaling center. Default is current y position
  8027.         * @access public
  8028.         * @since 2.1.000 (2008-01-07)
  8029.         * @see StartTransform(), StopTransform()
  8030.         */
  8031.         public function ScaleXY($s$x=''$y=''{
  8032.             $this->Scale($s$s$x$y);
  8033.         }
  8034.         
  8035.         /**
  8036.         * Vertical and horizontal non-proportional Scaling.
  8037.         * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  8038.         * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  8039.         * @param int $x abscissa of the scaling center. Default is current x position
  8040.         * @param int $y ordinate of the scaling center. Default is current y position
  8041.         * @access public
  8042.         * @since 2.1.000 (2008-01-07)
  8043.         * @see StartTransform(), StopTransform()
  8044.         */
  8045.         public function Scale($s_x$s_y$x=''$y=''{
  8046.             if ($x === ''{
  8047.                 $x $this->x;
  8048.             }
  8049.             if ($y === ''{
  8050.                 $y $this->y;
  8051.             }
  8052.             if ($this->rtl{
  8053.                 $x $this->w - $x;
  8054.             }
  8055.             if (($s_x == 0OR ($s_y == 0)) {
  8056.                 $this->Error('Please do not use values equal to zero for scaling');
  8057.             }
  8058.             $y ($this->h - $y$this->k;
  8059.             $x *= $this->k;
  8060.             //calculate elements of transformation matrix
  8061.             $s_x /= 100;
  8062.             $s_y /= 100;
  8063.             $tm[0$s_x;
  8064.             $tm[10;
  8065.             $tm[20;
  8066.             $tm[3$s_y;
  8067.             $tm[4$x ($s_x);
  8068.             $tm[5$y ($s_y);
  8069.             //scale the coordinate system
  8070.             $this->Transform($tm);
  8071.         }
  8072.         
  8073.         /**
  8074.         * Horizontal Mirroring.
  8075.         * @param int $x abscissa of the point. Default is current x position
  8076.         * @access public
  8077.         * @since 2.1.000 (2008-01-07)
  8078.         * @see StartTransform(), StopTransform()
  8079.         */
  8080.         public function MirrorH($x=''{
  8081.             $this->Scale(-100100$x);
  8082.         }
  8083.         
  8084.         /**
  8085.         * Verical Mirroring.
  8086.         * @param int $y ordinate of the point. Default is current y position
  8087.         * @access public
  8088.         * @since 2.1.000 (2008-01-07)
  8089.         * @see StartTransform(), StopTransform()
  8090.         */
  8091.         public function MirrorV($y=''{
  8092.             $this->Scale(100-100''$y);
  8093.         }
  8094.         
  8095.         /**
  8096.         * Point reflection mirroring.
  8097.         * @param int $x abscissa of the point. Default is current x position
  8098.         * @param int $y ordinate of the point. Default is current y position
  8099.         * @access public
  8100.         * @since 2.1.000 (2008-01-07)
  8101.         * @see StartTransform(), StopTransform()
  8102.         */
  8103.         public function MirrorP($x='',$y=''{
  8104.             $this->Scale(-100-100$x$y);
  8105.         }
  8106.         
  8107.         /**
  8108.         * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  8109.         * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  8110.         * @param int $x abscissa of the point. Default is current x position
  8111.         * @param int $y ordinate of the point. Default is current y position
  8112.         * @access public
  8113.         * @since 2.1.000 (2008-01-07)
  8114.         * @see StartTransform(), StopTransform()
  8115.         */
  8116.         public function MirrorL($angle=0$x='',$y=''{
  8117.             $this->Scale(-100100$x$y);
  8118.             $this->Rotate(-2*($angle-90)$x$y);
  8119.         }
  8120.         
  8121.         /**
  8122.         * Translate graphic object horizontally.
  8123.         * @param int $t_x movement to the right (or left for RTL)
  8124.         * @access public
  8125.         * @since 2.1.000 (2008-01-07)
  8126.         * @see StartTransform(), StopTransform()
  8127.         */
  8128.         public function TranslateX($t_x{
  8129.             $this->Translate($t_x0);
  8130.         }
  8131.         
  8132.         /**
  8133.         * Translate graphic object vertically.
  8134.         * @param int $t_y movement to the bottom
  8135.         * @access public
  8136.         * @since 2.1.000 (2008-01-07)
  8137.         * @see StartTransform(), StopTransform()
  8138.         */
  8139.         public function TranslateY($t_y{
  8140.             $this->Translate(0$t_y);
  8141.         }
  8142.         
  8143.         /**
  8144.         * Translate graphic object horizontally and vertically.
  8145.         * @param int $t_x movement to the right
  8146.         * @param int $t_y movement to the bottom
  8147.         * @access public
  8148.         * @since 2.1.000 (2008-01-07)
  8149.         * @see StartTransform(), StopTransform()
  8150.         */
  8151.         public function Translate($t_x$t_y{
  8152.             if ($this->rtl{
  8153.                 $t_x = -$t_x;
  8154.             }
  8155.             //calculate elements of transformation matrix
  8156.             $tm[01;
  8157.             $tm[10;
  8158.             $tm[20;
  8159.             $tm[31;
  8160.             $tm[4$t_x $this->k;
  8161.             $tm[5= -$t_y $this->k;
  8162.             //translate the coordinate system
  8163.             $this->Transform($tm);
  8164.         }
  8165.         
  8166.         /**
  8167.         * Rotate object.
  8168.         * @param float $angle angle in degrees for counter-clockwise rotation
  8169.         * @param int $x abscissa of the rotation center. Default is current x position
  8170.         * @param int $y ordinate of the rotation center. Default is current y position
  8171.         * @access public
  8172.         * @since 2.1.000 (2008-01-07)
  8173.         * @see StartTransform(), StopTransform()
  8174.         */
  8175.         public function Rotate($angle$x=''$y=''{
  8176.             if ($x === ''{
  8177.                 $x $this->x;
  8178.             }
  8179.             if ($y === ''{
  8180.                 $y $this->y;
  8181.             }
  8182.             if ($this->rtl{
  8183.                 $x $this->w - $x;
  8184.                 $angle = -$angle;
  8185.             }
  8186.             $y ($this->h - $y$this->k;
  8187.             $x *= $this->k;
  8188.             //calculate elements of transformation matrix
  8189.             $tm[0cos(deg2rad($angle));
  8190.             $tm[1sin(deg2rad($angle));
  8191.             $tm[2= -$tm[1];
  8192.             $tm[3$tm[0];
  8193.             $tm[4$x ($tm[1$y($tm[0$x);
  8194.             $tm[5$y ($tm[0$y($tm[1$x);
  8195.             //rotate the coordinate system around ($x,$y)
  8196.             $this->Transform($tm);
  8197.         }
  8198.         
  8199.         /**
  8200.         * Skew horizontally.
  8201.         * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  8202.         * @param int $x abscissa of the skewing center. default is current x position
  8203.         * @param int $y ordinate of the skewing center. default is current y position
  8204.         * @access public
  8205.         * @since 2.1.000 (2008-01-07)
  8206.         * @see StartTransform(), StopTransform()
  8207.         */
  8208.         public function SkewX($angle_x$x=''$y=''{
  8209.             $this->Skew($angle_x0$x$y);
  8210.         }
  8211.         
  8212.         /**
  8213.         * Skew vertically.
  8214.         * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  8215.         * @param int $x abscissa of the skewing center. default is current x position
  8216.         * @param int $y ordinate of the skewing center. default is current y position
  8217.         * @access public
  8218.         * @since 2.1.000 (2008-01-07)
  8219.         * @see StartTransform(), StopTransform()
  8220.         */
  8221.         public function SkewY($angle_y$x=''$y=''{
  8222.             $this->Skew(0$angle_y$x$y);
  8223.         }
  8224.         
  8225.         /**
  8226.         * Skew.
  8227.         * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  8228.         * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  8229.         * @param int $x abscissa of the skewing center. default is current x position
  8230.         * @param int $y ordinate of the skewing center. default is current y position
  8231.         * @access public
  8232.         * @since 2.1.000 (2008-01-07)
  8233.         * @see StartTransform(), StopTransform()
  8234.         */
  8235.         public function Skew($angle_x$angle_y$x=''$y=''{
  8236.             if ($x === ''{
  8237.                 $x $this->x;
  8238.             }
  8239.             if ($y === ''{
  8240.                 $y $this->y;
  8241.             }
  8242.             if ($this->rtl{
  8243.                 $x $this->w - $x;
  8244.                 $angle_x = -$angle_x;
  8245.             }
  8246.             if (($angle_x <= -90OR ($angle_x >= 90OR ($angle_y <= -90OR ($angle_y >= 90)) {
  8247.                 $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  8248.             }
  8249.             $x *= $this->k;
  8250.             $y ($this->h - $y$this->k;
  8251.             //calculate elements of transformation matrix
  8252.             $tm[01;
  8253.             $tm[1tan(deg2rad($angle_y));
  8254.             $tm[2tan(deg2rad($angle_x));
  8255.             $tm[31;
  8256.             $tm[4= -$tm[2$y;
  8257.             $tm[5= -$tm[1$x;
  8258.             //skew the coordinate system
  8259.             $this->Transform($tm);
  8260.         }
  8261.         
  8262.         /**
  8263.         * Apply graphic transformations.
  8264.         * @access protected
  8265.         * @since 2.1.000 (2008-01-07)
  8266.         * @see StartTransform(), StopTransform()
  8267.         */
  8268.         protected function Transform($tm{
  8269.             $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'$tm[0]$tm[1]$tm[2]$tm[3]$tm[4]$tm[5]));
  8270.             // add tranformation matrix
  8271.             $this->transfmatrix[$this->transfmatrix_key][array('a' => $tm[0]'b' => $tm[1]'c' => $tm[2]'d' => $tm[3]'e' => $tm[4]'f' => $tm[5]);
  8272.             // update tranformation mark
  8273.             if (end($this->transfmrk[$this->page]!== false{
  8274.                 $key key($this->transfmrk[$this->page]);
  8275.                 $this->transfmrk[$this->page][$key$this->pagelen[$this->page];
  8276.             }
  8277.         }
  8278.         
  8279.         // END TRANSFORMATIONS SECTION -------------------------
  8280.         
  8281.         
  8282.         // START GRAPHIC FUNCTIONS SECTION ---------------------
  8283.         // The following section is based on the code provided by David Hernandez Sanz
  8284.         
  8285.         /**
  8286.         * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
  8287.         * @param float $width The width.
  8288.         * @access public
  8289.         * @since 1.0
  8290.         * @see Line(), Rect(), Cell(), MultiCell()
  8291.         */
  8292.         public function SetLineWidth($width{
  8293.             //Set line width
  8294.             $this->LineWidth = $width;
  8295.             $this->linestyleWidth = sprintf('%.2F w'($width $this->k));
  8296.             if ($this->page > 0{
  8297.                 $this->_out($this->linestyleWidth);
  8298.             }
  8299.         }
  8300.         
  8301.         /**
  8302.         * Returns the current the line width.
  8303.         * @return int Line width
  8304.         * @access public
  8305.         * @since 2.1.000 (2008-01-07)
  8306.         * @see Line(), SetLineWidth()
  8307.         */
  8308.         public function GetLineWidth({
  8309.             return $this->LineWidth;
  8310.         }
  8311.         
  8312.         /**
  8313.         * Set line style.
  8314.         * @param array $style Line style. Array with keys among the following:
  8315.         *  <ul>
  8316.         *      <li>width (float): Width of the line in user units.</li>
  8317.         *      <li>cap (string): Type of cap to put on the line. Possible values are:
  8318.         *  butt, round, square. The difference between "square" and "butt" is that
  8319.         *  "square" projects a flat end past the end of the line.</li>
  8320.         *      <li>join (string): Type of join. Possible values are: miter, round,
  8321.         *  bevel.</li>
  8322.         *      <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  8323.         *  series of length values, which are the lengths of the on and off dashes.
  8324.         *  For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  8325.         *  1 off, 2 on, 1 off, ...</li>
  8326.         *      <li>phase (integer): Modifier on the dash pattern which is used to shift
  8327.         *  the point at which the pattern starts.</li>
  8328.         *      <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  8329.         *  </ul>
  8330.         * @access public
  8331.         * @since 2.1.000 (2008-01-08)
  8332.         */
  8333.         public function SetLineStyle($style{
  8334.             if (!is_array($style)) {
  8335.                 return;
  8336.             }
  8337.             extract($style);
  8338.             if (isset($width)) {
  8339.                 $width_prev $this->LineWidth;
  8340.                 $this->SetLineWidth($width);
  8341.                 $this->LineWidth = $width_prev;
  8342.             }
  8343.             if (isset($cap)) {
  8344.                 $ca array('butt' => 0'round'=> 1'square' => 2);
  8345.                 if (isset($ca[$cap])) {
  8346.                     $this->linestyleCap = $ca[$cap].' J';
  8347.                     $this->_out($this->linestyleCap);
  8348.                 }
  8349.             }
  8350.             if (isset($join)) {
  8351.                 $ja array('miter' => 0'round' => 1'bevel' => 2);
  8352.                 if (isset($ja[$join])) {
  8353.                     $this->linestyleJoin = $ja[$join].' j';
  8354.                     $this->_out($this->linestyleJoin);
  8355.                 }
  8356.             }
  8357.             if (isset($dash)) {
  8358.                 $dash_string '';
  8359.                 if ($dash{
  8360.                     if (preg_match('/^.+,/'$dash0{
  8361.                         $tab explode(','$dash);
  8362.                     else {
  8363.                         $tab array($dash);
  8364.                     }
  8365.                     $dash_string '';
  8366.                     foreach ($tab as $i => $v{
  8367.                         if ($i{
  8368.                             $dash_string .= ' ';
  8369.                         }
  8370.                         $dash_string .= sprintf("%.2F"$v);
  8371.                     }
  8372.                 }
  8373.                 if (!isset($phaseOR !$dash{
  8374.                     $phase 0;
  8375.                 }
  8376.                 $this->linestyleDash = sprintf("[%s] %.2F d"$dash_string$phase);
  8377.                 $this->_out($this->linestyleDash);
  8378.             }
  8379.             if (isset($color)) {
  8380.                 $this->SetDrawColorArray($color);
  8381.             }
  8382.         }
  8383.         
  8384.         /*
  8385.         * Set a draw point.
  8386.         * @param float $x Abscissa of point.
  8387.         * @param float $y Ordinate of point.
  8388.         * @access protected
  8389.         * @since 2.1.000 (2008-01-08)
  8390.         */
  8391.         protected function _outPoint($x$y{
  8392.             if ($this->rtl{
  8393.                 $x $this->w - $x;
  8394.             }
  8395.             $this->_out(sprintf("%.2F %.2F m"$x $this->k($this->h - $y$this->k));
  8396.         }
  8397.         
  8398.         /*
  8399.         * Draws a line from last draw point.
  8400.         * @param float $x Abscissa of end point.
  8401.         * @param float $y Ordinate of end point.
  8402.         * @access protected
  8403.         * @since 2.1.000 (2008-01-08)
  8404.         */
  8405.         protected function _outLine($x$y{
  8406.             if ($this->rtl{
  8407.                 $x $this->w - $x;
  8408.             }
  8409.             $this->_out(sprintf("%.2F %.2F l"$x $this->k($this->h - $y$this->k));
  8410.         }
  8411.         
  8412.         /**
  8413.         * Draws a rectangle.
  8414.         * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  8415.         * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  8416.         * @param float $w Width.
  8417.         * @param float $h Height.
  8418.         * @param string $op options
  8419.         * @access protected
  8420.         * @since 2.1.000 (2008-01-08)
  8421.         */
  8422.         protected function _outRect($x$y$w$h$op{
  8423.             if ($this->rtl{
  8424.                 $x $this->w - $x $w;
  8425.             }
  8426.             $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s'$x*$this->k($this->h-$y)*$this->k$w*$this->k-$h*$this->k$op));
  8427.         }
  8428.         
  8429.         /*
  8430.         * Draws a Bezier curve from last draw point.
  8431.         * The Bezier curve is a tangent to the line between the control points at either end of the curve.
  8432.         * @param float $x1 Abscissa of control point 1.
  8433.         * @param float $y1 Ordinate of control point 1.
  8434.         * @param float $x2 Abscissa of control point 2.
  8435.         * @param float $y2 Ordinate of control point 2.
  8436.         * @param float $x3 Abscissa of end point.
  8437.         * @param float $y3 Ordinate of end point.
  8438.         * @access protected
  8439.         * @since 2.1.000 (2008-01-08)
  8440.         */
  8441.         protected function _outCurve($x1$y1$x2$y2$x3$y3{
  8442.             if ($this->rtl{
  8443.                 $x1 $this->w - $x1;
  8444.                 $x2 $this->w - $x2;
  8445.                 $x3 $this->w - $x3;
  8446.             }
  8447.             $this->_out(sprintf("%.2F %.2F %.2F %.2F %.2F %.2F c"$x1 $this->k($this->h - $y1$this->k$x2 $this->k($this->h - $y2$this->k$x3 $this->k($this->h - $y3$this->k));
  8448.         }
  8449.         
  8450.         /**
  8451.         * Draws a line between two points.
  8452.         * @param float $x1 Abscissa of first point.
  8453.         * @param float $y1 Ordinate of first point.
  8454.         * @param float $x2 Abscissa of second point.
  8455.         * @param float $y2 Ordinate of second point.
  8456.         * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8457.         * @access public
  8458.         * @since 1.0
  8459.         * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  8460.         */
  8461.         public function Line($x1$y1$x2$y2$style=array()) {
  8462.             if (is_array($style)) {
  8463.                 $this->SetLineStyle($style);
  8464.             }
  8465.             $this->_outPoint($x1$y1);
  8466.             $this->_outLine($x2$y2);
  8467.             $this->_out(' S');
  8468.         }
  8469.         
  8470.         /**
  8471.         * Draws a rectangle.
  8472.         * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  8473.         * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  8474.         * @param float $w Width.
  8475.         * @param float $h Height.
  8476.         * @param string $style Style of rendering. Possible values are:
  8477.         *  <ul>
  8478.         *      <li>D or empty string: Draw (default).</li>
  8479.         *      <li>F: Fill.</li>
  8480.         *      <li>DF or FD: Draw and fill.</li>
  8481.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8482.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8483.         *  </ul>
  8484.         * @param array $border_style Border style of rectangle. Array with keys among the following:
  8485.         *  <ul>
  8486.         *      <li>all: Line style of all borders. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8487.         *      <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8488.         *  </ul>
  8489.         *  If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  8490.         * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8491.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  8492.         * @access public
  8493.         * @since 1.0
  8494.         * @see SetLineStyle()
  8495.         */
  8496.         public function Rect($x$y$w$h$style=''$border_style=array()$fill_color=array()) {
  8497.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  8498.                 $this->SetFillColorArray($fill_color);
  8499.             }
  8500.             switch ($style{
  8501.                 case 'F'{
  8502.                     $op 'f';
  8503.                     $border_style array();
  8504.                     $this->_outRect($x$y$w$h$op);
  8505.                     break;
  8506.                 }
  8507.                 case 'DF':
  8508.                 case 'FD'{
  8509.                     if ((!$border_styleOR (isset($border_style['all']))) {
  8510.                         $op 'B';
  8511.                         if (isset($border_style['all'])) {
  8512.                             $this->SetLineStyle($border_style['all']);
  8513.                             $border_style array();
  8514.                         }
  8515.                     else {
  8516.                         $op 'f';
  8517.                     }
  8518.                     $this->_outRect($x$y$w$h$op);
  8519.                     break;
  8520.                 }
  8521.                 case 'CNZ'{
  8522.                     $op 'W n';
  8523.                     $this->_outRect($x$y$w$h$op);
  8524.                     break;
  8525.                 }
  8526.                 case 'CEO'{
  8527.                     $op 'W* n';
  8528.                     $this->_outRect($x$y$w$h$op);
  8529.                     break;
  8530.                 }
  8531.                 default{
  8532.                     $op 'S';
  8533.                     if ((!$border_styleOR (isset($border_style['all']))) {
  8534.                         if (isset($border_style['all']AND $border_style['all']{
  8535.                             $this->SetLineStyle($border_style['all']);
  8536.                             $border_style array();
  8537.                         }
  8538.                         $this->_outRect($x$y$w$h$op);
  8539.                     }
  8540.                     break;
  8541.                 }
  8542.             }
  8543.             if ($border_style{
  8544.                 $border_style2 array();
  8545.                 foreach ($border_style as $line => $value{
  8546.                     $lenght strlen($line);
  8547.                     for ($i 0$i $lenght++$i{
  8548.                         $border_style2[$line[$i]] $value;
  8549.                     }
  8550.                 }
  8551.                 $border_style $border_style2;
  8552.                 if (isset($border_style['L']AND $border_style['L']{
  8553.                     $this->Line($x$y$x$y $h$border_style['L']);
  8554.                 }
  8555.                 if (isset($border_style['T']AND $border_style['T']{
  8556.                     $this->Line($x$y$x $w$y$border_style['T']);
  8557.                 }
  8558.                 if (isset($border_style['R']AND $border_style['R']{
  8559.                     $this->Line($x $w$y$x $w$y $h$border_style['R']);
  8560.                 }
  8561.                 if (isset($border_style['B']AND $border_style['B']{
  8562.                     $this->Line($x$y $h$x $w$y $h$border_style['B']);
  8563.                 }
  8564.             }
  8565.         }
  8566.         
  8567.         
  8568.         /**
  8569.         * Draws a Bezier curve.
  8570.         * The Bezier curve is a tangent to the line between the control points at
  8571.         * either end of the curve.
  8572.         * @param float $x0 Abscissa of start point.
  8573.         * @param float $y0 Ordinate of start point.
  8574.         * @param float $x1 Abscissa of control point 1.
  8575.         * @param float $y1 Ordinate of control point 1.
  8576.         * @param float $x2 Abscissa of control point 2.
  8577.         * @param float $y2 Ordinate of control point 2.
  8578.         * @param float $x3 Abscissa of end point.
  8579.         * @param float $y3 Ordinate of end point.
  8580.         * @param string $style Style of rendering. Possible values are:
  8581.         *  <ul>
  8582.         *      <li>D or empty string: Draw (default).</li>
  8583.         *      <li>F: Fill.</li>
  8584.         *      <li>DF or FD: Draw and fill.</li>
  8585.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8586.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8587.         *  </ul>
  8588.         * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8589.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  8590.         * @access public
  8591.         * @see SetLineStyle()
  8592.         * @since 2.1.000 (2008-01-08)
  8593.         */
  8594.         public function Curve($x0$y0$x1$y1$x2$y2$x3$y3$style=''$line_style=array()$fill_color=array()) {
  8595.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  8596.                 $this->SetFillColorArray($fill_color);
  8597.             }
  8598.             switch ($style{
  8599.                 case 'F'{
  8600.                     $op 'f';
  8601.                     $line_style array();
  8602.                     break;
  8603.                 }
  8604.                 case 'FD'
  8605.                 case 'DF'{
  8606.                     $op 'B';
  8607.                     break;
  8608.                 }
  8609.                 case 'CNZ'{
  8610.                     $op 'W n';
  8611.                     break;
  8612.                 }
  8613.                 case 'CEO'{
  8614.                     $op 'W* n';
  8615.                     break;
  8616.                 }
  8617.                 default{
  8618.                     $op 'S';
  8619.                     break;
  8620.                 }
  8621.             }
  8622.             if ($line_style{
  8623.                 $this->SetLineStyle($line_style);
  8624.             }
  8625.             $this->_outPoint($x0$y0);
  8626.             $this->_outCurve($x1$y1$x2$y2$x3$y3);
  8627.             $this->_out($op);
  8628.         }
  8629.         
  8630.         /**
  8631.         * Draws a poly-Bezier curve.
  8632.         * Each Bezier curve segment is a tangent to the line between the control points at
  8633.         * either end of the curve.
  8634.         * @param float $x0 Abscissa of start point.
  8635.         * @param float $y0 Ordinate of start point.
  8636.         * @param float $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  8637.         * @param string $style Style of rendering. Possible values are:
  8638.         *  <ul>
  8639.         *      <li>D or empty string: Draw (default).</li>
  8640.         *      <li>F: Fill.</li>
  8641.         *      <li>DF or FD: Draw and fill.</li>
  8642.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8643.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8644.         *  </ul>
  8645.         * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8646.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  8647.         * @access public
  8648.         * @see SetLineStyle()
  8649.         * @since 3.0008 (2008-05-12)
  8650.         */
  8651.         public function Polycurve($x0$y0$segments$style=''$line_style=array()$fill_color=array()) {
  8652.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  8653.                 $this->SetFillColorArray($fill_color);
  8654.             }
  8655.             switch ($style{
  8656.                 case 'F'{
  8657.                     $op 'f';
  8658.                     $line_style array();
  8659.                     break;
  8660.                 }
  8661.                 case 'FD':
  8662.                 case 'DF'{
  8663.                     $op 'B';
  8664.                     break;
  8665.                 }
  8666.                 case 'CNZ'{
  8667.                     $op 'W n';
  8668.                     break;
  8669.                 }
  8670.                 case 'CEO'{
  8671.                     $op 'W* n';
  8672.                     break;
  8673.                 }
  8674.                 default{
  8675.                     $op 'S';
  8676.                     break;
  8677.                 }
  8678.             }
  8679.             if ($line_style{
  8680.                 $this->SetLineStyle($line_style);
  8681.             }
  8682.             $this->_outPoint($x0$y0);
  8683.             foreach ($segments as $segment{
  8684.                 list($x1$y1$x2$y2$x3$y3$segment;
  8685.                 $this->_outCurve($x1$y1$x2$y2$x3$y3);
  8686.             }    
  8687.             $this->_out($op);
  8688.         }
  8689.         
  8690.         /**
  8691.         * Draws an ellipse.
  8692.         * An ellipse is formed from n Bezier curves.
  8693.         * @param float $x0 Abscissa of center point.
  8694.         * @param float $y0 Ordinate of center point.
  8695.         * @param float $rx Horizontal radius.
  8696.         * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  8697.         * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  8698.         * @param float $astart: Angle start of draw line. Default value: 0.
  8699.         * @param float $afinish: Angle finish of draw line. Default value: 360.
  8700.         * @param string $style Style of rendering. Possible values are:
  8701.         *  <ul>
  8702.         *      <li>D or empty string: Draw (default).</li>
  8703.         *      <li>F: Fill.</li>
  8704.         *      <li>DF or FD: Draw and fill.</li>
  8705.         *      <li>C: Draw close.</li>
  8706.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8707.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8708.         *  </ul>
  8709.         * @param array $line_style Line style of ellipse. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8710.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  8711.         * @param integer $nc Number of curves used in ellipse. Default value: 8.
  8712.         * @access public
  8713.         * @since 2.1.000 (2008-01-08)
  8714.         */
  8715.         public function Ellipse($x0$y0$rx$ry=0$angle=0$astart=0$afinish=360$style=''$line_style=array()$fill_color=array()$nc=8{
  8716.             if ($angle{
  8717.                 $this->StartTransform();
  8718.                 $this->Rotate($angle$x0$y0);
  8719.                 $this->Ellipse($x0$y0$rx$ry0$astart$afinish$style$line_style$fill_color$nc);
  8720.                 $this->StopTransform();
  8721.                 return;
  8722.             }
  8723.             if ($rx{
  8724.                 if (!(false === strpos($style'F')) AND isset($fill_color)) {
  8725.                     $this->SetFillColorArray($fill_color);
  8726.                 }
  8727.                 switch ($style{
  8728.                     case 'F'{
  8729.                         $op 'f';
  8730.                         $line_style array();
  8731.                         break;
  8732.                     }
  8733.                     case 'FD'
  8734.                     case 'DF'{
  8735.                         $op 'B';
  8736.                         break;
  8737.                     }
  8738.                     case 'C'{
  8739.                         $op 's'// Small 's' signifies closing the path as well
  8740.                         break;
  8741.                     }
  8742.                     case 'CNZ'{
  8743.                         $op 'W n';
  8744.                         break;
  8745.                     }
  8746.                     case 'CEO'{
  8747.                         $op 'W* n';
  8748.                         break;
  8749.                     }
  8750.                     default{
  8751.                         $op 'S';
  8752.                         break;
  8753.                     }
  8754.                 }
  8755.                 if ($line_style{
  8756.                     $this->SetLineStyle($line_style);
  8757.                 }
  8758.                 if (!$ry{
  8759.                     $ry $rx;
  8760.                 }
  8761.                 $rx *= $this->k;
  8762.                 $ry *= $this->k;
  8763.                 if ($nc 2{
  8764.                     $nc 2;
  8765.                 }
  8766.                 $astart deg2rad((float) $astart);
  8767.                 $afinish deg2rad((float) $afinish);
  8768.                 $total_angle $afinish $astart;
  8769.                 $dt $total_angle $nc;
  8770.                 $dtm $dt 3;
  8771.                 $x0 *= $this->k;
  8772.                 $y0 ($this->h - $y0$this->k;
  8773.                 $t1 $astart;
  8774.                 $a0 $x0 ($rx cos($t1));
  8775.                 $b0 $y0 ($ry sin($t1));
  8776.                 $c0 = -$rx sin($t1);
  8777.                 $d0 $ry cos($t1);
  8778.                 $this->_outPoint($a0 $this->k$this->h - ($b0 $this->k));
  8779.                 for ($i 1$i <= $nc++$i{
  8780.                     // Draw this bit of the total curve
  8781.                     $t1 ($i $dt$astart;
  8782.                     $a1 $x0 ($rx cos($t1));
  8783.                     $b1 $y0 ($ry sin($t1));
  8784.                     $c1 = -$rx sin($t1);
  8785.                     $d1 $ry cos($t1);
  8786.                     $this->_outCurve(($a0 ($c0 $dtm)) $this->k$this->h - (($b0 ($d0 $dtm)) $this->k)($a1 ($c1 $dtm)) $this->k$this->h - (($b1 ($d1 $dtm)) $this->k)$a1 $this->k$this->h - ($b1 $this->k));
  8787.                     $a0 $a1;
  8788.                     $b0 $b1;
  8789.                     $c0 $c1;
  8790.                     $d0 $d1;
  8791.                 }
  8792.                 $this->_out($op);
  8793.             }
  8794.         }
  8795.         
  8796.         /**
  8797.         * Draws a circle.
  8798.         * A circle is formed from n Bezier curves.
  8799.         * @param float $x0 Abscissa of center point.
  8800.         * @param float $y0 Ordinate of center point.
  8801.         * @param float $r Radius.
  8802.         * @param float $astart: Angle start of draw line. Default value: 0.
  8803.         * @param float $afinish: Angle finish of draw line. Default value: 360.
  8804.         * @param string $style Style of rendering. Possible values are:
  8805.         *  <ul>
  8806.         *      <li>D or empty string: Draw (default).</li>
  8807.         *      <li>F: Fill.</li>
  8808.         *      <li>DF or FD: Draw and fill.</li>
  8809.         *      <li>C: Draw close.</li>
  8810.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8811.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8812.         *  </ul>
  8813.         * @param array $line_style Line style of circle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8814.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  8815.         * @param integer $nc Number of curves used in circle. Default value: 8.
  8816.         * @access public
  8817.         * @since 2.1.000 (2008-01-08)
  8818.         */
  8819.         public function Circle($x0$y0$r$astart=0$afinish=360$style=''$line_style=array()$fill_color=array()$nc=8{
  8820.             $this->Ellipse($x0$y0$r00$astart$afinish$style$line_style$fill_color$nc);
  8821.         }
  8822.  
  8823.         /**
  8824.         * Draws a polygonal line
  8825.         * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  8826.         * @param string $style Style of rendering. Possible values are:
  8827.         *  <ul>
  8828.         *      <li>D or empty string: Draw (default).</li>
  8829.         *      <li>F: Fill.</li>
  8830.         *      <li>DF or FD: Draw and fill.</li>
  8831.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8832.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8833.         *  </ul>
  8834.         * @param array $line_style Line style of polygon. Array with keys among the following:
  8835.         *  <ul>
  8836.         *      <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8837.         *      <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8838.         *  </ul>
  8839.         *  If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  8840.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  8841.         * @param boolean $closed if true the polygon is closes, otherwise will remain open
  8842.         * @access public
  8843.         * @since 4.8.003 (2009-09-15)
  8844.         */
  8845.         public function PolyLine($p$style=''$line_style=array()$fill_color=array()) {
  8846.             $this->Polygon($p$style$line_style$fill_colorfalse);
  8847.         }
  8848.  
  8849.         /**
  8850.         * Draws a polygon.
  8851.         * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  8852.         * @param string $style Style of rendering. Possible values are:
  8853.         *  <ul>
  8854.         *      <li>D or empty string: Draw (default).</li>
  8855.         *      <li>F: Fill.</li>
  8856.         *      <li>DF or FD: Draw and fill.</li>
  8857.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8858.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8859.         *  </ul>
  8860.         * @param array $line_style Line style of polygon. Array with keys among the following:
  8861.         *  <ul>
  8862.         *      <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8863.         *      <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8864.         *  </ul>
  8865.         *  If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  8866.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  8867.         * @param boolean $closed if true the polygon is closes, otherwise will remain open
  8868.         * @access public
  8869.         * @since 2.1.000 (2008-01-08)
  8870.         */
  8871.         public function Polygon($p$style=''$line_style=array()$fill_color=array()$closed=true{
  8872.             $nc count($p)// number of coordinates
  8873.             $np $nc 2// number of points
  8874.             if ($closed{
  8875.                 // close polygon by adding the first 2 points at the end (one line)
  8876.                 for ($i 0$i 4++$i{
  8877.                     $p[$nc $i$p[$i];
  8878.                 }
  8879.                 // copy style for the last added line
  8880.                 if (isset($line_style[0])) {
  8881.                     $line_style[$np$line_style[0];
  8882.                 }            
  8883.                 $nc += 4;
  8884.             }
  8885.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  8886.                 $this->SetFillColorArray($fill_color);
  8887.             }
  8888.             switch ($style{
  8889.                 case 'F'{
  8890.                     $line_style array();
  8891.                     $op 'f';
  8892.                     break;
  8893.                 }
  8894.                 case 'FD'
  8895.                 case 'DF'{
  8896.                     $op 'B';
  8897.                     break;
  8898.                 }
  8899.                 case 'CNZ'{
  8900.                     $op 'W n';
  8901.                     break;
  8902.                 }
  8903.                 case 'CEO'{
  8904.                     $op 'W* n';
  8905.                     break;
  8906.                 }                
  8907.                 default{
  8908.                     $op 'S';
  8909.                     break;
  8910.                 }
  8911.             }
  8912.             $draw true;
  8913.             if ($line_style{
  8914.                 if (isset($line_style['all'])) {
  8915.                     $this->SetLineStyle($line_style['all']);
  8916.                 else {
  8917.                     $draw false;
  8918.                     if ($op == 'B'{
  8919.                         // draw fill
  8920.                         $op 'f';
  8921.                         $this->_outPoint($p[0]$p[1]);
  8922.                         for ($i 2$i $nc$i $i 2{
  8923.                             $this->_outLine($p[$i]$p[$i 1]);
  8924.                         }
  8925.                         $this->_out($op);
  8926.                     }
  8927.                     // draw outline
  8928.                     $this->_outPoint($p[0]$p[1]);
  8929.                     for ($i 2$i $nc$i $i 2{
  8930.                         $line_num ($i 21;
  8931.                         if (isset($line_style[$line_num])) {
  8932.                             if ($line_style[$line_num!= 0{
  8933.                                 if (is_array($line_style[$line_num])) {
  8934.                                     $this->_out('S');
  8935.                                     $this->SetLineStyle($line_style[$line_num]);
  8936.                                     $this->_outPoint($p[$i 2]$p[$i 1]);
  8937.                                     $this->_outLine($p[$i]$p[$i 1]);
  8938.                                     $this->_out('S');
  8939.                                     $this->_outPoint($p[$i]$p[$i 1]);
  8940.                                 else {
  8941.                                     $this->_outLine($p[$i]$p[$i 1]);
  8942.                                 }
  8943.                             }
  8944.                         else {
  8945.                             $this->_outLine($p[$i]$p[$i 1]);
  8946.                         }
  8947.                     }
  8948.                     $this->_out($op);
  8949.                 }
  8950.             }
  8951.             if ($draw{
  8952.                 $this->_outPoint($p[0]$p[1]);
  8953.                 for ($i 2$i $nc$i $i 2{
  8954.                     $this->_outLine($p[$i]$p[$i 1]);
  8955.                 }
  8956.                 $this->_out($op);
  8957.             }
  8958.         }
  8959.         
  8960.         /**
  8961.         * Draws a regular polygon.
  8962.         * @param float $x0 Abscissa of center point.
  8963.         * @param float $y0 Ordinate of center point.
  8964.         * @param float $r: Radius of inscribed circle.
  8965.         * @param integer $ns Number of sides.
  8966.         * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  8967.         * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  8968.         * @param string $style Style of rendering. Possible values are:
  8969.         *  <ul>
  8970.         *      <li>D or empty string: Draw (default).</li>
  8971.         *      <li>F: Fill.</li>
  8972.         *      <li>DF or FD: Draw and fill.</li>
  8973.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8974.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8975.         *  </ul>
  8976.         * @param array $line_style Line style of polygon sides. Array with keys among the following:
  8977.         *  <ul>
  8978.         *      <li>all: Line style of all sides. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8979.         *      <li>0 to ($ns - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8980.         *  </ul>
  8981.         *  If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  8982.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  8983.         * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  8984.         *  <ul>
  8985.         *      <li>D or empty string: Draw (default).</li>
  8986.         *      <li>F: Fill.</li>
  8987.         *      <li>DF or FD: Draw and fill.</li>
  8988.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8989.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8990.         *  </ul>
  8991.         * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8992.         * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  8993.         * @access public
  8994.         * @since 2.1.000 (2008-01-08)
  8995.         */
  8996.         public function RegularPolygon($x0$y0$r$ns$angle=0$draw_circle=false$style=''$line_style=array()$fill_color=array()$circle_style=''$circle_outLine_style=array()$circle_fill_color=array()) {
  8997.             if ($ns{
  8998.                 $ns 3;
  8999.             }
  9000.             if ($draw_circle{
  9001.                 $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  9002.             }
  9003.             $p array();
  9004.             for ($i 0$i $ns++$i{
  9005.                 $a $angle ($i 360 $ns);
  9006.                 $a_rad deg2rad((float) $a);
  9007.                 $p[$x0 ($r sin($a_rad));
  9008.                 $p[$y0 ($r cos($a_rad));
  9009.             }
  9010.             $this->Polygon($p$style$line_style$fill_color);
  9011.         }
  9012.         
  9013.         /**
  9014.         * Draws a star polygon
  9015.         * @param float $x0 Abscissa of center point.
  9016.         * @param float $y0 Ordinate of center point.
  9017.         * @param float $r Radius of inscribed circle.
  9018.         * @param integer $nv Number of vertices.
  9019.         * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  9020.         * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  9021.         * @param boolean $draw_circle: Draw inscribed circle or not. Default value is false.
  9022.         * @param string $style Style of rendering. Possible values are:
  9023.         *  <ul>
  9024.         *      <li>D or empty string: Draw (default).</li>
  9025.         *      <li>F: Fill.</li>
  9026.         *      <li>DF or FD: Draw and fill.</li>
  9027.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9028.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9029.         *  </ul>
  9030.         * @param array $line_style Line style of polygon sides. Array with keys among the following:
  9031.         *  <ul>
  9032.         *      <li>all: Line style of all sides. Array like for
  9033.         *  {@link SetLineStyle SetLineStyle}.</li>
  9034.         *      <li>0 to (n - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  9035.         *  </ul>
  9036.         *  If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  9037.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  9038.         * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  9039.         *  <ul>
  9040.         *      <li>D or empty string: Draw (default).</li>
  9041.         *      <li>F: Fill.</li>
  9042.         *      <li>DF or FD: Draw and fill.</li>
  9043.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9044.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9045.         *  </ul>
  9046.         * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  9047.         * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  9048.         * @access public
  9049.         * @since 2.1.000 (2008-01-08)
  9050.         */
  9051.         public function StarPolygon($x0$y0$r$nv$ng$angle=0$draw_circle=false$style=''$line_style=array()$fill_color=array()$circle_style=''$circle_outLine_style=array()$circle_fill_color=array()) {
  9052.             if ($nv 2{
  9053.                 $nv 2;
  9054.             }
  9055.             if ($draw_circle{
  9056.                 $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  9057.             }
  9058.             $p2 array();
  9059.             $visited array();
  9060.             for ($i 0$i $nv++$i{
  9061.                 $a $angle ($i 360 $nv);
  9062.                 $a_rad deg2rad((float) $a);
  9063.                 $p2[$x0 ($r sin($a_rad));
  9064.                 $p2[$y0 ($r cos($a_rad));
  9065.                 $visited[false;
  9066.             }
  9067.             $p array();
  9068.             $i 0;
  9069.             do {
  9070.                 $p[$p2[$i 2];
  9071.                 $p[$p2[($i 21];
  9072.                 $visited[$itrue;
  9073.                 $i += $ng;
  9074.                 $i %= $nv;
  9075.             while (!$visited[$i]);
  9076.             $this->Polygon($p$style$line_style$fill_color);
  9077.         }
  9078.         
  9079.         /**
  9080.         * Draws a rounded rectangle.
  9081.         * @param float $x Abscissa of upper-left corner.
  9082.         * @param float $y Ordinate of upper-left corner.
  9083.         * @param float $w Width.
  9084.         * @param float $h Height.
  9085.         * @param float $r Radius of the rounded corners.
  9086.         * @param string $round_corner Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
  9087.         * @param string $style Style of rendering. Possible values are:
  9088.         *  <ul>
  9089.         *      <li>D or empty string: Draw (default).</li>
  9090.         *      <li>F: Fill.</li>
  9091.         *      <li>DF or FD: Draw and fill.</li>
  9092.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  9093.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  9094.         *  </ul>
  9095.         * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  9096.         * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  9097.         * @access public
  9098.         * @since 2.1.000 (2008-01-08)
  9099.         */
  9100.         public function RoundedRect($x$y$w$h$r$round_corner='1111'$style=''$border_style=array()$fill_color=array()) {
  9101.             if ('0000' == $round_corner// Not rounded
  9102.                 $this->Rect($x$y$w$h$style$border_style$fill_color);
  9103.             else // Rounded
  9104.                 if (!(false === strpos($style'F')) AND isset($fill_color)) {
  9105.                     $this->SetFillColorArray($fill_color);
  9106.                 }
  9107.                 switch ($style{
  9108.                     case 'F'{
  9109.                         $border_style array();
  9110.                         $op 'f';
  9111.                         break;
  9112.                     }
  9113.                     case 'FD'
  9114.                     case 'DF'{
  9115.                         $op 'B';
  9116.                         break;
  9117.                     }
  9118.                     case 'CNZ'{
  9119.                         $op 'W n';
  9120.                         break;
  9121.                     }
  9122.                     case 'CEO'{
  9123.                         $op 'W* n';
  9124.                         break;
  9125.                     }
  9126.                     default{
  9127.                         $op 'S';
  9128.                         break;
  9129.                     }
  9130.                 }
  9131.                 if ($border_style{
  9132.                     $this->SetLineStyle($border_style);
  9133.                 }
  9134.                 $MyArc (sqrt(21);
  9135.                 $this->_outPoint($x $r$y);
  9136.                 $xc $x $w $r;
  9137.                 $yc $y $r;
  9138.                 $this->_outLine($xc$y);
  9139.                 if ($round_corner[0]{
  9140.                     $this->_outCurve($xc ($r $MyArc)$yc $r$xc $r$yc ($r $MyArc)$xc $r$yc);
  9141.                 else {
  9142.                     $this->_outLine($x $w$y);
  9143.                 }
  9144.                 $xc $x $w $r;
  9145.                 $yc $y $h $r;
  9146.                 $this->_outLine($x $w$yc);
  9147.                 if ($round_corner[1]{
  9148.                     $this->_outCurve($xc $r$yc ($r $MyArc)$xc ($r $MyArc)$yc $r$xc$yc $r);
  9149.                 else {
  9150.                     $this->_outLine($x $w$y $h);
  9151.                 }
  9152.                 $xc $x $r;
  9153.                 $yc $y $h $r;
  9154.                 $this->_outLine($xc$y $h);
  9155.                 if ($round_corner[2]{
  9156.                     $this->_outCurve($xc ($r $MyArc)$yc $r$xc $r$yc ($r $MyArc)$xc $r$yc);
  9157.                 else {
  9158.                     $this->_outLine($x$y $h);
  9159.                 }
  9160.                 $xc $x $r;
  9161.                 $yc $y $r;
  9162.                 $this->_outLine($x$yc);
  9163.                 if ($round_corner[3]{
  9164.                     $this->_outCurve($xc $r$yc ($r $MyArc)$xc ($r $MyArc)$yc $r$xc$yc $r);
  9165.                 else {
  9166.                     $this->_outLine($x$y);
  9167.                     $this->_outLine($x $r$y);
  9168.                 }
  9169.                 $this->_out($op);
  9170.             }
  9171.         }
  9172.         
  9173.         /**
  9174.         * Draws a grahic arrow.
  9175.         * @parameter float $x0 Abscissa of first point.
  9176.         * @parameter float $y0 Ordinate of first point.
  9177.         * @parameter float $x0 Abscissa of second point.
  9178.         * @parameter float $y1 Ordinate of second point.
  9179.         * @parameter int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  9180.         * @parameter float $arm_size length of arrowhead arms
  9181.         * @parameter int $arm_angle angle between an arm and the shaft
  9182.         * @author Piotr Galecki, Nicola Asuni, Andy Meier
  9183.         * @since 4.6.018 (2009-07-10)
  9184.         */
  9185.         public function Arrow($x0$y0$x1$y1$head_style=0$arm_size=5$arm_angle=15{
  9186.             // getting arrow direction angle
  9187.             // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  9188.             $dir_angle rad2deg(atan2(($y0 $y1)($x0 $x1)));
  9189.             $sx1 $x1;
  9190.             $sy1 $y1;
  9191.             if ($head_style 0{
  9192.                 // calculate the stopping point for the arrow shaft
  9193.                 $sx1 $x1 (($arm_size $this->LineWidthcos(deg2rad($dir_angle)));
  9194.                 $sy1 $y1 (($arm_size $this->LineWidthsin(deg2rad($dir_angle)));
  9195.             
  9196.             // main arrow line / shaft
  9197.             $this->Line($x0$y0$sx1$sy1);
  9198.             // left arrowhead arm tip
  9199.             $x2L $x1 ($arm_size cos(deg2rad($dir_angle $arm_angle)));
  9200.             $y2L $y1 ($arm_size sin(deg2rad($dir_angle $arm_angle)));
  9201.             // right arrowhead arm tip
  9202.             $x2R $x1 ($arm_size cos(deg2rad($dir_angle $arm_angle)));
  9203.             $y2R $y1 ($arm_size sin(deg2rad($dir_angle $arm_angle)));
  9204.             $mode 'D';
  9205.             $style array();
  9206.             switch ($head_style{
  9207.                 case 0{
  9208.                     // draw only arrowhead arms
  9209.                     $mode 'D';
  9210.                     $style array(110);
  9211.                     break;
  9212.                 }
  9213.                 case 1{
  9214.                     // draw closed arrowhead, but no fill
  9215.                     $mode 'D';
  9216.                     break;
  9217.                 }
  9218.                 case 2{
  9219.                     // closed and filled arrowhead
  9220.                     $mode 'DF';
  9221.                     break;
  9222.                 }
  9223.                 case 3{
  9224.                     // filled arrowhead
  9225.                     $mode 'F';
  9226.                     break;
  9227.                 }
  9228.             }
  9229.             $this->Polygon(array($x2L$y2L$x1$y1$x2R$y2R)$mode$stylearray());
  9230.         }
  9231.         
  9232.         // END GRAPHIC FUNCTIONS SECTION -----------------------
  9233.         
  9234.         // BIDIRECTIONAL TEXT SECTION --------------------------
  9235.         /**
  9236.          * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  9237.          * @param string $str string to manipulate.
  9238.          * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  9239.          * @return string 
  9240.          * @access protected
  9241.          * @author Nicola Asuni
  9242.          * @since 2.1.000 (2008-01-08)
  9243.         */
  9244.         protected function utf8StrRev($str$setbom=false$forcertl=false{
  9245.             return $this->arrUTF8ToUTF16BE($this->utf8Bidi($this->UTF8StringToArray($str)$str$forcertl)$setbom);
  9246.         }
  9247.         
  9248.         /**
  9249.          * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  9250.          * @param array $ta array of characters composing the string.
  9251.          * @param string $str string to process
  9252.          * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  9253.          * @return string 
  9254.          * @author Nicola Asuni
  9255.          * @access protected
  9256.          * @since 2.4.000 (2008-03-06)
  9257.         */
  9258.         protected function utf8Bidi($ta$str=''$forcertl=false{
  9259.             global $unicode$unicode_mirror$unicode_arlet$laa_array$diacritics;
  9260.             // paragraph embedding level
  9261.             $pel 0;
  9262.             // max level
  9263.             $maxlevel 0;
  9264.             if ($this->empty_string($str)) {
  9265.                 // create string from array
  9266.                 $str $this->UTF8ArrSubString($ta);
  9267.             }
  9268.             // check if string contains arabic text
  9269.             if (preg_match(K_RE_PATTERN_ARABIC$str)) {
  9270.                 $arabic true;
  9271.             else {
  9272.                 $arabic false;
  9273.             }
  9274.             // check if string contains RTL text
  9275.             if (!($forcertl OR $arabic OR preg_match(K_RE_PATTERN_RTL$str))) {
  9276.                 return $ta;
  9277.             }
  9278.             
  9279.             // get number of chars
  9280.             $numchars count($ta);
  9281.             
  9282.             if ($forcertl == 'R'{
  9283.                     $pel 1;
  9284.             elseif ($forcertl == 'L'{
  9285.                     $pel 0;
  9286.             else {
  9287.                 // P2. In each paragraph, find the first character of type L, AL, or R.
  9288.                 // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
  9289.                 for ($i=0$i $numchars++$i{
  9290.                     $type $unicode[$ta[$i]];
  9291.                     if ($type == 'L'{
  9292.                         $pel 0;
  9293.                         break;
  9294.                     elseif (($type == 'AL'OR ($type == 'R')) {
  9295.                         $pel 1;
  9296.                         break;
  9297.                     }
  9298.                 }
  9299.             }
  9300.             
  9301.             // Current Embedding Level
  9302.             $cel $pel;
  9303.             // directional override status
  9304.             $dos 'N';
  9305.             $remember array();
  9306.             // start-of-level-run
  9307.             $sor $pel 'R' 'L';
  9308.             $eor $sor;
  9309.             
  9310.             // Array of characters data
  9311.             $chardata Array();
  9312.             
  9313.             // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
  9314.             //     In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  9315.             for ($i=0$i $numchars++$i{
  9316.                 if ($ta[$i== K_RLE{
  9317.                     // X2. With each RLE, compute the least greater odd embedding level.
  9318.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  9319.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9320.                     $next_level $cel ($cel 21;
  9321.                     if ($next_level 62{
  9322.                         $remember[array('num' => K_RLE'cel' => $cel'dos' => $dos);
  9323.                         $cel $next_level;
  9324.                         $dos 'N';
  9325.                         $sor $eor;
  9326.                         $eor $cel 'R' 'L';
  9327.                     }
  9328.                 elseif ($ta[$i== K_LRE{
  9329.                     // X3. With each LRE, compute the least greater even embedding level.
  9330.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  9331.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9332.                     $next_level $cel ($cel 2);
  9333.                     if $next_level 62 {
  9334.                         $remember[array('num' => K_LRE'cel' => $cel'dos' => $dos);
  9335.                         $cel $next_level;
  9336.                         $dos 'N';
  9337.                         $sor $eor;
  9338.                         $eor $cel 'R' 'L';
  9339.                     }
  9340.                 elseif ($ta[$i== K_RLO{
  9341.                     // X4. With each RLO, compute the least greater odd embedding level.
  9342.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
  9343.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9344.                     $next_level $cel ($cel 21;
  9345.                     if ($next_level 62{
  9346.                         $remember[array('num' => K_RLO'cel' => $cel'dos' => $dos);
  9347.                         $cel $next_level;
  9348.                         $dos 'R';
  9349.                         $sor $eor;
  9350.                         $eor $cel 'R' 'L';
  9351.                     }
  9352.                 elseif ($ta[$i== K_LRO{
  9353.                     // X5. With each LRO, compute the least greater even embedding level.
  9354.                     //    a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
  9355.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  9356.                     $next_level $cel ($cel 2);
  9357.                     if $next_level 62 {
  9358.                         $remember[array('num' => K_LRO'cel' => $cel'dos' => $dos);
  9359.                         $cel $next_level;
  9360.                         $dos 'L';
  9361.                         $sor $eor;
  9362.                         $eor $cel 'R' 'L';
  9363.                     }
  9364.                 elseif ($ta[$i== K_PDF{
  9365.                     // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
  9366.                     if (count($remember)) {
  9367.                         $last count($remember 1;
  9368.                         if (($remember[$last]['num'== K_RLEOR 
  9369.                               ($remember[$last]['num'== K_LREOR 
  9370.                               ($remember[$last]['num'== K_RLOOR 
  9371.                               ($remember[$last]['num'== K_LRO)) {
  9372.                             $match array_pop($remember);
  9373.                             $cel $match['cel'];
  9374.                             $dos $match['dos'];
  9375.                             $sor $eor;
  9376.                             $eor ($cel $match['cel'$cel $match['cel']'R' 'L';
  9377.                         }
  9378.                     }
  9379.                 elseif (($ta[$i!= K_RLEAND
  9380.                                  ($ta[$i!= K_LREAND
  9381.                                  ($ta[$i!= K_RLOAND
  9382.                                  ($ta[$i!= K_LROAND
  9383.                                  ($ta[$i!= K_PDF)) {
  9384.                     // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  9385.                     //    a. Set the level of the current character to the current embedding level.
  9386.                     //    b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  9387.                     if ($dos != 'N'{
  9388.                         $chardir $dos;
  9389.                     else {
  9390.                         if (isset($unicode[$ta[$i]])) {
  9391.                             $chardir $unicode[$ta[$i]];
  9392.                         else {
  9393.                             $chardir 'L';
  9394.                         }
  9395.                     }
  9396.                     // stores string characters and other information
  9397.                     $chardata[array('char' => $ta[$i]'level' => $cel'type' => $chardir'sor' => $sor'eor' => $eor);
  9398.                 }
  9399.             // end for each char
  9400.             
  9401.             // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  9402.             // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  9403.             // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
  9404.             
  9405.             // 3.3.3 Resolving Weak Types
  9406.             // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
  9407.             // Nonspacing marks are now resolved based on the previous characters.
  9408.             $numchars count($chardata);
  9409.             
  9410.             // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
  9411.             $prevlevel = -1// track level changes
  9412.             $levcount 0// counts consecutive chars at the same level
  9413.             for ($i=0$i $numchars++$i{
  9414.                 if ($chardata[$i]['type'== 'NSM'{
  9415.                     if ($levcount{
  9416.                         $chardata[$i]['type'$chardata[$i]['sor'];
  9417.                     elseif ($i 0{
  9418.                         $chardata[$i]['type'$chardata[($i-1)]['type'];
  9419.                     }
  9420.                 }
  9421.                 if ($chardata[$i]['level'!= $prevlevel{
  9422.                     $levcount 0;
  9423.                 else {
  9424.                     ++$levcount;
  9425.                 }
  9426.                 $prevlevel $chardata[$i]['level'];
  9427.             }
  9428.             
  9429.             // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
  9430.             $prevlevel = -1;
  9431.             $levcount 0;
  9432.             for ($i=0$i $numchars++$i{
  9433.                 if ($chardata[$i]['char'== 'EN'{
  9434.                     for ($j=$levcount$j >= 0$j--{
  9435.                         if ($chardata[$j]['type'== 'AL'{
  9436.                             $chardata[$i]['type''AN';
  9437.                         elseif (($chardata[$j]['type'== 'L'OR ($chardata[$j]['type'== 'R')) {
  9438.                             break;
  9439.                         }
  9440.                     }
  9441.                 }
  9442.                 if ($chardata[$i]['level'!= $prevlevel{
  9443.                     $levcount 0;
  9444.                 else {
  9445.                     ++$levcount;
  9446.                 }
  9447.                 $prevlevel $chardata[$i]['level'];
  9448.             }
  9449.             
  9450.             // W3. Change all ALs to R.
  9451.             for ($i=0$i $numchars++$i{
  9452.                 if ($chardata[$i]['type'== 'AL'{
  9453.                     $chardata[$i]['type''R';
  9454.                 
  9455.             }
  9456.             
  9457.             // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
  9458.             $prevlevel = -1;
  9459.             $levcount 0;
  9460.             for ($i=0$i $numchars++$i{
  9461.                 if (($levcount 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  9462.                     if (($chardata[$i]['type'== 'ES'AND ($chardata[($i-1)]['type'== 'EN'AND ($chardata[($i+1)]['type'== 'EN')) {
  9463.                         $chardata[$i]['type''EN';
  9464.                     elseif (($chardata[$i]['type'== 'CS'AND ($chardata[($i-1)]['type'== 'EN'AND ($chardata[($i+1)]['type'== 'EN')) {
  9465.                         $chardata[$i]['type''EN';
  9466.                     elseif (($chardata[$i]['type'== 'CS'AND ($chardata[($i-1)]['type'== 'AN'AND ($chardata[($i+1)]['type'== 'AN')) {
  9467.                         $chardata[$i]['type''AN';
  9468.                     }
  9469.                 }
  9470.                 if ($chardata[$i]['level'!= $prevlevel{
  9471.                     $levcount 0;
  9472.                 else {
  9473.                     ++$levcount;
  9474.                 }
  9475.                 $prevlevel $chardata[$i]['level'];
  9476.             }
  9477.             
  9478.             // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  9479.             $prevlevel = -1;
  9480.             $levcount 0;
  9481.             for ($i=0$i $numchars++$i{
  9482.                 if ($chardata[$i]['type'== 'ET'{
  9483.                     if (($levcount 0AND ($chardata[($i-1)]['type'== 'EN')) {
  9484.                         $chardata[$i]['type''EN';
  9485.                     else {
  9486.                         $j $i+1;
  9487.                         while (($j $numcharsAND ($chardata[$j]['level'== $prevlevel)) {
  9488.                             if ($chardata[$j]['type'== 'EN'{
  9489.                                 $chardata[$i]['type''EN';
  9490.                                 break;
  9491.                             elseif ($chardata[$j]['type'!= 'ET'{
  9492.                                 break;
  9493.                             }
  9494.                             ++$j;
  9495.                         }
  9496.                     }
  9497.                 }
  9498.                 if ($chardata[$i]['level'!= $prevlevel{
  9499.                     $levcount 0;
  9500.                 else {
  9501.                     ++$levcount;
  9502.                 }
  9503.                 $prevlevel $chardata[$i]['level'];
  9504.             }
  9505.             
  9506.             // W6. Otherwise, separators and terminators change to Other Neutral.
  9507.             $prevlevel = -1;
  9508.             $levcount 0;
  9509.             for ($i=0$i $numchars++$i{
  9510.                 if (($chardata[$i]['type'== 'ET'OR ($chardata[$i]['type'== 'ES'OR ($chardata[$i]['type'== 'CS')) {
  9511.                     $chardata[$i]['type''ON';
  9512.                 }
  9513.                 if ($chardata[$i]['level'!= $prevlevel{
  9514.                     $levcount 0;
  9515.                 else {
  9516.                     ++$levcount;
  9517.                 }
  9518.                 $prevlevel $chardata[$i]['level'];
  9519.             }
  9520.             
  9521.             //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
  9522.             $prevlevel = -1;
  9523.             $levcount 0;
  9524.             for ($i=0$i $numchars++$i{
  9525.                 if ($chardata[$i]['char'== 'EN'{
  9526.                     for ($j=$levcount$j >= 0$j--{
  9527.                         if ($chardata[$j]['type'== 'L'{
  9528.                             $chardata[$i]['type''L';
  9529.                         elseif ($chardata[$j]['type'== 'R'{
  9530.                             break;
  9531.                         }
  9532.                     }
  9533.                 }
  9534.                 if ($chardata[$i]['level'!= $prevlevel{
  9535.                     $levcount 0;
  9536.                 else {
  9537.                     ++$levcount;
  9538.                 }
  9539.                 $prevlevel $chardata[$i]['level'];
  9540.             }
  9541.             
  9542.             // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
  9543.             $prevlevel = -1;
  9544.             $levcount 0;
  9545.             for ($i=0$i $numchars++$i{
  9546.                 if (($levcount 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  9547.                     if (($chardata[$i]['type'== 'N'AND ($chardata[($i-1)]['type'== 'L'AND ($chardata[($i+1)]['type'== 'L')) {
  9548.                         $chardata[$i]['type''L';
  9549.                     elseif (($chardata[$i]['type'== 'N'AND
  9550.                      (($chardata[($i-1)]['type'== 'R'OR ($chardata[($i-1)]['type'== 'EN'OR ($chardata[($i-1)]['type'== 'AN')) AND
  9551.                      (($chardata[($i+1)]['type'== 'R'OR ($chardata[($i+1)]['type'== 'EN'OR ($chardata[($i+1)]['type'== 'AN'))) {
  9552.                         $chardata[$i]['type''R';
  9553.                     elseif ($chardata[$i]['type'== 'N'{
  9554.                         // N2. Any remaining neutrals take the embedding direction
  9555.                         $chardata[$i]['type'$chardata[$i]['sor'];
  9556.                     }
  9557.                 elseif (($levcount == 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  9558.                     // first char
  9559.                     if (($chardata[$i]['type'== 'N'AND ($chardata[$i]['sor'== 'L'AND ($chardata[($i+1)]['type'== 'L')) {
  9560.                         $chardata[$i]['type''L';
  9561.                     elseif (($chardata[$i]['type'== 'N'AND
  9562.                      (($chardata[$i]['sor'== 'R'OR ($chardata[$i]['sor'== 'EN'OR ($chardata[$i]['sor'== 'AN')) AND
  9563.                      (($chardata[($i+1)]['type'== 'R'OR ($chardata[($i+1)]['type'== 'EN'OR ($chardata[($i+1)]['type'== 'AN'))) {
  9564.                         $chardata[$i]['type''R';
  9565.                     elseif ($chardata[$i]['type'== 'N'{
  9566.                         // N2. Any remaining neutrals take the embedding direction
  9567.                         $chardata[$i]['type'$chardata[$i]['sor'];
  9568.                     }
  9569.                 elseif (($levcount 0AND ((($i+1== $numcharsOR (($i+1$numcharsAND ($chardata[($i+1)]['level'!= $prevlevel))) {
  9570.                     //last char
  9571.                     if (($chardata[$i]['type'== 'N'AND ($chardata[($i-1)]['type'== 'L'AND ($chardata[$i]['eor'== 'L')) {
  9572.                         $chardata[$i]['type''L';
  9573.                     elseif (($chardata[$i]['type'== 'N'AND
  9574.                      (($chardata[($i-1)]['type'== 'R'OR ($chardata[($i-1)]['type'== 'EN'OR ($chardata[($i-1)]['type'== 'AN')) AND
  9575.                      (($chardata[$i]['eor'== 'R'OR ($chardata[$i]['eor'== 'EN'OR ($chardata[$i]['eor'== 'AN'))) {
  9576.                         $chardata[$i]['type''R';
  9577.                     elseif ($chardata[$i]['type'== 'N'{
  9578.                         // N2. Any remaining neutrals take the embedding direction
  9579.                         $chardata[$i]['type'$chardata[$i]['sor'];
  9580.                     }
  9581.                 elseif ($chardata[$i]['type'== 'N'{
  9582.                     // N2. Any remaining neutrals take the embedding direction
  9583.                     $chardata[$i]['type'$chardata[$i]['sor'];
  9584.                 }
  9585.                 if ($chardata[$i]['level'!= $prevlevel{
  9586.                     $levcount 0;
  9587.                 else {
  9588.                     ++$levcount;
  9589.                 }
  9590.                 $prevlevel $chardata[$i]['level'];
  9591.             }
  9592.             
  9593.             // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
  9594.             // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  9595.             for ($i=0$i $numchars++$i{
  9596.                 $odd $chardata[$i]['level'2;
  9597.                 if ($odd{
  9598.                     if (($chardata[$i]['type'== 'L'OR ($chardata[$i]['type'== 'AN'OR ($chardata[$i]['type'== 'EN')) {
  9599.                         $chardata[$i]['level'+= 1;
  9600.                     }
  9601.                 else {
  9602.                     if ($chardata[$i]['type'== 'R'{
  9603.                         $chardata[$i]['level'+= 1;
  9604.                     elseif (($chardata[$i]['type'== 'AN'OR ($chardata[$i]['type'== 'EN')) {
  9605.                         $chardata[$i]['level'+= 2;
  9606.                     }
  9607.                 }
  9608.                 $maxlevel max($chardata[$i]['level'],$maxlevel);
  9609.             }
  9610.             
  9611.             // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  9612.             //    1. Segment separators,
  9613.             //    2. Paragraph separators,
  9614.             //    3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  9615.             //    4. Any sequence of white space characters at the end of the line.
  9616.             for ($i=0$i $numchars++$i{
  9617.                 if (($chardata[$i]['type'== 'B'OR ($chardata[$i]['type'== 'S')) {
  9618.                     $chardata[$i]['level'$pel;
  9619.                 elseif ($chardata[$i]['type'== 'WS'{
  9620.                     $j $i+1;
  9621.                     while ($j $numchars{
  9622.                         if ((($chardata[$j]['type'== 'B'OR ($chardata[$j]['type'== 'S')) OR
  9623.                             (($j == ($numchars-1)) AND ($chardata[$j]['type'== 'WS'))) {
  9624.                             $chardata[$i]['level'$pel;
  9625.                             break;
  9626.                         elseif ($chardata[$j]['type'!= 'WS'{
  9627.                             break;
  9628.                         }
  9629.                         ++$j;
  9630.                     }
  9631.                 }
  9632.             }
  9633.             
  9634.             // Arabic Shaping
  9635.             // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run. 
  9636.             if ($arabic{
  9637.                 $endedletter array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
  9638.                 $alfletter array(1570,1571,1573,1575);
  9639.                 $chardata2 $chardata;
  9640.                 $laaletter false;
  9641.                 $charAL array();
  9642.                 $x 0;
  9643.                 for ($i=0$i $numchars++$i{
  9644.                     if (($unicode[$chardata[$i]['char']] == 'AL'OR ($chardata[$i]['char'== 32OR ($chardata[$i]['char'== 8204)) {
  9645.                         $charAL[$x$chardata[$i];
  9646.                         $charAL[$x]['i'$i;
  9647.                         $chardata[$i]['x'$x;
  9648.                         ++$x;
  9649.                     }
  9650.                 }
  9651.                 $numAL $x;
  9652.                 for ($i=0$i $numchars++$i{
  9653.                     $thischar $chardata[$i];
  9654.                     if ($i 0{
  9655.                         $prevchar $chardata[($i-1)];
  9656.                     else {
  9657.                         $prevchar false;
  9658.                     }
  9659.                     if (($i+1$numchars{
  9660.                         $nextchar $chardata[($i+1)];
  9661.                     else {
  9662.                         $nextchar false;
  9663.                     }
  9664.                     if ($unicode[$thischar['char']] == 'AL'{
  9665.                         $x $thischar['x'];
  9666.                         if ($x 0{
  9667.                             $prevchar $charAL[($x-1)];
  9668.                         else {
  9669.                             $prevchar false;
  9670.                         }
  9671.                         if (($x+1$numAL{
  9672.                             $nextchar $charAL[($x+1)];
  9673.                         else {
  9674.                             $nextchar false;
  9675.                         }
  9676.                         // if laa letter
  9677.                         if (($prevchar !== falseAND ($prevchar['char'== 1604AND (in_array($thischar['char']$alfletter))) {
  9678.                             $arabicarr $laa_array;
  9679.                             $laaletter true;
  9680.                             if ($x 1{
  9681.                                 $prevchar $charAL[($x-2)];
  9682.                             else {
  9683.                                 $prevchar false;
  9684.                             }
  9685.                         else {
  9686.                             $arabicarr $unicode_arlet;
  9687.                             $laaletter false;
  9688.                         }
  9689.                         if (($prevchar !== falseAND ($nextchar !== falseAND
  9690.                             (($unicode[$prevchar['char']] == 'AL'OR ($unicode[$prevchar['char']] == 'NSM')) AND
  9691.                             (($unicode[$nextchar['char']] == 'AL'OR ($unicode[$nextchar['char']] == 'NSM')) AND
  9692.                             ($prevchar['type'== $thischar['type']AND
  9693.                             ($nextchar['type'== $thischar['type']AND
  9694.                             ($nextchar['char'!= 1567)) {
  9695.                             if (in_array($prevchar['char']$endedletter)) {
  9696.                                 if (isset($arabicarr[$thischar['char']][2])) {
  9697.                                     // initial
  9698.                                     $chardata2[$i]['char'$arabicarr[$thischar['char']][2];
  9699.                                 }
  9700.                             else {
  9701.                                 if (isset($arabicarr[$thischar['char']][3])) {
  9702.                                     // medial
  9703.                                     $chardata2[$i]['char'$arabicarr[$thischar['char']][3];
  9704.                                 }
  9705.                             }
  9706.                         elseif (($nextchar !== falseAND
  9707.                             (($unicode[$nextchar['char']] == 'AL'OR ($unicode[$nextchar['char']] == 'NSM')) AND
  9708.                             ($nextchar['type'== $thischar['type']AND
  9709.                             ($nextchar['char'!= 1567)) {
  9710.                             if (isset($arabicarr[$chardata[$i]['char']][2])) {
  9711.                                 // initial
  9712.                                 $chardata2[$i]['char'$arabicarr[$thischar['char']][2];
  9713.                             }
  9714.                         elseif ((($prevchar !== falseAND
  9715.                             (($unicode[$prevchar['char']] == 'AL'OR ($unicode[$prevchar['char']] == 'NSM')) AND
  9716.                             ($prevchar['type'== $thischar['type'])) OR
  9717.                             (($nextchar !== falseAND ($nextchar['char'== 1567))) {
  9718.                             // final
  9719.                             if (($i 1AND ($thischar['char'== 1607AND
  9720.                                 ($chardata[$i-1]['char'== 1604AND
  9721.                                 ($chardata[$i-2]['char'== 1604)) {
  9722.                                 //Allah Word
  9723.                                 // mark characters to delete with false
  9724.                                 $chardata2[$i-2]['char'false;
  9725.                                 $chardata2[$i-1]['char'false
  9726.                                 $chardata2[$i]['char'65010;
  9727.                             else {
  9728.                                 if (($prevchar !== falseAND in_array($prevchar['char']$endedletter)) {
  9729.                                     if (isset($arabicarr[$thischar['char']][0])) {
  9730.                                         // isolated
  9731.                                         $chardata2[$i]['char'$arabicarr[$thischar['char']][0];
  9732.                                     }
  9733.                                 else {
  9734.                                     if (isset($arabicarr[$thischar['char']][1])) {
  9735.                                         // final
  9736.                                         $chardata2[$i]['char'$arabicarr[$thischar['char']][1];
  9737.                                     }
  9738.                                 }
  9739.                             }
  9740.                         elseif (isset($arabicarr[$thischar['char']][0])) {
  9741.                             // isolated
  9742.                             $chardata2[$i]['char'$arabicarr[$thischar['char']][0];
  9743.                         }
  9744.                         // if laa letter
  9745.                         if ($laaletter{
  9746.                             // mark characters to delete with false
  9747.                             $chardata2[($charAL[($x-1)]['i'])]['char'false;
  9748.                         }
  9749.                     // end if AL (Arabic Letter)
  9750.                 // end for each char
  9751.                 /* 
  9752.                  * Combining characters that can occur with Shadda (0651 HEX, 1617 DEC) are placed in UE586-UE594. 
  9753.                  * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  9754.                  */
  9755.                 $cw &$this->CurrentFont['cw'];
  9756.                 for ($i 0$i ($numchars-1)++$i{
  9757.                     if (($chardata2[$i]['char'== 1617AND (isset($diacritics[($chardata2[$i+1]['char'])]))) {
  9758.                         // check if the subtitution font is defined on current font
  9759.                         if (isset($cw[($diacritics[($chardata2[$i+1]['char'])])])) {
  9760.                             $chardata2[$i]['char'false;
  9761.                             $chardata2[$i+1]['char'$diacritics[($chardata2[$i+1]['char'])];
  9762.                         }
  9763.                     }
  9764.                 }
  9765.                 // remove marked characters
  9766.                 foreach ($chardata2 as $key => $value{
  9767.                     if ($value['char'=== false{
  9768.                         unset($chardata2[$key]);
  9769.                     }
  9770.                 }
  9771.                 $chardata array_values($chardata2);
  9772.                 $numchars count($chardata);
  9773.                 unset($chardata2);
  9774.                 unset($arabicarr);
  9775.                 unset($laaletter);
  9776.                 unset($charAL);
  9777.             }
  9778.             
  9779.             // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
  9780.             for ($j=$maxlevel$j 0$j--{
  9781.                 $ordarray Array();
  9782.                 $revarr Array();
  9783.                 $onlevel false;
  9784.                 for ($i=0$i $numchars++$i{
  9785.                     if ($chardata[$i]['level'>= $j{
  9786.                         $onlevel true;
  9787.                         if (isset($unicode_mirror[$chardata[$i]['char']])) {
  9788.                             // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
  9789.                             $chardata[$i]['char'$unicode_mirror[$chardata[$i]['char']];
  9790.                         }
  9791.                         $revarr[$chardata[$i];
  9792.                     else {
  9793.                         if ($onlevel{
  9794.                             $revarr array_reverse($revarr);
  9795.                             $ordarray array_merge($ordarray$revarr);
  9796.                             $revarr Array();
  9797.                             $onlevel false;
  9798.                         }
  9799.                         $ordarray[$chardata[$i];
  9800.                     }
  9801.                 }
  9802.                 if ($onlevel{
  9803.                     $revarr array_reverse($revarr);
  9804.                     $ordarray array_merge($ordarray$revarr);
  9805.                 }
  9806.                 $chardata $ordarray;
  9807.             }
  9808.             
  9809.             $ordarray array();
  9810.             for ($i=0$i $numchars++$i{
  9811.                 $ordarray[$chardata[$i]['char'];
  9812.             }
  9813.             
  9814.             return $ordarray;
  9815.         }
  9816.         
  9817.         // END OF BIDIRECTIONAL TEXT SECTION -------------------
  9818.         
  9819.         /*
  9820.         * Adds a bookmark.
  9821.         * @param string $txt bookmark description.
  9822.         * @param int $level bookmark level (minimum value is 0).
  9823.         * @param float $y Ordinate of the boorkmark position (default = -1 = current position).
  9824.         * @param int $page target page number (leave empty for current page).
  9825.         * @access public
  9826.         * @author Olivier Plathey, Nicola Asuni
  9827.         * @since 2.1.002 (2008-02-12)
  9828.         */
  9829.         public function Bookmark($txt$level=0$y=-1$page=''{
  9830.             if ($level 0{
  9831.                 $level 0;
  9832.             }
  9833.             if (isset($this->outlines[0])) {
  9834.                 $lastoutline end($this->outlines);
  9835.                 $maxlevel $lastoutline['l'1;
  9836.             else {
  9837.                 $maxlevel 0;
  9838.             }
  9839.             if ($level $maxlevel{
  9840.                 $level $maxlevel;
  9841.             }
  9842.             if ($y == -1{
  9843.                 $y $this->GetY();
  9844.             }
  9845.             if (empty($page)) {
  9846.                 $page $this->PageNo();
  9847.             }
  9848.             $this->outlines[array('t' => $txt'l' => $level'y' => $y'p' => $page);
  9849.         }
  9850.         
  9851.         /*
  9852.         * Create a bookmark PDF string.
  9853.         * @access protected
  9854.         * @author Olivier Plathey, Nicola Asuni
  9855.         * @since 2.1.002 (2008-02-12)
  9856.         */
  9857.         protected function _putbookmarks({
  9858.             $nb count($this->outlines);
  9859.             if ($nb == 0{
  9860.                 return;
  9861.             }
  9862.             $lru array();
  9863.             $level 0;
  9864.             foreach ($this->outlines as $i => $o{
  9865.                 if ($o['l'0{
  9866.                     $parent $lru[($o['l'1)];
  9867.                     //Set parent and last pointers
  9868.                     $this->outlines[$i]['parent'$parent;
  9869.                     $this->outlines[$parent]['last'$i;
  9870.                     if ($o['l'$level{
  9871.                         //Level increasing: set first pointer
  9872.                         $this->outlines[$parent]['first'$i;
  9873.                     }
  9874.                 else {
  9875.                     $this->outlines[$i]['parent'$nb;
  9876.                 }
  9877.                 if (($o['l'<= $levelAND ($i 0)) {
  9878.                     //Set prev and next pointers
  9879.                     $prev $lru[$o['l']];
  9880.                     $this->outlines[$prev]['next'$i;
  9881.                     $this->outlines[$i]['prev'$prev;
  9882.                 }
  9883.                 $lru[$o['l']] $i;
  9884.                 $level $o['l'];
  9885.             }
  9886.             //Outline items
  9887.             $n $this->n + 1;
  9888.             foreach ($this->outlines as $i => $o{
  9889.                 $this->_newobj();
  9890.                 $this->_out('<</Title '.$this->_textstring($o['t']));
  9891.                 $this->_out('/Parent '.($n $o['parent']).' 0 R');
  9892.                 if (isset($o['prev']))
  9893.                 $this->_out('/Prev '.($n $o['prev']).' 0 R');
  9894.                 if (isset($o['next']))
  9895.                 $this->_out('/Next '.($n $o['next']).' 0 R');
  9896.                 if (isset($o['first']))
  9897.                 $this->_out('/First '.($n $o['first']).' 0 R');
  9898.                 if (isset($o['last']))
  9899.                 $this->_out('/Last '.($n $o['last']).' 0 R');
  9900.                 $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]'(($o['p']))($this->pagedim[$o['p']]['h'($o['y'$this->k))));
  9901.                 $this->_out('/Count 0>>');
  9902.                 $this->_out('endobj');
  9903.             }
  9904.             //Outline root
  9905.             $this->_newobj();
  9906.             $this->OutlineRoot = $this->n;
  9907.             $this->_out('<</Type /Outlines /First '.$n.' 0 R');
  9908.             $this->_out('/Last '.($n $lru[0]).' 0 R>>');
  9909.             $this->_out('endobj');
  9910.         }
  9911.         
  9912.         
  9913.         // --- JAVASCRIPT ------------------------------------------------------
  9914.         
  9915.         /*
  9916.         * Adds a javascript
  9917.         * @param string $script Javascript code
  9918.         * @access public
  9919.         * @author Johannes Güntert, Nicola Asuni
  9920.         * @since 2.1.002 (2008-02-12)
  9921.         */
  9922.         public function IncludeJS($script{
  9923.             $this->javascript .= $script;
  9924.         }
  9925.  
  9926.         /*
  9927.         * Adds a javascript object and return object ID
  9928.         * @param string $script Javascript code
  9929.         * @param boolean $onload if true executes this object when opening the document
  9930.         * @return int internal object ID
  9931.         * @access public
  9932.         * @author Nicola Asuni
  9933.         * @since 4.8.000 (2009-09-07)
  9934.         */
  9935.         public function addJavascriptObject($script$onload=false{
  9936.             ++$this->js_obj_id;
  9937.             $this->js_objects[$this->js_obj_idarray('js' => $script'onload' => $onload);
  9938.             return $this->js_obj_id;
  9939.         }
  9940.  
  9941.         /*
  9942.         * Create a javascript PDF string.
  9943.         * @access protected
  9944.         * @author Johannes Güntert, Nicola Asuni
  9945.         * @since 2.1.002 (2008-02-12)
  9946.         */
  9947.         protected function _putjavascript({
  9948.             if (empty($this->javascriptAND empty($this->js_objects)) {
  9949.                 return;
  9950.             }
  9951.             if (strpos($this->javascript'this.addField'0{
  9952.                 if (!$this->ur{
  9953.                     //$this->setUserRights();
  9954.                 }
  9955.                 // the following two lines are used to avoid form fields duplication after saving
  9956.                 // The addField method only works on Acrobat Writer, unless the document is signed with Adobe private key (UR3)
  9957.                 $jsa sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);"'tcpdfdocsaved''text'00101);
  9958.                 $jsb "getField('tcpdfdocsaved').value='saved';";
  9959.                 $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  9960.             }
  9961.             $this->n_js = $this->_newobj();
  9962.             $this->_out('<<');
  9963.             $this->_out('/Names [');
  9964.             if (!empty($this->javascript)) {
  9965.                 $this->_out('(EmbeddedJS) '.($this->n + 1).' 0 R');
  9966.             }
  9967.             if (!empty($this->js_objects)) {
  9968.                 foreach ($this->js_objects as $key => $val{
  9969.                     if ($val['onload']{
  9970.                         $this->_out('(JS'.$key.') '.$key.' 0 R');
  9971.                     }
  9972.                 }
  9973.             }
  9974.             $this->_out(']');
  9975.             $this->_out('>>');
  9976.             $this->_out('endobj');
  9977.             // default Javascript object
  9978.             if (!empty($this->javascript)) {
  9979.                 $this->_newobj();
  9980.                 $this->_out('<<');
  9981.                 $this->_out('/S /JavaScript');
  9982.                 $this->_out('/JS '.$this->_textstring($this->javascript));
  9983.                 $this->_out('>>');
  9984.                 $this->_out('endobj');
  9985.             }
  9986.             // additional Javascript objects
  9987.             if (!empty($this->js_objects)) {
  9988.                 foreach ($this->js_objects as $key => $val{
  9989.                     $this->offsets[$key$this->bufferlen;
  9990.                     $this->_out($key.' 0 obj');
  9991.                     $this->_out('<<');
  9992.                     $this->_out('/S /JavaScript');
  9993.                     $this->_out('/JS '.$this->_textstring($val['js']));
  9994.                     $this->_out('>>');
  9995.                     $this->_out('endobj');
  9996.                 }
  9997.             }            
  9998.         }
  9999.         
  10000.         /*
  10001.         * Convert color to javascript color.
  10002.         * @param string $color color name or #RRGGBB
  10003.         * @access protected
  10004.         * @author Denis Van Nuffelen, Nicola Asuni
  10005.         * @since 2.1.002 (2008-02-12)
  10006.         */
  10007.         protected function _JScolor($color{
  10008.             static $aColors array('transparent''black''white''red''green''blue''cyan''magenta''yellow''dkGray''gray''ltGray');
  10009.             if (substr($color,0,1== '#'{
  10010.                 return sprintf("['RGB',%.3F,%.3F,%.3F]"hexdec(substr($color,1,2))/255hexdec(substr($color,3,2))/255hexdec(substr($color,5,2))/255);
  10011.             }
  10012.             if (!in_array($color,$aColors)) {
  10013.                 $this->Error('Invalid color: '.$color);
  10014.             }
  10015.             return 'color.'.$color;
  10016.         }
  10017.         
  10018.         /*
  10019.         * Adds a javascript form field.
  10020.         * @param string $type field type
  10021.         * @param string $name field name
  10022.         * @param int $x horizontal position
  10023.         * @param int $y vertical position
  10024.         * @param int $w width
  10025.         * @param int $h height
  10026.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10027.         * @access protected
  10028.         * @author Denis Van Nuffelen, Nicola Asuni
  10029.         * @since 2.1.002 (2008-02-12)
  10030.         */
  10031.         protected function _addfield($type$name$x$y$w$h$prop{
  10032.             if ($this->rtl{
  10033.                 $x $x $w;
  10034.             }
  10035.             // the followind avoid fields duplication after saving the document
  10036.             $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
  10037.             $k $this->k;
  10038.             $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";
  10039.             $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  10040.             while (list($key$valeach($prop)) {
  10041.                 if (strcmp(substr($key-5)'Color'== 0{
  10042.                     $val $this->_JScolor($val);
  10043.                 else {
  10044.                     $val "'".$val."'";
  10045.                 }
  10046.                 $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  10047.             }
  10048.             if ($this->rtl{
  10049.                 $this->x -= $w;
  10050.             else {
  10051.                 $this->x += $w;
  10052.             }
  10053.             $this->javascript .= '}';
  10054.         }
  10055.  
  10056.         // --- FORM FIELDS -----------------------------------------------------
  10057.  
  10058.         /*
  10059.         * Convert JavaScript form fields properties array to Annotation Properties array.
  10060.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10061.         * @return array of annotation properties
  10062.         * @access protected
  10063.         * @author Nicola Asuni
  10064.         * @since 4.8.000 (2009-09-06)
  10065.         */
  10066.         protected function getAnnotOptFromJSProp($prop{
  10067.             if (isset($prop['aopt']AND is_array($prop['aopt'])) {
  10068.                 // the annotation options area lready defined
  10069.                 return $prop['aopt'];
  10070.             }
  10071.             $opt array()// value to be returned
  10072.             // alignment: Controls how the text is laid out within the text field.
  10073.             if (isset($prop['alignment'])) {
  10074.                 switch ($prop['alignment']{
  10075.                     case 'left'{
  10076.                         $opt['q'0;
  10077.                         break;
  10078.                     }
  10079.                     case 'center'{
  10080.                         $opt['q'1;
  10081.                         break;
  10082.                     }
  10083.                     case 'right'{
  10084.                         $opt['q'2;
  10085.                         break;
  10086.                     }
  10087.                     default{
  10088.                         $opt['q'($this->rtl)?2:0;
  10089.                         break;
  10090.                     }
  10091.                 }
  10092.             }
  10093.             // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  10094.             if (isset($prop['lineWidth'])) {
  10095.                 $linewidth intval($prop['lineWidth']);
  10096.             else {
  10097.                 $linewidth 1;
  10098.             }
  10099.             // borderStyle: The border style for a field.
  10100.             if (isset($prop['borderStyle'])) {
  10101.                 switch ($prop['borderStyle']{
  10102.                     case 'border.d':
  10103.                     case 'dashed'{
  10104.                         $opt['border'array(00$linewidtharray(32));
  10105.                         $opt['bs'array('w'=>$linewidth's'=>'D''d'=>array(32));
  10106.                         break;
  10107.                     }
  10108.                     case 'border.b':
  10109.                     case 'beveled'{
  10110.                         $opt['border'array(00$linewidth);
  10111.                         $opt['bs'array('w'=>$linewidth's'=>'B');
  10112.                         break;
  10113.                     }
  10114.                     case 'border.i':
  10115.                     case 'inset'{
  10116.                         $opt['border'array(00$linewidth);
  10117.                         $opt['bs'array('w'=>$linewidth's'=>'I');
  10118.                         break;
  10119.                     }
  10120.                     case 'border.u':
  10121.                     case 'underline'{
  10122.                         $opt['border'array(00$linewidth);
  10123.                         $opt['bs'array('w'=>$linewidth's'=>'U');
  10124.                         break;
  10125.                     }
  10126.                     default:
  10127.                     case 'border.s':
  10128.                     case 'solid'{
  10129.                         $opt['border'array(00$linewidth);
  10130.                         $opt['bs'array('w'=>$linewidth's'=>'S');
  10131.                         break;
  10132.                     }
  10133.                 }
  10134.             }
  10135.             if (isset($prop['border']AND is_array($prop['border'])) {
  10136.                 $opt['border'$prop['border'];
  10137.             }
  10138.             if (!isset($opt['mk'])) {
  10139.                 $opt['mk'array();
  10140.             }
  10141.             if (!isset($opt['mk']['if'])) {
  10142.                 $opt['mk']['if'array();
  10143.             }
  10144.             $opt['mk']['if']['a'array(0.50.5);
  10145.             // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  10146.             if (isset($prop['buttonAlignX'])) {
  10147.                 $opt['mk']['if']['a'][0$prop['buttonAlignX'];
  10148.             }
  10149.             // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  10150.             if (isset($prop['buttonAlignY'])) {
  10151.                 $opt['mk']['if']['a'][1$prop['buttonAlignY'];
  10152.             }
  10153.             // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  10154.             if (isset($prop['buttonFitBounds']AND ($prop['buttonFitBounds'== 'true')) {
  10155.                 $opt['mk']['if']['fb'true;
  10156.             }            
  10157.             // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  10158.             if (isset($prop['buttonScaleHow'])) {
  10159.                 switch ($prop['buttonScaleHow']{
  10160.                     case 'scaleHow.proportional'{
  10161.                         $opt['mk']['if']['s''P';
  10162.                         break;
  10163.                     }
  10164.                     case 'scaleHow.anamorphic'{
  10165.                         $opt['mk']['if']['s''A';
  10166.                         break;
  10167.                     }
  10168.                 }
  10169.             }
  10170.             // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  10171.             if (isset($prop['buttonScaleWhen'])) {
  10172.                 switch ($prop['buttonScaleWhen']{
  10173.                     case 'scaleWhen.always'{
  10174.                         $opt['mk']['if']['sw''A';
  10175.                         break;
  10176.                     }
  10177.                     case 'scaleWhen.never'{
  10178.                         $opt['mk']['if']['sw''N';
  10179.                         break;
  10180.                     }
  10181.                     case 'scaleWhen.tooBig'{
  10182.                         $opt['mk']['if']['sw''B';
  10183.                         break;
  10184.                     }
  10185.                     case 'scaleWhen.tooSmall'{
  10186.                         $opt['mk']['if']['sw''S';
  10187.                         break;
  10188.                     }
  10189.                 }
  10190.             }
  10191.             // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  10192.             if (isset($prop['buttonPosition'])) {
  10193.                 switch ($prop['buttonPosition']{
  10194.                     case 0:
  10195.                     case 'position.textOnly'{
  10196.                         $opt['mk']['tp'0;
  10197.                         break;
  10198.                     }
  10199.                     case 1:
  10200.                     case 'position.iconOnly'{
  10201.                         $opt['mk']['tp'1;
  10202.                         break;
  10203.                     }
  10204.                     case 2:
  10205.                     case 'position.iconTextV'{
  10206.                         $opt['mk']['tp'2;
  10207.                         break;
  10208.                     }
  10209.                     case 3:
  10210.                     case 'position.textIconV'{
  10211.                         $opt['mk']['tp'3;
  10212.                         break;
  10213.                     }
  10214.                     case 4:
  10215.                     case 'position.iconTextH'{
  10216.                         $opt['mk']['tp'4;
  10217.                         break;
  10218.                     }
  10219.                     case 5:
  10220.                     case 'position.textIconH'{
  10221.                         $opt['mk']['tp'5;
  10222.                         break;
  10223.                     }
  10224.                     case 6:
  10225.                     case 'position.overlay'{
  10226.                         $opt['mk']['tp'6;
  10227.                         break;
  10228.                     }
  10229.                 }                
  10230.             }
  10231.             // fillColor: Specifies the background color for a field.
  10232.             if (isset($prop['fillColor'])) {
  10233.                 if (is_array($prop['fillColor'])) {
  10234.                     $opt['mk']['bg'$prop['fillColor'];
  10235.                 else {
  10236.                     $opt['mk']['bg'$this->convertHTMLColorToDec($prop['fillColor']);
  10237.                 }
  10238.             }
  10239.             // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
  10240.             if (isset($prop['strokeColor'])) {
  10241.                 if (is_array($prop['strokeColor'])) {
  10242.                     $opt['mk']['bc'$prop['strokeColor'];
  10243.                 else {
  10244.                     $opt['mk']['bc'$this->convertHTMLColorToDec($prop['strokeColor']);
  10245.                 }
  10246.             }
  10247.             // rotation: The rotation of a widget in counterclockwise increments.
  10248.             if (isset($prop['rotation'])) {
  10249.                 $opt['mk']['r'$prop['rotation'];
  10250.             }
  10251.             // charLimit: Limits the number of characters that a user can type into a text field.
  10252.             if (isset($prop['charLimit'])) {
  10253.                 $opt['maxlen'intval($prop['charLimit']);
  10254.             }
  10255.             if (!isset($ff)) {
  10256.                 $ff 0;
  10257.             }
  10258.             // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  10259.             if (isset($prop['readonly']AND ($prop['readonly'== 'true')) {
  10260.                 $ff += << 0;
  10261.             }
  10262.             // required: Specifies whether a field requires a value.
  10263.             if (isset($prop['required']AND ($prop['required'== 'true')) {
  10264.                 $ff += << 1;
  10265.             }
  10266.             // multiline: Controls how text is wrapped within the field.
  10267.             if (isset($prop['multiline']AND ($prop['multiline'== 'true')) {
  10268.                 $ff += << 12;
  10269.             }
  10270.             // password: Specifies whether the field should display asterisks when data is entered in the field.
  10271.             if (isset($prop['password']AND ($prop['password'== 'true')) {
  10272.                 $ff += << 13;
  10273.             }
  10274.             // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  10275.             if (isset($prop['NoToggleToOff']AND ($prop['NoToggleToOff'== 'true')) {
  10276.                 $ff += << 14;
  10277.             }
  10278.             // Radio: If set, the field is a set of radio buttons.
  10279.             if (isset($prop['Radio']AND ($prop['Radio'== 'true')) {
  10280.                 $ff += << 15;
  10281.             }
  10282.             // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  10283.             if (isset($prop['Pushbutton']AND ($prop['Pushbutton'== 'true')) {
  10284.                 $ff += << 16;
  10285.             }
  10286.             // Combo: If set, the field is a combo box; if clear, the field is a list box.
  10287.             if (isset($prop['Combo']AND ($prop['Combo'== 'true')) {
  10288.                 $ff += << 17;
  10289.             }
  10290.             // editable: Controls whether a combo box is editable.
  10291.             if (isset($prop['editable']AND ($prop['editable'== 'true')) {
  10292.                 $ff += << 18;
  10293.             }
  10294.             // Sort: If set, the field's option items shall be sorted alphabetically.
  10295.             if (isset($prop['Sort']AND ($prop['Sort'== 'true')) {
  10296.                 $ff += << 19;
  10297.             }
  10298.             // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  10299.             if (isset($prop['fileSelect']AND ($prop['fileSelect'== 'true')) {
  10300.                 $ff += << 20;
  10301.             }
  10302.             // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  10303.             if (isset($prop['multipleSelection']AND ($prop['multipleSelection'== 'true')) {
  10304.                 $ff += << 21;
  10305.             }
  10306.             // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  10307.             if (isset($prop['doNotSpellCheck']AND ($prop['doNotSpellCheck'== 'true')) {
  10308.                 $ff += << 22;
  10309.             }
  10310.             // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  10311.             if (isset($prop['doNotScroll']AND ($prop['doNotScroll'== 'true')) {
  10312.                 $ff += << 23;
  10313.             }
  10314.             // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set.
  10315.             if (isset($prop['comb']AND ($prop['comb'== 'true')) {
  10316.                 $ff += << 24;
  10317.             }
  10318.             // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons.
  10319.             if (isset($prop['radiosInUnison']AND ($prop['radiosInUnison'== 'true')) {
  10320.                 $ff += << 25;
  10321.             }
  10322.             // richText: If true, the field allows rich text formatting.
  10323.             if (isset($prop['richText']AND ($prop['richText'== 'true')) {
  10324.                 $ff += << 25;
  10325.             }
  10326.             // commitOnSelChange: Controls whether a field value is committed after a selection change.
  10327.             if (isset($prop['commitOnSelChange']AND ($prop['commitOnSelChange'== 'true')) {
  10328.                 $ff += << 26;
  10329.             }
  10330.             $opt['ff'$ff;
  10331.             // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  10332.             if (isset($prop['defaultValue'])) {
  10333.                 $opt['dv'$prop['defaultValue'];
  10334.             }
  10335.             $f 4// default value for annotation flags
  10336.             // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  10337.             if (isset($prop['readonly']AND ($prop['readonly'== 'true')) {
  10338.                 $f += << 6;
  10339.             }
  10340.             // display: Controls whether the field is hidden or visible on screen and in print.
  10341.             if (isset($prop['display'])) {
  10342.                 if ($prop['display'== 'display.visible'{
  10343.                     //
  10344.                 elseif ($prop['display'== 'display.hidden'{
  10345.                     $f += << 1;
  10346.                 elseif ($prop['display'== 'display.noPrint'{
  10347.                     $f -= << 2;
  10348.                 elseif ($prop['display'== 'display.noView'{
  10349.                     $f += << 5;
  10350.                 }
  10351.             }
  10352.             $opt['f'$f;
  10353.             // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  10354.             if (isset($prop['currentValueIndices']AND is_array($prop['currentValueIndices'])) {
  10355.                 $opt['i'$prop['currentValueIndices'];
  10356.             }
  10357.             // value: The value of the field data that the user has entered.
  10358.             if (isset($prop['value'])) {
  10359.                 if (is_array($prop['value'])) {
  10360.                     $opt['opt'array();
  10361.                     foreach ($prop['value'AS $key => $optval{
  10362.                         // exportValues: An array of strings representing the export values for the field.
  10363.                         if (isset($prop['exportValues'][$key])) {
  10364.                             $opt['opt'][$keyarray($prop['exportValues'][$key]$prop['value'][$key]);
  10365.                         else {
  10366.                             $opt['opt'][$key$prop['value'][$key];
  10367.                         }
  10368.                     }
  10369.                 else {
  10370.                     $opt['v'$prop['value'];
  10371.                 }
  10372.             }
  10373.             // richValue: This property specifies the text contents and formatting of a rich text field.
  10374.             if (isset($prop['richValue'])) {
  10375.                 $opt['rv'$prop['richValue'];
  10376.             }
  10377.             // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  10378.             if (isset($prop['submitName'])) {
  10379.                 $opt['tm'$prop['submitName'];
  10380.             }
  10381.             // name: Fully qualified field name.
  10382.             if (isset($prop['name'])) {
  10383.                 $opt['t'$prop['name'];
  10384.             }
  10385.             // userName: The user name (short description string) of the field.
  10386.             if (isset($prop['userName'])) {
  10387.                 $opt['tu'$prop['userName'];
  10388.             }
  10389.             // highlight: Defines how a button reacts when a user clicks it.
  10390.             if (isset($prop['highlight'])) {
  10391.                 switch ($prop['highlight']{
  10392.                     case 'none':
  10393.                     case 'highlight.n'{
  10394.                         $opt['h''N';
  10395.                         break;
  10396.                     }
  10397.                     case 'invert':
  10398.                     case 'highlight.i'{
  10399.                         $opt['h''i';
  10400.                         break;
  10401.                     }
  10402.                     case 'push':
  10403.                     case 'highlight.p'{
  10404.                         $opt['h''P';
  10405.                         break;
  10406.                     }
  10407.                     case 'outline':
  10408.                     case 'highlight.o'{
  10409.                         $opt['h''O';
  10410.                         break;
  10411.                     }
  10412.                 }                
  10413.             }
  10414.             // Unsupported options:
  10415.             // - calcOrderIndex: Changes the calculation order of fields in the document.
  10416.             // - delay: Delays the redrawing of a field's appearance.
  10417.             // - defaultStyle: This property defines the default style attributes for the form field.
  10418.             // - style: Allows the user to set the glyph style of a check box or radio button.
  10419.             // - textColor, textFont, textSize
  10420.             return $opt;
  10421.         }
  10422.         
  10423.         /*
  10424.         * Set default properties for form fields.
  10425.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10426.         * @access public
  10427.         * @author Nicola Asuni
  10428.         * @since 4.8.000 (2009-09-06)
  10429.         */
  10430.         public function setFormDefaultProp($prop=array()) {
  10431.             $this->default_form_prop $prop;
  10432.         }
  10433.         
  10434.         /*
  10435.         * Return the default properties for form fields.
  10436.         * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10437.         * @access public
  10438.         * @author Nicola Asuni
  10439.         * @since 4.8.000 (2009-09-06)
  10440.         */
  10441.         public function getFormDefaultProp({
  10442.             return $this->default_form_prop;
  10443.         }
  10444.         
  10445.         /*
  10446.         * Creates a text field
  10447.         * @param string $name field name
  10448.         * @param float $w Width of the rectangle
  10449.         * @param float $h Height of the rectangle
  10450.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10451.         * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10452.         * @param float $x Abscissa of the upper-left corner of the rectangle
  10453.         * @param float $y Ordinate of the upper-left corner of the rectangle
  10454.         * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10455.         * @access public
  10456.         * @author Nicola Asuni
  10457.         * @since 4.8.000 (2009-09-07)
  10458.         */
  10459.         public function TextField($name$w$h$prop=array()$opt=array()$x=''$y=''$js=false{
  10460.             if ($x === ''{
  10461.                 $x $this->x;
  10462.             }
  10463.             if ($y === ''{
  10464.                 $y $this->y;
  10465.             }
  10466.             if ($js{
  10467.                 $this->_addfield('text'$name$x$y$w$h$prop);
  10468.                 return;
  10469.             }
  10470.             // get default style
  10471.             $prop array_merge($this->getFormDefaultProp()$prop);
  10472.             // get annotation data
  10473.             $popt $this->getAnnotOptFromJSProp($prop);
  10474.             // set default appearance stream
  10475.             $font $this->FontFamily;
  10476.             $fontkey array_search($font$this->fontkeys);
  10477.             if (!in_array($fontkey$this->annotation_fonts)) {
  10478.                 $this->annotation_fonts[$font$fontkey;
  10479.             }
  10480.             $fontstyle sprintf('/F%d %.2F Tf %s'($fontkey 1)$this->FontSizePt$this->TextColor);
  10481.             $popt['da'$fontstyle;
  10482.             $popt['ap'array();
  10483.             $popt['ap']['n''q BT '.$fontstyle.' ET Q';
  10484.             // merge options
  10485.             $opt array_merge($popt$opt);
  10486.             // remove some conflicting options
  10487.             unset($opt['bs']);
  10488.             // set remaining annotation data
  10489.             $opt['Subtype''Widget';
  10490.             $opt['ft''Tx';
  10491.             $opt['t'$name;
  10492.             /*
  10493.             Additional annotation's parameters (check _putannotsobj() method):
  10494.             //$opt['f']
  10495.             //$opt['ap']
  10496.             //$opt['as']
  10497.             //$opt['bs']
  10498.             //$opt['be']
  10499.             //$opt['c']
  10500.             //$opt['border']
  10501.             //$opt['h']
  10502.             //$opt['mk']
  10503.             //$opt['mk']['r']
  10504.             //$opt['mk']['bc']
  10505.             //$opt['mk']['bg']
  10506.             //$opt['mk']['ca']
  10507.             //$opt['mk']['rc']
  10508.             //$opt['mk']['ac']
  10509.             //$opt['mk']['i']
  10510.             //$opt['mk']['ri']
  10511.             //$opt['mk']['ix']
  10512.             //$opt['mk']['if']
  10513.             //$opt['mk']['if']['sw']
  10514.             //$opt['mk']['if']['s']
  10515.             //$opt['mk']['if']['a']
  10516.             //$opt['mk']['if']['fb']
  10517.             //$opt['mk']['tp']
  10518.             //$opt['tu']
  10519.             //$opt['tm']
  10520.             //$opt['ff']
  10521.             //$opt['v']
  10522.             //$opt['dv']
  10523.             //$opt['a']
  10524.             //$opt['aa']
  10525.             //$opt['q']
  10526.             */
  10527.             $this->Annotation($x$y$w$h$name$opt0);
  10528.             if ($this->rtl{
  10529.                 $this->x -= $w;
  10530.             else {
  10531.                 $this->x += $w;
  10532.             }
  10533.         }
  10534.  
  10535.         /*
  10536.         * Creates a RadioButton field
  10537.         * @param string $name field name
  10538.         * @param int $w width
  10539.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10540.         * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10541.         * @param string $onvalue value to be returned if selected.
  10542.         * @param boolean $checked define the initial state.
  10543.         * @param float $x Abscissa of the upper-left corner of the rectangle
  10544.         * @param float $y Ordinate of the upper-left corner of the rectangle
  10545.         * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10546.         * @access public
  10547.         * @author Nicola Asuni
  10548.         * @since 4.8.000 (2009-09-07)
  10549.         */
  10550.         public function RadioButton($name$w$prop=array()$opt=array()$onvalue='On'$checked=false$x=''$y=''$js=false{
  10551.             if ($x === ''{
  10552.                 $x $this->x;
  10553.             }
  10554.             if ($y === ''{
  10555.                 $y $this->y;
  10556.             }
  10557.             if ($js{
  10558.                 $this->_addfield('radiobutton'$name$x$y$w$w$prop);
  10559.                 return;
  10560.             }
  10561.             if ($this->empty_string($onvalue)) {
  10562.                 $onvalue 'On';
  10563.             }
  10564.             if ($checked{
  10565.                 $defval $onvalue;
  10566.             else {
  10567.                 $defval 'Off';
  10568.             }
  10569.             // set data for parent group
  10570.             if (!isset($this->radiobutton_groups[$this->page])) {
  10571.                 $this->radiobutton_groups[$this->pagearray();
  10572.             }
  10573.             if (!isset($this->radiobutton_groups[$this->page][$name])) {
  10574.                 $this->radiobutton_groups[$this->page][$namearray();
  10575.                 ++$this->annot_obj_id;
  10576.                 $this->radio_groups[$this->annot_obj_id;
  10577.             }
  10578.             // save object ID to be added on Kids entry on parent object
  10579.             $this->radiobutton_groups[$this->page][$name][array('kid' => ($this->annot_obj_id 1)'def' => $defval);
  10580.             // get default style
  10581.             $prop array_merge($this->getFormDefaultProp()$prop);
  10582.             $prop['NoToggleToOff''true';
  10583.             $prop['Radio''true';
  10584.             $prop['borderStyle''inset';
  10585.             // get annotation data
  10586.             $popt $this->getAnnotOptFromJSProp($prop);
  10587.             // set additional default values
  10588.             $font 'zapfdingbats';
  10589.             $this->AddFont($font);
  10590.             $fontkey array_search($font$this->fontkeys);
  10591.             if (!in_array($fontkey$this->annotation_fonts)) {
  10592.                 $this->annotation_fonts[$font$fontkey;
  10593.             }
  10594.             $fontstyle sprintf('/F%d %.2F Tf %s'($fontkey 1)$this->FontSizePt$this->TextColor);
  10595.             $popt['da'$fontstyle;
  10596.             $popt['ap'array();
  10597.             $popt['ap']['n'array();
  10598.             $popt['ap']['n'][$onvalue'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10599.             $popt['ap']['n']['Off''q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10600.             if (!isset($popt['mk'])) {
  10601.                 $popt['mk'array();
  10602.             }
  10603.             $popt['mk']['ca''(l)';
  10604.             // merge options
  10605.             $opt array_merge($popt$opt);
  10606.             // set remaining annotation data
  10607.             $opt['Subtype''Widget';
  10608.             $opt['ft''Btn';
  10609.             if ($checked{
  10610.                 $opt['v'array('/'.$onvalue);
  10611.                 $opt['as'$onvalue;
  10612.             else {
  10613.                 $opt['as''Off';
  10614.             }
  10615.             $this->Annotation($x$y$w$w$name$opt0);
  10616.             if ($this->rtl{
  10617.                 $this->x -= $w;
  10618.             else {
  10619.                 $this->x += $w;
  10620.             }
  10621.         }
  10622.         
  10623.         /*
  10624.         * Creates a List-box field
  10625.         * @param string $name field name
  10626.         * @param int $w width
  10627.         * @param int $h height
  10628.         * @param array $values array containing the list of values.
  10629.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10630.         * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10631.         * @param float $x Abscissa of the upper-left corner of the rectangle
  10632.         * @param float $y Ordinate of the upper-left corner of the rectangle
  10633.         * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10634.         * @access public
  10635.         * @author Nicola Asuni
  10636.         * @since 4.8.000 (2009-09-07)
  10637.         */
  10638.         public function ListBox($name$w$h$values$prop=array()$opt=array()$x=''$y=''$js=false{
  10639.             if ($x === ''{
  10640.                 $x $this->x;
  10641.             }
  10642.             if ($y === ''{
  10643.                 $y $this->y;
  10644.             }
  10645.             if ($js{
  10646.                 $this->_addfield('listbox'$name$x$y$w$h$prop);
  10647.                 $s '';
  10648.                 foreach ($values as $value{
  10649.                     $s .= "'".addslashes($value)."',";
  10650.                 }
  10651.                 $this->javascript .= 'f'.$name.'.setItems(['.substr($s0-1)."]);\n";
  10652.                 return;
  10653.             }
  10654.             // get default style
  10655.             $prop array_merge($this->getFormDefaultProp()$prop);
  10656.             // get annotation data
  10657.             $popt $this->getAnnotOptFromJSProp($prop);
  10658.             // set additional default values
  10659.             $font $this->FontFamily;
  10660.             $fontkey array_search($font$this->fontkeys);
  10661.             if (!in_array($fontkey$this->annotation_fonts)) {
  10662.                 $this->annotation_fonts[$font$fontkey;
  10663.             }
  10664.             $fontstyle sprintf('/F%d %.2F Tf %s'($fontkey 1)$this->FontSizePt$this->TextColor);
  10665.             $popt['da'$fontstyle;
  10666.             $popt['ap'array();
  10667.             $popt['ap']['n''q BT '.$fontstyle.' ET Q';
  10668.             // merge options
  10669.             $opt array_merge($popt$opt);
  10670.             // set remaining annotation data
  10671.             $opt['Subtype''Widget';
  10672.             $opt['ft''Ch';
  10673.             $opt['t'$name;
  10674.             $opt['opt'$values;
  10675.             $this->Annotation($x$y$w$h$name$opt0);
  10676.             if ($this->rtl{
  10677.                 $this->x -= $w;
  10678.             else {
  10679.                 $this->x += $w;
  10680.             }
  10681.         }
  10682.         
  10683.         /*
  10684.         * Creates a Combo-box field
  10685.         * @param string $name field name
  10686.         * @param int $w width
  10687.         * @param int $h height
  10688.         * @param array $values array containing the list of values.
  10689.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10690.         * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10691.         * @param float $x Abscissa of the upper-left corner of the rectangle
  10692.         * @param float $y Ordinate of the upper-left corner of the rectangle
  10693.         * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10694.         * @access public
  10695.         * @author Nicola Asuni
  10696.         * @since 4.8.000 (2009-09-07)
  10697.         */
  10698.         public function ComboBox($name$w$h$values$prop=array()$opt=array()$x=''$y=''$js=false{
  10699.             if ($x === ''{
  10700.                 $x $this->x;
  10701.             }
  10702.             if ($y === ''{
  10703.                 $y $this->y;
  10704.             }
  10705.             if ($js{
  10706.                 $this->_addfield('combobox'$name$x$y$w$h$prop);
  10707.                 $s '';
  10708.                 foreach ($values as $value{
  10709.                     $s .= "'".addslashes($value)."',";
  10710.                 }
  10711.                 $this->javascript .= 'f'.$name.'.setItems(['.substr($s0-1)."]);\n";
  10712.                 return;
  10713.             }
  10714.             // get default style
  10715.             $prop array_merge($this->getFormDefaultProp()$prop);
  10716.             $prop['Combo'true;
  10717.             // get annotation data
  10718.             $popt $this->getAnnotOptFromJSProp($prop);
  10719.             // set additional default options
  10720.             $font $this->FontFamily;
  10721.             $fontkey array_search($font$this->fontkeys);
  10722.             if (!in_array($fontkey$this->annotation_fonts)) {
  10723.                 $this->annotation_fonts[$font$fontkey;
  10724.             }
  10725.             $fontstyle sprintf('/F%d %.2F Tf %s'($fontkey 1)$this->FontSizePt$this->TextColor);
  10726.             $popt['da'$fontstyle;
  10727.             $popt['ap'array();
  10728.             $popt['ap']['n''q BT '.$fontstyle.' ET Q';
  10729.             // merge options
  10730.             $opt array_merge($popt$opt);
  10731.             // set remaining annotation data
  10732.             $opt['Subtype''Widget';
  10733.             $opt['ft''Ch';
  10734.             $opt['t'$name;
  10735.             $opt['opt'$values;
  10736.             $this->Annotation($x$y$w$h$name$opt0);
  10737.             if ($this->rtl{
  10738.                 $this->x -= $w;
  10739.             else {
  10740.                 $this->x += $w;
  10741.             }
  10742.         }
  10743.         
  10744.         /*
  10745.         * Creates a CheckBox field
  10746.         * @param string $name field name
  10747.         * @param int $w width
  10748.         * @param boolean $checked define the initial state.
  10749.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10750.         * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10751.         * @param string $onvalue value to be returned if selected.
  10752.         * @param float $x Abscissa of the upper-left corner of the rectangle
  10753.         * @param float $y Ordinate of the upper-left corner of the rectangle
  10754.         * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10755.         * @access public
  10756.         * @author Nicola Asuni
  10757.         * @since 4.8.000 (2009-09-07)
  10758.         */
  10759.         public function CheckBox($name$w$checked=false$prop=array()$opt=array()$onvalue='Yes'$x=''$y=''$js=false{
  10760.             if ($x === ''{
  10761.                 $x $this->x;
  10762.             }
  10763.             if ($y === ''{
  10764.                 $y $this->y;
  10765.             }
  10766.             if ($js{
  10767.                 $this->_addfield('checkbox'$name$x$y$w$w$prop);
  10768.                 return;
  10769.             }
  10770.             if (!isset($prop['value'])) {
  10771.                 $prop['value'array('Yes');
  10772.             }
  10773.             // get default style
  10774.             $prop array_merge($this->getFormDefaultProp()$prop);
  10775.             $prop['borderStyle''inset';
  10776.             // get annotation data
  10777.             $popt $this->getAnnotOptFromJSProp($prop);
  10778.             // set additional default options
  10779.             $font 'zapfdingbats';
  10780.             $this->AddFont($font);
  10781.             $fontkey array_search($font$this->fontkeys);
  10782.             if (!in_array($fontkey$this->annotation_fonts)) {
  10783.                 $this->annotation_fonts[$font$fontkey;
  10784.             }
  10785.             $fontstyle sprintf('/F%d %.2F Tf %s'($fontkey 1)$this->FontSizePt$this->TextColor);
  10786.             $popt['da'$fontstyle;
  10787.             $popt['ap'array();
  10788.             $popt['ap']['n'array();
  10789.             $popt['ap']['n']['Yes''q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10790.             $popt['ap']['n']['Off''q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
  10791.             // merge options
  10792.             $opt array_merge($popt$opt);
  10793.             // set remaining annotation data
  10794.             $opt['Subtype''Widget';
  10795.             $opt['ft''Btn';
  10796.             $opt['t'$name;
  10797.             $opt['opt'array($onvalue);
  10798.             if ($checked{
  10799.                 $opt['v'array('/0');
  10800.                 $opt['as''Yes';
  10801.             else {
  10802.                 $opt['v'array('/Off');
  10803.                 $opt['as''Off';
  10804.             }
  10805.             $this->Annotation($x$y$w$w$name$opt0);
  10806.             if ($this->rtl{
  10807.                 $this->x -= $w;
  10808.             else {
  10809.                 $this->x += $w;
  10810.             }
  10811.         }
  10812.         
  10813.         /*
  10814.         * Creates a button field
  10815.         * @param string $name field name
  10816.         * @param int $w width
  10817.         * @param int $h height
  10818.         * @param string $caption caption.
  10819.         * @param mixed $action action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008.
  10820.         * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  10821.         * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  10822.         * @param float $x Abscissa of the upper-left corner of the rectangle
  10823.         * @param float $y Ordinate of the upper-left corner of the rectangle
  10824.         * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  10825.         * @access public
  10826.         * @author Nicola Asuni
  10827.         * @since 4.8.000 (2009-09-07)
  10828.         */
  10829.         public function Button($name$w$h$caption$action$prop=array()$opt=array()$x=''$y=''$js=false{
  10830.             if ($x === ''{
  10831.                 $x $this->x;
  10832.             }
  10833.             if ($y === ''{
  10834.                 $y $this->y;
  10835.             }
  10836.             if ($js{
  10837.                 $this->_addfield('button'$name$this->x$this->y$w$h$prop);
  10838.                 $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  10839.                 $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  10840.                 $this->javascript .= 'f'.$name.".highlight='push';\n";
  10841.                 $this->javascript .= 'f'.$name.".print=false;\n";
  10842.                 return;
  10843.             }
  10844.             // get default style
  10845.             $prop array_merge($this->getFormDefaultProp()$prop);
  10846.             $prop['Pushbutton''true';
  10847.             $prop['highlight''push';
  10848.             $prop['display''display.noPrint';
  10849.             // get annotation data
  10850.             $popt $this->getAnnotOptFromJSProp($prop);
  10851.             // set additional default options
  10852.             if (!isset($popt['mk'])) {
  10853.                 $popt['mk'array();
  10854.             }
  10855.             $popt['mk']['ca'$this->_textstring($caption);
  10856.             $popt['mk']['rc'$this->_textstring($caption);
  10857.             $popt['mk']['ac'$this->_textstring($caption);
  10858.             $font $this->FontFamily;
  10859.             $fontkey array_search($font$this->fontkeys);
  10860.             if (!in_array($fontkey$this->annotation_fonts)) {
  10861.                 $this->annotation_fonts[$font$fontkey;
  10862.             }
  10863.             $fontstyle sprintf('/F%d %.2F Tf %s'($fontkey 1)$this->FontSizePt$this->TextColor);
  10864.             $popt['da'$fontstyle;
  10865.             $popt['ap'array();
  10866.             $popt['ap']['n''q BT '.$fontstyle.' ET Q';
  10867.             // merge options
  10868.             $opt array_merge($popt$opt);
  10869.             // set remaining annotation data
  10870.             $opt['Subtype''Widget';
  10871.             $opt['ft''Btn';
  10872.             $opt['t'$caption;
  10873.             $opt['v'$name;
  10874.             if (!empty($action)) {
  10875.                 if (is_array($action)) {
  10876.                     // form action options as on section 12.7.5 of PDF32000_2008.
  10877.                     $opt['aa''/D <<';
  10878.                     $bmode array('SubmitForm''ResetForm''ImportData');
  10879.                     foreach ($action AS $key => $val{
  10880.                         if (($key == 'S'AND in_array($val$bmode)) {
  10881.                             $opt['aa'.= ' /S /'.$val;
  10882.                         elseif (($key == 'F'AND (!empty($val))) {
  10883.                             $opt['aa'.= ' /F '.$this->_datastring($val);
  10884.                         elseif (($key == 'Fields'AND is_array($valAND !empty($val)) {
  10885.                             $opt['aa'.= ' /Fields [';
  10886.                             foreach ($val AS $field{
  10887.                                 $opt['aa'.= ' '.$this->_textstring($field);
  10888.                             }
  10889.                             $opt['aa'.= ']';
  10890.                         elseif (($key == 'Flags')) {
  10891.                             $ff 0;
  10892.                             if (is_array($val)) {
  10893.                                 foreach ($val AS $flag{
  10894.                                     switch ($flag{
  10895.                                         case 'Include/Exclude'{
  10896.                                             $ff += << 0;
  10897.                                             break;
  10898.                                         }
  10899.                                         case 'IncludeNoValueFields'{
  10900.                                             $ff += << 1;
  10901.                                             break;
  10902.                                         }
  10903.                                         case 'ExportFormat'{
  10904.                                             $ff += << 2;
  10905.                                             break;
  10906.                                         }
  10907.                                         case 'GetMethod'{
  10908.                                             $ff += << 3;
  10909.                                             break;
  10910.                                         }
  10911.                                         case 'SubmitCoordinates'{
  10912.                                             $ff += << 4;
  10913.                                             break;
  10914.                                         }
  10915.                                         case 'XFDF'{
  10916.                                             $ff += << 5;
  10917.                                             break;
  10918.                                         }
  10919.                                         case 'IncludeAppendSaves'{
  10920.                                             $ff += << 6;
  10921.                                             break;
  10922.                                         }
  10923.                                         case 'IncludeAnnotations'{
  10924.                                             $ff += << 7;
  10925.                                             break;
  10926.                                         }
  10927.                                         case 'SubmitPDF'{
  10928.                                             $ff += << 8;
  10929.                                             break;
  10930.                                         }
  10931.                                         case 'CanonicalFormat'{
  10932.                                             $ff += << 9;
  10933.                                             break;
  10934.                                         }
  10935.                                         case 'ExclNonUserAnnots'{
  10936.                                             $ff += << 10;
  10937.                                             break;
  10938.                                         }
  10939.                                         case 'ExclFKey'{
  10940.                                             $ff += << 11;
  10941.                                             break;
  10942.                                         }
  10943.                                         case 'EmbedForm'{
  10944.                                             $ff += << 13;
  10945.                                             break;
  10946.                                         }
  10947.                                     }
  10948.                                 }
  10949.                             else {
  10950.                                 $ff intval($val);
  10951.                             }
  10952.                             $opt['aa'.= ' /Flags '.$ff;
  10953.                         }
  10954.                     }
  10955.                     $opt['aa'.= ' >>';
  10956.                 else {
  10957.                     // Javascript action or raw action command
  10958.                     $js_obj_id $this->addJavascriptObject($action);
  10959.                     $opt['aa''/D '.$js_obj_id.' 0 R';
  10960.                 }
  10961.             }
  10962.             $this->Annotation($x$y$w$h$name$opt0);
  10963.             if ($this->rtl{
  10964.                 $this->x -= $w;
  10965.             else {
  10966.                 $this->x += $w;
  10967.             }
  10968.         }
  10969.         
  10970.         // --- END FORMS FIELDS ------------------------------------------------
  10971.         
  10972.         /*
  10973.         * Add certification signature (DocMDP or UR3)
  10974.         * You can set only one signature type
  10975.         * @access protected
  10976.         * @author Nicola Asuni
  10977.         * @since 4.6.008 (2009-05-07)
  10978.         */
  10979.         protected function _putsignature({
  10980.             if ((!$this->signOR (!isset($this->signature_data['cert_type']))) {
  10981.                 return;
  10982.             }
  10983.             $this->_out('/Type /Sig');
  10984.             $this->_out('/Filter /Adobe.PPKLite');
  10985.             $this->_out('/SubFilter /adbe.pkcs7.detached');
  10986.             $this->_out($this->byterange_string);
  10987.             $this->_out('/Contents<>'.str_repeat(' '$this->signature_max_lenght));
  10988.             $this->_out('/Reference');
  10989.             $this->_out('[');
  10990.             $this->_out('<<');
  10991.             $this->_out('/Type /SigRef');
  10992.             if ($this->signature_data['cert_type'0{
  10993.                 $this->_out('/TransformMethod /DocMDP');
  10994.                 $this->_out('/TransformParams');
  10995.                 $this->_out('<<');
  10996.                 $this->_out('/Type /TransformParams');
  10997.                 $this->_out('/V /1.2');
  10998.                 $this->_out('/P '.$this->signature_data['cert_type'].'');
  10999.             else {
  11000.                 $this->_out('/TransformMethod /UR3');
  11001.                 $this->_out('/TransformParams');
  11002.                 $this->_out('<<');
  11003.                 $this->_out('/Type /TransformParams');
  11004.                 $this->_out('/V /2.2');
  11005.                 if (!$this->empty_string($this->ur_document)) {
  11006.                     $this->_out('/Document['.$this->ur_document.']');
  11007.                 }
  11008.                 if (!$this->empty_string($this->ur_annots)) {
  11009.                     $this->_out('/Annots['.$this->ur_annots.']');
  11010.                 }
  11011.                 if (!$this->empty_string($this->ur_form)) {
  11012.                     $this->_out('/Form['.$this->ur_form.']');
  11013.                 }
  11014.                 if (!$this->empty_string($this->ur_signature)) {
  11015.                     $this->_out('/Signature['.$this->ur_signature.']');
  11016.                 }
  11017.             }
  11018.             $this->_out('>>');
  11019.             $this->_out('>>');
  11020.             $this->_out(']');
  11021.             if (isset($this->signature_data['info']['Name']AND !$this->empty_string($this->signature_data['info']['Name'])) {
  11022.                 $this->_out('/Name '.$this->_textstring($this->signature_data['info']['Name']).'');
  11023.             }
  11024.             if (isset($this->signature_data['info']['Location']AND !$this->empty_string($this->signature_data['info']['Location'])) {
  11025.                 $this->_out('/Location '.$this->_textstring($this->signature_data['info']['Location']).'');
  11026.             }
  11027.             if (isset($this->signature_data['info']['Reason']AND !$this->empty_string($this->signature_data['info']['Reason'])) {
  11028.                 $this->_out('/Reason '.$this->_textstring($this->signature_data['info']['Reason']).'');
  11029.             }
  11030.             if (isset($this->signature_data['info']['ContactInfo']AND !$this->empty_string($this->signature_data['info']['ContactInfo'])) {
  11031.                 $this->_out('/ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo']).'');
  11032.             }
  11033.             $this->_out('/M '.$this->_datestring());
  11034.         }
  11035.         
  11036.         /*
  11037.         * Set User's Rights for PDF Reader
  11038.         * WARNING: This works only using the Adobe private key with the setSignature() method!.
  11039.         * Check the PDF Reference 8.7.1 Transform Methods, 
  11040.         * Table 8.105 Entries in the UR transform parameters dictionary
  11041.         * @param boolean $enable if true enable user's rights on PDF reader
  11042.         * @param string $document Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data.
  11043.         * @param string $annots Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations.
  11044.         * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate 
  11045.         * @param string $signature Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field.
  11046.         * @access public
  11047.         * @author Nicola Asuni
  11048.         * @since 2.9.000 (2008-03-26)
  11049.         */
  11050.         public function setUserRights(
  11051.                 $enable=true
  11052.                 $document='/FullSave',
  11053.                 $annots='/Create/Delete/Modify/Copy/Import/Export',
  11054.                 $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  11055.                 $signature='/Modify'{
  11056.             $this->ur $enable;
  11057.             $this->ur_document $document;
  11058.             $this->ur_annots $annots;
  11059.             $this->ur_form $form;
  11060.             $this->ur_signature $signature;
  11061.             if (!$this->sign{
  11062.                 // This signature only works using the Adobe Private key that is unavailable!
  11063.                 $this->setSignature(''''''''0array());
  11064.             }
  11065.         }
  11066.         
  11067.         /*
  11068.         * Enable document signature (requires the OpenSSL Library).
  11069.         * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  11070.         * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
  11071.         * @param mixed $private_key private key (string or filename prefixed with 'file://')
  11072.         * @param string $private_key_password password
  11073.         * @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.
  11074.         * @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.
  11075.         * @parm array $info array of option information: Name, Location, Reason, ContactInfo.
  11076.         * @access public
  11077.         * @author Nicola Asuni
  11078.         * @since 4.6.005 (2009-04-24)
  11079.         */
  11080.         public function setSignature($signing_cert=''$private_key=''$private_key_password=''$extracerts=''$cert_type=2$info=array()) {
  11081.             // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  11082.             // to convert pfx certificate to pem: openssl
  11083.             //     OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  11084.             $this->sign true;
  11085.             $this->signature_data array();
  11086.             if (strlen($signing_cert== 0{
  11087.                 $signing_cert 'file://'.dirname(__FILE__).'/tcpdf.crt';
  11088.                 $private_key_password 'tcpdfdemo';
  11089.             }
  11090.             if (strlen($private_key== 0{
  11091.                 $private_key $signing_cert;
  11092.             }
  11093.             $this->signature_data['signcert'$signing_cert;
  11094.             $this->signature_data['privkey'$private_key;
  11095.             $this->signature_data['password'$private_key_password;
  11096.             $this->signature_data['extracerts'$extracerts;
  11097.             $this->signature_data['cert_type'$cert_type;
  11098.             $this->signature_data['info'$info;
  11099.         }
  11100.         
  11101.         /*
  11102.         * Create a new page group.
  11103.         * NOTE: call this function before calling AddPage()
  11104.         * @param int $page starting group page (leave empty for next page).
  11105.         * @access public
  11106.         * @since 3.0.000 (2008-03-27)
  11107.         */
  11108.         public function startPageGroup($page=''{
  11109.             if (empty($page)) {
  11110.                 $page $this->page 1;
  11111.             }
  11112.             $this->newpagegroup[$pagetrue;
  11113.         }
  11114.  
  11115.         /**
  11116.         * Defines an alias for the total number of pages.
  11117.         * It will be substituted as the document is closed.
  11118.         * @param string $alias The alias.
  11119.         * @access public
  11120.         * @since 1.4
  11121.         * @see getAliasNbPages(), PageNo(), Footer()
  11122.         */
  11123.         public function AliasNbPages($alias='{nb}'{
  11124.             $this->AliasNbPages = $alias;
  11125.         }
  11126.         
  11127.         /**
  11128.          * Returns the string alias used for the total number of pages.
  11129.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11130.          * @return string 
  11131.          * @access public
  11132.          * @since 4.0.018 (2008-08-08)
  11133.          * @see AliasNbPages(), PageNo(), Footer()
  11134.         */
  11135.         public function getAliasNbPages({
  11136.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  11137.                 return '{'.$this->AliasNbPages.'}';
  11138.             }
  11139.             return $this->AliasNbPages;
  11140.         }
  11141.  
  11142.         /**
  11143.         * Defines an alias for the page number.
  11144.         * It will be substituted as the document is closed.
  11145.         * @param string $alias The alias.
  11146.         * @access public
  11147.         * @since 4.5.000 (2009-01-02)
  11148.         * @see getAliasNbPages(), PageNo(), Footer()
  11149.         */
  11150.         public function AliasNumPage($alias='{pnb}'{
  11151.             //Define an alias for total number of pages
  11152.             $this->AliasNumPage = $alias;
  11153.         }
  11154.         
  11155.         /**
  11156.          * Returns the string alias used for the page number.
  11157.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11158.          * @return string 
  11159.          * @access public
  11160.          * @since 4.5.000 (2009-01-02)
  11161.          * @see AliasNbPages(), PageNo(), Footer()
  11162.         */
  11163.         public function getAliasNumPage({
  11164.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  11165.                 return '{'.$this->AliasNumPage.'}';
  11166.             }
  11167.             return $this->AliasNumPage;
  11168.         }
  11169.         
  11170.         /*
  11171.         * Return the current page in the group.
  11172.         * @return current page in the group
  11173.         * @access public
  11174.         * @since 3.0.000 (2008-03-27)
  11175.         */
  11176.         public function getGroupPageNo({
  11177.             return $this->pagegroups[$this->currpagegroup];
  11178.         }
  11179.  
  11180.         /**
  11181.         * Returns the current group page number formatted as a string.
  11182.         * @access public
  11183.         * @since 4.3.003 (2008-11-18)
  11184.         * @see PaneNo(), formatPageNumber()
  11185.         */
  11186.         public function getGroupPageNoFormatted({
  11187.             return $this->formatPageNumber($this->getGroupPageNo());
  11188.         }
  11189.         
  11190.         /*
  11191.          * Return the alias of the current page group
  11192.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11193.          * (will be replaced by the total number of pages in this group).
  11194.          * @return alias of the current page group
  11195.          * @access public
  11196.          * @since 3.0.000 (2008-03-27)
  11197.         */
  11198.         public function getPageGroupAlias({
  11199.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  11200.                 return '{'.$this->currpagegroup.'}';
  11201.             }
  11202.             return $this->currpagegroup;
  11203.         }
  11204.         
  11205.         /*
  11206.          * Return the alias for the page number on the current page group
  11207.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  11208.          * (will be replaced by the total number of pages in this group).
  11209.          * @return alias of the current page group
  11210.          * @access public
  11211.          * @since 4.5.000 (2009-01-02)
  11212.         */
  11213.         public function getPageNumGroupAlias({
  11214.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  11215.                 return '{'.str_replace('{nb''{pnb'$this->currpagegroup).'}';
  11216.             }
  11217.             return str_replace('{nb''{pnb'$this->currpagegroup);
  11218.         }
  11219.  
  11220.         /**
  11221.         * Format the page numbers.
  11222.         * This method can be overriden for custom formats.
  11223.         * @param int $num page number
  11224.         * @access protected
  11225.         * @since 4.2.005 (2008-11-06)
  11226.         */
  11227.         protected function formatPageNumber($num{
  11228.             return number_format((float)$num0'''.');
  11229.         }
  11230.  
  11231.         /**
  11232.         * Format the page numbers on the Table Of Content.
  11233.         * This method can be overriden for custom formats.
  11234.         * @param int $num page number
  11235.         * @access protected
  11236.         * @since 4.5.001 (2009-01-04)
  11237.         * @see addTOC()
  11238.         */
  11239.         protected function formatTOCPageNumber($num{
  11240.             return number_format((float)$num0'''.');
  11241.         }
  11242.  
  11243.         /**
  11244.         * Returns the current page number formatted as a string.
  11245.         * @access public
  11246.         * @since 4.2.005 (2008-11-06)
  11247.         * @see PaneNo(), formatPageNumber()
  11248.         */
  11249.         public function PageNoFormatted({
  11250.             return $this->formatPageNumber($this->PageNo());
  11251.         }
  11252.  
  11253.         /*
  11254.         * Put visibility settings.
  11255.         * @access protected
  11256.         * @since 3.0.000 (2008-03-27)
  11257.         */
  11258.         protected function _putocg({
  11259.             $this->_newobj();
  11260.             $this->n_ocg_print $this->n;
  11261.             $this->_out('<</Type /OCG /Name '.$this->_textstring('print'));
  11262.             $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  11263.             $this->_out('endobj');
  11264.             $this->_newobj();
  11265.             $this->n_ocg_view $this->n;
  11266.             $this->_out('<</Type /OCG /Name '.$this->_textstring('view'));
  11267.             $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  11268.             $this->_out('endobj');
  11269.         }
  11270.         
  11271.         /*
  11272.         * Set the visibility of the successive elements.
  11273.         * This can be useful, for instance, to put a background 
  11274.         * image or color that will show on screen but won't print.
  11275.         * @param string $v visibility mode. Legal values are: all, print, screen.
  11276.         * @access public
  11277.         * @since 3.0.000 (2008-03-27)
  11278.         */
  11279.         public function setVisibility($v{
  11280.             if ($this->openMarkedContent{
  11281.                 // close existing open marked-content
  11282.                 $this->_out('EMC');
  11283.                 $this->openMarkedContent false;
  11284.             }
  11285.             switch($v{
  11286.                 case 'print'{
  11287.                     $this->_out('/OC /OC1 BDC');
  11288.                     $this->openMarkedContent true;
  11289.                     break;
  11290.                 }
  11291.                 case 'screen'{
  11292.                     $this->_out('/OC /OC2 BDC');
  11293.                     $this->openMarkedContent true;
  11294.                     break;
  11295.                 }
  11296.                 case 'all'{
  11297.                     $this->_out('');
  11298.                     break;
  11299.                 }
  11300.                 default{
  11301.                     $this->Error('Incorrect visibility: '.$v);
  11302.                     break;
  11303.                 }
  11304.             }
  11305.             $this->visibility $v;
  11306.         }
  11307.         
  11308.         /*
  11309.         * Add transparency parameters to the current extgstate
  11310.         * @param array $params parameters
  11311.         * @return the number of extgstates
  11312.         * @access protected
  11313.         * @since 3.0.000 (2008-03-27)
  11314.         */
  11315.         protected function addExtGState($parms{
  11316.             $n count($this->extgstates1;
  11317.             $this->extgstates[$n]['parms'$parms;
  11318.             return $n;
  11319.         }
  11320.         
  11321.         /*
  11322.         * Add an extgstate
  11323.         * @param array $gs extgstate
  11324.         * @access protected
  11325.         * @since 3.0.000 (2008-03-27)
  11326.         */
  11327.         protected function setExtGState($gs{
  11328.             $this->_out(sprintf('/GS%d gs'$gs));
  11329.         }
  11330.         
  11331.         /*
  11332.         * Put extgstates for object transparency
  11333.         * @param array $gs extgstate
  11334.         * @access protected
  11335.         * @since 3.0.000 (2008-03-27)
  11336.         */
  11337.         protected function _putextgstates({
  11338.             $ne count($this->extgstates);
  11339.             for ($i 1$i <= $ne++$i{
  11340.                 $this->_newobj();
  11341.                 $this->extgstates[$i]['n'$this->n;
  11342.                 $this->_out('<</Type /ExtGState');
  11343.                 foreach ($this->extgstates[$i]['parms'as $k => $v{
  11344.                     $this->_out('/'.$k.' '.$v);
  11345.                 }
  11346.                 $this->_out('>>');
  11347.                 $this->_out('endobj');
  11348.             }
  11349.         }
  11350.         
  11351.         /*
  11352.         * Set alpha for stroking (CA) and non-stroking (ca) operations.
  11353.         * @param float $alpha real value from 0 (transparent) to 1 (opaque)
  11354.         * @param string $bm blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  11355.         * @access public
  11356.         * @since 3.0.000 (2008-03-27)
  11357.         */
  11358.         public function setAlpha($alpha$bm='Normal'{
  11359.             $gs $this->addExtGState(array('ca' => $alpha'CA' => $alpha'BM' => '/'.$bm));
  11360.             $this->setExtGState($gs);
  11361.         }
  11362.  
  11363.         /*
  11364.         * Set the default JPEG compression quality (1-100)
  11365.         * @param int $quality JPEG quality, integer between 1 and 100
  11366.         * @access public
  11367.         * @since 3.0.000 (2008-03-27)
  11368.         */
  11369.         public function setJPEGQuality($quality{
  11370.             if (($quality 1OR ($quality 100)) {
  11371.                 $quality 75;
  11372.             }
  11373.             $this->jpeg_quality intval($quality);
  11374.         }
  11375.         
  11376.         /*
  11377.         * Set the default number of columns in a row for HTML tables.
  11378.         * @param int $cols number of columns
  11379.         * @access public
  11380.         * @since 3.0.014 (2008-06-04)
  11381.         */
  11382.         public function setDefaultTableColumns($cols=4
  11383.             $this->default_table_columns intval($cols)
  11384.         }
  11385.         
  11386.         /*
  11387.         * Set the height of the cell (line height) respect the font height.
  11388.         * @param int $h cell proportion respect font height (typical value = 1.25).
  11389.         * @access public
  11390.         * @since 3.0.014 (2008-06-04)
  11391.         */
  11392.         public function setCellHeightRatio($h
  11393.             $this->cell_height_ratio $h
  11394.         }
  11395.         
  11396.         /*
  11397.         * return the height of cell repect font height.
  11398.         * @access public
  11399.         * @since 4.0.012 (2008-07-24)
  11400.         */
  11401.         public function getCellHeightRatio(
  11402.             return $this->cell_height_ratio
  11403.         }
  11404.         
  11405.         /*
  11406.         * Set the PDF version (check PDF reference for valid values).
  11407.         * Default value is 1.t
  11408.         * @access public
  11409.         * @since 3.1.000 (2008-06-09)
  11410.         */
  11411.         public function setPDFVersion($version='1.7'
  11412.             $this->PDFVersion $version;
  11413.         }
  11414.         
  11415.         /*
  11416.         * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  11417.         * (see Section 8.1 of PDF reference, "Viewer Preferences").
  11418.         * <ul>
  11419.         * <li>HideToolbar boolean (Optional) A flag specifying whether to hide the viewer application's tool bars when the document is active. Default value: false.</li>
  11420.         * <li>HideMenubar boolean (Optional) A flag specifying whether to hide the viewer application's menu bar when the document is active. Default value: false.</li>
  11421.         * <li>HideWindowUI boolean (Optional) A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed. Default value: false.</li>
  11422.         * <li>FitWindow boolean (Optional) A flag specifying whether to resize the document's window to fit the size of the first displayed page. Default value: false.</li>
  11423.         * <li>CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.</li>
  11424.         * <li>DisplayDocTitle boolean (Optional; PDF 1.4) A flag specifying whether the window's title bar should display the document title taken from the Title entry of the document information dictionary (see Section 10.2.1, "Document Information Dictionary"). If false, the title bar should instead display the name of the PDF file containing the document. Default value: false.</li>
  11425.         * <li>NonFullScreenPageMode name (Optional) The document's page mode, specifying how to display the document on exiting full-screen mode:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>UseOC Optional content group panel visible</li><ul>This entry is meaningful only if the value of the PageMode entry in the catalog dictionary (see Section 3.6.1, "Document Catalog") is FullScreen; it is ignored otherwise. Default value: UseNone.</li>
  11426.         * <li>ViewArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be displayed when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  11427.         * <li>ViewClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  11428.         * <li>PrintArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be rendered when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  11429.         * <li>PrintClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li>
  11430.         * <li>PrintScaling name (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document. Valid values are: <ul><li>None, which indicates that the print dialog should reflect no page scaling</li><li>AppDefault (default), which indicates that applications should use the current print scaling</li><ul></li>
  11431.         * <li>Duplex name (Optional; PDF 1.7) The paper handling option to use when printing the file from the print dialog. The following values are valid:<ul><li>Simplex - Print single-sided</li><li>DuplexFlipShortEdge - Duplex and flip on the short edge of the sheet</li><li>DuplexFlipLongEdge - Duplex and flip on the long edge of the sheet</li></ul>Default value: none</li>
  11432.         * <li>PickTrayByPDFSize boolean (Optional; PDF 1.7) A flag specifying whether the PDF page size is used to select the input paper tray. This setting influences only the preset values used to populate the print dialog presented by a PDF viewer application. If PickTrayByPDFSize is true, the check box in the print dialog associated with input paper tray is checked. Note: This setting has no effect on Mac OS systems, which do not provide the ability to pick the input tray by size.</li>
  11433.         * <li>PrintPageRange array (Optional; PDF 1.7) The page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 1. Each pair consists of the first and last pages in the sub-range. An odd number of integers causes this entry to be ignored. Negative numbers cause the entire array to be ignored. Default value: as defined by PDF viewer application</li>
  11434.         * <li>NumCopies integer (Optional; PDF 1.7) The number of copies to be printed when the print dialog is opened for this file. Supported values are the integers 2 through 5. Values outside this range are ignored. Default value: as defined by PDF viewer application, but typically 1</li>
  11435.         * </ul>
  11436.         * @param array $preferences array of options.
  11437.         * @author Nicola Asuni
  11438.         * @access public
  11439.         * @since 3.1.000 (2008-06-09)
  11440.         */
  11441.         public function setViewerPreferences($preferences
  11442.             $this->viewer_preferences $preferences;
  11443.         }
  11444.         
  11445.         /**
  11446.         * Paints a linear colour gradient.
  11447.         * @param float $x abscissa of the top left corner of the rectangle.
  11448.         * @param float $y ordinate of the top left corner of the rectangle.
  11449.         * @param float $w width of the rectangle.
  11450.         * @param float $h height of the rectangle.
  11451.         * @param array $col1 first color (RGB components).
  11452.         * @param array $col2 second color (RGB components).
  11453.         * @param array $coords array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  11454.         * @author Andreas Würmser, Nicola Asuni
  11455.         * @since 3.1.000 (2008-06-09)
  11456.         * @access public
  11457.         */
  11458.         public function LinearGradient($x$y$w$h$col1=array()$col2=array()$coords=array(0,0,1,0)) {
  11459.             $this->Clip($x$y$w$h);
  11460.             $this->Gradient(2$col1$col2$coords);
  11461.         }
  11462.         
  11463.         /**
  11464.         * Paints a radial colour gradient.
  11465.         * @param float $x abscissa of the top left corner of the rectangle.
  11466.         * @param float $y ordinate of the top left corner of the rectangle.
  11467.         * @param float $w width of the rectangle.
  11468.         * @param float $h height of the rectangle.
  11469.         * @param array $col1 first color (RGB components).
  11470.         * @param array $col2 second color (RGB components).
  11471.         * @param array $coords array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined.
  11472.         * @author Andreas Würmser, Nicola Asuni
  11473.         * @since 3.1.000 (2008-06-09)
  11474.         * @access public
  11475.         */
  11476.         public function RadialGradient($x$y$w$h$col1=array()$col2=array()$coords=array(0.5,0.5,0.5,0.5,1)) {
  11477.             $this->Clip($x$y$w$h);
  11478.             $this->Gradient(3$col1$col2$coords);
  11479.         }
  11480.         
  11481.         /**
  11482.         * Paints a coons patch mesh.
  11483.         * @param float $x abscissa of the top left corner of the rectangle.
  11484.         * @param float $y ordinate of the top left corner of the rectangle.
  11485.         * @param float $w width of the rectangle.
  11486.         * @param float $h height of the rectangle.
  11487.         * @param array $col1 first color (lower left corner) (RGB components).
  11488.         * @param array $col2 second color (lower right corner) (RGB components).
  11489.         * @param array $col3 third color (upper right corner) (RGB components).
  11490.         * @param array $col4 fourth color (upper left corner) (RGB components).
  11491.         * @param array $coords <ul><li>for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).</li><li>for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches</li></ul>
  11492.         * @param array $coords_min minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  11493.         * @param array $coords_max maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  11494.         * @author Andreas Würmser, Nicola Asuni
  11495.         * @since 3.1.000 (2008-06-09)
  11496.         * @access public
  11497.         */
  11498.         public function CoonsPatchMesh($x$y$w$h$col1=array()$col2=array()$col3=array()$col4=array()$coords=array(0.00,0.0,0.33,0.00,0.67,0.00,1.00,0.00,1.00,0.33,1.00,0.67,1.00,1.00,0.67,1.00,0.33,1.00,0.00,1.00,0.00,0.67,0.00,0.33)$coords_min=0$coords_max=1{
  11499.             $this->Clip($x$y$w$h);        
  11500.             $n count($this->gradients1;
  11501.             $this->gradients[$n]['type'6//coons patch mesh
  11502.             //check the coords array if it is the simple array or the multi patch array
  11503.             if (!isset($coords[0]['f'])) {
  11504.                 //simple array -> convert to multi patch array
  11505.                 if (!isset($col1[1])) {
  11506.                     $col1[1$col1[2$col1[0];
  11507.                 }
  11508.                 if (!isset($col2[1])) {
  11509.                     $col2[1$col2[2$col2[0];
  11510.                 }
  11511.                 if (!isset($col3[1])) {
  11512.                     $col3[1$col3[2$col3[0];
  11513.                 }
  11514.                 if (!isset($col4[1])) {
  11515.                     $col4[1$col4[2$col4[0];
  11516.                 }
  11517.                 $patch_array[0]['f'0;
  11518.                 $patch_array[0]['points'$coords;
  11519.                 $patch_array[0]['colors'][0]['r'$col1[0];
  11520.                 $patch_array[0]['colors'][0]['g'$col1[1];
  11521.                 $patch_array[0]['colors'][0]['b'$col1[2];
  11522.                 $patch_array[0]['colors'][1]['r'$col2[0];
  11523.                 $patch_array[0]['colors'][1]['g'$col2[1];
  11524.                 $patch_array[0]['colors'][1]['b'$col2[2];
  11525.                 $patch_array[0]['colors'][2]['r'$col3[0];
  11526.                 $patch_array[0]['colors'][2]['g'$col3[1];
  11527.                 $patch_array[0]['colors'][2]['b'$col3[2];
  11528.                 $patch_array[0]['colors'][3]['r'$col4[0];
  11529.                 $patch_array[0]['colors'][3]['g'$col4[1];
  11530.                 $patch_array[0]['colors'][3]['b'$col4[2];
  11531.             else {
  11532.                 //multi patch array
  11533.                 $patch_array $coords;
  11534.             }
  11535.             $bpcd 65535//16 BitsPerCoordinate
  11536.             //build the data stream
  11537.             $this->gradients[$n]['stream''';
  11538.             $count_patch count($patch_array);
  11539.             for ($i=0$i $count_patch++$i{
  11540.                 $this->gradients[$n]['stream'.= chr($patch_array[$i]['f'])//start with the edge flag as 8 bit
  11541.                 $count_points count($patch_array[$i]['points']);
  11542.                 for ($j=0$j $count_points++$j{
  11543.                     //each point as 16 bit
  11544.                     $patch_array[$i]['points'][$j(($patch_array[$i]['points'][$j$coords_min($coords_max $coords_min)) $bpcd;
  11545.                     if ($patch_array[$i]['points'][$j0{
  11546.                         $patch_array[$i]['points'][$j0;
  11547.                     }
  11548.                     if ($patch_array[$i]['points'][$j$bpcd{
  11549.                         $patch_array[$i]['points'][$j$bpcd;
  11550.                     }
  11551.                     $this->gradients[$n]['stream'.= chr(floor($patch_array[$i]['points'][$j256));
  11552.                     $this->gradients[$n]['stream'.= chr(floor($patch_array[$i]['points'][$j256));
  11553.                 }
  11554.                 $count_cols count($patch_array[$i]['colors']);
  11555.                 for ($j=0$j $count_cols++$j{
  11556.                     //each color component as 8 bit
  11557.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['r']);
  11558.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['g']);
  11559.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['b']);
  11560.                 }
  11561.             }
  11562.             //paint the gradient
  11563.             $this->_out('/Sh'.$n.' sh');
  11564.             //restore previous Graphic State
  11565.             $this->_out('Q');
  11566.         }
  11567.         
  11568.         /**
  11569.         * Set a rectangular clipping area.
  11570.         * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  11571.         * @param float $y ordinate of the top left corner of the rectangle.
  11572.         * @param float $w width of the rectangle.
  11573.         * @param float $h height of the rectangle.
  11574.         * @author Andreas Würmser, Nicola Asuni
  11575.         * @since 3.1.000 (2008-06-09)
  11576.         * @access protected
  11577.         */
  11578.         protected function Clip($x$y$w$h{
  11579.             if ($this->rtl{
  11580.                 $x $this->w $x $w;
  11581.             }
  11582.             //save current Graphic State
  11583.             $s 'q';
  11584.             //set clipping area
  11585.             $s .= sprintf(' %.2F %.2F %.2F %.2F re W n'$x*$this->k($this->h-$y)*$this->k$w*$this->k-$h*$this->k);
  11586.             //set up transformation matrix for gradient
  11587.             $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm'$w*$this->k$h*$this->k$x*$this->k($this->h-($y+$h))*$this->k);
  11588.             $this->_out($s);
  11589.         }
  11590.                 
  11591.         /**
  11592.         * Output gradient.
  11593.         * @param int $type type of gradient.
  11594.         * @param array $col1 first color (RGB components).
  11595.         * @param array $col2 second color (RGB components).
  11596.         * @param array $coords array of coordinates.
  11597.         * @author Andreas Würmser, Nicola Asuni
  11598.         * @since 3.1.000 (2008-06-09)
  11599.         * @access protected
  11600.         */
  11601.         protected function Gradient($type$col1$col2$coords{
  11602.             $n count($this->gradients1;
  11603.             $this->gradients[$n]['type'$type;
  11604.             if (!isset($col1[1])) {
  11605.                 $col1[1]=$col1[2]=$col1[0];
  11606.             }
  11607.             $this->gradients[$n]['col1'sprintf('%.3F %.3F %.3F'($col1[0]/255)($col1[1]/255)($col1[2]/255));
  11608.             if (!isset($col2[1])) {
  11609.                 $col2[1$col2[2$col2[0];
  11610.             }
  11611.             $this->gradients[$n]['col2'sprintf('%.3F %.3F %.3F'($col2[0]/255)($col2[1]/255)($col2[2]/255));
  11612.             $this->gradients[$n]['coords'$coords;
  11613.             //paint the gradient
  11614.             $this->_out('/Sh'.$n.' sh');
  11615.             //restore previous Graphic State
  11616.             $this->_out('Q');
  11617.         }
  11618.         
  11619.         /**
  11620.         * Output shaders.
  11621.         * @author Andreas Würmser, Nicola Asuni
  11622.         * @since 3.1.000 (2008-06-09)
  11623.         * @access protected
  11624.         */
  11625.         function _putshaders({
  11626.             foreach ($this->gradients as $id => $grad{  
  11627.                 if (($grad['type'== 2OR ($grad['type'== 3)) {
  11628.                     $this->_newobj();
  11629.                     $this->_out('<<');
  11630.                     $this->_out('/FunctionType 2');
  11631.                     $this->_out('/Domain [0.0 1.0]');
  11632.                     $this->_out('/C0 ['.$grad['col1'].']');
  11633.                     $this->_out('/C1 ['.$grad['col2'].']');
  11634.                     $this->_out('/N 1');
  11635.                     $this->_out('>>');
  11636.                     $this->_out('endobj');
  11637.                     $f1 $this->n;
  11638.                 }
  11639.                 $this->_newobj();
  11640.                 $this->_out('<<');
  11641.                 $this->_out('/ShadingType '.$grad['type']);
  11642.                 $this->_out('/ColorSpace /DeviceRGB');
  11643.                 if ($grad['type'== 2{
  11644.                     $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]'$grad['coords'][0]$grad['coords'][1]$grad['coords'][2]$grad['coords'][3]));
  11645.                     $this->_out('/Function '.$f1.' 0 R');
  11646.                     $this->_out('/Extend [true true] ');
  11647.                     $this->_out('>>');
  11648.                 elseif ($grad['type'== 3{
  11649.                     //x0, y0, r0, x1, y1, r1
  11650.                     //at this this time radius of inner circle is 0
  11651.                     $this->_out(sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]'$grad['coords'][0]$grad['coords'][1]$grad['coords'][2]$grad['coords'][3]$grad['coords'][4]));
  11652.                     $this->_out('/Function '.$f1.' 0 R');
  11653.                     $this->_out('/Extend [true true] ');
  11654.                     $this->_out('>>');
  11655.                 elseif ($grad['type'== 6{
  11656.                     $this->_out('/BitsPerCoordinate 16');
  11657.                     $this->_out('/BitsPerComponent 8');
  11658.                     $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]');
  11659.                     $this->_out('/BitsPerFlag 8');
  11660.                     $this->_out('/Length '.strlen($grad['stream']));
  11661.                     $this->_out('>>');
  11662.                     $this->_putstream($grad['stream']);
  11663.                 }
  11664.                 $this->_out('endobj');
  11665.                 $this->gradients[$id]['id'$this->n;
  11666.             }
  11667.         }
  11668.  
  11669.         /**
  11670.         * Output an arc
  11671.         * @author Maxime Delorme, Nicola Asuni
  11672.         * @since 3.1.000 (2008-06-09)
  11673.         * @access protected
  11674.         */
  11675.         protected function _outarc($x1$y1$x2$y2$x3$y3 {
  11676.             $h $this->h;
  11677.             $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c'$x1*$this->k($h-$y1)*$this->k$x2*$this->k($h-$y2)*$this->k$x3*$this->k($h-$y3)*$this->k));
  11678.         }
  11679.         
  11680.         /**
  11681.         * Draw the sector of a circle.
  11682.         * It can be used for instance to render pie charts.
  11683.         * @param float $xc abscissa of the center.
  11684.         * @param float $yc ordinate of the center.
  11685.         * @param float $r radius.
  11686.         * @param float $a start angle (in degrees).
  11687.         * @param float $b end angle (in degrees).
  11688.         * @param string $style: D, F, FD or DF (draw, fill, fill and draw). Default: FD.
  11689.         * @param float $cw: indicates whether to go clockwise (default: true).
  11690.         * @param float $o: origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  11691.         * @author Maxime Delorme, Nicola Asuni
  11692.         * @since 3.1.000 (2008-06-09)
  11693.         * @access public
  11694.         */
  11695.         public function PieSector($xc$yc$r$a$b$style='FD'$cw=true$o=90{
  11696.             if ($this->rtl{
  11697.                 $xc $this->w $xc;
  11698.             }
  11699.             if ($cw{
  11700.                 $d $b;
  11701.                 $b $o $a;
  11702.                 $a $o $d;
  11703.             else {
  11704.                 $b += $o;
  11705.                 $a += $o;
  11706.             }
  11707.             $a ($a 360360;
  11708.             $b ($b 360360;
  11709.             if ($a $b{
  11710.                 $b +=360;
  11711.             }
  11712.             $b $b 360 M_PI;
  11713.             $a $a 360 M_PI;
  11714.             $d $b $a;
  11715.             if ($d == {
  11716.                 $d M_PI;
  11717.             }
  11718.             $k $this->k;
  11719.             $hp $this->h;
  11720.             if ($style=='F'{
  11721.                 $op 'f';
  11722.             elseif ($style=='FD' or $style=='DF'{
  11723.                 $op 'b';
  11724.             else {
  11725.                 $op 's';
  11726.             }
  11727.             if (sin($d/2)) {
  11728.                 $MyArc 4/(cos($d/2)) sin($d/2$r;
  11729.             }
  11730.             //first put the center
  11731.             $this->_out(sprintf('%.2F %.2F m'($xc)*$k($hp-$yc)*$k));
  11732.             //put the first point
  11733.             $this->_out(sprintf('%.2F %.2F l'($xc+$r*cos($a))*$k(($hp-($yc-$r*sin($a)))*$k)));
  11734.             //draw the arc
  11735.             if ($d (M_PI/2)) {
  11736.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  11737.             else {
  11738.                 $b $a $d/4;
  11739.                 $MyArc 4/3*(1-cos($d/8))/sin($d/8)*$r;
  11740.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  11741.                 $a $b;
  11742.                 $b $a $d/4;
  11743.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  11744.                 $a $b;
  11745.                 $b $a $d/4;
  11746.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b) );
  11747.                 $a $b;
  11748.                 $b $a $d/4;
  11749.                 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a)$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a)$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2)$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2)$xc+$r*cos($b)$yc-$r*sin($b));
  11750.             }
  11751.             //terminate drawing
  11752.             $this->_out($op);
  11753.         }
  11754.         
  11755.         /**
  11756.         * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  11757.         * Only vector drawing is supported, not text or bitmap.
  11758.         * Although the script was successfully tested with various AI format versions, best results are probably achieved with files that were exported in the AI3 format (tested with Illustrator CS2, Freehand MX and Photoshop CS2).
  11759.         * @param string $file Name of the file containing the image.
  11760.         * @param float $x Abscissa of the upper-left corner.
  11761.         * @param float $y Ordinate of the upper-left corner.
  11762.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  11763.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  11764.         * @param mixed $link URL or identifier returned by AddLink().
  11765.         * @param boolean useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  11766.         * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  11767.         * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  11768.         * @param mixed $border Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  11769.         * @author Valentin Schmidt, Nicola Asuni
  11770.         * @since 3.1.000 (2008-06-09)
  11771.         * @access public
  11772.         */
  11773.         public function ImageEps($file$x=''$y=''$w=0$h=0$link=''$useBoundingBox=true$align=''$palign=''$border=0{
  11774.             if ($x === ''{
  11775.                 $x $this->x;
  11776.             }
  11777.             if ($y === ''{
  11778.                 $y $this->y;
  11779.             }
  11780.             $k $this->k;
  11781.             $data file_get_contents($file);
  11782.             if ($data === false{
  11783.                 $this->Error('EPS file not found: '.$file);
  11784.             }
  11785.             $regs array();
  11786.             // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  11787.             preg_match("/%%Creator:([^\r\n]+)/"$data$regs)# find Creator
  11788.             if (count($regs1{
  11789.                 $version_str trim($regs[1])# e.g. "Adobe Illustrator(R) 8.0"
  11790.                 if (strpos($version_str'Adobe Illustrator'!== false{
  11791.                     $versexp explode(' '$version_str);
  11792.                     $version = (float)array_pop($versexp);
  11793.                     if ($version >= 9{
  11794.                         $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  11795.                     }
  11796.                 }
  11797.             }
  11798.             // strip binary bytes in front of PS-header
  11799.             $start strpos($data'%!PS-Adobe');
  11800.             if ($start 0{
  11801.                 $data substr($data$start);
  11802.             }
  11803.             // find BoundingBox params
  11804.             preg_match("/%%BoundingBox:([^\r\n]+)/"$data$regs);
  11805.             if (count($regs1{
  11806.                 list($x1$y1$x2$y2explode(' 'trim($regs[1]));
  11807.             else {
  11808.                 $this->Error('No BoundingBox found in EPS file: '.$file);
  11809.             }
  11810.             $start strpos($data'%%EndSetup');
  11811.             if ($start === false{
  11812.                 $start strpos($data'%%EndProlog');
  11813.             }
  11814.             if ($start === false{
  11815.                 $start strpos($data'%%BoundingBox');
  11816.             }
  11817.             $data substr($data$start);
  11818.             $end strpos($data'%%PageTrailer');
  11819.             if ($end===false{
  11820.                 $end strpos($data'showpage');
  11821.             }
  11822.             if ($end{
  11823.                 $data substr($data0$end);
  11824.             }
  11825.             if ($w 0{
  11826.                 $scale_x $w (($x2 $x1$k);
  11827.                 if ($h 0{
  11828.                     $scale_y $h (($y2 $y1$k);
  11829.                 else {
  11830.                     $scale_y $scale_x;
  11831.                     $h ($y2 $y1$k $scale_y;
  11832.                 }
  11833.             else {
  11834.                 if ($h 0{
  11835.                     $scale_y $h (($y2 $y1$k);
  11836.                     $scale_x $scale_y;
  11837.                     $w ($x2-$x1$k $scale_x;
  11838.                 else {
  11839.                     $w ($x2 $x1$k;
  11840.                     $h ($y2 $y1$k;
  11841.                 }
  11842.             }
  11843.             // Check whether we need a new page first as this does not fit
  11844.             if ($this->checkPageBreak($h$y)) {
  11845.                 $y $this->GetY($this->cMargin;
  11846.             }
  11847.             // set bottomcoordinates
  11848.             $this->img_rb_y $y $h;
  11849.             // set alignment
  11850.             if ($this->rtl{
  11851.                 if ($palign == 'L'{
  11852.                     $ximg $this->lMargin;
  11853.                     // set right side coordinate
  11854.                     $this->img_rb_x $ximg $w;
  11855.                 elseif ($palign == 'C'{
  11856.                     $ximg ($this->w $x $w2;
  11857.                     // set right side coordinate
  11858.                     $this->img_rb_x $ximg $w;
  11859.                 else {
  11860.                     $ximg $this->w $x $w;
  11861.                     // set left side coordinate
  11862.                     $this->img_rb_x $ximg;
  11863.                 }
  11864.             else {
  11865.                 if ($palign == 'R'{
  11866.                     $ximg $this->w $this->rMargin $w;
  11867.                     // set left side coordinate
  11868.                     $this->img_rb_x $ximg;
  11869.                 elseif ($palign == 'C'{
  11870.                     $ximg ($this->w $x $w2;
  11871.                     // set right side coordinate
  11872.                     $this->img_rb_x $ximg $w;
  11873.                 else {
  11874.                     $ximg $x;
  11875.                     // set right side coordinate
  11876.                     $this->img_rb_x $ximg $w;
  11877.                 }
  11878.             }
  11879.             if ($useBoundingBox{
  11880.                 $dx $ximg $k $x1;
  11881.                 $dy $y $k $y1;
  11882.             else {
  11883.                 $dx $ximg $k;
  11884.                 $dy $y $k;
  11885.             }
  11886.             // save the current graphic state
  11887.             $this->_out('q'.$this->epsmarker);
  11888.             // translate
  11889.             $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'1001$dx$dy ($this->hPt ($y $k($y2 $y1))));
  11890.             // scale
  11891.             if (isset($scale_x)) {
  11892.                 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'$scale_x00$scale_y$x1 ($scale_x)$y2 ($scale_y)));
  11893.             }
  11894.             // handle pc/unix/mac line endings
  11895.             preg_match('/[\r\n]+/s'$data$regs);
  11896.             $lines explode($regs[0]$data);
  11897.             $u=0;
  11898.             $cnt count($lines);
  11899.             for ($i=0$i $cnt++$i{
  11900.                 $line $lines[$i];
  11901.                 if (($line == ''OR ($line{0== '%')) {
  11902.                     continue;
  11903.                 }
  11904.                 $len strlen($line);
  11905.                 $chunks explode(' '$line);
  11906.                 $cmd array_pop($chunks);
  11907.                 // RGB
  11908.                 if (($cmd == 'Xa'OR ($cmd == 'XA')) {
  11909.                     $b array_pop($chunks)
  11910.                     $g array_pop($chunks)
  11911.                     $r array_pop($chunks);
  11912.                     $this->_out(''.$r.' '.$g.' '.$b.' '.($cmd=='Xa'?'rg':'RG'))//substr($line, 0, -2).'rg' -> in EPS (AI8): c m y k r g b rg!
  11913.                     continue;
  11914.                 }
  11915.                 switch ($cmd{
  11916.                     case 'm':
  11917.                     case 'l':
  11918.                     case 'v':
  11919.                     case 'y':
  11920.                     case 'c':
  11921.                     case 'k':
  11922.                     case 'K':
  11923.                     case 'g':
  11924.                     case 'G':
  11925.                     case 's':
  11926.                     case 'S':
  11927.                     case 'J':
  11928.                     case 'j':
  11929.                     case 'w':
  11930.                     case 'M':
  11931.                     case 'd':
  11932.                     case 'n':
  11933.                     case 'v'{
  11934.                         $this->_out($line);
  11935.                         break;
  11936.                     }
  11937.                     case 'x'{// custom fill color
  11938.                         list($c,$m,$y,$k$chunks;
  11939.                         $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' k');
  11940.                         break;
  11941.                     }
  11942.                     case 'X'// custom stroke color
  11943.                         list($c,$m,$y,$k$chunks;
  11944.                         $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' K');
  11945.                         break;
  11946.                     }
  11947.                     case 'Y':
  11948.                     case 'N':
  11949.                     case 'V':
  11950.                     case 'L':
  11951.                     case 'C'{
  11952.                         $line{$len-1strtolower($cmd);
  11953.                         $this->_out($line);
  11954.                         break;
  11955.                     }
  11956.                     case 'b':
  11957.                     case 'B'{
  11958.                         $this->_out($cmd '*');
  11959.                         break;
  11960.                     }
  11961.                     case 'f':
  11962.                     case 'F'{
  11963.                         if ($u 0{
  11964.                             $isU false;
  11965.                             $max min($i+5$cnt);
  11966.                             for ($j=$i+1$j $max++$j)
  11967.                               $isU ($isU OR (($lines[$j== 'U'OR ($lines[$j== '*U')));
  11968.                             if ($isU{
  11969.                                 $this->_out('f*');
  11970.                             }
  11971.                         else {
  11972.                             $this->_out('f*');
  11973.                         }
  11974.                         break;
  11975.                     }
  11976.                     case '*u'{
  11977.                         ++$u;
  11978.                         break;
  11979.                     }
  11980.                     case '*U'{
  11981.                         --$u;
  11982.                         break;
  11983.                     }
  11984.                 }
  11985.             }
  11986.             // restore previous graphic state
  11987.             $this->_out($this->epsmarker.'Q');
  11988.             if (!empty($border)) {
  11989.                 $bx $x;
  11990.                 $by $y;
  11991.                 $this->x $x;
  11992.                 $this->y $y;
  11993.                 $this->Cell($w$h''$border0''0''0);
  11994.                 $this->x $bx;
  11995.                 $this->y $by;
  11996.             }
  11997.             if ($link{
  11998.                 $this->Link($ximg$y$w$h$link0);
  11999.             }
  12000.             // set pointer to align the successive text/objects
  12001.             switch($align{
  12002.                 case 'T':{
  12003.                     $this->y $y;
  12004.                     $this->x $this->img_rb_x;
  12005.                     break;
  12006.                 }
  12007.                 case 'M':{
  12008.                     $this->y $y round($h/2);
  12009.                     $this->x $this->img_rb_x;
  12010.                     break;
  12011.                 }
  12012.                 case 'B':{
  12013.                     $this->y $this->img_rb_y;
  12014.                     $this->x $this->img_rb_x;
  12015.                     break;
  12016.                 }
  12017.                 case 'N':{
  12018.                     $this->SetY($this->img_rb_y);
  12019.                     break;
  12020.                 }
  12021.                 default:{
  12022.                     break;
  12023.                 }
  12024.             }
  12025.             $this->endlinex $this->img_rb_x;
  12026.         }
  12027.         
  12028.         /**
  12029.           * Set document barcode.
  12030.          * @param string $bc barcode
  12031.          * @access public
  12032.          */
  12033.         public function setBarcode($bc=''{
  12034.             $this->barcode $bc;
  12035.         }
  12036.         
  12037.         /**
  12038.           * Get current barcode.
  12039.          * @return string 
  12040.          * @access public
  12041.          * @since 4.0.012 (2008-07-24)
  12042.          */
  12043.         public function getBarcode({
  12044.             return $this->barcode;
  12045.         }
  12046.         
  12047.         /**
  12048.           * Print a Linear Barcode.
  12049.           * @param string $code code to print
  12050.           * @param string $type type of barcode.
  12051.          * @param int $x x position in user units
  12052.          * @param int $y y position in user units
  12053.          * @param int $w width in user units
  12054.          * @param int $h height in user units
  12055.          * @param float $xres width of the smallest bar in user units
  12056.          * @param array $style array of options:<ul><li>string $style['position'] barcode position inside the specified width: L = left (default for LTR); C = center; R = right (default for RTL); S = stretch</li><li>boolean $style['border'] if true prints a border around the barcode</li><li>int $style['padding'] padding to leave around the barcode in user units</li><li>array $style['fgcolor'] color array for bars and text</li><li>mixed $style['bgcolor'] color array for background or false for transparent</li><li>boolean $style["text"] boolean if true prints text below the barcode</li><li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li><li>int $style['stretchtext']: 0 = disabled; 1 = horizontal scaling only if necessary; 2 = forced horizontal scaling; 3 = character spacing only if necessary; 4 = forced character spacing</li></ul>
  12057.          * @param string $align Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  12058.          * @author Nicola Asuni
  12059.          * @since 3.1.000 (2008-06-09)
  12060.          * @access public
  12061.          */
  12062.         public function write1DBarcode($code$type$x=''$y=''$w=''$h=''$xres=0.4$style=''$align=''{
  12063.             if ($this->empty_string($code)) {
  12064.                 return;
  12065.             }
  12066.             require_once(dirname(__FILE__).'/barcodes.php');
  12067.             // save current graphic settings
  12068.             $gvars $this->getGraphicVars();
  12069.             // create new barcode object
  12070.             $barcodeobj new TCPDFBarcode($code$type);
  12071.             $arrcode $barcodeobj->getBarcodeArray();
  12072.             if ($arrcode === false{
  12073.                 $this->Error('Error in 1D barcode string');
  12074.             }
  12075.             // set default values
  12076.             if (!isset($style['position'])) {
  12077.                 if ($this->rtl{
  12078.                     $style['position''R';
  12079.                 else {
  12080.                     $style['position''L';
  12081.                 }
  12082.             }
  12083.             if (!isset($style['padding'])) {
  12084.                 $style['padding'0;
  12085.             }
  12086.             if (!isset($style['fgcolor'])) {
  12087.                 $style['fgcolor'array(0,0,0)// default black
  12088.             }
  12089.             if (!isset($style['bgcolor'])) {
  12090.                 $style['bgcolor'false// default transparent
  12091.             }
  12092.             if (!isset($style['border'])) {
  12093.                 $style['border'false;
  12094.             }
  12095.             $fontsize 0;
  12096.             if (!isset($style['text'])) {
  12097.                 $style['text'false;
  12098.             }
  12099.             if ($style['text'AND isset($style['font'])) {
  12100.                 if (isset($style['fontsize'])) {
  12101.                     $fontsize $style['fontsize'];
  12102.                 }
  12103.                 $this->SetFont($style['font']''$fontsize);
  12104.             }
  12105.             if (!isset($style['stretchtext'])) {
  12106.                 $style['stretchtext'4;
  12107.             }
  12108.             // set foreground color
  12109.             $this->SetDrawColorArray($style['fgcolor']);
  12110.             $this->SetTextColorArray($style['fgcolor']);
  12111.             if ($this->empty_string($wOR ($w <= 0)) {
  12112.                 if ($this->rtl{
  12113.                     $w $this->x $this->lMargin;
  12114.                 else {
  12115.                     $w $this->w $this->rMargin $this->x;
  12116.                 }
  12117.             }
  12118.             if ($this->empty_string($x)) {
  12119.                 $x $this->GetX();
  12120.             }
  12121.             if ($this->rtl{
  12122.                 $x $this->w $x;
  12123.             }
  12124.             if ($this->empty_string($y)) {
  12125.                 $y $this->GetY();
  12126.             }
  12127.             if ($this->empty_string($xres)) {
  12128.                 $xres 0.4;
  12129.             }
  12130.             $fbw ($arrcode['maxw'$xres($style['padding']);
  12131.             $extraspace ($this->cell_height_ratio $fontsize $this->k($style['padding']);
  12132.             if ($this->empty_string($hOR ($h <= 0)) {
  12133.                 $h 10 $extraspace;
  12134.             }
  12135.             if ($this->checkPageBreak($h)) {
  12136.                 $y $this->y;
  12137.             }
  12138.             // maximum bar heigth
  12139.             $barh $h $extraspace;
  12140.             switch ($style['position']{
  12141.                 case 'L'// left
  12142.                     if ($this->rtl{
  12143.                         $xpos $x $w;
  12144.                     else {
  12145.                         $xpos $x;
  12146.                     }
  12147.                     break;
  12148.                 }
  12149.                 case 'C'// center
  12150.                     $xdiff (($w $fbw2);
  12151.                     if ($this->rtl{
  12152.                         $xpos $x $w $xdiff;
  12153.                     else {
  12154.                         $xpos $x $xdiff;
  12155.                     }
  12156.                     break;
  12157.                 }
  12158.                 case 'R'// right
  12159.                     if ($this->rtl{
  12160.                         $xpos $x $fbw;
  12161.                     else {
  12162.                         $xpos $x $w $fbw;
  12163.                     }
  12164.                     break;
  12165.                 }
  12166.                 case 'S'// stretch
  12167.                     $fbw $w;
  12168.                     $xres ($w ($style['padding'])) $arrcode['maxw'];
  12169.                     if ($this->rtl{
  12170.                         $xpos $x $w;
  12171.                     else {
  12172.                         $xpos $x;
  12173.                     }
  12174.                     break;
  12175.                 }
  12176.             }
  12177.             $xpos_rect $xpos;
  12178.             $xpos $xpos_rect $style['padding'];
  12179.             $xpos_text $xpos;
  12180.             // barcode is always printed in LTR direction
  12181.             $tempRTL $this->rtl;
  12182.             $this->rtl false;
  12183.             // print background color
  12184.             if ($style['bgcolor']{
  12185.                 $this->Rect($xpos_rect$y$fbw$h$style['border''DF' 'F'''$style['bgcolor']);
  12186.             elseif ($style['border']{
  12187.                 $this->Rect($xpos_rect$y$fbw$h'D');
  12188.             }
  12189.             // print bars
  12190.             if ($arrcode !== false{
  12191.                 foreach ($arrcode['bcode'as $k => $v{
  12192.                     $bw ($v['w'$xres);
  12193.                     if ($v['t']{
  12194.                         // draw a vertical bar
  12195.                         $ypos $y $style['padding'($v['p'$barh $arrcode['maxh']);
  12196.                         $this->Rect($xpos$ypos$bw($v['h'$barh  $arrcode['maxh'])'F'array()$style['fgcolor']);
  12197.                     }
  12198.                     $xpos += $bw;
  12199.                 }
  12200.             }
  12201.             // print text
  12202.             if ($style['text']{
  12203.                 // print text
  12204.                 $this->x $xpos_text;
  12205.                 $this->y $y $style['padding'$barh
  12206.                 $this->Cell(($arrcode['maxw'$xres)($this->cell_height_ratio $fontsize $this->k)$code00'C'0''$style['stretchtext']);
  12207.             }
  12208.             // restore original direction
  12209.             $this->rtl $tempRTL;
  12210.             // restore previous settings
  12211.             $this->setGraphicVars($gvars);
  12212.             // set bottomcoordinates
  12213.             $this->img_rb_y $y $h;
  12214.             if ($this->rtl{
  12215.                 // set left side coordinate
  12216.                 $this->img_rb_x ($this->w $x $w);
  12217.             else {
  12218.                 // set right side coordinate
  12219.                 $this->img_rb_x $x $w;
  12220.             }
  12221.             // set pointer to align the successive text/objects
  12222.             switch($align{
  12223.                 case 'T':{
  12224.                     $this->y $y;
  12225.                     $this->x $this->img_rb_x;
  12226.                     break;
  12227.                 }
  12228.                 case 'M':{
  12229.                     $this->y $y round($h/2);
  12230.                     $this->x $this->img_rb_x;
  12231.                     break;
  12232.                 }
  12233.                 case 'B':{
  12234.                     $this->y $this->img_rb_y;
  12235.                     $this->x $this->img_rb_x;
  12236.                     break;
  12237.                 }
  12238.                 case 'N':{
  12239.                     $this->SetY($this->img_rb_y);
  12240.                     break;
  12241.                 }
  12242.                 default:{
  12243.                     break;
  12244.                 }
  12245.             }
  12246.         }
  12247.         
  12248.         /**
  12249.           * This function is DEPRECATED, please use the new write1DBarcode() function.
  12250.          * @param int $x x position in user units
  12251.          * @param int $y y position in user units
  12252.          * @param int $w width in user units
  12253.          * @param int $h height position in user units
  12254.          * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
  12255.          * @param string $style barcode style
  12256.          * @param string $font font for text
  12257.          * @param int $xres x resolution
  12258.          * @param string $code code to print
  12259.          * @deprecated deprecated since version 3.1.000 (2008-06-10)
  12260.          * @access public
  12261.          * @see write1DBarcode()
  12262.          */
  12263.         public function writeBarcode($x$y$w$h$type$style$font$xres$code{
  12264.             // convert old settings for the new write1DBarcode() function.
  12265.             $xres $xres;
  12266.             $newstyle array(
  12267.                 'position' => 'L',
  12268.                 'border' => false,
  12269.                 'padding' => 0,
  12270.                 'fgcolor' => array(0,0,0),
  12271.                 'bgcolor' => false,
  12272.                 'text' => true,
  12273.                 'font' => $font,
  12274.                 'fontsize' => 8,
  12275.                 'stretchtext' => 4
  12276.             );
  12277.             if ($style 1{
  12278.                 $newstyle['border'true;
  12279.             }
  12280.             if ($style 2{
  12281.                 $newstyle['bgcolor'false;
  12282.             }
  12283.             if ($style 4{
  12284.                 $newstyle['position''C';
  12285.             elseif ($style 8{
  12286.                 $newstyle['position''L';
  12287.             elseif ($style 16{
  12288.                 $newstyle['position''R';
  12289.             }
  12290.             if ($style 128{
  12291.                 $newstyle['text'true;
  12292.             }
  12293.             if ($style 256{
  12294.                 $newstyle['stretchtext'4;
  12295.             }
  12296.             $this->write1DBarcode($code$type$x$y$w$h$xres$newstyle'');
  12297.         }
  12298.         
  12299.         /**
  12300.           * Print 2D Barcode.
  12301.           * @param string $code code to print
  12302.           * @param string $type type of barcode.
  12303.          * @param int $x x position in user units
  12304.          * @param int $y y position in user units
  12305.          * @param int $w width in user units
  12306.          * @param int $h height in user units
  12307.          * @param array $style array of options:<ul><li>boolean $style['border'] if true prints a border around the barcode</li><li>int $style['padding'] padding to leave around the barcode in user units</li><li>array $style['fgcolor'] color array for bars and text</li><li>mixed $style['bgcolor'] color array for background or false for transparent</li></ul>
  12308.          * @param string $align Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  12309.          * @author Nicola Asuni
  12310.          * @since 4.5.037 (2009-04-07)
  12311.          * @access public
  12312.          */
  12313.         public function write2DBarcode($code$type$x=''$y=''$w=''$h=''$style=''$align=''{
  12314.             if ($this->empty_string($code)) {
  12315.                 return;
  12316.             }
  12317.             require_once(dirname(__FILE__).'/2dbarcodes.php');
  12318.             // save current graphic settings
  12319.             $gvars $this->getGraphicVars();
  12320.             // create new barcode object
  12321.             $barcodeobj new TCPDF2DBarcode($code$type);
  12322.             $arrcode $barcodeobj->getBarcodeArray();
  12323.             if ($arrcode === false{
  12324.                 $this->Error('Error in 2D barcode string');
  12325.             }
  12326.             // set default values
  12327.             if (!isset($style['padding'])) {
  12328.                 $style['padding'0;
  12329.             }
  12330.             if (!isset($style['fgcolor'])) {
  12331.                 $style['fgcolor'array(0,0,0)// default black
  12332.             }
  12333.             if (!isset($style['bgcolor'])) {
  12334.                 $style['bgcolor'false// default transparent
  12335.             }
  12336.             if (!isset($style['border'])) {
  12337.                 $style['border'false;
  12338.             }
  12339.             // set foreground color
  12340.             $this->SetDrawColorArray($style['fgcolor']);
  12341.             if ($this->empty_string($x)) {
  12342.                 $x $this->GetX();
  12343.             }
  12344.             if ($this->rtl{
  12345.                 $x $this->w $x;
  12346.             }
  12347.             if ($this->empty_string($y)) {
  12348.                 $y $this->GetY();
  12349.             }
  12350.             if ($this->empty_string($wOR ($w <= 0)) {
  12351.                 if ($this->rtl{
  12352.                     $w $x $this->lMargin;
  12353.                 else {
  12354.                     $w $this->w $this->rMargin $x;
  12355.                 }
  12356.             }
  12357.             if ($this->empty_string($hOR ($h <= 0)) {
  12358.                 // 2d barcodes are square by default
  12359.                 $h $w;
  12360.             }
  12361.             if ($this->checkPageBreak($h)) {
  12362.                 $y $this->y;
  12363.             }
  12364.             // calculate barcode size (excluding padding)
  12365.             $bw $w ($style['padding']);
  12366.             $bh $h ($style['padding']);
  12367.             // calculate starting coordinates
  12368.             if ($this->rtl{
  12369.                 $xpos $x $w;
  12370.             else {
  12371.                 $xpos $x;
  12372.             }
  12373.             $xpos += $style['padding'];
  12374.             $ypos $y $style['padding'];
  12375.             // barcode is always printed in LTR direction
  12376.             $tempRTL $this->rtl;
  12377.             $this->rtl false;
  12378.             // print background color
  12379.             if ($style['bgcolor']{
  12380.                 $this->Rect($x$y$w$h$style['border''DF' 'F'''$style['bgcolor']);
  12381.             elseif ($style['border']{
  12382.                 $this->Rect($x$y$w$h'D');
  12383.             }
  12384.             // print barcode cells
  12385.             if ($arrcode !== false{
  12386.                 $rows $arrcode['num_rows'];
  12387.                 $cols $arrcode['num_cols'];
  12388.                 // calculate dimension of single barcode cell
  12389.                 $cw $bw $cols;
  12390.                 $ch $bh $rows;
  12391.                 // for each row
  12392.                 for ($r 0$r $rows++$r{
  12393.                     $xr $xpos;
  12394.                     // for each column
  12395.                     for ($c 0$c $cols++$c{
  12396.                         if ($arrcode['bcode'][$r][$c== 1{
  12397.                             // draw a single barcode cell
  12398.                             $this->Rect($xr$ypos$cw$ch'F'array()$style['fgcolor']);
  12399.                         }
  12400.                         $xr += $cw;
  12401.                     }
  12402.                     $ypos += $ch;
  12403.                 }
  12404.             }
  12405.             // restore original direction
  12406.             $this->rtl $tempRTL;
  12407.             // restore previous settings
  12408.             $this->setGraphicVars($gvars);
  12409.             // set bottomcoordinates
  12410.             $this->img_rb_y $y $h;
  12411.             if ($this->rtl{
  12412.                 // set left side coordinate
  12413.                 $this->img_rb_x ($this->w $x $w);
  12414.             else {
  12415.                 // set right side coordinate
  12416.                 $this->img_rb_x $x $w;
  12417.             }
  12418.             // set pointer to align the successive text/objects
  12419.             switch($align{
  12420.                 case 'T':{
  12421.                     $this->y $y;
  12422.                     $this->x $this->img_rb_x;
  12423.                     break;
  12424.                 }
  12425.                 case 'M':{
  12426.                     $this->y $y round($h/2);
  12427.                     $this->x $this->img_rb_x;
  12428.                     break;
  12429.                 }
  12430.                 case 'B':{
  12431.                     $this->y $this->img_rb_y;
  12432.                     $this->x $this->img_rb_x;
  12433.                     break;
  12434.                 }
  12435.                 case 'N':{
  12436.                     $this->SetY($this->img_rb_y);
  12437.                     break;
  12438.                 }
  12439.                 default:{
  12440.                     break;
  12441.                 }
  12442.             }
  12443.         }
  12444.         
  12445.         /**
  12446.          * Returns an array containing current margins:
  12447.          * <ul>
  12448.                 <li>$ret['left'] = left  margin</li>
  12449.                 <li>$ret['right'] = right margin</li>
  12450.                 <li>$ret['top'] = top margin</li>
  12451.                 <li>$ret['bottom'] = bottom margin</li>
  12452.                 <li>$ret['header'] = header margin</li>
  12453.                 <li>$ret['footer'] = footer margin</li>
  12454.                 <li>$ret['cell'] = cell margin</li>
  12455.          * </ul>
  12456.          * @return array containing all margins measures
  12457.          * @access public
  12458.          * @since 3.2.000 (2008-06-23)
  12459.          */
  12460.         public function getMargins({
  12461.             $ret array(
  12462.                 'left' => $this->lMargin,
  12463.                 'right' => $this->rMargin,
  12464.                 'top' => $this->tMargin,
  12465.                 'bottom' => $this->bMargin,
  12466.                 'header' => $this->header_margin,
  12467.                 'footer' => $this->footer_margin,
  12468.                 'cell' => $this->cMargin,
  12469.             );
  12470.             return $ret;
  12471.         }
  12472.         
  12473.         /**
  12474.          * Returns an array containing original margins:
  12475.          * <ul>
  12476.                 <li>$ret['left'] = left  margin</li>
  12477.                 <li>$ret['right'] = right margin</li>
  12478.          * </ul>
  12479.          * @return array containing all margins measures
  12480.          * @access public
  12481.          * @since 4.0.012 (2008-07-24)
  12482.          */
  12483.         public function getOriginalMargins({
  12484.             $ret array(
  12485.                 'left' => $this->original_lMargin,
  12486.                 'right' => $this->original_rMargin
  12487.             );
  12488.             return $ret;
  12489.         }
  12490.         
  12491.         /**
  12492.          * Returns the current font size.
  12493.          * @return current font size
  12494.          * @access public
  12495.          * @since 3.2.000 (2008-06-23)
  12496.          */
  12497.         public function getFontSize({
  12498.             return $this->FontSize;
  12499.         }
  12500.         
  12501.         /**
  12502.          * Returns the current font size in points unit.
  12503.          * @return current font size in points unit
  12504.          * @access public
  12505.          * @since 3.2.000 (2008-06-23)
  12506.          */
  12507.         public function getFontSizePt({
  12508.             return $this->FontSizePt;
  12509.         }
  12510.  
  12511.         /**
  12512.          * Returns the current font family name.
  12513.          * @return string current font family name
  12514.          * @access public
  12515.          * @since 4.3.008 (2008-12-05)
  12516.          */
  12517.         public function getFontFamily({
  12518.             return $this->FontFamily;
  12519.         }
  12520.  
  12521.         /**
  12522.          * Returns the current font style.
  12523.          * @return string current font style
  12524.          * @access public
  12525.          * @since 4.3.008 (2008-12-05)
  12526.          */
  12527.         public function getFontStyle({
  12528.             return $this->FontStyle;
  12529.         }
  12530.         
  12531.         /**
  12532.          * Prints a cell (rectangular area) with optional borders, background color and html text string.
  12533.          * The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.<br />
  12534.          * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  12535.          * @param float $w Cell width. If 0, the cell extends up to the right margin.
  12536.          * @param float $h Cell minimum height. The cell extends automatically if needed.
  12537.          * @param float $x upper-left corner X coordinate
  12538.          * @param float $y upper-left corner Y coordinate
  12539.          * @param string $html html text to print. Default value: empty string.
  12540.          * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  12541.          * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL language)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  12542.     Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  12543.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  12544.          * @param boolean $reseth if true reset the last cell height (default true).
  12545.          * @param string $align Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  12546.          * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  12547.          * @access public
  12548.          * @uses MultiCell()
  12549.          * @see Multicell(), writeHTML()
  12550.          */
  12551.         public function writeHTMLCell($w$h$x$y$html=''$border=0$ln=0$fill=0$reseth=true$align=''$autopadding=true{
  12552.             return $this->MultiCell($w$h$html$border$align$fill$ln$x$y$reseth0true$autopadding0);
  12553.         }
  12554.         
  12555.         /**
  12556.           * Returns the HTML DOM array.
  12557.           * <ul><li>$dom[$key]['tag'] = true if tag, false otherwise;</li><li>$dom[$key]['value'] = tag name or text;</li><li>$dom[$key]['opening'] = true if opening tag, false otherwise;</li><li>$dom[$key]['attribute'] = array of attributes (attribute name is the key);</li><li>$dom[$key]['style'] = array of style attributes (attribute name is the key);</li><li>$dom[$key]['parent'] = id of parent element;</li><li>$dom[$key]['fontname'] = font family name;</li><li>$dom[$key]['fontstyle'] = font style;</li><li>$dom[$key]['fontsize'] = font size in points;</li><li>$dom[$key]['bgcolor'] = RGB array of background color;</li><li>$dom[$key]['fgcolor'] = RGB array of foreground color;</li><li>$dom[$key]['width'] = width in pixels;</li><li>$dom[$key]['height'] = height in pixels;</li><li>$dom[$key]['align'] = text alignment;</li><li>$dom[$key]['cols'] = number of colums in table;</li><li>$dom[$key]['rows'] = number of rows in table;</li></ul>
  12558.          * @param string $html html code
  12559.          * @return array 
  12560.          * @access protected
  12561.          * @since 3.2.000 (2008-06-20)
  12562.          */
  12563.         protected function getHtmlDomArray($html{
  12564.             // remove all unsupported tags (the line below lists all supported tags)
  12565.             $html strip_tags($html'<marker/><a><b><blockquote><br><br/><dd><del><div><dl><dt><em><font><form><h1><h2><h3><h4><h5><h6><hr><i><img><input><label><li><ol><option><p><pre><select><small><span><strong><sub><sup><table><tablehead><tcpdf><td><textarea><th><thead><tr><tt><u><ul>');
  12566.             //replace some blank characters
  12567.             $html preg_replace('/<pre/''<xre'$html)// preserve pre tag
  12568.             $html preg_replace('/<(table|tr|td|th|tcpdf|blockquote|dd|div|dt|form|h1|h2|h3|h4|h5|h6|br|hr|li|ol|ul|p)([^\>]*)>[\n\r\t]+/''<\\1\\2>'$html);
  12569.             $html preg_replace('@(\r\n|\r)@'"\n"$html);
  12570.             $repTable array("\t" => ' '"\0" => ' '"\x0B" => ' '"\\" => "\\\\");
  12571.             $html strtr($html$repTable);
  12572.             $offset 0;
  12573.             while (($offset strlen($html)) AND ($pos strpos($html'</pre>'$offset)) !== false{
  12574.                 $html_a substr($html0$offset);
  12575.                 $html_b substr($html$offset($pos $offset 6));
  12576.                 while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si"$html_b)) {
  12577.                     // preserve newlines on <pre> tag
  12578.                     $html_b preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si""<xre\\1>\\2<br />\\3</pre>"$html_b);
  12579.                 }
  12580.                 $html $html_a.$html_b.substr($html$pos 6);
  12581.                 $offset strlen($html_a.$html_b);
  12582.             }
  12583.             $offset 0;
  12584.             while (($offset strlen($html)) AND ($pos strpos($html'</textarea>'$offset)) !== false{
  12585.                 $html_a substr($html0$offset);
  12586.                 $html_b substr($html$offset($pos $offset 11));
  12587.                 while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si"$html_b)) {
  12588.                     // preserve newlines on <textarea> tag
  12589.                     $html_b preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si""<textarea\\1>\\2<TBR>\\3</textarea>"$html_b);
  12590.                     $html_b preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si""<textarea\\1>\\2''\\3</textarea>"$html_b);
  12591.                 }
  12592.                 $html $html_a.$html_b.substr($html$pos 11);
  12593.                 $offset strlen($html_a.$html_b);
  12594.             }
  12595.             $html preg_replace("'([\s]*)<option'si""<option"$html);
  12596.             $html preg_replace("'</option>([\s]*)'si""</option>"$html);
  12597.             $offset 0;
  12598.             while (($offset strlen($html)) AND ($pos strpos($html'</option>'$offset)) !== false{
  12599.                 $html_a substr($html0$offset);
  12600.                 $html_b substr($html$offset($pos $offset 9));
  12601.                 while (preg_match("'<option([^\>]*)>(.*?)</option>'si"$html_b)) {
  12602.                     $html_b preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si""\\2\t\\4\r"$html_b);
  12603.                     $html_b preg_replace("'<option([^\>]*)>(.*?)</option>'si""\\2\r"$html_b);
  12604.                 }
  12605.                 $html $html_a.$html_b.substr($html$pos 9);
  12606.                 $offset strlen($html_a.$html_b);
  12607.             }
  12608.             $html preg_replace("'<select([^\>]*)>'si""<select\\1 opt=\""$html);
  12609.             $html preg_replace("'([\s]+)</select>'si""\" />"$html);
  12610.             $html str_replace("\n"' '$html);
  12611.             // restore textarea newlines
  12612.             $html str_replace('<TBR>'"\n"$html);
  12613.             // remove extra spaces from code
  12614.             $html preg_replace('/[\s]+<\/(table|tr|td|th|ul|ol|li)>/''</\\1>'$html);
  12615.             $html preg_replace('/[\s]+<(tr|td|th|ul|ol|li|br)/''<\\1'$html);
  12616.             $html preg_replace('/<\/(table|tr|td|th|blockquote|dd|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|ul|p)>[\s]+</''</\\1><'$html);
  12617.             $html preg_replace('/<\/(td|th)>/''<marker style="font-size:0"/></\\1>'$html);
  12618.             $html preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/''</table>'$html);
  12619.             $html preg_replace('/<img/'' <img'$html);
  12620.             $html preg_replace('/<img([^\>]*)>/xi''<img\\1><span></span>'$html);
  12621.             $html preg_replace('/<xre/''<pre'$html)// restore pre tag
  12622.             $html preg_replace('/<textarea([^\>]*)>/xi''<textarea\\1 value="'$html);
  12623.             $html preg_replace('/<\/textarea>/''" />'$html);
  12624.             // trim string
  12625.             $html preg_replace('/^[\s]+/'''$html);
  12626.             $html preg_replace('/[\s]+$/'''$html);
  12627.             // pattern for generic tag
  12628.             $tagpattern '/(<[^>]+>)/';
  12629.             // explodes the string
  12630.             $a preg_split($tagpattern$html-1PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_NO_EMPTY);
  12631.             // count elements
  12632.             $maxel count($a);
  12633.             $elkey 0;
  12634.             $key 0;
  12635.             // create an array of elements
  12636.             $dom array();
  12637.             $dom[$keyarray();
  12638.             // set first void element
  12639.             $dom[$key]['tag'false;
  12640.             $dom[$key]['value''';
  12641.             $dom[$key]['parent'0;
  12642.             $dom[$key]['fontname'$this->FontFamily;
  12643.             $dom[$key]['fontstyle'$this->FontStyle;
  12644.             $dom[$key]['fontsize'$this->FontSizePt;
  12645.             $dom[$key]['bgcolor'false;
  12646.             $dom[$key]['fgcolor'$this->fgcolor;
  12647.             $dom[$key]['align''';
  12648.             $dom[$key]['listtype''';
  12649.             $dom[$key]['text-indent'0;
  12650.             $thead false// true when we are inside the THEAD tag
  12651.             ++$key;
  12652.             $level array();
  12653.             array_push($level0)// root
  12654.             while ($elkey $maxel{
  12655.                 $dom[$keyarray();
  12656.                 $element $a[$elkey];
  12657.                 $dom[$key]['elkey'$elkey;
  12658.                 if (preg_match($tagpattern$element)) {
  12659.                     // html tag
  12660.                     $element substr($element1-1);
  12661.                     // get tag name
  12662.                     preg_match('/[\/]?([a-zA-Z0-9]*)/'$element$tag);
  12663.                     $tagname strtolower($tag[1]);
  12664.                     // check if we are inside a table header
  12665.                     if ($tagname == 'thead'{
  12666.                         if ($element{0== '/'{
  12667.                             $thead false;
  12668.                         else {
  12669.                             $thead true;
  12670.                         }
  12671.                         ++$elkey;
  12672.                         continue;
  12673.                     }
  12674.                     $dom[$key]['tag'true;
  12675.                     $dom[$key]['value'$tagname;
  12676.                     if ($element{0== '/'{
  12677.                         // closing html tag
  12678.                         $dom[$key]['opening'false;
  12679.                         $dom[$key]['parent'end($level);
  12680.                         array_pop($level);
  12681.                         $dom[$key]['fontname'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  12682.                         $dom[$key]['fontstyle'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  12683.                         $dom[$key]['fontsize'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  12684.                         $dom[$key]['bgcolor'$dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  12685.                         $dom[$key]['fgcolor'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  12686.                         $dom[$key]['align'$dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  12687.                         if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  12688.                             $dom[$key]['listtype'$dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  12689.                         }
  12690.                         // set the number of columns in table tag
  12691.                         if (($dom[$key]['value'== 'tr'AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  12692.                             $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'$dom[($dom[$key]['parent'])]['cols'];
  12693.                         }
  12694.                         if (($dom[$key]['value'== 'td'OR ($dom[$key]['value'== 'th')) {
  12695.                             $dom[($dom[$key]['parent'])]['content''';
  12696.                             for ($i ($dom[$key]['parent'1)$i $key++$i{
  12697.                                 $dom[($dom[$key]['parent'])]['content'.= $a[$dom[$i]['elkey']];
  12698.                             }
  12699.                             $key $i;
  12700.                         }
  12701.                         // store header rows on a new table
  12702.                         if (($dom[$key]['value'== 'tr'AND ($dom[($dom[$key]['parent'])]['thead'=== true)) {
  12703.                             if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  12704.                                 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  12705.                             }
  12706.                             for ($i $dom[$key]['parent']$i <= $key++$i{
  12707.                                 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'.= $a[$dom[$i]['elkey']];
  12708.                             }
  12709.                         }
  12710.                         if (($dom[$key]['value'== 'table'AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  12711.                             $dom[($dom[$key]['parent'])]['thead'.= '</tablehead>';
  12712.                         }
  12713.                     else {
  12714.                         // opening html tag
  12715.                         $dom[$key]['opening'true;
  12716.                         $dom[$key]['parent'end($level);
  12717.                         if (substr($element-11!= '/'{
  12718.                             // not self-closing tag
  12719.                             array_push($level$key);
  12720.                             $dom[$key]['self'false;
  12721.                         else {
  12722.                             $dom[$key]['self'true;
  12723.                         }
  12724.                         // copy some values from parent
  12725.                         $parentkey 0;
  12726.                         if ($key 0{
  12727.                             $parentkey $dom[$key]['parent'];
  12728.                             $dom[$key]['fontname'$dom[$parentkey]['fontname'];
  12729.                             $dom[$key]['fontstyle'$dom[$parentkey]['fontstyle'];
  12730.                             $dom[$key]['fontsize'$dom[$parentkey]['fontsize'];
  12731.                             $dom[$key]['bgcolor'$dom[$parentkey]['bgcolor'];
  12732.                             $dom[$key]['fgcolor'$dom[$parentkey]['fgcolor'];
  12733.                             $dom[$key]['align'$dom[$parentkey]['align'];
  12734.                             $dom[$key]['listtype'$dom[$parentkey]['listtype'];
  12735.                             $dom[$key]['text-indent'$dom[$parentkey]['text-indent'];
  12736.                         }
  12737.                         // get attributes
  12738.                         preg_match_all('/([^=\s]*)=["]?([^"]*)["]?/'$element$attr_arrayPREG_PATTERN_ORDER);
  12739.                         $dom[$key]['attribute'array()// reset attribute array
  12740.                         while (list($id$nameeach($attr_array[1])) {
  12741.                             $dom[$key]['attribute'][strtolower($name)$attr_array[2][$id];
  12742.                         }
  12743.                         // split style attributes
  12744.                         if (isset($dom[$key]['attribute']['style'])) {
  12745.                             // get style attributes
  12746.                             preg_match_all('/([^;:\s]*):([^;]*)/'$dom[$key]['attribute']['style']$style_arrayPREG_PATTERN_ORDER);
  12747.                             $dom[$key]['style'array()// reset style attribute array
  12748.                             while (list($id$nameeach($style_array[1])) {
  12749.                                 $dom[$key]['style'][strtolower($name)trim($style_array[2][$id]);
  12750.                             }
  12751.                             // --- get some style attributes ---
  12752.                             if (isset($dom[$key]['style']['font-family'])) {
  12753.                                 // font family
  12754.                                 if (isset($dom[$key]['style']['font-family'])) {
  12755.                                     $fontslist preg_split('/[,]/'strtolower($dom[$key]['style']['font-family']));
  12756.                                     foreach ($fontslist as $font{
  12757.                                         $font trim(strtolower($font));
  12758.                                         if (in_array($font$this->fontlistOR in_array($font$this->fontkeys)) {
  12759.                                             $dom[$key]['fontname'$font;
  12760.                                             break;
  12761.                                         }
  12762.                                     }
  12763.                                 }
  12764.                             }
  12765.                             // list-style-type
  12766.                             if (isset($dom[$key]['style']['list-style-type'])) {
  12767.                                 $dom[$key]['listtype'trim(strtolower($dom[$key]['style']['list-style-type']));
  12768.                                 if ($dom[$key]['listtype'== 'inherit'{
  12769.                                     $dom[$key]['listtype'$dom[$parentkey]['listtype'];
  12770.                                 }
  12771.                             }
  12772.                             // text-indent
  12773.                             if (isset($dom[$key]['style']['text-indent'])) {
  12774.                                 $dom[$key]['text-indent'$this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  12775.                                 if ($dom[$key]['text-indent'== 'inherit'{
  12776.                                     $dom[$key]['text-indent'$dom[$parentkey]['text-indent'];
  12777.                                 }
  12778.                             }
  12779.                             // font size
  12780.                             if (isset($dom[$key]['style']['font-size'])) {
  12781.                                 $fsize trim($dom[$key]['style']['font-size']);
  12782.                                 switch ($fsize{
  12783.                                     // absolute-size
  12784.                                     case 'xx-small'{
  12785.                                         $dom[$key]['fontsize'$dom[0]['fontsize'4;
  12786.                                         break;
  12787.                                     }
  12788.                                     case 'x-small'{
  12789.                                         $dom[$key]['fontsize'$dom[0]['fontsize'3;
  12790.                                         break;
  12791.                                     }
  12792.                                     case 'small'{
  12793.                                         $dom[$key]['fontsize'$dom[0]['fontsize'2;
  12794.                                         break;
  12795.                                     }
  12796.                                     case 'medium'{
  12797.                                         $dom[$key]['fontsize'$dom[0]['fontsize'];
  12798.                                         break;
  12799.                                     }
  12800.                                     case 'large'{
  12801.                                         $dom[$key]['fontsize'$dom[0]['fontsize'2;
  12802.                                         break;
  12803.                                     }
  12804.                                     case 'x-large'{
  12805.                                         $dom[$key]['fontsize'$dom[0]['fontsize'4;
  12806.                                         break;
  12807.                                     }
  12808.                                     case 'xx-large'{
  12809.                                         $dom[$key]['fontsize'$dom[0]['fontsize'6;
  12810.                                         break;
  12811.                                     }
  12812.                                     // relative-size
  12813.                                     case 'smaller'{
  12814.                                         $dom[$key]['fontsize'$dom[$parentkey]['fontsize'3;
  12815.                                         break;
  12816.                                     }
  12817.                                     case 'larger'{
  12818.                                         $dom[$key]['fontsize'$dom[$parentkey]['fontsize'3;
  12819.                                         break;
  12820.                                     }
  12821.                                     default{
  12822.                                         $dom[$key]['fontsize'$this->getHTMLUnitToUnits($fsize$dom[$parentkey]['fontsize']'pt'true);
  12823.                                     }
  12824.                                 }
  12825.                             }
  12826.                             // font style
  12827.                             if (isset($dom[$key]['style']['font-weight']AND (strtolower($dom[$key]['style']['font-weight']{0}== 'b')) {
  12828.                                 $dom[$key]['fontstyle'.= 'B';
  12829.                             }
  12830.                             if (isset($dom[$key]['style']['font-style']AND (strtolower($dom[$key]['style']['font-style']{0}== 'i')) {
  12831.                                 $dom[$key]['fontstyle'.= '"I';
  12832.                             }
  12833.                             // font color
  12834.                             if (isset($dom[$key]['style']['color']AND (!$this->empty_string($dom[$key]['style']['color']))) {
  12835.                                 $dom[$key]['fgcolor'$this->convertHTMLColorToDec($dom[$key]['style']['color']);
  12836.                             }
  12837.                             // background color
  12838.                             if (isset($dom[$key]['style']['background-color']AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
  12839.                                 $dom[$key]['bgcolor'$this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  12840.                             }
  12841.                             // text-decoration
  12842.                             if (isset($dom[$key]['style']['text-decoration'])) {
  12843.                                 $decors explode(' 'strtolower($dom[$key]['style']['text-decoration']));
  12844.                                 foreach ($decors as $dec{
  12845.                                     $dec trim($dec);
  12846.                                     if (!$this->empty_string($dec)) {
  12847.                                         if ($dec{0== 'u'{
  12848.                                             $dom[$key]['fontstyle'.= 'U';
  12849.                                         elseif ($dec{0== 'l'{
  12850.                                             $dom[$key]['fontstyle'.= 'D';
  12851.                                         }
  12852.                                     }
  12853.                                 }
  12854.                             }
  12855.                             // check for width attribute
  12856.                             if (isset($dom[$key]['style']['width'])) {
  12857.                                 $dom[$key]['width'$dom[$key]['style']['width'];
  12858.                             }
  12859.                             // check for height attribute
  12860.                             if (isset($dom[$key]['style']['height'])) {
  12861.                                 $dom[$key]['height'$dom[$key]['style']['height'];
  12862.                             }
  12863.                             // check for text alignment
  12864.                             if (isset($dom[$key]['style']['text-align'])) {
  12865.                                 $dom[$key]['align'strtoupper($dom[$key]['style']['text-align']{0});
  12866.                             }
  12867.                             // check for border attribute
  12868.                             if (isset($dom[$key]['style']['border'])) {
  12869.                                 $dom[$key]['attribute']['border'$dom[$key]['style']['border'];
  12870.                             }
  12871.                         }
  12872.                         // check for font tag
  12873.                         if ($dom[$key]['value'== 'font'{
  12874.                             // font family
  12875.                             if (isset($dom[$key]['attribute']['face'])) {
  12876.                                 $fontslist preg_split('/[,]/'strtolower($dom[$key]['attribute']['face']));
  12877.                                 foreach ($fontslist as $font{
  12878.                                     $font trim(strtolower($font));
  12879.                                     if (in_array($font$this->fontlistOR in_array($font$this->fontkeys)) {
  12880.                                         $dom[$key]['fontname'$font;
  12881.                                         break;
  12882.                                     }
  12883.                                 }
  12884.                             }
  12885.                             // font size
  12886.                             if (isset($dom[$key]['attribute']['size'])) {
  12887.                                 if ($key 0{
  12888.                                     if ($dom[$key]['attribute']['size']{0== '+'{
  12889.                                         $dom[$key]['fontsize'$dom[($dom[$key]['parent'])]['fontsize'intval(substr($dom[$key]['attribute']['size']1));
  12890.                                     elseif ($dom[$key]['attribute']['size']{0== '-'{
  12891.                                         $dom[$key]['fontsize'$dom[($dom[$key]['parent'])]['fontsize'intval(substr($dom[$key]['attribute']['size']1));
  12892.                                     else {
  12893.                                         $dom[$key]['fontsize'intval($dom[$key]['attribute']['size']);
  12894.                                     }
  12895.                                 else {
  12896.                                     $dom[$key]['fontsize'intval($dom[$key]['attribute']['size']);
  12897.                                 }
  12898.                             }
  12899.                         }
  12900.                         // force natural alignment for lists
  12901.                         if ((($dom[$key]['value'== 'ul'OR ($dom[$key]['value'== 'ol'OR ($dom[$key]['value'== 'dl'))
  12902.                             AND (!isset($dom[$key]['align']OR $this->empty_string($dom[$key]['align']OR ($dom[$key]['align'!= 'J'))) {
  12903.                             if ($this->rtl{
  12904.                                 $dom[$key]['align''R';
  12905.                             else {
  12906.                                 $dom[$key]['align''L';
  12907.                             }
  12908.                         }
  12909.                         if (($dom[$key]['value'== 'small'OR ($dom[$key]['value'== 'sup'OR ($dom[$key]['value'== 'sub')) {
  12910.                             $dom[$key]['fontsize'$dom[$key]['fontsize'K_SMALL_RATIO;
  12911.                         }
  12912.                         if (($dom[$key]['value'== 'strong'OR ($dom[$key]['value'== 'b')) {
  12913.                             $dom[$key]['fontstyle'.= 'B';
  12914.                         }
  12915.                         if (($dom[$key]['value'== 'em'OR ($dom[$key]['value'== 'i')) {
  12916.                             $dom[$key]['fontstyle'.= 'I';
  12917.                         }
  12918.                         if ($dom[$key]['value'== 'u'{
  12919.                             $dom[$key]['fontstyle'.= 'U';
  12920.                         }
  12921.                         if ($dom[$key]['value'== 'del'{
  12922.                             $dom[$key]['fontstyle'.= 'D';
  12923.                         }
  12924.                         if (($dom[$key]['value'== 'pre'OR ($dom[$key]['value'== 'tt')) {
  12925.                             $dom[$key]['fontname'$this->default_monospaced_font;
  12926.                         }
  12927.                         if (($dom[$key]['value']{0== 'h'AND (intval($dom[$key]['value']{1}0AND (intval($dom[$key]['value']{1}7)) {
  12928.                             $headsize (intval($dom[$key]['value']{1})) 2;
  12929.                             $dom[$key]['fontsize'$dom[0]['fontsize'$headsize;
  12930.                             $dom[$key]['fontstyle'.= 'B';
  12931.                         }
  12932.                         if (($dom[$key]['value'== 'table')) {
  12933.                             $dom[$key]['rows'0// number of rows
  12934.                             $dom[$key]['trids'array()// IDs of TR elements
  12935.                             $dom[$key]['thead'''// table header rows
  12936.                         }
  12937.                         if (($dom[$key]['value'== 'tr')) {
  12938.                             $dom[$key]['cols'0;
  12939.                             // store the number of rows on table element
  12940.                             ++$dom[($dom[$key]['parent'])]['rows'];
  12941.                             // store the TR elements IDs on table element
  12942.                             array_push($dom[($dom[$key]['parent'])]['trids']$key);
  12943.                             if ($thead{
  12944.                                 $dom[$key]['thead'true;
  12945.                             else {
  12946.                                 $dom[$key]['thead'false;
  12947.                             }
  12948.                         }
  12949.                         if (($dom[$key]['value'== 'th'OR ($dom[$key]['value'== 'td')) {
  12950.                             if (isset($dom[$key]['attribute']['colspan'])) {
  12951.                                 $colspan intval($dom[$key]['attribute']['colspan']);
  12952.                             else {
  12953.                                 $colspan 1;
  12954.                             }
  12955.                             $dom[$key]['attribute']['colspan'$colspan;
  12956.                             $dom[($dom[$key]['parent'])]['cols'+= $colspan;
  12957.                         }
  12958.                         // set foreground color attribute
  12959.                         if (isset($dom[$key]['attribute']['color']AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
  12960.                             $dom[$key]['fgcolor'$this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  12961.                         }
  12962.                         // set background color attribute
  12963.                         if (isset($dom[$key]['attribute']['bgcolor']AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
  12964.                             $dom[$key]['bgcolor'$this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  12965.                         }
  12966.                         // check for width attribute
  12967.                         if (isset($dom[$key]['attribute']['width'])) {
  12968.                             $dom[$key]['width'$dom[$key]['attribute']['width'];
  12969.                         }
  12970.                         // check for height attribute
  12971.                         if (isset($dom[$key]['attribute']['height'])) {
  12972.                             $dom[$key]['height'$dom[$key]['attribute']['height'];
  12973.                         }
  12974.                         // check for text alignment
  12975.                         if (isset($dom[$key]['attribute']['align']AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'!== 'img')) {
  12976.                             $dom[$key]['align'strtoupper($dom[$key]['attribute']['align']{0});
  12977.                         }
  12978.                     // end opening tag
  12979.                 else {
  12980.                     // text
  12981.                     $dom[$key]['tag'false;
  12982.                     $dom[$key]['value'stripslashes($this->unhtmlentities($element));
  12983.                     $dom[$key]['parent'end($level);
  12984.                 }
  12985.                 ++$elkey;
  12986.                 ++$key;
  12987.             }
  12988.             return $dom;
  12989.         }
  12990.         
  12991.         /**
  12992.          * Allows to preserve some HTML formatting (limited support).<br />
  12993.          * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  12994.          * 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
  12995.          * @param string $html text to display
  12996.          * @param boolean $ln if true add a new line after text (default = true)
  12997.          * @param int $fill Indicates if the background must be painted (true) or transparent (false).
  12998.          * @param boolean $reseth if true reset the last cell height (default false).
  12999.          * @param boolean $cell if true add the default cMargin space to each Write (default false).
  13000.          * @param string $align Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  13001.          * @access public
  13002.          */
  13003.         public function writeHTML($html$ln=true$fill=false$reseth=false$cell=false$align=''{
  13004.             $gvars $this->getGraphicVars();
  13005.             // store current values
  13006.             $prevPage $this->page;
  13007.             $prevlMargin $this->lMargin;
  13008.             $prevrMargin $this->rMargin;
  13009.             $curfontname $this->FontFamily;
  13010.             $curfontstyle $this->FontStyle;
  13011.             $curfontsize $this->FontSizePt;    
  13012.             $this->newline true;
  13013.             $startlinepage $this->page;
  13014.             $minstartliney $this->y;
  13015.             $startlinex $this->x;
  13016.             $startliney $this->y;
  13017.             $yshift 0;
  13018.             $newline true;
  13019.             $loop 0;
  13020.             $curpos 0;
  13021.             $this_method_vars array();
  13022.             $undo false;
  13023.             $blocktags array('blockquote','br','dd','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','ul','tcpdf');
  13024.             $this->premode false;
  13025.             if (isset($this->PageAnnots[$this->page])) {
  13026.                 $pask count($this->PageAnnots[$this->page]);
  13027.             else {
  13028.                 $pask 0;
  13029.             }
  13030.             if (isset($this->footerlen[$this->page])) {
  13031.                 $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  13032.             else {
  13033.                 $this->footerpos[$this->page$this->pagelen[$this->page];
  13034.             }
  13035.             $startlinepos $this->footerpos[$this->page];
  13036.             $lalign $align;
  13037.             $plalign $align;
  13038.             if ($this->rtl{
  13039.                 $w $this->x $this->lMargin;
  13040.             else {
  13041.                 $w $this->w $this->rMargin $this->x;
  13042.             }
  13043.             $w -= ($this->cMargin);
  13044.             if ($cell{
  13045.                 if ($this->rtl{
  13046.                     $this->x -= $this->cMargin;
  13047.                 else {
  13048.                     $this->x += $this->cMargin;
  13049.                 }
  13050.             }
  13051.             if ($this->customlistindent >= 0{
  13052.                 $this->listindent $this->customlistindent;
  13053.             else {
  13054.                 $this->listindent $this->GetStringWidth('0000');
  13055.             }
  13056.             // save previous states
  13057.             $prev_listnum $this->listnum;
  13058.             $prev_listordered $this->listordered;
  13059.             $prev_listcount $this->listcount;
  13060.             $prev_lispacer $this->lispacer;
  13061.             $this->listnum 0;
  13062.             $this->listordered array();
  13063.             $this->listcount array();
  13064.             $this->lispacer '';
  13065.             if (($this->empty_string($this->lasth)) OR ($reseth)) {
  13066.                 //set row height
  13067.                 $this->lasth $this->FontSize $this->cell_height_ratio
  13068.             }
  13069.             $dom $this->getHtmlDomArray($html);
  13070.             $maxel count($dom);
  13071.             $key 0;
  13072.             while ($key $maxel{
  13073.                 if ($dom[$key]['tag'AND $dom[$key]['opening'AND isset($dom[$key]['attribute']['nobr']AND ($dom[$key]['attribute']['nobr'== 'true')) {
  13074.                     if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'== 'true')) {
  13075.                         $dom[$key]['attribute']['nobr'false;
  13076.                     else {
  13077.                         // store current object
  13078.                         $this->startTransaction();
  13079.                         // save this method vars
  13080.                         $this_method_vars['html'$html;
  13081.                         $this_method_vars['ln'$ln;
  13082.                         $this_method_vars['fill'$fill;
  13083.                         $this_method_vars['reseth'$reseth;
  13084.                         $this_method_vars['cell'$cell;
  13085.                         $this_method_vars['align'$align;
  13086.                         $this_method_vars['gvars'$gvars;
  13087.                         $this_method_vars['prevPage'$prevPage;
  13088.                         $this_method_vars['prevlMargin'$prevlMargin;
  13089.                         $this_method_vars['prevrMargin'$prevrMargin;
  13090.                         $this_method_vars['curfontname'$curfontname;
  13091.                         $this_method_vars['curfontstyle'$curfontstyle;
  13092.                         $this_method_vars['curfontsize'$curfontsize;
  13093.                         $this_method_vars['minstartliney'$minstartliney;
  13094.                         $this_method_vars['yshift'$yshift;
  13095.                         $this_method_vars['startlinepage'$startlinepage;
  13096.                         $this_method_vars['startlinepos'$startlinepos;
  13097.                         $this_method_vars['startlinex'$startlinex;
  13098.                         $this_method_vars['startliney'$startliney;
  13099.                         $this_method_vars['newline'$newline;
  13100.                         $this_method_vars['loop'$loop;
  13101.                         $this_method_vars['curpos'$curpos;
  13102.                         $this_method_vars['pask'$pask;
  13103.                         $this_method_vars['lalign'$lalign;
  13104.                         $this_method_vars['plalign'$plalign;
  13105.                         $this_method_vars['w'$w;
  13106.                         $this_method_vars['prev_listnum'$prev_listnum;
  13107.                         $this_method_vars['prev_listordered'$prev_listordered;
  13108.                         $this_method_vars['prev_listcount'$prev_listcount;
  13109.                         $this_method_vars['prev_lispacer'$prev_lispacer;
  13110.                         $this_method_vars['key'$key;
  13111.                         $this_method_vars['dom'$dom;
  13112.                     }
  13113.                 }
  13114.                 if ($dom[$key]['tag'OR ($key == 0)) {
  13115.                     if ((($dom[$key]['value'== 'table'OR ($dom[$key]['value'== 'tr')) AND (isset($dom[$key]['align']))) {
  13116.                         $dom[$key]['align'($this->rtl'R' 'L';
  13117.                     }
  13118.                     // vertically align image in line
  13119.                     if ((!$this->newline)
  13120.                         AND ($dom[$key]['value'== 'img')
  13121.                         AND (isset($dom[$key]['attribute']['height']))
  13122.                         AND ($dom[$key]['attribute']['height'0)) {
  13123.                         
  13124.                         // get image height
  13125.                         $imgh $this->getHTMLUnitToUnits($dom[$key]['attribute']['height']$this->lasth'px');
  13126.                         if (!$this->InFooter{
  13127.                             // check for page break
  13128.                             $this->checkPageBreak($imgh);
  13129.                         }
  13130.                         if ($this->page $startlinepage{
  13131.                             // fix line splitted over two pages
  13132.                             if (isset($this->footerlen[$startlinepage])) {
  13133.                                 $curpos $this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  13134.                             }
  13135.                             // line to be moved one page forward
  13136.                             $pagebuff $this->getPageBuffer($startlinepage);
  13137.                             $linebeg substr($pagebuff$startlinepos($curpos $startlinepos));
  13138.                             $tstart substr($pagebuff0$startlinepos);
  13139.                             $tend substr($this->getPageBuffer($startlinepage)$curpos);
  13140.                             // remove line from previous page
  13141.                             $this->setPageBuffer($startlinepage$tstart.''.$tend);
  13142.                             $pagebuff $this->getPageBuffer($this->page);
  13143.                             $tstart substr($pagebuff0$this->cntmrk[$this->page]);
  13144.                             $tend substr($pagebuff$this->cntmrk[$this->page]);
  13145.                             // add line start to current page
  13146.                             $yshift $minstartliney $this->y;
  13147.                             $try sprintf('1 0 0 1 0 %.3F cm'($yshift $this->k));
  13148.                             $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  13149.                             // shift the annotations and links
  13150.                             if (isset($this->PageAnnots[$this->page])) {
  13151.                                 $next_pask count($this->PageAnnots[$this->page]);
  13152.                             else {
  13153.                                 $next_pask 0;
  13154.                             }
  13155.                             if (isset($this->PageAnnots[$startlinepage])) {
  13156.                                 foreach ($this->PageAnnots[$startlinepageas $pak => $pac{
  13157.                                     if ($pak >= $pask{
  13158.                                         $this->PageAnnots[$this->page][$pac;
  13159.                                         unset($this->PageAnnots[$startlinepage][$pak]);
  13160.                                         $npak count($this->PageAnnots[$this->page]1;
  13161.                                         $this->PageAnnots[$this->page][$npak]['y'-= $yshift;                                        
  13162.                                     }
  13163.                                 }
  13164.                                 
  13165.                             }
  13166.                             $pask $next_pask;
  13167.                             $startlinepos $this->cntmrk[$this->page];
  13168.                             $startlinepage $this->page;
  13169.                             $startliney $this->y;
  13170.                         }
  13171.                         $this->y += (($curfontsize $this->k$imgh);
  13172.                         $minstartliney min($this->y$minstartliney);    
  13173.                     elseif (isset($dom[$key]['fontname']OR isset($dom[$key]['fontstyle']OR isset($dom[$key]['fontsize'])) {
  13174.                         // account for different font size
  13175.                         $pfontname $curfontname;
  13176.                         $pfontstyle $curfontstyle;
  13177.                         $pfontsize $curfontsize;
  13178.                         $fontname = isset($dom[$key]['fontname']$dom[$key]['fontname'$curfontname;
  13179.                         $fontstyle = isset($dom[$key]['fontstyle']$dom[$key]['fontstyle'$curfontstyle;
  13180.                         $fontsize = isset($dom[$key]['fontsize']$dom[$key]['fontsize'$curfontsize;
  13181.                         if (($fontname != $curfontnameOR ($fontstyle != $curfontstyleOR ($fontsize != $curfontsize)) {
  13182.                             $this->SetFont($fontname$fontstyle$fontsize);
  13183.                             $this->lasth $this->FontSize $this->cell_height_ratio;
  13184.                             if (is_numeric($fontsizeAND ($fontsize 0)
  13185.                                 AND is_numeric($curfontsizeAND ($curfontsize 0)
  13186.                                 AND ($fontsize != $curfontsizeAND (!$this->newline)
  13187.                                 AND ($key ($maxel 1))
  13188.                                 {
  13189.                                 if ((!$this->newlineAND ($this->page $startlinepage)) {
  13190.                                     // fix lines splitted over two pages
  13191.                                     if (isset($this->footerlen[$startlinepage])) {
  13192.                                         $curpos $this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  13193.                                     }
  13194.                                     // line to be moved one page forward
  13195.                                     $pagebuff $this->getPageBuffer($startlinepage);
  13196.                                     $linebeg substr($pagebuff$startlinepos($curpos $startlinepos));
  13197.                                     $tstart substr($pagebuff0$startlinepos);
  13198.                                     $tend substr($this->getPageBuffer($startlinepage)$curpos);
  13199.                                     // remove line start from previous page
  13200.                                     $this->setPageBuffer($startlinepage$tstart.''.$tend);
  13201.                                     $pagebuff $this->getPageBuffer($this->page);
  13202.                                     $tstart substr($pagebuff0$this->cntmrk[$this->page]);
  13203.                                     $tend substr($pagebuff$this->cntmrk[$this->page]);
  13204.                                     // add line start to current page
  13205.                                     $yshift $minstartliney $this->y;
  13206.                                     $try sprintf('1 0 0 1 0 %.3F cm'($yshift $this->k));
  13207.                                     $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  13208.                                     // shift the annotations and links
  13209.                                     if (isset($this->PageAnnots[$this->page])) {
  13210.                                         $next_pask count($this->PageAnnots[$this->page]);
  13211.                                     else {
  13212.                                         $next_pask 0;
  13213.                                     }
  13214.                                     if (isset($this->PageAnnots[$startlinepage])) {
  13215.                                         foreach ($this->PageAnnots[$startlinepageas $pak => $pac{
  13216.                                             if ($pak >= $pask{
  13217.                                                 $this->PageAnnots[$this->page][$pac;
  13218.                                                 unset($this->PageAnnots[$startlinepage][$pak]);
  13219.                                                 $npak count($this->PageAnnots[$this->page]1;
  13220.                                                 $this->PageAnnots[$this->page][$npak]['y'-= $yshift;
  13221.                                             }
  13222.                                         }
  13223.                                     }
  13224.                                     $pask $next_pask;
  13225.                                 }
  13226.                                 if (($dom[$key]['value'!= 'td'AND ($dom[$key]['value'!= 'th')) {
  13227.                                     $this->y += (($curfontsize $fontsize$this->k);
  13228.                                 }
  13229.                                 $minstartliney min($this->y$minstartliney);
  13230.                             }
  13231.                             $curfontname $fontname;
  13232.                             $curfontstyle $fontstyle;
  13233.                             $curfontsize $fontsize;
  13234.                         }
  13235.                     }
  13236.                     if (($plalign == 'J'AND (in_array($dom[$key]['value']$blocktags))) {
  13237.                         $plalign '';
  13238.                     }
  13239.                     // get current position on page buffer
  13240.                     $curpos $this->pagelen[$startlinepage];
  13241.                     if (isset($dom[$key]['bgcolor']AND ($dom[$key]['bgcolor'!== false)) {
  13242.                         $this->SetFillColorArray($dom[$key]['bgcolor']);
  13243.                         $wfill true;
  13244.                     else {
  13245.                         $wfill $fill false;
  13246.                     }
  13247.                     if (isset($dom[$key]['fgcolor']AND ($dom[$key]['fgcolor'!== false)) {
  13248.                         $this->SetTextColorArray($dom[$key]['fgcolor']);
  13249.                     }
  13250.                     if (isset($dom[$key]['align'])) {
  13251.                         $lalign $dom[$key]['align'];
  13252.                     }
  13253.                     if ($this->empty_string($lalign)) {
  13254.                         $lalign $align;
  13255.                     }
  13256.                 }
  13257.                 // align lines
  13258.                 if ($this->newline AND (strlen($dom[$key]['value']0AND ($dom[$key]['value'!= 'td'AND ($dom[$key]['value'!= 'th')) {
  13259.                     $newline true;
  13260.                     // we are at the beginning of a new line
  13261.                     if (isset($startlinex)) {
  13262.                         $yshift $minstartliney $startliney;
  13263.                         if (($yshift 0OR ($this->page $startlinepage)) {
  13264.                             $yshift 0;
  13265.                         }
  13266.                         if ((isset($plalignAND ((($plalign == 'C'OR ($plalign == 'J'OR (($plalign == 'R'AND (!$this->rtl)) OR (($plalign == 'L'AND ($this->rtl))))) OR ($yshift 0)) {
  13267.                             // the last line must be shifted to be aligned as requested
  13268.                             $linew abs($this->endlinex $startlinex);
  13269.                             $pstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  13270.                             if (isset($opentagposAND isset($this->footerlen[$startlinepage]AND (!$this->InFooter)) {
  13271.                                 $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  13272.                                 $midpos min($opentagpos$this->footerpos[$startlinepage]);
  13273.                             elseif (isset($opentagpos)) {
  13274.                                 $midpos $opentagpos;
  13275.                             elseif (isset($this->footerlen[$startlinepage]AND (!$this->InFooter)) {
  13276.                                 $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  13277.                                 $midpos $this->footerpos[$startlinepage];
  13278.                             else {
  13279.                                 $midpos 0;
  13280.                             }
  13281.                             if ($midpos 0{
  13282.                                 $pmid substr($this->getPageBuffer($startlinepage)$startlinepos($midpos $startlinepos));
  13283.                                 $pend substr($this->getPageBuffer($startlinepage)$midpos);
  13284.                             else {
  13285.                                 $pmid substr($this->getPageBuffer($startlinepage)$startlinepos);
  13286.                                 $pend '';
  13287.                             }
  13288.                             // calculate shifting amount
  13289.                             $tw $w;
  13290.                             if ($this->lMargin != $prevlMargin{
  13291.                                 $tw += ($prevlMargin $this->lMargin);
  13292.                             }
  13293.                             if ($this->rMargin != $prevrMargin{
  13294.                                 $tw += ($prevrMargin $this->rMargin);
  13295.                             }
  13296.                             $mdiff abs($tw $linew);
  13297.                             $t_x 0;
  13298.                             if ($plalign == 'C'{
  13299.                                 if ($this->rtl{
  13300.                                     $t_x = -($mdiff 2);
  13301.                                 else {
  13302.                                     $t_x ($mdiff 2);
  13303.                                 }
  13304.                             elseif (($plalign == 'R'AND (!$this->rtl)) {
  13305.                                 // right alignment on LTR document
  13306.                                 $t_x $mdiff;    
  13307.                             elseif (($plalign == 'L'AND ($this->rtl)) {
  13308.                                 // left alignment on RTL document
  13309.                                 $t_x = -$mdiff;
  13310.                             elseif (($plalign == 'J'AND ($plalign == $lalign)) {
  13311.                                 // Justification
  13312.                                 if ($this->rtl OR $this->tmprtl{
  13313.                                     $t_x $this->lMargin $this->endlinex;
  13314.                                 }
  13315.                                 $no 0;
  13316.                                 $ns 0;
  13317.                                 $pmidtemp $pmid;
  13318.                                 // escape special characters
  13319.                                 $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  13320.                                 $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  13321.                                 // search spaces
  13322.                                 if (preg_match_all('/\[\(([^\)]*)\)\]/x'$pmidtemp$lnstringPREG_PATTERN_ORDER)) {
  13323.                                     $maxkk count($lnstring[1]1;
  13324.                                     for ($kk=0$kk <= $maxkk++$kk{
  13325.                                         // restore special characters
  13326.                                         $lnstring[1][$kkstr_replace('#!#OP#!#''('$lnstring[1][$kk]);
  13327.                                         $lnstring[1][$kkstr_replace('#!#CP#!#'')'$lnstring[1][$kk]);
  13328.                                         if ($kk == $maxkk{
  13329.                                             if ($this->rtl OR $this->tmprtl{
  13330.                                                 $tvalue ltrim($lnstring[1][$kk]);
  13331.                                             else {
  13332.                                                 $tvalue rtrim($lnstring[1][$kk]);
  13333.                                             }
  13334.                                         else {
  13335.                                             $tvalue $lnstring[1][$kk];
  13336.                                         }
  13337.                                         // count spaces on line
  13338.                                         $no += substr_count($lnstring[1][$kk]chr(32));
  13339.                                         $ns += substr_count($tvaluechr(32));
  13340.                                     }
  13341.                                     if ($this->rtl OR $this->tmprtl{
  13342.                                         $t_x $this->lMargin $this->endlinex (($no $ns 1$this->GetStringWidth(chr(32)));
  13343.                                     }
  13344.                                     // calculate additional space to add to each space
  13345.                                     $spacelen $this->GetStringWidth(chr(32));
  13346.                                     $spacewidth (($tw $linew (($no $ns$spacelen)) ($ns?$ns:1)) $this->k;
  13347.                                     $spacewidthu = -1000 ($tw $linew ($no $spacelen)) ($ns?$ns:1$this->FontSize;
  13348.                                     $nsmax $ns;
  13349.                                     $ns 0;
  13350.                                     reset($lnstring);
  13351.                                     $offset 0;
  13352.                                     $strcount 0;
  13353.                                     $prev_epsposbeg 0;
  13354.                                     global $spacew;
  13355.                                     while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x'$pmid$strpiecePREG_OFFSET_CAPTURE$offset== 1{
  13356.                                         // check if we are inside a string section '[( ... )]'
  13357.                                         $stroffset strpos($pmid'[('$offset);
  13358.                                         if (($stroffset !== falseAND ($stroffset <= $strpiece[2][1])) {
  13359.                                             // set offset to the end of string section 
  13360.                                             $offset strpos($pmid')]'$stroffset);
  13361.                                             while (($offset !== falseAND ($pmid{($offset 1)== '\\')) {
  13362.                                                 $offset strpos($pmid')]'($offset 1));
  13363.                                             }
  13364.                                             if ($offset === false{
  13365.                                                 $this->Error('HTML Justification: malformed PDF code.');
  13366.                                             }
  13367.                                             continue;
  13368.                                         }
  13369.                                         if ($this->rtl OR $this->tmprtl{
  13370.                                             $spacew ($spacewidth ($nsmax $ns));
  13371.                                         else {
  13372.                                             $spacew ($spacewidth $ns);
  13373.                                         }
  13374.                                         $offset $strpiece[2][1strlen($strpiece[2][0]);
  13375.                                         $epsposbeg strpos($pmid'q'.$this->epsmarker$offset);
  13376.                                         $epsposend strpos($pmid$this->epsmarker.'Q'$offsetstrlen($this->epsmarker.'Q');
  13377.                                         if ((($epsposbeg 0AND ($epsposend 0AND ($offset $epsposbegAND ($offset $epsposend))
  13378.                                             OR (($epsposbeg === falseAND ($epsposend 0AND ($offset $epsposend))) {
  13379.                                             // shift EPS images
  13380.                                             $trx sprintf('1 0 0 1 %.3F 0 cm'$spacew);
  13381.                                             $epsposbeg strpos($pmid'q'.$this->epsmarker($prev_epsposbeg 6));
  13382.                                             $pmid_b substr($pmid0$epsposbeg);
  13383.                                             $pmid_m substr($pmid$epsposbeg($epsposend $epsposbeg));
  13384.                                             $pmid_e substr($pmid$epsposend);
  13385.                                             $pmid $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  13386.                                             $offset $epsposend;
  13387.                                             continue;
  13388.                                         }
  13389.                                         $prev_epsposbeg $epsposbeg;
  13390.                                         $currentxpos 0;
  13391.                                         // shift blocks of code
  13392.                                         switch ($strpiece[2][0]{
  13393.                                             case 'Td':
  13394.                                             case 'cm':
  13395.                                             case 'm':
  13396.                                             case 'l'{
  13397.                                                 // get current X position
  13398.                                                 preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  13399.                                                 $currentxpos $xmatches[1];
  13400.                                                 if (($strcount <= $maxkkAND ($strpiece[2][0== 'Td')) {
  13401.                                                     if ($strcount == $maxkk{
  13402.                                                         if ($this->rtl OR $this->tmprtl{
  13403.                                                             $tvalue $lnstring[1][$strcount];
  13404.                                                         else {
  13405.                                                             $tvalue rtrim($lnstring[1][$strcount]);
  13406.                                                         }
  13407.                                                     else {
  13408.                                                         $tvalue $lnstring[1][$strcount];
  13409.                                                     }
  13410.                                                     $ns += substr_count($tvaluechr(32));
  13411.                                                     ++$strcount;
  13412.                                                 }
  13413.                                                 if ($this->rtl OR $this->tmprtl{
  13414.                                                     $spacew ($spacewidth ($nsmax $ns));
  13415.                                                 }
  13416.                                                 // justify block
  13417.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  13418.                                                     create_function('$matches''global $spacew;
  13419.                                                     $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
  13420.                                                     return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];')$pmid1);
  13421.                                                 break;
  13422.                                             }
  13423.                                             case 're'{
  13424.                                                 // get current X position
  13425.                                                 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  13426.                                                 $currentxpos $xmatches[1];
  13427.                                                 // justify block
  13428.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  13429.                                                     create_function('$matches''global $spacew;
  13430.                                                     $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
  13431.                                                     return "".$newx." ".$matches[2]." ".$matches[3]." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];')$pmid1);
  13432.                                                 break;
  13433.                                             }
  13434.                                             case 'c'{
  13435.                                                 // get current X position
  13436.                                                 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);
  13437.                                                 $currentxpos $xmatches[1];
  13438.                                                 // justify block
  13439.                                                 $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',
  13440.                                                     create_function('$matches''global $spacew;
  13441.                                                     $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
  13442.                                                     $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
  13443.                                                     $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
  13444.                                                     return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];')$pmid1);
  13445.                                                 break;
  13446.                                             }
  13447.                                         }
  13448.                                         // shift the annotations and links
  13449.                                         if (isset($this->PageAnnots[$this->page])) {
  13450.                                             foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  13451.                                                 if (($pac['y'>= $minstartlineyAND (($pac['x'$this->k>= ($currentxpos $this->feps)) AND (($pac['x'$this->k<= ($currentxpos $this->feps))) {
  13452.                                                     $this->PageAnnots[$this->page][$pak]['x'+= ($spacew $this->k);
  13453.                                                     $this->PageAnnots[$this->page][$pak]['w'+= (($spacewidth $pac['numspaces']$this->k);
  13454.                                                     break;
  13455.                                                 }
  13456.                                             }
  13457.                                         }
  13458.                                     // end of while
  13459.                                     // remove markers
  13460.                                     $pmid str_replace('x*#!#*x'''$pmid);
  13461.                                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  13462.                                         // multibyte characters
  13463.                                         $spacew $spacewidthu;
  13464.                                         $pmidtemp $pmid;
  13465.                                         // escape special characters
  13466.                                         $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  13467.                                         $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  13468.                                         $pmid preg_replace_callback("/\[\(([^\)]*)\)\]/x",
  13469.                                                     create_function('$matches''global $spacew;
  13470.                                                     $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  13471.                                                     $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  13472.                                                     return "[(".str_replace(chr(0).chr(32), ") ".($spacew)." (", $matches[1]).")]";')$pmidtemp);
  13473.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\n".$pend);
  13474.                                         $endlinepos strlen($pstart."\n".$pmid."\n");
  13475.                                     else {
  13476.                                         // non-unicode (single-byte characters)
  13477.                                         $rs sprintf("%.3F Tw"$spacewidth);
  13478.                                         $pmid preg_replace("/\[\(/x"$rs.' [('$pmid);
  13479.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  13480.                                         $endlinepos strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  13481.                                     }
  13482.                                 }
  13483.                             // end of J
  13484.                             if (($t_x != 0OR ($yshift 0)) {
  13485.                                 // shift the line
  13486.                                 $trx sprintf('1 0 0 1 %.3F %.3F cm'($t_x $this->k)($yshift $this->k));
  13487.                                 $this->setPageBuffer($startlinepage$pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend);
  13488.                                 $endlinepos strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n");
  13489.                                 // shift the annotations and links
  13490.                                 if (isset($this->PageAnnots[$this->page])) {
  13491.                                     foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  13492.                                         if ($pak >= $pask{
  13493.                                             $this->PageAnnots[$this->page][$pak]['x'+= $t_x;
  13494.                                             $this->PageAnnots[$this->page][$pak]['y'-= $yshift;
  13495.                                         }
  13496.                                     }
  13497.                                 }
  13498.                                 $this->y -= $yshift;
  13499.                             }
  13500.                         }
  13501.                     }
  13502.                     $this->newline false;
  13503.                     $pbrk $this->checkPageBreak($this->lasth);
  13504.                     $this->SetFont($fontname$fontstyle$fontsize);
  13505.                     if ($wfill{
  13506.                         $this->SetFillColorArray($this->bgcolor);
  13507.                     }
  13508.                     $startlinex $this->x;
  13509.                     $startliney $this->y;
  13510.                     $minstartliney $this->y;
  13511.                     $startlinepage $this->page;
  13512.                     if (isset($endlineposAND (!$pbrk)) {
  13513.                         $startlinepos $endlinepos;
  13514.                         unset($endlinepos);
  13515.                     else {
  13516.                         if (isset($this->footerlen[$this->page])) {
  13517.                             $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  13518.                         else {
  13519.                             $this->footerpos[$this->page$this->pagelen[$this->page];
  13520.                         }
  13521.                         $startlinepos $this->footerpos[$this->page];
  13522.                     }
  13523.                     $plalign $lalign;
  13524.                     if (isset($this->PageAnnots[$this->page])) {
  13525.                         $pask count($this->PageAnnots[$this->page]);
  13526.                     else {
  13527.                         $pask 0;
  13528.                     }
  13529.                 }
  13530.                 if (isset($opentagpos)) {
  13531.                     unset($opentagpos);
  13532.                 }
  13533.                 if ($dom[$key]['tag']{
  13534.                     if ($dom[$key]['opening']{
  13535.                         // get text indentation (if any)
  13536.                         if (isset($dom[$key]['text-indent']AND in_array($dom[$key]['value']array('blockquote','dd','div','dt','h1','h2','h3','h4','h5','h6','li','ol','p','ul','table','tr','td'))) {
  13537.                             $this->textindent $dom[$key]['text-indent'];
  13538.                         }
  13539.                         if ($dom[$key]['value'== 'table'{
  13540.                             if ($this->rtl{
  13541.                                 $wtmp $this->x $this->lMargin;
  13542.                             else {
  13543.                                 $wtmp $this->w $this->rMargin $this->x;
  13544.                             }
  13545.                             $wtmp -= ($this->cMargin);
  13546.                             // calculate cell width
  13547.                             if (isset($dom[$key]['width'])) {
  13548.                                 $table_width $this->getHTMLUnitToUnits($dom[$key]['width']$wtmp'px');
  13549.                             else {
  13550.                                 $table_width $wtmp;
  13551.                             }
  13552.                         }
  13553.                         // table content is handled in a special way
  13554.                         if (($dom[$key]['value'== 'td'OR ($dom[$key]['value'== 'th')) {
  13555.                             $trid $dom[$key]['parent'];
  13556.                             $table_el $dom[$trid]['parent'];
  13557.                             if (!isset($dom[$table_el]['cols'])) {
  13558.                                 $dom[$table_el]['cols'$trid['cols'];
  13559.                             }
  13560.                             $oldmargin $this->cMargin;
  13561.                             if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  13562.                                 $currentcmargin $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding']1'px');
  13563.                             else {
  13564.                                 $currentcmargin 0;        
  13565.                             }
  13566.                             $this->cMargin $currentcmargin;
  13567.                             if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellspacing'])) {
  13568.                                 $cellspacing $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellspacing']1'px');
  13569.                             else {
  13570.                                 $cellspacing 0;
  13571.                             }
  13572.                             if ($this->rtl{
  13573.                                 $cellspacingx = -$cellspacing;
  13574.                             else {
  13575.                                 $cellspacingx $cellspacing;
  13576.                             }
  13577.                             $colspan $dom[$key]['attribute']['colspan'];
  13578.                             $wtmp ($colspan ($table_width $dom[$table_el]['cols']));
  13579.                             if (isset($dom[$key]['width'])) {
  13580.                                 $cellw $this->getHTMLUnitToUnits($dom[$key]['width']$table_width'px');
  13581.                             else {
  13582.                                 $cellw $wtmp;
  13583.                             }
  13584.                             if (isset($dom[$key]['height'])) {
  13585.                                 // minimum cell height
  13586.                                 $cellh $this->getHTMLUnitToUnits($dom[$key]['height']0'px');
  13587.                             else {
  13588.                                 $cellh 0;
  13589.                             }
  13590.                             $cellw -= $cellspacing;
  13591.                             if (isset($dom[$key]['content'])) {
  13592.                                 $cell_content $dom[$key]['content'];
  13593.                             else {
  13594.                                 $cell_content '&nbsp;';
  13595.                             }
  13596.                             $tagtype $dom[$key]['value'];
  13597.                             $parentid $key;
  13598.                             while (($key $maxelAND (!(($dom[$key]['tag']AND (!$dom[$key]['opening']AND ($dom[$key]['value'== $tagtypeAND ($dom[$key]['parent'== $parentid)))) {
  13599.                                 // move $key index forward
  13600.                                 ++$key;
  13601.                             }
  13602.                             if (!isset($dom[$trid]['startpage'])) {
  13603.                                 $dom[$trid]['startpage'$this->page;
  13604.                             else {
  13605.                                 $this->setPage($dom[$trid]['startpage']);
  13606.                             }
  13607.                             if (!isset($dom[$trid]['starty'])) {
  13608.                                 $dom[$trid]['starty'$this->y;
  13609.                             else {
  13610.                                 $this->y $dom[$trid]['starty'];
  13611.                             }
  13612.                             if (!isset($dom[$trid]['startx'])) {
  13613.                                 $dom[$trid]['startx'$this->x;
  13614.                             }
  13615.                             $this->x += ($cellspacingx 2);                        
  13616.                             if (isset($dom[$parentid]['attribute']['rowspan'])) {
  13617.                                 $rowspan intval($dom[$parentid]['attribute']['rowspan']);
  13618.                             else {
  13619.                                 $rowspan 1;
  13620.                             }
  13621.                             // skip row-spanned cells started on the previous rows
  13622.                             if (isset($dom[$table_el]['rowspans'])) {
  13623.                                 $rsk 0;
  13624.                                 $rskmax count($dom[$table_el]['rowspans']);
  13625.                                 while ($rsk $rskmax{
  13626.                                     $trwsp $dom[$table_el]['rowspans'][$rsk];
  13627.                                     $rsstartx $trwsp['startx'];
  13628.                                     $rsendx $trwsp['endx'];
  13629.                                     // account for margin changes
  13630.                                     if ($trwsp['startpage'$this->page{
  13631.                                         if (($this->rtlAND ($this->pagedim[$this->page]['orm'!= $this->pagedim[$trwsp['startpage']]['orm'])) {
  13632.                                             $dl ($this->pagedim[$this->page]['orm'$this->pagedim[$trwsp['startpage']]['orm']);
  13633.                                             $rsstartx -= $dl;
  13634.                                             $rsendx -= $dl;
  13635.                                         elseif ((!$this->rtlAND ($this->pagedim[$this->page]['olm'!= $this->pagedim[$trwsp['startpage']]['olm'])) {
  13636.                                             $dl ($this->pagedim[$this->page]['olm'$this->pagedim[$trwsp['startpage']]['olm']);
  13637.                                             $rsstartx += $dl;
  13638.                                             $rsendx += $dl;
  13639.                                         }
  13640.                                     }
  13641.                                     if  (($trwsp['rowspan'0)
  13642.                                         AND ($rsstartx ($this->x $cellspacing $currentcmargin $this->feps))
  13643.                                         AND ($rsstartx ($this->x $cellspacing $currentcmargin $this->feps))
  13644.                                         AND (($trwsp['starty'($this->y $this->feps)) OR ($trwsp['startpage'$this->page))) {
  13645.                                         // set the starting X position of the current cell
  13646.                                         $this->x $rsendx $cellspacingx;
  13647.                                         if (($trwsp['rowspan'== 1)
  13648.                                             AND (isset($dom[$trid]['endy']))
  13649.                                             AND (isset($dom[$trid]['endpage']))
  13650.                                             AND ($trwsp['endpage'== $dom[$trid]['endpage'])) {
  13651.                                             // set ending Y position for row
  13652.                                             $dom[$table_el]['rowspans'][$rsk]['endy'max($dom[$trid]['endy']$trwsp['endy']);
  13653.                                             $dom[$trid]['endy'$dom[$table_el]['rowspans'][$rsk]['endy'];
  13654.                                         }
  13655.                                         $rsk 0;
  13656.                                     else {
  13657.                                         ++$rsk;
  13658.                                     }
  13659.                                 }
  13660.                             }
  13661.                             // add rowspan information to table element
  13662.                             if ($rowspan 1{
  13663.                                 if (isset($this->footerlen[$this->page])) {
  13664.                                     $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  13665.                                 else {
  13666.                                     $this->footerpos[$this->page$this->pagelen[$this->page];
  13667.                                 }
  13668.                                 $trintmrkpos $this->footerpos[$this->page];
  13669.                                 $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));
  13670.                             }
  13671.                             $cellid array_push($dom[$trid]['cellpos']array('startx' => $this->x));
  13672.                             if ($rowspan 1{
  13673.                                 $dom[$trid]['cellpos'][($cellid 1)]['rowspanid'($trsid 1);
  13674.                             }
  13675.                             // push background colors
  13676.                             if (isset($dom[$parentid]['bgcolor']AND ($dom[$parentid]['bgcolor'!== false)) {
  13677.                                 $dom[$trid]['cellpos'][($cellid 1)]['bgcolor'$dom[$parentid]['bgcolor'];
  13678.                             }
  13679.                             $prevLastH $this->lasth;
  13680.                             // ****** write the cell content ******
  13681.                             $this->MultiCell($cellw$cellh$cell_contentfalse$lalignfalse2''''true0true);
  13682.                             $this->lasth $prevLastH;
  13683.                             $this->cMargin $oldmargin;
  13684.                             $dom[$trid]['cellpos'][($cellid 1)]['endx'$this->x;
  13685.                             // update the end of row position
  13686.                             if ($rowspan <= 1{
  13687.                                 if (isset($dom[$trid]['endy'])) {
  13688.                                     if ($this->page == $dom[$trid]['endpage']{
  13689.                                         $dom[$trid]['endy'max($this->y$dom[$trid]['endy']);
  13690.                                     elseif ($this->page $dom[$trid]['endpage']{
  13691.                                         $dom[$trid]['endy'$this->y;
  13692.                                     }
  13693.                                 else {
  13694.                                     $dom[$trid]['endy'$this->y;
  13695.                                 }
  13696.                                 if (isset($dom[$trid]['endpage'])) {
  13697.                                     $dom[$trid]['endpage'max($this->page$dom[$trid]['endpage']);
  13698.                                 else {
  13699.                                     $dom[$trid]['endpage'$this->page;
  13700.                                 }                                
  13701.                             else {
  13702.                                 // account for row-spanned cells
  13703.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endx'$this->x;
  13704.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endy'$this->y;
  13705.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endpage'$this->page;
  13706.                             }
  13707.                             if (isset($dom[$table_el]['rowspans'])) {
  13708.                                 // update endy and endpage on rowspanned cells
  13709.                                 foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  13710.                                     if ($trwsp['rowspan'0{
  13711.                                         if (isset($dom[$trid]['endpage'])) {
  13712.                                             if ($trwsp['endpage'== $dom[$trid]['endpage']{
  13713.                                                 $dom[$table_el]['rowspans'][$k]['endy'max($dom[$trid]['endy']$trwsp['endy']);
  13714.                                             elseif ($trwsp['endpage'$dom[$trid]['endpage']{
  13715.                                                 $dom[$table_el]['rowspans'][$k]['endy'$dom[$trid]['endy'];
  13716.                                                 $dom[$table_el]['rowspans'][$k]['endpage'$dom[$trid]['endpage'];
  13717.                                             else {
  13718.                                                 $dom[$trid]['endy'$this->pagedim[$dom[$trid]['endpage']]['hk'$this->pagedim[$dom[$trid]['endpage']]['bm'];
  13719.                                             }
  13720.                                         }
  13721.                                     }
  13722.                                 }
  13723.                             }
  13724.                             $this->x += ($cellspacingx 2);
  13725.                         else {
  13726.                             // opening tag (or self-closing tag)
  13727.                             if (!isset($opentagpos)) {
  13728.                                 if (!$this->InFooter{
  13729.                                     if (isset($this->footerlen[$this->page])) {
  13730.                                         $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  13731.                                     else {
  13732.                                         $this->footerpos[$this->page$this->pagelen[$this->page];
  13733.                                     }
  13734.                                     $opentagpos $this->footerpos[$this->page];
  13735.                                 }
  13736.                             }
  13737.                             $this->openHTMLTagHandler($dom$key$cell);
  13738.                         }
  13739.                     else {
  13740.                         // closing tag
  13741.                         $this->closeHTMLTagHandler($dom$key$cell);
  13742.                     }
  13743.                 elseif (strlen($dom[$key]['value']0{
  13744.                     // print list-item
  13745.                     if (!$this->empty_string($this->lispacer)) {
  13746.                         $this->SetFont($pfontname$pfontstyle$pfontsize);
  13747.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  13748.                         $minstartliney $this->y;
  13749.                         $this->putHtmlListBullet($this->listnum$this->lispacer$pfontsize);
  13750.                         $this->SetFont($curfontname$curfontstyle$curfontsize);
  13751.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  13752.                         if (is_numeric($pfontsizeAND ($pfontsize 0AND is_numeric($curfontsizeAND ($curfontsize 0AND ($pfontsize != $curfontsize)) {
  13753.                             $this->y += (($pfontsize $curfontsize$this->k);
  13754.                             $minstartliney min($this->y$minstartliney);
  13755.                         }
  13756.                     }
  13757.                     // text
  13758.                     $this->htmlvspace 0;
  13759.                     if ((!$this->premodeAND ($this->rtl OR $this->tmprtl)) {
  13760.                         // reverse spaces order
  13761.                         $len1 strlen($dom[$key]['value']);
  13762.                         $lsp $len1 strlen(ltrim($dom[$key]['value']));
  13763.                         $rsp $len1 strlen(rtrim($dom[$key]['value']));
  13764.                         $tmpstr '';
  13765.                         if ($rsp 0{
  13766.                             $tmpstr .= substr($dom[$key]['value']-$rsp);
  13767.                         }
  13768.                         $tmpstr .= trim($dom[$key]['value']);
  13769.                         if ($lsp 0{
  13770.                             $tmpstr .= substr($dom[$key]['value']0$lsp);
  13771.                         }
  13772.                         $dom[$key]['value'$tmpstr;
  13773.                     }
  13774.                     if ($newline{
  13775.                         if (!$this->premode{
  13776.                             if (($this->rtl OR $this->tmprtl)) {
  13777.                                 $dom[$key]['value'rtrim($dom[$key]['value']);
  13778.                             else {
  13779.                                 $dom[$key]['value'ltrim($dom[$key]['value']);
  13780.                             }
  13781.                         }
  13782.                         $newline false;
  13783.                         $firstblock true;
  13784.                     else {
  13785.                         $firstblock false;
  13786.                     }
  13787.                     $strrest '';
  13788.                     if (!empty($this->HREFAND (isset($this->HREF['url']))) {
  13789.                         // HTML <a> Link
  13790.                         $strrest $this->addHtmlLink($this->HREF['url']$dom[$key]['value']$wfilltrue$this->HREF['color']$this->HREF['style']);
  13791.                     else {
  13792.                         $ctmpmargin $this->cMargin;
  13793.                         $this->cMargin 0;
  13794.                         if ($this->rtl{
  13795.                             $this->x -= $this->textindent;
  13796.                         else {
  13797.                             $this->x += $this->textindent;
  13798.                         }
  13799.                         // ****** write only until the end of the line and get the rest ******
  13800.                         $strrest $this->Write($this->lasth$dom[$key]['value']''$wfill''false0true$firstblock);
  13801.                         $this->textindent 0;
  13802.                         $this->cMargin $ctmpmargin;
  13803.                     }
  13804.                     if (strlen($strrest0{
  13805.                         // store the remaining string on the previous $key position
  13806.                         $this->newline true;
  13807.                         if ($cell{
  13808.                             if ($this->rtl{
  13809.                                 $this->x -= $this->cMargin;
  13810.                             else {
  13811.                                 $this->x += $this->cMargin;
  13812.                             }
  13813.                         }
  13814.                         if ($strrest == $dom[$key]['value']{
  13815.                             // used to avoid infinite loop
  13816.                             ++$loop;
  13817.                         else {
  13818.                             $loop 0;
  13819.                         }
  13820.                         $dom[$key]['value'ltrim($strrest);
  13821.                         if ($loop 3{
  13822.                             --$key;
  13823.                         }
  13824.                     else {
  13825.                         $loop 0;
  13826.                     }
  13827.                 }
  13828.                 ++$key;
  13829.                 if (isset($dom[$key]['tag']AND $dom[$key]['tag'AND (!isset($dom[$key]['opening']OR !$dom[$key]['opening']AND isset($dom[($dom[$key]['parent'])]['attribute']['nobr']AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'== 'true')) {
  13830.                     if ((!$undoAND ($this->start_transaction_page == ($this->numpages 1))) {
  13831.                         // restore previous object
  13832.                         $this->rollbackTransaction(true);
  13833.                         // restore previous values
  13834.                         foreach ($this_method_vars as $vkey => $vval{
  13835.                             $$vkey $vval;
  13836.                         }
  13837.                         // add a page
  13838.                         $this->AddPage();
  13839.                         $undo true// avoid infinite loop
  13840.                     else {
  13841.                         $undo false;
  13842.                     }
  13843.                 }
  13844.             // end for each $key
  13845.             // align the last line
  13846.             if (isset($startlinex)) {
  13847.                 $yshift $minstartliney $startliney;
  13848.                 if (($yshift 0OR ($this->page $startlinepage)) {
  13849.                     $yshift 0;
  13850.                 }
  13851.                 if ((isset($plalignAND ((($plalign == 'C'OR ($plalign == 'J'OR (($plalign == 'R'AND (!$this->rtl)) OR (($plalign == 'L'AND ($this->rtl))))) OR ($yshift 0)) {
  13852.                     // the last line must be shifted to be aligned as requested
  13853.                     $linew abs($this->endlinex $startlinex);
  13854.                     $pstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  13855.                     if (isset($opentagposAND isset($this->footerlen[$startlinepage]AND (!$this->InFooter)) {
  13856.                         $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  13857.                         $midpos min($opentagpos$this->footerpos[$startlinepage]);
  13858.                     elseif (isset($opentagpos)) {
  13859.                         $midpos $opentagpos;
  13860.                     elseif (isset($this->footerlen[$startlinepage]AND (!$this->InFooter)) {
  13861.                         $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  13862.                         $midpos $this->footerpos[$startlinepage];
  13863.                     else {
  13864.                         $midpos 0;
  13865.                     }
  13866.                     if ($midpos 0{
  13867.                         $pmid substr($this->getPageBuffer($startlinepage)$startlinepos($midpos $startlinepos));
  13868.                         $pend substr($this->getPageBuffer($startlinepage)$midpos);
  13869.                     else {
  13870.                         $pmid substr($this->getPageBuffer($startlinepage)$startlinepos);
  13871.                         $pend '';
  13872.                     }    
  13873.                     // calculate shifting amount
  13874.                     $tw $w;
  13875.                     if ($this->lMargin != $prevlMargin{
  13876.                         $tw += ($prevlMargin $this->lMargin);
  13877.                     }
  13878.                     if ($this->rMargin != $prevrMargin{
  13879.                         $tw += ($prevrMargin $this->rMargin);
  13880.                     }
  13881.                     $mdiff abs($tw $linew);
  13882.                     if ($plalign == 'C'{
  13883.                         if ($this->rtl{
  13884.                             $t_x = -($mdiff 2);
  13885.                         else {
  13886.                             $t_x ($mdiff 2);
  13887.                         }
  13888.                     elseif (($plalign == 'R'AND (!$this->rtl)) {
  13889.                         // right alignment on LTR document
  13890.                         $t_x $mdiff;
  13891.                     elseif (($plalign == 'L'AND ($this->rtl)) {
  13892.                         // left alignment on RTL document
  13893.                         $t_x = -$mdiff;
  13894.                     else {
  13895.                         $t_x 0;
  13896.                     }
  13897.                     if (($t_x != 0OR ($yshift 0)) {
  13898.                         // shift the line
  13899.                         $trx sprintf('1 0 0 1 %.3F %.3F cm'($t_x $this->k)($yshift $this->k));
  13900.                         $this->setPageBuffer($startlinepage$pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend);
  13901.                         $endlinepos strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n");
  13902.                         // shift the annotations and links
  13903.                         if (isset($this->PageAnnots[$this->page])) {
  13904.                             foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  13905.                                 if ($pak >= $pask{
  13906.                                     $this->PageAnnots[$this->page][$pak]['x'+= $t_x;
  13907.                                     $this->PageAnnots[$this->page][$pak]['y'-= $yshift;
  13908.                                 }
  13909.                             }
  13910.                         }
  13911.                         $this->y -= $yshift;
  13912.                     }
  13913.                 }
  13914.             }
  13915.             if ($ln AND (!($cell AND ($dom[$key-1]['value'== 'table')))) {
  13916.                 $this->Ln($this->lasth);
  13917.             }
  13918.             // restore previous values
  13919.             $this->setGraphicVars($gvars);
  13920.             if ($this->page $prevPage{
  13921.                 $this->lMargin $this->pagedim[$this->page]['olm'];
  13922.                 $this->rMargin $this->pagedim[$this->page]['orm'];
  13923.             }
  13924.             // restore previous list state
  13925.             $this->listnum $prev_listnum;
  13926.             $this->listordered $prev_listordered;
  13927.             $this->listcount $prev_listcount;
  13928.             $this->lispacer $prev_lispacer;
  13929.             unset($dom);
  13930.         }
  13931.         
  13932.         /**
  13933.          * Process opening tags.
  13934.          * @param array $dom html dom array
  13935.          * @param int $key current element id
  13936.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  13937.          * @access protected
  13938.          */
  13939.         protected function openHTMLTagHandler(&$dom$key$cell=false{
  13940.             $tag $dom[$key];
  13941.             $parent $dom[($dom[$key]['parent'])];
  13942.             $firstorlast ($key == 1);
  13943.             // check for text direction attribute
  13944.             if (isset($tag['attribute']['dir'])) {
  13945.                 $this->tmprtl $tag['attribute']['dir'== 'rtl' 'R' 'L';
  13946.             else {
  13947.                 $this->tmprtl false;
  13948.             }
  13949.             //Opening tag
  13950.             switch($tag['value']{
  13951.                 case 'table'{
  13952.                     $cp 0;
  13953.                     $cs 0;
  13954.                     $dom[$key]['rowspans'array();
  13955.                     if (!$this->empty_string($dom[$key]['thead'])) {
  13956.                         // set table header
  13957.                         $this->thead $dom[$key]['thead'];
  13958.                         if (!isset($this->theadMarginsOR (empty($this->theadMargins))) {
  13959.                             $this->theadMargins array();
  13960.                             $this->theadMargins['cmargin'$this->cMargin;
  13961.                         }
  13962.                     }
  13963.                     if (isset($tag['attribute']['cellpadding'])) {
  13964.                         $cp $this->getHTMLUnitToUnits($tag['attribute']['cellpadding']1'px');
  13965.                         $this->oldcMargin $this->cMargin;
  13966.                         $this->cMargin $cp;
  13967.                     }
  13968.                     if (isset($tag['attribute']['cellspacing'])) {
  13969.                         $cs $this->getHTMLUnitToUnits($tag['attribute']['cellspacing']1'px');
  13970.                     }
  13971.                     $this->checkPageBreak(($cp($cs$this->lasth);
  13972.                     break;
  13973.                 }
  13974.                 case 'tr'{
  13975.                     // array of columns positions
  13976.                     $dom[$key]['cellpos'array();
  13977.                     break;
  13978.                 }
  13979.                 case 'hr'{
  13980.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  13981.                     $this->htmlvspace 0;
  13982.                     $wtmp $this->w $this->lMargin $this->rMargin;
  13983.                     if ((isset($tag['attribute']['width'])) AND ($tag['attribute']['width'!= '')) {
  13984.                         $hrWidth $this->getHTMLUnitToUnits($tag['attribute']['width']$wtmp'px');
  13985.                     else {
  13986.                         $hrWidth $wtmp;
  13987.                     }
  13988.                     $x $this->GetX();
  13989.                     $y $this->GetY();
  13990.                     $prevlinewidth $this->GetLineWidth();
  13991.                     $this->Line($x$y$x $hrWidth$y);
  13992.                     $this->SetLineWidth($prevlinewidth);
  13993.                     $this->addHTMLVertSpace(1$cell''!isset($dom[($key 1)])$tag['value']false);
  13994.                     break;
  13995.                 }
  13996.                 case 'a'{
  13997.                     if (array_key_exists('href'$tag['attribute'])) {
  13998.                         $this->HREF['url'$tag['attribute']['href'];
  13999.                     }
  14000.                     $this->HREF['color'$this->htmlLinkColorArray;
  14001.                     $this->HREF['style'$this->htmlLinkFontStyle;
  14002.                     if (array_key_exists('style'$tag['attribute'])) {
  14003.                         // get style attributes
  14004.                         preg_match_all('/([^;:\s]*):([^;]*)/'$tag['attribute']['style']$style_arrayPREG_PATTERN_ORDER);
  14005.                         $astyle array();
  14006.                         while (list($id$nameeach($style_array[1])) {
  14007.                             $name strtolower($name);
  14008.                             $astyle[$nametrim($style_array[2][$id]);
  14009.                         }
  14010.                         if (isset($astyle['color'])) {
  14011.                             $this->HREF['color'$this->convertHTMLColorToDec($astyle['color']);
  14012.                         }
  14013.                         if (isset($astyle['text-decoration'])) {
  14014.                             $this->HREF['style''';
  14015.                             $decors explode(' 'strtolower($astyle['text-decoration']));
  14016.                             foreach ($decors as $dec{
  14017.                                 $dec trim($dec);
  14018.                                 if (!$this->empty_string($dec)) {
  14019.                                     if ($dec{0== 'u'{
  14020.                                         $this->HREF['style'.= 'U';
  14021.                                     elseif ($dec{0== 'l'{
  14022.                                         $this->HREF['style'.= 'D';
  14023.                                     }
  14024.                                 }
  14025.                             }
  14026.                         }
  14027.                     }        
  14028.                     break;
  14029.                 }
  14030.                 case 'img'{
  14031.                     if (isset($tag['attribute']['src'])) {
  14032.                         // replace relative path with real server path
  14033.                         if (($tag['attribute']['src'][0== '/'AND ($_SERVER['DOCUMENT_ROOT'!= '/')) {
  14034.                             $tag['attribute']['src'$_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
  14035.                         }
  14036.                         $tag['attribute']['src'urldecode($tag['attribute']['src']);
  14037.                         $tag['attribute']['src'str_replace(K_PATH_URLK_PATH_MAIN$tag['attribute']['src']);
  14038.                         if (!isset($tag['attribute']['width'])) {
  14039.                             $tag['attribute']['width'0;
  14040.                         }
  14041.                         if (!isset($tag['attribute']['height'])) {
  14042.                             $tag['attribute']['height'0;
  14043.                         }
  14044.                         //if (!isset($tag['attribute']['align'])) {
  14045.                             // the only alignment supported is "bottom"
  14046.                             // further development is required for other modes.
  14047.                             $tag['attribute']['align''bottom';
  14048.                         //} 
  14049.                         switch($tag['attribute']['align']{
  14050.                             case 'top'{
  14051.                                 $align 'T';
  14052.                                 break;
  14053.                             }
  14054.                             case 'middle'{
  14055.                                 $align 'M';
  14056.                                 break;
  14057.                             }
  14058.                             case 'bottom'{
  14059.                                 $align 'B';
  14060.                                 break;
  14061.                             }
  14062.                             default{
  14063.                                 $align 'B';
  14064.                                 break;
  14065.                             }
  14066.                         }
  14067.                         $fileinfo pathinfo($tag['attribute']['src']);
  14068.                         if (isset($fileinfo['extension']AND (!$this->empty_string($fileinfo['extension']))) {
  14069.                             $type strtolower($fileinfo['extension']);
  14070.                         }
  14071.                         $prevy $this->y;
  14072.                         $xpos $this->GetX();
  14073.                         if (isset($dom[($key 1)]AND ($dom[($key 1)]['value'== ' ')) {
  14074.                             if ($this->rtl{
  14075.                                 $xpos += $this->GetStringWidth(' ');
  14076.                             else {
  14077.                                 $xpos -= $this->GetStringWidth(' ');
  14078.                             }
  14079.                         }
  14080.                         $imglink '';
  14081.                         if (isset($this->HREF['url']AND !$this->empty_string($this->HREF['url'])) {
  14082.                             $imglink $this->HREF['url'];
  14083.                             if ($imglink{0== '#'{
  14084.                                 // convert url to internal link
  14085.                                 $page intval(substr($imglink1));
  14086.                                 $imglink $this->AddLink();
  14087.                                 $this->SetLink($imglink0$page);
  14088.                             }
  14089.                         }
  14090.                         $border 0;
  14091.                         if (isset($tag['attribute']['border']AND !empty($tag['attribute']['border'])) {
  14092.                             // currently only support 1 (frame) or a combination of 'LTRB'
  14093.                             $border $tag['attribute']['border'];
  14094.                         }
  14095.                         $iw '';
  14096.                         if (isset($tag['attribute']['width'])) {
  14097.                             $iw $this->getHTMLUnitToUnits($tag['attribute']['width']1'px'false);
  14098.                         }
  14099.                         $ih '';
  14100.                         if (isset($tag['attribute']['height'])) {
  14101.                             $ih $this->getHTMLUnitToUnits($tag['attribute']['height']1'px'false);
  14102.                         }
  14103.                         if (($type == 'eps'OR ($type == 'ai')) {
  14104.                             $this->ImageEps($tag['attribute']['src']$xpos$this->GetY()$iw$ih$imglinktrue$align''$border);
  14105.                         else {
  14106.                             $this->Image($tag['attribute']['src']$xpos$this->GetY()$iw$ih''$imglink$alignfalse300''falsefalse$border);
  14107.                         }
  14108.                         switch($align{
  14109.                             case 'T'{
  14110.                                 $this->y $prevy;
  14111.                                 break;
  14112.                             }
  14113.                             case 'M'{
  14114.                                 $this->y (($this->img_rb_y $prevy ($tag['fontsize'$this->k)) 2;
  14115.                                 break;
  14116.                             }
  14117.                             case 'B'{
  14118.                                 $this->y $this->img_rb_y ($tag['fontsize'$this->k);
  14119.                                 break;
  14120.                             }
  14121.                         }
  14122.                     }
  14123.                     break;
  14124.                 }
  14125.                 case 'dl'{
  14126.                     ++$this->listnum;
  14127.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  14128.                     break;
  14129.                 }
  14130.                 case 'dt'{
  14131.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  14132.                     break;
  14133.                 }
  14134.                 case 'dd'{
  14135.                     if ($this->rtl{
  14136.                         $this->rMargin += $this->listindent;
  14137.                     else {
  14138.                         $this->lMargin += $this->listindent;
  14139.                     }
  14140.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  14141.                     break;
  14142.                 }
  14143.                 case 'ul':
  14144.                 case 'ol'{
  14145.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  14146.                     $this->htmlvspace 0;
  14147.                     ++$this->listnum;
  14148.                     if ($tag['value'== 'ol'{
  14149.                         $this->listordered[$this->listnumtrue;
  14150.                     else {
  14151.                         $this->listordered[$this->listnumfalse;
  14152.                     }
  14153.                     if (isset($tag['attribute']['start'])) {
  14154.                         $this->listcount[$this->listnumintval($tag['attribute']['start']1;
  14155.                     else {
  14156.                         $this->listcount[$this->listnum0;
  14157.                     }
  14158.                     if ($this->rtl{
  14159.                         $this->rMargin += $this->listindent;
  14160.                     else {
  14161.                         $this->lMargin += $this->listindent;
  14162.                     }
  14163.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  14164.                     $this->htmlvspace 0;
  14165.                     break;
  14166.                 }
  14167.                 case 'li'{
  14168.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  14169.                     if ($this->listordered[$this->listnum]{
  14170.                         // ordered item
  14171.                         if (isset($parent['attribute']['type']AND !$this->empty_string($parent['attribute']['type'])) {
  14172.                             $this->lispacer $parent['attribute']['type'];
  14173.                         elseif (isset($parent['listtype']AND !$this->empty_string($parent['listtype'])) {
  14174.                             $this->lispacer $parent['listtype'];
  14175.                         elseif (isset($this->lisymbolAND !$this->empty_string($this->lisymbol)) {
  14176.                             $this->lispacer $this->lisymbol;
  14177.                         else {
  14178.                             $this->lispacer '#';
  14179.                         }
  14180.                         ++$this->listcount[$this->listnum];
  14181.                         if (isset($tag['attribute']['value'])) {
  14182.                             $this->listcount[$this->listnumintval($tag['attribute']['value']);
  14183.                         }
  14184.                     else {
  14185.                         // unordered item
  14186.                         if (isset($parent['attribute']['type']AND !$this->empty_string($parent['attribute']['type'])) {
  14187.                             $this->lispacer $parent['attribute']['type'];
  14188.                         elseif (isset($parent['listtype']AND !$this->empty_string($parent['listtype'])) {
  14189.                             $this->lispacer $parent['listtype'];
  14190.                         elseif (isset($this->lisymbolAND !$this->empty_string($this->lisymbol)) {
  14191.                             $this->lispacer $this->lisymbol;
  14192.                         else {
  14193.                             $this->lispacer '!';
  14194.                         }
  14195.                     }
  14196.                     break;
  14197.                 }
  14198.                 case 'blockquote'{
  14199.                     if ($this->rtl{
  14200.                         $this->rMargin += $this->listindent;
  14201.                     else {
  14202.                         $this->lMargin += $this->listindent;
  14203.                     }
  14204.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']false);
  14205.                     break;
  14206.                 }
  14207.                 case 'br'{
  14208.                     $this->Ln(''$cell);
  14209.                     break;
  14210.                 }
  14211.                 case 'div'{
  14212.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  14213.                     break;
  14214.                 }
  14215.                 case 'p'{
  14216.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']false);
  14217.                     break;
  14218.                 }
  14219.                 case 'pre'{
  14220.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  14221.                     $this->premode true;
  14222.                     break;
  14223.                 }
  14224.                 case 'sup'{
  14225.                     $this->SetXY($this->GetX()$this->GetY(((0.7 $this->FontSizePt$this->k));
  14226.                     break;
  14227.                 }
  14228.                 case 'sub'{
  14229.                     $this->SetXY($this->GetX()$this->GetY(((0.3 $this->FontSizePt$this->k));
  14230.                     break;
  14231.                 }
  14232.                 case 'h1'
  14233.                 case 'h2'
  14234.                 case 'h3'
  14235.                 case 'h4'
  14236.                 case 'h5'
  14237.                 case 'h6'{
  14238.                     $this->addHTMLVertSpace(1$cell($tag['fontsize'1.5$this->k$firstorlast$tag['value']false);
  14239.                     break;
  14240.                 }
  14241.                 // Form fields (since 4.8.000 - 2009-09-07)
  14242.                 case 'form'{
  14243.                     if (isset($tag['attribute']['action'])) {
  14244.                         $this->form_action $tag['attribute']['action'];
  14245.                     else {
  14246.                         $this->form_action K_PATH_URL.$_SERVER['SCRIPT_NAME'];
  14247.                     }
  14248.                     if (isset($tag['attribute']['enctype'])) {
  14249.                         $this->form_enctype $tag['attribute']['enctype'];
  14250.                     else {
  14251.                         $this->form_enctype 'application/x-www-form-urlencoded';
  14252.                     }
  14253.                     if (isset($tag['attribute']['method'])) {
  14254.                         $this->form_mode $tag['attribute']['method'];
  14255.                     else {
  14256.                         $this->form_mode 'post';
  14257.                     }
  14258.                     break;
  14259.                 }
  14260.                 case 'input'{
  14261.                     if (isset($tag['attribute']['name']AND !$this->empty_string($tag['attribute']['name'])) {
  14262.                         $name $tag['attribute']['name'];
  14263.                     else {
  14264.                         break;
  14265.                     }
  14266.                     $prop array();
  14267.                     $opt array();
  14268.                     if (isset($tag['attribute']['value']AND !$this->empty_string($tag['attribute']['value'])) {
  14269.                         $value $tag['attribute']['value'];
  14270.                     }
  14271.                     if (isset($tag['attribute']['maxlength']AND !$this->empty_string($tag['attribute']['maxlength'])) {
  14272.                         $opt['maxlen'intval($tag['attribute']['value']);
  14273.                     }
  14274.                     $h $this->FontSize $this->cell_height_ratio;
  14275.                     if (isset($tag['attribute']['size']AND !$this->empty_string($tag['attribute']['size'])) {
  14276.                         $w intval($tag['attribute']['size']$this->GetStringWidth(chr(32)) 2;
  14277.                     else {
  14278.                         $w $h;
  14279.                     }
  14280.                     if (isset($tag['attribute']['checked']AND (($tag['attribute']['checked'== 'checked'OR ($tag['attribute']['checked'== 'true'))) {
  14281.                         $checked true;
  14282.                     else {
  14283.                         $checked false;
  14284.                     }
  14285.                     switch ($tag['attribute']['type']{
  14286.                         case 'text'{
  14287.                             if (isset($value)) {
  14288.                                 $opt['v'$value;
  14289.                             }
  14290.                             $this->TextField($name$w$h$prop$opt''''false);
  14291.                             break;
  14292.                         }
  14293.                         case 'password'{
  14294.                             if (isset($value)) {
  14295.                                 $opt['v'$value;
  14296.                             }
  14297.                             $prop['password''true';
  14298.                             $this->TextField($name$w$h$prop$opt''''false);
  14299.                             break;
  14300.                         }
  14301.                         case 'checkbox'{
  14302.                             $this->CheckBox($name$w$checked$prop$opt$value''''false);
  14303.                             break;
  14304.                         }
  14305.                         case 'radio'{
  14306.                             $this->RadioButton($name$w$prop$opt$value$checked''''false);
  14307.                             break;
  14308.                         }
  14309.                         case 'submit'{
  14310.                             $w $this->GetStringWidth($value1.5;
  14311.                             $h *= 1.6;
  14312.                             $prop array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196)'strokeColor'=>array(255255255));
  14313.                             $action array();
  14314.                             $action['S''SubmitForm';
  14315.                             $action['F'$this->form_action;
  14316.                             if ($this->form_enctype != 'FDF'{
  14317.                                 $action['Flags'array('ExportFormat');
  14318.                             }
  14319.                             if ($this->form_mode == 'get'{
  14320.                                 $action['Flags'array('GetMethod');
  14321.                             }
  14322.                             $this->Button($name$w$h$value$action$prop$opt''''false);
  14323.                             break;
  14324.                         }
  14325.                         case 'reset'{
  14326.                             $w $this->GetStringWidth($value1.5;
  14327.                             $h *= 1.6;
  14328.                             $prop array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196)'strokeColor'=>array(255255255));
  14329.                             $this->Button($name$w$h$valuearray('S'=>'ResetForm')$prop$opt''''false);
  14330.                             break;
  14331.                         }
  14332.                         case 'file'{
  14333.                             $prop['fileSelect''true';
  14334.                             $this->TextField($name$w$h$prop$opt''''false);
  14335.                             if (!isset($value)) {
  14336.                                 $value '*';
  14337.                             }
  14338.                             $w $this->GetStringWidth($value2;
  14339.                             $h *= 1.2;
  14340.                             $prop array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196)'strokeColor'=>array(255255255));
  14341.                             $jsaction 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  14342.                             $this->Button('FB_'.$name$w$h$value$jsaction$prop$opt''''false);
  14343.                             break;
  14344.                         }
  14345.                         case 'hidden'{
  14346.                             if (isset($value)) {
  14347.                                 $opt['v'$value;
  14348.                             }
  14349.                             $opt['f'array('invisible''hidden');
  14350.                             $this->TextField($name00$prop$opt''''false);
  14351.                             break;
  14352.                         }
  14353.                         case 'image'{
  14354.                             // THIS TYPE MUST BE FIXED
  14355.                             if (isset($tag['attribute']['src']AND !$this->empty_string($tag['attribute']['src'])) {
  14356.                                 $img $tag['attribute']['src'];
  14357.                             else {
  14358.                                 break;
  14359.                             }
  14360.                             $value 'img';
  14361.                             //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  14362.                             if (isset($tag['attribute']['onclick']AND !empty($tag['attribute']['onclick'])) {
  14363.                                 $jsaction $tag['attribute']['onclick'];
  14364.                             else {
  14365.                                 $jsaction '';
  14366.                             }
  14367.                             $this->Button($name$w$h$value$jsaction$prop$opt''''false);
  14368.                             break;
  14369.                         }
  14370.                         case 'button'{
  14371.                             $w $this->GetStringWidth($value1.5;
  14372.                             $h *= 1.6;
  14373.                             $prop array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196)'strokeColor'=>array(255255255));
  14374.                             if (isset($tag['attribute']['onclick']AND !empty($tag['attribute']['onclick'])) {
  14375.                                 $jsaction $tag['attribute']['onclick'];
  14376.                             else {
  14377.                                 $jsaction '';
  14378.                             }
  14379.                             $this->Button($name$w$h$value$jsaction$prop$opt''''false);
  14380.                             break;
  14381.                         }
  14382.                     }
  14383.                     break;
  14384.                 }
  14385.                 case 'textarea'{
  14386.                     $prop array();
  14387.                     $opt array();
  14388.                     if (isset($tag['attribute']['name']AND !$this->empty_string($tag['attribute']['name'])) {
  14389.                         $name $tag['attribute']['name'];
  14390.                     else {
  14391.                         break;
  14392.                     }
  14393.                     if (isset($tag['attribute']['value']AND !$this->empty_string($tag['attribute']['value'])) {
  14394.                         $opt['v'$tag['attribute']['value'];
  14395.                     }
  14396.                     if (isset($tag['attribute']['cols']AND !$this->empty_string($tag['attribute']['cols'])) {
  14397.                         $w intval($tag['attribute']['cols']$this->GetStringWidth(chr(32)) 2;
  14398.                     else {
  14399.                         $w 40;
  14400.                     }
  14401.                     if (isset($tag['attribute']['rows']AND !$this->empty_string($tag['attribute']['rows'])) {
  14402.                         $h intval($tag['attribute']['rows']$this->FontSize $this->cell_height_ratio;
  14403.                     else {
  14404.                         $h 10;
  14405.                     }
  14406.                     $prop['multiline''true';
  14407.                     $this->TextField($name$w$h$prop$opt''''false);
  14408.                     break;
  14409.                 }
  14410.                 case 'select'{
  14411.                     $h $this->FontSize $this->cell_height_ratio;
  14412.                     if (isset($tag['attribute']['size']AND !$this->empty_string($tag['attribute']['size'])) {
  14413.                         $h *= ($tag['attribute']['size'1);
  14414.                     }
  14415.                     $prop array();
  14416.                     $opt array();
  14417.                     if (isset($tag['attribute']['name']AND !$this->empty_string($tag['attribute']['name'])) {
  14418.                         $name $tag['attribute']['name'];
  14419.                     else {
  14420.                         break;
  14421.                     }
  14422.                     $w 0;
  14423.                     if (isset($tag['attribute']['opt']AND !$this->empty_string($tag['attribute']['opt'])) {
  14424.                         $options explode ("\r"$tag['attribute']['opt']);
  14425.                         $values array();
  14426.                         foreach ($options as $val{
  14427.                             if (strpos($val"\t"!== false{
  14428.                                 $opts explode("\t"$val);
  14429.                                 $values[$opts;
  14430.                                 $w max($w$this->GetStringWidth($opts[1]));
  14431.                             else {
  14432.                                 $values[$val;
  14433.                                 $w max($w$this->GetStringWidth($val));
  14434.                             }
  14435.                         }
  14436.                     else {
  14437.                         break;
  14438.                     }
  14439.                     $w *= 2;
  14440.                     if (isset($tag['attribute']['multiple']AND ($tag['attribute']['multiple']='multiple')) {
  14441.                         $prop['multipleSelection''true';
  14442.                         $this->ListBox($name$w$h$values$prop$opt''''false);
  14443.                     else {
  14444.                         $this->ComboBox($name$w$h$values$prop$opt''''false);
  14445.                     }
  14446.                     break;
  14447.                 }
  14448.                 case 'tcpdf'{
  14449.                     // NOT HTML: used to call TCPDF methods
  14450.                     if (isset($tag['attribute']['method'])) {
  14451.                         $tcpdf_method $tag['attribute']['method'];
  14452.                         if (method_exists($this$tcpdf_method)) {
  14453.                             if (isset($tag['attribute']['params']AND (!empty($tag['attribute']['params']))) {
  14454.                                 eval('$params = array('.$this->unhtmlentities($tag['attribute']['params']).');');
  14455.                                 call_user_func_array(array($this$tcpdf_method)$params);
  14456.                             else {
  14457.                                 $this->$tcpdf_method();
  14458.                             }
  14459.                             $this->newline true;
  14460.                         }
  14461.                     }
  14462.                 }
  14463.                 default{
  14464.                     break;
  14465.                 }
  14466.             }
  14467.         }
  14468.         
  14469.         /**
  14470.          * Process closing tags.
  14471.          * @param array $dom html dom array
  14472.          * @param int $key current element id
  14473.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  14474.          * @access protected
  14475.          */
  14476.         protected function closeHTMLTagHandler(&$dom$key$cell=false{
  14477.             $tag $dom[$key];
  14478.             $parent $dom[($dom[$key]['parent'])];
  14479.             $firstorlast ((!isset($dom[($key 1)])) OR ((!isset($dom[($key 2)])) AND ($dom[($key 1)]['value'== 'marker')));
  14480.             $in_table_head false;
  14481.             //Closing tag
  14482.             switch($tag['value']{
  14483.                 case 'tr'{
  14484.                     $table_el $dom[($dom[$key]['parent'])]['parent'];
  14485.                     if(!isset($parent['endy'])) {
  14486.                         $dom[($dom[$key]['parent'])]['endy'$this->y;
  14487.                         $parent['endy'$this->y;
  14488.                     }
  14489.                     if(!isset($parent['endpage'])) {
  14490.                         $dom[($dom[$key]['parent'])]['endpage'$this->page;
  14491.                         $parent['endpage'$this->page;
  14492.                     }
  14493.                     // update row-spanned cells
  14494.                     if (isset($dom[$table_el]['rowspans'])) {
  14495.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  14496.                             $dom[$table_el]['rowspans'][$k]['rowspan'-= 1;
  14497.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  14498.                                 if ($dom[$table_el]['rowspans'][$k]['endpage'== $parent['endpage']{
  14499.                                     $dom[($dom[$key]['parent'])]['endy'max($dom[$table_el]['rowspans'][$k]['endy']$parent['endy']);
  14500.                                 elseif ($dom[$table_el]['rowspans'][$k]['endpage'$parent['endpage']{
  14501.                                     $dom[($dom[$key]['parent'])]['endy'$dom[$table_el]['rowspans'][$k]['endy'];
  14502.                                     $dom[($dom[$key]['parent'])]['endpage'$dom[$table_el]['rowspans'][$k]['endpage'];
  14503.                                 }
  14504.                             }
  14505.                         }
  14506.                         // report new endy and endpage to the rowspanned cells
  14507.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  14508.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  14509.                                 $dom[$table_el]['rowspans'][$k]['endpage'max($dom[$table_el]['rowspans'][$k]['endpage']$dom[($dom[$key]['parent'])]['endpage']);
  14510.                                 $dom[($dom[$key]['parent'])]['endpage'$dom[$table_el]['rowspans'][$k]['endpage'];
  14511.                                 $dom[$table_el]['rowspans'][$k]['endy'max($dom[$table_el]['rowspans'][$k]['endy']$dom[($dom[$key]['parent'])]['endy']);
  14512.                                 $dom[($dom[$key]['parent'])]['endy'$dom[$table_el]['rowspans'][$k]['endy'];
  14513.                             }
  14514.                         }
  14515.                         // update remaining rowspanned cells
  14516.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  14517.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  14518.                                 $dom[$table_el]['rowspans'][$k]['endpage'$dom[($dom[$key]['parent'])]['endpage'];
  14519.                                 $dom[$table_el]['rowspans'][$k]['endy'$dom[($dom[$key]['parent'])]['endy'];
  14520.                             }
  14521.                         }
  14522.                     }
  14523.                     $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  14524.                     $this->y $dom[($dom[$key]['parent'])]['endy'];
  14525.                     if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  14526.                         $cellspacing $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing']1'px');
  14527.                         $this->y += $cellspacing;
  14528.                     }                
  14529.                     $this->Ln(0$cell);
  14530.                     $this->x $parent['startx'];
  14531.                     // account for booklet mode
  14532.                     if ($this->page $parent['startpage']{
  14533.                         if (($this->rtlAND ($this->pagedim[$this->page]['orm'!= $this->pagedim[$parent['startpage']]['orm'])) {
  14534.                             $this->x += ($this->pagedim[$this->page]['orm'$this->pagedim[$parent['startpage']]['orm']);
  14535.                         elseif ((!$this->rtlAND ($this->pagedim[$this->page]['olm'!= $this->pagedim[$parent['startpage']]['olm'])) {
  14536.                             $this->x += ($this->pagedim[$this->page]['olm'$this->pagedim[$parent['startpage']]['olm']);
  14537.                         }
  14538.                     }
  14539.                     break;
  14540.                 }
  14541.                 case 'tablehead':
  14542.                     // closing tag used for the thead part
  14543.                     $in_table_head true;
  14544.                 case 'table'{
  14545.                     // draw borders
  14546.                     $table_el $parent;
  14547.                     if ((isset($table_el['attribute']['border']AND ($table_el['attribute']['border'0)) 
  14548.                         OR (isset($table_el['style']['border']AND ($table_el['style']['border'0))) {
  14549.                             $border 1;
  14550.                     else {
  14551.                         $border 0;
  14552.                     }
  14553.                     // fix bottom line alignment of last line before page break
  14554.                     foreach ($dom[($dom[$key]['parent'])]['trids'as $j => $trkey{
  14555.                         // update row-spanned cells
  14556.                         if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  14557.                             foreach ($dom[($dom[$key]['parent'])]['rowspans'as $k => $trwsp{
  14558.                                 if ($trwsp['trid'== $trkey{
  14559.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'-= 1;
  14560.                                 }
  14561.                                 if (isset($prevtrkeyAND ($trwsp['trid'== $prevtrkeyAND ($trwsp['mrowspan'>= 0)) {
  14562.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'$trkey;
  14563.                                 }
  14564.                             }
  14565.                         }
  14566.                         if (isset($prevtrkeyAND ($dom[$trkey]['startpage'$dom[$prevtrkey]['endpage'])) {
  14567.                             $pgendy $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'$this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  14568.                             $dom[$prevtrkey]['endy'$pgendy;
  14569.                             // update row-spanned cells
  14570.                             if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  14571.                                 foreach ($dom[($dom[$key]['parent'])]['rowspans'as $k => $trwsp{
  14572.                                     if (($trwsp['trid'== $trkeyAND ($trwsp['mrowspan'== 1AND ($trwsp['endpage'== $dom[$prevtrkey]['endpage'])) {
  14573.                                         $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'$pgendy;
  14574.                                         $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'= -1;
  14575.                                     }
  14576.                                 }
  14577.                             }
  14578.                         }
  14579.                         $prevtrkey $trkey;
  14580.                         $table_el $dom[($dom[$key]['parent'])];
  14581.                     }
  14582.                     // for each row
  14583.                     foreach ($table_el['trids'as $j => $trkey{
  14584.                         $parent $dom[$trkey];
  14585.                         // for each cell on the row
  14586.                         foreach ($parent['cellpos'as $k => $cellpos{
  14587.                             if (isset($cellpos['rowspanid']AND ($cellpos['rowspanid'>= 0)) {
  14588.                                 $cellpos['startx'$table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  14589.                                 $cellpos['endx'$table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  14590.                                 $endy $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  14591.                                 $startpage $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  14592.                                 $endpage $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  14593.                             else {
  14594.                                 $endy $parent['endy'];
  14595.                                 $startpage $parent['startpage'];
  14596.                                 $endpage $parent['endpage'];
  14597.                             }
  14598.                             if ($endpage $startpage{
  14599.                                 // design borders around HTML cells.
  14600.                                 for ($page=$startpage$page <= $endpage++$page{
  14601.                                     $this->setPage($page);
  14602.                                     if ($page == $startpage{
  14603.                                         $this->y $parent['starty']// put cursor at the beginning of row on the first page
  14604.                                         $ch $this->getPageHeight($parent['starty'$this->getBreakMargin();
  14605.                                         $cborder $this->getBorderMode($border$position='start');
  14606.                                     elseif ($page == $endpage{
  14607.                                         $this->y $this->tMargin// put cursor at the beginning of last page
  14608.                                         $ch $endy $this->tMargin;
  14609.                                         $cborder $this->getBorderMode($border$position='end');
  14610.                                     else {
  14611.                                         $this->y $this->tMargin// put cursor at the beginning of the current page
  14612.                                         $ch $this->getPageHeight($this->tMargin $this->getBreakMargin();
  14613.                                         $cborder $this->getBorderMode($border$position='middle');
  14614.                                     }
  14615.                                     if (isset($cellpos['bgcolor']AND ($cellpos['bgcolor']!== false{
  14616.                                         $this->SetFillColorArray($cellpos['bgcolor']);
  14617.                                         $fill true;
  14618.                                     else {
  14619.                                         $fill false;
  14620.                                     }
  14621.                                     $cw abs($cellpos['endx'$cellpos['startx']);
  14622.                                     $this->x $cellpos['startx'];
  14623.                                     // account for margin changes
  14624.                                     if ($page $startpage{
  14625.                                         if (($this->rtlAND ($this->pagedim[$page]['orm'!= $this->pagedim[$startpage]['orm'])) {
  14626.                                             $this->x -= ($this->pagedim[$page]['orm'$this->pagedim[$startpage]['orm']);
  14627.                                         elseif ((!$this->rtlAND ($this->pagedim[$page]['lm'!= $this->pagedim[$startpage]['olm'])) {
  14628.                                             $this->x += ($this->pagedim[$page]['olm'$this->pagedim[$startpage]['olm']);
  14629.                                         }
  14630.                                     }
  14631.                                     // design a cell around the text
  14632.                                     $ccode $this->FillColor."\n".$this->getCellCode($cw$ch''$cborder1''$fill''0true);
  14633.                                     if ($cborder OR $fill{
  14634.                                         $pagebuff $this->getPageBuffer($this->page);
  14635.                                         $pstart substr($pagebuff0$this->intmrk[$this->page]);
  14636.                                         $pend substr($pagebuff$this->intmrk[$this->page]);
  14637.                                         $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  14638.                                         $this->intmrk[$this->page+= strlen($ccode."\n");
  14639.                                     }
  14640.                                 }
  14641.                             else {
  14642.                                 $this->setPage($startpage);
  14643.                                 if (isset($cellpos['bgcolor']AND ($cellpos['bgcolor']!== false{
  14644.                                     $this->SetFillColorArray($cellpos['bgcolor']);
  14645.                                     $fill true;
  14646.                                 else {
  14647.                                     $fill false;
  14648.                                 }
  14649.                                 $this->x $cellpos['startx'];
  14650.                                 $this->y $parent['starty'];
  14651.                                 $cw abs($cellpos['endx'$cellpos['startx']);
  14652.                                 $ch $endy $parent['starty'];
  14653.                                 // design a cell around the text
  14654.                                 $ccode $this->FillColor."\n".$this->getCellCode($cw$ch''$border1''$fill''0true);
  14655.                                 if ($border OR $fill{
  14656.                                     if (end($this->transfmrk[$this->page]!== false{
  14657.                                         $pagemarkkey key($this->transfmrk[$this->page]);
  14658.                                         $pagemark &$this->transfmrk[$this->page][$pagemarkkey];
  14659.                                     elseif ($this->InFooter{
  14660.                                         $pagemark &$this->footerpos[$this->page];
  14661.                                     else {
  14662.                                         $pagemark &$this->intmrk[$this->page];
  14663.                                     }
  14664.                                     $pagebuff $this->getPageBuffer($this->page);
  14665.                                     $pstart substr($pagebuff0$pagemark);
  14666.                                     $pend substr($pagebuff$pagemark);
  14667.                                     $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  14668.                                     $pagemark += strlen($ccode."\n");
  14669.                                 }                    
  14670.                             }
  14671.                         }                    
  14672.                         if (isset($table_el['attribute']['cellspacing'])) {
  14673.                             $cellspacing $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing']1'px');
  14674.                             $this->y += $cellspacing;
  14675.                         }                
  14676.                         $this->Ln(0$cell);
  14677.                         $this->x $parent['startx'];
  14678.                         if ($endpage $startpage{
  14679.                             if (($this->rtlAND ($this->pagedim[$endpage]['orm'!= $this->pagedim[$startpage]['orm'])) {
  14680.                                 $this->x += ($this->pagedim[$endpage]['orm'$this->pagedim[$startpage]['orm']);
  14681.                             elseif ((!$this->rtlAND ($this->pagedim[$endpage]['olm'!= $this->pagedim[$startpage]['olm'])) {
  14682.                                 $this->x += ($this->pagedim[$endpage]['olm'$this->pagedim[$startpage]['olm']);
  14683.                             }
  14684.                         }
  14685.                     }
  14686.                     if (!$in_table_head{
  14687.                         // we are not inside a thead section
  14688.                         if (isset($parent['cellpadding'])) {
  14689.                             $this->cMargin $this->oldcMargin;
  14690.                         }
  14691.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  14692.                         if (isset($this->theadMargins['top'])) {
  14693.                             // restore top margin
  14694.                             $this->tMargin $this->theadMargins['top'];
  14695.                             $this->pagedim[$this->page]['tm'$this->tMargin;
  14696.                         }
  14697.                         // reset table header
  14698.                         $this->thead '';
  14699.                         $this->theadMargins array();
  14700.                     }
  14701.                     break;
  14702.                 }
  14703.                 case 'a'{
  14704.                     $this->HREF '';
  14705.                     break;
  14706.                 }
  14707.                 case 'sup'{
  14708.                     $this->SetXY($this->GetX()$this->GetY(((0.7 $parent['fontsize']$this->k));
  14709.                     break;
  14710.                 }
  14711.                 case 'sub'{
  14712.                     $this->SetXY($this->GetX()$this->GetY(((0.3 $parent['fontsize'])/$this->k));
  14713.                     break;
  14714.                 }
  14715.                 case 'div'{
  14716.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']true);
  14717.                     break;
  14718.                 }
  14719.                 case 'blockquote'{
  14720.                     if ($this->rtl{
  14721.                         $this->rMargin -= $this->listindent;
  14722.                     else {
  14723.                         $this->lMargin -= $this->listindent;
  14724.                     }
  14725.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  14726.                     break;
  14727.                 }
  14728.                 case 'p'{
  14729.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  14730.                     break;
  14731.                 }
  14732.                 case 'pre'{
  14733.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']true);
  14734.                     $this->premode false;
  14735.                     break;
  14736.                 }
  14737.                 case 'dl'{
  14738.                     --$this->listnum;
  14739.                     if ($this->listnum <= 0{
  14740.                         $this->listnum 0;
  14741.                         $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  14742.                     }
  14743.                     break;
  14744.                 }
  14745.                 case 'dt'{
  14746.                     $this->lispacer '';
  14747.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  14748.                     break;
  14749.                 }
  14750.                 case 'dd'{
  14751.                     $this->lispacer '';
  14752.                     if ($this->rtl{
  14753.                         $this->rMargin -= $this->listindent;
  14754.                     else {
  14755.                         $this->lMargin -= $this->listindent;
  14756.                     }
  14757.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  14758.                     break;
  14759.                 }
  14760.                 case 'ul':
  14761.                 case 'ol'{
  14762.                     --$this->listnum;
  14763.                     $this->lispacer '';
  14764.                     if ($this->rtl{
  14765.                         $this->rMargin -= $this->listindent;
  14766.                     else {
  14767.                         $this->lMargin -= $this->listindent;
  14768.                     }
  14769.                     if ($this->listnum <= 0{
  14770.                         $this->listnum 0;
  14771.                         $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  14772.                     }
  14773.                     $this->lasth $this->FontSize $this->cell_height_ratio;
  14774.                     break;
  14775.                 }
  14776.                 case 'li'{
  14777.                     $this->lispacer '';
  14778.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  14779.                     break;
  14780.                 }
  14781.                 case 'h1'
  14782.                 case 'h2'
  14783.                 case 'h3'
  14784.                 case 'h4'
  14785.                 case 'h5'
  14786.                 case 'h6'{
  14787.                     $this->addHTMLVertSpace(1$cell($parent['fontsize'1.5$this->k$firstorlast$tag['value']true);
  14788.                     break;
  14789.                 }
  14790.                 // Form fields (since 4.8.000 - 2009-09-07)
  14791.                 case 'form'{
  14792.                     $this->form_action '';
  14793.                     $this->form_enctype 'application/x-www-form-urlencoded';
  14794.                     break;
  14795.                 }
  14796.                 default {
  14797.                     break;
  14798.                 }
  14799.             }
  14800.             $this->tmprtl false;
  14801.         }
  14802.         
  14803.         /**
  14804.          * Add vertical spaces if needed.
  14805.          * @param int $n number of spaces to add
  14806.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  14807.          * @param string $h The height of the break. By default, the value equals the height of the last printed cell.
  14808.          * @param boolean $firstorlast if true do not print additional empty lines.
  14809.          * @param string $tag HTML tag to which this space will be applied
  14810.          * @param boolean $closing true if this space will be applied to a closing tag, false otherwise
  14811.          * @access protected
  14812.          */
  14813.         protected function addHTMLVertSpace($n$cell=false$h=''$firstorlast=false$tag=''$closing=false{
  14814.             if ($firstorlast{
  14815.                 $this->Ln(0$cell);
  14816.                 $this->htmlvspace 0;
  14817.                 return;
  14818.             }
  14819.             if (isset($this->tagvspaces[$tag][intval($closing)]['n'])) {
  14820.                 $n $this->tagvspaces[$tag][intval($closing)]['n'];
  14821.             }
  14822.             if (isset($this->tagvspaces[$tag][intval($closing)]['h'])) {
  14823.                 $h $this->tagvspaces[$tag][intval($closing)]['h'];
  14824.             }
  14825.             if (is_string($h)) {
  14826.                 $vsize $n $this->lasth;
  14827.             else {
  14828.                 $vsize $n $h;
  14829.             }
  14830.             if ($vsize $this->htmlvspace{
  14831.                 $this->Ln(($vsize $this->htmlvspace)$cell);
  14832.                 $this->htmlvspace $vsize;
  14833.             }
  14834.         }
  14835.         
  14836.         /**
  14837.          * Set the default bullet to be used as LI bullet symbol
  14838.          * @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')
  14839.          * @access public
  14840.          * @since 4.0.028 (2008-09-26)
  14841.          */
  14842.         public function setLIsymbol($symbol='!'{
  14843.             $symbol strtolower($symbol);
  14844.             switch ($symbol{
  14845.                 case '!' :
  14846.                 case '#' :
  14847.                 case 'disc' :
  14848.                 case 'disc' :
  14849.                 case 'circle' :
  14850.                 case 'square' :
  14851.                 case '1':
  14852.                 case 'decimal':
  14853.                 case 'decimal-leading-zero':
  14854.                 case 'i':
  14855.                 case 'lower-roman':
  14856.                 case 'I':
  14857.                 case 'upper-roman':
  14858.                 case 'a':
  14859.                 case 'lower-alpha':
  14860.                 case 'lower-latin':
  14861.                 case 'A':
  14862.                 case 'upper-alpha':
  14863.                 case 'upper-latin':
  14864.                 case 'lower-greek'{
  14865.                     $this->lisymbol $symbol;
  14866.                     break;
  14867.                 }
  14868.                 default {
  14869.                     $this->lisymbol '';
  14870.                 }
  14871.             }
  14872.         }
  14873.         
  14874.         /**
  14875.         * Set the booklet mode for double-sided pages.
  14876.         * @param boolean $booklet true set the booklet mode on, fals eotherwise.
  14877.         * @param float $inner Inner page margin.
  14878.         * @param float $outer Outer page margin.
  14879.         * @access public
  14880.         * @since 4.2.000 (2008-10-29)
  14881.         */
  14882.         public function SetBooklet($booklet=true$inner=-1$outer=-1{
  14883.             $this->booklet $booklet;
  14884.             if ($inner >= 0{
  14885.                 $this->lMargin $inner;
  14886.             }
  14887.             if ($outer >= 0{
  14888.                 $this->rMargin $outer;
  14889.             }
  14890.         }
  14891.         
  14892.         /**
  14893.         * Swap the left and right margins.
  14894.         * @param boolean $reverse if true swap left and right margins.
  14895.         * @access protected
  14896.         * @since 4.2.000 (2008-10-29)
  14897.         */
  14898.         protected function swapMargins($reverse=true{
  14899.             if ($reverse{
  14900.                 // swap left and right margins
  14901.                 $mtemp $this->original_lMargin;
  14902.                 $this->original_lMargin $this->original_rMargin;
  14903.                 $this->original_rMargin $mtemp;
  14904.                 $deltam $this->original_lMargin $this->original_rMargin;
  14905.                 $this->lMargin += $deltam;
  14906.                 $this->rMargin -= $deltam;
  14907.             }
  14908.         }
  14909.  
  14910.         /**
  14911.         * Set the vertical spaces for HTML tags.
  14912.         * The array must have the following structure (example):
  14913.         * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  14914.         * The first array level contains the tag names,
  14915.         * the second level contains 0 for opening tags or 1 for closing tags,
  14916.         * the third level contains the vertical space unit (h) and the number spaces to add (n).
  14917.         * If the h parameter is not specified, default values are used.
  14918.         * @param array $tagvs array of tags and relative vertical spaces.
  14919.         * @access public
  14920.         * @since 4.2.001 (2008-10-30)
  14921.         */
  14922.         public function setHtmlVSpace($tagvs{
  14923.             $this->tagvspaces $tagvs;
  14924.         }
  14925.  
  14926.         /**
  14927.         * Set custom width for list indentation.
  14928.         * @param float $width width of the indentation. Use negative value to disable it.
  14929.         * @access public
  14930.         * @since 4.2.007 (2008-11-12)
  14931.         */
  14932.         public function setListIndentWidth($width{
  14933.             return $this->customlistindent floatval($width);
  14934.         }
  14935.  
  14936.         /**
  14937.         * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  14938.         * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  14939.         * @access public
  14940.         * @since 4.2.010 (2008-11-14)
  14941.         */
  14942.         public function setOpenCell($isopen{
  14943.             $this->opencell $isopen;
  14944.         }
  14945.  
  14946.         /**
  14947.         * Set the color and font style for HTML links.
  14948.         * @param array $color RGB array of colors
  14949.         * @param string $fontstyle additional font styles to add
  14950.         * @access public
  14951.         * @since 4.4.003 (2008-12-09)
  14952.         */
  14953.         public function setHtmlLinksStyle($color=array(0,0,255)$fontstyle='U'{
  14954.             $this->htmlLinkColorArray $color;
  14955.             $this->htmlLinkFontStyle $fontstyle;
  14956.         }
  14957.  
  14958.         /**
  14959.         * convert html string containing value and unit of measure to user's units or points.
  14960.         * @param string $htmlval string containing values and unit
  14961.         * @param string $refsize reference value in points
  14962.         * @param string $defaultunit default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  14963.         * @param boolean $point if true returns points, otherwise returns value in user's units
  14964.         * @return float value in user's unit or point if $points=true
  14965.         * @access public
  14966.         * @since 4.4.004 (2008-12-10)
  14967.         */
  14968.         public function getHTMLUnitToUnits($htmlval$refsize=1$defaultunit='px'$points=false{
  14969.             $supportedunits array('%''em''ex''px''in''cm''mm''pc''pt');
  14970.             $retval 0;
  14971.             $value 0;
  14972.             $unit 'px';
  14973.             $k $this->k;
  14974.             if ($points{
  14975.                 $k 1;
  14976.             }
  14977.             if (in_array($defaultunit$supportedunits)) {
  14978.                 $unit $defaultunit;
  14979.             }
  14980.             if (is_numeric($htmlval)) {
  14981.                 $value floatval($htmlval);
  14982.             elseif (preg_match('/([0-9\.]+)/'$htmlval$mnum)) {
  14983.                 $value floatval($mnum[1]);
  14984.                 if (preg_match('/([a-z%]+)/'$htmlval$munit)) {
  14985.                     if (in_array($munit[1]$supportedunits)) {
  14986.                         $unit $munit[1];
  14987.                     }
  14988.                 }
  14989.             }
  14990.             switch ($unit{
  14991.                 // percentage
  14992.                 case '%'{
  14993.                     $retval (($value $refsize100);
  14994.                     break;
  14995.                 }
  14996.                 // relative-size
  14997.                 case 'em'{
  14998.                     $retval ($value $refsize);
  14999.                     break;
  15000.                 }
  15001.                 case 'ex'{
  15002.                     $retval $value ($refsize 2);
  15003.                     break;
  15004.                 }
  15005.                 // absolute-size
  15006.                 case 'in'{
  15007.                     $retval ($value $this->dpi$k;
  15008.                     break;
  15009.                 }
  15010.                 case 'cm'{
  15011.                     $retval ($value 2.54 $this->dpi$k;
  15012.                     break;
  15013.                 }
  15014.                 case 'mm'{
  15015.                     $retval ($value 25.4 $this->dpi$k;
  15016.                     break;
  15017.                 }
  15018.                 case 'pc'{
  15019.                     // one pica is 12 points
  15020.                     $retval ($value 12$k;
  15021.                     break;
  15022.                 }
  15023.                 case 'pt'{
  15024.                     $retval $value $k;
  15025.                     break;
  15026.                 }
  15027.                 case 'px'{
  15028.                     $retval $this->pixelsToUnits($value);
  15029.                     break;
  15030.                 }
  15031.             }
  15032.             return $retval;
  15033.         }
  15034.  
  15035.         /**
  15036.         * Returns the Roman representation of an integer number
  15037.         * @param int number to convert
  15038.         * @return string roman representation of the specified number
  15039.         * @access public
  15040.         * @since 4.4.004 (2008-12-10)
  15041.         */
  15042.         public function intToRoman($number{
  15043.             $roman '';
  15044.             while ($number >= 1000{
  15045.                 $roman .= 'M';
  15046.                 $number -= 1000;
  15047.             }
  15048.             while ($number >= 900{
  15049.                 $roman .= 'CM';
  15050.                 $number -= 900;
  15051.             }
  15052.             while ($number >= 500{
  15053.                 $roman .= 'D';
  15054.                 $number -= 500;
  15055.             }
  15056.             while ($number >= 400{
  15057.                 $roman .= 'CD';
  15058.                 $number -= 400;
  15059.             }
  15060.             while ($number >= 100{
  15061.                 $roman .= 'C';
  15062.                 $number -= 100;
  15063.             }
  15064.             while ($number >= 90{
  15065.             $roman .= 'XC';
  15066.             $number -= 90;
  15067.             }
  15068.             while ($number >= 50{
  15069.                 $roman .= 'L';
  15070.                 $number -= 50;
  15071.             }
  15072.             while ($number >= 40{
  15073.                 $roman .= 'XL';
  15074.                 $number -= 40;
  15075.             }
  15076.             while ($number >= 10{
  15077.             $roman .= 'X';
  15078.             $number -= 10;
  15079.             }
  15080.             while ($number >= 9{
  15081.                 $roman .= 'IX';
  15082.                 $number -= 9;
  15083.             }
  15084.             while ($number >= 5{
  15085.                 $roman .= 'V';
  15086.                 $number -= 5;
  15087.             }
  15088.             while ($number >= 4{
  15089.             $roman .= 'IV';
  15090.             $number -= 4;
  15091.             }
  15092.             while ($number >= 1{
  15093.                 $roman .= 'I';
  15094.                 --$number;
  15095.             }
  15096.             return $roman;
  15097.         }
  15098.  
  15099.         /**
  15100.         * Output an HTML list bullet or ordered item symbol
  15101.         * @param int $listdepth list nesting level
  15102.         * @param string $listtype type of list
  15103.         * @param float $size current font size
  15104.         * @access protected
  15105.         * @since 4.4.004 (2008-12-10)
  15106.         */
  15107.         protected function putHtmlListBullet($listdepth$listtype=''$size=10{
  15108.             $size /= $this->k;
  15109.             $fill '';
  15110.             $color $this->fgcolor;
  15111.             $width 0;
  15112.             $textitem '';
  15113.             $tmpx $this->x;        
  15114.             $lspace $this->GetStringWidth('  ');
  15115.             if ($listtype == '!'{
  15116.                 // set default list type for unordered list
  15117.                 $deftypes array('disc''circle''square');
  15118.                 $listtype $deftypes[($listdepth 13];
  15119.             elseif ($listtype == '#'{
  15120.                 // set default list type for ordered list
  15121.                 $listtype 'decimal';
  15122.             }
  15123.             switch ($listtype{
  15124.                 // unordered types
  15125.                 case 'none'{
  15126.                     break;
  15127.                 }
  15128.                 case 'disc'{
  15129.                     $fill 'F';
  15130.                 }
  15131.                 case 'circle'{
  15132.                     $fill .= 'D';
  15133.                     $r $size 6;
  15134.                     $lspace += ($r);
  15135.                     if ($this->rtl{
  15136.                         $this->x $this->w $this->x $lspace;
  15137.                     else {
  15138.                         $this->x -= $lspace;
  15139.                     }
  15140.                     $this->Circle(($this->x $r)($this->y ($this->lasth 2))$r0360$fillarray('color'=>$color)$color8);
  15141.                     break;
  15142.                 }
  15143.                 case 'square'{
  15144.                     $l $size 3;
  15145.                     $lspace += $l;
  15146.                     if ($this->rtl{
  15147.                         $this->x $this->w $this->x $lspace;
  15148.                     else {
  15149.                         $this->x -= $lspace;
  15150.                     }
  15151.                     $this->Rect($this->x($this->y (($this->lasth $l)2))$l$l'F'array()$color);
  15152.                     break;
  15153.                 }
  15154.                 // ordered types
  15155.  
  15156.                 // $this->listcount[$this->listnum];
  15157.                 // $textitem
  15158.                 case '1':
  15159.                 case 'decimal'{
  15160.                     $textitem $this->listcount[$this->listnum];
  15161.                     break;
  15162.                 }
  15163.                 case 'decimal-leading-zero'{
  15164.                     $textitem sprintf("%02d"$this->listcount[$this->listnum]);
  15165.                     break;
  15166.                 }
  15167.                 case 'i':
  15168.                 case 'lower-roman'{
  15169.                     $textitem strtolower($this->intToRoman($this->listcount[$this->listnum]));
  15170.                     break;
  15171.                 }
  15172.                 case 'I':
  15173.                 case 'upper-roman'{
  15174.                     $textitem $this->intToRoman($this->listcount[$this->listnum]);
  15175.                     break;
  15176.                 }
  15177.                 case 'a':
  15178.                 case 'lower-alpha':
  15179.                 case 'lower-latin'{
  15180.                     $textitem chr(97 $this->listcount[$this->listnum1);
  15181.                     break;
  15182.                 }
  15183.                 case 'A':
  15184.                 case 'upper-alpha':
  15185.                 case 'upper-latin'{
  15186.                     $textitem chr(65 $this->listcount[$this->listnum1);
  15187.                     break;
  15188.                 }
  15189.                 case 'lower-greek'{
  15190.                     $textitem $this->unichr(945 $this->listcount[$this->listnum1);
  15191.                     break;
  15192.                 }
  15193.                 /*
  15194.                 // Types to be implemented (special handling)
  15195.                 case 'hebrew': {
  15196.                     break;
  15197.                 }
  15198.                 case 'armenian': {
  15199.                     break;
  15200.                 }
  15201.                 case 'georgian': {
  15202.                     break;
  15203.                 }
  15204.                 case 'cjk-ideographic': {
  15205.                     break;
  15206.                 }
  15207.                 case 'hiragana': {
  15208.                     break;
  15209.                 }
  15210.                 case 'katakana': {
  15211.                     break;
  15212.                 }
  15213.                 case 'hiragana-iroha': {
  15214.                     break;
  15215.                 }
  15216.                 case 'katakana-iroha': {
  15217.                     break;
  15218.                 }
  15219.                 */
  15220.                 default{
  15221.                     $textitem $this->listcount[$this->listnum];
  15222.                 }
  15223.             }
  15224.             if (!$this->empty_string($textitem)) {
  15225.                 // print ordered item
  15226.                 if ($this->rtl{
  15227.                     $textitem '.'.$textitem;
  15228.                 else {
  15229.                     $textitem $textitem.'.';
  15230.                 }
  15231.                 $lspace += $this->GetStringWidth($textitem);
  15232.                 if ($this->rtl{
  15233.                     $this->x += $lspace;
  15234.                 else {
  15235.                     $this->x -= $lspace;
  15236.                 }
  15237.                 $this->Write($this->lasth$textitem''false''false0false);
  15238.             }
  15239.             $this->x $tmpx;
  15240.             $this->lispacer '';
  15241.         }
  15242.  
  15243.         /**
  15244.         * Returns current graphic variables as array.
  15245.         * @return array graphic variables
  15246.         * @access protected
  15247.         * @since 4.2.010 (2008-11-14)
  15248.         */
  15249.         protected function getGraphicVars({
  15250.             $grapvars array(
  15251.                 'FontFamily' => $this->FontFamily,
  15252.                 'FontStyle' => $this->FontStyle,
  15253.                 'FontSizePt' => $this->FontSizePt,
  15254.                 'rMargin' => $this->rMargin,
  15255.                 'lMargin' => $this->lMargin,
  15256.                 'cMargin' => $this->cMargin,
  15257.                 'LineWidth' => $this->LineWidth,
  15258.                 'linestyleWidth' => $this->linestyleWidth,
  15259.                 'linestyleCap' => $this->linestyleCap,
  15260.                 'linestyleJoin' => $this->linestyleJoin,
  15261.                 'linestyleDash' => $this->linestyleDash,
  15262.                 'DrawColor' => $this->DrawColor,
  15263.                 'FillColor' => $this->FillColor,
  15264.                 'TextColor' => $this->TextColor,
  15265.                 'ColorFlag' => $this->ColorFlag,
  15266.                 'bgcolor' => $this->bgcolor,
  15267.                 'fgcolor' => $this->fgcolor,
  15268.                 'htmlvspace' => $this->htmlvspace,
  15269.                 'lasth' => $this->lasth
  15270.                 );
  15271.             return $grapvars;
  15272.         }
  15273.  
  15274.         /**
  15275.         * Set graphic variables.
  15276.         * @param $gvars array graphic variables
  15277.         * @access protected
  15278.         * @since 4.2.010 (2008-11-14)
  15279.         */
  15280.         protected function setGraphicVars($gvars{
  15281.             $this->FontFamily $gvars['FontFamily'];
  15282.             $this->FontStyle $gvars['FontStyle'];
  15283.             $this->FontSizePt $gvars['FontSizePt'];
  15284.             $this->rMargin $gvars['rMargin'];
  15285.             $this->lMargin $gvars['lMargin'];
  15286.             $this->cMargin $gvars['cMargin'];
  15287.             $this->LineWidth $gvars['LineWidth'];
  15288.             $this->linestyleWidth $gvars['linestyleWidth'];
  15289.             $this->linestyleCap $gvars['linestyleCap'];
  15290.             $this->linestyleJoin $gvars['linestyleJoin'];
  15291.             $this->linestyleDash $gvars['linestyleDash'];
  15292.             $this->DrawColor $gvars['DrawColor'];
  15293.             $this->FillColor $gvars['FillColor'];
  15294.             $this->TextColor $gvars['TextColor'];
  15295.             $this->ColorFlag $gvars['ColorFlag'];
  15296.             $this->bgcolor $gvars['bgcolor'];
  15297.             $this->fgcolor $gvars['fgcolor'];
  15298.             $this->htmlvspace $gvars['htmlvspace'];
  15299.             //$this->lasth = $gvars['lasth'];
  15300.             $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  15301.             if (!$this->empty_string($this->FontFamily)) {
  15302.                 $this->SetFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  15303.             }
  15304.         }
  15305.  
  15306.         /**
  15307.         * Returns a temporary filename for caching object on filesystem.
  15308.         * @param string $prefix prefix to add to filename
  15309.         *  return string filename.
  15310.         * @access protected
  15311.         * @since 4.5.000 (2008-12-31)
  15312.         */
  15313.         protected function getObjFilename($name{
  15314.             return tempnam(K_PATH_CACHE$name.'_');
  15315.         }
  15316.  
  15317.         /**
  15318.         * Writes data to a temporary file on filesystem.
  15319.         * @param string $file file name
  15320.         * @param mixed $data data to write on file
  15321.         * @param boolean $append if true append data, false replace.
  15322.         * @access protected
  15323.         * @since 4.5.000 (2008-12-31)
  15324.         */
  15325.         protected function writeDiskCache($filename$data$append=false{
  15326.             if ($append{
  15327.                 $fmode 'ab+';
  15328.             else {
  15329.                 $fmode 'wb+';
  15330.             }
  15331.             $f @fopen($filename$fmode);
  15332.             if (!$f{
  15333.                 $this->Error('Unable to write cache file: '.$filename);
  15334.             else {
  15335.                 fwrite($f$data);
  15336.                 fclose($f);
  15337.             }
  15338.             // update file lenght (needed for transactions)
  15339.             if (!isset($this->cache_file_lenght['_'.$filename])) {
  15340.                 $this->cache_file_lenght['_'.$filenamestrlen($data);
  15341.             else {
  15342.                 $this->cache_file_lenght['_'.$filename+= strlen($data);
  15343.             }
  15344.         }
  15345.  
  15346.         /**
  15347.         * Read data from a temporary file on filesystem.
  15348.         * @param string $file file name
  15349.         * @return mixed retrieved data
  15350.         * @access protected
  15351.         * @since 4.5.000 (2008-12-31)
  15352.         */
  15353.         protected function readDiskCache($filename{
  15354.             return file_get_contents($filename);
  15355.         }
  15356.  
  15357.         /**
  15358.         * Set buffer content (always append data).
  15359.         * @param string $data data
  15360.         * @access protected
  15361.         * @since 4.5.000 (2009-01-02)
  15362.         */
  15363.         protected function setBuffer($data{
  15364.             $this->bufferlen += strlen($data);
  15365.             if ($this->diskcache{
  15366.                 if (!isset($this->bufferOR $this->empty_string($this->buffer)) {
  15367.                     $this->buffer $this->getObjFilename('buffer');
  15368.                 }
  15369.                 $this->writeDiskCache($this->buffer$datatrue);
  15370.             else {
  15371.                 $this->buffer .= $data;
  15372.             }
  15373.         }
  15374.  
  15375.         /**
  15376.         * Get buffer content.
  15377.         * @return string buffer content
  15378.         * @access protected
  15379.         * @since 4.5.000 (2009-01-02)
  15380.         */
  15381.         protected function getBuffer({
  15382.             if ($this->diskcache{
  15383.                 return $this->readDiskCache($this->buffer);
  15384.             else {
  15385.                 return $this->buffer;
  15386.             }
  15387.         }
  15388.  
  15389.         /**
  15390.         * Set page buffer content.
  15391.         * @param int $page page number
  15392.         * @param string $data page data
  15393.         * @param boolean $append if true append data, false replace.
  15394.         * @access protected
  15395.         * @since 4.5.000 (2008-12-31)
  15396.         */
  15397.         protected function setPageBuffer($page$data$append=false{
  15398.             if ($this->diskcache{
  15399.                 if (!isset($this->pages[$page])) {
  15400.                     $this->pages[$page$this->getObjFilename('page'.$page);
  15401.                 }
  15402.                 $this->writeDiskCache($this->pages[$page]$data$append);
  15403.             else {
  15404.                 if ($append{
  15405.                     $this->pages[$page.= $data;
  15406.                 else {
  15407.                     $this->pages[$page$data;
  15408.                 }
  15409.             }
  15410.             if ($append AND isset($this->pagelen[$page])) {
  15411.                 $this->pagelen[$page+= strlen($data);
  15412.             else {
  15413.                 $this->pagelen[$pagestrlen($data);
  15414.             }
  15415.         }
  15416.  
  15417.         /**
  15418.         * Get page buffer content.
  15419.         * @param int $page page number
  15420.         * @return string page buffer content or false in case of error
  15421.         * @access protected
  15422.         * @since 4.5.000 (2008-12-31)
  15423.         */
  15424.         protected function getPageBuffer($page{
  15425.             if ($this->diskcache{
  15426.                 return $this->readDiskCache($this->pages[$page]);
  15427.             elseif (isset($this->pages[$page])) {
  15428.                 return $this->pages[$page];
  15429.             }
  15430.             return false;
  15431.         }
  15432.  
  15433.         /**
  15434.         * Set image buffer content.
  15435.         * @param string $image image key
  15436.         * @param array $data image data
  15437.         * @access protected
  15438.         * @since 4.5.000 (2008-12-31)
  15439.         */
  15440.         protected function setImageBuffer($image$data{
  15441.             if ($this->diskcache{
  15442.                 if (!isset($this->images[$image])) {
  15443.                     $this->images[$image$this->getObjFilename('image'.$image);
  15444.                 }
  15445.                 $this->writeDiskCache($this->images[$image]serialize($data));
  15446.             else {
  15447.                 $this->images[$image$data;
  15448.             }
  15449.             if (!in_array($image$this->imagekeys)) {
  15450.                 $this->imagekeys[$image;
  15451.             }
  15452.             ++$this->numimages;
  15453.         }
  15454.  
  15455.         /**
  15456.         * Set image buffer content.
  15457.         * @param string $image image key
  15458.         * @param string $key image sub-key
  15459.         * @param array $data image data
  15460.         * @access protected
  15461.         * @since 4.5.000 (2008-12-31)
  15462.         */
  15463.         protected function setImageSubBuffer($image$key$data{
  15464.             if (!isset($this->images[$image])) {
  15465.                 $this->setImageBuffer($imagearray());
  15466.             }
  15467.             if ($this->diskcache{
  15468.                 $tmpimg $this->getImageBuffer($image);
  15469.                 $tmpimg[$key$data;
  15470.                 $this->writeDiskCache($this->images[$image]serialize($tmpimg));
  15471.             else {
  15472.                 $this->images[$image][$key$data;
  15473.             }
  15474.         }
  15475.  
  15476.         /**
  15477.         * Get image buffer content.
  15478.         * @param string $image image key
  15479.         * @return string image buffer content or false in case of error
  15480.         * @access protected
  15481.         * @since 4.5.000 (2008-12-31)
  15482.         */
  15483.         protected function getImageBuffer($image{
  15484.             if ($this->diskcache AND isset($this->images[$image])) {
  15485.                 return unserialize($this->readDiskCache($this->images[$image]));
  15486.             elseif (isset($this->images[$image])) {
  15487.                 return $this->images[$image];
  15488.             }
  15489.             return false;
  15490.         }
  15491.  
  15492.         /**
  15493.         * Set font buffer content.
  15494.         * @param string $font font key
  15495.         * @param array $data font data
  15496.         * @access protected
  15497.         * @since 4.5.000 (2009-01-02)
  15498.         */
  15499.         protected function setFontBuffer($font$data{
  15500.             if ($this->diskcache{
  15501.                 if (!isset($this->fonts[$font])) {
  15502.                     $this->fonts[$font$this->getObjFilename('font');
  15503.                 }
  15504.                 $this->writeDiskCache($this->fonts[$font]serialize($data));
  15505.             else {
  15506.                 $this->fonts[$font$data;
  15507.             }
  15508.             if (!in_array($font$this->fontkeys)) {
  15509.                 $this->fontkeys[$font;
  15510.             }
  15511.         }
  15512.  
  15513.         /**
  15514.         * Set font buffer content.
  15515.         * @param string $font font key
  15516.         * @param string $key font sub-key
  15517.         * @param array $data font data
  15518.         * @access protected
  15519.         * @since 4.5.000 (2009-01-02)
  15520.         */
  15521.         protected function setFontSubBuffer($font$key$data{
  15522.             if (!isset($this->fonts[$font])) {
  15523.                 $this->setFontBuffer($fontarray());
  15524.             }
  15525.             if ($this->diskcache{
  15526.                 $tmpfont $this->getFontBuffer($font);
  15527.                 $tmpfont[$key$data;
  15528.                 $this->writeDiskCache($this->fonts[$font]serialize($tmpfont));
  15529.             else {
  15530.                 $this->fonts[$font][$key$data;
  15531.             }
  15532.         }
  15533.  
  15534.         /**
  15535.         * Get font buffer content.
  15536.         * @param string $font font key
  15537.         * @return string font buffer content or false in case of error
  15538.         * @access protected
  15539.         * @since 4.5.000 (2009-01-02)
  15540.         */
  15541.         protected function getFontBuffer($font{
  15542.             if ($this->diskcache AND isset($this->fonts[$font])) {
  15543.                 return unserialize($this->readDiskCache($this->fonts[$font]));
  15544.             elseif (isset($this->fonts[$font])) {
  15545.                 return $this->fonts[$font];
  15546.             }
  15547.             return false;
  15548.         }
  15549.  
  15550.         /**
  15551.         * Move a page to a previous position.
  15552.         * @param int $frompage number of the source page
  15553.         * @param int $topage number of the destination page (must be less than $frompage)
  15554.         * @return true in case of success, false in case of error.
  15555.         * @access public
  15556.         * @since 4.5.000 (2009-01-02)
  15557.         */
  15558.         public function movePage($frompage$topage{
  15559.             if (($frompage $this->numpagesOR ($frompage <= $topage)) {
  15560.                 return false;
  15561.             }
  15562.             if ($frompage == $this->page{
  15563.                 // close the page before moving it
  15564.                 $this->endPage();
  15565.             }
  15566.             // move all page-related states
  15567.             $tmppage $this->pages[$frompage];
  15568.             $tmppagedim $this->pagedim[$frompage];
  15569.             $tmppagelen $this->pagelen[$frompage];
  15570.             $tmpintmrk $this->intmrk[$frompage];
  15571.             if (isset($this->footerpos[$frompage])) {
  15572.                 $tmpfooterpos $this->footerpos[$frompage];
  15573.             }
  15574.             if (isset($this->footerlen[$frompage])) {
  15575.                 $tmpfooterlen $this->footerlen[$frompage];
  15576.             }
  15577.             if (isset($this->transfmrk[$frompage])) {
  15578.                 $tmptransfmrk $this->transfmrk[$frompage];
  15579.             }
  15580.             if (isset($this->PageAnnots[$frompage])) {
  15581.                 $tmpannots $this->PageAnnots[$frompage];
  15582.             }
  15583.             if (isset($this->newpagegroup[$frompage])) {
  15584.                 $tmpnewpagegroup $this->newpagegroup[$frompage];
  15585.             }
  15586.             for ($i $frompage$i $topage--$i{
  15587.                 $j $i 1;
  15588.                 // shift pages down
  15589.                 $this->pages[$i$this->pages[$j];
  15590.                 $this->pagedim[$i$this->pagedim[$j];
  15591.                 $this->pagelen[$i$this->pagelen[$j];
  15592.                 $this->intmrk[$i$this->intmrk[$j];
  15593.                 if (isset($this->footerpos[$j])) {
  15594.                     $this->footerpos[$i$this->footerpos[$j];
  15595.                 elseif (isset($this->footerpos[$i])) {
  15596.                     unset($this->footerpos[$i]);
  15597.                 }
  15598.                 if (isset($this->footerlen[$j])) {
  15599.                     $this->footerlen[$i$this->footerlen[$j];
  15600.                 elseif (isset($this->footerlen[$i])) {
  15601.                     unset($this->footerlen[$i]);
  15602.                 }
  15603.                 if (isset($this->transfmrk[$j])) {
  15604.                     $this->transfmrk[$i$this->transfmrk[$j];
  15605.                 elseif (isset($this->transfmrk[$i])) {
  15606.                     unset($this->transfmrk[$i]);
  15607.                 }
  15608.                 if (isset($this->PageAnnots[$j])) {
  15609.                     $this->PageAnnots[$i$this->PageAnnots[$j];
  15610.                 elseif (isset($this->PageAnnots[$i])) {
  15611.                     unset($this->PageAnnots[$i]);
  15612.                 }
  15613.                 if (isset($this->newpagegroup[$j])) {
  15614.                     $this->newpagegroup[$i$this->newpagegroup[$j];
  15615.                 elseif (isset($this->newpagegroup[$i])) {
  15616.                     unset($this->newpagegroup[$i]);
  15617.                 }
  15618.             }
  15619.             $this->pages[$topage$tmppage;
  15620.             $this->pagedim[$topage$tmppagedim;
  15621.             $this->pagelen[$topage$tmppagelen;
  15622.             $this->intmrk[$topage$tmpintmrk;
  15623.             if (isset($tmpfooterpos)) {
  15624.                 $this->footerpos[$topage$tmpfooterpos;
  15625.             elseif (isset($this->footerpos[$topage])) {
  15626.                 unset($this->footerpos[$topage]);
  15627.             }
  15628.             if (isset($tmpfooterlen)) {
  15629.                 $this->footerlen[$topage$tmpfooterlen;
  15630.             elseif (isset($this->footerlen[$topage])) {
  15631.                 unset($this->footerlen[$topage]);
  15632.             }
  15633.             if (isset($tmptransfmrk)) {
  15634.                 $this->transfmrk[$topage$tmptransfmrk;
  15635.             elseif (isset($this->transfmrk[$topage])) {
  15636.                 unset($this->transfmrk[$topage]);
  15637.             }
  15638.             if (isset($tmpannots)) {
  15639.                 $this->PageAnnots[$topage$tmpannots;
  15640.             elseif (isset($this->PageAnnots[$topage])) {
  15641.                 unset($this->PageAnnots[$topage]);
  15642.             }
  15643.             if (isset($tmpnewpagegroup)) {
  15644.                 $this->newpagegroup[$topage$tmpnewpagegroup;
  15645.             elseif (isset($this->newpagegroup[$topage])) {
  15646.                 unset($this->newpagegroup[$topage]);
  15647.             }
  15648.             // adjust outlines
  15649.             $tmpoutlines $this->outlines;
  15650.             foreach ($tmpoutlines as $key => $outline{
  15651.                 if (($outline['p'>= $topageAND ($outline['p'$frompage)) {
  15652.                     $this->outlines[$key]['p'$outline['p'1;
  15653.                 elseif ($outline['p'== $frompage{
  15654.                     $this->outlines[$key]['p'$topage;
  15655.                 }
  15656.             }
  15657.             // adjust links
  15658.             $tmplinks $this->links;
  15659.             foreach ($tmplinks as $key => $link{
  15660.                 if (($link[0>= $topageAND ($link[0$frompage)) {
  15661.                     $this->links[$key][0$link[01;
  15662.                 elseif ($link[0== $frompage{
  15663.                     $this->links[$key][0$topage;
  15664.                 }
  15665.             }
  15666.             // adjust javascript
  15667.             $tmpjavascript $this->javascript;
  15668.             global $jfrompage$jtopage;
  15669.             $jfrompage $frompage;
  15670.             $jtopage $topage;
  15671.             $this->javascript preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  15672.                 create_function('$matches''global $jfrompage, $jtopage;
  15673.                 $pagenum = intval($matches[3]) + 1;
  15674.                 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  15675.                     $newpage = ($pagenum + 1);
  15676.                 } elseif ($pagenum == $jfrompage) {
  15677.                     $newpage = $jtopage;
  15678.                 } else {
  15679.                     $newpage = $pagenum;
  15680.                 }
  15681.                 --$newpage;
  15682.                 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";')$tmpjavascript);
  15683.             // return to last page
  15684.             $this->lastPage(true);
  15685.             return true;
  15686.         }
  15687.  
  15688.         /**
  15689.         * Remove the specified page.
  15690.         * @param int $page page to remove
  15691.         * @return true in case of success, false in case of error.
  15692.         * @access public
  15693.         * @since 4.6.004 (2009-04-23)
  15694.         */
  15695.         public function deletePage($page{
  15696.             if ($page $this->numpages{
  15697.                 return false;
  15698.             }
  15699.             // delete current page
  15700.             unset($this->pages[$page]);
  15701.             unset($this->pagedim[$page]);
  15702.             unset($this->pagelen[$page]);
  15703.             unset($this->intmrk[$page]);
  15704.             if (isset($this->footerpos[$page])) {
  15705.                 unset($this->footerpos[$page]);
  15706.             }
  15707.             if (isset($this->footerlen[$page])) {
  15708.                 unset($this->footerlen[$page]);
  15709.             }
  15710.             if (isset($this->transfmrk[$page])) {
  15711.                 unset($this->transfmrk[$page]);
  15712.             }
  15713.             if (isset($this->PageAnnots[$page])) {
  15714.                 unset($this->PageAnnots[$page]);
  15715.             }
  15716.             if (isset($this->newpagegroup[$page])) {
  15717.                 unset($this->newpagegroup[$page]);
  15718.             }
  15719.             if (isset($this->pageopen[$page])) {
  15720.                 unset($this->pageopen[$page]);
  15721.             }
  15722.             // update remaining pages
  15723.             for ($i $page$i $this->numpages++$i{
  15724.                 $j $i 1;
  15725.                 // shift pages
  15726.                 $this->pages[$i$this->pages[$j];
  15727.                 $this->pagedim[$i$this->pagedim[$j];
  15728.                 $this->pagelen[$i$this->pagelen[$j];
  15729.                 $this->intmrk[$i$this->intmrk[$j];
  15730.                 if (isset($this->footerpos[$j])) {
  15731.                     $this->footerpos[$i$this->footerpos[$j];
  15732.                 elseif (isset($this->footerpos[$i])) {
  15733.                     unset($this->footerpos[$i]);
  15734.                 }
  15735.                 if (isset($this->footerlen[$j])) {
  15736.                     $this->footerlen[$i$this->footerlen[$j];
  15737.                 elseif (isset($this->footerlen[$i])) {
  15738.                     unset($this->footerlen[$i]);
  15739.                 }
  15740.                 if (isset($this->transfmrk[$j])) {
  15741.                     $this->transfmrk[$i$this->transfmrk[$j];
  15742.                 elseif (isset($this->transfmrk[$i])) {
  15743.                     unset($this->transfmrk[$i]);
  15744.                 }
  15745.                 if (isset($this->PageAnnots[$j])) {
  15746.                     $this->PageAnnots[$i$this->PageAnnots[$j];
  15747.                 elseif (isset($this->PageAnnots[$i])) {
  15748.                     unset($this->PageAnnots[$i]);
  15749.                 }
  15750.                 if (isset($this->newpagegroup[$j])) {
  15751.                     $this->newpagegroup[$i$this->newpagegroup[$j];
  15752.                 elseif (isset($this->newpagegroup[$i])) {
  15753.                     unset($this->newpagegroup[$i]);
  15754.                 }
  15755.                 if (isset($this->pageopen[$j])) {
  15756.                     $this->pageopen[$i$this->pageopen[$j];
  15757.                 elseif (isset($this->pageopen[$i])) {
  15758.                     unset($this->pageopen[$i]);
  15759.                 }
  15760.             }
  15761.             // remove last page
  15762.             unset($this->pages[$this->numpages]);
  15763.             unset($this->pagedim[$this->numpages]);
  15764.             unset($this->pagelen[$this->numpages]);
  15765.             unset($this->intmrk[$this->numpages]);
  15766.             if (isset($this->footerpos[$this->numpages])) {
  15767.                 unset($this->footerpos[$this->numpages]);
  15768.             }
  15769.             if (isset($this->footerlen[$this->numpages])) {
  15770.                 unset($this->footerlen[$this->numpages]);
  15771.             }
  15772.             if (isset($this->transfmrk[$this->numpages])) {
  15773.                 unset($this->transfmrk[$this->numpages]);
  15774.             }
  15775.             if (isset($this->PageAnnots[$this->numpages])) {
  15776.                 unset($this->PageAnnots[$this->numpages]);
  15777.             }
  15778.             if (isset($this->newpagegroup[$this->numpages])) {
  15779.                 unset($this->newpagegroup[$this->numpages]);
  15780.             }
  15781.             if (isset($this->pageopen[$this->numpages])) {
  15782.                 unset($this->pageopen[$this->numpages]);
  15783.             }
  15784.             --$this->numpages;
  15785.             $this->page $this->numpages;
  15786.             // adjust outlines
  15787.             $tmpoutlines $this->outlines;
  15788.             foreach ($tmpoutlines as $key => $outline{
  15789.                 if ($outline['p'$page{
  15790.                     $this->outlines[$key]['p'$outline['p'1;
  15791.                 elseif ($outline['p'== $page{
  15792.                     unset($this->outlines[$key]);
  15793.                 }
  15794.             }
  15795.             // adjust links
  15796.             $tmplinks $this->links;
  15797.             foreach ($tmplinks as $key => $link{
  15798.                 if ($link[0$page{
  15799.                     $this->links[$key][0$link[01;
  15800.                 elseif ($link[0== $page{
  15801.                     unset($this->links[$key]);
  15802.                 }
  15803.             }
  15804.             // adjust javascript
  15805.             $tmpjavascript $this->javascript;
  15806.             global $jpage;
  15807.             $jpage $page;
  15808.             $this->javascript preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  15809.                 create_function('$matches''global $jpage;
  15810.                 $pagenum = intval($matches[3]) + 1;
  15811.                 if ($pagenum >= $jpage) {
  15812.                     $newpage = ($pagenum - 1);
  15813.                 } elseif ($pagenum == $jpage) {
  15814.                     $newpage = 1;
  15815.                 } else {
  15816.                     $newpage = $pagenum;
  15817.                 }
  15818.                 --$newpage;
  15819.                 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";')$tmpjavascript);
  15820.             // return to last page
  15821.             $this->lastPage(true);
  15822.             return true;
  15823.         }
  15824.  
  15825.         /**
  15826.         * Output a Table of Content Index (TOC).
  15827.         * You can override this method to achieve different styles.
  15828.         * @param int $page page number where this TOC should be inserted (leave empty for current page).
  15829.         * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  15830.         * @param string $filler string used to fill the space between text and page number.
  15831.         * @access public
  15832.         * @author Nicola Asuni
  15833.         * @since 4.5.000 (2009-01-02)
  15834.         */
  15835.         public function addTOC($page=''$numbersfont=''$filler='.'{
  15836.             $fontsize $this->FontSizePt;
  15837.             $fontfamily $this->FontFamily;
  15838.             $fontstyle $this->FontStyle;
  15839.             $w $this->w $this->lMargin $this->rMargin;
  15840.             $spacer $this->GetStringWidth(' '4;
  15841.             $page_first $this->getPage();
  15842.             $lmargin $this->lMargin;
  15843.             $rmargin $this->rMargin;
  15844.             $x_start $this->GetX();
  15845.             if ($this->empty_string($numbersfont)) {
  15846.                 $numbersfont $this->default_monospaced_font;
  15847.             }
  15848.             if ($this->empty_string($filler)) {
  15849.                 $filler ' ';
  15850.             }
  15851.             if ($this->empty_string($page)) {
  15852.                 $gap ' ';
  15853.             else {
  15854.                 $gap '';
  15855.             }
  15856.             foreach ($this->outlines as $key => $outline{
  15857.                 if ($this->rtl{
  15858.                     $aligntext 'R';
  15859.                     $alignnum 'L';
  15860.                 else {
  15861.                     $aligntext 'L';
  15862.                     $alignnum 'R';
  15863.                 }
  15864.                 if ($outline['l'== 0{
  15865.                     $this->SetFont($fontfamily$fontstyle.'B'$fontsize);
  15866.                 else {
  15867.                     $this->SetFont($fontfamily$fontstyle$fontsize $outline['l']);
  15868.                 }
  15869.                 $indent ($spacer $outline['l']);
  15870.                 if ($this->rtl{
  15871.                     $this->rMargin += $indent;
  15872.                     $this->x -= $indent;
  15873.                 else {
  15874.                     $this->lMargin += $indent;
  15875.                     $this->x += $indent;
  15876.                 }
  15877.                 $link $this->AddLink();
  15878.                 $this->SetLink($link0$outline['p']);
  15879.                 // write the text
  15880.                 $this->Write(0$outline['t']$link0$aligntextfalse0falsefalse0);
  15881.                 $this->SetFont($numbersfont$fontstyle$fontsize);
  15882.                 if ($this->empty_string($page)) {
  15883.                     $pagenum $outline['p'];
  15884.                 else {
  15885.                     // placemark to be replaced with the correct number
  15886.                     $pagenum '{#'.($outline['p']).'}';
  15887.                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  15888.                         $pagenum '{'.$pagenum.'}';
  15889.                     }
  15890.                 }
  15891.                 $numwidth $this->GetStringWidth($pagenum);
  15892.                 if ($this->rtl{
  15893.                     $tw $this->x $this->lMargin;
  15894.                 else {
  15895.                     $tw $this->w $this->rMargin $this->x;
  15896.                 }
  15897.                 $fw $tw $numwidth $this->GetStringWidth(' ');
  15898.                 $numfills floor($fw $this->GetStringWidth($filler));
  15899.                 if ($numfills 0{
  15900.                     $rowfill str_repeat($filler$numfills);
  15901.                 else {
  15902.                     $rowfill '';
  15903.                 }
  15904.                 if ($this->rtl{
  15905.                     $pagenum $pagenum.$gap.$rowfill.' ';
  15906.                 else {
  15907.                     $pagenum ' '.$rowfill.$gap.$pagenum;
  15908.                 }
  15909.                 // write the number
  15910.                 //$this->SetX($x_start);
  15911.                 $this->Cell($tw0$pagenum01$alignnum0$link0);
  15912.                 $this->SetX($x_start);
  15913.                 $this->lMargin $lmargin;
  15914.                 $this->rMargin $rmargin;
  15915.             }
  15916.             $page_last $this->getPage();
  15917.             $numpages $page_last $page_first 1;
  15918.             if (!$this->empty_string($page)) {
  15919.                 for ($p $page_first$p <= $page_last++$p{
  15920.                     // get page data
  15921.                     $temppage $this->getPageBuffer($p);
  15922.                     for ($n 1$n <= $this->numpages++$n{
  15923.                         // update page numbers
  15924.                         $k '{#'.$n.'}';
  15925.                         $ku '{'.$k.'}';
  15926.                         $alias_a $this->_escape($k);
  15927.                         $alias_au $this->_escape('{'.$k.'}');
  15928.                         if ($this->isunicode{
  15929.                             $alias_b $this->_escape($this->UTF8ToLatin1($k));
  15930.                             $alias_bu $this->_escape($this->UTF8ToLatin1($ku));
  15931.                             $alias_c $this->_escape($this->utf8StrRev($kfalse$this->tmprtl));
  15932.                             $alias_cu $this->_escape($this->utf8StrRev($kufalse$this->tmprtl));
  15933.                         }
  15934.                         if ($n >= $page{
  15935.                             $np $n $numpages;
  15936.                         else {
  15937.                             $np $n;
  15938.                         }
  15939.                         $ns $this->formatTOCPageNumber($np);
  15940.                         $nu $ns;
  15941.                         $sdiff strlen($kstrlen($ns1;
  15942.                         $sdiffu strlen($kustrlen($ns1;
  15943.                         $sfill str_repeat($filler$sdiff);
  15944.                         $sfillu str_repeat($filler$sdiffu);
  15945.                         if ($this->rtl{
  15946.                             $ns $ns.' '.$sfill;
  15947.                             $nu $nu.' '.$sfillu;
  15948.                         else {
  15949.                             $ns $sfill.' '.$ns;
  15950.                             $nu $sfillu.' '.$nu;
  15951.                         }
  15952.                         $nu $this->UTF8ToUTF16BE($nufalse);
  15953.                         $temppage str_replace($alias_au$nu$temppage);
  15954.                         if ($this->isunicode{
  15955.                             $temppage str_replace($alias_bu$nu$temppage);
  15956.                             $temppage str_replace($alias_cu$nu$temppage);
  15957.                             $temppage str_replace($alias_b$ns$temppage);
  15958.                             $temppage str_replace($alias_c$ns$temppage);
  15959.                         }
  15960.                         $temppage str_replace($alias_a$ns$temppage);
  15961.                     }
  15962.                     // save changes
  15963.                     $this->setPageBuffer($p$temppage);
  15964.                 }
  15965.                 // move pages
  15966.                 for ($i 0$i $numpages++$i{
  15967.                     $this->movePage($page_last$page);
  15968.                 }
  15969.             }
  15970.             $this->SetFont($fontfamily$fontstyle$fontsize);
  15971.         }
  15972.  
  15973.         /**
  15974.         * Stores a copy of the current TCPDF object used for undo operation.
  15975.         * @access public
  15976.         * @since 4.5.029 (2009-03-19)
  15977.         */
  15978.         public function startTransaction({
  15979.             if (isset($this->objcopy)) {
  15980.                 // remove previous copy
  15981.                 $this->commitTransaction();
  15982.             }
  15983.             // record current page number
  15984.             $this->start_transaction_page $this->page;
  15985.             // clone current object
  15986.             $this->objcopy $this->objclone($this);
  15987.         }
  15988.  
  15989.         /**
  15990.         * Delete the copy of the current TCPDF object used for undo operation.
  15991.         * @access public
  15992.         * @since 4.5.029 (2009-03-19)
  15993.         */
  15994.         public function commitTransaction({
  15995.             if (isset($this->objcopy)) {
  15996.                 $this->objcopy->_destroy(truetrue);
  15997.                 unset($this->objcopy);
  15998.             }
  15999.         }
  16000.  
  16001.         /**
  16002.         * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  16003.         * @param boolean $self if true restores current class object to previous state without the need of reassignment via the returned value.
  16004.         * @return TCPDF object.
  16005.         * @access public
  16006.         * @since 4.5.029 (2009-03-19)
  16007.         */
  16008.         public function rollbackTransaction($self=false{
  16009.             if (isset($this->objcopy)) {
  16010.                 if (isset($this->objcopy->diskcacheAND $this->objcopy->diskcache{
  16011.                     // truncate files to previous values
  16012.                     foreach ($this->objcopy->cache_file_lenght as $file => $lenght{
  16013.                         $file substr($file1);
  16014.                         $handle fopen($file'r+');
  16015.                         ftruncate($handle$lenght);
  16016.                     }
  16017.                 }
  16018.                 $this->_destroy(truetrue);
  16019.                 if ($self{
  16020.                     $objvars get_object_vars($this->objcopy);
  16021.                     foreach ($objvars as $key => $value{
  16022.                         $this->$key $value;
  16023.                     }
  16024.                 }
  16025.                 return $this->objcopy;
  16026.             }
  16027.             return $this;
  16028.         }
  16029.  
  16030.         /**
  16031.         * Creates a copy of a class object
  16032.         * @param object $object class object to be cloned
  16033.         * @return cloned object
  16034.         * @access public
  16035.         * @since 4.5.029 (2009-03-19)
  16036.         */
  16037.         public function objclone($object{
  16038.             return @clone($object);
  16039.         }
  16040.  
  16041.         /**
  16042.         * Determine whether a string is empty.
  16043.         * @param srting $str string to be checked
  16044.         * @return boolean true if string is empty
  16045.         * @access public
  16046.         * @since 4.5.044 (2009-04-16)
  16047.         */
  16048.         public function empty_string($str{
  16049.             return (is_null($strOR (is_string($strAND (strlen($str== 0)));
  16050.         }
  16051.         
  16052.     // END OF TCPDF CLASS
  16053. }
  16054. //============================================================+
  16055. // END OF FILE
  16056. //============================================================+
  16057. ?>

Documentation generated on Tue, 01 Jun 2010 17:06:55 +0200 by phpDocumentor 1.4.3