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-04-16
  6. // Author      : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version     : 4.6.000
  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 UTF-8 Unicode and Right-To-Left languages;
  40. //     * supports document encryption;
  41. //     * includes methods to publish some XHTML code;
  42. //     * includes graphic (geometric) and transformation methods;
  43. //     * includes bookmarks;
  44. //     * includes Javascript and forms support;
  45. //     * includes a method to print various barcode formats;
  46. //     * supports TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  47. //     * supports custom page formats, margins and units of measure;
  48. //     * includes methods for page header and footer management;
  49. //     * supports automatic page break;
  50. //     * supports automatic page numbering and page groups;
  51. //     * supports automatic line break and text justification;
  52. //     * supports JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
  53. //     * supports stroke and clipping mode for text;
  54. //     * supports clipping masks;
  55. //     * supports Grayscale, RGB, CMYK, Spot colors and transparency;
  56. //     * supports links and annotations;
  57. //     * supports page compression (requires zlib extension);
  58. //     * supports PDF user's rights.
  59. //
  60. // -----------------------------------------------------------
  61. // THANKS TO:
  62. // 
  63. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  64. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  65. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  66. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  67. // dullus for text Justification.
  68. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  69. // Patrick Benny for text stretch suggestion on Cell().
  70. // Johannes Güntert for JavaScript support.
  71. // Denis Van Nuffelen for Dynamic Form.
  72. // Jacek Czekaj for multibyte justification
  73. // Anthony Ferrara for the reintroduction of legacy image methods.
  74. // Sourceforge user 1707880 (hucste) for line-trough mode.
  75. // Larry Stanbery for page groups.
  76. // Martin Hall-May for transparency.
  77. // Aaron C. Spike for Polycurve method.
  78. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  79. // Moritz Wagner and Andreas Wurmser for graphic functions.
  80. // Andrew Whitehead for core fonts support.
  81. // Esteban Joël Marín for OpenType font conversion.
  82. // Teus Hagen for several suggestions and fixes.
  83. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  84. // Kosmas Papachristos for some CSS improvements.
  85. // Marcel Partap for some fixes.
  86. // Won Kyu Park for several suggestions, fixes and patches.
  87. // Anyone that has reported a bug or sent a suggestion.
  88. //============================================================+
  89.  
  90. /**
  91.  * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  92.  * 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>
  93.  * <h3>TCPDF main features are:</h3>
  94.  * <ul>
  95.  * <li>no external libraries are required for the basic functions;</li>
  96.  * <li>supports all ISO page formats;</li>
  97.  * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  98.  * <li>supports document encryption;</li>
  99.  * <li>includes methods to publish some XHTML code;</li>
  100.  * <li>includes graphic (geometric) and transformation methods;</li>
  101.  * <li>includes bookmarks;</li>
  102.  * <li>includes Javascript and forms support;</li>
  103.  * <li>includes a method to print various barcode formats;</li>
  104.  * <li>supports TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  105.  * <li>supports custom page formats, margins and units of measure;</li>
  106.  * <li>includes methods for page header and footer management;</li>
  107.  * <li>supports automatic page break;</li>
  108.  * <li>supports automatic page numbering and page groups;</li>
  109.  * <li>supports automatic line break and text justification;
  110.  * <li>supports JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;</li>
  111.  * <li>supports stroke and clipping mode for text;</li>
  112.  * <li>supports clipping masks;</li>
  113.  * <li>supports Grayscale, RGB and CMYK colors and transparency;</li>
  114.  * <li>supports links and annotations;</li>
  115.  * <li>supports page compression (requires zlib extension);</li>
  116.  * <li>supports PDF user's rights.</li>
  117.  * </ul>
  118.  * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  119.  * @package com.tecnick.tcpdf
  120.  * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  121.  * @author Nicola Asuni
  122.  * @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
  123.  * @link http://www.tcpdf.org
  124.  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  125.  * @version 4.6.000
  126.  */
  127.  
  128. /**
  129.  * main configuration file
  130.  */
  131. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  132.  
  133. // includes some support files
  134.  
  135. /**
  136.  * unicode data
  137.  */
  138. require_once(dirname(__FILE__).'/unicode_data.php');
  139.  
  140. /**
  141.  * html colors table
  142.  */
  143. require_once(dirname(__FILE__).'/htmlcolors.php');
  144.  
  145. if (!class_exists('TCPDF'false)) {
  146.     /**
  147.      * define default PDF document producer
  148.      */ 
  149.     define('PDF_PRODUCER''TCPDF 4.6.000 (http://www.tcpdf.org)');
  150.     
  151.     /**
  152.     * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  153.     * 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>
  154.     * @name TCPDF
  155.     * @package com.tecnick.tcpdf
  156.     * @version 4.6.000
  157.     * @author Nicola Asuni - info@tecnick.com
  158.     * @link http://www.tcpdf.org
  159.     * @license http://www.gnu.org/copyleft/lesser.html LGPL
  160.     */
  161.     class TCPDF {
  162.         
  163.         // protected or Protected properties
  164.  
  165.         /**
  166.         * @var current page number
  167.         * @access protected
  168.         */
  169.         protected $page;
  170.         
  171.         /**
  172.         * @var current object number
  173.         * @access protected
  174.         */
  175.         protected $n;
  176.  
  177.         /**
  178.         * @var array of object offsets
  179.         * @access protected
  180.         */
  181.         protected $offsets;
  182.  
  183.         /**
  184.         * @var buffer holding in-memory PDF
  185.         * @access protected
  186.         */
  187.         protected $buffer;
  188.  
  189.         /**
  190.         * @var array containing pages
  191.         * @access protected
  192.         */
  193.         protected $pages = array();
  194.  
  195.         /**
  196.         * @var current document state
  197.         * @access protected
  198.         */
  199.         protected $state;
  200.  
  201.         /**
  202.         * @var compression flag
  203.         * @access protected
  204.         */
  205.         protected $compress;
  206.         
  207.         /**
  208.         * @var current page orientation (P = Portrait, L = Landscape)
  209.         * @access protected
  210.         */
  211.         protected $CurOrientation;
  212.  
  213.         /**
  214.         * @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>
  215.         * @access protected
  216.         */
  217.         protected $pagedim = array();
  218.  
  219.         /**
  220.         * @var scale factor (number of points in user unit)
  221.         * @access protected
  222.         */
  223.         protected $k;
  224.  
  225.         /**
  226.         * @var width of page format in points
  227.         * @access protected
  228.         */
  229.         protected $fwPt;
  230.  
  231.         /**
  232.         * @var height of page format in points
  233.         * @access protected
  234.         */
  235.         protected $fhPt;
  236.  
  237.         /**
  238.         * @var current width of page in points
  239.         * @access protected
  240.         */
  241.         protected $wPt;
  242.  
  243.         /**
  244.         * @var current height of page in points
  245.         * @access protected
  246.         */
  247.         protected $hPt;
  248.  
  249.         /**
  250.         * @var current width of page in user unit
  251.         * @access protected
  252.         */
  253.         protected $w;
  254.  
  255.         /**
  256.         * @var current height of page in user unit
  257.         * @access protected
  258.         */
  259.         protected $h;
  260.  
  261.         /**
  262.         * @var left margin
  263.         * @access protected
  264.         */
  265.         protected $lMargin;
  266.  
  267.         /**
  268.         * @var top margin
  269.         * @access protected
  270.         */
  271.         protected $tMargin;
  272.  
  273.         /**
  274.         * @var right margin
  275.         * @access protected
  276.         */
  277.         protected $rMargin;
  278.  
  279.         /**
  280.         * @var page break margin
  281.         * @access protected
  282.         */
  283.         protected $bMargin;
  284.  
  285.         /**
  286.         * @var cell internal padding
  287.         * @access protected
  288.         */
  289.         //protected
  290.         public $cMargin;
  291.         
  292.         /**
  293.         * @var cell internal padding (previous value)
  294.         * @access protected
  295.         */
  296.         protected $oldcMargin;
  297.  
  298.         /**
  299.         * @var current horizontal position in user unit for cell positioning
  300.         * @access protected
  301.         */
  302.         protected $x;
  303.  
  304.         /**
  305.         * @var current vertical position in user unit for cell positioning
  306.         * @access protected
  307.         */
  308.         protected $y;
  309.  
  310.         /**
  311.         * @var height of last cell printed
  312.         * @access protected
  313.         */
  314.         protected $lasth;
  315.  
  316.         /**
  317.         * @var line width in user unit
  318.         * @access protected
  319.         */
  320.         protected $LineWidth;
  321.  
  322.         /**
  323.         * @var array of standard font names
  324.         * @access protected
  325.         */
  326.         protected $CoreFonts;
  327.  
  328.         /**
  329.         * @var array of used fonts
  330.         * @access protected
  331.         */
  332.         protected $fonts = array();
  333.  
  334.         /**
  335.         * @var array of font files
  336.         * @access protected
  337.         */
  338.         protected $FontFiles = array();
  339.  
  340.         /**
  341.         * @var array of encoding differences
  342.         * @access protected
  343.         */
  344.         protected $diffs = array();
  345.  
  346.         /**
  347.         * @var array of used images
  348.         * @access protected
  349.         */
  350.         protected $images = array();
  351.  
  352.         /**
  353.         * @var array of Annotations in pages
  354.         * @access protected
  355.         */
  356.         protected $PageAnnots = array();
  357.  
  358.         /**
  359.         * @var array of internal links
  360.         * @access protected
  361.         */
  362.         protected $links = array();
  363.  
  364.         /**
  365.         * @var current font family
  366.         * @access protected
  367.         */
  368.         protected $FontFamily;
  369.  
  370.         /**
  371.         * @var current font style
  372.         * @access protected
  373.         */
  374.         protected $FontStyle;
  375.         
  376.         /**
  377.         * @var current font ascent (distance between font top and baseline)
  378.         * @access protected
  379.         * @since 2.8.000 (2007-03-29)
  380.         */
  381.         protected $FontAscent;
  382.         
  383.         /**
  384.         * @var current font descent (distance between font bottom and baseline)
  385.         * @access protected
  386.         * @since 2.8.000 (2007-03-29)
  387.         */
  388.         protected $FontDescent;
  389.  
  390.         /**
  391.         * @var underlining flag
  392.         * @access protected
  393.         */
  394.         protected $underline;
  395.  
  396.         /**
  397.         * @var current font info
  398.         * @access protected
  399.         */
  400.         protected $CurrentFont;
  401.  
  402.         /**
  403.         * @var current font size in points
  404.         * @access protected
  405.         */
  406.         protected $FontSizePt;
  407.  
  408.         /**
  409.         * @var current font size in user unit
  410.         * @access protected
  411.         */
  412.         protected $FontSize;
  413.  
  414.         /**
  415.         * @var commands for drawing color
  416.         * @access protected
  417.         */
  418.         protected $DrawColor;
  419.  
  420.         /**
  421.         * @var commands for filling color
  422.         * @access protected
  423.         */
  424.         protected $FillColor;
  425.  
  426.         /**
  427.         * @var commands for text color
  428.         * @access protected
  429.         */
  430.         protected $TextColor;
  431.  
  432.         /**
  433.         * @var indicates whether fill and text colors are different
  434.         * @access protected
  435.         */
  436.         protected $ColorFlag;
  437.  
  438.         /**
  439.         * @var automatic page breaking
  440.         * @access protected
  441.         */
  442.         protected $AutoPageBreak;
  443.  
  444.         /**
  445.         * @var threshold used to trigger page breaks
  446.         * @access protected
  447.         */
  448.         protected $PageBreakTrigger;
  449.  
  450.         /**
  451.         * @var flag set when processing footer
  452.         * @access protected
  453.         */
  454.         protected $InFooter = false;
  455.  
  456.         /**
  457.         * @var zoom display mode
  458.         * @access protected
  459.         */
  460.         protected $ZoomMode;
  461.  
  462.         /**
  463.         * @var layout display mode
  464.         * @access protected
  465.         */
  466.         protected $LayoutMode;
  467.  
  468.         /**
  469.         * @var title 
  470.         * @access protected
  471.         */
  472.         protected $title = '';
  473.  
  474.         /**
  475.         * @var subject 
  476.         * @access protected
  477.         */
  478.         protected $subject = '';
  479.  
  480.         /**
  481.         * @var author 
  482.         * @access protected
  483.         */
  484.         protected $author = '';
  485.  
  486.         /**
  487.         * @var keywords 
  488.         * @access protected
  489.         */
  490.         protected $keywords = '';
  491.  
  492.         /**
  493.         * @var creator 
  494.         * @access protected
  495.         */
  496.         protected $creator = '';
  497.  
  498.         /**
  499.         * @var alias for total number of pages
  500.         * @access protected
  501.         */
  502.         protected $AliasNbPages = '{nb}';
  503.         
  504.         /**
  505.         * @var alias for page number
  506.         * @access protected
  507.         */
  508.         protected $AliasNumPage = '{pnb}';
  509.         
  510.         /**
  511.         * @var right-bottom corner X coordinate of inserted image
  512.         * @since 2002-07-31
  513.         * @author Nicola Asuni
  514.         * @access protected
  515.         */
  516.         protected $img_rb_x;
  517.  
  518.         /**
  519.         * @var right-bottom corner Y coordinate of inserted image
  520.         * @since 2002-07-31
  521.         * @author Nicola Asuni
  522.         * @access protected
  523.         */
  524.         protected $img_rb_y;
  525.  
  526.         /**
  527.         * @var image scale factor
  528.         * @since 2004-06-14
  529.         * @author Nicola Asuni
  530.         * @access protected
  531.         */
  532.         protected $imgscale = 1;
  533.  
  534.         /**
  535.         * @var boolean set to true when the input text is unicode (require unicode fonts)
  536.         * @since 2005-01-02
  537.         * @author Nicola Asuni
  538.         * @access protected
  539.         */
  540.         protected $isunicode = false;
  541.  
  542.         /**
  543.         * @var PDF version
  544.         * @since 1.5.3
  545.         * @access protected
  546.         */
  547.         protected $PDFVersion = '1.7';
  548.         
  549.         
  550.         // ----------------------
  551.         
  552.         /**
  553.          * @var Minimum distance between header and top page margin.
  554.          * @access protected
  555.          */
  556.         protected $header_margin;
  557.         
  558.         /**
  559.          * @var Minimum distance between footer and bottom page margin.
  560.          * @access protected
  561.          */
  562.         protected $footer_margin;
  563.         
  564.         /**
  565.          * @var original left margin value
  566.          * @access protected
  567.          * @since 1.53.0.TC013
  568.          */
  569.         protected $original_lMargin;
  570.         
  571.         /**
  572.          * @var original right margin value
  573.          * @access protected
  574.          * @since 1.53.0.TC013
  575.          */
  576.         protected $original_rMargin;
  577.             
  578.         /**
  579.          * @var Header font.
  580.          * @access protected
  581.          */
  582.         protected $header_font;
  583.         
  584.         /**
  585.          * @var Footer font.
  586.          * @access protected
  587.          */
  588.         protected $footer_font;
  589.         
  590.         /**
  591.          * @var Language templates.
  592.          * @access protected
  593.          */
  594.         protected $l;
  595.         
  596.         /**
  597.          * @var Barcode to print on page footer (only if set).
  598.          * @access protected
  599.          */
  600.         protected $barcode = false;
  601.         
  602.         /**
  603.          * @var If true prints header
  604.          * @access protected
  605.          */
  606.         protected $print_header = true;
  607.         
  608.         /**
  609.          * @var If true prints footer.
  610.          * @access protected
  611.          */
  612.         protected $print_footer = true;
  613.             
  614.         /**
  615.          * @var Header image logo.
  616.          * @access protected
  617.          */
  618.         protected $header_logo = '';
  619.         
  620.         /**
  621.          * @var Header image logo width in mm.
  622.          * @access protected
  623.          */
  624.         protected $header_logo_width = 30;
  625.         
  626.         /**
  627.          * @var String to print as title on document header.
  628.          * @access protected
  629.          */
  630.         protected $header_title = '';
  631.         
  632.         /**
  633.          * @var String to print on document header.
  634.          * @access protected
  635.          */
  636.         protected $header_string = '';
  637.         
  638.         /**
  639.          * @var Default number of columns for html table.
  640.          * @access protected
  641.          */
  642.         protected $default_table_columns = 4;
  643.         
  644.         
  645.         // variables for html parser
  646.         
  647.         /**
  648.          * @var HTML PARSER: array to store current link and rendering styles.
  649.          * @access protected
  650.          */
  651.         protected $HREF = array();
  652.         
  653.         /**
  654.          * @var store a list of available fonts on filesystem.
  655.          * @access protected
  656.          */
  657.         protected $fontlist = array();
  658.         
  659.         /**
  660.          * @var current foreground color
  661.          * @access protected
  662.          */
  663.         protected $fgcolor;
  664.                         
  665.         /**
  666.          * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  667.          * @access protected
  668.          */
  669.         protected $listordered = array();
  670.         
  671.         /**
  672.          * @var HTML PARSER: array count list items on nested lists.
  673.          * @access protected
  674.          */
  675.         protected $listcount = array();
  676.         
  677.         /**
  678.          * @var HTML PARSER: current list nesting level.
  679.          * @access protected
  680.          */
  681.         protected $listnum = 0;
  682.         
  683.         /**
  684.          * @var HTML PARSER: indent amount for lists.
  685.          * @access protected
  686.          */
  687.         protected $listindent;
  688.         
  689.         /**
  690.          * @var current background color
  691.          * @access protected
  692.          */
  693.         protected $bgcolor;
  694.         
  695.         /**
  696.          * @var Store temporary font size in points.
  697.          * @access protected
  698.          */
  699.         protected $tempfontsize = 10;
  700.         
  701.         /**
  702.          * @var spacer for LI tags.
  703.          * @access protected
  704.          */
  705.         protected $lispacer = '';
  706.         
  707.         /**
  708.          * @var default encoding
  709.          * @access protected
  710.          * @since 1.53.0.TC010
  711.          */
  712.         protected $encoding = 'UTF-8';
  713.         
  714.         /**
  715.          * @var PHP internal encoding
  716.          * @access protected
  717.          * @since 1.53.0.TC016
  718.          */
  719.         protected $internal_encoding;
  720.         
  721.         /**
  722.          * @var indicates if the document language is Right-To-Left
  723.          * @access protected
  724.          * @since 2.0.000
  725.          */
  726.         protected $rtl = false;
  727.         
  728.         /**
  729.          * @var used to force RTL or LTR string inversion
  730.          * @access protected
  731.          * @since 2.0.000
  732.          */
  733.         protected $tmprtl = false;
  734.         
  735.         // --- Variables used for document encryption:
  736.         
  737.         /**
  738.          * Indicates whether document is protected
  739.          * @access protected
  740.          * @since 2.0.000 (2008-01-02)
  741.          */
  742.         protected $encrypted;
  743.         
  744.         /**
  745.          * U entry in pdf document
  746.          * @access protected
  747.          * @since 2.0.000 (2008-01-02)
  748.          */
  749.         protected $Uvalue;
  750.         
  751.         /**
  752.          * O entry in pdf document
  753.          * @access protected
  754.          * @since 2.0.000 (2008-01-02)
  755.          */
  756.         protected $Ovalue;
  757.         
  758.         /**
  759.          * P entry in pdf document
  760.          * @access protected
  761.          * @since 2.0.000 (2008-01-02)
  762.          */
  763.         protected $Pvalue;
  764.         
  765.         /**
  766.          * encryption object id
  767.          * @access protected
  768.          * @since 2.0.000 (2008-01-02)
  769.          */
  770.         protected $enc_obj_id;
  771.         
  772.         /**
  773.          * last RC4 key encrypted (cached for optimisation)
  774.          * @access protected
  775.          * @since 2.0.000 (2008-01-02)
  776.          */
  777.         protected $last_rc4_key;
  778.         
  779.         /**
  780.          * last RC4 computed key
  781.          * @access protected
  782.          * @since 2.0.000 (2008-01-02)
  783.          */
  784.         protected $last_rc4_key_c;
  785.         
  786.         /**
  787.          * RC4 padding
  788.          * @access protected
  789.          */
  790.         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";
  791.         
  792.         /**
  793.          * RC4 encryption key
  794.          * @access protected
  795.          */
  796.         protected $encryption_key;
  797.         
  798.         // --- bookmark ---
  799.         
  800.         /**
  801.          * Outlines for bookmark
  802.          * @access protected
  803.          * @since 2.1.002 (2008-02-12)
  804.          */
  805.         protected $outlines = array();
  806.         
  807.         /**
  808.          * Outline root for bookmark
  809.          * @access protected
  810.          * @since 2.1.002 (2008-02-12)
  811.          */
  812.         protected $OutlineRoot;
  813.         
  814.         
  815.         // --- javascript and form ---
  816.         
  817.         /**
  818.          * javascript code
  819.          * @access protected
  820.          * @since 2.1.002 (2008-02-12)
  821.          */
  822.         protected $javascript = '';
  823.         
  824.         /**
  825.          * javascript counter
  826.          * @access protected
  827.          * @since 2.1.002 (2008-02-12)
  828.          */
  829.         protected $n_js;
  830.  
  831.         /**
  832.          * line trough state
  833.          * @access protected
  834.          * @since 2.8.000 (2008-03-19)
  835.          */
  836.         protected $linethrough;
  837.  
  838.         // --- Variables used for User's Rights ---
  839.         // See PDF reference chapter 8.7 Digital Signatures
  840.  
  841.         /**
  842.          * If true enables user's rights on PDF reader
  843.          * @access protected
  844.          * @since 2.9.000 (2008-03-26)
  845.          */
  846.         protected $ur;
  847.  
  848.         /**
  849.          * Names specifying additional document-wide usage rights for the document.
  850.          * @access protected
  851.          * @since 2.9.000 (2008-03-26)
  852.          */
  853.         protected $ur_document;
  854.  
  855.         /**
  856.          * Names specifying additional annotation-related usage rights for the document.
  857.          * @access protected
  858.          * @since 2.9.000 (2008-03-26)
  859.          */
  860.         protected $ur_annots;
  861.  
  862.         /**
  863.          * Names specifying additional form-field-related usage rights for the document.
  864.          * @access protected
  865.          * @since 2.9.000 (2008-03-26)
  866.          */
  867.         protected $ur_form;
  868.  
  869.         /**
  870.          * Names specifying additional signature-related usage rights for the document.
  871.          * @access protected
  872.          * @since 2.9.000 (2008-03-26)
  873.          */
  874.         protected $ur_signature;
  875.  
  876.         /**
  877.          * Dot Per Inch Document Resolution (do not change)
  878.          * @access protected
  879.          * @since 3.0.000 (2008-03-27)
  880.          */
  881.         protected $dpi = 72;
  882.         
  883.         /**
  884.          * Array of page numbers were a new page group was started
  885.          * @access protected
  886.          * @since 3.0.000 (2008-03-27)
  887.          */
  888.         protected $newpagegroup = array();
  889.         
  890.         /**
  891.          * Contains the number of pages of the groups
  892.          * @access protected
  893.          * @since 3.0.000 (2008-03-27)
  894.          */
  895.         protected $pagegroups;
  896.         
  897.         /**
  898.          * Contains the alias of the current page group
  899.          * @access protected
  900.          * @since 3.0.000 (2008-03-27)
  901.          */
  902.         protected $currpagegroup
  903.         
  904.         /**
  905.          * Restrict the rendering of some elements to screen or printout.
  906.          * @access protected
  907.          * @since 3.0.000 (2008-03-27)
  908.          */
  909.         protected $visibility = 'all';
  910.         
  911.         /**
  912.          * Print visibility.
  913.          * @access protected
  914.          * @since 3.0.000 (2008-03-27)
  915.          */
  916.         protected $n_ocg_print;
  917.         
  918.         /**
  919.          * View visibility.
  920.          * @access protected
  921.          * @since 3.0.000 (2008-03-27)
  922.          */
  923.         protected $n_ocg_view;
  924.         
  925.         /**
  926.          * Array of transparency objects and parameters.
  927.          * @access protected
  928.          * @since 3.0.000 (2008-03-27)
  929.          */
  930.         protected $extgstates;
  931.         
  932.         /**
  933.          * Set the default JPEG compression quality (1-100)
  934.          * @access protected
  935.          * @since 3.0.000 (2008-03-27)
  936.          */
  937.         protected $jpeg_quality;
  938.         
  939.         /**
  940.          * Default cell height ratio.
  941.          * @access protected
  942.          * @since 3.0.014 (2008-05-23)
  943.          */
  944.         protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  945.         
  946.         /**
  947.          * PDF viewer preferences.
  948.          * @access protected
  949.          * @since 3.1.000 (2008-06-09)
  950.          */
  951.         protected $viewer_preferences;
  952.         
  953.         /**
  954.          * A name object specifying how the document should be displayed when opened.
  955.          * @access protected
  956.          * @since 3.1.000 (2008-06-09)
  957.          */
  958.         protected $PageMode;
  959.         
  960.         /**
  961.          * Array for storing gradient information.
  962.          * @access protected
  963.          * @since 3.1.000 (2008-06-09)
  964.          */
  965.         protected $gradients = array();
  966.         
  967.         /**
  968.          * Array used to store positions inside the pages buffer.
  969.          * keys are the page numbers
  970.          * @access protected
  971.          * @since 3.2.000 (2008-06-26)
  972.          */
  973.         protected $intmrk = array();
  974.         
  975.         /**
  976.          * Array used to store footer positions of each page.
  977.          * @access protected
  978.          * @since 3.2.000 (2008-07-01)
  979.          */
  980.         protected $footerpos = array();
  981.         
  982.         
  983.         /**
  984.          * Array used to store footer lenght of each page.
  985.          * @access protected
  986.          * @since 4.0.014 (2008-07-29)
  987.          */
  988.         protected $footerlen = array();
  989.         
  990.         /**
  991.          * True if a newline is created.
  992.          * @access protected
  993.          * @since 3.2.000 (2008-07-01)
  994.          */
  995.         protected $newline = true;
  996.         
  997.         /**
  998.          * End position of the latest inserted line
  999.          * @access protected
  1000.          * @since 3.2.000 (2008-07-01)
  1001.          */
  1002.         protected $endlinex = 0;
  1003.         
  1004.         /**
  1005.          * PDF string for last line width
  1006.          * @access protected
  1007.          * @since 4.0.006 (2008-07-16)
  1008.          */
  1009.         protected $linestyleWidth = '';
  1010.         
  1011.         /**
  1012.          * PDF string for last line width
  1013.          * @access protected
  1014.          * @since 4.0.006 (2008-07-16)
  1015.          */
  1016.         protected $linestyleCap = '0 J';
  1017.         
  1018.         /**
  1019.          * PDF string for last line width
  1020.          * @access protected
  1021.          * @since 4.0.006 (2008-07-16)
  1022.          */
  1023.         protected $linestyleJoin = '0 j';
  1024.         
  1025.         /**
  1026.          * PDF string for last line width
  1027.          * @access protected
  1028.          * @since 4.0.006 (2008-07-16)
  1029.          */
  1030.         protected $linestyleDash = '[] 0 d';
  1031.         
  1032.         /**
  1033.          * True if marked-content sequence is open
  1034.          * @access protected
  1035.          * @since 4.0.013 (2008-07-28)
  1036.          */
  1037.         protected $openMarkedContent = false;
  1038.         
  1039.         /**
  1040.          * Count the latest inserted vertical spaces on HTML
  1041.          * @access protected
  1042.          * @since 4.0.021 (2008-08-24)
  1043.          */
  1044.         protected $htmlvspace = 0;
  1045.         
  1046.         /**
  1047.          * Array of Spot colors
  1048.          * @access protected
  1049.          * @since 4.0.024 (2008-09-12)
  1050.          */
  1051.         protected $spot_colors = array();
  1052.         
  1053.         /**
  1054.          * Symbol used for HTML unordered list items
  1055.          * @access protected
  1056.          * @since 4.0.028 (2008-09-26)
  1057.          */
  1058.         protected $lisymbol = '';
  1059.         
  1060.         /**
  1061.          * String used to mark the beginning and end of EPS image blocks
  1062.          * @access protected
  1063.          * @since 4.1.000 (2008-10-18)
  1064.          */
  1065.         protected $epsmarker = 'x#!#EPS#!#x';
  1066.         
  1067.         /**
  1068.          * Array of transformation matrix
  1069.          * @access protected
  1070.          * @since 4.2.000 (2008-10-29)
  1071.          */
  1072.         protected $transfmatrix = array();
  1073.         
  1074.         /**
  1075.          * Booklet mode for double-sided pages
  1076.          * @access protected
  1077.          * @since 4.2.000 (2008-10-29)
  1078.          */
  1079.         protected $booklet = false;
  1080.         
  1081.         /**
  1082.          * Epsilon value used for float calculations
  1083.          * @access protected
  1084.          * @since 4.2.000 (2008-10-29)
  1085.          */
  1086.         protected $feps = 0.001;
  1087.         
  1088.         /**
  1089.          * Array used for custom vertical spaces for HTML tags
  1090.          * @access protected
  1091.          * @since 4.2.001 (2008-10-30)
  1092.          */
  1093.         protected $tagvspaces = array();
  1094.         
  1095.         /**
  1096.          * @var HTML PARSER: custom indent amount for lists.
  1097.          *  Negative value means disabled.
  1098.          * @access protected
  1099.          * @since 4.2.007 (2008-11-12)
  1100.          */
  1101.         protected $customlistindent = -1;
  1102.         
  1103.         /**
  1104.          * @var if true keeps the border open for the cell sides that cross the page.
  1105.          * @access protected
  1106.          * @since 4.2.010 (2008-11-14)
  1107.          */
  1108.         protected $opencell = true;
  1109.  
  1110.         /**
  1111.          * @var array of files to embedd
  1112.          * @access protected
  1113.          * @since 4.4.000 (2008-12-07)
  1114.          */
  1115.         protected $embeddedfiles = array();
  1116.  
  1117.         /**
  1118.          * @var boolean true when inside html pre tag
  1119.          * @access protected
  1120.          * @since 4.4.001 (2008-12-08)
  1121.          */
  1122.         protected $premode = false;
  1123.  
  1124.         /**
  1125.          * Array used to store positions of graphics transformation blocks inside the page buffer.
  1126.          * keys are the page numbers
  1127.          * @access protected
  1128.          * @since 4.4.002 (2008-12-09)
  1129.          */
  1130.         protected $transfmrk = array();
  1131.  
  1132.         /**
  1133.          * Default color for html links
  1134.          * @access protected
  1135.          * @since 4.4.003 (2008-12-09)
  1136.          */
  1137.         protected $htmlLinkColorArray = array(00255);
  1138.  
  1139.         /**
  1140.          * Default font style to add to html links
  1141.          * @access protected
  1142.          * @since 4.4.003 (2008-12-09)
  1143.          */
  1144.         protected $htmlLinkFontStyle = 'U';
  1145.  
  1146.         /**
  1147.          * Counts the number of pages.
  1148.          * @access protected
  1149.          * @since 4.5.000 (2008-12-31)
  1150.          */
  1151.         protected $numpages = 0;
  1152.  
  1153.         /**
  1154.          * Array containing page lenghts in bytes.
  1155.          * @access protected
  1156.          * @since 4.5.000 (2008-12-31)
  1157.          */
  1158.         protected $pagelen = array();
  1159.  
  1160.         /**
  1161.          * Counts the number of pages.
  1162.          * @access protected
  1163.          * @since 4.5.000 (2008-12-31)
  1164.          */
  1165.         protected $numimages = 0;
  1166.  
  1167.         /**
  1168.          * Store the image keys.
  1169.          * @access protected
  1170.          * @since 4.5.000 (2008-12-31)
  1171.          */
  1172.         protected $imagekeys = array();
  1173.  
  1174.         /**
  1175.          * Lenght of the buffer in bytes.
  1176.          * @access protected
  1177.          * @since 4.5.000 (2008-12-31)
  1178.          */
  1179.         protected $bufferlen = 0;
  1180.  
  1181.         /**
  1182.          * If true enables disk caching.
  1183.          * @access protected
  1184.          * @since 4.5.000 (2008-12-31)
  1185.          */
  1186.         protected $diskcache = false;
  1187.  
  1188.         /**
  1189.          * Counts the number of fonts.
  1190.          * @access protected
  1191.          * @since 4.5.000 (2009-01-02)
  1192.          */
  1193.         protected $numfonts = 0;
  1194.  
  1195.         /**
  1196.          * Store the font keys.
  1197.          * @access protected
  1198.          * @since 4.5.000 (2009-01-02)
  1199.          */
  1200.         protected $fontkeys = array();
  1201.  
  1202.         /**
  1203.          * Store the fage status (true when opened, false when closed).
  1204.          * @access protected
  1205.          * @since 4.5.000 (2009-01-02)
  1206.          */
  1207.         protected $pageopen = array();
  1208.         
  1209.         /**
  1210.          * Default monospaced font
  1211.          * @access protected
  1212.          * @since 4.5.025 (2009-03-10)
  1213.          */
  1214.         protected $default_monospaced_font = 'courier';
  1215.  
  1216.         /**
  1217.          * Used to store a cloned copy of the current class object
  1218.          * @access protected
  1219.          * @since 4.5.029 (2009-03-19)
  1220.          */
  1221.         protected $objcopy;
  1222.  
  1223.         /**
  1224.          * Array used to store the lenghts of cache files
  1225.          * @access protected
  1226.          * @since 4.5.029 (2009-03-19)
  1227.          */
  1228.         protected $cache_file_lenght = array();
  1229.  
  1230.         /**
  1231.          * Table header content to be repeated on each new page
  1232.          * @access protected
  1233.          * @since 4.5.030 (2009-03-20)
  1234.          */
  1235.         protected $thead = '';
  1236.  
  1237.         /**
  1238.          * Distance between the top of page and end of table headers on a new page.
  1239.          * @access protected
  1240.          * @since 4.5.030 (2009-03-20)
  1241.          */
  1242.         protected $theadMargin = '';
  1243.  
  1244.         /**
  1245.          * Cache array for UTF8StringToArray() method.
  1246.          * @access protected
  1247.          * @since 4.5.037 (2009-04-07)
  1248.          */
  1249.         protected $cache_UTF8StringToArray = array();
  1250.  
  1251.         /**
  1252.          * Maximum size of cache array used for UTF8StringToArray() method.
  1253.          * @access protected
  1254.          * @since 4.5.037 (2009-04-07)
  1255.          */
  1256.         protected $cache_maxsize_UTF8StringToArray = 8;
  1257.  
  1258.         /**
  1259.          * Current size of cache array used for UTF8StringToArray() method.
  1260.          * @access protected
  1261.          * @since 4.5.037 (2009-04-07)
  1262.          */
  1263.         protected $cache_size_UTF8StringToArray = 0;
  1264.         
  1265.         
  1266.         //------------------------------------------------------------
  1267.         // METHODS
  1268.         //------------------------------------------------------------
  1269.  
  1270.         /**
  1271.          * This is the class constructor.
  1272.          * It allows to set up the page format, the orientation and
  1273.          * the measure unit used in all the methods (except for the font sizes).
  1274.          * @since 1.0
  1275.          * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1276.          * @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.
  1277.          * @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>
  1278.          * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1279.          * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1280.          * @param String $encoding charset encoding; default is UTF-8
  1281.          * @access public
  1282.          */
  1283.         public function __construct($orientation='P'$unit='mm'$format='A4'$unicode=true$encoding='UTF-8'$diskcache=false{
  1284.             /* Set internal character encoding to ASCII */
  1285.             if (function_exists('mb_internal_encoding'AND mb_internal_encoding()) {
  1286.                 $this->internal_encoding = mb_internal_encoding();
  1287.                 mb_internal_encoding('ASCII');
  1288.             }
  1289.             // set disk caching
  1290.             $this->diskcache = $diskcache true false;
  1291.             // set language direction
  1292.             $this->rtl = $this->l['a_meta_dir']=='rtl' true false;
  1293.             $this->tmprtl = false;
  1294.             //Some checks
  1295.             $this->_dochecks();
  1296.             //Initialization of properties
  1297.             $this->isunicode = $unicode;
  1298.             $this->page = 0;
  1299.             $this->transfmrk[0array();
  1300.             $this->pagedim = array();
  1301.             $this->n = 2;
  1302.             $this->buffer = '';
  1303.             $this->pages = array();
  1304.             $this->state = 0;
  1305.             $this->fonts = array();
  1306.             $this->FontFiles = array();
  1307.             $this->diffs = array();
  1308.             $this->images = array();
  1309.             $this->links = array();
  1310.             $this->gradients = array();
  1311.             $this->InFooter = false;
  1312.             $this->lasth = 0;
  1313.             $this->FontFamily = 'helvetica';
  1314.             $this->FontStyle = '';
  1315.             $this->FontSizePt = 12;
  1316.             $this->underline = false;
  1317.             $this->linethrough = false;
  1318.             $this->DrawColor = '0 G';
  1319.             $this->FillColor = '0 g';
  1320.             $this->TextColor = '0 g';
  1321.             $this->ColorFlag = false;
  1322.             // encryption values
  1323.             $this->encrypted = false;
  1324.             $this->last_rc4_key = '';
  1325.             $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";
  1326.             //Standard Unicode fonts
  1327.             $this->CoreFonts = array(
  1328.                 'courier'=>'Courier',
  1329.                 'courierB'=>'Courier-Bold',
  1330.                 'courierI'=>'Courier-Oblique',
  1331.                 'courierBI'=>'Courier-BoldOblique',
  1332.                 'helvetica'=>'Helvetica',
  1333.                 'helveticaB'=>'Helvetica-Bold',
  1334.                 'helveticaI'=>'Helvetica-Oblique',
  1335.                 'helveticaBI'=>'Helvetica-BoldOblique',
  1336.                 'times'=>'Times-Roman',
  1337.                 'timesB'=>'Times-Bold',
  1338.                 'timesI'=>'Times-Italic',
  1339.                 'timesBI'=>'Times-BoldItalic',
  1340.                 'symbol'=>'Symbol',
  1341.                 'zapfdingbats'=>'ZapfDingbats'
  1342.             );
  1343.             //Set scale factor
  1344.             $this->setPageUnit($unit);
  1345.             // set page format and orientation
  1346.             $this->setPageFormat($format$orientation);
  1347.             //Page margins (1 cm)
  1348.             $margin 28.35 $this->k;
  1349.             $this->SetMargins($margin$margin);
  1350.             //Interior cell margin
  1351.             $this->cMargin = $margin 10;
  1352.             //Line width (0.2 mm)
  1353.             $this->LineWidth = 0.57 $this->k;
  1354.             $this->linestyleWidth = sprintf('%.2F w'($this->LineWidth * $this->k));
  1355.             $this->linestyleCap = '0 J';
  1356.             $this->linestyleJoin = '0 j';
  1357.             $this->linestyleDash = '[] 0 d';
  1358.             //Automatic page break
  1359.             $this->SetAutoPageBreak(true($margin));
  1360.             //Full width display mode
  1361.             $this->SetDisplayMode('fullwidth');
  1362.             //Compression
  1363.             $this->SetCompression(true);
  1364.             //Set default PDF version number
  1365.             $this->PDFVersion = '1.7';
  1366.             $this->encoding = $encoding;
  1367.             $this->HREF = array();
  1368.             $this->getFontsList();
  1369.             $this->fgcolor = array('R' => 0'G' => 0'B' => 0);
  1370.             $this->bgcolor = array('R' => 255'G' => 255'B' => 255);
  1371.             $this->extgstates = array();
  1372.             // user's rights
  1373.             $this->ur = false;
  1374.             $this->ur_document = '/FullSave';
  1375.             $this->ur_annots = '/Create/Delete/Modify/Copy/Import/Export';
  1376.             $this->ur_form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1377.             $this->ur_signature = '/Modify';            
  1378.             // set default JPEG quality
  1379.             $this->jpeg_quality = 75;
  1380.             // initialize some settings
  1381.             $this->utf8Bidi(array('')'');
  1382.             // set default font
  1383.             $this->SetFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  1384.         }
  1385.         
  1386.         /**
  1387.          * Default destructor.
  1388.          * @access public
  1389.          * @since 1.53.0.TC016
  1390.          */
  1391.         public function __destruct({
  1392.             // restore internal encoding
  1393.             if (isset($this->internal_encodingAND !empty($this->internal_encoding)) {
  1394.                 mb_internal_encoding($this->internal_encoding);
  1395.             }
  1396.             // unset all class variables
  1397.             $this->_destroy(true);
  1398.         }
  1399.         
  1400.         /**
  1401.          * Set the units of measure for the document.
  1402.          * @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.
  1403.          * @access public
  1404.          * @since 3.0.015 (2008-06-06)
  1405.          */
  1406.         public function setPageUnit($unit{
  1407.         //Set scale factor
  1408.             switch (strtolower($unit)) {
  1409.                 // points
  1410.                 case 'px':
  1411.                 case 'pt'{
  1412.                     $this->k = 1;
  1413.                     break;
  1414.                 }
  1415.                 // millimeters
  1416.                 case 'mm'{
  1417.                     $this->k = $this->dpi / 25.4;
  1418.                     break;
  1419.                 }
  1420.                 // centimeters
  1421.                 case 'cm'{
  1422.                     $this->k = $this->dpi / 2.54;
  1423.                     break;
  1424.                 }
  1425.                 // inches
  1426.                 case 'in'{
  1427.                     $this->k = $this->dpi;
  1428.                     break;
  1429.                 }
  1430.                 // unsupported unit
  1431.                 default {
  1432.                     $this->Error('Incorrect unit: '.$unit);
  1433.                     break;
  1434.                 }
  1435.             }
  1436.             if (isset($this->CurOrientation)) {
  1437.                     $this->setPageOrientation($this->CurOrientation);
  1438.             }
  1439.         }
  1440.         
  1441.         /**
  1442.         * Set the page format
  1443.         * @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>
  1444.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1445.         * @access public
  1446.         * @since 3.0.015 (2008-06-06)
  1447.         */
  1448.         public function setPageFormat($format$orientation='P'{
  1449.             //Page format
  1450.             if (is_string($format)) {
  1451.                 // Page formats (45 standard ISO paper formats and 4 american common formats).
  1452.                 // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  1453.                 switch (strtoupper($format)) {
  1454.                     case '4A0'{$format array(4767.87,6740.79)break;}
  1455.                     case '2A0'{$format array(3370.39,4767.87)break;}
  1456.                     case 'A0'{$format array(2383.94,3370.39)break;}
  1457.                     case 'A1'{$format array(1683.78,2383.94)break;}
  1458.                     case 'A2'{$format array(1190.55,1683.78)break;}
  1459.                     case 'A3'{$format array(841.89,1190.55)break;}
  1460.                     case 'A4'default{$format array(595.28,841.89)break;}
  1461.                     case 'A5'{$format array(419.53,595.28)break;}
  1462.                     case 'A6'{$format array(297.64,419.53)break;}
  1463.                     case 'A7'{$format array(209.76,297.64)break;}
  1464.                     case 'A8'{$format array(147.40,209.76)break;}
  1465.                     case 'A9'{$format array(104.88,147.40)break;}
  1466.                     case 'A10'{$format array(73.70,104.88)break;}
  1467.                     case 'B0'{$format array(2834.65,4008.19)break;}
  1468.                     case 'B1'{$format array(2004.09,2834.65)break;}
  1469.                     case 'B2'{$format array(1417.32,2004.09)break;}
  1470.                     case 'B3'{$format array(1000.63,1417.32)break;}
  1471.                     case 'B4'{$format array(708.66,1000.63)break;}
  1472.                     case 'B5'{$format array(498.90,708.66)break;}
  1473.                     case 'B6'{$format array(354.33,498.90)break;}
  1474.                     case 'B7'{$format array(249.45,354.33)break;}
  1475.                     case 'B8'{$format array(175.75,249.45)break;}
  1476.                     case 'B9'{$format array(124.72,175.75)break;}
  1477.                     case 'B10'{$format array(87.87,124.72)break;}
  1478.                     case 'C0'{$format array(2599.37,3676.54)break;}
  1479.                     case 'C1'{$format array(1836.85,2599.37)break;}
  1480.                     case 'C2'{$format array(1298.27,1836.85)break;}
  1481.                     case 'C3'{$format array(918.43,1298.27)break;}
  1482.                     case 'C4'{$format array(649.13,918.43)break;}
  1483.                     case 'C5'{$format array(459.21,649.13)break;}
  1484.                     case 'C6'{$format array(323.15,459.21)break;}
  1485.                     case 'C7'{$format array(229.61,323.15)break;}
  1486.                     case 'C8'{$format array(161.57,229.61)break;}
  1487.                     case 'C9'{$format array(113.39,161.57)break;}
  1488.                     case 'C10'{$format array(79.37,113.39)break;}
  1489.                     case 'RA0'{$format array(2437.80,3458.27)break;}
  1490.                     case 'RA1'{$format array(1729.13,2437.80)break;}
  1491.                     case 'RA2'{$format array(1218.90,1729.13)break;}
  1492.                     case 'RA3'{$format array(864.57,1218.90)break;}
  1493.                     case 'RA4'{$format array(609.45,864.57)break;}
  1494.                     case 'SRA0'{$format array(2551.18,3628.35)break;}
  1495.                     case 'SRA1'{$format array(1814.17,2551.18)break;}
  1496.                     case 'SRA2'{$format array(1275.59,1814.17)break;}
  1497.                     case 'SRA3'{$format array(907.09,1275.59)break;}
  1498.                     case 'SRA4'{$format array(637.80,907.09)break;}
  1499.                     case 'LETTER'{$format array(612.00,792.00)break;}
  1500.                     case 'LEGAL'{$format array(612.00,1008.00)break;}
  1501.                     case 'EXECUTIVE'{$format array(521.86,756.00)break;}
  1502.                     case 'FOLIO'{$format array(612.00,936.00)break;}
  1503.                 }
  1504.                 $this->fwPt = $format[0];
  1505.                 $this->fhPt = $format[1];
  1506.             else {
  1507.                 $this->fwPt = $format[0$this->k;
  1508.                 $this->fhPt = $format[1$this->k;
  1509.             }
  1510.             $this->setPageOrientation($orientation);
  1511.         }
  1512.         
  1513.         /**
  1514.         * Set page orientation.
  1515.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1516.         * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1517.         * @param float $bottommargin bottom margin of the page.
  1518.         * @access public
  1519.         * @since 3.0.015 (2008-06-06)
  1520.         */
  1521.         public function setPageOrientation($orientation$autopagebreak=''$bottommargin=''{
  1522.             $orientation strtoupper($orientation);
  1523.             if (($orientation == 'P'OR ($orientation == 'PORTRAIT')) {
  1524.                 $this->CurOrientation = 'P';
  1525.                 $this->wPt = $this->fwPt;
  1526.                 $this->hPt = $this->fhPt;
  1527.             elseif (($orientation == 'L'OR ($orientation == 'LANDSCAPE')) {
  1528.                 $this->CurOrientation = 'L';
  1529.                 $this->wPt = $this->fhPt;
  1530.                 $this->hPt = $this->fwPt;
  1531.             else {
  1532.                 $this->Error('Incorrect orientation: '.$orientation);
  1533.             }
  1534.             $this->w = $this->wPt / $this->k;
  1535.             $this->h = $this->hPt / $this->k;
  1536.             if ($this->empty_string($autopagebreak)) {
  1537.                 if (isset($this->AutoPageBreak)) {
  1538.                     $autopagebreak $this->AutoPageBreak;
  1539.                 else {
  1540.                     $autopagebreak true;
  1541.                 }
  1542.             }
  1543.             if ($this->empty_string($bottommargin)) {
  1544.                 if (isset($this->bMargin)) {
  1545.                     $bottommargin $this->bMargin;
  1546.                 else {
  1547.                     // default value = 2 cm
  1548.                     $bottommargin 28.35 $this->k;
  1549.                 }
  1550.             }
  1551.             $this->SetAutoPageBreak($autopagebreak$bottommargin);
  1552.             // store page dimensions
  1553.             $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);
  1554.         }
  1555.                 
  1556.         /**
  1557.          * Enable or disable Right-To-Left language mode
  1558.          * @param Boolean $enable if true enable Right-To-Left language mode.
  1559.          * @access public
  1560.         * @since 2.0.000 (2008-01-03)
  1561.          */
  1562.         public function setRTL($enable{
  1563.             $this->rtl = $enable true false;
  1564.             $this->tmprtl = false;
  1565.         }
  1566.         
  1567.         /**
  1568.          * Return the RTL status
  1569.          * @return boolean 
  1570.          * @access public
  1571.          * @since 4.0.012 (2008-07-24)
  1572.          */
  1573.         public function getRTL({
  1574.             return $this->rtl;
  1575.         }
  1576.         
  1577.         /**
  1578.         * Force temporary RTL language direction
  1579.         * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  1580.         * @access public
  1581.         * @since 2.1.000 (2008-01-09)
  1582.         */
  1583.         public function setTempRTL($mode{
  1584.             switch ($mode{
  1585.                 case false:
  1586.                 case 'L':
  1587.                 case 'R'{
  1588.                     $this->tmprtl = $mode;
  1589.                 }
  1590.             }
  1591.         }
  1592.         
  1593.         /**
  1594.         * Set the last cell height.
  1595.         * @param float $h cell height.
  1596.         * @author Nicola Asuni
  1597.         * @access public
  1598.         * @since 1.53.0.TC034
  1599.         */
  1600.         public function setLastH($h{
  1601.             $this->lasth = $h;
  1602.         }
  1603.         
  1604.         /**
  1605.         * Get the last cell height.
  1606.         * @return last cell height
  1607.         * @access public
  1608.         * @since 4.0.017 (2008-08-05)
  1609.         */
  1610.         public function getLastH({
  1611.             return $this->lasth;
  1612.         }
  1613.         
  1614.         /**
  1615.         * Set the image scale.
  1616.         * @param float $scale image scale.
  1617.         * @author Nicola Asuni
  1618.         * @access public
  1619.         * @since 1.5.2
  1620.         */
  1621.         public function setImageScale($scale{
  1622.             $this->imgscale = $scale;
  1623.         }
  1624.  
  1625.         /**
  1626.         * Returns the image scale.
  1627.         * @return float image scale.
  1628.         * @author Nicola Asuni
  1629.         * @access public
  1630.         * @since 1.5.2
  1631.         */
  1632.         public function getImageScale({
  1633.             return $this->imgscale;
  1634.         }
  1635.                 
  1636.         /**
  1637.         * Returns an array of page dimensions:
  1638.         * <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>
  1639.         * @param int $pagenum page number (empty = current page)
  1640.         * @return array of page dimensions.
  1641.         * @author Nicola Asuni
  1642.         * @access public
  1643.         * @since 4.5.027 (2009-03-16)
  1644.         */
  1645.         public function getPageDimensions($pagenum=''{
  1646.             if (empty($pagenum)) {
  1647.                 $pagenum $this->page;
  1648.             }
  1649.             return $this->pagedim[$pagenum];
  1650.         }
  1651.         
  1652.         /**
  1653.         * Returns the page width in units.
  1654.         * @param int $pagenum page number (empty = current page)
  1655.         * @return int page width.
  1656.         * @author Nicola Asuni
  1657.         * @access public
  1658.         * @since 1.5.2
  1659.         * @see getPageDimensions()
  1660.         */
  1661.         public function getPageWidth($pagenum=''{
  1662.             if (empty($pagenum)) {
  1663.                 return $this->w;
  1664.             }
  1665.             return $this->pagedim[$pagenum]['w'];
  1666.         }
  1667.  
  1668.         /**
  1669.         * Returns the page height in units.
  1670.         * @param int $pagenum page number (empty = current page)
  1671.         * @return int page height.
  1672.         * @author Nicola Asuni
  1673.         * @access public
  1674.         * @since 1.5.2
  1675.         * @see getPageDimensions()
  1676.         */
  1677.         public function getPageHeight($pagenum=''{
  1678.             if (empty($pagenum)) {
  1679.                 return $this->h;
  1680.             }
  1681.             return $this->pagedim[$pagenum]['h'];
  1682.         }
  1683.  
  1684.         /**
  1685.         * Returns the page break margin.
  1686.         * @param int $pagenum page number (empty = current page)
  1687.         * @return int page break margin.
  1688.         * @author Nicola Asuni
  1689.         * @access public
  1690.         * @since 1.5.2
  1691.         * @see getPageDimensions()
  1692.         */
  1693.         public function getBreakMargin($pagenum=''{
  1694.             if (empty($pagenum)) {
  1695.                 return $this->bMargin;
  1696.             }
  1697.             return $this->pagedim[$pagenum]['bm'];
  1698.         }
  1699.  
  1700.         /**
  1701.         * Returns the scale factor (number of points in user unit).
  1702.         * @return int scale factor.
  1703.         * @author Nicola Asuni
  1704.         * @access public
  1705.         * @since 1.5.2
  1706.         */
  1707.         public function getScaleFactor({
  1708.             return $this->k;
  1709.         }
  1710.  
  1711.         /**
  1712.         * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  1713.         * @param float $left Left margin.
  1714.         * @param float $top Top margin.
  1715.         * @param float $right Right margin. Default value is the left one.
  1716.         * @access public
  1717.         * @since 1.0
  1718.         * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  1719.         */
  1720.         public function SetMargins($left$top$right=-1{
  1721.             //Set left, top and right margins
  1722.             $this->lMargin = $left;
  1723.             $this->tMargin = $top;
  1724.             if ($right == -1{
  1725.                 $right $left;
  1726.             }
  1727.             $this->rMargin = $right;
  1728.         }
  1729.  
  1730.         /**
  1731.         * 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.
  1732.         * @param float $margin The margin.
  1733.         * @access public
  1734.         * @since 1.4
  1735.         * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1736.         */
  1737.         public function SetLeftMargin($margin{
  1738.             //Set left margin
  1739.             $this->lMargin=$margin;
  1740.             if (($this->page > 0AND ($this->x < $margin)) {
  1741.                 $this->x = $margin;
  1742.             }
  1743.         }
  1744.  
  1745.         /**
  1746.         * Defines the top margin. The method can be called before creating the first page.
  1747.         * @param float $margin The margin.
  1748.         * @access public
  1749.         * @since 1.5
  1750.         * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1751.         */
  1752.         public function SetTopMargin($margin{
  1753.             //Set top margin
  1754.             $this->tMargin=$margin;
  1755.             if (($this->page > 0AND ($this->y < $margin)) {
  1756.                 $this->y = $margin;
  1757.             }
  1758.         }
  1759.  
  1760.         /**
  1761.         * Defines the right margin. The method can be called before creating the first page.
  1762.         * @param float $margin The margin.
  1763.         * @access public
  1764.         * @since 1.5
  1765.         * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1766.         */
  1767.         public function SetRightMargin($margin{
  1768.             $this->rMargin=$margin;
  1769.             if (($this->page > 0AND ($this->x > ($this->w - $margin))) {
  1770.                 $this->x = $this->w - $margin;
  1771.             }
  1772.         }
  1773.  
  1774.         /**
  1775.         * Set the internal Cell padding.
  1776.         * @param float $pad internal padding.
  1777.         * @access public
  1778.         * @since 2.1.000 (2008-01-09)
  1779.         * @see Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1780.         */
  1781.         public function SetCellPadding($pad{
  1782.             $this->cMargin = $pad;
  1783.         }
  1784.  
  1785.         /**
  1786.         * 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.
  1787.         * @param boolean $auto Boolean indicating if mode should be on or off.
  1788.         * @param float $margin Distance from the bottom of the page.
  1789.         * @access public
  1790.         * @since 1.0
  1791.         * @see Cell(), MultiCell(), AcceptPageBreak()
  1792.         */
  1793.         public function SetAutoPageBreak($auto$margin=0{
  1794.             //Set auto page break mode and triggering margin
  1795.             $this->AutoPageBreak = $auto;
  1796.             $this->bMargin = $margin;
  1797.             $this->PageBreakTrigger = $this->h - $margin;
  1798.         }
  1799.  
  1800.         /**
  1801.         * Defines the way the document is to be displayed by the viewer.
  1802.         * @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>
  1803.         * @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>
  1804.         * @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>
  1805.         * @access public
  1806.         * @since 1.2
  1807.         */
  1808.         public function SetDisplayMode($zoom$layout='SinglePage'$mode='UseNone'{
  1809.             //Set display mode in viewer
  1810.             if (($zoom == 'fullpage'OR ($zoom == 'fullwidth'OR ($zoom == 'real'OR ($zoom == 'default'OR (!is_string($zoom))) {
  1811.                 $this->ZoomMode = $zoom;
  1812.             else {
  1813.                 $this->Error('Incorrect zoom display mode: '.$zoom);
  1814.             }
  1815.             switch ($layout{
  1816.                 case 'default':
  1817.                 case 'single':
  1818.                 case 'SinglePage'{
  1819.                     $this->LayoutMode = 'SinglePage';
  1820.                     break;
  1821.                 }
  1822.                 case 'continuous':
  1823.                 case 'OneColumn'{
  1824.                     $this->LayoutMode = 'OneColumn';
  1825.                     break;
  1826.                 }
  1827.                 case 'two':
  1828.                 case 'TwoColumnLeft'{
  1829.                     $this->LayoutMode = 'TwoColumnLeft';
  1830.                     break;
  1831.                 }
  1832.                 case 'TwoColumnRight'{
  1833.                     $this->LayoutMode = 'TwoColumnRight';
  1834.                     break;
  1835.                 }
  1836.                 case 'TwoPageLeft'{
  1837.                     $this->LayoutMode = 'TwoPageLeft';
  1838.                     break;
  1839.                 }
  1840.                 case 'TwoPageRight'{
  1841.                     $this->LayoutMode = 'TwoPageRight';
  1842.                     break;
  1843.                 }
  1844.                 default{
  1845.                     $this->LayoutMode = 'SinglePage';
  1846.                 }
  1847.             }
  1848.             switch ($mode{
  1849.                 case 'UseNone'{
  1850.                     $this->PageMode = 'UseNone';
  1851.                     break;
  1852.                 }
  1853.                 case 'UseOutlines'{
  1854.                     $this->PageMode = 'UseOutlines';
  1855.                     break;
  1856.                 }
  1857.                 case 'UseThumbs'{
  1858.                     $this->PageMode = 'UseThumbs';
  1859.                     break;
  1860.                 }
  1861.                 case 'FullScreen'{
  1862.                     $this->PageMode = 'FullScreen';
  1863.                     break;
  1864.                 }
  1865.                 case 'UseOC'{
  1866.                     $this->PageMode = 'UseOC';
  1867.                     break;
  1868.                 }
  1869.                 case ''{
  1870.                     $this->PageMode = 'UseAttachments';
  1871.                     break;
  1872.                 }
  1873.                 default{
  1874.                     $this->PageMode = 'UseNone';
  1875.                 }
  1876.             }
  1877.         }
  1878.  
  1879.         /**
  1880.         * 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.
  1881.         * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  1882.         * @param boolean $compress Boolean indicating if compression must be enabled.
  1883.         * @access public
  1884.         * @since 1.4
  1885.         */
  1886.         public function SetCompression($compress{
  1887.             //Set page compression
  1888.             if (function_exists('gzcompress')) {
  1889.                 $this->compress = $compress;
  1890.             else {
  1891.                 $this->compress = false;
  1892.             }
  1893.         }
  1894.  
  1895.         /**
  1896.         * Defines the title of the document.
  1897.         * @param string $title The title.
  1898.         * @access public
  1899.         * @since 1.2
  1900.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  1901.         */
  1902.         public function SetTitle($title{
  1903.             //Title of document
  1904.             $this->title = $title;
  1905.         }
  1906.  
  1907.         /**
  1908.         * Defines the subject of the document.
  1909.         * @param string $subject The subject.
  1910.         * @access public
  1911.         * @since 1.2
  1912.         * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  1913.         */
  1914.         public function SetSubject($subject{
  1915.             //Subject of document
  1916.             $this->subject = $subject;
  1917.         }
  1918.  
  1919.         /**
  1920.         * Defines the author of the document.
  1921.         * @param string $author The name of the author.
  1922.         * @access public
  1923.         * @since 1.2
  1924.         * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  1925.         */
  1926.         public function SetAuthor($author{
  1927.             //Author of document
  1928.             $this->author = $author;
  1929.         }
  1930.  
  1931.         /**
  1932.         * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  1933.         * @param string $keywords The list of keywords.
  1934.         * @access public
  1935.         * @since 1.2
  1936.         * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  1937.         */
  1938.         public function SetKeywords($keywords{
  1939.             //Keywords of document
  1940.             $this->keywords = $keywords;
  1941.         }
  1942.  
  1943.         /**
  1944.         * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  1945.         * @param string $creator The name of the creator.
  1946.         * @access public
  1947.         * @since 1.2
  1948.         * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  1949.         */
  1950.         public function SetCreator($creator{
  1951.             //Creator of document
  1952.             $this->creator = $creator;
  1953.         }
  1954.         
  1955.         /**
  1956.         * 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.
  1957.         * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  1958.         * @param string $msg The error message
  1959.         * @access public
  1960.         * @since 1.0
  1961.         */
  1962.         public function Error($msg{
  1963.             // unset all class variables
  1964.             $this->_destroy(true);
  1965.             // exit program and print error
  1966.             die('<strong>TCPDF ERROR: </strong>'.$msg);
  1967.         }
  1968.  
  1969.         /**
  1970.         * This method begins the generation of the PDF document.
  1971.         * It is not necessary to call it explicitly because AddPage() does it automatically.
  1972.         * Note: no page is created by this method
  1973.         * @access public
  1974.         * @since 1.0
  1975.         * @see AddPage(), Close()
  1976.         */
  1977.         public function Open({
  1978.             //Begin document
  1979.             $this->state = 1;
  1980.         }
  1981.  
  1982.         /**
  1983.         * Terminates the PDF document.
  1984.         * It is not necessary to call this method explicitly because Output() does it automatically.
  1985.         * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  1986.         * @access public
  1987.         * @since 1.0
  1988.         * @see Open(), Output()
  1989.         */
  1990.         public function Close({
  1991.             if ($this->state == 3{
  1992.                 return;
  1993.             }
  1994.             if ($this->page == 0{
  1995.                 $this->AddPage();
  1996.             }
  1997.             // close page
  1998.             $this->endPage();
  1999.             // close document
  2000.             $this->_enddoc();
  2001.             // unset all class variables (except critical ones)
  2002.             $this->_destroy(false);
  2003.         }
  2004.         
  2005.         /**
  2006.         * Move pointer at the specified document page and update page dimensions.
  2007.         * @param int $pnum page number
  2008.         * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2009.         * @access public
  2010.         * @since 2.1.000 (2008-01-07)
  2011.         * @see getPage(), lastpage(), getNumPages()
  2012.         */
  2013.         public function setPage($pnum$resetmargins=false{
  2014.             if ($pnum == $this->page{
  2015.                 return;
  2016.             }
  2017.             if (($pnum 0AND ($pnum <= $this->numpages)) {
  2018.                 $this->state = 2;
  2019.                 // save current graphic settings
  2020.                 //$gvars = $this->getGraphicVars();
  2021.                 $oldpage $this->page;
  2022.                 $this->page = $pnum;
  2023.                 $this->wPt = $this->pagedim[$this->page]['w'];
  2024.                 $this->hPt = $this->pagedim[$this->page]['h'];
  2025.                 $this->w = $this->wPt / $this->k;
  2026.                 $this->h = $this->hPt / $this->k;
  2027.                 $this->tMargin = $this->pagedim[$this->page]['tm'];
  2028.                 $this->bMargin = $this->pagedim[$this->page]['bm'];
  2029.                 $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2030.                 $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2031.                 $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2032.                 $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2033.                 $this->SetAutoPageBreak($this->AutoPageBreak$this->bMargin);
  2034.                 // restore graphic settings
  2035.                 //$this->setGraphicVars($gvars);
  2036.                 if ($resetmargins{
  2037.                     $this->lMargin = $this->pagedim[$this->page]['olm'];
  2038.                     $this->rMargin = $this->pagedim[$this->page]['orm'];
  2039.                     $this->SetY($this->tMargin);
  2040.                 else {
  2041.                     // account for booklet mode
  2042.                     if ($this->pagedim[$this->page]['olm'!= $this->pagedim[$oldpage]['olm']{
  2043.                         $deltam $this->pagedim[$this->page]['olm'$this->pagedim[$this->page]['orm'];
  2044.                         $this->lMargin += $deltam;
  2045.                         $this->rMargin -= $deltam;
  2046.                     }
  2047.                 }
  2048.             else {
  2049.                 $this->Error('Wrong page number on setPage() function.');
  2050.             }
  2051.         }
  2052.         
  2053.         /**
  2054.         * Reset pointer to the last document page.
  2055.         * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2056.         * @access public
  2057.         * @since 2.0.000 (2008-01-04)
  2058.         * @see setPage(), getPage(), getNumPages()
  2059.         */
  2060.         public function lastPage($resetmargins=false{
  2061.             $this->setPage($this->getNumPages()$resetmargins);
  2062.         }
  2063.         
  2064.         /**
  2065.         * Get current document page number.
  2066.         * @return int page number
  2067.         * @access public
  2068.         * @since 2.1.000 (2008-01-07)
  2069.         * @see setPage(), lastpage(), getNumPages()
  2070.         */
  2071.         public function getPage({
  2072.             return $this->page;
  2073.         }
  2074.         
  2075.         
  2076.         /**
  2077.         * Get the total number of insered pages.
  2078.         * @return int number of pages
  2079.         * @access public
  2080.         * @since 2.1.000 (2008-01-07)
  2081.         * @see setPage(), getPage(), lastpage()
  2082.         */
  2083.         public function getNumPages({
  2084.             return $this->numpages;
  2085.         }
  2086.  
  2087.         /**
  2088.         * 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).
  2089.         * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2090.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2091.         * @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>
  2092.         * @access public
  2093.         * @since 1.0
  2094.         * @see startPage(), endPage()
  2095.         */
  2096.         public function AddPage($orientation=''$format=''{
  2097.             if (!isset($this->original_lMargin)) {
  2098.                 $this->original_lMargin = $this->lMargin;
  2099.             }
  2100.             if (!isset($this->original_rMargin)) {
  2101.                 $this->original_rMargin = $this->rMargin;
  2102.             }
  2103.             // terminate previous page
  2104.             $this->endPage();
  2105.             // start new page
  2106.             $this->startPage($orientation$format);
  2107.         }
  2108.  
  2109.         /**
  2110.         * Terminate the current page
  2111.         * @access protected
  2112.         * @since 4.2.010 (2008-11-14)
  2113.         * @see startPage(), AddPage()
  2114.         */
  2115.         protected function endPage({
  2116.             // check if page is already closed
  2117.             if (($this->page == 0OR ($this->numpages > $this->pageOR (!$this->pageopen[$this->page])) {
  2118.                 return;
  2119.             }
  2120.             $this->InFooter = true;
  2121.             // print page footer
  2122.             $this->setFooter();
  2123.             // close page
  2124.             $this->_endpage();
  2125.             // mark page as closed
  2126.             $this->pageopen[$this->pagefalse;
  2127.             $this->InFooter = false;
  2128.         }
  2129.  
  2130.         /**
  2131.         * Starts a new page to the document. The page must be closed using the endPage() function.
  2132.         * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2133.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2134.         * @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>
  2135.         * @access protected
  2136.         * @since 4.2.010 (2008-11-14)
  2137.         * @see endPage(), AddPage()
  2138.         */
  2139.         protected function startPage($orientation=''$format=''{
  2140.             if ($this->numpages > $this->page{
  2141.                 // this page has been already added
  2142.                 $this->setPage($this->page + 1);
  2143.                 $this->SetY($this->tMargin);
  2144.                 return;
  2145.             }
  2146.             // start a new page
  2147.             if ($this->state == 0{
  2148.                 $this->Open();
  2149.             }
  2150.             ++$this->numpages;
  2151.             $this->swapMargins($this->booklet);
  2152.             // save current graphic settings
  2153.             $gvars $this->getGraphicVars();
  2154.             // start new page
  2155.             $this->_beginpage($orientation$format);
  2156.             // mark page as open
  2157.             $this->pageopen[$this->pagetrue;
  2158.             // restore graphic settings
  2159.             $this->setGraphicVars($gvars);
  2160.             // mark this point
  2161.             $this->setPageMark();
  2162.             // print page header
  2163.             $this->setHeader();
  2164.             // restore graphic settings
  2165.             $this->setGraphicVars($gvars);
  2166.             // mark this point
  2167.             $this->setPageMark();
  2168.             // print table header (if any)
  2169.             $this->setTableHeader();
  2170.         }
  2171.             
  2172.         /**
  2173.           * Set start-writing mark on current page for multicell borders and fills.
  2174.           * This function must be called after calling Image() function for a background image.
  2175.           * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2176.           * @access public
  2177.           * @since 4.0.016 (2008-07-30)
  2178.          */
  2179.         public function setPageMark({
  2180.             $this->intmrk[$this->page$this->pagelen[$this->page];
  2181.         }
  2182.         
  2183.         /**
  2184.           * Set header data.
  2185.          * @param string $ln header image logo
  2186.          * @param string $lw header image logo width in mm
  2187.          * @param string $ht string to print as title on document header
  2188.          * @param string $hs string to print on document header
  2189.          * @access public
  2190.          */
  2191.         public function setHeaderData($ln=''$lw=0$ht=''$hs=''{
  2192.             $this->header_logo = $ln;
  2193.             $this->header_logo_width = $lw;
  2194.             $this->header_title = $ht;
  2195.             $this->header_string = $hs;
  2196.         }
  2197.         
  2198.         /**
  2199.           * Returns header data:
  2200.           * <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>
  2201.          * @return array() 
  2202.          * @access public
  2203.          * @since 4.0.012 (2008-07-24)
  2204.          */
  2205.         public function getHeaderData({
  2206.             $ret array();
  2207.             $ret['logo'$this->header_logo;
  2208.             $ret['logo_width'$this->header_logo_width;
  2209.             $ret['title'$this->header_title;
  2210.             $ret['string'$this->header_string;
  2211.             return $ret;
  2212.         }
  2213.         
  2214.         /**
  2215.           * Set header margin.
  2216.          * (minimum distance between header and top page margin)
  2217.          * @param int $hm distance in user units
  2218.          * @access public
  2219.          */
  2220.         public function setHeaderMargin($hm=10{
  2221.             $this->header_margin = $hm;
  2222.         }
  2223.         
  2224.         /**
  2225.           * Returns header margin in user units.
  2226.          * @return float 
  2227.          * @since 4.0.012 (2008-07-24)
  2228.          * @access public
  2229.          */
  2230.         public function getHeaderMargin({
  2231.             return $this->header_margin;
  2232.         }
  2233.         
  2234.         /**
  2235.           * Set footer margin.
  2236.          * (minimum distance between footer and bottom page margin)
  2237.          * @param int $fm distance in user units
  2238.          * @access public
  2239.          */
  2240.         public function setFooterMargin($fm=10{
  2241.             $this->footer_margin = $fm;
  2242.         }
  2243.         
  2244.         /**
  2245.           * Returns footer margin in user units.
  2246.          * @return float 
  2247.          * @since 4.0.012 (2008-07-24)
  2248.          * @access public
  2249.          */
  2250.         public function getFooterMargin({
  2251.             return $this->footer_margin;
  2252.         }
  2253.         /**
  2254.           * Set a flag to print page header.
  2255.          * @param boolean $val set to true to print the page header (default), false otherwise.
  2256.          * @access public
  2257.          */
  2258.         public function setPrintHeader($val=true{
  2259.             $this->print_header = $val;
  2260.         }
  2261.         
  2262.         /**
  2263.           * Set a flag to print page footer.
  2264.          * @param boolean $value set to true to print the page footer (default), false otherwise.
  2265.          * @access public
  2266.          */
  2267.         public function setPrintFooter($val=true{
  2268.             $this->print_footer = $val;
  2269.         }
  2270.         
  2271.         /**
  2272.           * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  2273.          * @return float 
  2274.          * @access public
  2275.          */
  2276.         public function getImageRBX({
  2277.             return $this->img_rb_x;
  2278.         }
  2279.         
  2280.         /**
  2281.           * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  2282.          * @return float 
  2283.          * @access public
  2284.          */
  2285.         public function getImageRBY({
  2286.             return $this->img_rb_y;
  2287.         }
  2288.         
  2289.         /**
  2290.           * This method is used to render the page header.
  2291.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2292.          * @access public
  2293.          */
  2294.         public function Header({
  2295.             $ormargins $this->getOriginalMargins();
  2296.             $headerfont $this->getHeaderFont();
  2297.             $headerdata $this->getHeaderData();
  2298.             if (($headerdata['logo']AND ($headerdata['logo'!= K_BLANK_IMAGE)) {
  2299.                 $this->Image(K_PATH_IMAGES.$headerdata['logo']$this->GetX()$this->getHeaderMargin()$headerdata['logo_width']);
  2300.                 $imgy $this->getImageRBY();
  2301.             else {
  2302.                 $imgy $this->GetY();
  2303.             }
  2304.             $cell_height round(($this->getCellHeightRatio($headerfont[2]$this->getScaleFactor()2);
  2305.             // set starting margin for text data cell
  2306.             if ($this->getRTL()) {
  2307.                 $header_x $ormargins['right'($headerdata['logo_width'1.1);
  2308.             else {
  2309.                 $header_x $ormargins['left'($headerdata['logo_width'1.1);
  2310.             }
  2311.             $this->SetTextColor(000);
  2312.             // header title
  2313.             $this->SetFont($headerfont[0]'B'$headerfont[21);
  2314.             $this->SetX($header_x);            
  2315.             $this->Cell(0$cell_height$headerdata['title']01''0''0);
  2316.             // header string
  2317.             $this->SetFont($headerfont[0]$headerfont[1]$headerfont[2]);
  2318.             $this->SetX($header_x);
  2319.             $this->MultiCell(0$cell_height$headerdata['string']0''01''''true0false);
  2320.             // print an ending header line
  2321.             $this->SetLineStyle(array('width' => 0.85 $this->getScaleFactor()'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));
  2322.             $this->SetY((2.835 $this->getScaleFactor()) max($imgy$this->GetY()));
  2323.             if ($this->getRTL()) {
  2324.                 $this->SetX($ormargins['right']);
  2325.             else {
  2326.                 $this->SetX($ormargins['left']);
  2327.             }
  2328.             $this->Cell(00'''T'0'C');
  2329.         }
  2330.         
  2331.         /**
  2332.           * This method is used to render the page footer.
  2333.           * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  2334.          * @access public
  2335.          */
  2336.         public function Footer({                
  2337.             $cur_y $this->GetY();
  2338.             $ormargins $this->getOriginalMargins();
  2339.             $this->SetTextColor(000);            
  2340.             //set style for cell border
  2341.             $line_width 0.85 $this->getScaleFactor();
  2342.             $this->SetLineStyle(array('width' => $line_width'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));
  2343.             //print document barcode
  2344.             $barcode $this->getBarcode();
  2345.             if (!empty($barcode)) {
  2346.                 $this->Ln($line_width);
  2347.                 $barcode_width round(($this->getPageWidth($ormargins['left'$ormargins['right'])/3);
  2348.                 $this->write1DBarcode($barcode'C128B'$this->GetX()$cur_y $line_width$barcode_width(($this->getFooterMargin(3$line_width)0.3'''');    
  2349.             }
  2350.             if (empty($this->pagegroups)) {
  2351.                 $pagenumtxt $this->l['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  2352.             else {
  2353.                 $pagenumtxt $this->l['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  2354.             }        
  2355.             $this->SetY($cur_y);
  2356.             //Print page number
  2357.             if ($this->getRTL()) {
  2358.                 $this->SetX($ormargins['right']);
  2359.                 $this->Cell(00$pagenumtxt'T'0'L');
  2360.             else {
  2361.                 $this->SetX($ormargins['left']);
  2362.                 $this->Cell(00$pagenumtxt'T'0'R');
  2363.             }
  2364.         }
  2365.         
  2366.         /**
  2367.           * This method is used to render the page header.
  2368.           * @access protected
  2369.           * @since 4.0.012 (2008-07-24)
  2370.          */
  2371.         protected function setHeader({
  2372.             if ($this->print_header{
  2373.                 $lasth $this->lasth;
  2374.                 $this->_out('q');
  2375.                 $this->rMargin = $this->original_rMargin;
  2376.                 $this->lMargin = $this->original_lMargin;
  2377.                 $this->cMargin = 0;
  2378.                 //set current position
  2379.                 if ($this->rtl{
  2380.                     $this->SetXY($this->original_rMargin$this->header_margin);
  2381.                 else {
  2382.                     $this->SetXY($this->original_lMargin$this->header_margin);
  2383.                 }
  2384.                 $this->SetFont($this->header_font[0]$this->header_font[1]$this->header_font[2]);
  2385.                 $this->Header();
  2386.                 //restore position
  2387.                 if ($this->rtl{
  2388.                     $this->SetXY($this->original_rMargin$this->tMargin);
  2389.                 else {
  2390.                     $this->SetXY($this->original_lMargin$this->tMargin);
  2391.                 }
  2392.                 $this->_out('Q');
  2393.                 $this->lasth = $lasth;
  2394.             }
  2395.         }
  2396.         
  2397.         /**
  2398.           * This method is used to render the page footer.
  2399.           * @access protected
  2400.           * @since 4.0.012 (2008-07-24)
  2401.          */
  2402.         protected function setFooter({
  2403.             //Page footer
  2404.             // save current graphic settings
  2405.             $gvars $this->getGraphicVars();
  2406.             // mark this point
  2407.             $this->footerpos[$this->page$this->pagelen[$this->page];
  2408.             $this->_out("\n");
  2409.             if ($this->print_footer{
  2410.                 $lasth $this->lasth;
  2411.                 $this->_out('q');
  2412.                 $this->rMargin = $this->original_rMargin;
  2413.                 $this->lMargin = $this->original_lMargin;
  2414.                 $this->cMargin = 0;
  2415.                 //set current position
  2416.                 $footer_y $this->h - $this->footer_margin;
  2417.                 if ($this->rtl{
  2418.                     $this->SetXY($this->original_rMargin$footer_y);
  2419.                 else {
  2420.                     $this->SetXY($this->original_lMargin$footer_y);
  2421.                 }
  2422.                 $this->SetFont($this->footer_font[0]$this->footer_font[1]$this->footer_font[2]);
  2423.                 $this->Footer();
  2424.                 //restore position
  2425.                 if ($this->rtl{
  2426.                     $this->SetXY($this->original_rMargin$this->tMargin);
  2427.                 else {
  2428.                     $this->SetXY($this->original_lMargin$this->tMargin);
  2429.                 }
  2430.                 $this->_out('Q');
  2431.                 $this->lasth = $lasth;
  2432.             }
  2433.             // restore graphic settings
  2434.             $this->setGraphicVars($gvars);
  2435.             // calculate footer lenght
  2436.             $this->footerlen[$this->page$this->pagelen[$this->page$this->footerpos[$this->page1;
  2437.         }
  2438.  
  2439.         /**
  2440.           * This method is used to render the table header on new page (if any).
  2441.           * @access protected
  2442.           * @since 4.5.030 (2009-03-25)
  2443.          */
  2444.         protected function setTableHeader({
  2445.             if (!$this->empty_string($this->theadMargin)) {
  2446.                 // restore the original top-margin
  2447.                 $this->tMargin = $this->theadMargin;
  2448.                 $this->pagedim[$this->page]['tm'$this->theadMargin;
  2449.                 $this->y = $this->theadMargin;
  2450.             }
  2451.             if (!$this->empty_string($this->thead)) {
  2452.                 // print table header
  2453.                 $this->writeHTML($this->theadfalsefalsefalsefalse'');
  2454.                 // set new top margin to skip the table headers
  2455.                 if (!isset($this->theadMarginOR ($this->empty_string($this->theadMargin))) {
  2456.                     $this->theadMargin = $this->tMargin;
  2457.                 }
  2458.                 $this->tMargin = $this->y;
  2459.                 $this->pagedim[$this->page]['tm'$this->tMargin;
  2460.             }
  2461.         }
  2462.         
  2463.         /**
  2464.         * Returns the current page number.
  2465.         * @return int page number
  2466.         * @access public
  2467.         * @since 1.0
  2468.         * @see AliasNbPages(), getAliasNbPages()
  2469.         */
  2470.         public function PageNo({
  2471.             return $this->page;
  2472.         }
  2473.  
  2474.         /**
  2475.         * Defines a new spot color.
  2476.         * It can be expressed in RGB components or gray scale.
  2477.         * The method can be called before the first page is created and the value is retained from page to page.
  2478.         * @param int $c Cyan color for CMYK. Value between 0 and 255
  2479.         * @param int $m Magenta color for CMYK. Value between 0 and 255
  2480.         * @param int $y Yellow color for CMYK. Value between 0 and 255
  2481.         * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  2482.         * @access public
  2483.         * @since 4.0.024 (2008-09-12)
  2484.         * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2485.         */
  2486.         public function AddSpotColor($name$c$m$y$k{
  2487.             if (!isset($this->spot_colors[$name])) {
  2488.                 $i count($this->spot_colors);
  2489.                 $this->spot_colors[$namearray('i' => $i'c' => $c'm' => $m'y' => $y'k' => $k);
  2490.             }
  2491.         }
  2492.  
  2493.         /**
  2494.         * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  2495.         * It can be expressed in RGB components or gray scale.
  2496.         * The method can be called before the first page is created and the value is retained from page to page.
  2497.         * @param array $color array of colors
  2498.         * @access public
  2499.         * @since 3.1.000 (2008-06-11)
  2500.         * @see SetDrawColor()
  2501.         */
  2502.         public function SetDrawColorArray($color{
  2503.             if (isset($color)) {
  2504.                 $color array_values($color);
  2505.                 $r = isset($color[0]$color[0: -1;
  2506.                 $g = isset($color[1]$color[1: -1;
  2507.                 $b = isset($color[2]$color[2: -1;
  2508.                 $k = isset($color[3]$color[3: -1;
  2509.                 if ($r >= 0{
  2510.                     $this->SetDrawColor($r$g$b$k);
  2511.                 }
  2512.             }
  2513.         }
  2514.  
  2515.         /**
  2516.         * 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.
  2517.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2518.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2519.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2520.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2521.         * @access public
  2522.         * @since 1.3
  2523.         * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  2524.         */
  2525.         public function SetDrawColor($col1=0$col2=-1$col3=-1$col4=-1{
  2526.             // set default values
  2527.             if (!is_numeric($col1)) {
  2528.                 $col1 0;
  2529.             }
  2530.             if (!is_numeric($col2)) {
  2531.                 $col2 = -1;
  2532.             }
  2533.             if (!is_numeric($col3)) {
  2534.                 $col3 = -1;
  2535.             }
  2536.             if (!is_numeric($col4)) {
  2537.                 $col4 = -1;
  2538.             }
  2539.             //Set color for all stroking operations
  2540.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2541.                 // Grey scale
  2542.                 $this->DrawColor = sprintf('%.3F G'$col1/255);
  2543.             elseif ($col4 == -1{
  2544.                 // RGB
  2545.                 $this->DrawColor = sprintf('%.3F %.3F %.3F RG'$col1/255$col2/255$col3/255);
  2546.             else {
  2547.                 // CMYK
  2548.                 $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K'$col1/100$col2/100$col3/100$col4/100);
  2549.             }
  2550.             if ($this->page > 0{
  2551.                 $this->_out($this->DrawColor);
  2552.             }
  2553.         }
  2554.         
  2555.         /**
  2556.         * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  2557.         * @param string $name name of the spot color
  2558.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2559.         * @access public
  2560.         * @since 4.0.024 (2008-09-12)
  2561.         * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  2562.         */
  2563.         public function SetDrawSpotColor($name$tint=100{
  2564.             if (!isset($this->spot_colors[$name])) {
  2565.                 $this->Error('Undefined spot color: '.$name);
  2566.             }
  2567.             $this->DrawColor = sprintf('/CS%d CS %.3F SCN'$this->spot_colors[$name]['i']$tint/100);
  2568.             if ($this->page > 0{
  2569.                 $this->_out($this->DrawColor);
  2570.             }
  2571.         }
  2572.         
  2573.         /**
  2574.         * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  2575.         * It can be expressed in RGB components or gray scale.
  2576.         * The method can be called before the first page is created and the value is retained from page to page.
  2577.         * @param array $color array of colors
  2578.         * @access public
  2579.         * @since 3.1.000 (2008-6-11)
  2580.         * @see SetFillColor()
  2581.         */
  2582.         public function SetFillColorArray($color{
  2583.             if (isset($color)) {
  2584.                 $color array_values($color);
  2585.                 $r = isset($color[0]$color[0: -1;
  2586.                 $g = isset($color[1]$color[1: -1;
  2587.                 $b = isset($color[2]$color[2: -1;
  2588.                 $k = isset($color[3]$color[3: -1;
  2589.                 if ($r >= 0{
  2590.                     $this->SetFillColor($r$g$b$k);
  2591.                 }
  2592.             }
  2593.         }
  2594.         
  2595.         /**
  2596.         * 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.
  2597.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2598.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2599.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2600.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2601.         * @access public
  2602.         * @since 1.3
  2603.         * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  2604.         */
  2605.         public function SetFillColor($col1=0$col2=-1$col3=-1$col4=-1{
  2606.             // set default values
  2607.             if (!is_numeric($col1)) {
  2608.                 $col1 0;
  2609.             }
  2610.             if (!is_numeric($col2)) {
  2611.                 $col2 = -1;
  2612.             }
  2613.             if (!is_numeric($col3)) {
  2614.                 $col3 = -1;
  2615.             }
  2616.             if (!is_numeric($col4)) {
  2617.                 $col4 = -1;
  2618.             }
  2619.             //Set color for all filling operations
  2620.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2621.                 // Grey scale
  2622.                 $this->FillColor = sprintf('%.3F g'$col1/255);
  2623.                 $this->bgcolor = array('G' => $col1);
  2624.             elseif ($col4 == -1{
  2625.                 // RGB
  2626.                 $this->FillColor = sprintf('%.3F %.3F %.3F rg'$col1/255$col2/255$col3/255);
  2627.                 $this->bgcolor = array('R' => $col1'G' => $col2'B' => $col3);
  2628.             else {
  2629.                 // CMYK
  2630.                 $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k'$col1/100$col2/100$col3/100$col4/100);
  2631.                 $this->bgcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  2632.             }
  2633.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2634.             if ($this->page > 0{
  2635.                 $this->_out($this->FillColor);
  2636.             }
  2637.         }
  2638.         
  2639.         /**
  2640.         * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  2641.         * @param string $name name of the spot color
  2642.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2643.         * @access public
  2644.         * @since 4.0.024 (2008-09-12)
  2645.         * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  2646.         */
  2647.         public function SetFillSpotColor($name$tint=100{
  2648.             if (!isset($this->spot_colors[$name])) {
  2649.                 $this->Error('Undefined spot color: '.$name);
  2650.             }
  2651.             $this->FillColor = sprintf('/CS%d cs %.3F scn'$this->spot_colors[$name]['i']$tint/100);
  2652.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2653.             if ($this->page > 0{
  2654.                 $this->_out($this->FillColor);
  2655.             }
  2656.         }
  2657.         
  2658.         /**
  2659.         * Defines the color used for text. It can be expressed in RGB components or gray scale.
  2660.         * The method can be called before the first page is created and the value is retained from page to page.
  2661.         * @param array $color array of colors
  2662.         * @access public
  2663.         * @since 3.1.000 (2008-6-11)
  2664.         * @see SetFillColor()
  2665.         */
  2666.         public function SetTextColorArray($color{
  2667.             if (isset($color)) {
  2668.                 $color array_values($color);
  2669.                 $r = isset($color[0]$color[0: -1;
  2670.                 $g = isset($color[1]$color[1: -1;
  2671.                 $b = isset($color[2]$color[2: -1;
  2672.                 $k = isset($color[3]$color[3: -1;
  2673.                 if ($r >= 0{
  2674.                     $this->SetTextColor($r$g$b$k);
  2675.                 }
  2676.             }
  2677.         }
  2678.  
  2679.         /**
  2680.         * 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.
  2681.         * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  2682.         * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  2683.         * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  2684.         * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  2685.         * @access public
  2686.         * @since 1.3
  2687.         * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  2688.         */
  2689.         public function SetTextColor($col1=0$col2=-1$col3=-1$col4=-1{
  2690.             // set default values
  2691.             if (!is_numeric($col1)) {
  2692.                 $col1 0;
  2693.             }
  2694.             if (!is_numeric($col2)) {
  2695.                 $col2 = -1;
  2696.             }
  2697.             if (!is_numeric($col3)) {
  2698.                 $col3 = -1;
  2699.             }
  2700.             if (!is_numeric($col4)) {
  2701.                 $col4 = -1;
  2702.             }
  2703.             //Set color for text
  2704.             if (($col2 == -1AND ($col3 == -1AND ($col4 == -1)) {
  2705.                 // Grey scale
  2706.                 $this->TextColor = sprintf('%.3F g'$col1/255);
  2707.                 $this->fgcolor = array('G' => $col1);
  2708.             elseif ($col4 == -1{
  2709.                 // RGB
  2710.                 $this->TextColor = sprintf('%.3F %.3F %.3F rg'$col1/255$col2/255$col3/255);
  2711.                 $this->fgcolor = array('R' => $col1'G' => $col2'B' => $col3);
  2712.             else {
  2713.                 // CMYK
  2714.                 $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k'$col1/100$col2/100$col3/100$col4/100);
  2715.                 $this->fgcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  2716.             }
  2717.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2718.         }
  2719.         
  2720.         /**
  2721.         * Defines the spot color used for text.
  2722.         * @param string $name name of the spot color
  2723.         * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  2724.         * @access public
  2725.         * @since 4.0.024 (2008-09-12)
  2726.         * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  2727.         */
  2728.         public function SetTextSpotColor($name$tint=100{
  2729.             if (!isset($this->spot_colors[$name])) {
  2730.                 $this->Error('Undefined spot color: '.$name);
  2731.             }
  2732.             $this->TextColor = sprintf('/CS%d cs %.3F scn'$this->spot_colors[$name]['i']$tint/100);
  2733.             $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2734.             if ($this->page > 0{
  2735.                 $this->_out($this->TextColor);
  2736.             }
  2737.         }
  2738.  
  2739.         /**
  2740.         * Returns the length of a string in user unit. A font must be selected.<br>
  2741.         * @param string $s The string whose length is to be computed
  2742.         * @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.
  2743.         * @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.
  2744.         * @param float $fontsize Font size in points. The default value is the current size.
  2745.         * @return int string length
  2746.         * @author Nicola Asuni
  2747.         * @access public
  2748.         * @since 1.2
  2749.         */
  2750.         public function GetStringWidth($s$fontname=''$fontstyle=''$fontsize=0{
  2751.             return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s)$s$this->tmprtl)$fontname$fontstyle$fontsize);
  2752.         }
  2753.         
  2754.         /**
  2755.         * Returns the string length of an array of chars in user unit. A font must be selected.<br>
  2756.         * @param string $arr The array of chars whose total length is to be computed
  2757.         * @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.
  2758.         * @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.
  2759.         * @param float $fontsize Font size in points. The default value is the current size.
  2760.         * @return int string length
  2761.         * @author Nicola Asuni
  2762.         * @access public
  2763.         * @since 2.4.000 (2008-03-06)
  2764.         */
  2765.         public function GetArrStringWidth($sa$fontname=''$fontstyle=''$fontsize=0{
  2766.             // store current values
  2767.             if (!$this->empty_string($fontname)) {
  2768.                 $prev_FontFamily $this->FontFamily;
  2769.                 $prev_FontStyle $this->FontStyle;
  2770.                 $prev_FontSizePt $this->FontSizePt;
  2771.                 $this->SetFont($fontname$fontstyle$fontsize);
  2772.             }
  2773.             $w 0;
  2774.             foreach ($sa as $char{
  2775.                 $w += $this->GetCharWidth($char);
  2776.             }
  2777.             // restore previous values
  2778.             if (!$this->empty_string($fontname)) {
  2779.                 $this->SetFont($prev_FontFamily$prev_FontStyle$prev_FontSizePt);
  2780.             }
  2781.             return $w;
  2782.         }
  2783.         
  2784.         /**
  2785.         * Returns the length of the char in user unit for the current font.<br>
  2786.         * @param int $char The char code whose length is to be returned
  2787.         * @return int char width
  2788.         * @author Nicola Asuni
  2789.         * @access public
  2790.         * @since 2.4.000 (2008-03-06)
  2791.         */
  2792.         public function GetCharWidth($char{
  2793.             if ($char == 173{
  2794.                 // SHY character will not be printed
  2795.                 return (0);
  2796.             }
  2797.             $cw &$this->CurrentFont['cw'];
  2798.             if (isset($cw[$char])) {
  2799.                 $w $cw[$char];
  2800.             elseif (isset($this->CurrentFont['dw'])) {
  2801.                 // default width
  2802.                 $w $this->CurrentFont['dw'];
  2803.             elseif (isset($cw[32])) {
  2804.                 // default width
  2805.                 $dw $cw[32];
  2806.             else {
  2807.                 $w 600;
  2808.             }
  2809.             return ($w $this->FontSize / 1000);
  2810.         }
  2811.         
  2812.         /**
  2813.         * Returns the numbero of characters in a string.
  2814.         * @param string $s The input string.
  2815.         * @return int number of characters
  2816.         * @access public
  2817.         * @since 2.0.0001 (2008-01-07)
  2818.         */
  2819.         public function GetNumChars($s{
  2820.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  2821.                 return count($this->UTF8StringToArray($s));
  2822.             
  2823.             return strlen($s);
  2824.         }
  2825.             
  2826.         /**
  2827.         * Fill the list of available fonts ($this->fontlist).
  2828.         * @access protected
  2829.         * @since 4.0.013 (2008-07-28)
  2830.         */
  2831.         protected function getFontsList({
  2832.             $fontsdir opendir($this->_getfontpath());
  2833.             while (($file readdir($fontsdir)) !== false{
  2834.                 if (substr($file-4== '.php'{
  2835.                     array_push($this->fontliststrtolower(basename($file'.php')));
  2836.                 }
  2837.             }
  2838.             closedir($fontsdir);
  2839.         }
  2840.         
  2841.         /**
  2842.         * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  2843.         * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  2844.         * 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.
  2845.         * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  2846.         * @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>
  2847.         * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  2848.         * @return array containing the font data, or false in case of error.
  2849.         * @access public
  2850.         * @since 1.5
  2851.         * @see SetFont()
  2852.         */
  2853.         public function AddFont($family$style=''$fontfile=''{
  2854.             if ($this->empty_string($family)) {
  2855.                 if (!$this->empty_string($this->FontFamily)) {
  2856.                     $family $this->FontFamily;
  2857.                 else {
  2858.                     $this->Error('Empty font family');
  2859.                 }
  2860.             }
  2861.             $family strtolower($family);
  2862.             if ((!$this->isunicodeAND ($family == 'arial')) {
  2863.                 $family 'helvetica';
  2864.             }
  2865.             if (($family == 'symbol'OR ($family == 'zapfdingbats')) {
  2866.                 $style '';
  2867.             }
  2868.             $tempstyle strtoupper($style);
  2869.             $style '';
  2870.             // underline
  2871.             if (strpos($tempstyle'U'!== false{
  2872.                 $this->underline = true;
  2873.             else {
  2874.                 $this->underline = false;
  2875.             }
  2876.             // line through (deleted)
  2877.             if (strpos($tempstyle'D'!== false{
  2878.                 $this->linethrough = true;
  2879.             else {
  2880.                 $this->linethrough = false;
  2881.             }
  2882.             // bold
  2883.             if (strpos($tempstyle'B'!== false{
  2884.                 $style .= 'B';
  2885.             }
  2886.             // oblique
  2887.             if (strpos($tempstyle'I'!== false{
  2888.                 $style .= 'I';
  2889.             }
  2890.             $bistyle $style;
  2891.             $fontkey $family.$style;
  2892.             $font_style $style.($this->underline ? 'U' '').($this->linethrough ? 'D' '');
  2893.             $fontdata array('fontkey' => $fontkey'family' => $family'style' => $font_style);
  2894.             // check if the font has been already added
  2895.             if ($this->getFontBuffer($fontkey!== false{
  2896.                 return $fontdata;
  2897.             }
  2898.             if (isset($type)) {
  2899.                 unset($type)
  2900.             }
  2901.             if (isset($cw)) {
  2902.                 unset($cw)
  2903.             }
  2904.             // get specified font directory (if any)
  2905.             $fontdir '';
  2906.             if (!$this->empty_string($fontfile)) {
  2907.                 $fontdir dirname($fontfile);
  2908.                 if ($this->empty_string($fontdirOR ($fontdir == '.')) {
  2909.                     $fontdir '';
  2910.                 else {
  2911.                     $fontdir .= '/';
  2912.                 }
  2913.             }
  2914.             // search and include font file
  2915.             if ($this->empty_string($fontfileOR (!file_exists($fontfile))) {
  2916.                 // build a standard filenames for specified font
  2917.                 $fontfile1 str_replace(' '''$family).strtolower($style).'.php';
  2918.                 $fontfile2 str_replace(' '''$family).'.php';
  2919.                 // search files on various directories
  2920.                 if (file_exists($fontdir.$fontfile1)) {
  2921.                     $fontfile $fontdir.$fontfile1;
  2922.                 elseif (file_exists($this->_getfontpath().$fontfile1)) {
  2923.                     $fontfile $this->_getfontpath().$fontfile1;
  2924.                 elseif (file_exists($fontfile1)) {
  2925.                     $fontfile $fontfile1;
  2926.                 elseif (file_exists($fontdir.$fontfile2)) {
  2927.                     $fontfile $fontdir.$fontfile2;
  2928.                 elseif (file_exists($this->_getfontpath().$fontfile2)) {
  2929.                     $fontfile $this->_getfontpath().$fontfile2;
  2930.                 else {
  2931.                     $fontfile $fontfile2;
  2932.                 }
  2933.             }
  2934.             // include font file
  2935.             if (file_exists($fontfile)) {
  2936.                 include($fontfile);
  2937.             else {
  2938.                 $this->Error('Could not include font definition file: '.$family.'');
  2939.             }
  2940.             // check font parameters
  2941.             if ((!isset($type)) OR (!isset($cw))) {
  2942.                 $this->Error('The font definition file has a bad format: '.$fontfile.'');
  2943.             }
  2944.             if (!isset($file)) {
  2945.                 $file '';
  2946.             }
  2947.             if (!isset($enc)) {
  2948.                 $enc '';
  2949.             }
  2950.             if (!isset($dwOR $this->empty_string($dw)) {
  2951.                 // set default width
  2952.                 if (isset($desc['MissingWidth']AND ($desc['MissingWidth'0)) {
  2953.                     $dw $desc['MissingWidth'];
  2954.                 elseif (isset($cw[32])) {
  2955.                     $dw $cw[32];
  2956.                 else {
  2957.                     $dw 600;
  2958.                 }
  2959.             }
  2960.             ++$this->numfonts;            
  2961.             // register CID font (all styles at once)
  2962.             if ($type == 'cidfont0'{
  2963.                 $file ''// not embedded
  2964.                 $styles array('' => '''B' => ',Bold''I' => ',Italic''BI' => ',BoldItalic');
  2965.                 $sname $name.$styles[$bistyle];
  2966.                 if ((strpos($bistyle'B'!== falseAND (isset($desc['StemV'])) AND ($desc['StemV'== 70)) {
  2967.                     $desc['StemV'120;
  2968.                 }
  2969.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $sname'desc' => $desc'cidinfo' => $cidinfo'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'enc' => $enc));
  2970.             elseif ($type == 'core'{
  2971.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => 'core''name' => $this->CoreFonts[$fontkey]'up' => -100'ut' => 50'cw' => $cw'dw' => $dw));
  2972.             elseif (($type == 'TrueType'OR ($type == 'Type1')) {
  2973.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $name'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'file' => $file'enc' => $enc'desc' => $desc));
  2974.             elseif ($type == 'TrueTypeUnicode'{
  2975.                 $this->setFontBuffer($fontkeyarray('i' => $this->numfonts'type' => $type'name' => $name'desc' => $desc'up' => $up'ut' => $ut'cw' => $cw'dw' => $dw'enc' => $enc'file' => $file'ctg' => $ctg));
  2976.             else {
  2977.                 $this->Error('Unknow font type: '.$type.'');
  2978.             }
  2979.             if (isset($diffAND (!empty($diff))) {
  2980.                 //Search existing encodings
  2981.                 $d 0;
  2982.                 $nb count($this->diffs);
  2983.                 for($i=1$i <= $nb++$i{
  2984.                     if ($this->diffs[$i== $diff{
  2985.                         $d $i;
  2986.                         break;
  2987.                     }
  2988.                 }
  2989.                 if ($d == 0{
  2990.                     $d $nb 1;
  2991.                     $this->diffs[$d$diff;
  2992.                 }
  2993.                 $this->setFontSubBuffer($fontkey'diff'$d);
  2994.             }
  2995.             if (!$this->empty_string($file)) {
  2996.                 if ((strcasecmp($type,'TrueType'== 0OR (strcasecmp($type'TrueTypeUnicode'== 0)) {
  2997.                     $this->FontFiles[$filearray('length1' => $originalsize'fontdir' => $fontdir);
  2998.                 elseif ($type != 'core'{
  2999.                     $this->FontFiles[$filearray('length1' => $size1'length2' => $size2'fontdir' => $fontdir);
  3000.                 }
  3001.             }
  3002.             return $fontdata;
  3003.         }
  3004.  
  3005.         /**
  3006.         * Sets the font used to print character strings.
  3007.         * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  3008.         * The method can be called before the first page is created and the font is retained from page to page.
  3009.         * If you just wish to change the current font size, it is simpler to call SetFontSize().
  3010.         * 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 />
  3011.         * @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.
  3012.         * @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.
  3013.         * @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
  3014.         * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3015.         * @access public
  3016.         * @since 1.0
  3017.         * @see AddFont(), SetFontSize()
  3018.         */
  3019.         public function SetFont($family$style=''$size=0$fontfile=''{
  3020.             //Select a font; size given in points
  3021.             if ($size == 0{
  3022.                 $size $this->FontSizePt;
  3023.             }
  3024.             // try to add font (if not already added)
  3025.             $fontdata $this->AddFont($family$style$fontfile);
  3026.             $this->FontFamily = $fontdata['family'];
  3027.             $this->FontStyle = $fontdata['style'];
  3028.             $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  3029.             $this->SetFontSize($size);
  3030.         }
  3031.  
  3032.         /**
  3033.         * Defines the size of the current font.
  3034.         * @param float $size The size (in points)
  3035.         * @access public
  3036.         * @since 1.0
  3037.         * @see SetFont()
  3038.         */
  3039.         public function SetFontSize($size{
  3040.             //Set font size in points
  3041.             $this->FontSizePt = $size;
  3042.             $this->FontSize = $size $this->k;
  3043.             if (isset($this->CurrentFont['desc']['Ascent']AND ($this->CurrentFont['desc']['Ascent'0)) {
  3044.                 $this->FontAscent = $this->CurrentFont['desc']['Ascent'$this->FontSize / 1000;
  3045.             else {
  3046.                 $this->FontAscent = 0.8 $this->FontSize;
  3047.             }
  3048.             if (isset($this->CurrentFont['desc']['Descent']AND ($this->CurrentFont['desc']['Descent'0)) {
  3049.                 $this->FontDescent = - $this->CurrentFont['desc']['Descent'$this->FontSize / 1000;
  3050.             else {
  3051.                 $this->FontDescent = 0.2 $this->FontSize;
  3052.             }
  3053.             if (($this->page > 0AND (isset($this->CurrentFont['i']))) {
  3054.                 $this->_out(sprintf('BT /F%d %.2F Tf ET'$this->CurrentFont['i']$this->FontSizePt));
  3055.             }
  3056.         }
  3057.  
  3058.         /**
  3059.         * Defines the default monospaced font.
  3060.         * @param string $font Font name.
  3061.         * @access public
  3062.         * @since 4.5.025
  3063.         */
  3064.         public function SetDefaultMonospacedFont($font{
  3065.             $this->default_monospaced_font = $font;
  3066.         }
  3067.         
  3068.         /**
  3069.         * 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 />
  3070.         * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  3071.         * @access public
  3072.         * @since 1.5
  3073.         * @see Cell(), Write(), Image(), Link(), SetLink()
  3074.         */
  3075.         public function AddLink({
  3076.             //Create a new internal link
  3077.             $n count($this->links1;
  3078.             $this->links[$narray(00);
  3079.             return $n;
  3080.         }
  3081.  
  3082.         /**
  3083.         * Defines the page and position a link points to.
  3084.         * @param int $link The link identifier returned by AddLink()
  3085.         * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  3086.         * @param int $page Number of target page; -1 indicates the current page. This is the default value
  3087.         * @access public
  3088.         * @since 1.5
  3089.         * @see AddLink()
  3090.         */
  3091.         public function SetLink($link$y=0$page=-1{
  3092.             if ($y == -1{
  3093.                 $y $this->y;
  3094.             }
  3095.             if ($page == -1{
  3096.                 $page $this->page;
  3097.             }
  3098.             $this->links[$linkarray($page$y);
  3099.         }
  3100.  
  3101.         /**
  3102.         * Puts a link on a rectangular area of the page.
  3103.         * 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.
  3104.         * @param float $x Abscissa of the upper-left corner of the rectangle
  3105.         * @param float $y Ordinate of the upper-left corner of the rectangle
  3106.         * @param float $w Width of the rectangle
  3107.         * @param float $h Height of the rectangle
  3108.         * @param mixed $link URL or identifier returned by AddLink()
  3109.         * @param int $spaces number of spaces on the text to link
  3110.         * @access public
  3111.         * @since 1.5
  3112.         * @see AddLink(), Annotation(), Cell(), Write(), Image()
  3113.         */
  3114.         public function Link($x$y$w$h$link$spaces=0{
  3115.             $this->Annotation($x$y$w$h$linkarray('Subtype'=>'Link')$spaces);
  3116.         }
  3117.         
  3118.         /**
  3119.         * Puts a markup annotation on a rectangular area of the page.
  3120.         * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  3121.         * @param float $x Abscissa of the upper-left corner of the rectangle
  3122.         * @param float $y Ordinate of the upper-left corner of the rectangle
  3123.         * @param float $w Width of the rectangle
  3124.         * @param float $h Height of the rectangle
  3125.         * @param string $text annotation text or alternate content
  3126.         * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  3127.         * @param int $spaces number of spaces on the text to link
  3128.         * @access public
  3129.         * @since 4.0.018 (2008-08-06)
  3130.         */
  3131.         public function Annotation($x$y$w$h$text$opt=array('Subtype'=>'Text')$spaces=0{
  3132.             // recalculate coordinates to account for graphic transformations
  3133.             if (isset($this->transfmatrix)) {
  3134.                 $maxid count($this->transfmatrix1;
  3135.                 for ($i=$maxid$i >= 0$i--{
  3136.                     $ctm $this->transfmatrix[$i];
  3137.                     if (isset($ctm['a'])) {
  3138.                         $x $x $this->k;
  3139.                         $y ($this->h - $y$this->k;
  3140.                         $w $w $this->k;
  3141.                         $h $h $this->k;
  3142.                         // top left
  3143.                         $xt $x;
  3144.                         $yt $y;
  3145.                         $x1 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3146.                         $y1 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3147.                         // top right
  3148.                         $xt $x $w;
  3149.                         $yt $y;
  3150.                         $x2 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3151.                         $y2 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3152.                         // bottom left
  3153.                         $xt $x;
  3154.                         $yt $y $h;
  3155.                         $x3 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3156.                         $y3 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3157.                         // bottom right
  3158.                         $xt $x $w;
  3159.                         $yt $y $h;
  3160.                         $x4 ($ctm['a'$xt($ctm['c'$yt$ctm['e'];
  3161.                         $y4 ($ctm['b'$xt($ctm['d'$yt$ctm['f'];
  3162.                         // new coordinates (rectangle area)
  3163.                         $x min($x1$x2$x3$x4);
  3164.                         $y max($y1$y2$y3$y4);
  3165.                         $w (max($x1$x2$x3$x4$x$this->k;
  3166.                         $h ($y min($y1$y2$y3$y4)) $this->k;
  3167.                         $x $x $this->k;
  3168.                         $y $this->h - ($y $this->k);
  3169.                     }
  3170.                 }
  3171.             }
  3172.             $this->PageAnnots[$this->page][array('x' => $x'y' => $y'w' => $w'h' => $h'txt' => $text'opt' => $opt'numspaces' => $spaces);
  3173.             if (($opt['Subtype'== 'FileAttachment'AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  3174.                 $this->embeddedfiles[basename($opt['FS'])array('file' => $opt['FS']'n' => ($this->n + count($this->embeddedfiles10000));
  3175.             }
  3176.         }
  3177.  
  3178.         /**
  3179.         * Embedd the attached files.
  3180.         * @since 4.4.000 (2008-12-07)
  3181.         * @access protected
  3182.         * @see Annotation()
  3183.         */
  3184.         protected function _putEmbeddedFiles({
  3185.             reset($this->embeddedfiles);
  3186.             foreach ($this->embeddedfiles as $filename => $filedata{
  3187.                 $data file_get_contents($filedata['file']);
  3188.                 $filter '';
  3189.                 if ($this->compress{
  3190.                     $data gzcompress($data);
  3191.                     $filter ' /Filter /FlateDecode';
  3192.                 }
  3193.                 $this->offsets[$filedata['n']] $this->bufferlen;
  3194.                 $this->_out($filedata['n'].' 0 obj');
  3195.                 $this->_out('<</Type /EmbeddedFile'.$filter.' /Length '.strlen($data).' >>');
  3196.                 $this->_putstream($data);
  3197.                 $this->_out('endobj');
  3198.             }
  3199.         }
  3200.         
  3201.         /**
  3202.         * Prints a character string.
  3203.         * The origin is on the left of the first charcter, on the baseline.
  3204.         * This method allows to place a string precisely on the page.
  3205.         * @param float $x Abscissa of the origin
  3206.         * @param float $y Ordinate of the origin
  3207.         * @param string $txt String to print
  3208.         * @param int $stroke outline size in points (0 = disable)
  3209.         * @param boolean $clip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  3210.         * @access public
  3211.         * @since 1.0
  3212.         * @deprecated deprecated since version 4.3.005 (2008-11-25)
  3213.         * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  3214.         */
  3215.         public function Text($x$y$txt$stroke=0$clip=false{
  3216.             //Output a string
  3217.             if ($this->rtl{
  3218.                 // bidirectional algorithm (some chars may be changed affecting the line length)
  3219.                 $s $this->utf8Bidi($this->UTF8StringToArray($txt)$txt$this->tmprtl);
  3220.                 $l $this->GetArrStringWidth($s);
  3221.                 $xr $this->w - $x $this->GetArrStringWidth($s);
  3222.             else {
  3223.                 $xr $x;
  3224.             }
  3225.             $opt '';
  3226.             if (($stroke 0AND (!$clip)) {
  3227.                 $opt .= '1 Tr '.intval($stroke).' w ';
  3228.             elseif (($stroke 0AND $clip{
  3229.                 $opt .= '5 Tr '.intval($stroke).' w ';
  3230.             elseif ($clip{
  3231.                 $opt .= '7 Tr ';
  3232.             }
  3233.             $s sprintf('BT %.2F %.2F Td %s(%s) Tj ET 0 Tr'$xr $this->k($this->h-$y$this->k$opt$this->_escapetext($txt));
  3234.             if ($this->underline AND ($txt!='')) {
  3235.                 $s .= ' '.$this->_dounderline($xr$y$txt);
  3236.             }
  3237.             if ($this->linethrough AND ($txt!='')) 
  3238.                 $s .= ' '.$this->_dolinethrough($xr$y$txt)
  3239.             }
  3240.             if ($this->ColorFlag AND (!$clip)) {
  3241.                 $s='q '.$this->TextColor.' '.$s.' Q';
  3242.             }
  3243.             $this->_out($s);
  3244.         }
  3245.  
  3246.         /**
  3247.         * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  3248.         * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  3249.         * This method is called automatically and should not be called directly by the application.
  3250.         * @return boolean 
  3251.         * @access public
  3252.         * @since 1.4
  3253.         * @see SetAutoPageBreak()
  3254.         */
  3255.         public function AcceptPageBreak({
  3256.             return $this->AutoPageBreak;
  3257.         }
  3258.         
  3259.         /**
  3260.         * Add page if needed.
  3261.         * @param float $h Cell height. Default value: 0.
  3262.         * @return boolean true in case of page break, false otherwise.
  3263.         * @since 3.2.000 (2008-07-01)
  3264.         * @access protected
  3265.         */
  3266.         protected function checkPageBreak($h{
  3267.             if ((($this->y + $h$this->PageBreakTriggerAND (!$this->InFooterAND ($this->AcceptPageBreak())) {
  3268.                 //Automatic page break
  3269.                 $x $this->x;
  3270.                 $this->AddPage($this->CurOrientation);
  3271.                 $this->y = $this->tMargin;
  3272.                 $oldpage $this->page - 1;
  3273.                 if ($this->rtl{
  3274.                     if ($this->pagedim[$this->page]['orm'!= $this->pagedim[$oldpage]['orm']{
  3275.                         $this->x = $x ($this->pagedim[$this->page]['orm'$this->pagedim[$oldpage]['orm']);
  3276.                     else {
  3277.                         $this->x = $x;
  3278.                     }
  3279.                 else {
  3280.                     if ($this->pagedim[$this->page]['olm'!= $this->pagedim[$oldpage]['olm']{
  3281.                         $this->x = $x ($this->pagedim[$this->page]['olm'$this->pagedim[$oldpage]['olm']);
  3282.                     else {
  3283.                         $this->x = $x;
  3284.                     }
  3285.                 }
  3286.                 return true;
  3287.             }
  3288.             return false;
  3289.         }
  3290.  
  3291.         /**
  3292.         * 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 />
  3293.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3294.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3295.         * @param float $h Cell height. Default value: 0.
  3296.         * @param string $txt String to print. Default value: empty string.
  3297.         * @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>
  3298.         * @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>
  3299.         Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3300.         * @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>
  3301.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3302.         * @param mixed $link URL or identifier returned by AddLink().
  3303.         * @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>
  3304.         * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3305.         * @access public
  3306.         * @since 1.0
  3307.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  3308.         */
  3309.         public function Cell($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''$stretch=0$ignore_min_height=false{
  3310.             //$min_cell_height = $this->FontAscent + $this->FontDescent;
  3311.             $min_cell_height $this->FontSize * $this->cell_height_ratio;
  3312.             if ($h $min_cell_height{
  3313.                 $h $min_cell_height;
  3314.             }
  3315.             $this->checkPageBreak($h);
  3316.             $this->_out($this->getCellCode($w$h$txt$border$ln$align$fill$link$stretch$ignore_min_height));
  3317.         }
  3318.  
  3319.         /**
  3320.         * Removes SHY characters from text.
  3321.         * @param string $txt input string
  3322.         * @return string without SHY characters.
  3323.         * @access public
  3324.         * @since (4.5.019) 2009-02-28
  3325.         */
  3326.         public function removeSHY($txt=''{
  3327.             /*
  3328.             * Unicode Data
  3329.             * Name : SOFT HYPHEN, commonly abbreviated as SHY
  3330.             * HTML Entity (decimal): &#173;
  3331.             * HTML Entity (hex): &#xad;
  3332.             * HTML Entity (named): &shy;
  3333.             * How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
  3334.             * UTF-8 (hex): 0xC2 0xAD (c2ad)
  3335.             * UTF-8 character: chr(194).chr(173)
  3336.             */
  3337.             $txt preg_replace('/([\\xc2]{1}[\\xad]{1})/'''$txt);
  3338.             if (!$this->isunicode{
  3339.                 $txt preg_replace('/([\\xad]{1})/'''$txt);
  3340.             }
  3341.             return $txt;
  3342.         }
  3343.         
  3344.         /**
  3345.         * 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 />
  3346.         * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3347.         * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3348.         * @param float $h Cell height. Default value: 0.
  3349.         * @param string $txt String to print. Default value: empty string.
  3350.         * @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>
  3351.         * @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.
  3352.         * @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>
  3353.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3354.         * @param mixed $link URL or identifier returned by AddLink().
  3355.         * @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>
  3356.         * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  3357.         * @access protected
  3358.         * @since 1.0
  3359.         * @see Cell()
  3360.         */
  3361.         protected function getCellCode($w$h=0$txt=''$border=0$ln=0$align=''$fill=0$link=''$stretch=0$ignore_min_height=false{
  3362.             $txt $this->removeSHY($txt);
  3363.             $rs ''//string to be returned
  3364.             if (!$ignore_min_height{
  3365.                 $min_cell_height $this->FontSize * $this->cell_height_ratio;
  3366.                 if ($h $min_cell_height{
  3367.                     $h $min_cell_height;
  3368.                 }
  3369.             }
  3370.             $k $this->k;
  3371.             if ($this->empty_string($wOR ($w <= 0)) {
  3372.                 if ($this->rtl{
  3373.                     $w $this->x - $this->lMargin;
  3374.                 else {
  3375.                     $w $this->w - $this->rMargin - $this->x;
  3376.                 }
  3377.             }
  3378.             $s '';            
  3379.             if (($fill == 1OR ($border == 1)) {
  3380.                 if ($fill == 1{
  3381.                     $op ($border == 1'B' 'f';
  3382.                 else {
  3383.                     $op 'S';
  3384.                 }
  3385.                 if ($this->rtl{
  3386.                     $xk (($this->x  - $w$k);
  3387.                 else {
  3388.                     $xk ($this->x * $k);
  3389.                 }
  3390.                 $s .= sprintf('%.2F %.2F %.2F %.2F re %s '$xk(($this->h - $this->y$k)($w $k)(-$h $k)$op);
  3391.             }
  3392.             if (is_string($border)) {
  3393.                 $lm ($this->LineWidth / 2);
  3394.                 $x $this->x;
  3395.                 $y $this->y;
  3396.                 if (strpos($border,'L'!== false{
  3397.                     if ($this->rtl{
  3398.                         $xk ($x $w$k;
  3399.                     else {
  3400.                         $xk $x $k;
  3401.                     }
  3402.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - $y $lm$k)$xk(($this->h - ($y $h $lm)) $k));
  3403.                 }
  3404.                 if (strpos($border,'T'!== false{
  3405.                     if ($this->rtl{
  3406.                         $xk ($x $w $lm$k;
  3407.                         $xwk ($x $lm$k;
  3408.                     else {
  3409.                         $xk ($x $lm$k;
  3410.                         $xwk ($x $w $lm$k;
  3411.                     }
  3412.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - $y$k)$xwk(($this->h - $y$k));
  3413.                 }
  3414.                 if (strpos($border,'R'!== false{
  3415.                     if ($this->rtl{
  3416.                         $xk $x $k;
  3417.                     else {
  3418.                         $xk ($x $w$k;
  3419.                     }
  3420.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - $y $lm$k)$xk(($this->h - ($y $h $lm))$k));
  3421.                 }
  3422.                 if (strpos($border,'B'!== false{
  3423.                     if ($this->rtl{
  3424.                         $xk ($x $w $lm$k;
  3425.                         $xwk ($x $lm$k;
  3426.                     else {
  3427.                         $xk ($x $lm$k;
  3428.                         $xwk ($x $w $lm$k;
  3429.                     }
  3430.                     $s .= sprintf('%.2F %.2F m %.2F %.2F l S '$xk(($this->h - ($y $h)) $k)$xwk(($this->h - ($y $h)) $k));
  3431.                 }
  3432.             }
  3433.             if ($txt != ''{
  3434.                 // text lenght
  3435.                 $width $this->GetStringWidth($txt);
  3436.                 // ratio between cell lenght and text lenght
  3437.                 $ratio ($w ($this->cMargin)) $width;
  3438.                 
  3439.                 // stretch text if required
  3440.                 if (($stretch 0AND (($ratio 1OR (($ratio 1AND (($stretch 2== 0)))) {
  3441.                     if ($stretch 2{
  3442.                         // spacing
  3443.                         //Calculate character spacing in points
  3444.                         $char_space (($w $width ($this->cMargin)) $this->kmax($this->GetNumChars($txt)-1,1);
  3445.                         //Set character spacing
  3446.                         $rs .= sprintf('BT %.2F Tc ET '$char_space);
  3447.                     else {
  3448.                         // scaling
  3449.                         //Calculate horizontal scaling
  3450.                         $horiz_scale $ratio 100.0;
  3451.                         //Set horizontal scaling
  3452.                         $rs .= sprintf('BT %.2F Tz ET '$horiz_scale);
  3453.                     }
  3454.                     $align '';
  3455.                     $width $w ($this->cMargin);
  3456.                 else {
  3457.                     $stretch == 0;
  3458.                 }
  3459.                 if ($align == 'L'{
  3460.                     if ($this->rtl{
  3461.                         $dx $w $width $this->cMargin;
  3462.                     else {
  3463.                         $dx $this->cMargin;
  3464.                     }
  3465.                 elseif ($align == 'R'{
  3466.                     if ($this->rtl{
  3467.                         $dx $this->cMargin;
  3468.                     else {
  3469.                         $dx $w $width $this->cMargin;
  3470.                     }
  3471.                 elseif ($align == 'C'{
  3472.                     $dx ($w $width2;
  3473.                 elseif ($align == 'J'{
  3474.                     if ($this->rtl{
  3475.                         $dx $w $width $this->cMargin;
  3476.                     else {
  3477.                         $dx $this->cMargin;
  3478.                     }
  3479.                 else {
  3480.                     $dx $this->cMargin;
  3481.                 }
  3482.                 if ($this->ColorFlag{
  3483.                     $s .= 'q '.$this->TextColor.' ';
  3484.                 }
  3485.                 $txt2 $this->_escapetext($txt);
  3486.                 if ($this->rtl{
  3487.                     $xdk ($this->x - $dx $width$k;
  3488.                 else {
  3489.                     $xdk ($this->x + $dx$k;
  3490.                 }
  3491.                 // Justification
  3492.                 if ($align == 'J'{
  3493.                     // count number of spaces
  3494.                     $ns substr_count($txt' ');
  3495.                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  3496.                         // get string width without spaces
  3497.                         $width $this->GetStringWidth(str_replace(' '''$txt));
  3498.                         // calculate average space width
  3499.                         $spacewidth ($w $width ($this->cMargin)) ($ns?$ns:1$this->FontSize / $this->k;
  3500.                         // set word position to be used with TJ operator
  3501.                         $txt2 str_replace(chr(0).' '') '.(-2830 $spacewidth).' ('$txt2);
  3502.                     else {
  3503.                         // get string width
  3504.                         $width $this->GetStringWidth($txt);
  3505.                         $spacewidth (($w $width ($this->cMargin)) ($ns?$ns:1)) $this->k;
  3506.                         $rs .= sprintf('BT %.3F Tw ET '$spacewidth);
  3507.                     }
  3508.                 }
  3509.                 // calculate approximate position of the font base line
  3510.                 //$basefonty = $this->y + (($h + $this->FontAscent - $this->FontDescent)/2);
  3511.                 $basefonty $this->y + ($h/2($this->FontSize/3);
  3512.                 // print text
  3513.                 $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET'$xdk(($this->h - $basefonty$k)$txt2);
  3514.                 if ($this->rtl{
  3515.                     $xdx $this->x - $dx $width;
  3516.                 else {
  3517.                     $xdx $this->x + $dx;
  3518.                 }
  3519.                 if ($this->underline)  {
  3520.                     $s .= ' '.$this->_dounderline($xdx$basefonty$txt);
  3521.                 }
  3522.                 if ($this->linethrough
  3523.                     $s .= ' '.$this->_dolinethrough($xdx$basefonty$txt);
  3524.                 }
  3525.                 if ($this->ColorFlag{
  3526.                     $s .= ' Q';
  3527.                 }
  3528.                 if ($link{
  3529.                     $this->Link($xdx$this->y + (($h $this->FontSize)/2)$width$this->FontSize$linksubstr_count($txtchr(32)));
  3530.                 }
  3531.             }
  3532.             // output cell
  3533.             if ($s{
  3534.                 // output cell
  3535.                 $rs .= $s;
  3536.                 // reset text stretching
  3537.                 if ($stretch 2{
  3538.                     //Reset character horizontal spacing
  3539.                     $rs .= ' BT 0 Tc ET';
  3540.                 elseif ($stretch 0{
  3541.                     //Reset character horizontal scaling
  3542.                     $rs .= ' BT 100 Tz ET';
  3543.                 }
  3544.             }
  3545.             // reset word spacing
  3546.             if (!(($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) AND ($align == 'J')) {
  3547.                 $rs .= ' BT 0 Tw ET';
  3548.             }
  3549.             $this->lasth = $h;
  3550.             if ($ln 0{
  3551.                 //Go to the beginning of the next line
  3552.                 $this->y += $h;
  3553.                 if ($ln == 1{
  3554.                     if ($this->rtl{
  3555.                         $this->x = $this->w - $this->rMargin;
  3556.                     else {
  3557.                         $this->x = $this->lMargin;
  3558.                     }
  3559.                 }
  3560.             else {
  3561.                 // go left or right by case
  3562.                 if ($this->rtl{
  3563.                     $this->x -= $w;
  3564.                 else {
  3565.                     $this->x += $w;
  3566.                 }
  3567.             }
  3568.             $gstyles ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  3569.             $rs $gstyles.$rs;
  3570.             return $rs;
  3571.         }
  3572.  
  3573.         /**
  3574.         * This method allows printing text with line breaks.
  3575.         * 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 />
  3576.         * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  3577.         * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  3578.         * @param float $h Cell minimum height. The cell extends automatically if needed.
  3579.         * @param string $txt String to print
  3580.         * @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>
  3581.         * @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>
  3582.         * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3583.         * @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>
  3584.         * @param int $x x position in user units
  3585.         * @param int $y y position in user units
  3586.         * @param boolean $reseth if true reset the last cell height (default true).
  3587.         * @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>
  3588.         * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  3589.         * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  3590.         * @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.
  3591.         * @return int Return the number of cells or 1 for html mode.
  3592.         * @access public
  3593.         * @since 1.3
  3594.         * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  3595.         */
  3596.         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{    
  3597.             if ($this->empty_string($this->lasthOR $reseth{
  3598.                 //set row height
  3599.                 $this->lasth = $this->FontSize * $this->cell_height_ratio;
  3600.             }
  3601.             if (!$this->empty_string($y)) {
  3602.                 $this->SetY($y);
  3603.             else {
  3604.                 $y $this->GetY();
  3605.             }
  3606.             // check for page break
  3607.             $this->checkPageBreak($h);
  3608.             $y $this->GetY();
  3609.             // get current page number
  3610.             $startpage $this->page;
  3611.             if (!$this->empty_string($x)) {
  3612.                 $this->SetX($x);
  3613.             else {
  3614.                 $x $this->GetX();
  3615.             }
  3616.             if ($this->empty_string($wOR ($w <= 0)) {
  3617.                 if ($this->rtl{
  3618.                     $w $this->x - $this->lMargin;
  3619.                 else {
  3620.                     $w $this->w - $this->rMargin - $this->x;
  3621.                 }
  3622.             }
  3623.             // store original margin values
  3624.             $lMargin $this->lMargin;
  3625.             $rMargin $this->rMargin;
  3626.             if ($this->rtl{
  3627.                 $this->SetRightMargin($this->w - $this->x);
  3628.                 $this->SetLeftMargin($this->x - $w);
  3629.             else {
  3630.                 $this->SetLeftMargin($this->x);
  3631.                 $this->SetRightMargin($this->w - $this->x - $w);
  3632.             }
  3633.             $starty $this->y;
  3634.             if ($autopadding{
  3635.                 // Adjust internal padding
  3636.                 if ($this->cMargin < ($this->LineWidth / 2)) {
  3637.                     $this->cMargin = ($this->LineWidth / 2);
  3638.                 }
  3639.                 // Add top space if needed
  3640.                 if (($this->lasth - $this->FontSize$this->LineWidth{
  3641.                     $this->y += $this->LineWidth / 2;
  3642.                 }
  3643.                 // add top padding
  3644.                 $this->y += $this->cMargin;
  3645.             }
  3646.             if ($ishtml{
  3647.                 // ******* Write HTML text
  3648.                 $this->writeHTML($txttrue0$resethtrue$align);
  3649.                 $nl 1;
  3650.             else {
  3651.                 // ******* Write text
  3652.                 $nl $this->Write($this->lasth$txt''0$aligntrue$stretchfalsefalse$maxh);
  3653.             }
  3654.             if ($autopadding{
  3655.                 // add bottom padding
  3656.                 $this->y += $this->cMargin;
  3657.                 // Add bottom space if needed
  3658.                 if (($this->lasth - $this->FontSize$this->LineWidth{
  3659.                     $this->y += $this->LineWidth / 2;
  3660.                 }
  3661.             }
  3662.             // Get end-of-text Y position
  3663.             $currentY $this->y;
  3664.             // get latest page number
  3665.             $endpage $this->page;
  3666.             // check if a new page has been created
  3667.             if ($endpage $startpage{
  3668.                 // design borders around HTML cells.
  3669.                 for ($page=$startpage$page <= $endpage++$page{
  3670.                     $this->setPage($page);
  3671.                     if ($page == $startpage{
  3672.                         $this->y = $starty// put cursor at the beginning of cell on the first page
  3673.                         $h $this->getPageHeight($starty $this->getBreakMargin();
  3674.                         $cborder $this->getBorderMode($border$position='start');
  3675.                     elseif ($page == $endpage{
  3676.                         $this->y = $this->tMargin// put cursor at the beginning of last page
  3677.                         $h $currentY $this->tMargin;
  3678.                         $cborder $this->getBorderMode($border$position='end');
  3679.                     else {
  3680.                         $this->y = $this->tMargin// put cursor at the beginning of the current page
  3681.                         $h $this->getPageHeight($this->tMargin - $this->getBreakMargin();
  3682.                         $cborder $this->getBorderMode($border$position='middle');
  3683.                     }
  3684.                     $nx $x;
  3685.                     // account for margin changes
  3686.                     if ($page $startpage{
  3687.                         if (($this->rtlAND ($this->pagedim[$page]['orm'!= $this->pagedim[$startpage]['orm'])) {
  3688.                             $nx $x ($this->pagedim[$page]['orm'$this->pagedim[$startpage]['orm']);
  3689.                         elseif ((!$this->rtlAND ($this->pagedim[$page]['olm'!= $this->pagedim[$startpage]['olm'])) {
  3690.                             $nx $x ($this->pagedim[$page]['olm'$this->pagedim[$startpage]['olm']);
  3691.                         }
  3692.                     }
  3693.                     $this->SetX($nx);
  3694.                     $ccode $this->getCellCode($w$h''$cborder1''$fill''0false);
  3695.                     if ($cborder OR $fill{
  3696.                         $pagebuff $this->getPageBuffer($this->page);
  3697.                         $pstart substr($pagebuff0$this->intmrk[$this->page]);
  3698.                         $pend substr($pagebuff$this->intmrk[$this->page]);
  3699.                         $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  3700.                         $this->intmrk[$this->page+= strlen($ccode."\n");
  3701.                     }
  3702.                 }
  3703.             else {
  3704.                 $h max($h($currentY $y));
  3705.                 // put cursor at the beginning of text
  3706.                 $this->SetY($y)
  3707.                 $this->SetX($x);
  3708.                 // design a cell around the text
  3709.                 $ccode $this->getCellCode($w$h''$border1''$fill''0true);
  3710.                 if ($border OR $fill{
  3711.                     if (end($this->transfmrk[$this->page]!== false{
  3712.                         $pagemarkkey key($this->transfmrk[$this->page]);
  3713.                         $pagemark &$this->transfmrk[$this->page][$pagemarkkey];
  3714.                     elseif ($this->InFooter{
  3715.                         $pagemark &$this->footerpos[$this->page];
  3716.                     else {
  3717.                         $pagemark &$this->intmrk[$this->page];
  3718.                     }
  3719.                     $pagebuff $this->getPageBuffer($this->page);
  3720.                     $pstart substr($pagebuff0$pagemark);
  3721.                     $pend substr($pagebuff$pagemark);
  3722.                     $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  3723.                     $pagemark += strlen($ccode."\n");
  3724.                 }
  3725.             }
  3726.             // Get end-of-cell Y position
  3727.             $currentY $this->GetY();
  3728.             // restore original margin values
  3729.             $this->SetLeftMargin($lMargin);
  3730.             $this->SetRightMargin($rMargin);
  3731.             if ($ln 0{
  3732.                 //Go to the beginning of the next line
  3733.                 $this->SetY($currentY);
  3734.                 if ($ln == 2{
  3735.                     $this->SetX($x $w);
  3736.                 }
  3737.             else {
  3738.                 // go left or right by case
  3739.                 $this->setPage($startpage);
  3740.                 $this->y = $y;
  3741.                 $this->SetX($x $w);
  3742.             }
  3743.             return $nl;
  3744.         }
  3745.  
  3746.         /**
  3747.         * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  3748.         * @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>
  3749.         * @param string multicell position: 'start', 'middle', 'end'
  3750.         * @return border mode
  3751.         * @access protected
  3752.         * @since 4.4.002 (2008-12-09)
  3753.         */
  3754.         protected function getBorderMode($border$position='start'{
  3755.             if ((!$this->opencellAND ($border == 1)) {
  3756.                 return 1;
  3757.             }
  3758.             $cborder '';
  3759.             switch ($position{
  3760.                 case 'start'{
  3761.                     if ($border == 1{
  3762.                         $cborder 'LTR';
  3763.                     else {
  3764.                         if (!(false === strpos($border'L'))) {
  3765.                             $cborder .= 'L';
  3766.                         }
  3767.                         if (!(false === strpos($border'T'))) {
  3768.                             $cborder .= 'T';
  3769.                         }
  3770.                         if (!(false === strpos($border'R'))) {
  3771.                             $cborder .= 'R';
  3772.                         }
  3773.                         if ((!$this->opencellAND (!(false === strpos($border'B')))) {
  3774.                             $cborder .= 'B';
  3775.                         }
  3776.                     }
  3777.                     break;
  3778.                 }
  3779.                 case 'middle'{
  3780.                     if ($border == 1{
  3781.                         $cborder 'LR';
  3782.                     else {
  3783.                         if (!(false === strpos($border'L'))) {
  3784.                             $cborder .= 'L';
  3785.                         }
  3786.                         if ((!$this->opencellAND (!(false === strpos($border'T')))) {
  3787.                             $cborder .= 'T';
  3788.                         }
  3789.                         if (!(false === strpos($border'R'))) {
  3790.                             $cborder .= 'R';
  3791.                         }
  3792.                         if ((!$this->opencellAND (!(false === strpos($border'B')))) {
  3793.                             $cborder .= 'B';
  3794.                         }
  3795.                     }
  3796.                     break;
  3797.                 }
  3798.                 case 'end'{
  3799.                     if ($border == 1{
  3800.                         $cborder 'LRB';
  3801.                     else {
  3802.                         if (!(false === strpos($border'L'))) {
  3803.                             $cborder .= 'L';
  3804.                         }
  3805.                         if ((!$this->opencellAND (!(false === strpos($border'T')))) {
  3806.                             $cborder .= 'T';
  3807.                         }
  3808.                         if (!(false === strpos($border'R'))) {
  3809.                             $cborder .= 'R';
  3810.                         }
  3811.                         if (!(false === strpos($border'B'))) {
  3812.                             $cborder .= 'B';
  3813.                         }
  3814.                     }
  3815.                     break;
  3816.                 }
  3817.                 default{
  3818.                     $cborder $border;
  3819.                     break;
  3820.                 }
  3821.             }
  3822.             return $cborder;
  3823.         }
  3824.  
  3825.         /**
  3826.         * This method returns the estimated number of lines required to print the text.
  3827.         * @param string $txt text to print
  3828.         * @param float $w width of cell. If 0, they extend up to the right margin of the page.
  3829.         * @return int Return the estimated number of lines.
  3830.         * @access public
  3831.         * @since 4.5.011
  3832.         */
  3833.         public function getNumLines($txt$w=0{
  3834.             $lines 0;
  3835.             if ($this->empty_string($wOR ($w <= 0)) {
  3836.                 if ($this->rtl{
  3837.                     $w $this->x - $this->lMargin;
  3838.                 else {
  3839.                     $w $this->w - $this->rMargin - $this->x;
  3840.                 }
  3841.             }
  3842.             // max column width
  3843.             $wmax $w ($this->cMargin);
  3844.             // remove carriage returns
  3845.             $txt str_replace("\r"''$txt);
  3846.             // remove last newline (if any)
  3847.             if (substr($txt,-1== "\n"{
  3848.                 $txt substr($txt0-1);
  3849.             }
  3850.             // divide text in blocks
  3851.             $txtblocks explode("\n"$txt);
  3852.             // for each block;
  3853.             foreach ($txtblocks as $block{
  3854.                 // estimate the number of lines
  3855.                 $lines += $this->empty_string($block(ceil($this->GetStringWidth($block$wmax));
  3856.             }
  3857.             return $lines;
  3858.         }
  3859.             
  3860.         /**
  3861.         * This method prints text from the current position.<br />
  3862.         * @param float $h Line height
  3863.         * @param string $txt String to print
  3864.         * @param mixed $link URL or identifier returned by AddLink()
  3865.         * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  3866.         * @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>
  3867.         * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  3868.         * @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>
  3869.         * @param boolean $firstline if true prints only the first line and return the remaining string.
  3870.         * @param boolean $firstblock if true the string is the starting of a line.
  3871.         * @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.
  3872.         * @return mixed Return the number of cells or the remaining string if $firstline = true.
  3873.         * @access public
  3874.         * @since 1.5
  3875.         */
  3876.         public function Write($h$txt$link=''$fill=0$align=''$ln=false$stretch=0$firstline=false$firstblock=false$maxh=0{
  3877.             if (strlen($txt== 0{
  3878.                 $txt ' ';
  3879.             }
  3880.             // remove carriage returns
  3881.             $s str_replace("\r"''$txt);
  3882.             // check if string contains arabic text
  3883.             if (preg_match(K_RE_PATTERN_ARABIC$s)) {
  3884.                 $arabic true;
  3885.             else {
  3886.                 $arabic false;
  3887.             }
  3888.             // check if string contains RTL text
  3889.             if ($arabic OR $this->tmprtl OR preg_match(K_RE_PATTERN_RTL$txt)) {
  3890.                 $rtlmode true;
  3891.             else {
  3892.                 $rtlmode false;
  3893.             }
  3894.             // get a char width
  3895.             $chrwidth $this->GetCharWidth('.');
  3896.             // get array of unicode values
  3897.             $chars $this->UTF8StringToArray($s);
  3898.             // get array of chars
  3899.             $uchars $this->UTF8ArrayToUniArray($chars);
  3900.             // get the number of characters
  3901.             $nb count($chars);
  3902.             // replacement for SHY character (minus symbol)
  3903.             $shy_replacement 45;
  3904.             $shy_replacement_char $this->unichr($shy_replacement);
  3905.             // widht for SHY replacement
  3906.             $shy_replacement_width $this->GetCharWidth($shy_replacement);
  3907.             // store current position
  3908.             $prevx $this->x;
  3909.             $prevy $this->y;
  3910.             // max Y
  3911.             $maxy $this->y + $maxh $h ($this->cMargin);
  3912.             // calculate remaining line width ($w)
  3913.             if ($this->rtl{
  3914.                 $w $this->x - $this->lMargin;
  3915.             else {
  3916.                 $w $this->w - $this->rMargin - $this->x;
  3917.             }
  3918.             // max column width
  3919.             $wmax $w ($this->cMargin);
  3920.             $i 0// character position
  3921.             $j 0// current starting position
  3922.             $sep = -1// position of the last blank space
  3923.             $shy false// true if the last blank is a soft hypen (SHY)
  3924.             $l 0// current string lenght
  3925.             $nl 0//number of lines
  3926.             $linebreak false;
  3927.             // for each character
  3928.             while ($i $nb{
  3929.                 if (($maxh 0AND ($this->y >= $maxy) ) {
  3930.                     $firstline true;
  3931.                 }
  3932.                 //Get the current character
  3933.                 $c $chars[$i];
  3934.                 if ($c == 10// 10 = "\n" = new line
  3935.                     //Explicit line break
  3936.                     if ($align == 'J'{
  3937.                         if ($this->rtl{
  3938.                             $talign 'R';
  3939.                         else {
  3940.                             $talign 'L';
  3941.                         }
  3942.                     else {
  3943.                         $talign $align;
  3944.                     }
  3945.                     $tmpstr $this->UniArrSubString($uchars$j$i);
  3946.                     if ($firstline{
  3947.                         $startx $this->x;
  3948.                         $tmparr array_slice($chars$j$i);
  3949.                         if ($rtlmode{
  3950.                             $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  3951.                         }
  3952.                         $linew $this->GetArrStringWidth($tmparr);
  3953.                         unset($tmparr);
  3954.                         if ($this->rtl{
  3955.                             $this->endlinex = $startx $linew;
  3956.                         else {
  3957.                             $this->endlinex = $startx $linew;
  3958.                         }
  3959.                         $w $linew;
  3960.                         $tmpcmargin $this->cMargin;
  3961.                         if ($maxh == 0{
  3962.                             $this->cMargin = 0;
  3963.                         }
  3964.                     }
  3965.                     $this->Cell($w$h$tmpstr01$talign$fill$link$stretch);
  3966.                     unset($tmpstr);
  3967.                     if ($firstline{
  3968.                         $this->cMargin = $tmpcmargin;
  3969.                         return ($this->UniArrSubString($uchars$i));
  3970.                     }
  3971.                     ++$nl;
  3972.                     $j $i 1;
  3973.                     $l 0;
  3974.                     $sep = -1;
  3975.                     $shy false;
  3976.                     // account for margin changes
  3977.                     if ((($this->y + $this->lasth$this->PageBreakTriggerAND (!$this->InFooter)) {
  3978.                         // AcceptPageBreak() may be overriden on extended classed to include margin changes
  3979.                         $this->AcceptPageBreak();
  3980.                     }
  3981.                     $w $this->getRemainingWidth();
  3982.                     $wmax $w ($this->cMargin);
  3983.                 else {
  3984.                     // 160 is the non-breaking space.
  3985.                     // 173 is SHY (Soft Hypen).
  3986.                     // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  3987.                     // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  3988.                     // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  3989.                     if (($c != 160AND (($c == 173OR preg_match('/[\s\p{Z}\p{Lo}]/'$this->unichr($c)))) {
  3990.                         // update last blank space position
  3991.                         $sep $i;
  3992.                         // check if is a SHY
  3993.                         if ($c == 173{
  3994.                             $shy true;
  3995.                         else {
  3996.                             $shy false;
  3997.                         }
  3998.                     }
  3999.                     // update string length
  4000.                     if ((($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) AND ($arabic)) {
  4001.                         // with bidirectional algorithm some chars may be changed affecting the line length
  4002.                         // *** very slow ***
  4003.                         $l $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars$j$i-$j+1)''$this->tmprtl));
  4004.                     else {
  4005.                         $l += $this->GetCharWidth($c);
  4006.                     }
  4007.                     if (($l $wmaxOR ($shy AND (($l $shy_replacement_width$wmax)) ) {
  4008.                         // we have reached the end of column
  4009.                         if ($sep == -1{
  4010.                             // check if the line was already started
  4011.                             if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
  4012.                                 OR ((!$this->rtlAND ($this->x >= ($this->lMargin + $chrwidth)))) {
  4013.                                 // print a void cell and go to next line
  4014.                                 $this->Cell($w$h''01);
  4015.                                 $linebreak true;
  4016.                                 if ($firstline{
  4017.                                     return ($this->UniArrSubString($uchars$j));
  4018.                                 }
  4019.                             else {
  4020.                                 // truncate the word because do not fit on column
  4021.                                 $tmpstr $this->UniArrSubString($uchars$j$i);
  4022.                                 if ($firstline{
  4023.                                     $startx $this->x;
  4024.                                     $tmparr array_slice($chars$j$i);
  4025.                                     if ($rtlmode{
  4026.                                         $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4027.                                     }
  4028.                                     $linew $this->GetArrStringWidth($tmparr);
  4029.                                     unset($tmparr);
  4030.                                     if ($this->rtl{
  4031.                                         $this->endlinex = $startx $linew;
  4032.                                     else {
  4033.                                         $this->endlinex = $startx $linew;
  4034.                                     }
  4035.                                     $w $linew;
  4036.                                     $tmpcmargin $this->cMargin;
  4037.                                     if ($maxh == 0{
  4038.                                         $this->cMargin = 0;
  4039.                                     }
  4040.                                 }
  4041.                                 $this->Cell($w$h$tmpstr01$align$fill$link$stretch);
  4042.                                 unset($tmpstr);
  4043.                                 if ($firstline{
  4044.                                     $this->cMargin = $tmpcmargin;
  4045.                                     return ($this->UniArrSubString($uchars$i));
  4046.                                 }
  4047.                                 $j $i;
  4048.                                 --$i;
  4049.                             }    
  4050.                         else {
  4051.                             // word wrapping
  4052.                             if ($this->rtl AND (!$firstblock)) {
  4053.                                 $endspace 1;
  4054.                             else {
  4055.                                 $endspace 0;
  4056.                             }
  4057.                             if ($shy{
  4058.                                 // add hypen (minus symbol) at the end of the line
  4059.                                 $shy_width $shy_replacement_width;
  4060.                                 if ($this->rtl{
  4061.                                     $shy_char_left $shy_replacement_char;
  4062.                                     $shy_char_right '';
  4063.                                 else {
  4064.                                     $shy_char_left '';
  4065.                                     $shy_char_right $shy_replacement_char;
  4066.                                 }
  4067.                             else {
  4068.                                 $shy_width 0;
  4069.                                 $shy_char_left '';
  4070.                                 $shy_char_right '';
  4071.                             }
  4072.                             $tmpstr $this->UniArrSubString($uchars$j($sep $endspace));
  4073.                             if ($firstline{
  4074.                                 $startx $this->x;
  4075.                                 $tmparr array_slice($chars$j($sep $endspace));
  4076.                                 if ($rtlmode{
  4077.                                     $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4078.                                 }
  4079.                                 $linew $this->GetArrStringWidth($tmparr);
  4080.                                 unset($tmparr);
  4081.                                 if ($this->rtl{
  4082.                                     $this->endlinex = $startx $linew $shy_width;
  4083.                                 else {
  4084.                                     $this->endlinex = $startx $linew $shy_width;
  4085.                                 }
  4086.                                 $w $linew;
  4087.                                 $tmpcmargin $this->cMargin;
  4088.                                 if ($maxh == 0{
  4089.                                     $this->cMargin = 0;
  4090.                                 }
  4091.                             }
  4092.                             // print the line
  4093.                             $this->Cell($w$h$shy_char_left.$tmpstr.$shy_char_right01$align$fill$link$stretch);
  4094.                             unset($tmpstr);
  4095.                             if ($firstline{
  4096.                                 // return the remaining text
  4097.                                 $this->cMargin = $tmpcmargin;
  4098.                                 return ($this->UniArrSubString($uchars($sep $endspace)));
  4099.                             }
  4100.                             $i $sep;
  4101.                             $sep = -1;
  4102.                             $shy false;
  4103.                             $j ($i+1);
  4104.                         }
  4105.                         // account for margin changes
  4106.                         if ((($this->y + $this->lasth$this->PageBreakTriggerAND (!$this->InFooter)) {
  4107.                             // AcceptPageBreak() may be overriden on extended classed to include margin changes
  4108.                             $this->AcceptPageBreak();
  4109.                         }
  4110.                         $w $this->getRemainingWidth();
  4111.                         $wmax $w ($this->cMargin);
  4112.                         if ($linebreak{
  4113.                             $linebreak false;
  4114.                         else {
  4115.                             ++$nl;
  4116.                             $l 0;
  4117.                         }
  4118.                     }
  4119.                 }
  4120.                 ++$i;
  4121.             // end while i < nb
  4122.             // print last substring (if any)
  4123.             if ($l 0{
  4124.                 switch ($align{
  4125.                     case 'J':
  4126.                     case 'C'{
  4127.                         $w $w;
  4128.                         break;
  4129.                     }
  4130.                     case 'L'{
  4131.                         if ($this->rtl{
  4132.                             $w $w;
  4133.                         else {
  4134.                             $w $l;
  4135.                         }
  4136.                         break;
  4137.                     }
  4138.                     case 'R'{
  4139.                         if ($this->rtl{
  4140.                             $w $l;
  4141.                         else {
  4142.                             $w $w;
  4143.                         }
  4144.                         break;
  4145.                     }
  4146.                     default{
  4147.                         $w $l;
  4148.                         break;
  4149.                     }
  4150.                 }
  4151.                 $tmpstr $this->UniArrSubString($uchars$j$nb);
  4152.                 if ($firstline{
  4153.                     $startx $this->x;
  4154.                     $tmparr array_slice($chars$j$nb);
  4155.                     if ($rtlmode{
  4156.                         $tmparr $this->utf8Bidi($tmparr$tmpstr$this->tmprtl);
  4157.                     }
  4158.                     $linew $this->GetArrStringWidth($tmparr);
  4159.                     unset($tmparr);
  4160.                     if ($this->rtl{
  4161.                         $this->endlinex = $startx $linew;
  4162.                     else {
  4163.                         $this->endlinex = $startx $linew;
  4164.                     }
  4165.                     $w $linew;
  4166.                     $tmpcmargin $this->cMargin;
  4167.                     if ($maxh == 0{
  4168.                         $this->cMargin = 0;
  4169.                     }
  4170.                 }
  4171.                 $this->Cell($w$h$tmpstr0$ln$align$fill$link$stretch);
  4172.                 unset($tmpstr);
  4173.                 if ($firstline{
  4174.                     $this->cMargin = $tmpcmargin;
  4175.                     return ($this->UniArrSubString($uchars$nb));
  4176.                 }
  4177.                 ++$nl;
  4178.             }
  4179.             if ($firstline{
  4180.                 return '';
  4181.             }
  4182.             return $nl;
  4183.         }
  4184.                 
  4185.         /**
  4186.         * Returns the remaining width between the current position and margins.
  4187.         * @return int Return the remaining width
  4188.         * @access protected
  4189.         */
  4190.         protected function getRemainingWidth({
  4191.             if ($this->rtl{
  4192.                 return ($this->x - $this->lMargin);
  4193.             else {
  4194.                 return ($this->w - $this->rMargin - $this->x);
  4195.             }
  4196.         }
  4197.  
  4198.          /**
  4199.         * Extract a slice of the $strarr array and return it as string.
  4200.         * @param string $strarr The input array of characters.
  4201.         * @param int $start the starting element of $strarr.
  4202.         * @param int $end first element that will not be returned.
  4203.         * @return Return part of a string
  4204.         * @access public
  4205.         */
  4206.         public function UTF8ArrSubString($strarr$start=''$end=''{
  4207.             if (strlen($start== 0{
  4208.                 $start 0;
  4209.             }
  4210.             if (strlen($end== 0{
  4211.                 $end count($strarr);
  4212.             }
  4213.             $string '';
  4214.             for ($i=$start$i $end++$i{
  4215.                 $string .= $this->unichr($strarr[$i]);
  4216.             }
  4217.             return $string;
  4218.         }
  4219.  
  4220.          /**
  4221.         * Extract a slice of the $uniarr array and return it as string.
  4222.         * @param string $uniarr The input array of characters.
  4223.         * @param int $start the starting element of $strarr.
  4224.         * @param int $end first element that will not be returned.
  4225.         * @return Return part of a string
  4226.         * @access public
  4227.         * @since 4.5.037 (2009-04-07)
  4228.         */
  4229.         public function UniArrSubString($uniarr$start=''$end=''{
  4230.             if (strlen($start== 0{
  4231.                 $start 0;
  4232.             }
  4233.             if (strlen($end== 0{
  4234.                 $end count($uniarr);
  4235.             }
  4236.             $string '';
  4237.             for ($i=$start$i $end++$i{
  4238.                 $string .= $uniarr[$i];
  4239.             }
  4240.             return $string;
  4241.         }
  4242.  
  4243.          /**
  4244.         * Convert an array of UTF8 values to array of unicode characters
  4245.         * @param string $ta The input array of UTF8 values.
  4246.         * @return Return array of unicode characters
  4247.         * @access public
  4248.         * @since 4.5.037 (2009-04-07)
  4249.         */
  4250.         public function UTF8ArrayToUniArray($ta{
  4251.             return array_map(array($this'unichr')$ta);
  4252.         }
  4253.         
  4254.         /**
  4255.         * Returns the unicode caracter specified by UTF-8 code
  4256.         * @param int $c UTF-8 code
  4257.         * @return Returns the specified character.
  4258.         * @author Miguel Perez, Nicola Asuni
  4259.         * @access public
  4260.         * @since 2.3.000 (2008-03-05)
  4261.         */
  4262.         public function unichr($c{
  4263.             if (!$this->isunicode{
  4264.                 return chr($c);
  4265.             elseif ($c <= 0x7F{
  4266.                 // one byte
  4267.                 return chr($c);
  4268.             elseif ($c <= 0x7FF{
  4269.                 // two bytes
  4270.                 return chr(0xC0 $c >> 6).chr(0x80 $c 0x3F);
  4271.             elseif ($c <= 0xFFFF{
  4272.                 // three bytes
  4273.                 return chr(0xE0 $c >> 12).chr(0x80 $c >> 0x3F).chr(0x80 $c 0x3F);
  4274.             elseif ($c <= 0x10FFFF{
  4275.                 // four bytes
  4276.                 return chr(0xF0 $c >> 18).chr(0x80 $c >> 12 0x3F).chr(0x80 $c >> 0x3F).chr(0x80 $c 0x3F);
  4277.             else {
  4278.                 return '';
  4279.             }
  4280.         }
  4281.         
  4282.         /**
  4283.         * Puts an image in the page.
  4284.         * The upper-left corner must be given.
  4285.         * The dimensions can be specified in different ways:<ul>
  4286.         * <li>explicit width and height (expressed in user unit)</li>
  4287.         * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  4288.         * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  4289.         * 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;
  4290.         * The format can be specified explicitly or inferred from the file extension.<br />
  4291.         * It is possible to put a link on the image.<br />
  4292.         * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  4293.         * @param string $file Name of the file containing the image.
  4294.         * @param float $x Abscissa of the upper-left corner.
  4295.         * @param float $y Ordinate of the upper-left corner.
  4296.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4297.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4298.         * @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.
  4299.         * @param mixed $link URL or identifier returned by AddLink().
  4300.         * @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>
  4301.         * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  4302.         * @param int $dpi dot-per-inch resolution used on resize
  4303.         * @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>
  4304.         * @param boolean $ismask true if this image is a mask, false otherwise
  4305.         * @param mixed $imgmask image object returned by this function or false
  4306.         * @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>
  4307.         * @return image information
  4308.         * @access public
  4309.         * @since 1.1
  4310.         */
  4311.         public function Image($file$x=''$y=''$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''$ismask=false$imgmask=false$border=0{
  4312.             if ($x === ''{
  4313.                 $x $this->x;
  4314.             }
  4315.             if ($y === ''{
  4316.                 $y $this->y;
  4317.             }
  4318.             // get image dimensions
  4319.             $imsize @getimagesize($file);
  4320.             if ($imsize === FALSE{
  4321.                 // encode spaces on filename
  4322.                 $file str_replace(' ''%20'$file);
  4323.                 $imsize @getimagesize($file);
  4324.                 if ($imsize === FALSE{
  4325.                     $this->Error('[Image] No such file or directory in '.$file);
  4326.                 }
  4327.             }
  4328.             // get original image width and height in pixels
  4329.             list($pixw$pixh$imsize;
  4330.             // calculate image width and height on document
  4331.             if (($w <= 0AND ($h <= 0)) {
  4332.                 // convert image size to document unit
  4333.                 $w $pixw ($this->imgscale * $this->k);
  4334.                 $h $pixh ($this->imgscale * $this->k);
  4335.             elseif ($w <= 0{
  4336.                 $w $h $pixw $pixh;
  4337.             elseif ($h <= 0{
  4338.                 $h $w $pixh $pixw;
  4339.             }
  4340.             // calculate new minimum dimensions in pixels
  4341.             $neww round($w $this->k * $dpi $this->dpi);
  4342.             $newh round($h $this->k * $dpi $this->dpi);
  4343.             // check if resize is necessary (resize is used only to reduce the image)
  4344.             if (($neww $newh>= ($pixw $pixh)) {
  4345.                 $resize false;
  4346.             }
  4347.             // check if image has been already added on document
  4348.             if (!in_array($file$this->imagekeys)) {
  4349.                 //First use of image, get info
  4350.                 if ($type == ''{
  4351.                     $fileinfo pathinfo($file);
  4352.                     if (isset($fileinfo['extension']AND (!$this->empty_string($fileinfo['extension']))) {
  4353.                         $type $fileinfo['extension'];
  4354.                     else {
  4355.                         $this->Error('Image file has no extension and no type was specified: '.$file);
  4356.                     }
  4357.                 }
  4358.                 $type strtolower($type);
  4359.                 if ($type == 'jpg'{
  4360.                     $type 'jpeg';
  4361.                 }
  4362.                 $mqr get_magic_quotes_runtime();
  4363.                 set_magic_quotes_runtime(0);
  4364.                 // Specific image handlers
  4365.                 $mtd '_parse'.$type;
  4366.                 // GD image handler function
  4367.                 $gdfunction 'imagecreatefrom'.$type;
  4368.                 $info false;
  4369.                 if ((method_exists($this$mtd)) AND (!($resize AND function_exists($gdfunction)))) {
  4370.                     // TCPDF image functions
  4371.                     $info $this->$mtd($file);
  4372.                     if ($info == 'pngalpha'{
  4373.                         return $this->ImagePngAlpha($file$x$y$w$h'PNG'$link$align$resize$dpi$palign);
  4374.                     }
  4375.                 
  4376.                 if (!$info{
  4377.                     if (function_exists($gdfunction)) {
  4378.                         // GD library
  4379.                         $img $gdfunction($file);
  4380.                         if ($resize{
  4381.                             $imgr imagecreatetruecolor($neww$newh);
  4382.                             imagecopyresampled($imgr$img0000$neww$newh$pixw$pixh)
  4383.                             $info $this->_toJPEG($imgr);
  4384.                         else {
  4385.                             $info $this->_toJPEG($img);
  4386.                         }
  4387.                     elseif (extension_loaded('imagick')) {
  4388.                         // ImageMagick library
  4389.                         $img new Imagick();
  4390.                         $img->readImage($file);
  4391.                         if ($resize{
  4392.                             $img->resizeImage($neww$newh101false);
  4393.                         }
  4394.                         $img->setCompressionQuality($this->jpeg_quality);
  4395.                         $img->setImageFormat('jpeg');
  4396.                         $tempname tempnam(K_PATH_CACHE'jpg_');
  4397.                         $img->writeImage($tempname);
  4398.                         $info $this->_parsejpeg($tempname);
  4399.                         unlink($tempname);
  4400.                         $img->destroy();
  4401.                     else {
  4402.                         return;
  4403.                     }
  4404.                 }
  4405.                 if ($info === false{
  4406.                     //If false, we cannot process image
  4407.                     return;
  4408.                 }
  4409.                 set_magic_quotes_runtime($mqr);
  4410.                 if ($ismask{
  4411.                     // force grayscale
  4412.                     $info['cs''DeviceGray';
  4413.                 }
  4414.                 $info['i'$this->numimages + 1;
  4415.                 if ($imgmask !== false{
  4416.                     $info['masked'$imgmask;
  4417.                 }
  4418.                 // add image to document
  4419.                 $this->setImageBuffer($file$info);
  4420.             else {
  4421.                 $info $this->getImageBuffer($file);
  4422.             }
  4423.             // Check whether we need a new page first as this does not fit
  4424.             if ((($y $h$this->PageBreakTriggerAND (!$this->InFooterAND $this->AcceptPageBreak()) {
  4425.                 // Automatic page break
  4426.                 $this->AddPage($this->CurOrientation);
  4427.                 // Reset Y coordinate to the top of next page
  4428.                 $y $this->GetY($this->cMargin;
  4429.             }
  4430.             // set bottomcoordinates
  4431.             $this->img_rb_y = $y $h;
  4432.             // set alignment
  4433.             if ($this->rtl{
  4434.                 if ($palign == 'L'{
  4435.                     $ximg $this->lMargin;
  4436.                     // set right side coordinate
  4437.                     $this->img_rb_x = $ximg $w;
  4438.                 elseif ($palign == 'C'{
  4439.                     $ximg ($this->w - $x $w2;
  4440.                     // set right side coordinate
  4441.                     $this->img_rb_x = $ximg $w;
  4442.                 else {
  4443.                     $ximg $this->w - $x $w;
  4444.                     // set left side coordinate
  4445.                     $this->img_rb_x = $ximg;
  4446.                 }
  4447.             else {
  4448.                 if ($palign == 'R'{
  4449.                     $ximg $this->w - $this->rMargin - $w;
  4450.                     // set left side coordinate
  4451.                     $this->img_rb_x = $ximg;
  4452.                 elseif ($palign == 'C'{
  4453.                     $ximg ($this->w - $x $w2;
  4454.                     // set right side coordinate
  4455.                     $this->img_rb_x = $ximg $w;
  4456.                 else {
  4457.                     $ximg $x;
  4458.                     // set right side coordinate
  4459.                     $this->img_rb_x = $ximg $w;
  4460.                 }
  4461.             }
  4462.             if ($ismask{
  4463.                 // embed hidden, ouside the canvas
  4464.                 $xkimg ($this->pagedim[$this->page]['w'10);
  4465.             else {
  4466.                 $xkimg $ximg $this->k;
  4467.             }
  4468.             $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']));
  4469.             if (!empty($border)) {
  4470.                 $bx $x;
  4471.                 $by $y;
  4472.                 $this->x = $ximg;
  4473.                 $this->y = $y;
  4474.                 $this->Cell($w$h''$border0''0''0);
  4475.                 $this->x = $bx;
  4476.                 $this->y = $by;
  4477.             }
  4478.             if ($link{
  4479.                 $this->Link($ximg$y$w$h$link0);
  4480.             }
  4481.             // set pointer to align the successive text/objects
  4482.             switch($align{
  4483.                 case 'T'{
  4484.                     $this->y = $y;
  4485.                     $this->x = $this->img_rb_x;
  4486.                     break;
  4487.                 }
  4488.                 case 'M'{
  4489.                     $this->y = $y round($h/2);
  4490.                     $this->x = $this->img_rb_x;
  4491.                     break;
  4492.                 }
  4493.                 case 'B'{
  4494.                     $this->y = $this->img_rb_y;
  4495.                     $this->x = $this->img_rb_x;
  4496.                     break;
  4497.                 }
  4498.                 case 'N'{
  4499.                     $this->SetY($this->img_rb_y);
  4500.                     break;
  4501.                 }
  4502.                 default:{
  4503.                     break;
  4504.                 }
  4505.             }
  4506.             $this->endlinex = $this->img_rb_x;
  4507.             return $info['i'];
  4508.         }
  4509.                 
  4510.         /**
  4511.         * Convert the loaded php image to a JPEG and then return a structure for the PDF creator.
  4512.         * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  4513.         * @param string $file Image file name.
  4514.         * @param image $image Image object.
  4515.         *  return image JPEG image object.
  4516.         * @access protected
  4517.         */
  4518.         protected function _toJPEG($image{
  4519.             $tempname tempnam(K_PATH_CACHE'jpg_');
  4520.             imagejpeg($image$tempname$this->jpeg_quality);
  4521.             imagedestroy($image);
  4522.             $retvars $this->_parsejpeg($tempname);
  4523.             // tidy up by removing temporary image
  4524.             unlink($tempname);
  4525.             return $retvars;
  4526.         }
  4527.         
  4528.         /**
  4529.         * Extract info from a JPEG file without using the GD library.
  4530.         * @param string $file image file to parse
  4531.         * @return array structure containing the image data
  4532.         * @access protected
  4533.         */
  4534.         protected function _parsejpeg($file{
  4535.             $a getimagesize($file);
  4536.             if (empty($a)) {
  4537.                 $this->Error('Missing or incorrect image file: '.$file);
  4538.             }
  4539.             if ($a[2!= 2{
  4540.                 $this->Error('Not a JPEG file: '.$file);
  4541.             }
  4542.             if ((!isset($a['channels'])) OR ($a['channels'== 3)) {
  4543.                 $colspace 'DeviceRGB';
  4544.             elseif ($a['channels'== 4{
  4545.                 $colspace 'DeviceCMYK';
  4546.             else {
  4547.                 $colspace 'DeviceGray';
  4548.             }
  4549.             $bpc = isset($a['bits']$a['bits'8;
  4550.             $data file_get_contents($file);
  4551.             return array('w' => $a[0]'h' => $a[1]'cs' => $colspace'bpc' => $bpc'f' => 'DCTDecode''data' => $data);
  4552.         }
  4553.  
  4554.         /**
  4555.         * Extract info from a PNG file without using the GD library.
  4556.         * @param string $file image file to parse
  4557.         * @return array structure containing the image data
  4558.         * @access protected
  4559.         */
  4560.         protected function _parsepng($file{
  4561.             $f fopen($file'rb');
  4562.             if ($f === false{
  4563.                 $this->Error('Can\'t open image file: '.$file);
  4564.             }
  4565.             //Check signature
  4566.             if (fread($f8!= chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  4567.                 $this->Error('Not a PNG file: '.$file);
  4568.             }
  4569.             //Read header chunk
  4570.             fread($f4);
  4571.             if (fread($f4!= 'IHDR'{
  4572.                 $this->Error('Incorrect PNG file: '.$file);
  4573.             }
  4574.             $w $this->_freadint($f);
  4575.             $h $this->_freadint($f);
  4576.             $bpc ord(fread($f1));
  4577.             if ($bpc 8{
  4578.                 //$this->Error('16-bit depth not supported: '.$file);
  4579.                 fclose($f);
  4580.                 return false;
  4581.             }
  4582.             $ct ord(fread($f1));
  4583.             if ($ct == 0{
  4584.                 $colspace 'DeviceGray';
  4585.             elseif ($ct == 2{
  4586.                 $colspace 'DeviceRGB';
  4587.             elseif ($ct == 3{
  4588.                 $colspace 'Indexed';
  4589.             else {
  4590.                 // alpha channel
  4591.                 fclose($f);
  4592.                 return 'pngalpha';
  4593.             }
  4594.             if (ord(fread($f1)) != 0{
  4595.                 //$this->Error('Unknown compression method: '.$file);
  4596.                 fclose($f);
  4597.                 return false;
  4598.             }
  4599.             if (ord(fread($f1)) != 0{
  4600.                 //$this->Error('Unknown filter method: '.$file);
  4601.                 fclose($f);
  4602.                 return false;
  4603.             }
  4604.             if (ord(fread($f1)) != 0{
  4605.                 //$this->Error('Interlacing not supported: '.$file);
  4606.                 fclose($f);
  4607.                 return false;
  4608.             }
  4609.             fread($f4);
  4610.             $parms '/DecodeParms <</Predictor 15 /Colors '.($ct==1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  4611.             //Scan chunks looking for palette, transparency and image data
  4612.             $pal '';
  4613.             $trns '';
  4614.             $data '';
  4615.             do {
  4616.                 $n $this->_freadint($f);
  4617.                 $type fread($f4);
  4618.                 if ($type == 'PLTE'{
  4619.                     //Read palette
  4620.                     $pal $this->rfread($f$n);
  4621.                     fread($f4);
  4622.                 elseif ($type == 'tRNS'{
  4623.                     //Read transparency info
  4624.                     $t $this->rfread($f$n);
  4625.                     if ($ct == 0{
  4626.                         $trns array(ord(substr($t11)));
  4627.                     elseif ($ct == 2{
  4628.                         $trns array(ord(substr($t11))ord(substr($t31))ord(substr($t51)));
  4629.                     else {
  4630.                         $pos strpos($tchr(0));
  4631.                         if ($pos !== false{
  4632.                             $trns array($pos);
  4633.                         }
  4634.                     }
  4635.                     fread($f4);
  4636.                 elseif ($type == 'IDAT'{
  4637.                     //Read image data block
  4638.                     $data .= $this->rfread($f$n);
  4639.                     fread($f4);
  4640.                 elseif ($type == 'IEND'{
  4641.                     break;
  4642.                 else {
  4643.                     $this->rfread($f$n 4);
  4644.                 }
  4645.             while ($n);
  4646.             if (($colspace == 'Indexed'AND (empty($pal))) {
  4647.                 //$this->Error('Missing palette in '.$file);
  4648.                 fclose($f);
  4649.                 return false;
  4650.             }
  4651.             fclose($f);
  4652.             return array('w' => $w'h' => $h'cs' => $colspace'bpc' => $bpc'f' => 'FlateDecode''parms' => $parms'pal' => $pal'trns' => $trns'data' => $data);
  4653.         }
  4654.  
  4655.         /**
  4656.         * Binary-safe and URL-safe file read.
  4657.         * 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.
  4658.         * @param resource $handle 
  4659.         * @param int $length 
  4660.         * @return Returns the read string or FALSE in case of error.
  4661.         * @author Nicola Asuni
  4662.         * @access protected
  4663.         * @since 4.5.027 (2009-03-16)
  4664.         */
  4665.         protected function rfread($handle$length{
  4666.             $data fread($handle$length);
  4667.             if ($data === false{
  4668.                 return false;
  4669.             }
  4670.             $rest $length strlen($data);
  4671.             if ($rest 0{
  4672.                 $data .= $this->rfread($handle$rest);
  4673.             }
  4674.             return $data;
  4675.         }
  4676.  
  4677.         /**
  4678.         * Extract info from a PNG image with alpha channel using the GD library.
  4679.         * @param string $file Name of the file containing the image.
  4680.         * @param float $x Abscissa of the upper-left corner.
  4681.         * @param float $y Ordinate of the upper-left corner.
  4682.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4683.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  4684.         * @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.
  4685.         * @param mixed $link URL or identifier returned by AddLink().
  4686.         * @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>
  4687.         * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  4688.         * @param int $dpi dot-per-inch resolution used on resize
  4689.         * @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>
  4690.         * @author Valentin Schmidt, Nicola Asuni
  4691.         * @access protected
  4692.         * @since 4.3.007 (2008-12-04)
  4693.         * @see Image()
  4694.         */
  4695.         protected function ImagePngAlpha($file$x=''$y=''$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''{
  4696.             // get image size
  4697.             list($wpx$hpxgetimagesize($file);
  4698.             // generate images
  4699.             $img imagecreatefrompng($file);
  4700.             $imgalpha imagecreate($wpx$hpx);
  4701.             // generate gray scale pallete
  4702.             for($c 0$c 256++$c{
  4703.                 ImageColorAllocate($imgalpha$c$c$c);
  4704.             }
  4705.             // extract alpha channel
  4706.             for ($xpx 0$xpx $wpx++$xpx{
  4707.                 for ($ypx 0$ypx $hpx++$ypx{
  4708.                     $colorindex imagecolorat($img$xpx$ypx);
  4709.                     $col imagecolorsforindex($img$colorindex);
  4710.                     imagesetpixel($imgalpha$xpx$ypx$this->getGDgamma((127 $col['alpha']255 127));
  4711.                 }
  4712.             }
  4713.             // create temp alpha file
  4714.             $tempfile_alpha tempnam(K_PATH_CACHE'mska_');
  4715.             imagepng($imgalpha$tempfile_alpha);
  4716.             imagedestroy($imgalpha);
  4717.             // extract image without alpha channel
  4718.             $imgplain imagecreatetruecolor($wpx$hpx);
  4719.             imagecopy($imgplain$img0000$wpx$hpx);
  4720.             // create temp image file
  4721.             $tempfile_plain tempnam(K_PATH_CACHE'mskp_');
  4722.             imagepng($imgplain$tempfile_plain);
  4723.             imagedestroy($imgplain);
  4724.             // embed mask image
  4725.             $imgmask $this->Image($tempfile_alpha$x$y$w$h'PNG'''''$resize$dpi''truefalse);
  4726.             // embed image, masked with previously embedded mask
  4727.             $this->Image($tempfile_plain$x$y$w$h$type$link$align$resize$dpi$palignfalse$imgmask);
  4728.             // remove temp files
  4729.             unlink($tempfile_alpha);
  4730.             unlink($tempfile_plain);
  4731.         }
  4732.  
  4733.         /**
  4734.         * Correct the gamma value to be used with GD library
  4735.         * @param float $v the gamma value to be corrected
  4736.         * @access protected
  4737.         * @since 4.3.007 (2008-12-04)
  4738.         */
  4739.         protected function getGDgamma($v{
  4740.             return (pow(($v 255)2.2255);
  4741.         
  4742.         
  4743.         /**
  4744.         * Performs a line break.
  4745.         * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  4746.         * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  4747.         * @param boolean $cell if true add a cMargin to the x coordinate
  4748.         * @access public
  4749.         * @since 1.0
  4750.         * @see Cell()
  4751.         */
  4752.         public function Ln($h=''$cell=false{
  4753.             //Line feed; default value is last cell height
  4754.             if ($cell{
  4755.                 $cellmargin $this->cMargin;
  4756.             else {
  4757.                 $cellmargin 0;
  4758.             }
  4759.             if ($this->rtl{
  4760.                 $this->x = $this->w - $this->rMargin - $cellmargin;
  4761.             else {
  4762.                 $this->x = $this->lMargin + $cellmargin;
  4763.             }
  4764.             if (is_string($h)) {
  4765.                 $this->y += $this->lasth;
  4766.             else {
  4767.                 $this->y += $h;
  4768.             }
  4769.             $this->newline = true;
  4770.         }
  4771.  
  4772.         /**
  4773.         * Returns the relative X value of current position.
  4774.         * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  4775.         * @return float 
  4776.         * @access public
  4777.         * @since 1.2
  4778.         * @see SetX(), GetY(), SetY()
  4779.         */
  4780.         public function GetX({
  4781.             //Get x position
  4782.             if ($this->rtl{
  4783.                 return ($this->w - $this->x);
  4784.             else {
  4785.                 return $this->x;
  4786.             }
  4787.         }
  4788.         
  4789.         /**
  4790.         * Returns the absolute X value of current position.
  4791.         * @return float 
  4792.         * @access public
  4793.         * @since 1.2
  4794.         * @see SetX(), GetY(), SetY()
  4795.         */
  4796.         public function GetAbsX({
  4797.             return $this->x;
  4798.         }
  4799.         
  4800.         /**
  4801.         * Returns the ordinate of the current position.
  4802.         * @return float 
  4803.         * @access public
  4804.         * @since 1.0
  4805.         * @see SetY(), GetX(), SetX()
  4806.         */
  4807.         public function GetY({
  4808.             //Get y position
  4809.             return $this->y;
  4810.         }
  4811.         
  4812.         /**
  4813.         * Defines the abscissa of the current position.
  4814.         * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  4815.         * @param float $x The value of the abscissa.
  4816.         * @access public
  4817.         * @since 1.2
  4818.         * @see GetX(), GetY(), SetY(), SetXY()
  4819.         */
  4820.         public function SetX($x{
  4821.             //Set x position
  4822.             if ($this->rtl{
  4823.                 if ($x >= 0{
  4824.                     $this->x = $this->w - $x;
  4825.                 else {
  4826.                     $this->x = abs($x);
  4827.                 }
  4828.             else {
  4829.                 if ($x >= 0{
  4830.                     $this->x = $x;
  4831.                 else {
  4832.                     $this->x = $this->w + $x;
  4833.                 }
  4834.             }
  4835.             if ($this->x < 0{
  4836.                 $this->x = 0;
  4837.             }
  4838.             if ($this->x > $this->w{
  4839.                 $this->x = $this->w;
  4840.             }
  4841.         }
  4842.         
  4843.         /**
  4844.         * Moves the current abscissa back to the left margin and sets the ordinate.
  4845.         * If the passed value is negative, it is relative to the bottom of the page.
  4846.         * @param float $y The value of the ordinate.
  4847.         * @param bool $resetx if true (default) reset the X position.
  4848.         * @access public
  4849.         * @since 1.0
  4850.         * @see GetX(), GetY(), SetY(), SetXY()
  4851.         */
  4852.         public function SetY($y$resetx=true{
  4853.             if ($resetx{
  4854.                 //reset x
  4855.                 if ($this->rtl{
  4856.                     $this->x = $this->w - $this->rMargin;
  4857.                 else {
  4858.                     $this->x = $this->lMargin;
  4859.                 }
  4860.             }
  4861.             if ($y >= 0{
  4862.                 $this->y = $y;
  4863.             else {
  4864.                 $this->y = $this->h + $y;
  4865.             }
  4866.             if ($this->y < 0{
  4867.                 $this->y = 0;
  4868.             }
  4869.             if ($this->y > $this->h{
  4870.                 $this->y = $this->h;
  4871.             }
  4872.         }
  4873.         
  4874.         /**
  4875.         * Defines the abscissa and ordinate of the current position.
  4876.         * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  4877.         * @param float $x The value of the abscissa
  4878.         * @param float $y The value of the ordinate
  4879.         * @access public
  4880.         * @since 1.2
  4881.         * @see SetX(), SetY()
  4882.         */
  4883.         public function SetXY($x$y{
  4884.             //Set x and y positions
  4885.             $this->SetY($y);
  4886.             $this->SetX($x);
  4887.         }
  4888.  
  4889.         /**
  4890.         * Send the document to a given destination: string, local file or browser.
  4891.         * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  4892.         * The method first calls Close() if necessary to terminate the document.
  4893.         * @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.
  4894.         * @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>
  4895.         * @access public
  4896.         * @since 1.0
  4897.         * @see Close()
  4898.         */
  4899.         public function Output($name='doc.pdf'$dest='I'{
  4900.             //Output PDF to some destination
  4901.             //Finish document if necessary
  4902.             if ($this->state < 3{
  4903.                 $this->Close();
  4904.             }
  4905.             //Normalize parameters
  4906.             if (is_bool($dest)) {
  4907.                 $dest $dest 'D' 'F';
  4908.             }
  4909.             $dest strtoupper($dest);
  4910.             if ($dest != 'F'{
  4911.                 $name preg_replace('/[\s]+/''_'$name);
  4912.                 $name preg_replace('/[^a-zA-Z0-9_\.-]/'''$name);
  4913.             }
  4914.             switch($dest{
  4915.                 case 'I'{
  4916.                     // Send PDF to the standard output
  4917.                     if (ob_get_contents()) {
  4918.                         $this->Error('Some data has already been output, can\'t send PDF file');
  4919.                     }
  4920.                     if (php_sapi_name(!= 'cli'{
  4921.                         //We send to a browser
  4922.                         header('Content-Type: application/pdf');
  4923.                         if (headers_sent()) {
  4924.                             $this->Error('Some data has already been output to browser, can\'t send PDF file');
  4925.                         }
  4926.                         header('Cache-Control: public, must-revalidate, max-age=0')// HTTP/1.1
  4927.                         header('Pragma: public');
  4928.                         header('Expires: Sat, 26 Jul 1997 05:00:00 GMT')// Date in the past
  4929.                         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');    
  4930.                         header('Content-Length: '.$this->bufferlen);
  4931.                         header('Content-Disposition: inline; filename="'.basename($name).'";');
  4932.                     }
  4933.                     echo $this->getBuffer();
  4934.                     break;
  4935.                 }
  4936.                 case 'D'{
  4937.                     // Download PDF as file
  4938.                     if (ob_get_contents()) {
  4939.                         $this->Error('Some data has already been output, can\'t send PDF file');
  4940.                     }
  4941.                     header('Content-Description: File Transfer');
  4942.                     if (headers_sent()) {
  4943.                         $this->Error('Some data has already been output to browser, can\'t send PDF file');
  4944.                     }
  4945.                     header('Cache-Control: public, must-revalidate, max-age=0')// HTTP/1.1
  4946.                     header('Pragma: public');
  4947.                     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT')// Date in the past
  4948.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  4949.                     // force download dialog
  4950.                     header('Content-Type: application/force-download');
  4951.                     header('Content-Type: application/octet-stream'false);
  4952.                     header('Content-Type: application/download'false);
  4953.                     header('Content-Type: application/pdf'false);
  4954.                     // use the Content-Disposition header to supply a recommended filename
  4955.                     header('Content-Disposition: attachment; filename="'.basename($name).'";');
  4956.                     header('Content-Transfer-Encoding: binary');
  4957.                     header('Content-Length: '.$this->bufferlen);
  4958.                     echo $this->getBuffer();
  4959.                     break;
  4960.                 }
  4961.                 case 'F'{
  4962.                     // Save PDF to a local file
  4963.                     if ($this->diskcache{
  4964.                         copy($this->buffer$name);
  4965.                     else {
  4966.                         $f fopen($name'wb');
  4967.                         if (!$f{
  4968.                             $this->Error('Unable to create output file: '.$name);
  4969.                         }
  4970.                         fwrite($f$this->getBuffer()$this->bufferlen);
  4971.                         fclose($f);
  4972.                     }
  4973.                     break;
  4974.                 }
  4975.                 case 'S'{
  4976.                     // Returns PDF as a string
  4977.                     return $this->getBuffer();
  4978.                 }
  4979.                 default{
  4980.                     $this->Error('Incorrect output destination: '.$dest);
  4981.                 }
  4982.             }
  4983.             return '';
  4984.         }
  4985.  
  4986.         /**
  4987.          * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  4988.          * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  4989.          * @param boolean $preserve_objcopy if true preserves the objcopy variable
  4990.          * @access public
  4991.          * @since 4.5.016 (2009-02-24)
  4992.          */
  4993.         public function _destroy($destroyall=false$preserve_objcopy=false{
  4994.             if ($destroyall AND isset($this->diskcacheAND $this->diskcache AND (!$preserve_objcopyAND (!$this->empty_string($this->buffer))) {
  4995.                 // remove buffer file from cache
  4996.                 unlink($this->buffer);
  4997.             }
  4998.             foreach (array_keys(get_object_vars($this)) as $val{
  4999.                 if ($destroyall OR (($val != 'internal_encoding'AND ($val != 'state'AND ($val != 'bufferlen'AND ($val != 'buffer'AND ($val != 'diskcache'))) {
  5000.                     if (!$preserve_objcopy OR ($val != 'objcopy')) {
  5001.                         unset($this->$val);
  5002.                     }
  5003.                 }
  5004.             }
  5005.         }
  5006.         
  5007.         /**
  5008.         * Check for locale-related bug
  5009.         * @access protected
  5010.         */
  5011.         protected function _dochecks({
  5012.             //Check for locale-related bug
  5013.             if (1.1 == 1{
  5014.                 $this->Error('Don\'t alter the locale before including class file');
  5015.             }
  5016.             //Check for decimal separator
  5017.             if (sprintf('%.1F'1.0!= '1.0'{
  5018.                 setlocale(LC_NUMERIC'C');
  5019.             }
  5020.         }
  5021.  
  5022.         /**
  5023.         * Return fonts path
  5024.         * @return string 
  5025.         * @access protected
  5026.         */
  5027.         protected function _getfontpath({
  5028.             if (!defined('K_PATH_FONTS'AND is_dir(dirname(__FILE__).'/fonts')) {
  5029.                 define('K_PATH_FONTS'dirname(__FILE__).'/fonts/');
  5030.             }
  5031.             return defined('K_PATH_FONTS'K_PATH_FONTS '';
  5032.         }
  5033.         
  5034.         /**
  5035.         * Output pages.
  5036.         * @access protected
  5037.         */
  5038.         protected function _putpages({
  5039.             $nb $this->numpages;
  5040.             if (!empty($this->AliasNbPages)) {
  5041.                 $nbs $this->formatPageNumber($nb);
  5042.                 $nbu $this->UTF8ToUTF16BE($nbsfalse)// replacement for unicode font
  5043.                 $alias_a $this->_escape($this->AliasNbPages);
  5044.                 $alias_au $this->_escape('{'.$this->AliasNbPages.'}');
  5045.                 if ($this->isunicode{
  5046.                     $alias_b $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  5047.                     $alias_bu $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages.'}'));
  5048.                     $alias_c $this->_escape($this->utf8StrRev($this->AliasNbPagesfalse$this->tmprtl));
  5049.                     $alias_cu $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages.'}'false$this->tmprtl));
  5050.                 }
  5051.             }
  5052.             if (!empty($this->AliasNumPage)) {
  5053.                 $alias_pa $this->_escape($this->AliasNumPage);
  5054.                 $alias_pau $this->_escape('{'.$this->AliasNumPage.'}');
  5055.                 if ($this->isunicode{
  5056.                     $alias_pb $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  5057.                     $alias_pbu $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage.'}'));
  5058.                     $alias_pc $this->_escape($this->utf8StrRev($this->AliasNumPagefalse$this->tmprtl));
  5059.                     $alias_pcu $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage.'}'false$this->tmprtl));
  5060.                 }
  5061.             }
  5062.             $pagegroupnum 0;
  5063.             $filter ($this->compress'/Filter /FlateDecode ' '';
  5064.             for($n=1$n <= $nb++$n{
  5065.                 $temppage $this->getPageBuffer($n);
  5066.                 if (!empty($this->pagegroups)) {
  5067.                     if(isset($this->newpagegroup[$n])) {
  5068.                         $pagegroupnum 0;
  5069.                     }
  5070.                     ++$pagegroupnum;
  5071.                     foreach ($this->pagegroups as $k => $v{
  5072.                         // replace total pages group numbers
  5073.                         $vs $this->formatPageNumber($v);
  5074.                         $vu $this->UTF8ToUTF16BE($vsfalse);
  5075.                         $alias_ga $this->_escape($k);
  5076.                         $alias_gau $this->_escape('{'.$k.'}');
  5077.                         if ($this->isunicode{
  5078.                             $alias_gb $this->_escape($this->UTF8ToLatin1($k));
  5079.                             $alias_gbu $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
  5080.                             $alias_gc $this->_escape($this->utf8StrRev($kfalse$this->tmprtl));
  5081.                             $alias_gcu $this->_escape($this->utf8StrRev('{'.$k.'}'false$this->tmprtl));
  5082.                         }
  5083.                         $temppage str_replace($alias_gau$vu$temppage);
  5084.                         if ($this->isunicode{
  5085.                             $temppage str_replace($alias_gbu$vu$temppage);
  5086.                             $temppage str_replace($alias_gcu$vu$temppage);
  5087.                             $temppage str_replace($alias_gb$vs$temppage);
  5088.                             $temppage str_replace($alias_gc$vs$temppage);
  5089.                         }
  5090.                         $temppage str_replace($alias_ga$vs$temppage);
  5091.                         // replace page group numbers
  5092.                         $pvs $this->formatPageNumber($pagegroupnum);
  5093.                         $pvu $this->UTF8ToUTF16BE($pvsfalse);
  5094.                         $pk str_replace('{nb''{pnb'$k);
  5095.                         $alias_pga $this->_escape($pk);
  5096.                         $alias_pgau $this->_escape('{'.$pk.'}');
  5097.                         if ($this->isunicode{
  5098.                             $alias_pgb $this->_escape($this->UTF8ToLatin1($pk));
  5099.                             $alias_pgbu $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
  5100.                             $alias_pgc $this->_escape($this->utf8StrRev($pkfalse$this->tmprtl));
  5101.                             $alias_pgcu $this->_escape($this->utf8StrRev('{'.$pk.'}'false$this->tmprtl));
  5102.                         }
  5103.                         $temppage str_replace($alias_pgau$pvu$temppage);
  5104.                         if ($this->isunicode{
  5105.                             $temppage str_replace($alias_pgbu$pvu$temppage);
  5106.                             $temppage str_replace($alias_pgcu$pvu$temppage);
  5107.                             $temppage str_replace($alias_pgb$pvs$temppage);
  5108.                             $temppage str_replace($alias_pgc$pvs$temppage);
  5109.                         }
  5110.                         $temppage str_replace($alias_pga$pvs$temppage);
  5111.                     }
  5112.                 }
  5113.                 if (!empty($this->AliasNbPages)) {
  5114.                     // replace total pages number
  5115.                     $temppage str_replace($alias_au$nbu$temppage);
  5116.                     if ($this->isunicode{
  5117.                         $temppage str_replace($alias_bu$nbu$temppage);
  5118.                         $temppage str_replace($alias_cu$nbu$temppage);
  5119.                         $temppage str_replace($alias_b$nbs$temppage);
  5120.                         $temppage str_replace($alias_c$nbs$temppage);
  5121.                     }
  5122.                     $temppage str_replace($alias_a$nbs$temppage);
  5123.                 }
  5124.                 if (!empty($this->AliasNumPage)) {
  5125.                     // replace page number
  5126.                     $pnbs $this->formatPageNumber($n);
  5127.                     $pnbu $this->UTF8ToUTF16BE($pnbsfalse)// replacement for unicode font
  5128.                     $temppage str_replace($alias_pau$pnbu$temppage);
  5129.                     if ($this->isunicode{
  5130.                         $temppage str_replace($alias_pbu$pnbu$temppage);
  5131.                         $temppage str_replace($alias_pcu$pnbu$temppage);
  5132.                         $temppage str_replace($alias_pb$pnbs$temppage);
  5133.                         $temppage str_replace($alias_pc$pnbs$temppage);
  5134.                     }
  5135.                     $temppage str_replace($alias_pa$pnbs$temppage);
  5136.                 }
  5137.                 $temppage str_replace($this->epsmarker''$temppage);
  5138.                 //$this->setPageBuffer($n, $temppage);
  5139.                 //Page
  5140.                 $this->_newobj();
  5141.                 $this->_out('<</Type /Page');
  5142.                 $this->_out('/Parent 1 0 R');
  5143.                 $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]'$this->pagedim[$n]['w']$this->pagedim[$n]['h']));
  5144.                 $this->_out('/Resources 2 0 R');
  5145.                 $this->_putannots($n);
  5146.                 $this->_out('/Contents '.($this->n + 1).' 0 R>>');
  5147.                 $this->_out('endobj');
  5148.                 //Page content
  5149.                 $p ($this->compressgzcompress($temppage$temppage;
  5150.                 $this->_newobj();
  5151.                 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  5152.                 $this->_putstream($p);
  5153.                 $this->_out('endobj');
  5154.                 if ($this->diskcache{
  5155.                     // remove temporary files
  5156.                     unlink($this->pages[$n]);
  5157.                 }
  5158.             }
  5159.             //Pages root
  5160.             $this->offsets[1$this->bufferlen;
  5161.             $this->_out('1 0 obj');
  5162.             $this->_out('<</Type /Pages');
  5163.             $kids='/Kids [';
  5164.             for($i=0$i $nb++$i{
  5165.                 $kids .= (($i)).' 0 R ';
  5166.             }
  5167.             $this->_out($kids.']');
  5168.             $this->_out('/Count '.$nb);
  5169.             //$this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->pagedim[0]['w'],$this->pagedim[0]['h']));
  5170.             $this->_out('>>');
  5171.             $this->_out('endobj');
  5172.         }
  5173.  
  5174.         /**
  5175.         * Output Page Annotations.
  5176.         * !!! THIS FUNCTION IS NOT YET COMPLETED !!!
  5177.         * See section 8.4 of PDF reference.
  5178.         * @param int $n page number
  5179.         * @access protected
  5180.         * @author Nicola Asuni
  5181.         * @since 4.0.018 (2008-08-06)
  5182.         */
  5183.         protected function _putannots($n{
  5184.             if (isset($this->PageAnnots[$n])) {
  5185.                 $annots '/Annots [';
  5186.                 foreach ($this->PageAnnots[$nas $key => $pl{
  5187.                     $pl['opt'array_change_key_case($pl['opt']CASE_LOWER);
  5188.                     $a $pl['x'$this->k;
  5189.                     $b $this->pagedim[$n]['h'($pl['y']  $this->k);
  5190.                     $c $pl['w'$this->k;
  5191.                     $d $pl['h'$this->k;
  5192.                     $rect sprintf('%.2F %.2F %.2F %.2F'$a$b$a+$c$b-$d);
  5193.                     $annots .= "\n";
  5194.                     $annots .= '<</Type /Annot';
  5195.                     $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  5196.                     $annots .= ' /Rect ['.$rect.']';
  5197.                     $annots .= ' /Contents '.$this->_textstring($pl['txt']);
  5198.                     //$annots .= ' /P ';
  5199.                     $annots .= ' /NM '.$this->_textstring(sprintf('%04u-%04u'$n$key));
  5200.                     $annots .= ' /M '.$this->_datastring('D:'.date('YmdHis'));
  5201.                     if (isset($pl['opt']['f'])) {
  5202.                         $val 0;
  5203.                         if (is_array($pl['opt']['f'])) {
  5204.                             foreach ($pl['opt']['f'as $f{
  5205.                                 switch (strtolower($f)) {
  5206.                                     case 'invisible'{
  5207.                                         $val += << 0;
  5208.                                         break;
  5209.                                     }
  5210.                                     case 'hidden'{
  5211.                                         $val += << 1;
  5212.                                         break;
  5213.                                     }
  5214.                                     case 'print'{
  5215.                                         $val += << 2;
  5216.                                         break;
  5217.                                     }
  5218.                                     case 'nozoom'{
  5219.                                         $val += << 3;
  5220.                                         break;
  5221.                                     }
  5222.                                     case 'norotate'{
  5223.                                         $val += << 4;
  5224.                                         break;
  5225.                                     }
  5226.                                     case 'noview'{
  5227.                                         $val += << 5;
  5228.                                         break;
  5229.                                     }
  5230.                                     case 'readonly'{
  5231.                                         $val += << 6;
  5232.                                         break;
  5233.                                     }
  5234.                                     case 'locked'{
  5235.                                         $val += << 8;
  5236.                                         break;
  5237.                                     }
  5238.                                     case 'togglenoview'{
  5239.                                         $val += << 9;
  5240.                                         break;
  5241.                                     }
  5242.                                     case 'lockedcontents'{
  5243.                                         $val += << 10;
  5244.                                         break;
  5245.                                     }
  5246.                                     default{
  5247.                                         break;
  5248.                                     }
  5249.                                 }
  5250.                             }
  5251.                         }
  5252.                         $annots .= ' /F '.intval($val);
  5253.                     }
  5254.                     //$annots .= ' /AP ';
  5255.                     //$annots .= ' /AS ';
  5256.                     $annots .= ' /Border [';
  5257.                     if (isset($pl['opt']['border']AND (count($pl['opt']['border']>= 3)) {
  5258.                         $annots .= intval($pl['opt']['border'][0]).' ';
  5259.                         $annots .= intval($pl['opt']['border'][1]).' ';
  5260.                         $annots .= intval($pl['opt']['border'][2]);
  5261.                         if (isset($pl['opt']['border'][3]AND is_array($pl['opt']['border'][3])) {
  5262.                             $annots .= ' [';
  5263.                             foreach ($pl['opt']['border'][3as $dash{
  5264.                                 $annots .= intval($dash).' ';
  5265.                             }
  5266.                             $annots .= ']';
  5267.                         }
  5268.                     else {
  5269.                         $annots .= '0 0 0';
  5270.                     }
  5271.                     $annots .= ']';
  5272.                     if (isset($pl['opt']['bs']AND (is_array($pl['opt']['bs']))) {
  5273.                         $annots .= ' /BS <<Type /Border';
  5274.                         if (isset($pl['opt']['bs']['w'])) {
  5275.                             $annots .= ' /W '.sprintf("%.4F"floatval($pl['opt']['bs']['w']));
  5276.                         }
  5277.                         $bstyles array('S''D''B''I''U');
  5278.                         if (isset($pl['opt']['bs']['s']AND in_array($pl['opt']['bs']['s']$bstyles)) {
  5279.                             $annots .= ' /S /'.$pl['opt']['bs']['s'];
  5280.                         }
  5281.                         if (isset($pl['opt']['bs']['d']AND (is_array($pl['opt']['bs']['d']))) {
  5282.                             $annots .= ' /D [';
  5283.                             foreach ($pl['opt']['bs']['d'as $cord{
  5284.                                 $cord floatval($cord);
  5285.                                 $annots .= sprintf(" %.4F"$cord);
  5286.                             }
  5287.                             $annots .= ']';
  5288.                         }
  5289.                         $annots .= '>> ';
  5290.                     }
  5291.                     if (isset($pl['opt']['be']AND (is_array($pl['opt']['be']))) {
  5292.                         $annots .= ' /BE <<';
  5293.                         $bstyles array('S''C');
  5294.                         if (isset($pl['opt']['be']['s']AND in_array($pl['opt']['be']['s']$markups)) {
  5295.                             $annots .= ' /S /'.$pl['opt']['bs']['s'];
  5296.                         else {
  5297.                             $annots .= ' /S /S';
  5298.                         }
  5299.                         if (isset($pl['opt']['be']['i']AND ($pl['opt']['be']['i'>= 0AND ($pl['opt']['be']['i'<= 2)) {
  5300.                             $annots .= ' /I '.sprintf(" %.4F"$pl['opt']['be']['i']);
  5301.                         }
  5302.                         $annots .= '>>';
  5303.                     }
  5304.                     $annots .= ' /C [';
  5305.                     if (isset($pl['opt']['c']AND (is_array($pl['opt']['c']))) {
  5306.                         foreach ($pl['opt']['c'as $col{
  5307.                             $col intval($col);
  5308.                             $color $col <= ($col >= 255 $col 255);
  5309.                             $annots .= sprintf(" %.4F"$color);
  5310.                         }
  5311.                     }
  5312.                     $annots .= ']';
  5313.                     //$annots .= ' /StructParent ';
  5314.                     //$annots .= ' /OC ';
  5315.                     $markups array('text''freetext''line''square''circle''polygon''polyline''highlight',  'underline''squiggly''strikeout''stamp''caret''ink''fileattachment''sound');
  5316.                     if (in_array(strtolower($pl['opt']['subtype'])$markups)) {
  5317.                         // this is a markup type
  5318.                         if (isset($pl['opt']['t']AND is_string($pl['opt']['t'])) {
  5319.                             $annots .= ' /T '.$this->_textstring($pl['opt']['t']);
  5320.                         }
  5321.                         //$annots .= ' /Popup ';
  5322.                         if (isset($pl['opt']['ca'])) {
  5323.                             $annots .= ' /CA '.sprintf("%.4F"floatval($pl['opt']['ca']));
  5324.                         }
  5325.                         if (isset($pl['opt']['rc'])) {
  5326.                             $annots .= ' /RC '.$this->_textstring($pl['opt']['rc']);
  5327.                         }
  5328.                         $annots .= ' /CreationDate '.$this->_datastring('D:'.date('YmdHis'));
  5329.                         //$annots .= ' /IRT ';
  5330.                         if (isset($pl['opt']['subj'])) {
  5331.                             $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj']);
  5332.                         }
  5333.                         //$annots .= ' /RT ';
  5334.                         //$annots .= ' /IT ';
  5335.                         //$annots .= ' /ExData ';
  5336.                     }
  5337.                     switch (strtolower($pl['opt']['subtype'])) {
  5338.                         case 'text'{
  5339.                             if (isset($pl['opt']['open'])) {
  5340.                                 $annots .= ' /Open '(strtolower($pl['opt']['open']== 'true' 'true' 'false');
  5341.                             }
  5342.                             $iconsapp array('Comment''Help''Insert''Key''NewParagraph''Note''Paragraph');
  5343.                             if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  5344.                                 $annots .= ' /Name /'.$pl['opt']['name'];
  5345.                             else {
  5346.                                 $annots .= ' /Name /Note';
  5347.                             }
  5348.                             $statemodels array('Marked''Review');
  5349.                             if (isset($pl['opt']['statemodel']AND in_array($pl['opt']['statemodel']$statemodels)) {
  5350.                                 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  5351.                             else {
  5352.                                 $pl['opt']['statemodel''Marked';
  5353.                                 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  5354.                             }
  5355.                             if ($pl['opt']['statemodel'== 'Marked'{
  5356.                                 $states array('Accepted''Unmarked');
  5357.                             else {
  5358.                                 $states array('Accepted''Rejected''Cancelled''Completed''None');
  5359.                             }
  5360.                             if (isset($pl['opt']['state']AND in_array($pl['opt']['state']$states)) {
  5361.                                 $annots .= ' /State /'.$pl['opt']['state'];
  5362.                             else {
  5363.                                 if ($pl['opt']['statemodel'== 'Marked'{
  5364.                                     $annots .= ' /State /Unmarked';
  5365.                                 else {
  5366.                                     $annots .= ' /State /None';
  5367.                                 }
  5368.                             }
  5369.                             break;
  5370.                         }
  5371.                         case 'link'{
  5372.                             if(is_string($pl['txt'])) {
  5373.                                 // external URI link
  5374.                                 $annots .= ' /A <</S /URI /URI '.$this->_datastring($pl['txt']).'>>';
  5375.                             else {
  5376.                                 // internal link
  5377.                                 $l $this->links[$pl['txt']];
  5378.                                 $annots .= sprintf(' /Dest [%d 0 R /XYZ 0 %.2F null]'(($l[0]))($this->pagedim[$l[0]]['h'($l[1$this->k)));
  5379.                             }
  5380.                             $hmodes array('N''I''O''P');
  5381.                             if (isset($pl['opt']['h']AND in_array($pl['opt']['h']$hmodes)) {
  5382.                                 $annots .= ' /H /'.$pl['opt']['h'];
  5383.                             else {
  5384.                                 $annots .= ' /H /I';
  5385.                             }
  5386.                             //$annots .= ' /PA ';
  5387.                             //$annots .= ' /Quadpoints ';
  5388.                             break;
  5389.                         }
  5390.                         case 'freetext'{
  5391.                             $annots .= ' /DA '.$this->_textstring($pl['txt']);
  5392.                             if (isset($pl['opt']['q']AND ($pl['opt']['q'>= 0AND ($pl['opt']['q'<= 2)) {
  5393.                                 $annots .= ' /Q '.intval($pl['opt']['q']);
  5394.                             }
  5395.                             if (isset($pl['opt']['rc'])) {
  5396.                                 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc']);
  5397.                             }
  5398.                             if (isset($pl['opt']['ds'])) {
  5399.                                 $annots .= ' /DS '.$this->_textstring($pl['opt']['ds']);
  5400.                             }
  5401.                             if (isset($pl['opt']['cl']AND is_array($pl['opt']['cl'])) {
  5402.                                 $annots .= ' /CL [';
  5403.                                 foreach ($pl['opt']['cl'as $cl{
  5404.                                     $annots .= sprintf("%.4F "$cl $this->k);
  5405.                                 }
  5406.                                 $annots .= ']';
  5407.                             }
  5408.                             $tfit array('FreeTextCallout''FreeTextTypeWriter');
  5409.                             if (isset($pl['opt']['it']AND in_array($pl['opt']['it']$tfit)) {
  5410.                                 $annots .= ' /IT '.$pl['opt']['it'];
  5411.                             }
  5412.                             if (isset($pl['opt']['rd']AND is_array($pl['opt']['rd'])) {
  5413.                                 $l $pl['opt']['rd'][0$this->k;
  5414.                                 $r $pl['opt']['rd'][1$this->k;
  5415.                                 $t $pl['opt']['rd'][2$this->k;
  5416.                                 $b $pl['opt']['rd'][3$this->k;
  5417.                                 $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F'$l$r$t$b).']';
  5418.                             }
  5419.                             //$annots .= ' /LE ';
  5420.                             break;
  5421.                         }
  5422.                         // ... to be completed ...
  5423.                         case 'line'{
  5424.                             break;
  5425.                         }
  5426.                         case 'square'{
  5427.                             break;
  5428.                         }
  5429.                         case 'circle'{
  5430.                             break;
  5431.                         }
  5432.                         case 'polygon'{
  5433.                             break;
  5434.                         }
  5435.                         case 'polyline'{
  5436.                             break;
  5437.                         }
  5438.                         case 'highlight'{
  5439.                             break;
  5440.                         }
  5441.                         case 'underline'{
  5442.                             break;
  5443.                         }
  5444.                         case 'squiggly'{
  5445.                             break;
  5446.                         }
  5447.                         case 'strikeout'{
  5448.                             break;
  5449.                         }
  5450.                         case 'stamp'{
  5451.                             break;
  5452.                         }
  5453.                         case 'caret'{
  5454.                             break;
  5455.                         }
  5456.                         case 'ink'{
  5457.                             break;
  5458.                         }
  5459.                         case 'popup'{
  5460.                             break;
  5461.                         }
  5462.                         case 'fileattachment'{
  5463.                             if (!isset($pl['opt']['fs'])) {
  5464.                                 break;
  5465.                             }
  5466.                             $filename basename($pl['opt']['fs']);
  5467.                             if (isset($this->embeddedfiles[$filename]['n'])) {
  5468.                                 $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename).' /EF <</F '.$this->embeddedfiles[$filename]['n'].' 0 R>> >>';
  5469.                                 $iconsapp array('Graph''Paperclip''PushPin''Tag');
  5470.                                 if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  5471.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  5472.                                 else {
  5473.                                     $annots .= ' /Name /PushPin';
  5474.                                 }
  5475.                             }
  5476.                             break;
  5477.                         }
  5478.                         case 'sound'{
  5479.                             if (!isset($pl['opt']['sound'])) {
  5480.                                 break;
  5481.                             }
  5482.                             $filename basename($pl['opt']['sound']);
  5483.                             if (isset($this->embeddedfiles[$filename]['n'])) {
  5484.                                 // to be completed...
  5485.                                 $iconsapp array('Speaker''Mic');
  5486.                                 if (isset($pl['opt']['name']AND in_array($pl['opt']['name']$iconsapp)) {
  5487.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  5488.                                 else {
  5489.                                     $annots .= ' /Name /Speaker';
  5490.                                 }
  5491.                             }
  5492.                             break;
  5493.                         }
  5494.                         case 'movie'{
  5495.                             break;
  5496.                         }
  5497.                         case 'widget'{
  5498.                             break;
  5499.                         }
  5500.                         case 'screen'{
  5501.                             break;
  5502.                         }
  5503.                         case 'printermark'{
  5504.                             break;
  5505.                         }
  5506.                         case 'trapnet'{
  5507.                             break;
  5508.                         }
  5509.                         case 'watermark'{
  5510.                             break;
  5511.                         }
  5512.                         case '3d'{
  5513.                             break;
  5514.                         }
  5515.                         default{
  5516.                             break;
  5517.                         }
  5518.                     }
  5519.                     
  5520.                 $annots .= '>>';
  5521.                 }
  5522.                 $annots .= "\n]";
  5523.                 $this->_out($annots);
  5524.             }
  5525.         }
  5526.  
  5527.         /**
  5528.         * Output fonts.
  5529.         * @access protected
  5530.         */
  5531.         protected function _putfonts({
  5532.             $nf $this->n;
  5533.             foreach ($this->diffs as $diff{
  5534.                 //Encodings
  5535.                 $this->_newobj();
  5536.                 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  5537.                 $this->_out('endobj');
  5538.             }
  5539.             $mqr get_magic_quotes_runtime();
  5540.             set_magic_quotes_runtime(0);
  5541.             foreach ($this->FontFiles as $file => $info{
  5542.                 // search and get font file to embedd
  5543.                 $fontdir $info['fontdir'];
  5544.                 $file strtolower($file);
  5545.                 $fontfile '';
  5546.                 // search files on various directories
  5547.                 if (file_exists($fontdir.$file)) {
  5548.                     $fontfile $fontdir.$file;
  5549.                 elseif (file_exists($this->_getfontpath().$file)) {
  5550.                     $fontfile $this->_getfontpath().$file;
  5551.                 elseif (file_exists($file)) {
  5552.                     $fontfile $file;
  5553.                 }
  5554.                 if (!$this->empty_string($fontfile)) {
  5555.                     $font file_get_contents($fontfile);
  5556.                     $compressed (substr($file-2== '.z');
  5557.                     if ((!$compressedAND (isset($info['length2']))) {
  5558.                         $header (ord($font{0}== 128);
  5559.                         if ($header{
  5560.                             //Strip first binary header
  5561.                             $font substr($font6);
  5562.                         }
  5563.                         if ($header AND (ord($font{$info['length1']}== 128)) {
  5564.                             //Strip second binary header
  5565.                             $font substr($font0$info['length1']).substr($font($info['length1'6));
  5566.                         }
  5567.                     }
  5568.                     $this->_newobj();
  5569.                     $this->FontFiles[$file]['n'$this->n;
  5570.                     $this->_out('<</Length '.strlen($font));
  5571.                     if ($compressed{
  5572.                         $this->_out('/Filter /FlateDecode');
  5573.                     }
  5574.                     $this->_out('/Length1 '.$info['length1']);
  5575.                     if (isset($info['length2'])) {
  5576.                         $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  5577.                     }
  5578.                     $this->_out('>>');
  5579.                     $this->_putstream($font);
  5580.                     $this->_out('endobj');
  5581.                 }
  5582.             }
  5583.             set_magic_quotes_runtime($mqr);
  5584.             foreach ($this->fontkeys as $k{
  5585.                 //Font objects
  5586.                 $this->setFontSubBuffer($k'n'$this->n + 1);
  5587.                 $font $this->getFontBuffer($k);
  5588.                 $type $font['type'];
  5589.                 $name $font['name'];
  5590.                 if ($type == 'core'{
  5591.                     //Standard font
  5592.                     $this->_newobj();
  5593.                     $this->_out('<</Type /Font');
  5594.                     $this->_out('/BaseFont /'.$name);
  5595.                     $this->_out('/Subtype /Type1');
  5596.                     if (($name != 'symbol'AND ($name != 'zapfdingbats')) {
  5597.                         $this->_out('/Encoding /WinAnsiEncoding');
  5598.                     }
  5599.                     $this->_out('>>');
  5600.                     $this->_out('endobj');
  5601.                 elseif (($type == 'Type1'OR ($type == 'TrueType')) {
  5602.                     //Additional Type1 or TrueType font
  5603.                     $this->_newobj();
  5604.                     $this->_out('<</Type /Font');
  5605.                     $this->_out('/BaseFont /'.$name);
  5606.                     $this->_out('/Subtype /'.$type);
  5607.                     $this->_out('/FirstChar 32 /LastChar 255');
  5608.                     $this->_out('/Widths '.($this->n + 1).' 0 R');
  5609.                     $this->_out('/FontDescriptor '.($this->n + 2).' 0 R');
  5610.                     if ($font['enc']{
  5611.                         if (isset($font['diff'])) {
  5612.                             $this->_out('/Encoding '.($nf $font['diff']).' 0 R');
  5613.                         else {
  5614.                             $this->_out('/Encoding /WinAnsiEncoding');
  5615.                         }
  5616.                     }
  5617.                     $this->_out('>>');
  5618.                     $this->_out('endobj');
  5619.                     // Widths
  5620.                     $this->_newobj();
  5621.                     $cw &$font['cw'];
  5622.                     $s '[';
  5623.                     for($i 32$i 256++$i{
  5624.                         $s .= $cw[$i].' ';
  5625.                     }
  5626.                     $this->_out($s.']');
  5627.                     $this->_out('endobj');
  5628.                     //Descriptor
  5629.                     $this->_newobj();
  5630.                     $s '<</Type /FontDescriptor /FontName /'.$name;
  5631.                     foreach ($font['desc'as $k => $v{
  5632.                         $s .= ' /'.$k.' '.$v.'';
  5633.                     }
  5634.                     if (!$this->empty_string($font['file'])) {
  5635.                         $s .= ' /FontFile'.($type == 'Type1' '' '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  5636.                     }
  5637.                     $this->_out($s.'>>');
  5638.                     $this->_out('endobj');
  5639.                 else {
  5640.                     //Allow for additional types
  5641.                     $mtd '_put'.strtolower($type);
  5642.                     if (!method_exists($this$mtd)) {
  5643.                         $this->Error('Unsupported font type: '.$type);
  5644.                     }
  5645.                     $this->$mtd($font);
  5646.                 }
  5647.             }
  5648.         }
  5649.         
  5650.         /**
  5651.         * Outputs font widths
  5652.         * @parameter array $font font data
  5653.         * @parameter int $cidoffset offset for CID values
  5654.         * @author Nicola Asuni
  5655.         * @access protected
  5656.         * @since 4.4.000 (2008-12-07)
  5657.         */
  5658.         protected function _putfontwidths($font$cidoffset=0{
  5659.             ksort($font['cw']);
  5660.             $rangeid 0;
  5661.             $range array();
  5662.             $prevcid = -2;
  5663.             $prevwidth = -1;
  5664.             $interval false;
  5665.             // for each character
  5666.             foreach ($font['cw'as $cid => $width{
  5667.                 $cid -= $cidoffset;
  5668.                 if ($width != $font['dw']{
  5669.                     if ($cid == ($prevcid 1)) {
  5670.                         // consecutive CID
  5671.                         if ($width == $prevwidth{
  5672.                             if ($width == $range[$rangeid][0]{
  5673.                                 $range[$rangeid][$width;
  5674.                             else {
  5675.                                 array_pop($range[$rangeid]);
  5676.                                 // new range
  5677.                                 $rangeid $prevcid;
  5678.                                 $range[$rangeidarray();
  5679.                                 $range[$rangeid][$prevwidth;
  5680.                                 $range[$rangeid][$width;
  5681.                             }
  5682.                             $interval true;
  5683.                             $range[$rangeid]['interval'true;
  5684.                         else {
  5685.                             if ($interval{
  5686.                                 // new range
  5687.                                 $rangeid $cid;
  5688.                                 $range[$rangeidarray();
  5689.                                 $range[$rangeid][$width;
  5690.                             else {
  5691.                                 $range[$rangeid][$width;
  5692.                             }
  5693.                             $interval false;
  5694.                         }
  5695.                     else {
  5696.                         // new range
  5697.                         $rangeid $cid;
  5698.                         $range[$rangeidarray();
  5699.                         $range[$rangeid][$width;
  5700.                         $interval false;
  5701.                     }
  5702.                     $prevcid $cid;
  5703.                     $prevwidth $width;
  5704.                 }
  5705.             }
  5706.             // optimize ranges
  5707.             $prevk = -1;
  5708.             $nextk = -1;
  5709.             $prevint false;
  5710.             foreach ($range as $k => $ws{
  5711.                 $cws count($ws);
  5712.                 if (($k == $nextkAND (!$previntAND ((!isset($ws['interval'])) OR ($cws 4))) {
  5713.                     if (isset($range[$k]['interval'])) {
  5714.                         unset($range[$k]['interval']);
  5715.                     }
  5716.                     $range[$prevkarray_merge($range[$prevk]$range[$k]);
  5717.                     unset($range[$k]);
  5718.                 else {
  5719.                     $prevk $k;
  5720.                 }
  5721.                 $nextk $k $cws;
  5722.                 if (isset($ws['interval'])) {
  5723.                     if ($cws 3{
  5724.                         $prevint true;
  5725.                     else {
  5726.                         $prevint false;
  5727.                     }
  5728.                     unset($range[$k]['interval']);
  5729.                     --$nextk;
  5730.                 else {
  5731.                     $prevint false;
  5732.                 }
  5733.             }
  5734.             // output data
  5735.             $w '';
  5736.             foreach ($range as $k => $ws{
  5737.                 if (count(array_count_values($ws)) == 1{
  5738.                     // interval mode is more compact
  5739.                     $w .= ' '.$k.' '.($k count($ws1).' '.$ws[0];
  5740.                 else {
  5741.                     // range mode
  5742.                     $w .= ' '.$k.' [ '.implode(' '$ws).' ]';
  5743.                 }
  5744.             }
  5745.             $this->_out('/W ['.$w.' ]');
  5746.         }
  5747.         
  5748.         /**
  5749.         * Adds unicode fonts.<br>
  5750.         * Based on PDF Reference 1.3 (section 5)
  5751.         * @parameter array $font font data
  5752.         * @access protected
  5753.         * @author Nicola Asuni
  5754.         * @since 1.52.0.TC005 (2005-01-05)
  5755.         */
  5756.         protected function _puttruetypeunicode($font{
  5757.             // Type0 Font
  5758.             // A composite font composed of other fonts, organized hierarchically
  5759.             $this->_newobj();
  5760.             $this->_out('<</Type /Font');
  5761.             $this->_out('/Subtype /Type0');
  5762.             $this->_out('/BaseFont /'.$font['name'].'');
  5763.             $this->_out('/Encoding /Identity-H')//The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values.
  5764.             $this->_out('/ToUnicode /Identity-H');
  5765.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  5766.             $this->_out('>>');
  5767.             $this->_out('endobj');
  5768.             // CIDFontType2
  5769.             // A CIDFont whose glyph descriptions are based on TrueType font technology
  5770.             $this->_newobj();
  5771.             $this->_out('<</Type /Font');
  5772.             $this->_out('/Subtype /CIDFontType2');
  5773.             $this->_out('/BaseFont /'.$font['name'].'');
  5774.             // A dictionary containing entries that define the character collection of the CIDFont.
  5775.             $cidinfo '/Registry '.$this->_datastring('Adobe');
  5776.             $cidinfo .= ' /Ordering '.$this->_datastring('Identity');
  5777.             $cidinfo .= ' /Supplement 0';
  5778.             $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  5779.             $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  5780.             $this->_out('/DW '.$font['dw'].'')// default width
  5781.             $this->_putfontwidths($font0);
  5782.             $this->_out('/CIDToGIDMap '.($this->n + 2).' 0 R');
  5783.             $this->_out('>>');
  5784.             $this->_out('endobj');            
  5785.             // Font descriptor
  5786.             // A font descriptor describing the CIDFont default metrics other than its glyph widths
  5787.             $this->_newobj();
  5788.             $this->_out('<</Type /FontDescriptor');
  5789.             $this->_out('/FontName /'.$font['name']);
  5790.             foreach ($font['desc'as $key => $value{
  5791.                 $this->_out('/'.$key.' '.$value);
  5792.             }
  5793.             $fontdir '';
  5794.             if (!$this->empty_string($font['file'])) {
  5795.                 // A stream containing a TrueType font
  5796.                 $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  5797.                 $fontdir $this->FontFiles[$font['file']]['fontdir'];
  5798.             }
  5799.             $this->_out('>>');
  5800.             $this->_out('endobj');
  5801.             $this->_newobj();
  5802.             if (isset($font['ctg']AND (!$this->empty_string($font['ctg']))) {
  5803.                 // Embed CIDToGIDMap
  5804.                 // A specification of the mapping from CIDs to glyph indices
  5805.                 // search and get CTG font file to embedd
  5806.                 $ctgfile strtolower($font['ctg']);
  5807.                 // search and get ctg font file to embedd
  5808.                 $fontfile '';
  5809.                 // search files on various directories
  5810.                 if (file_exists($fontdir.$ctgfile)) {
  5811.                     $fontfile $fontdir.$ctgfile;
  5812.                 elseif (file_exists($this->_getfontpath().$ctgfile)) {
  5813.                     $fontfile $this->_getfontpath().$ctgfile;
  5814.                 elseif (file_exists($ctgfile)) {
  5815.                     $fontfile $ctgfile;
  5816.                 }
  5817.                 if ($this->empty_string($fontfile)) {
  5818.                     $this->Error('Font file not found: '.$ctgfile);
  5819.                 }
  5820.                 $size filesize($fontfile);
  5821.                 $this->_out('<</Length '.$size.'');
  5822.                 if (substr($fontfile-2== '.z'// check file extension
  5823.                     // Decompresses data encoded using the public-domain 
  5824.                     // zlib/deflate compression method, reproducing the 
  5825.                     // original text or binary data
  5826.                     $this->_out('/Filter /FlateDecode');
  5827.                 }
  5828.                 $this->_out('>>');
  5829.                 $this->_putstream(file_get_contents($fontfile));
  5830.             }
  5831.             $this->_out('endobj');
  5832.         }
  5833.         
  5834.         /**
  5835.          * Output CID-0 fonts.
  5836.          * @param array $font font data
  5837.          * @access protected
  5838.          * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  5839.          * @since 3.2.000 (2008-06-23)
  5840.          */
  5841.         protected function _putcidfont0($font{
  5842.             $cidoffset 31;
  5843.             if (isset($font['cidinfo']['uni2cid'])) {
  5844.                 // convert unicode to cid.
  5845.                 $uni2cid $font['cidinfo']['uni2cid'];
  5846.                 $cw array();
  5847.                 foreach ($font['cw'as $uni => $width{
  5848.                     if (isset($uni2cid[$uni])) {
  5849.                         $cw[($uni2cid[$uni$cidoffset)$width;
  5850.                     elseif ($uni 256{
  5851.                         $cw[$uni$width;
  5852.                     // else unknown character
  5853.                 }
  5854.                 $font array_merge($fontarray('cw' => $cw));
  5855.             }
  5856.             $name $font['name'];
  5857.             $enc $font['enc'];
  5858.             if ($enc{
  5859.                 $longname $name.'-'.$enc;
  5860.             else {
  5861.                 $longname $name;
  5862.             }
  5863.             $this->_newobj();
  5864.             $this->_out('<</Type /Font');
  5865.             $this->_out('/BaseFont /'.$longname);
  5866.             $this->_out('/Subtype /Type0');
  5867.             if ($enc{
  5868.                 $this->_out('/Encoding /'.$enc);
  5869.             }
  5870.             $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  5871.             $this->_out('>>');
  5872.             $this->_out('endobj');
  5873.             $this->_newobj();
  5874.             $this->_out('<</Type /Font');
  5875.             $this->_out('/BaseFont /'.$name);
  5876.             $this->_out('/Subtype /CIDFontType0');
  5877.             $cidinfo '/Registry '.$this->_datastring($font['cidinfo']['Registry']);
  5878.             $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering']);
  5879.             $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  5880.             $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  5881.             $this->_out('/FontDescriptor '.($this->n + 1).' 0 R');
  5882.             $this->_out('/DW '.$font['dw']);
  5883.             $this->_putfontwidths($font$cidoffset);
  5884.             $this->_out('>>');
  5885.             $this->_out('endobj');
  5886.             $this->_newobj();
  5887.             $s '<</Type /FontDescriptor /FontName /'.$name;
  5888.             foreach ($font['desc'as $k => $v{
  5889.                 if ($k != 'Style'{
  5890.                     $s .= ' /'.$k.' '.$v.'';
  5891.                 }
  5892.             }
  5893.             $this->_out($s.'>>');
  5894.             $this->_out('endobj');
  5895.         }
  5896.  
  5897.         /**
  5898.          * Output images.
  5899.          * @access protected
  5900.          */
  5901.         protected function _putimages({
  5902.             $filter ($this->compress'/Filter /FlateDecode ' '';
  5903.             foreach ($this->imagekeys as $file{
  5904.                 $info $this->getImageBuffer($file);
  5905.                 $this->_newobj();
  5906.                 $this->setImageSubBuffer($file'n'$this->n);
  5907.                 $this->_out('<</Type /XObject');
  5908.                 $this->_out('/Subtype /Image');
  5909.                 $this->_out('/Width '.$info['w']);
  5910.                 $this->_out('/Height '.$info['h']);
  5911.                 if (isset($info['masked'])) {
  5912.                     $this->_out('/SMask '.($this->n - 1).' 0 R');
  5913.                 }
  5914.                 if ($info['cs'== 'Indexed'{
  5915.                     $this->_out('/ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']31).' '.($this->n + 1).' 0 R]');
  5916.                 else {
  5917.                     $this->_out('/ColorSpace /'.$info['cs']);
  5918.                     if ($info['cs'== 'DeviceCMYK'{
  5919.                         $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  5920.                     }
  5921.                 }
  5922.                 $this->_out('/BitsPerComponent '.$info['bpc']);
  5923.                 if (isset($info['f'])) {
  5924.                     $this->_out('/Filter /'.$info['f']);
  5925.                 }
  5926.                 if (isset($info['parms'])) {
  5927.                     $this->_out($info['parms']);
  5928.                 }
  5929.                 if (isset($info['trns']AND is_array($info['trns'])) {
  5930.                     $trns='';
  5931.                     $count_info count($info['trns']);
  5932.                     for($i=0$i $count_info++$i{
  5933.                         $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  5934.                     }
  5935.                     $this->_out('/Mask ['.$trns.']');
  5936.                 }
  5937.                 $this->_out('/Length '.strlen($info['data']).'>>');
  5938.                 $this->_putstream($info['data']);
  5939.                 $this->_out('endobj');
  5940.                 //Palette
  5941.                 if ($info['cs'== 'Indexed'{
  5942.                     $this->_newobj();
  5943.                     $pal ($this->compressgzcompress($info['pal']$info['pal'];
  5944.                     $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  5945.                     $this->_putstream($pal);
  5946.                     $this->_out('endobj');
  5947.                 }
  5948.             }
  5949.         }
  5950.  
  5951.         /**
  5952.         * Output Spot Colors Resources.
  5953.         * @access protected
  5954.         * @since 4.0.024 (2008-09-12)
  5955.         */
  5956.         protected function _putspotcolors({
  5957.             foreach ($this->spot_colors as $name => $color{
  5958.                 $this->_newobj();
  5959.                 $this->spot_colors[$name]['n'$this->n;
  5960.                 $this->_out('[/Separation /'.str_replace(' ''#20'$name));
  5961.                 $this->_out('/DeviceCMYK <<');
  5962.                 $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
  5963.                 $this->_out(sprintf('/C1 [%.4F %.4F %.4F %.4F] '$color['c']/100$color['m']/100$color['y']/100$color['k']/100));
  5964.                 $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]');
  5965.                 $this->_out('endobj');
  5966.             }
  5967.         }
  5968.  
  5969.         /**
  5970.         * Output object dictionary for images.
  5971.         * @access protected
  5972.         */
  5973.         protected function _putxobjectdict({
  5974.             foreach ($this->imagekeys as $file{
  5975.                 $info $this->getImageBuffer($file);
  5976.                 $this->_out('/I'.$info['i'].' '.$info['n'].' 0 R');
  5977.             }
  5978.         }
  5979.  
  5980.         /**
  5981.         * Output Resources Dictionary.
  5982.         * @access protected
  5983.         */
  5984.         protected function _putresourcedict({
  5985.             $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  5986.             $this->_out('/Font <<');
  5987.             foreach ($this->fontkeys as $fontkey{
  5988.                 $font $this->getFontBuffer($fontkey);
  5989.                 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  5990.             }
  5991.             $this->_out('>>');
  5992.             $this->_out('/XObject <<');
  5993.             $this->_putxobjectdict();
  5994.             $this->_out('>>');
  5995.             // visibility
  5996.             $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R>>');
  5997.             // transparency
  5998.             $this->_out('/ExtGState <<');
  5999.             foreach ($this->extgstates as $k => $extgstate{
  6000.                 $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  6001.             }
  6002.             $this->_out('>>');
  6003.             // gradients
  6004.             if (isset($this->gradientsAND (count($this->gradients0)) {
  6005.                 $this->_out('/Shading <<');
  6006.                 foreach ($this->gradients as $id => $grad{
  6007.                     $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  6008.                 }
  6009.                 $this->_out('>>');
  6010.             }
  6011.             // spot colors
  6012.             if (isset($this->spot_colorsAND (count($this->spot_colors0)) {
  6013.                 $this->_out('/ColorSpace <<');
  6014.                 foreach ($this->spot_colors as $color{
  6015.                     $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R');
  6016.                 }
  6017.                 $this->_out('>>');
  6018.             }
  6019.         }
  6020.         
  6021.         /**
  6022.         * Output Resources.
  6023.         * @access protected
  6024.         */
  6025.         protected function _putresources({
  6026.             $this->_putextgstates();
  6027.             $this->_putocg();
  6028.             $this->_putfonts();
  6029.             $this->_putimages();
  6030.             $this->_putspotcolors();
  6031.             $this->_putshaders();
  6032.             //Resource dictionary
  6033.             $this->offsets[2$this->bufferlen;
  6034.             $this->_out('2 0 obj');
  6035.             $this->_out('<<');
  6036.             $this->_putresourcedict();
  6037.             $this->_out('>>');
  6038.             $this->_out('endobj');
  6039.             $this->_putjavascript();
  6040.             $this->_putbookmarks();
  6041.             $this->_putEmbeddedFiles();
  6042.             // encryption
  6043.             if ($this->encrypted{
  6044.                 $this->_newobj();
  6045.                 $this->enc_obj_id = $this->n;
  6046.                 $this->_out('<<');
  6047.                 $this->_putencryption();
  6048.                 $this->_out('>>');
  6049.                 $this->_out('endobj');
  6050.             }
  6051.         }
  6052.         
  6053.         /**
  6054.         * Adds some Metadata information
  6055.         * (see Chapter 10.2 of PDF Reference)
  6056.         * @access protected
  6057.         */
  6058.         protected function _putinfo({
  6059.             if (!$this->empty_string($this->title)) {
  6060.                 $this->_out('/Title '.$this->_textstring($this->title));
  6061.             }
  6062.             if (!$this->empty_string($this->author)) {
  6063.                 $this->_out('/Author '.$this->_textstring($this->author));
  6064.             }
  6065.             if (!$this->empty_string($this->subject)) {
  6066.                 $this->_out('/Subject '.$this->_textstring($this->subject));
  6067.             }
  6068.             if (!$this->empty_string($this->keywords)) {
  6069.                 $this->_out('/Keywords '.$this->_textstring($this->keywords));
  6070.             }
  6071.             if (!$this->empty_string($this->creator)) {
  6072.                 $this->_out('/Creator '.$this->_textstring($this->creator));
  6073.             }
  6074.             if (defined('PDF_PRODUCER')) {
  6075.                 $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
  6076.             }
  6077.             $this->_out('/CreationDate '.$this->_datastring('D:'.date('YmdHis')));
  6078.             $this->_out('/ModDate '.$this->_datastring('D:'.date('YmdHis')));    
  6079.         }
  6080.         
  6081.         /**
  6082.         * Output Catalog.
  6083.         * @access protected
  6084.         */
  6085.         protected function _putcatalog({
  6086.             $this->_out('/Type /Catalog');
  6087.             $this->_out('/Pages 1 0 R');
  6088.             if ($this->ZoomMode == 'fullpage'{
  6089.                 $this->_out('/OpenAction [3 0 R /Fit]');
  6090.             elseif ($this->ZoomMode == 'fullwidth'{
  6091.                 $this->_out('/OpenAction [3 0 R /FitH null]');
  6092.             elseif ($this->ZoomMode == 'real'{
  6093.                 $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  6094.             elseif (!is_string($this->ZoomMode)) {
  6095.                 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).']');
  6096.             }
  6097.             if (isset($this->LayoutModeAND (!$this->empty_string($this->LayoutMode))) {
  6098.                 $this->_out('/PageLayout /'.$this->LayoutMode.'');
  6099.             }
  6100.             if (isset($this->PageModeAND (!$this->empty_string($this->PageMode))) {
  6101.                 $this->_out('/PageMode /'.$this->PageMode);
  6102.             }
  6103.             if (isset($this->l['a_meta_language'])) {
  6104.                 $this->_out('/Lang /'.$this->l['a_meta_language']);
  6105.             }
  6106.             $this->_out('/Names <<');
  6107.             if (!$this->empty_string($this->javascript)) {
  6108.                 $this->_out('/JavaScript '.($this->n_js).' 0 R');
  6109.             }
  6110.             $this->_out('>>');
  6111.             if (count($this->outlines0{
  6112.                 $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  6113.                 $this->_out('/PageMode /UseOutlines');
  6114.             }
  6115.             $this->_putviewerpreferences();
  6116.             $p $this->n_ocg_print.' 0 R';
  6117.             $v $this->n_ocg_view.' 0 R';
  6118.             $as '<</Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print]>> <</Event /View /OCGs ['.$p.' '.$v.'] /Category [/View]>>';
  6119.             $this->_out('/OCProperties <</OCGs ['.$p.' '.$v.'] /D <</ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.']>>>>');
  6120.             $this->_putuserrights();
  6121.         }
  6122.         
  6123.         /**
  6124.         * Output viewer preferences.
  6125.         * @author Nicola asuni
  6126.         * @since 3.1.000 (2008-06-09)
  6127.         * @access protected
  6128.         */
  6129.         protected function _putviewerpreferences({
  6130.             $this->_out('/ViewerPreferences<<');
  6131.             if ($this->rtl{
  6132.                 $this->_out('/Direction /R2L');
  6133.             else {
  6134.                 $this->_out('/Direction /L2R');
  6135.             }
  6136.             if (isset($this->viewer_preferences['HideToolbar']AND ($this->viewer_preferences['HideToolbar'])) {
  6137.                 $this->_out('/HideToolbar true');
  6138.             }
  6139.             if (isset($this->viewer_preferences['HideMenubar']AND ($this->viewer_preferences['HideMenubar'])) {
  6140.                 $this->_out('/HideMenubar true');
  6141.             }
  6142.             if (isset($this->viewer_preferences['HideWindowUI']AND ($this->viewer_preferences['HideWindowUI'])) {
  6143.                 $this->_out('/HideWindowUI true');
  6144.             }
  6145.             if (isset($this->viewer_preferences['FitWindow']AND ($this->viewer_preferences['FitWindow'])) {
  6146.                 $this->_out('/FitWindow true');
  6147.             }
  6148.             if (isset($this->viewer_preferences['CenterWindow']AND ($this->viewer_preferences['CenterWindow'])) {
  6149.                 $this->_out('/CenterWindow true');
  6150.             }
  6151.             if (isset($this->viewer_preferences['DisplayDocTitle']AND ($this->viewer_preferences['DisplayDocTitle'])) {
  6152.                 $this->_out('/DisplayDocTitle true');
  6153.             }
  6154.             if (isset($this->viewer_preferences['NonFullScreenPageMode'])) {
  6155.                 $this->_out('/NonFullScreenPageMode /'.$this->viewer_preferences['NonFullScreenPageMode'].'');
  6156.             }
  6157.             if (isset($this->viewer_preferences['ViewArea'])) {
  6158.                 $this->_out('/ViewArea /'.$this->viewer_preferences['ViewArea']);
  6159.             }
  6160.             if (isset($this->viewer_preferences['ViewClip'])) {
  6161.                 $this->_out('/ViewClip /'.$this->viewer_preferences['ViewClip']);
  6162.             }
  6163.             if (isset($this->viewer_preferences['PrintArea'])) {
  6164.                 $this->_out('/PrintArea /'.$this->viewer_preferences['PrintArea']);
  6165.             }
  6166.             if (isset($this->viewer_preferences['PrintClip'])) {
  6167.                 $this->_out('/PrintClip /'.$this->viewer_preferences['PrintClip']);
  6168.             }
  6169.             if (isset($this->viewer_preferences['PrintScaling'])) {
  6170.                 $this->_out('/PrintScaling /'.$this->viewer_preferences['PrintScaling']);
  6171.             }
  6172.             if (isset($this->viewer_preferences['Duplex']AND (!$this->empty_string($this->viewer_preferences['Duplex']))) {
  6173.                 $this->_out('/Duplex /'.$this->viewer_preferences['Duplex']);
  6174.             }
  6175.             if (isset($this->viewer_preferences['PickTrayByPDFSize'])) {
  6176.                 if ($this->viewer_preferences['PickTrayByPDFSize']{
  6177.                     $this->_out('/PickTrayByPDFSize true');
  6178.                 else {
  6179.                     $this->_out('/PickTrayByPDFSize false');
  6180.                 }
  6181.             }
  6182.             if (isset($this->viewer_preferences['PrintPageRange'])) {
  6183.                 $PrintPageRangeNum '';
  6184.                 foreach ($this->viewer_preferences['PrintPageRange'as $k => $v{
  6185.                     $PrintPageRangeNum .= ' '.($v 1).'';
  6186.                 }
  6187.                 $this->_out('/PrintPageRange ['.substr($PrintPageRangeNum,1).']');
  6188.             }
  6189.             if (isset($this->viewer_preferences['NumCopies'])) {
  6190.                 $this->_out('/NumCopies '.intval($this->viewer_preferences['NumCopies']));
  6191.             }
  6192.             $this->_out('>>');
  6193.         }
  6194.  
  6195.         /**
  6196.         * Output trailer.
  6197.         * @access protected
  6198.         */
  6199.         protected function _puttrailer({
  6200.             $this->_out('/Size '.($this->n + 1));
  6201.             $this->_out('/Root '.$this->n.' 0 R');
  6202.             $this->_out('/Info '.($this->n - 1).' 0 R');
  6203.             if ($this->encrypted{
  6204.                 $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  6205.                 $this->_out('/ID [()()]');
  6206.             }
  6207.         }
  6208.  
  6209.         /**
  6210.         * Output PDF header.
  6211.         * @access protected
  6212.         */
  6213.         protected function _putheader({
  6214.             $this->_out('%PDF-'.$this->PDFVersion);
  6215.         }
  6216.  
  6217.         /**
  6218.         * Output end of document (EOF).
  6219.         * @access protected
  6220.         */
  6221.         protected function _enddoc({
  6222.             $this->state = 1;
  6223.             $this->_putheader();
  6224.             $this->_putpages();
  6225.             $this->_putresources();
  6226.             //Info
  6227.             $this->_newobj();
  6228.             $this->_out('<<');
  6229.             $this->_putinfo();
  6230.             $this->_out('>>');
  6231.             $this->_out('endobj');
  6232.             //Catalog
  6233.             $this->_newobj();
  6234.             $this->_out('<<');
  6235.             $this->_putcatalog();
  6236.             $this->_out('>>');
  6237.             $this->_out('endobj');
  6238.             //Cross-ref
  6239.             $o $this->bufferlen;
  6240.             $this->_out('xref');
  6241.             $this->_out('0 '.($this->n + 1));
  6242.             $this->_out('0000000000 65535 f ');
  6243.             for($i=1$i <= $this->n++$i{
  6244.                 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  6245.             }
  6246.             foreach ($this->embeddedfiles as $filename => $filedata{
  6247.                 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$filedata['n']]));
  6248.             }
  6249.             //Trailer
  6250.             $this->_out('trailer');
  6251.             $this->_out('<<');
  6252.             $this->_puttrailer();
  6253.             $this->_out('>>');
  6254.             $this->_out('startxref');
  6255.             $this->_out($o);
  6256.             $this->_out('%%EOF');
  6257.             $this->state = 3// end-of-doc
  6258.             if ($this->diskcache{
  6259.                 // remove temporary files used for images
  6260.                 foreach ($this->imagekeys as $key{
  6261.                     // remove temporary files
  6262.                     unlink($this->images[$key]);
  6263.                 }
  6264.                 foreach ($this->fontkeys as $key{
  6265.                     // remove temporary files
  6266.                     unlink($this->fonts[$key]);
  6267.                 }
  6268.             }
  6269.         }
  6270.  
  6271.         /**
  6272.         * Initialize a new page.
  6273.         * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  6274.         * @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>
  6275.         * @access protected
  6276.         */
  6277.         protected function _beginpage($orientation=''$format=''{
  6278.             ++$this->page;
  6279.             $this->setPageBuffer($this->page'');
  6280.             // initialize array for graphics tranformation positions inside a page buffer
  6281.             $this->transfmrk[$this->pagearray();
  6282.             $this->state = 2;
  6283.             if ($this->empty_string($orientation)) {
  6284.                 if (isset($this->CurOrientation)) {
  6285.                     $orientation $this->CurOrientation;
  6286.                 else {
  6287.                     $orientation 'P';
  6288.                 }
  6289.             }
  6290.             if ($this->empty_string($format)) {
  6291.                 $this->setPageOrientation($orientation);
  6292.             else {
  6293.                 $this->setPageFormat($format$orientation);
  6294.             }
  6295.             if ($this->rtl{
  6296.                 $this->x = $this->w - $this->rMargin;
  6297.             else {
  6298.                 $this->x = $this->lMargin;
  6299.             }
  6300.             $this->y = $this->tMargin;
  6301.             if (isset($this->newpagegroup[$this->page])) {
  6302.                 // start a new group
  6303.                 $n sizeof($this->pagegroups1;
  6304.                 $alias '{nb'.$n.'}';
  6305.                 $this->pagegroups[$alias1;
  6306.                 $this->currpagegroup = $alias;
  6307.             elseif ($this->currpagegroup{
  6308.                 ++$this->pagegroups[$this->currpagegroup];
  6309.             }
  6310.         }
  6311.  
  6312.         /**
  6313.         * Mark end of page.
  6314.         * @access protected
  6315.         */
  6316.         protected function _endpage({
  6317.             $this->setVisibility('all');
  6318.             $this->state = 1;
  6319.         }
  6320.  
  6321.         /**
  6322.         * Begin a new object.
  6323.         * @access protected
  6324.         */
  6325.         protected function _newobj({
  6326.             ++$this->n;
  6327.             $this->offsets[$this->n$this->bufferlen;
  6328.             $this->_out($this->n.' 0 obj');
  6329.         }
  6330.  
  6331.         /**
  6332.         * Underline text.
  6333.         * @param int $x X coordinate
  6334.         * @param int $y Y coordinate
  6335.         * @param string $txt text to underline
  6336.         * @access protected
  6337.         */
  6338.         protected function _dounderline($x$y$txt{
  6339.             $up $this->CurrentFont['up'];
  6340.             $ut $this->CurrentFont['ut'];
  6341.             $w $this->GetStringWidth($txt);
  6342.             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);
  6343.         }
  6344.         
  6345.         /**
  6346.         * Line through text.
  6347.         * @param int $x X coordinate
  6348.         * @param int $y Y coordinate
  6349.         * @param string $txt text to linethrough
  6350.         * @access protected
  6351.         */
  6352.         protected function _dolinethrough($x$y$txt{
  6353.             $up $this->CurrentFont['up'];
  6354.             $ut $this->CurrentFont['ut'];
  6355.             $w $this->GetStringWidth($txt);
  6356.             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);
  6357.         }
  6358.         
  6359.         /**
  6360.         * Read a 4-byte integer from file.
  6361.         * @param string $f file name.
  6362.         * @return 4-byte integer
  6363.         * @access protected
  6364.         */
  6365.         protected function _freadint($f{
  6366.             $a unpack('Ni'fread($f4));
  6367.             return $a['i'];
  6368.         }
  6369.         
  6370.         /**
  6371.         * Add "\" before "\", "(" and ")"
  6372.         * @param string $s string to escape.
  6373.         * @return string escaped string.
  6374.         * @access protected
  6375.         */
  6376.         protected function _escape($s{
  6377.             // the chr(13) substitution fixes the Bugs item #1421290.
  6378.             return strtr($sarray(')' => '\\)''(' => '\\(''\\' => '\\\\'chr(13=> '\r'));
  6379.         }
  6380.         
  6381.         /**
  6382.         * Format a date string for meta information
  6383.         * @param string $s date string to escape.
  6384.         * @return string escaped string.
  6385.         * @access protected
  6386.         */
  6387.         protected function _datastring($s{
  6388.             if ($this->encrypted{
  6389.                 $s $this->_RC4($this->_objectkey($this->n)$s);
  6390.             }
  6391.             return '('$this->_escape($s).')';
  6392.         }
  6393.         
  6394.         /**
  6395.         * Format a text string for meta information
  6396.         * @param string $s string to escape.
  6397.         * @return string escaped string.
  6398.         * @access protected
  6399.         */
  6400.         protected function _textstring($s{
  6401.             if ($this->isunicode{
  6402.                 //Convert string to UTF-16BE
  6403.                 $s $this->UTF8ToUTF16BE($strue);
  6404.             }
  6405.             return $this->_datastring($s);
  6406.         }
  6407.                 
  6408.         /**
  6409.         * Format a text string
  6410.         * @param string $s string to escape.
  6411.         * @return string escaped string.
  6412.         * @access protected
  6413.         */
  6414.         protected function _escapetext($s{
  6415.             if ($this->isunicode{
  6416.                 if (($this->CurrentFont['type'== 'core'OR ($this->CurrentFont['type'== 'TrueType'OR ($this->CurrentFont['type'== 'Type1')) {
  6417.                     $s $this->UTF8ToLatin1($s);
  6418.                 else {
  6419.                     //Convert string to UTF-16BE and reverse RTL language
  6420.                     $s $this->utf8StrRev($sfalse$this->tmprtl);
  6421.                 }
  6422.             }
  6423.             return $this->_escape($s);
  6424.         }
  6425.         
  6426.         /**
  6427.         * Output a stream.
  6428.         * @param string $s string to output.
  6429.         * @access protected
  6430.         */
  6431.         protected function _putstream($s{
  6432.             if ($this->encrypted{
  6433.                 $s $this->_RC4($this->_objectkey($this->n)$s);
  6434.             }
  6435.             $this->_out('stream');
  6436.             $this->_out($s);
  6437.             $this->_out('endstream');
  6438.         }
  6439.         
  6440.         /**
  6441.         * Output a string to the document.
  6442.         * @param string $s string to output.
  6443.         * @access protected
  6444.         */
  6445.         protected function _out($s{
  6446.             if ($this->state == 2{
  6447.                 if ((!$this->InFooterAND isset($this->footerlen[$this->page]AND ($this->footerlen[$this->page0)) {
  6448.                     // puts data before page footer
  6449.                     $pagebuff $this->getPageBuffer($this->page);
  6450.                     $page substr($pagebuff0-$this->footerlen[$this->page]);
  6451.                     $footer substr($pagebuff-$this->footerlen[$this->page]);
  6452.                     $this->setPageBuffer($this->page$page.$s."\n".$footer);
  6453.                     // update footer position
  6454.                     $this->footerpos[$this->page+= strlen($s."\n");    
  6455.                 else {
  6456.                     $this->setPageBuffer($this->page$s."\n"true);
  6457.                 }
  6458.             else {
  6459.                 $this->setBuffer($s."\n");
  6460.             }
  6461.         }
  6462.         
  6463.          /**
  6464.          * Converts UTF-8 strings to codepoints array.<br>
  6465.          * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  6466.          * Based on: http://www.faqs.org/rfcs/rfc3629.html
  6467.          * <pre>
  6468.          *       Char. number range  |        UTF-8 octet sequence
  6469.          *       (hexadecimal)    |              (binary)
  6470.          *    --------------------+-----------------------------------------------
  6471.          *    0000 0000-0000 007F | 0xxxxxxx
  6472.          *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  6473.          *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  6474.          *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  6475.          *    ---------------------------------------------------------------------
  6476.          *
  6477.          *   ABFN notation:
  6478.          *   ---------------------------------------------------------------------
  6479.          *   UTF8-octets = *( UTF8-char )
  6480.          *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  6481.          *   UTF8-1      = %x00-7F
  6482.          *   UTF8-2      = %xC2-DF UTF8-tail
  6483.          *
  6484.          *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  6485.          *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  6486.          *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  6487.          *                 %xF4 %x80-8F 2( UTF8-tail )
  6488.          *   UTF8-tail   = %x80-BF
  6489.          *   ---------------------------------------------------------------------
  6490.          * </pre>
  6491.          * @param string $str string to process.
  6492.          * @return array containing codepoints (UTF-8 characters values)
  6493.          * @access protected
  6494.          * @author Nicola Asuni
  6495.          * @since 1.53.0.TC005 (2005-01-05)
  6496.          */
  6497.         protected function UTF8StringToArray($str{
  6498.             if (isset($this->cache_UTF8StringToArray[$str])) {
  6499.                 // return cached value
  6500.                 return($this->cache_UTF8StringToArray[$str]);
  6501.             }
  6502.             // check cache size
  6503.             if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray{
  6504.                 // remove first element
  6505.                 array_shift($this->cache_UTF8StringToArray);
  6506.             }
  6507.             ++$this->cache_size_UTF8StringToArray;
  6508.             if (!$this->isunicode{
  6509.                 // split string into array of equivalent codes
  6510.                 $strarr array();
  6511.                 $strlen strlen($str);
  6512.                 for($i=0$i $strlen++$i{
  6513.                     $strarr[ord($str{$i});
  6514.                 }
  6515.                 // insert new value on cache
  6516.                 $this->cache_UTF8StringToArray[$str$strarr;
  6517.                 return $strarr;
  6518.             }
  6519.             $unicode array()// array containing unicode values
  6520.             $bytes  array()// array containing single character byte sequences
  6521.             $numbytes  1// number of octetc needed to represent the UTF-8 character
  6522.             $str .= ''// force $str to be a string
  6523.             $length strlen($str);
  6524.             for($i 0$i $length++$i{
  6525.                 $char ord($str{$i})// get one string character at time
  6526.                 if (count($bytes== 0// get starting octect
  6527.                     if ($char <= 0x7F{
  6528.                         $unicode[$char// use the character "as is" because is ASCII
  6529.                         $numbytes 1;
  6530.                     elseif (($char >> 0x05== 0x06// 2 bytes character (0x06 = 110 BIN)
  6531.                         $bytes[($char 0xC0<< 0x06
  6532.                         $numbytes 2;
  6533.                     elseif (($char >> 0x04== 0x0E// 3 bytes character (0x0E = 1110 BIN)
  6534.                         $bytes[($char 0xE0<< 0x0C
  6535.                         $numbytes 3;
  6536.                     elseif (($char >> 0x03== 0x1E// 4 bytes character (0x1E = 11110 BIN)
  6537.                         $bytes[($char 0xF0<< 0x12
  6538.                         $numbytes 4;
  6539.                     else {
  6540.                         // use replacement character for other invalid sequences
  6541.                         $unicode[0xFFFD;
  6542.                         $bytes array();
  6543.                         $numbytes 1;
  6544.                     }
  6545.                 elseif (($char >> 0x06== 0x02// bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  6546.                     $bytes[$char 0x80;
  6547.                     if (count($bytes== $numbytes{
  6548.                         // compose UTF-8 bytes to a single unicode value
  6549.                         $char $bytes[0];
  6550.                         for($j 1$j $numbytes++$j{
  6551.                             $char += ($bytes[$j<< (($numbytes $j 10x06));
  6552.                         }
  6553.                         if ((($char >= 0xD800AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  6554.                             /* The definition of UTF-8 prohibits encoding character numbers between
  6555.                             U+D800 and U+DFFF, which are reserved for use with the UTF-16
  6556.                             encoding form (as surrogate pairs) and do not directly represent
  6557.                             characters. */
  6558.                             $unicode[0xFFFD// use replacement character
  6559.                         else {
  6560.                             $unicode[$char// add char to array
  6561.                         }
  6562.                         // reset data for next char
  6563.                         $bytes array()
  6564.                         $numbytes 1;
  6565.                     }
  6566.                 else {
  6567.                     // use replacement character for other invalid sequences
  6568.                     $unicode[0xFFFD;
  6569.                     $bytes array();
  6570.                     $numbytes 1;
  6571.                 }
  6572.             }
  6573.             // insert new value on cache
  6574.             $this->cache_UTF8StringToArray[$str$unicode;
  6575.             return $unicode;
  6576.         }
  6577.         
  6578.         /**
  6579.          * Converts UTF-8 strings to UTF16-BE.<br>
  6580.          * @param string $str string to process.
  6581.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  6582.          * @return string 
  6583.          * @access protected
  6584.          * @author Nicola Asuni
  6585.          * @since 1.53.0.TC005 (2005-01-05)
  6586.          * @uses UTF8StringToArray(), arrUTF8ToUTF16BE()
  6587.          */
  6588.         protected function UTF8ToUTF16BE($str$setbom=true{
  6589.             if (!$this->isunicode{
  6590.                 return $str// string is not in unicode
  6591.             }
  6592.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  6593.             return $this->arrUTF8ToUTF16BE($unicode$setbom);
  6594.         }
  6595.         
  6596.         /**
  6597.          * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  6598.          * @param string $str string to process.
  6599.          * @return string 
  6600.          * @author Andrew Whitehead, Nicola Asuni
  6601.          * @access protected
  6602.          * @since 3.2.000 (2008-06-23)
  6603.          */
  6604.         protected function UTF8ToLatin1($str{
  6605.             global $utf8tolatin;
  6606.             if (!$this->isunicode{
  6607.                 return $str// string is not in unicode
  6608.             }
  6609.             $outstr ''// string to be returned
  6610.             $unicode $this->UTF8StringToArray($str)// array containing UTF-8 unicode values
  6611.             foreach ($unicode as $char{
  6612.                 if ($char 256{
  6613.                     $outstr .= chr($char);
  6614.                 elseif (array_key_exists($char$utf8tolatin)) {
  6615.                     // map from UTF-8
  6616.                     $outstr .= chr($utf8tolatin[$char]);
  6617.                 elseif ($char == 0xFFFD{
  6618.                     // skip
  6619.                 else {
  6620.                     $outstr .= '?';
  6621.                 }
  6622.             }
  6623.             return $outstr;
  6624.         }
  6625.  
  6626.         /**
  6627.          * Converts array of UTF-8 characters to UTF16-BE string.<br>
  6628.          * Based on: http://www.faqs.org/rfcs/rfc2781.html
  6629.           * <pre>
  6630.          *   Encoding UTF-16:
  6631.          * 
  6632.           *   Encoding of a single character from an ISO 10646 character value to
  6633.          *    UTF-16 proceeds as follows. Let U be the character number, no greater
  6634.          *    than 0x10FFFF.
  6635.          * 
  6636.          *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  6637.          *       terminate.
  6638.          * 
  6639.          *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  6640.          *       U' must be less than or equal to 0xFFFFF. That is, U' can be
  6641.          *       represented in 20 bits.
  6642.          * 
  6643.          *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  6644.          *       0xDC00, respectively. These integers each have 10 bits free to
  6645.          *       encode the character value, for a total of 20 bits.
  6646.          * 
  6647.          *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  6648.          *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
  6649.          *       bits of W2. Terminate.
  6650.          * 
  6651.          *    Graphically, steps 2 through 4 look like:
  6652.          *    U' = yyyyyyyyyyxxxxxxxxxx
  6653.          *    W1 = 110110yyyyyyyyyy
  6654.          *    W2 = 110111xxxxxxxxxx
  6655.          * </pre>
  6656.          * @param array $unicode array containing UTF-8 unicode values
  6657.          * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  6658.          * @return string 
  6659.          * @access protected
  6660.          * @author Nicola Asuni
  6661.          * @since 2.1.000 (2008-01-08)
  6662.          * @see UTF8ToUTF16BE()
  6663.          */
  6664.         protected function arrUTF8ToUTF16BE($unicode$setbom=true{
  6665.             $outstr ''// string to be returned
  6666.             if ($setbom{
  6667.                 $outstr .= "\xFE\xFF"// Byte Order Mark (BOM)
  6668.             }
  6669.             foreach ($unicode as $char{
  6670.                 if ($char == 0xFFFD{
  6671.                     $outstr .= "\xFF\xFD"// replacement character
  6672.                 elseif ($char 0x10000{
  6673.                     $outstr .= chr($char >> 0x08);
  6674.                     $outstr .= chr($char 0xFF);
  6675.                 else {
  6676.                     $char -= 0x10000;
  6677.                     $w1 0xD800 ($char >> 0x10);
  6678.                     $w2 0xDC00 ($char 0x3FF);    
  6679.                     $outstr .= chr($w1 >> 0x08);
  6680.                     $outstr .= chr($w1 0xFF);
  6681.                     $outstr .= chr($w2 >> 0x08);
  6682.                     $outstr .= chr($w2 0xFF);
  6683.                 }
  6684.             }
  6685.             return $outstr;
  6686.         }
  6687.         // ====================================================
  6688.         
  6689.         /**
  6690.           * Set header font.
  6691.          * @param array $font font
  6692.          * @access public
  6693.          * @since 1.1
  6694.          */
  6695.         public function setHeaderFont($font{
  6696.             $this->header_font = $font;
  6697.         }
  6698.         
  6699.         /**
  6700.           * Get header font.
  6701.           * @return array() 
  6702.          * @access public
  6703.          * @since 4.0.012 (2008-07-24)
  6704.          */
  6705.         public function getHeaderFont({
  6706.             return $this->header_font;
  6707.         }
  6708.         
  6709.         /**
  6710.           * Set footer font.
  6711.          * @param array $font font
  6712.          * @access public
  6713.          * @since 1.1
  6714.          */
  6715.         public function setFooterFont($font{
  6716.             $this->footer_font = $font;
  6717.         }
  6718.         
  6719.         /**
  6720.           * Get Footer font.
  6721.           * @return array() 
  6722.          * @access public
  6723.          * @since 4.0.012 (2008-07-24)
  6724.          */
  6725.         public function getFooterFont({
  6726.             return $this->footer_font;
  6727.         }
  6728.         
  6729.         /**
  6730.           * Set language array.
  6731.          * @param array $language 
  6732.          * @access public
  6733.          * @since 1.1
  6734.          */
  6735.         public function setLanguageArray($language{
  6736.             $this->l = $language;
  6737.             $this->rtl = $this->l['a_meta_dir']=='rtl' true false;
  6738.         }
  6739.         
  6740.         /**
  6741.          * Returns the PDF data.
  6742.          * @access public
  6743.          */
  6744.         public function getPDFData({
  6745.             if ($this->state < 3{
  6746.                 $this->Close();
  6747.             }
  6748.             return $this->buffer;
  6749.         }
  6750.                 
  6751.         /**
  6752.          * Output anchor link.
  6753.          * @param string $url link URL or internal link (i.e.: &lt;a href="#23"&gt;link to page 23&lt;/a&gt;)
  6754.          * @param string $name link name
  6755.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  6756.          * @param boolean $firstline if true prints only the first line and return the remaining string.
  6757.          * @param array $color array of RGB text color
  6758.          * @param string $style font style (U, D, B, I)
  6759.          * @return the number of cells used or the remaining text if $firstline = true;
  6760.          * @access public
  6761.          */
  6762.         public function addHtmlLink($url$name$fill=0$firstline=false$color=''$style=-1{
  6763.             if (!$this->empty_string($urlAND ($url{0== '#')) {
  6764.                 // convert url to internal link
  6765.                 $page intval(substr($url1));
  6766.                 $url $this->AddLink();
  6767.                 $this->SetLink($url0$page);
  6768.             }
  6769.             // store current settings
  6770.             $prevcolor $this->fgcolor;
  6771.             $prevstyle $this->FontStyle;
  6772.             if (empty($color)) {
  6773.                 $this->SetTextColorArray($this->htmlLinkColorArray);
  6774.             else {
  6775.                 $this->SetTextColorArray($color);
  6776.             }
  6777.             if ($style == -1{
  6778.                 $this->SetFont(''$this->FontStyle.$this->htmlLinkFontStyle);
  6779.             else {
  6780.                 $this->SetFont(''$this->FontStyle.$style);
  6781.             }
  6782.             $ret $this->Write($this->lasth$name$url$fill''false0$firstline);
  6783.             // restore settings
  6784.             $this->SetFont(''$prevstyle);
  6785.             $this->SetTextColorArray($prevcolor);
  6786.             return $ret;
  6787.         }
  6788.         
  6789.         /**
  6790.          * 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).
  6791.          * @param string $color html color
  6792.          * @return array RGB color or false in case of error.
  6793.          * @access public
  6794.          */        
  6795.         public function convertHTMLColorToDec($color='#FFFFFF'{
  6796.             global $webcolor;
  6797.             $color preg_replace('/[\s]*/'''$color)// remove extra spaces
  6798.             $color strtolower($color);
  6799.             if (strlen($color== 0{
  6800.                 return false;
  6801.             }
  6802.             if (substr($color03== 'rgb'{
  6803.                 $codes substr($color4);
  6804.                 $codes str_replace(')'''$codes);
  6805.                 $returncolor explode(','$codes3);
  6806.                 return $returncolor;
  6807.             }
  6808.             if (substr($color01!= '#'{
  6809.                 // decode color name
  6810.                 if (isset($webcolor[$color])) {
  6811.                     $color_code $webcolor[$color];
  6812.                 else {
  6813.                     return false;
  6814.                 }
  6815.             else {
  6816.                 $color_code substr($color1);
  6817.             }
  6818.             switch (strlen($color_code)) {
  6819.                 case 3{
  6820.                     // three-digit hexadecimal representation
  6821.                     $r substr($color_code01);
  6822.                     $g substr($color_code11);
  6823.                     $b substr($color_code21);
  6824.                     $returncolor['R'hexdec($r.$r);
  6825.                     $returncolor['G'hexdec($g.$g);
  6826.                     $returncolor['B'hexdec($b.$b);
  6827.                     break;
  6828.                 }
  6829.                 case 6{
  6830.                     // six-digit hexadecimal representation
  6831.                     $returncolor['R'hexdec(substr($color_code02));
  6832.                     $returncolor['G'hexdec(substr($color_code22));
  6833.                     $returncolor['B'hexdec(substr($color_code42));
  6834.                     break;
  6835.                 }
  6836.             }
  6837.             return $returncolor;
  6838.         }
  6839.         
  6840.         /**
  6841.          * Converts pixels to User's Units.
  6842.          * @param int $px pixels
  6843.          * @return float value in user's unit
  6844.          * @access public
  6845.          */
  6846.         public function pixelsToUnits($px{
  6847.             return ($px $this->k);
  6848.         }
  6849.             
  6850.         /**
  6851.          * Reverse function for htmlentities.
  6852.          * Convert entities in UTF-8.
  6853.          * @param $text_to_convert Text to convert.
  6854.          * @return string converted
  6855.          * @access public
  6856.         */
  6857.         public function unhtmlentities($text_to_convert{
  6858.             return html_entity_decode($text_to_convertENT_QUOTES$this->encoding);
  6859.         }
  6860.         
  6861.         // ENCRYPTION METHODS ----------------------------------
  6862.         // SINCE 2.0.000 (2008-01-02)
  6863.         
  6864.         /**
  6865.         * Compute encryption key depending on object number where the encrypted data is stored
  6866.         * @param int $n object number
  6867.         * @access protected
  6868.         * @since 2.0.000 (2008-01-02)
  6869.         */
  6870.         protected function _objectkey($n{
  6871.             return substr($this->_md5_16($this->encryption_key.pack('VXxx'$n))010);
  6872.         }
  6873.         
  6874.         /**
  6875.          * Put encryption on PDF document.
  6876.          * @access protected
  6877.          * @since 2.0.000 (2008-01-02)
  6878.          */
  6879.         protected function _putencryption({
  6880.             $this->_out('/Filter /Standard');
  6881.             $this->_out('/V 1');
  6882.             $this->_out('/R 2');
  6883.             $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  6884.             $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  6885.             $this->_out('/P '.$this->Pvalue);
  6886.         }
  6887.         
  6888.         /**
  6889.         * Returns the input text exrypted using RC4 algorithm and the specified key.
  6890.         * RC4 is the standard encryption algorithm used in PDF format
  6891.         * @param string $key encryption key
  6892.         * @param String $text input text to be encrypted
  6893.         * @return String encrypted text
  6894.         * @access protected
  6895.         * @since 2.0.000 (2008-01-02)
  6896.         * @author Klemen Vodopivec
  6897.         */
  6898.         protected function _RC4($key$text{
  6899.             if ($this->last_rc4_key != $key{
  6900.                 $k str_repeat($key((256 strlen($key)) 1));
  6901.                 $rc4 range(0255);
  6902.                 $j 0;
  6903.                 for ($i 0$i 256++$i{
  6904.                     $t $rc4[$i];
  6905.                     $j ($j $t ord($k{$i})) 256;
  6906.                     $rc4[$i$rc4[$j];
  6907.                     $rc4[$j$t;
  6908.                 }
  6909.                 $this->last_rc4_key = $key;
  6910.                 $this->last_rc4_key_c = $rc4;
  6911.             else {
  6912.                 $rc4 $this->last_rc4_key_c;
  6913.             }
  6914.             $len strlen($text);
  6915.             $a 0;
  6916.             $b 0;
  6917.             $out '';
  6918.             for ($i 0$i $len++$i{
  6919.                 $a ($a 1256;
  6920.                 $t $rc4[$a];
  6921.                 $b ($b $t256;
  6922.                 $rc4[$a$rc4[$b];
  6923.                 $rc4[$b$t;
  6924.                 $k $rc4[($rc4[$a$rc4[$b]256];
  6925.                 $out .= chr(ord($text{$i}$k);
  6926.             }
  6927.             return $out;
  6928.         }
  6929.         
  6930.         /**
  6931.         * Encrypts a string using MD5 and returns it's value as a binary string.
  6932.         * @param string $str input string
  6933.         * @return String MD5 encrypted binary string
  6934.         * @access protected
  6935.         * @since 2.0.000 (2008-01-02)
  6936.         * @author Klemen Vodopivec
  6937.         */
  6938.         protected function _md5_16($str{
  6939.             return pack('H*'md5($str));
  6940.         }
  6941.         
  6942.         /**
  6943.         * Compute O value (used for RC4 encryption)
  6944.         * @param String $user_pass user password
  6945.         * @param String $owner_pass user password
  6946.         * @return String O value
  6947.         * @access protected
  6948.         * @since 2.0.000 (2008-01-02)
  6949.         * @author Klemen Vodopivec
  6950.         */
  6951.         protected function _Ovalue($user_pass$owner_pass{
  6952.             $tmp $this->_md5_16($owner_pass);
  6953.             $owner_RC4_key substr($tmp05);
  6954.             return $this->_RC4($owner_RC4_key$user_pass);
  6955.         }
  6956.         
  6957.         /**
  6958.         * Compute U value (used for RC4 encryption)
  6959.         * @return String U value
  6960.         * @access protected
  6961.         * @since 2.0.000 (2008-01-02)
  6962.         * @author Klemen Vodopivec
  6963.         */
  6964.         protected function _Uvalue({
  6965.             return $this->_RC4($this->encryption_key$this->padding);
  6966.         }
  6967.         
  6968.         /**
  6969.         * Compute encryption key
  6970.         * @param String $user_pass user password
  6971.         * @param String $owner_pass user password
  6972.         * @param String $protection protection type
  6973.         * @access protected
  6974.         * @since 2.0.000 (2008-01-02)
  6975.         * @author Klemen Vodopivec
  6976.         */
  6977.         protected function _generateencryptionkey($user_pass$owner_pass$protection{
  6978.             // Pad passwords
  6979.             $user_pass substr($user_pass.$this->padding032);
  6980.             $owner_pass substr($owner_pass.$this->padding032);
  6981.             // Compute O value
  6982.             $this->Ovalue = $this->_Ovalue($user_pass$owner_pass);
  6983.             // Compute encyption key
  6984.             $tmp $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
  6985.             $this->encryption_key = substr($tmp05);
  6986.             // Compute U value
  6987.             $this->Uvalue = $this->_Uvalue();
  6988.             // Compute P value
  6989.             $this->Pvalue = -(($protection^2551);
  6990.         }
  6991.         
  6992.         /**
  6993.         * Set document protection
  6994.         * The permission array is composed of values taken from the following ones:
  6995.         * - copy: copy text and images to the clipboard
  6996.         * - print: print the document
  6997.         * - modify: modify it (except for annotations and forms)
  6998.         * - annot-forms: add annotations and forms
  6999.         * Remark: the protection against modification is for people who have the full Acrobat product.
  7000.         * 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.
  7001.         * 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.
  7002.         * @param Array $permissions the set of permissions. Empty by default (only viewing is allowed). (print, modify, copy, annot-forms)
  7003.         * @param String $user_pass user password. Empty by default.
  7004.         * @param String $owner_pass owner password. If not specified, a random value is used.
  7005.         * @access public
  7006.         * @since 2.0.000 (2008-01-02)
  7007.         * @author Klemen Vodopivec
  7008.         */
  7009.         public function SetProtection($permissions=array()$user_pass=''$owner_pass=null{
  7010.             $options array('print' => 4'modify' => 8'copy' => 16'annot-forms' => 32);
  7011.             $protection 192;
  7012.             foreach ($permissions as $permission{
  7013.                 if (!isset($options[$permission])) {
  7014.                     $this->Error('Incorrect permission: '.$permission);
  7015.                 }
  7016.                 $protection += $options[$permission];
  7017.             }
  7018.             if ($owner_pass === null{
  7019.                 $owner_pass uniqid(rand());
  7020.             }
  7021.             $this->encrypted = true;
  7022.             $this->_generateencryptionkey($user_pass$owner_pass$protection);
  7023.         }
  7024.         
  7025.         // END OF ENCRYPTION FUNCTIONS -------------------------
  7026.         
  7027.         // START TRANSFORMATIONS SECTION -----------------------
  7028.         
  7029.         /**
  7030.         * Starts a 2D tranformation saving current graphic state.
  7031.         * This function must be called before scaling, mirroring, translation, rotation and skewing.
  7032.         * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  7033.         * @access public
  7034.         * @since 2.1.000 (2008-01-07)
  7035.         * @see StartTransform(), StopTransform()
  7036.         */
  7037.         public function StartTransform({
  7038.             $this->_out('q');
  7039.             $this->transfmrk[$this->page][$this->pagelen[$this->page];
  7040.         }
  7041.         
  7042.         /**
  7043.         * Stops a 2D tranformation restoring previous graphic state.
  7044.         * This function must be called after scaling, mirroring, translation, rotation and skewing.
  7045.         * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  7046.         * @access public
  7047.         * @since 2.1.000 (2008-01-07)
  7048.         * @see StartTransform(), StopTransform()
  7049.         */
  7050.         public function StopTransform({
  7051.             $this->_out('Q');
  7052.             if (isset($this->transfmatrix)) {
  7053.                 array_pop($this->transfmatrix);
  7054.             }
  7055.             array_pop($this->transfmrk[$this->page]);
  7056.         }
  7057.         /**
  7058.         * Horizontal Scaling.
  7059.         * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  7060.         * @param int $x abscissa of the scaling center. Default is current x position
  7061.         * @param int $y ordinate of the scaling center. Default is current y position
  7062.         * @access public
  7063.         * @since 2.1.000 (2008-01-07)
  7064.         * @see StartTransform(), StopTransform()
  7065.         */
  7066.         public function ScaleX($s_x$x=''$y=''{
  7067.             $this->Scale($s_x100$x$y);
  7068.         }
  7069.         
  7070.         /**
  7071.         * Vertical Scaling.
  7072.         * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  7073.         * @param int $x abscissa of the scaling center. Default is current x position
  7074.         * @param int $y ordinate of the scaling center. Default is current y position
  7075.         * @access public
  7076.         * @since 2.1.000 (2008-01-07)
  7077.         * @see StartTransform(), StopTransform()
  7078.         */
  7079.         public function ScaleY($s_y$x=''$y=''{
  7080.             $this->Scale(100$s_y$x$y);
  7081.         }
  7082.         
  7083.         /**
  7084.         * Vertical and horizontal proportional Scaling.
  7085.         * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  7086.         * @param int $x abscissa of the scaling center. Default is current x position
  7087.         * @param int $y ordinate of the scaling center. Default is current y position
  7088.         * @access public
  7089.         * @since 2.1.000 (2008-01-07)
  7090.         * @see StartTransform(), StopTransform()
  7091.         */
  7092.         public function ScaleXY($s$x=''$y=''{
  7093.             $this->Scale($s$s$x$y);
  7094.         }
  7095.         
  7096.         /**
  7097.         * Vertical and horizontal non-proportional Scaling.
  7098.         * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  7099.         * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  7100.         * @param int $x abscissa of the scaling center. Default is current x position
  7101.         * @param int $y ordinate of the scaling center. Default is current y position
  7102.         * @access public
  7103.         * @since 2.1.000 (2008-01-07)
  7104.         * @see StartTransform(), StopTransform()
  7105.         */
  7106.         public function Scale($s_x$s_y$x=''$y=''{
  7107.             if ($x === ''{
  7108.                 $x $this->x;
  7109.             }
  7110.             if ($y === ''{
  7111.                 $y $this->y;
  7112.             }
  7113.             if ($this->rtl{
  7114.                 $x $this->w - $x;
  7115.             }
  7116.             if (($s_x == 0OR ($s_y == 0)) {
  7117.                 $this->Error('Please do not use values equal to zero for scaling');
  7118.             }
  7119.             $y ($this->h - $y$this->k;
  7120.             $x *= $this->k;
  7121.             //calculate elements of transformation matrix
  7122.             $s_x /= 100;
  7123.             $s_y /= 100;
  7124.             $tm[0$s_x;
  7125.             $tm[10;
  7126.             $tm[20;
  7127.             $tm[3$s_y;
  7128.             $tm[4$x ($s_x);
  7129.             $tm[5$y ($s_y);
  7130.             //scale the coordinate system
  7131.             $this->Transform($tm);
  7132.         }
  7133.         
  7134.         /**
  7135.         * Horizontal Mirroring.
  7136.         * @param int $x abscissa of the point. Default is current x position
  7137.         * @access public
  7138.         * @since 2.1.000 (2008-01-07)
  7139.         * @see StartTransform(), StopTransform()
  7140.         */
  7141.         public function MirrorH($x=''{
  7142.             $this->Scale(-100100$x);
  7143.         }
  7144.         
  7145.         /**
  7146.         * Verical Mirroring.
  7147.         * @param int $y ordinate of the point. Default is current y position
  7148.         * @access public
  7149.         * @since 2.1.000 (2008-01-07)
  7150.         * @see StartTransform(), StopTransform()
  7151.         */
  7152.         public function MirrorV($y=''{
  7153.             $this->Scale(100-100''$y);
  7154.         }
  7155.         
  7156.         /**
  7157.         * Point reflection mirroring.
  7158.         * @param int $x abscissa of the point. Default is current x position
  7159.         * @param int $y ordinate of the point. Default is current y position
  7160.         * @access public
  7161.         * @since 2.1.000 (2008-01-07)
  7162.         * @see StartTransform(), StopTransform()
  7163.         */
  7164.         public function MirrorP($x='',$y=''{
  7165.             $this->Scale(-100-100$x$y);
  7166.         }
  7167.         
  7168.         /**
  7169.         * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  7170.         * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  7171.         * @param int $x abscissa of the point. Default is current x position
  7172.         * @param int $y ordinate of the point. Default is current y position
  7173.         * @access public
  7174.         * @since 2.1.000 (2008-01-07)
  7175.         * @see StartTransform(), StopTransform()
  7176.         */
  7177.         public function MirrorL($angle=0$x='',$y=''{
  7178.             $this->Scale(-100100$x$y);
  7179.             $this->Rotate(-2*($angle-90)$x$y);
  7180.         }
  7181.         
  7182.         /**
  7183.         * Translate graphic object horizontally.
  7184.         * @param int $t_x movement to the right (or left for RTL)
  7185.         * @access public
  7186.         * @since 2.1.000 (2008-01-07)
  7187.         * @see StartTransform(), StopTransform()
  7188.         */
  7189.         public function TranslateX($t_x{
  7190.             $this->Translate($t_x0);
  7191.         }
  7192.         
  7193.         /**
  7194.         * Translate graphic object vertically.
  7195.         * @param int $t_y movement to the bottom
  7196.         * @access public
  7197.         * @since 2.1.000 (2008-01-07)
  7198.         * @see StartTransform(), StopTransform()
  7199.         */
  7200.         public function TranslateY($t_y{
  7201.             $this->Translate(0$t_y);
  7202.         }
  7203.         
  7204.         /**
  7205.         * Translate graphic object horizontally and vertically.
  7206.         * @param int $t_x movement to the right
  7207.         * @param int $t_y movement to the bottom
  7208.         * @access public
  7209.         * @since 2.1.000 (2008-01-07)
  7210.         * @see StartTransform(), StopTransform()
  7211.         */
  7212.         public function Translate($t_x$t_y{
  7213.             if ($this->rtl{
  7214.                 $t_x = -$t_x;
  7215.             }
  7216.             //calculate elements of transformation matrix
  7217.             $tm[01;
  7218.             $tm[10;
  7219.             $tm[20;
  7220.             $tm[31;
  7221.             $tm[4$t_x $this->k;
  7222.             $tm[5= -$t_y $this->k;
  7223.             //translate the coordinate system
  7224.             $this->Transform($tm);
  7225.         }
  7226.         
  7227.         /**
  7228.         * Rotate object.
  7229.         * @param float $angle angle in degrees for counter-clockwise rotation
  7230.         * @param int $x abscissa of the rotation center. Default is current x position
  7231.         * @param int $y ordinate of the rotation center. Default is current y position
  7232.         * @access public
  7233.         * @since 2.1.000 (2008-01-07)
  7234.         * @see StartTransform(), StopTransform()
  7235.         */
  7236.         public function Rotate($angle$x=''$y=''{
  7237.             if ($x === ''{
  7238.                 $x $this->x;
  7239.             }
  7240.             if ($y === ''{
  7241.                 $y $this->y;
  7242.             }
  7243.             if ($this->rtl{
  7244.                 $x $this->w - $x;
  7245.                 $angle = -$angle;
  7246.             }
  7247.             $y ($this->h - $y$this->k;
  7248.             $x *= $this->k;
  7249.             //calculate elements of transformation matrix
  7250.             $tm[0cos(deg2rad($angle));
  7251.             $tm[1sin(deg2rad($angle));
  7252.             $tm[2= -$tm[1];
  7253.             $tm[3$tm[0];
  7254.             $tm[4$x ($tm[1$y($tm[0$x);
  7255.             $tm[5$y ($tm[0$y($tm[1$x);
  7256.             //rotate the coordinate system around ($x,$y)
  7257.             $this->Transform($tm);
  7258.         }
  7259.         
  7260.         /**
  7261.         * Skew horizontally.
  7262.         * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  7263.         * @param int $x abscissa of the skewing center. default is current x position
  7264.         * @param int $y ordinate of the skewing center. default is current y position
  7265.         * @access public
  7266.         * @since 2.1.000 (2008-01-07)
  7267.         * @see StartTransform(), StopTransform()
  7268.         */
  7269.         public function SkewX($angle_x$x=''$y=''{
  7270.             $this->Skew($angle_x0$x$y);
  7271.         }
  7272.         
  7273.         /**
  7274.         * Skew vertically.
  7275.         * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  7276.         * @param int $x abscissa of the skewing center. default is current x position
  7277.         * @param int $y ordinate of the skewing center. default is current y position
  7278.         * @access public
  7279.         * @since 2.1.000 (2008-01-07)
  7280.         * @see StartTransform(), StopTransform()
  7281.         */
  7282.         public function SkewY($angle_y$x=''$y=''{
  7283.             $this->Skew(0$angle_y$x$y);
  7284.         }
  7285.         
  7286.         /**
  7287.         * Skew.
  7288.         * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  7289.         * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  7290.         * @param int $x abscissa of the skewing center. default is current x position
  7291.         * @param int $y ordinate of the skewing center. default is current y position
  7292.         * @access public
  7293.         * @since 2.1.000 (2008-01-07)
  7294.         * @see StartTransform(), StopTransform()
  7295.         */
  7296.         public function Skew($angle_x$angle_y$x=''$y=''{
  7297.             if ($x === ''{
  7298.                 $x $this->x;
  7299.             }
  7300.             if ($y === ''{
  7301.                 $y $this->y;
  7302.             }
  7303.             if ($this->rtl{
  7304.                 $x $this->w - $x;
  7305.                 $angle_x = -$angle_x;
  7306.             }
  7307.             if (($angle_x <= -90OR ($angle_x >= 90OR ($angle_y <= -90OR ($angle_y >= 90)) {
  7308.                 $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  7309.             }
  7310.             $x *= $this->k;
  7311.             $y ($this->h - $y$this->k;
  7312.             //calculate elements of transformation matrix
  7313.             $tm[01;
  7314.             $tm[1tan(deg2rad($angle_y));
  7315.             $tm[2tan(deg2rad($angle_x));
  7316.             $tm[31;
  7317.             $tm[4= -$tm[2$y;
  7318.             $tm[5= -$tm[1$x;
  7319.             //skew the coordinate system
  7320.             $this->Transform($tm);
  7321.         }
  7322.         
  7323.         /**
  7324.         * Apply graphic transformations.
  7325.         * @access protected
  7326.         * @since 2.1.000 (2008-01-07)
  7327.         * @see StartTransform(), StopTransform()
  7328.         */
  7329.         protected function Transform($tm{
  7330.             $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'$tm[0]$tm[1]$tm[2]$tm[3]$tm[4]$tm[5]));
  7331.             // store transformation matrix
  7332.             $this->transfmatrix[array('a' => $tm[0]'b' => $tm[1]'c' => $tm[2]'d' => $tm[3]'e' => $tm[4]'f' => $tm[5]);
  7333.             // update tranformation mark
  7334.             if (end($this->transfmrk[$this->page]!== false{
  7335.                 $key key($this->transfmrk[$this->page]);
  7336.                 $this->transfmrk[$this->page][$key$this->pagelen[$this->page];
  7337.             }
  7338.         }
  7339.         
  7340.         // END TRANSFORMATIONS SECTION -------------------------
  7341.         
  7342.         
  7343.         // START GRAPHIC FUNCTIONS SECTION ---------------------
  7344.         // The following section is based on the code provided by David Hernandez Sanz
  7345.         
  7346.         /**
  7347.         * 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.
  7348.         * @param float $width The width.
  7349.         * @access public
  7350.         * @since 1.0
  7351.         * @see Line(), Rect(), Cell(), MultiCell()
  7352.         */
  7353.         public function SetLineWidth($width{
  7354.             //Set line width
  7355.             $this->LineWidth = $width;
  7356.             $this->linestyleWidth = sprintf('%.2F w'($width $this->k));
  7357.             $this->_out($this->linestyleWidth);
  7358.         }
  7359.         
  7360.         /**
  7361.         * Returns the current the line width.
  7362.         * @return int Line width
  7363.         * @access public
  7364.         * @since 2.1.000 (2008-01-07)
  7365.         * @see Line(), SetLineWidth()
  7366.         */
  7367.         public function GetLineWidth({
  7368.             return $this->LineWidth;
  7369.         }
  7370.         
  7371.         /**
  7372.         * Set line style.
  7373.         * @param array $style Line style. Array with keys among the following:
  7374.         *  <ul>
  7375.         *      <li>width (float): Width of the line in user units.</li>
  7376.         *      <li>cap (string): Type of cap to put on the line. Possible values are:
  7377.         *  butt, round, square. The difference between "square" and "butt" is that
  7378.         *  "square" projects a flat end past the end of the line.</li>
  7379.         *      <li>join (string): Type of join. Possible values are: miter, round,
  7380.         *  bevel.</li>
  7381.         *      <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  7382.         *  series of length values, which are the lengths of the on and off dashes.
  7383.         *  For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  7384.         *  1 off, 2 on, 1 off, ...</li>
  7385.         *      <li>phase (integer): Modifier on the dash pattern which is used to shift
  7386.         *  the point at which the pattern starts.</li>
  7387.         *      <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  7388.         *  </ul>
  7389.         * @access public
  7390.         * @since 2.1.000 (2008-01-08)
  7391.         */
  7392.         public function SetLineStyle($style{
  7393.             extract($style);
  7394.             if (isset($width)) {
  7395.                 $width_prev $this->LineWidth;
  7396.                 $this->SetLineWidth($width);
  7397.                 $this->LineWidth = $width_prev;
  7398.             }
  7399.             if (isset($cap)) {
  7400.                 $ca array('butt' => 0'round'=> 1'square' => 2);
  7401.                 if (isset($ca[$cap])) {
  7402.                     $this->linestyleCap = $ca[$cap].' J';
  7403.                     $this->_out($this->linestyleCap);
  7404.                 }
  7405.             }
  7406.             if (isset($join)) {
  7407.                 $ja array('miter' => 0'round' => 1'bevel' => 2);
  7408.                 if (isset($ja[$join])) {
  7409.                     $this->linestyleJoin = $ja[$join].' j';
  7410.                     $this->_out($this->linestyleJoin);
  7411.                 }
  7412.             }
  7413.             if (isset($dash)) {
  7414.                 $dash_string '';
  7415.                 if ($dash{
  7416.                     if (ereg('^.+,'$dash)) {
  7417.                         $tab explode(','$dash);
  7418.                     else {
  7419.                         $tab array($dash);
  7420.                     }
  7421.                     $dash_string '';
  7422.                     foreach ($tab as $i => $v{
  7423.                         if ($i{
  7424.                             $dash_string .= ' ';
  7425.                         }
  7426.                         $dash_string .= sprintf("%.2F"$v);
  7427.                     }
  7428.                 }
  7429.                 if (!isset($phaseOR !$dash{
  7430.                     $phase 0;
  7431.                 }
  7432.                 $this->linestyleDash = sprintf("[%s] %.2F d"$dash_string$phase);
  7433.                 $this->_out($this->linestyleDash);
  7434.             }
  7435.             if (isset($color)) {
  7436.                 $this->SetDrawColorArray($color);
  7437.             }
  7438.         }
  7439.         
  7440.         /*
  7441.         * Set a draw point.
  7442.         * @param float $x Abscissa of point.
  7443.         * @param float $y Ordinate of point.
  7444.         * @access protected
  7445.         * @since 2.1.000 (2008-01-08)
  7446.         */
  7447.         protected function _outPoint($x$y{
  7448.             if ($this->rtl{
  7449.                 $x $this->w - $x;
  7450.             }
  7451.             $this->_out(sprintf("%.2F %.2F m"$x $this->k($this->h - $y$this->k));
  7452.         }
  7453.         
  7454.         /*
  7455.         * Draws a line from last draw point.
  7456.         * @param float $x Abscissa of end point.
  7457.         * @param float $y Ordinate of end point.
  7458.         * @access protected
  7459.         * @since 2.1.000 (2008-01-08)
  7460.         */
  7461.         protected function _outLine($x$y{
  7462.             if ($this->rtl{
  7463.                 $x $this->w - $x;
  7464.             }
  7465.             $this->_out(sprintf("%.2F %.2F l"$x $this->k($this->h - $y$this->k));
  7466.         }
  7467.         
  7468.         /**
  7469.         * Draws a rectangle.
  7470.         * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  7471.         * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  7472.         * @param float $w Width.
  7473.         * @param float $h Height.
  7474.         * @param string $op options
  7475.         * @access protected
  7476.         * @since 2.1.000 (2008-01-08)
  7477.         */
  7478.         protected function _outRect($x$y$w$h$op{
  7479.             if ($this->rtl{
  7480.                 $x $this->w - $x $w;
  7481.             }
  7482.             $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s'$x*$this->k($this->h-$y)*$this->k$w*$this->k-$h*$this->k$op));
  7483.         }
  7484.         
  7485.         /*
  7486.         * Draws a Bezier curve from last draw point.
  7487.         * The Bezier curve is a tangent to the line between the control points at either end of the curve.
  7488.         * @param float $x1 Abscissa of control point 1.
  7489.         * @param float $y1 Ordinate of control point 1.
  7490.         * @param float $x2 Abscissa of control point 2.
  7491.         * @param float $y2 Ordinate of control point 2.
  7492.         * @param float $x3 Abscissa of end point.
  7493.         * @param float $y3 Ordinate of end point.
  7494.         * @access protected
  7495.         * @since 2.1.000 (2008-01-08)
  7496.         */
  7497.         protected function _outCurve($x1$y1$x2$y2$x3$y3{
  7498.             if ($this->rtl{
  7499.                 $x1 $this->w - $x1;
  7500.                 $x2 $this->w - $x2;
  7501.                 $x3 $this->w - $x3;
  7502.             }
  7503.             $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));
  7504.         }
  7505.         
  7506.         /**
  7507.         * Draws a line between two points.
  7508.         * @param float $x1 Abscissa of first point.
  7509.         * @param float $y1 Ordinate of first point.
  7510.         * @param float $x2 Abscissa of second point.
  7511.         * @param float $y2 Ordinate of second point.
  7512.         * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7513.         * @access public
  7514.         * @since 1.0
  7515.         * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  7516.         */
  7517.         public function Line($x1$y1$x2$y2$style=array()) {
  7518.             if ($style{
  7519.                 $this->SetLineStyle($style);
  7520.             }
  7521.             $this->_outPoint($x1$y1);
  7522.             $this->_outLine($x2$y2);
  7523.             $this->_out(' S');
  7524.         }
  7525.         
  7526.         /**
  7527.         * Draws a rectangle.
  7528.         * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  7529.         * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  7530.         * @param float $w Width.
  7531.         * @param float $h Height.
  7532.         * @param string $style Style of rendering. Possible values are:
  7533.         *  <ul>
  7534.         *      <li>D or empty string: Draw (default).</li>
  7535.         *      <li>F: Fill.</li>
  7536.         *      <li>DF or FD: Draw and fill.</li>
  7537.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7538.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7539.         *  </ul>
  7540.         * @param array $border_style Border style of rectangle. Array with keys among the following:
  7541.         *  <ul>
  7542.         *      <li>all: Line style of all borders. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7543.         *      <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7544.         *  </ul>
  7545.         *  If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  7546.         * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7547.         * @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).
  7548.         * @access public
  7549.         * @since 1.0
  7550.         * @see SetLineStyle()
  7551.         */
  7552.         public function Rect($x$y$w$h$style=''$border_style=array()$fill_color=array()) {
  7553.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7554.                 $this->SetFillColorArray($fill_color);
  7555.             }
  7556.             switch ($style{
  7557.                 case 'F'{
  7558.                     $op 'f';
  7559.                     $border_style array();
  7560.                     $this->_outRect($x$y$w$h$op);
  7561.                     break;
  7562.                 }
  7563.                 case 'DF':
  7564.                 case 'FD'{
  7565.                     if ((!$border_styleOR (isset($border_style['all']))) {
  7566.                         $op 'B';
  7567.                         if (isset($border_style['all'])) {
  7568.                             $this->SetLineStyle($border_style['all']);
  7569.                             $border_style array();
  7570.                         }
  7571.                     else {
  7572.                         $op 'f';
  7573.                     }
  7574.                     $this->_outRect($x$y$w$h$op);
  7575.                     break;
  7576.                 }
  7577.                 case 'CNZ'{
  7578.                     $op 'W n';
  7579.                     $this->_outRect($x$y$w$h$op);
  7580.                     break;
  7581.                 }
  7582.                 case 'CEO'{
  7583.                     $op 'W* n';
  7584.                     $this->_outRect($x$y$w$h$op);
  7585.                     break;
  7586.                 }
  7587.                 default{
  7588.                     $op 'S';
  7589.                     if ((!$border_styleOR (isset($border_style['all']))) {
  7590.                         if (isset($border_style['all']AND $border_style['all']{
  7591.                             $this->SetLineStyle($border_style['all']);
  7592.                             $border_style array();
  7593.                         }
  7594.                         $this->_outRect($x$y$w$h$op);
  7595.                     }
  7596.                     break;
  7597.                 }
  7598.             }
  7599.             if ($border_style{
  7600.                 $border_style2 array();
  7601.                 foreach ($border_style as $line => $value{
  7602.                     $lenght strlen($line);
  7603.                     for ($i 0$i $lenght++$i{
  7604.                         $border_style2[$line[$i]] $value;
  7605.                     }
  7606.                 }
  7607.                 $border_style $border_style2;
  7608.                 if (isset($border_style['L']AND $border_style['L']{
  7609.                     $this->Line($x$y$x$y $h$border_style['L']);
  7610.                 }
  7611.                 if (isset($border_style['T']AND $border_style['T']{
  7612.                     $this->Line($x$y$x $w$y$border_style['T']);
  7613.                 }
  7614.                 if (isset($border_style['R']AND $border_style['R']{
  7615.                     $this->Line($x $w$y$x $w$y $h$border_style['R']);
  7616.                 }
  7617.                 if (isset($border_style['B']AND $border_style['B']{
  7618.                     $this->Line($x$y $h$x $w$y $h$border_style['B']);
  7619.                 }
  7620.             }
  7621.         }
  7622.         
  7623.         
  7624.         /**
  7625.         * Draws a Bezier curve.
  7626.         * The Bezier curve is a tangent to the line between the control points at
  7627.         * either end of the curve.
  7628.         * @param float $x0 Abscissa of start point.
  7629.         * @param float $y0 Ordinate of start point.
  7630.         * @param float $x1 Abscissa of control point 1.
  7631.         * @param float $y1 Ordinate of control point 1.
  7632.         * @param float $x2 Abscissa of control point 2.
  7633.         * @param float $y2 Ordinate of control point 2.
  7634.         * @param float $x3 Abscissa of end point.
  7635.         * @param float $y3 Ordinate of end point.
  7636.         * @param string $style Style of rendering. Possible values are:
  7637.         *  <ul>
  7638.         *      <li>D or empty string: Draw (default).</li>
  7639.         *      <li>F: Fill.</li>
  7640.         *      <li>DF or FD: Draw and fill.</li>
  7641.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7642.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7643.         *  </ul>
  7644.         * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7645.         * @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).
  7646.         * @access public
  7647.         * @see SetLineStyle()
  7648.         * @since 2.1.000 (2008-01-08)
  7649.         */
  7650.         public function Curve($x0$y0$x1$y1$x2$y2$x3$y3$style=''$line_style=array()$fill_color=array()) {
  7651.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7652.                 $this->SetFillColorArray($fill_color);
  7653.             }
  7654.             switch ($style{
  7655.                 case 'F'{
  7656.                     $op 'f';
  7657.                     $line_style array();
  7658.                     break;
  7659.                 }
  7660.                 case 'FD'
  7661.                 case 'DF'{
  7662.                     $op 'B';
  7663.                     break;
  7664.                 }
  7665.                 case 'CNZ'{
  7666.                     $op 'W n';
  7667.                     break;
  7668.                 }
  7669.                 case 'CEO'{
  7670.                     $op 'W* n';
  7671.                     break;
  7672.                 }
  7673.                 default{
  7674.                     $op 'S';
  7675.                     break;
  7676.                 }
  7677.             }
  7678.             if ($line_style{
  7679.                 $this->SetLineStyle($line_style);
  7680.             }
  7681.             $this->_outPoint($x0$y0);
  7682.             $this->_outCurve($x1$y1$x2$y2$x3$y3);
  7683.             $this->_out($op);
  7684.         }
  7685.         
  7686.         /**
  7687.         * Draws a poly-Bezier curve.
  7688.         * Each Bezier curve segment is a tangent to the line between the control points at
  7689.         * either end of the curve.
  7690.         * @param float $x0 Abscissa of start point.
  7691.         * @param float $y0 Ordinate of start point.
  7692.         * @param float $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  7693.         * @param string $style Style of rendering. Possible values are:
  7694.         *  <ul>
  7695.         *      <li>D or empty string: Draw (default).</li>
  7696.         *      <li>F: Fill.</li>
  7697.         *      <li>DF or FD: Draw and fill.</li>
  7698.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7699.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7700.         *  </ul>
  7701.         * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7702.         * @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).
  7703.         * @access public
  7704.         * @see SetLineStyle()
  7705.         * @since 3.0008 (2008-05-12)
  7706.         */
  7707.         public function Polycurve($x0$y0$segments$style=''$line_style=array()$fill_color=array()) {
  7708.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7709.                 $this->SetFillColorArray($fill_color);
  7710.             }
  7711.             switch ($style{
  7712.                 case 'F'{
  7713.                     $op 'f';
  7714.                     $line_style array();
  7715.                     break;
  7716.                 }
  7717.                 case 'FD':
  7718.                 case 'DF'{
  7719.                     $op 'B';
  7720.                     break;
  7721.                 }
  7722.                 case 'CNZ'{
  7723.                     $op 'W n';
  7724.                     break;
  7725.                 }
  7726.                 case 'CEO'{
  7727.                     $op 'W* n';
  7728.                     break;
  7729.                 }
  7730.                 default{
  7731.                     $op 'S';
  7732.                     break;
  7733.                 }
  7734.             }
  7735.             if ($line_style{
  7736.                 $this->SetLineStyle($line_style);
  7737.             }
  7738.             $this->_outPoint($x0$y0);
  7739.             foreach ($segments as $segment{
  7740.                 list($x1$y1$x2$y2$x3$y3$segment;
  7741.                 $this->_outCurve($x1$y1$x2$y2$x3$y3);
  7742.             }    
  7743.             $this->_out($op);
  7744.         }
  7745.         
  7746.         /**
  7747.         * Draws an ellipse.
  7748.         * An ellipse is formed from n Bezier curves.
  7749.         * @param float $x0 Abscissa of center point.
  7750.         * @param float $y0 Ordinate of center point.
  7751.         * @param float $rx Horizontal radius.
  7752.         * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  7753.         * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  7754.         * @param float $astart: Angle start of draw line. Default value: 0.
  7755.         * @param float $afinish: Angle finish of draw line. Default value: 360.
  7756.         * @param string $style Style of rendering. Possible values are:
  7757.         *  <ul>
  7758.         *      <li>D or empty string: Draw (default).</li>
  7759.         *      <li>F: Fill.</li>
  7760.         *      <li>DF or FD: Draw and fill.</li>
  7761.         *      <li>C: Draw close.</li>
  7762.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7763.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7764.         *  </ul>
  7765.         * @param array $line_style Line style of ellipse. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7766.         * @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).
  7767.         * @param integer $nc Number of curves used in ellipse. Default value: 8.
  7768.         * @access public
  7769.         * @since 2.1.000 (2008-01-08)
  7770.         */
  7771.         public function Ellipse($x0$y0$rx$ry=0$angle=0$astart=0$afinish=360$style=''$line_style=array()$fill_color=array()$nc=8{
  7772.             if ($angle{
  7773.                 $this->StartTransform();
  7774.                 $this->Rotate($angle$x0$y0);
  7775.                 $this->Ellipse($x0$y0$rx$ry0$astart$afinish$style$line_style$fill_color$nc);
  7776.                 $this->StopTransform();
  7777.                 return;
  7778.             }
  7779.             if ($rx{
  7780.                 if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7781.                     $this->SetFillColorArray($fill_color);
  7782.                 }
  7783.                 switch ($style{
  7784.                     case 'F'{
  7785.                         $op 'f';
  7786.                         $line_style array();
  7787.                         break;
  7788.                     }
  7789.                     case 'FD'
  7790.                     case 'DF'{
  7791.                         $op 'B';
  7792.                         break;
  7793.                     }
  7794.                     case 'C'{
  7795.                         $op 's'// Small 's' signifies closing the path as well
  7796.                         break;
  7797.                     }
  7798.                     case 'CNZ'{
  7799.                         $op 'W n';
  7800.                         break;
  7801.                     }
  7802.                     case 'CEO'{
  7803.                         $op 'W* n';
  7804.                         break;
  7805.                     }
  7806.                     default{
  7807.                         $op 'S';
  7808.                         break;
  7809.                     }
  7810.                 }
  7811.                 if ($line_style{
  7812.                     $this->SetLineStyle($line_style);
  7813.                 }
  7814.                 if (!$ry{
  7815.                     $ry $rx;
  7816.                 }
  7817.                 $rx *= $this->k;
  7818.                 $ry *= $this->k;
  7819.                 if ($nc 2{
  7820.                     $nc 2;
  7821.                 }
  7822.                 $astart deg2rad((float) $astart);
  7823.                 $afinish deg2rad((float) $afinish);
  7824.                 $total_angle $afinish $astart;
  7825.                 $dt $total_angle $nc;
  7826.                 $dtm $dt 3;
  7827.                 $x0 *= $this->k;
  7828.                 $y0 ($this->h - $y0$this->k;
  7829.                 $t1 $astart;
  7830.                 $a0 $x0 ($rx cos($t1));
  7831.                 $b0 $y0 ($ry sin($t1));
  7832.                 $c0 = -$rx sin($t1);
  7833.                 $d0 $ry cos($t1);
  7834.                 $this->_outPoint($a0 $this->k$this->h - ($b0 $this->k));
  7835.                 for ($i 1$i <= $nc++$i{
  7836.                     // Draw this bit of the total curve
  7837.                     $t1 ($i $dt$astart;
  7838.                     $a1 $x0 ($rx cos($t1));
  7839.                     $b1 $y0 ($ry sin($t1));
  7840.                     $c1 = -$rx sin($t1);
  7841.                     $d1 $ry cos($t1);
  7842.                     $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));
  7843.                     $a0 $a1;
  7844.                     $b0 $b1;
  7845.                     $c0 $c1;
  7846.                     $d0 $d1;
  7847.                 }
  7848.                 $this->_out($op);
  7849.             }
  7850.         }
  7851.         
  7852.         /**
  7853.         * Draws a circle.
  7854.         * A circle is formed from n Bezier curves.
  7855.         * @param float $x0 Abscissa of center point.
  7856.         * @param float $y0 Ordinate of center point.
  7857.         * @param float $r Radius.
  7858.         * @param float $astart: Angle start of draw line. Default value: 0.
  7859.         * @param float $afinish: Angle finish of draw line. Default value: 360.
  7860.         * @param string $style Style of rendering. Possible values are:
  7861.         *  <ul>
  7862.         *      <li>D or empty string: Draw (default).</li>
  7863.         *      <li>F: Fill.</li>
  7864.         *      <li>DF or FD: Draw and fill.</li>
  7865.         *      <li>C: Draw close.</li>
  7866.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7867.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7868.         *  </ul>
  7869.         * @param array $line_style Line style of circle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  7870.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  7871.         * @param integer $nc Number of curves used in circle. Default value: 8.
  7872.         * @access public
  7873.         * @since 2.1.000 (2008-01-08)
  7874.         */
  7875.         public function Circle($x0$y0$r$astart=0$afinish=360$style=''$line_style=array()$fill_color=array()$nc=8{
  7876.             $this->Ellipse($x0$y0$r00$astart$afinish$style$line_style$fill_color$nc);
  7877.         }
  7878.         
  7879.         /**
  7880.         * Draws a polygon.
  7881.         * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  7882.         * @param string $style Style of rendering. Possible values are:
  7883.         *  <ul>
  7884.         *      <li>D or empty string: Draw (default).</li>
  7885.         *      <li>F: Fill.</li>
  7886.         *      <li>DF or FD: Draw and fill.</li>
  7887.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7888.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7889.         *  </ul>
  7890.         * @param array $line_style Line style of polygon. Array with keys among the following:
  7891.         *  <ul>
  7892.         *      <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7893.         *      <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7894.         *  </ul>
  7895.         *  If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  7896.         * @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).
  7897.         * @access public
  7898.         * @since 2.1.000 (2008-01-08)
  7899.         */
  7900.         public function Polygon($p$style=''$line_style=array()$fill_color=array()) {
  7901.             $np count($p2;
  7902.             if (!(false === strpos($style'F')) AND isset($fill_color)) {
  7903.                 $this->SetFillColorArray($fill_color);
  7904.             }
  7905.             switch ($style{
  7906.                 case 'F'{
  7907.                     $line_style array();
  7908.                     $op 'f';
  7909.                     break;
  7910.                 }
  7911.                 case 'FD'
  7912.                 case 'DF'{
  7913.                     $op 'B';
  7914.                     break;
  7915.                 }
  7916.                 case 'CNZ'{
  7917.                     $op 'W n';
  7918.                     break;
  7919.                 }
  7920.                 case 'CEO'{
  7921.                     $op 'W* n';
  7922.                     break;
  7923.                 }                
  7924.                 default{
  7925.                     $op 'S';
  7926.                     break;
  7927.                 }
  7928.             }
  7929.             $draw true;
  7930.             if ($line_style{
  7931.                 if (isset($line_style['all'])) {
  7932.                     $this->SetLineStyle($line_style['all']);
  7933.                 else // 0 .. (np - 1), op = {B, S}
  7934.                     $draw false;
  7935.                     if ('B' == $op{
  7936.                         $op 'f';
  7937.                         $this->_outPoint($p[0]$p[1]);
  7938.                         for ($i 2$i ($np 2)$i $i 2{
  7939.                             $this->_outLine($p[$i]$p[$i 1]);
  7940.                         }
  7941.                         $this->_outLine($p[0]$p[1]);
  7942.                         $this->_out($op);
  7943.                     }
  7944.                     $p[($np 2)$p[0];
  7945.                     $p[(($np 21)$p[1];
  7946.                     for ($i 0$i $np++$i{
  7947.                         if (isset($line_style[$i]AND ($line_style[$i!= 0)) {
  7948.                             $this->Line($p[($i 2)]$p[(($i 21)]$p[(($i 22)]$p[(($i 23)]$line_style[$i]);
  7949.                         }
  7950.                     }
  7951.                 }
  7952.             }
  7953.             if ($draw{
  7954.                 $this->_outPoint($p[0]$p[1]);
  7955.                 for ($i 2$i ($np 2)$i $i 2{
  7956.                     $this->_outLine($p[$i]$p[$i 1]);
  7957.                 }
  7958.                 $this->_outLine($p[0]$p[1]);
  7959.                 $this->_out($op);
  7960.             }
  7961.         }
  7962.         
  7963.         /**
  7964.         * Draws a regular polygon.
  7965.         * @param float $x0 Abscissa of center point.
  7966.         * @param float $y0 Ordinate of center point.
  7967.         * @param float $r: Radius of inscribed circle.
  7968.         * @param integer $ns Number of sides.
  7969.         * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  7970.         * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  7971.         * @param string $style Style of rendering. Possible values are:
  7972.         *  <ul>
  7973.         *      <li>D or empty string: Draw (default).</li>
  7974.         *      <li>F: Fill.</li>
  7975.         *      <li>DF or FD: Draw and fill.</li>
  7976.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7977.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7978.         *  </ul>
  7979.         * @param array $line_style Line style of polygon sides. Array with keys among the following:
  7980.         *  <ul>
  7981.         *      <li>all: Line style of all sides. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7982.         *      <li>0 to ($ns - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  7983.         *  </ul>
  7984.         *  If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  7985.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  7986.         * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  7987.         *  <ul>
  7988.         *      <li>D or empty string: Draw (default).</li>
  7989.         *      <li>F: Fill.</li>
  7990.         *      <li>DF or FD: Draw and fill.</li>
  7991.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  7992.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  7993.         *  </ul>
  7994.         * @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).
  7995.         * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  7996.         * @access public
  7997.         * @since 2.1.000 (2008-01-08)
  7998.         */
  7999.         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()) {
  8000.             if ($ns{
  8001.                 $ns 3;
  8002.             }
  8003.             if ($draw_circle{
  8004.                 $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  8005.             }
  8006.             $p array();
  8007.             for ($i 0$i $ns++$i{
  8008.                 $a $angle ($i 360 $ns);
  8009.                 $a_rad deg2rad((float) $a);
  8010.                 $p[$x0 ($r sin($a_rad));
  8011.                 $p[$y0 ($r cos($a_rad));
  8012.             }
  8013.             $this->Polygon($p$style$line_style$fill_color);
  8014.         }
  8015.         
  8016.         /**
  8017.         * Draws a star polygon
  8018.         * @param float $x0 Abscissa of center point.
  8019.         * @param float $y0 Ordinate of center point.
  8020.         * @param float $r Radius of inscribed circle.
  8021.         * @param integer $nv Number of vertices.
  8022.         * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  8023.         * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  8024.         * @param boolean $draw_circle: Draw inscribed circle or not. Default value is false.
  8025.         * @param string $style Style of rendering. Possible values are:
  8026.         *  <ul>
  8027.         *      <li>D or empty string: Draw (default).</li>
  8028.         *      <li>F: Fill.</li>
  8029.         *      <li>DF or FD: Draw and fill.</li>
  8030.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8031.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8032.         *  </ul>
  8033.         * @param array $line_style Line style of polygon sides. Array with keys among the following:
  8034.         *  <ul>
  8035.         *      <li>all: Line style of all sides. Array like for
  8036.         *  {@link SetLineStyle SetLineStyle}.</li>
  8037.         *      <li>0 to (n - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  8038.         *  </ul>
  8039.         *  If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  8040.         * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  8041.         * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  8042.         *  <ul>
  8043.         *      <li>D or empty string: Draw (default).</li>
  8044.         *      <li>F: Fill.</li>
  8045.         *      <li>DF or FD: Draw and fill.</li>
  8046.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8047.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8048.         *  </ul>
  8049.         * @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).
  8050.         * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  8051.         * @access public
  8052.         * @since 2.1.000 (2008-01-08)
  8053.         */
  8054.         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()) {
  8055.             if ($nv{
  8056.                 $nv 2;
  8057.             }
  8058.             if ($draw_circle{
  8059.                 $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  8060.             }
  8061.             $p2 array();
  8062.             $visited array();
  8063.             for ($i 0$i $nv++$i{
  8064.                 $a $angle ($i 360 $nv);
  8065.                 $a_rad deg2rad((float) $a);
  8066.                 $p2[$x0 ($r sin($a_rad));
  8067.                 $p2[$y0 ($r cos($a_rad));
  8068.                 $visited[false;
  8069.             }
  8070.             $p array();
  8071.             $i 0;
  8072.             do {
  8073.                 $p[$p2[$i 2];
  8074.                 $p[$p2[($i 21];
  8075.                 $visited[$itrue;
  8076.                 $i += $ng;
  8077.                 $i %= $nv;
  8078.             while (!$visited[$i]);
  8079.             $this->Polygon($p$style$line_style$fill_color);
  8080.         }
  8081.         
  8082.         /**
  8083.         * Draws a rounded rectangle.
  8084.         * @param float $x Abscissa of upper-left corner.
  8085.         * @param float $y Ordinate of upper-left corner.
  8086.         * @param float $w Width.
  8087.         * @param float $h Height.
  8088.         * @param float $r Radius of the rounded corners.
  8089.         * @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").
  8090.         * @param string $style Style of rendering. Possible values are:
  8091.         *  <ul>
  8092.         *      <li>D or empty string: Draw (default).</li>
  8093.         *      <li>F: Fill.</li>
  8094.         *      <li>DF or FD: Draw and fill.</li>
  8095.         *      <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  8096.         *      <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  8097.         *  </ul>
  8098.         * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  8099.         * @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).
  8100.         * @access public
  8101.         * @since 2.1.000 (2008-01-08)
  8102.         */
  8103.         public function RoundedRect($x$y$w$h$r$round_corner='1111'$style=''$border_style=array()$fill_color=array()) {
  8104.             if ('0000' == $round_corner// Not rounded
  8105.                 $this->Rect($x$y$w$h$style$border_style$fill_color);
  8106.             else // Rounded
  8107.                 if (!(false === strpos($style'F')) AND isset($fill_color)) {
  8108.                     $this->SetFillColorArray($fill_color);
  8109.                 }
  8110.                 switch ($style{
  8111.                     case 'F'{
  8112.                         $border_style array();
  8113.                         $op 'f';
  8114.                         break;
  8115.                     }
  8116.                     case 'FD'
  8117.                     case 'DF'{
  8118.                         $op 'B';
  8119.                         break;
  8120.                     }
  8121.                     case 'CNZ'{
  8122.                         $op 'W n';
  8123.                         break;
  8124.                     }
  8125.                     case 'CEO'{
  8126.                         $op 'W* n';
  8127.                         break;
  8128.                     }
  8129.                     default{
  8130.                         $op 'S';
  8131.                         break;
  8132.                     }
  8133.                 }
  8134.                 if ($border_style{
  8135.                     $this->SetLineStyle($border_style);
  8136.                 }
  8137.                 $MyArc (sqrt(21);
  8138.                 $this->_outPoint($x $r$y);
  8139.                 $xc $x $w $r;
  8140.                 $yc $y $r;
  8141.                 $this->_outLine($xc$y);
  8142.                 if ($round_corner[0]{
  8143.                     $this->_outCurve($xc ($r $MyArc)$yc $r$xc $r$yc ($r $MyArc)$xc $r$yc);
  8144.                 else {
  8145.                     $this->_outLine($x $w$y);
  8146.                 }
  8147.                 $xc $x $w $r;
  8148.                 $yc $y $h $r;
  8149.                 $this->_outLine($x $w$yc);
  8150.                 if ($round_corner[1]{
  8151.                     $this->_outCurve($xc $r$yc ($r $MyArc)$xc ($r $MyArc)$yc $r$xc$yc $r);
  8152.                 else {
  8153.                     $this->_outLine($x $w$y $h);
  8154.                 }
  8155.                 $xc $x $r;
  8156.                 $yc $y $h $r;
  8157.                 $this->_outLine($xc$y $h);
  8158.                 if ($round_corner[2]{
  8159.                     $this->_outCurve($xc ($r $MyArc)$yc $r$xc $r$yc ($r $MyArc)$xc $r$yc);
  8160.                 else {
  8161.                     $this->_outLine($x$y $h);
  8162.                 }
  8163.                 $xc $x $r;
  8164.                 $yc $y $r;
  8165.                 $this->_outLine($x$yc);
  8166.                 if ($round_corner[3]{
  8167.                     $this->_outCurve($xc $r$yc ($r $MyArc)$xc ($r $MyArc)$yc $r$xc$yc $r);
  8168.                 else {
  8169.                     $this->_outLine($x$y);
  8170.                     $this->_outLine($x $r$y);
  8171.                 }
  8172.                 $this->_out($op);
  8173.             }
  8174.         }
  8175.         
  8176.         // END GRAPHIC FUNCTIONS SECTION -----------------------
  8177.         
  8178.         // BIDIRECTIONAL TEXT SECTION --------------------------
  8179.         /**
  8180.          * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  8181.          * @param string $str string to manipulate.
  8182.          * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  8183.          * @return string 
  8184.          * @access protected
  8185.          * @author Nicola Asuni
  8186.          * @since 2.1.000 (2008-01-08)
  8187.         */
  8188.         protected function utf8StrRev($str$setbom=false$forcertl=false{
  8189.             return $this->arrUTF8ToUTF16BE($this->utf8Bidi($this->UTF8StringToArray($str)$str$forcertl)$setbom);
  8190.         }
  8191.         
  8192.         /**
  8193.          * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  8194.          * @param array $ta array of characters composing the string.
  8195.          * @param string $str string to process
  8196.          * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  8197.          * @return string 
  8198.          * @author Nicola Asuni
  8199.          * @access protected
  8200.          * @since 2.4.000 (2008-03-06)
  8201.         */
  8202.         protected function utf8Bidi($ta$str=''$forcertl=false{
  8203.             global $unicode$unicode_mirror$unicode_arlet$laa_array$diacritics;
  8204.             // paragraph embedding level
  8205.             $pel 0;
  8206.             // max level
  8207.             $maxlevel 0;
  8208.             if ($this->empty_string($str)) {
  8209.                 // create string from array
  8210.                 $str $this->UTF8ArrSubString($ta);
  8211.             }
  8212.             // check if string contains arabic text
  8213.             if (preg_match(K_RE_PATTERN_ARABIC$str)) {
  8214.                 $arabic true;
  8215.             else {
  8216.                 $arabic false;
  8217.             }
  8218.             // check if string contains RTL text
  8219.             if (!($forcertl OR $arabic OR preg_match(K_RE_PATTERN_RTL$str))) {
  8220.                 return $ta;
  8221.             }
  8222.             
  8223.             // get number of chars
  8224.             $numchars count($ta);
  8225.             
  8226.             if ($forcertl == 'R'{
  8227.                     $pel 1;
  8228.             elseif ($forcertl == 'L'{
  8229.                     $pel 0;
  8230.             else {
  8231.                 // P2. In each paragraph, find the first character of type L, AL, or R.
  8232.                 // 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.
  8233.                 for ($i=0$i $numchars++$i{
  8234.                     $type $unicode[$ta[$i]];
  8235.                     if ($type == 'L'{
  8236.                         $pel 0;
  8237.                         break;
  8238.                     elseif (($type == 'AL'OR ($type == 'R')) {
  8239.                         $pel 1;
  8240.                         break;
  8241.                     }
  8242.                 }
  8243.             }
  8244.             
  8245.             // Current Embedding Level
  8246.             $cel $pel;
  8247.             // directional override status
  8248.             $dos 'N';
  8249.             $remember array();
  8250.             // start-of-level-run
  8251.             $sor $pel 'R' 'L';
  8252.             $eor $sor;
  8253.             
  8254.             // Array of characters data
  8255.             $chardata Array();
  8256.             
  8257.             // 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.
  8258.             //     In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  8259.             for ($i=0$i $numchars++$i{
  8260.                 if ($ta[$i== K_RLE{
  8261.                     // X2. With each RLE, compute the least greater odd embedding level.
  8262.                     //    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.
  8263.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  8264.                     $next_level $cel ($cel 21;
  8265.                     if ($next_level 62{
  8266.                         $remember[array('num' => K_RLE'cel' => $cel'dos' => $dos);
  8267.                         $cel $next_level;
  8268.                         $dos 'N';
  8269.                         $sor $eor;
  8270.                         $eor $cel 'R' 'L';
  8271.                     }
  8272.                 elseif ($ta[$i== K_LRE{
  8273.                     // X3. With each LRE, compute the least greater even embedding level.
  8274.                     //    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.
  8275.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  8276.                     $next_level $cel ($cel 2);
  8277.                     if $next_level 62 {
  8278.                         $remember[array('num' => K_LRE'cel' => $cel'dos' => $dos);
  8279.                         $cel $next_level;
  8280.                         $dos 'N';
  8281.                         $sor $eor;
  8282.                         $eor $cel 'R' 'L';
  8283.                     }
  8284.                 elseif ($ta[$i== K_RLO{
  8285.                     // X4. With each RLO, compute the least greater odd embedding level.
  8286.                     //    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.
  8287.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  8288.                     $next_level $cel ($cel 21;
  8289.                     if ($next_level 62{
  8290.                         $remember[array('num' => K_RLO'cel' => $cel'dos' => $dos);
  8291.                         $cel $next_level;
  8292.                         $dos 'R';
  8293.                         $sor $eor;
  8294.                         $eor $cel 'R' 'L';
  8295.                     }
  8296.                 elseif ($ta[$i== K_LRO{
  8297.                     // X5. With each LRO, compute the least greater even embedding level.
  8298.                     //    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.
  8299.                     //    b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  8300.                     $next_level $cel ($cel 2);
  8301.                     if $next_level 62 {
  8302.                         $remember[array('num' => K_LRO'cel' => $cel'dos' => $dos);
  8303.                         $cel $next_level;
  8304.                         $dos 'L';
  8305.                         $sor $eor;
  8306.                         $eor $cel 'R' 'L';
  8307.                     }
  8308.                 elseif ($ta[$i== K_PDF{
  8309.                     // 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.
  8310.                     if (count($remember)) {
  8311.                         $last count($remember 1;
  8312.                         if (($remember[$last]['num'== K_RLEOR 
  8313.                               ($remember[$last]['num'== K_LREOR 
  8314.                               ($remember[$last]['num'== K_RLOOR 
  8315.                               ($remember[$last]['num'== K_LRO)) {
  8316.                             $match array_pop($remember);
  8317.                             $cel $match['cel'];
  8318.                             $dos $match['dos'];
  8319.                             $sor $eor;
  8320.                             $eor ($cel $match['cel'$cel $match['cel']'R' 'L';
  8321.                         }
  8322.                     }
  8323.                 elseif (($ta[$i!= K_RLEAND
  8324.                                  ($ta[$i!= K_LREAND
  8325.                                  ($ta[$i!= K_RLOAND
  8326.                                  ($ta[$i!= K_LROAND
  8327.                                  ($ta[$i!= K_PDF)) {
  8328.                     // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  8329.                     //    a. Set the level of the current character to the current embedding level.
  8330.                     //    b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  8331.                     if ($dos != 'N'{
  8332.                         $chardir $dos;
  8333.                     else {
  8334.                         $chardir $unicode[$ta[$i]];
  8335.                     }
  8336.                     // stores string characters and other information
  8337.                     $chardata[array('char' => $ta[$i]'level' => $cel'type' => $chardir'sor' => $sor'eor' => $eor);
  8338.                 }
  8339.             // end for each char
  8340.             
  8341.             // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  8342.             // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  8343.             // 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.
  8344.             
  8345.             // 3.3.3 Resolving Weak Types
  8346.             // 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.
  8347.             // Nonspacing marks are now resolved based on the previous characters.
  8348.             $numchars count($chardata);
  8349.             
  8350.             // 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.
  8351.             $prevlevel = -1// track level changes
  8352.             $levcount 0// counts consecutive chars at the same level
  8353.             for ($i=0$i $numchars++$i{
  8354.                 if ($chardata[$i]['type'== 'NSM'{
  8355.                     if ($levcount{
  8356.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8357.                     elseif ($i 0{
  8358.                         $chardata[$i]['type'$chardata[($i-1)]['type'];
  8359.                     }
  8360.                 }
  8361.                 if ($chardata[$i]['level'!= $prevlevel{
  8362.                     $levcount 0;
  8363.                 else {
  8364.                     ++$levcount;
  8365.                 }
  8366.                 $prevlevel $chardata[$i]['level'];
  8367.             }
  8368.             
  8369.             // 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.
  8370.             $prevlevel = -1;
  8371.             $levcount 0;
  8372.             for ($i=0$i $numchars++$i{
  8373.                 if ($chardata[$i]['char'== 'EN'{
  8374.                     for ($j=$levcount$j >= 0$j--{
  8375.                         if ($chardata[$j]['type'== 'AL'{
  8376.                             $chardata[$i]['type''AN';
  8377.                         elseif (($chardata[$j]['type'== 'L'OR ($chardata[$j]['type'== 'R')) {
  8378.                             break;
  8379.                         }
  8380.                     }
  8381.                 }
  8382.                 if ($chardata[$i]['level'!= $prevlevel{
  8383.                     $levcount 0;
  8384.                 else {
  8385.                     ++$levcount;
  8386.                 }
  8387.                 $prevlevel $chardata[$i]['level'];
  8388.             }
  8389.             
  8390.             // W3. Change all ALs to R.
  8391.             for ($i=0$i $numchars++$i{
  8392.                 if ($chardata[$i]['type'== 'AL'{
  8393.                     $chardata[$i]['type''R';
  8394.                 
  8395.             }
  8396.             
  8397.             // 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.
  8398.             $prevlevel = -1;
  8399.             $levcount 0;
  8400.             for ($i=0$i $numchars++$i{
  8401.                 if (($levcount 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  8402.                     if (($chardata[$i]['type'== 'ES'AND ($chardata[($i-1)]['type'== 'EN'AND ($chardata[($i+1)]['type'== 'EN')) {
  8403.                         $chardata[$i]['type''EN';
  8404.                     elseif (($chardata[$i]['type'== 'CS'AND ($chardata[($i-1)]['type'== 'EN'AND ($chardata[($i+1)]['type'== 'EN')) {
  8405.                         $chardata[$i]['type''EN';
  8406.                     elseif (($chardata[$i]['type'== 'CS'AND ($chardata[($i-1)]['type'== 'AN'AND ($chardata[($i+1)]['type'== 'AN')) {
  8407.                         $chardata[$i]['type''AN';
  8408.                     }
  8409.                 }
  8410.                 if ($chardata[$i]['level'!= $prevlevel{
  8411.                     $levcount 0;
  8412.                 else {
  8413.                     ++$levcount;
  8414.                 }
  8415.                 $prevlevel $chardata[$i]['level'];
  8416.             }
  8417.             
  8418.             // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  8419.             $prevlevel = -1;
  8420.             $levcount 0;
  8421.             for ($i=0$i $numchars++$i{
  8422.                 if ($chardata[$i]['type'== 'ET'{
  8423.                     if (($levcount 0AND ($chardata[($i-1)]['type'== 'EN')) {
  8424.                         $chardata[$i]['type''EN';
  8425.                     else {
  8426.                         $j $i+1;
  8427.                         while (($j $numcharsAND ($chardata[$j]['level'== $prevlevel)) {
  8428.                             if ($chardata[$j]['type'== 'EN'{
  8429.                                 $chardata[$i]['type''EN';
  8430.                                 break;
  8431.                             elseif ($chardata[$j]['type'!= 'ET'{
  8432.                                 break;
  8433.                             }
  8434.                             ++$j;
  8435.                         }
  8436.                     }
  8437.                 }
  8438.                 if ($chardata[$i]['level'!= $prevlevel{
  8439.                     $levcount 0;
  8440.                 else {
  8441.                     ++$levcount;
  8442.                 }
  8443.                 $prevlevel $chardata[$i]['level'];
  8444.             }
  8445.             
  8446.             // W6. Otherwise, separators and terminators change to Other Neutral.
  8447.             $prevlevel = -1;
  8448.             $levcount 0;
  8449.             for ($i=0$i $numchars++$i{
  8450.                 if (($chardata[$i]['type'== 'ET'OR ($chardata[$i]['type'== 'ES'OR ($chardata[$i]['type'== 'CS')) {
  8451.                     $chardata[$i]['type''ON';
  8452.                 }
  8453.                 if ($chardata[$i]['level'!= $prevlevel{
  8454.                     $levcount 0;
  8455.                 else {
  8456.                     ++$levcount;
  8457.                 }
  8458.                 $prevlevel $chardata[$i]['level'];
  8459.             }
  8460.             
  8461.             //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.
  8462.             $prevlevel = -1;
  8463.             $levcount 0;
  8464.             for ($i=0$i $numchars++$i{
  8465.                 if ($chardata[$i]['char'== 'EN'{
  8466.                     for ($j=$levcount$j >= 0$j--{
  8467.                         if ($chardata[$j]['type'== 'L'{
  8468.                             $chardata[$i]['type''L';
  8469.                         elseif ($chardata[$j]['type'== 'R'{
  8470.                             break;
  8471.                         }
  8472.                     }
  8473.                 }
  8474.                 if ($chardata[$i]['level'!= $prevlevel{
  8475.                     $levcount 0;
  8476.                 else {
  8477.                     ++$levcount;
  8478.                 }
  8479.                 $prevlevel $chardata[$i]['level'];
  8480.             }
  8481.             
  8482.             // 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.
  8483.             $prevlevel = -1;
  8484.             $levcount 0;
  8485.             for ($i=0$i $numchars++$i{
  8486.                 if (($levcount 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  8487.                     if (($chardata[$i]['type'== 'N'AND ($chardata[($i-1)]['type'== 'L'AND ($chardata[($i+1)]['type'== 'L')) {
  8488.                         $chardata[$i]['type''L';
  8489.                     elseif (($chardata[$i]['type'== 'N'AND
  8490.                      (($chardata[($i-1)]['type'== 'R'OR ($chardata[($i-1)]['type'== 'EN'OR ($chardata[($i-1)]['type'== 'AN')) AND
  8491.                      (($chardata[($i+1)]['type'== 'R'OR ($chardata[($i+1)]['type'== 'EN'OR ($chardata[($i+1)]['type'== 'AN'))) {
  8492.                         $chardata[$i]['type''R';
  8493.                     elseif ($chardata[$i]['type'== 'N'{
  8494.                         // N2. Any remaining neutrals take the embedding direction
  8495.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8496.                     }
  8497.                 elseif (($levcount == 0AND (($i+1$numcharsAND ($chardata[($i+1)]['level'== $prevlevel)) {
  8498.                     // first char
  8499.                     if (($chardata[$i]['type'== 'N'AND ($chardata[$i]['sor'== 'L'AND ($chardata[($i+1)]['type'== 'L')) {
  8500.                         $chardata[$i]['type''L';
  8501.                     elseif (($chardata[$i]['type'== 'N'AND
  8502.                      (($chardata[$i]['sor'== 'R'OR ($chardata[$i]['sor'== 'EN'OR ($chardata[$i]['sor'== 'AN')) AND
  8503.                      (($chardata[($i+1)]['type'== 'R'OR ($chardata[($i+1)]['type'== 'EN'OR ($chardata[($i+1)]['type'== 'AN'))) {
  8504.                         $chardata[$i]['type''R';
  8505.                     elseif ($chardata[$i]['type'== 'N'{
  8506.                         // N2. Any remaining neutrals take the embedding direction
  8507.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8508.                     }
  8509.                 elseif (($levcount 0AND ((($i+1== $numcharsOR (($i+1$numcharsAND ($chardata[($i+1)]['level'!= $prevlevel))) {
  8510.                     //last char
  8511.                     if (($chardata[$i]['type'== 'N'AND ($chardata[($i-1)]['type'== 'L'AND ($chardata[$i]['eor'== 'L')) {
  8512.                         $chardata[$i]['type''L';
  8513.                     elseif (($chardata[$i]['type'== 'N'AND
  8514.                      (($chardata[($i-1)]['type'== 'R'OR ($chardata[($i-1)]['type'== 'EN'OR ($chardata[($i-1)]['type'== 'AN')) AND
  8515.                      (($chardata[$i]['eor'== 'R'OR ($chardata[$i]['eor'== 'EN'OR ($chardata[$i]['eor'== 'AN'))) {
  8516.                         $chardata[$i]['type''R';
  8517.                     elseif ($chardata[$i]['type'== 'N'{
  8518.                         // N2. Any remaining neutrals take the embedding direction
  8519.                         $chardata[$i]['type'$chardata[$i]['sor'];
  8520.                     }
  8521.                 elseif ($chardata[$i]['type'== 'N'{
  8522.                     // N2. Any remaining neutrals take the embedding direction
  8523.                     $chardata[$i]['type'$chardata[$i]['sor'];
  8524.                 }
  8525.                 if ($chardata[$i]['level'!= $prevlevel{
  8526.                     $levcount 0;
  8527.                 else {
  8528.                     ++$levcount;
  8529.                 }
  8530.                 $prevlevel $chardata[$i]['level'];
  8531.             }
  8532.             
  8533.             // 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.
  8534.             // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  8535.             for ($i=0$i $numchars++$i{
  8536.                 $odd $chardata[$i]['level'2;
  8537.                 if ($odd{
  8538.                     if (($chardata[$i]['type'== 'L'OR ($chardata[$i]['type'== 'AN'OR ($chardata[$i]['type'== 'EN')) {
  8539.                         $chardata[$i]['level'+= 1;
  8540.                     }
  8541.                 else {
  8542.                     if ($chardata[$i]['type'== 'R'{
  8543.                         $chardata[$i]['level'+= 1;
  8544.                     elseif (($chardata[$i]['type'== 'AN'OR ($chardata[$i]['type'== 'EN')) {
  8545.                         $chardata[$i]['level'+= 2;
  8546.                     }
  8547.                 }
  8548.                 $maxlevel max($chardata[$i]['level'],$maxlevel);
  8549.             }
  8550.             
  8551.             // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  8552.             //    1. Segment separators,
  8553.             //    2. Paragraph separators,
  8554.             //    3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  8555.             //    4. Any sequence of white space characters at the end of the line.
  8556.             for ($i=0$i $numchars++$i{
  8557.                 if (($chardata[$i]['type'== 'B'OR ($chardata[$i]['type'== 'S')) {
  8558.                     $chardata[$i]['level'$pel;
  8559.                 elseif ($chardata[$i]['type'== 'WS'{
  8560.                     $j $i+1;
  8561.                     while ($j $numchars{
  8562.                         if ((($chardata[$j]['type'== 'B'OR ($chardata[$j]['type'== 'S')) OR
  8563.                             (($j == ($numchars-1)) AND ($chardata[$j]['type'== 'WS'))) {
  8564.                             $chardata[$i]['level'$pel;
  8565.                             break;
  8566.                         elseif ($chardata[$j]['type'!= 'WS'{
  8567.                             break;
  8568.                         }
  8569.                         ++$j;
  8570.                     }
  8571.                 }
  8572.             }
  8573.             
  8574.             // Arabic Shaping
  8575.             // 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. 
  8576.             if ($arabic{
  8577.                 $endedletter array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
  8578.                 $alfletter array(1570,1571,1573,1575);
  8579.                 $chardata2 $chardata;
  8580.                 $laaletter false;
  8581.                 $charAL array();
  8582.                 $x 0;
  8583.                 for ($i=0$i $numchars++$i{
  8584.                     if (($unicode[$chardata[$i]['char']] == 'AL'OR ($chardata[$i]['char'== 32OR ($chardata[$i]['char'== 8204)) {
  8585.                         $charAL[$x$chardata[$i];
  8586.                         $charAL[$x]['i'$i;
  8587.                         $chardata[$i]['x'$x;
  8588.                         ++$x;
  8589.                     }
  8590.                 }
  8591.                 $numAL $x;
  8592.                 for ($i=0$i $numchars++$i{
  8593.                     $thischar $chardata[$i];
  8594.                     if ($i 0{
  8595.                         $prevchar $chardata[($i-1)];
  8596.                     else {
  8597.                         $prevchar false;
  8598.                     }
  8599.                     if (($i+1$numchars{
  8600.                         $nextchar $chardata[($i+1)];
  8601.                     else {
  8602.                         $nextchar false;
  8603.                     }
  8604.                     if ($unicode[$thischar['char']] == 'AL'{
  8605.                         $x $thischar['x'];
  8606.                         if ($x 0{
  8607.                             $prevchar $charAL[($x-1)];
  8608.                         else {
  8609.                             $prevchar false;
  8610.                         }
  8611.                         if (($x+1$numAL{
  8612.                             $nextchar $charAL[($x+1)];
  8613.                         else {
  8614.                             $nextchar false;
  8615.                         }
  8616.                         // if laa letter
  8617.                         if (($prevchar !== falseAND ($prevchar['char'== 1604AND (in_array($thischar['char']$alfletter))) {
  8618.                             $arabicarr $laa_array;
  8619.                             $laaletter true;
  8620.                             if ($x 1{
  8621.                                 $prevchar $charAL[($x-2)];
  8622.                             else {
  8623.                                 $prevchar false;
  8624.                             }
  8625.                         else {
  8626.                             $arabicarr $unicode_arlet;
  8627.                             $laaletter false;
  8628.                         }
  8629.                         if (($prevchar !== falseAND ($nextchar !== falseAND
  8630.                             (($unicode[$prevchar['char']] == 'AL'OR ($unicode[$prevchar['char']] == 'NSM')) AND
  8631.                             (($unicode[$nextchar['char']] == 'AL'OR ($unicode[$nextchar['char']] == 'NSM')) AND
  8632.                             ($prevchar['type'== $thischar['type']AND
  8633.                             ($nextchar['type'== $thischar['type']AND
  8634.                             ($nextchar['char'!= 1567)) {
  8635.                             if (in_array($prevchar['char']$endedletter)) {
  8636.                                 if (isset($arabicarr[$thischar['char']][2])) {
  8637.                                     // initial
  8638.                                     $chardata2[$i]['char'$arabicarr[$thischar['char']][2];
  8639.                                 }
  8640.                             else {
  8641.                                 if (isset($arabicarr[$thischar['char']][3])) {
  8642.                                     // medial
  8643.                                     $chardata2[$i]['char'$arabicarr[$thischar['char']][3];
  8644.                                 }
  8645.                             }
  8646.                         elseif (($nextchar !== falseAND
  8647.                             (($unicode[$nextchar['char']] == 'AL'OR ($unicode[$nextchar['char']] == 'NSM')) AND
  8648.                             ($nextchar['type'== $thischar['type']AND
  8649.                             ($nextchar['char'!= 1567)) {
  8650.                             if (isset($arabicarr[$chardata[$i]['char']][2])) {
  8651.                                 // initial
  8652.                                 $chardata2[$i]['char'$arabicarr[$thischar['char']][2];
  8653.                             }
  8654.                         elseif ((($prevchar !== falseAND
  8655.                             (($unicode[$prevchar['char']] == 'AL'OR ($unicode[$prevchar['char']] == 'NSM')) AND
  8656.                             ($prevchar['type'== $thischar['type'])) OR
  8657.                             (($nextchar !== falseAND ($nextchar['char'== 1567))) {
  8658.                             // final
  8659.                             if (($i 1AND ($thischar['char'== 1607AND
  8660.                                 ($chardata[$i-1]['char'== 1604AND
  8661.                                 ($chardata[$i-2]['char'== 1604)) {
  8662.                                 //Allah Word
  8663.                                 // mark characters to delete with false
  8664.                                 $chardata2[$i-2]['char'false;
  8665.                                 $chardata2[$i-1]['char'false
  8666.                                 $chardata2[$i]['char'65010;
  8667.                             else {
  8668.                                 if (($prevchar !== falseAND in_array($prevchar['char']$endedletter)) {
  8669.                                     if (isset($arabicarr[$thischar['char']][0])) {
  8670.                                         // isolated
  8671.                                         $chardata2[$i]['char'$arabicarr[$thischar['char']][0];
  8672.                                     }
  8673.                                 else {
  8674.                                     if (isset($arabicarr[$thischar['char']][1])) {
  8675.                                         // final
  8676.                                         $chardata2[$i]['char'$arabicarr[$thischar['char']][1];
  8677.                                     }
  8678.                                 }
  8679.                             }
  8680.                         elseif (isset($arabicarr[$thischar['char']][0])) {
  8681.                             // isolated
  8682.                             $chardata2[$i]['char'$arabicarr[$thischar['char']][0];
  8683.                         }
  8684.                         // if laa letter
  8685.                         if ($laaletter{
  8686.                             // mark characters to delete with false
  8687.                             $chardata2[($charAL[($x-1)]['i'])]['char'false;
  8688.                         }
  8689.                     // end if AL (Arabic Letter)
  8690.                 // end for each char
  8691.                 /* 
  8692.                  * Combining characters that can occur with Shadda (0651 HEX, 1617 DEC) are placed in UE586-UE594. 
  8693.                  * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  8694.                  */
  8695.                 $cw &$this->CurrentFont['cw'];
  8696.                 for ($i 0$i ($numchars-1)++$i{
  8697.                     if (($chardata2[$i]['char'== 1617AND (isset($diacritics[($chardata2[$i+1]['char'])]))) {
  8698.                         // check if the subtitution font is defined on current font
  8699.                         if (isset($cw[($diacritics[($chardata2[$i+1]['char'])])])) {
  8700.                             $chardata2[$i]['char'false;
  8701.                             $chardata2[$i+1]['char'$diacritics[($chardata2[$i+1]['char'])];
  8702.                         }
  8703.                     }
  8704.                 }
  8705.                 // remove marked characters
  8706.                 foreach ($chardata2 as $key => $value{
  8707.                     if ($value['char'=== false{
  8708.                         unset($chardata2[$key]);
  8709.                     }
  8710.                 }
  8711.                 $chardata array_values($chardata2);
  8712.                 $numchars count($chardata);
  8713.                 unset($chardata2);
  8714.                 unset($arabicarr);
  8715.                 unset($laaletter);
  8716.                 unset($charAL);
  8717.             }
  8718.             
  8719.             // 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.
  8720.             for ($j=$maxlevel$j 0$j--{
  8721.                 $ordarray Array();
  8722.                 $revarr Array();
  8723.                 $onlevel false;
  8724.                 for ($i=0$i $numchars++$i{
  8725.                     if ($chardata[$i]['level'>= $j{
  8726.                         $onlevel true;
  8727.                         if (isset($unicode_mirror[$chardata[$i]['char']])) {
  8728.                             // 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.
  8729.                             $chardata[$i]['char'$unicode_mirror[$chardata[$i]['char']];
  8730.                         }
  8731.                         $revarr[$chardata[$i];
  8732.                     else {
  8733.                         if ($onlevel{
  8734.                             $revarr array_reverse($revarr);
  8735.                             $ordarray array_merge($ordarray$revarr);
  8736.                             $revarr Array();
  8737.                             $onlevel false;
  8738.                         }
  8739.                         $ordarray[$chardata[$i];
  8740.                     }
  8741.                 }
  8742.                 if ($onlevel{
  8743.                     $revarr array_reverse($revarr);
  8744.                     $ordarray array_merge($ordarray$revarr);
  8745.                 }
  8746.                 $chardata $ordarray;
  8747.             }
  8748.             
  8749.             $ordarray array();
  8750.             for ($i=0$i $numchars++$i{
  8751.                 $ordarray[$chardata[$i]['char'];
  8752.             }
  8753.             
  8754.             return $ordarray;
  8755.         }
  8756.         
  8757.         // END OF BIDIRECTIONAL TEXT SECTION -------------------
  8758.         
  8759.         /*
  8760.         * Adds a bookmark.
  8761.         * @param string $txt bookmark description.
  8762.         * @param int $level bookmark level (minimum value is 0).
  8763.         * @param float $y Ordinate of the boorkmark position (default = -1 = current position).
  8764.         * @param int $page target page number (leave empty for current page).
  8765.         * @access public
  8766.         * @author Olivier Plathey, Nicola Asuni
  8767.         * @since 2.1.002 (2008-02-12)
  8768.         */
  8769.         public function Bookmark($txt$level=0$y=-1$page=''{
  8770.             if ($level 0{
  8771.                 $level 0;
  8772.             }
  8773.             if (isset($this->outlines[0])) {
  8774.                 $lastoutline end($this->outlines);
  8775.                 $maxlevel $lastoutline['l'1;
  8776.             else {
  8777.                 $maxlevel 0;
  8778.             }
  8779.             if ($level $maxlevel{
  8780.                 $level $maxlevel;
  8781.             }
  8782.             if ($y == -1{
  8783.                 $y $this->GetY();
  8784.             }
  8785.             if (empty($page)) {
  8786.                 $page $this->PageNo();
  8787.             }
  8788.             $this->outlines[array('t' => $txt'l' => $level'y' => $y'p' => $page);
  8789.         }
  8790.         
  8791.         /*
  8792.         * Create a bookmark PDF string.
  8793.         * @access protected
  8794.         * @author Olivier Plathey, Nicola Asuni
  8795.         * @since 2.1.002 (2008-02-12)
  8796.         */
  8797.         protected function _putbookmarks({
  8798.             $nb count($this->outlines);
  8799.             if ($nb == 0{
  8800.                 return;
  8801.             }
  8802.             $lru array();
  8803.             $level 0;
  8804.             foreach ($this->outlines as $i => $o{
  8805.                 if ($o['l'0{
  8806.                     $parent $lru[($o['l'1)];
  8807.                     //Set parent and last pointers
  8808.                     $this->outlines[$i]['parent'$parent;
  8809.                     $this->outlines[$parent]['last'$i;
  8810.                     if ($o['l'$level{
  8811.                         //Level increasing: set first pointer
  8812.                         $this->outlines[$parent]['first'$i;
  8813.                     }
  8814.                 else {
  8815.                     $this->outlines[$i]['parent'$nb;
  8816.                 }
  8817.                 if (($o['l'<= $levelAND ($i 0)) {
  8818.                     //Set prev and next pointers
  8819.                     $prev $lru[$o['l']];
  8820.                     $this->outlines[$prev]['next'$i;
  8821.                     $this->outlines[$i]['prev'$prev;
  8822.                 }
  8823.                 $lru[$o['l']] $i;
  8824.                 $level $o['l'];
  8825.             }
  8826.             //Outline items
  8827.             $n $this->n + 1;
  8828.             foreach ($this->outlines as $i => $o{
  8829.                 $this->_newobj();
  8830.                 $this->_out('<</Title '.$this->_textstring($o['t']));
  8831.                 $this->_out('/Parent '.($n $o['parent']).' 0 R');
  8832.                 if (isset($o['prev']))
  8833.                 $this->_out('/Prev '.($n $o['prev']).' 0 R');
  8834.                 if (isset($o['next']))
  8835.                 $this->_out('/Next '.($n $o['next']).' 0 R');
  8836.                 if (isset($o['first']))
  8837.                 $this->_out('/First '.($n $o['first']).' 0 R');
  8838.                 if (isset($o['last']))
  8839.                 $this->_out('/Last '.($n $o['last']).' 0 R');
  8840.                 $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]'(($o['p']))($this->pagedim[$o['p']]['h'($o['y'$this->k))));
  8841.                 $this->_out('/Count 0>>');
  8842.                 $this->_out('endobj');
  8843.             }
  8844.             //Outline root
  8845.             $this->_newobj();
  8846.             $this->OutlineRoot = $this->n;
  8847.             $this->_out('<</Type /Outlines /First '.$n.' 0 R');
  8848.             $this->_out('/Last '.($n $lru[0]).' 0 R>>');
  8849.             $this->_out('endobj');
  8850.         }
  8851.         
  8852.         
  8853.         // --- JAVASCRIPT - FORMS ------------------------------
  8854.         
  8855.         /*
  8856.         * Adds a javascript
  8857.         * @access public
  8858.         * @author Johannes Güntert, Nicola Asuni
  8859.         * @since 2.1.002 (2008-02-12)
  8860.         */
  8861.         public function IncludeJS($script{
  8862.             $this->javascript .= $script;
  8863.         }
  8864.         
  8865.         /*
  8866.         * Create a javascript PDF string.
  8867.         * @access protected
  8868.         * @author Johannes Güntert, Nicola Asuni
  8869.         * @since 2.1.002 (2008-02-12)
  8870.         */
  8871.         protected function _putjavascript({
  8872.             if (empty($this->javascript)) {
  8873.                 return;
  8874.             }
  8875.             // the following two lines are uded to avoid form fields duplication after saving
  8876.             $js1 sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);"'tcpdfdocsaved''text'00101);
  8877.             $js2 "getField('tcpdfdocsaved').value = 'saved';";
  8878.             $this->_newobj();
  8879.             $this->n_js = $this->n;
  8880.             $this->_out('<<');
  8881.             $this->_out('/Names [(EmbeddedJS) '.($this->n + 1).' 0 R ]');
  8882.             $this->_out('>>');
  8883.             $this->_out('endobj');
  8884.             $this->_newobj();
  8885.             $this->_out('<<');
  8886.             $this->_out('/S /JavaScript');
  8887.             $this->_out('/JS '.$this->_textstring($js1."\n".$this->javascript."\n".$js2));
  8888.             $this->_out('>>');
  8889.             $this->_out('endobj');
  8890.         }
  8891.         
  8892.         /*
  8893.         * Convert color to javascript color.
  8894.         * @param string $color color name or #RRGGBB
  8895.         * @access protected
  8896.         * @author Denis Van Nuffelen, Nicola Asuni
  8897.         * @since 2.1.002 (2008-02-12)
  8898.         */
  8899.         protected function _JScolor($color{
  8900.             static $aColors array('transparent''black''white''red''green''blue''cyan''magenta''yellow''dkGray''gray''ltGray');
  8901.             if (substr($color,0,1== '#'{
  8902.                 return sprintf("['RGB',%.3F,%.3F,%.3F]"hexdec(substr($color,1,2))/255hexdec(substr($color,3,2))/255hexdec(substr($color,5,2))/255);
  8903.             }
  8904.             if (!in_array($color,$aColors)) {
  8905.                 $this->Error('Invalid color: '.$color);
  8906.             }
  8907.             return 'color.'.$color;
  8908.         }
  8909.         
  8910.         /*
  8911.         * Adds a javascript form field.
  8912.         * @param string $type field type
  8913.         * @param string $name field name
  8914.         * @param int $x horizontal position
  8915.         * @param int $y vertical position
  8916.         * @param int $w width
  8917.         * @param int $h height
  8918.         * @param array $prop array of properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8919.         * @access protected
  8920.         * @author Denis Van Nuffelen, Nicola Asuni
  8921.         * @since 2.1.002 (2008-02-12)
  8922.         */
  8923.         protected function _addfield($type$name$x$y$w$h$prop{
  8924.             if ($this->rtl{
  8925.                 $x $x $w;
  8926.             }
  8927.             // the followind avoid fields duplication after saving the document
  8928.             $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
  8929.             $k $this->k;
  8930.             $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";
  8931.             $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  8932.             while (list($key$valeach($prop)) {
  8933.                 if (strcmp(substr($key-5)'Color'== 0{
  8934.                     $val $this->_JScolor($val);
  8935.                 else {
  8936.                     $val "'".$val."'";
  8937.                 }
  8938.                 $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  8939.             }
  8940.             if ($this->rtl{
  8941.                 $this->x -= $w;
  8942.             else {
  8943.                 $this->x += $w;
  8944.             }
  8945.             $this->javascript .= '}';
  8946.         }
  8947.         
  8948.         /*
  8949.         * Creates a text field
  8950.         * @param string $name field name
  8951.         * @param int $w width
  8952.         * @param int $h height
  8953.         * @param string $prop properties. The value property allows to set the initial value. The multiline property allows to define the field as multiline. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8954.         * @access public
  8955.         * @author Denis Van Nuffelen, Nicola Asuni
  8956.         * @since 2.1.002 (2008-02-12)
  8957.         */
  8958.         public function TextField($name$w$h$prop=array()) {
  8959.             $this->_addfield('text'$name$this->x$this->y$w$h$prop);
  8960.         }
  8961.         
  8962.         /*
  8963.         * Creates a RadioButton field
  8964.         * @param string $name field name
  8965.         * @param int $w width
  8966.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8967.         * @access public
  8968.         * @author Nicola Asuni
  8969.         * @since 2.2.003 (2008-03-03)
  8970.         */
  8971.         public function RadioButton($name$w$prop=array()) {
  8972.             if (!isset($prop['strokeColor'])) {
  8973.                 $prop['strokeColor']='black';
  8974.             }
  8975.             $this->_addfield('radiobutton'$name$this->x$this->y$w$w$prop);
  8976.         }
  8977.         
  8978.         /*
  8979.         * Creates a List-box field
  8980.         * @param string $name field name
  8981.         * @param int $w width
  8982.         * @param int $h height
  8983.         * @param array $values array containing the list of values.
  8984.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  8985.         * @access public
  8986.         * @author Nicola Asuni
  8987.         * @since 2.2.003 (2008-03-03)
  8988.         */
  8989.         public function ListBox($name$w$h$values$prop=array()) {
  8990.             if (!isset($prop['strokeColor'])) {
  8991.                 $prop['strokeColor''ltGray';
  8992.             }
  8993.             $this->_addfield('listbox'$name$this->x$this->y$w$h$prop);
  8994.             $s '';
  8995.             foreach ($values as $value{
  8996.                 $s .= "'".addslashes($value)."',";
  8997.             }
  8998.             $this->javascript .= 'f'.$name.'.setItems(['.substr($s0-1)."]);\n";
  8999.         }
  9000.         
  9001.         /*
  9002.         * Creates a Combo-box field
  9003.         * @param string $name field name
  9004.         * @param int $w width
  9005.         * @param int $h height
  9006.         * @param array $values array containing the list of values.
  9007.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  9008.         * @access public
  9009.         * @author Denis Van Nuffelen, Nicola Asuni
  9010.         * @since 2.1.002 (2008-02-12)
  9011.         */
  9012.         public function ComboBox($name$w$h$values$prop=array()) {
  9013.             $this->_addfield('combobox'$name$this->x$this->y$w$h$prop);
  9014.             $s '';
  9015.             foreach ($values as $value{
  9016.                 $s .= "'".addslashes($value)."',";
  9017.             }
  9018.             $this->javascript .= 'f'.$name.'.setItems(['.substr($s0-1)."]);\n";
  9019.         }
  9020.         
  9021.         /*
  9022.         * Creates a CheckBox field
  9023.         * @param string $name field name
  9024.         * @param int $w width
  9025.         * @param boolean $checked define the initial state (default = false).
  9026.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  9027.         * @access public
  9028.         * @author Denis Van Nuffelen, Nicola Asuni
  9029.         * @since 2.1.002 (2008-02-12)
  9030.         */
  9031.         public function CheckBox($name$w$checked=false$prop=array()) {
  9032.             $prop['value'($checked 'Yes' 'Off');
  9033.             if (!isset($prop['strokeColor'])) {
  9034.                 $prop['strokeColor''black';
  9035.             }
  9036.             $this->_addfield('checkbox'$name$this->x$this->y$w$w$prop);
  9037.         }
  9038.         
  9039.         /*
  9040.         * Creates a button field
  9041.         * @param string $name field name
  9042.         * @param int $w width
  9043.         * @param int $h height
  9044.         * @param string $caption caption.
  9045.         * @param string $action action triggered by the button (JavaScript code).
  9046.         * @param string $prop properties. Possible values are (http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf): <ul><li>rect: Position and size of field on page.</li><li>borderStyle: Rectangle border appearance.</li><li>strokeColor: Color of bounding rectangle.</li><li>lineWidth: Width of the edge of the surrounding rectangle.</li><li>rotation: Rotation of field in 90-degree increments.</li><li>fillColor: Background color of field (gray, transparent, RGB, or CMYK).</li><li>userName: Short description of field that appears on mouse-over.</li><li>readonly: Whether the user may change the field contents.</li><li>doNotScroll: Whether text fields may scroll.</li><li>display: Whether visible or hidden on screen or in print.</li><li>textFont: Text font.</li><li>textColor: Text color.</li><li>textSize: Text size.</li><li>richText: Rich text.</li><li>richValue: Text.</li><li>comb: Text comb format.</li><li>multiline: Text multiline.</li><li>charLimit: Text limit to number of characters.</li><li>fileSelect: Text file selection format.</li><li>password: Text password format.</li><li>alignment: Text layout in text fields.</li><li>buttonAlignX: X alignment of icon on button face.</li><li>buttonAlignY: Y alignment of icon on button face.</li><li>buttonFitBounds: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleHow: Relative scaling of an icon to fit inside a button face.</li><li>buttonScaleWhen: Relative scaling of an icon to fit inside a button face.</li><li>highlight: Appearance of a button when pushed.</li><li>style: Glyph style for checkbox and radio buttons.</li><li>numItems: Number of items in a combo box or list box.</li><li>editable: Whether the user can type in a combo box.</li><li>multipleSelection: Whether multiple list box items may be selected.</li></ul>
  9047.         * @access public
  9048.         * @author Denis Van Nuffelen, Nicola Asuni
  9049.         * @since 2.1.002 (2008-02-12)
  9050.         */
  9051.         public function Button($name$w$h$caption$action$prop=array()) {
  9052.             if (!isset($prop['strokeColor'])) {
  9053.                 $prop['strokeColor''black';
  9054.             }
  9055.             if (!isset($prop['borderStyle'])) {
  9056.                 $prop['borderStyle''beveled';
  9057.             }
  9058.             $this->_addfield('button'$name$this->x$this->y$w$h$prop);
  9059.             $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  9060.             $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  9061.             $this->javascript .= 'f'.$name.".highlight='push';\n";
  9062.             $this->javascript .= 'f'.$name.".print=false;\n";
  9063.         }
  9064.         
  9065.         // END JAVASCRIPT - FORMS ------------------------------
  9066.         
  9067.         /*
  9068.         * Enable Write permissions for PDF Reader.
  9069.         * (EXPERIMENTAL - ONLY WORKS WITH SOME ACROBAT READER VERSIONS)
  9070.         * TO BE COMPLETED
  9071.         * @access protected
  9072.         * @author Nicola Asuni
  9073.         * @since 2.9.000 (2008-03-26)
  9074.         */
  9075.         protected function _putuserrights({
  9076.             if (!$this->ur{
  9077.                 return;
  9078.             }
  9079.             $this->_out('/Perms');
  9080.             $this->_out('<<');
  9081.             $this->_out('/UR3');
  9082.             $this->_out('<<');            
  9083.             $this->_out('/Type/Sig');
  9084.             $this->_out('/Filter/Adobe.PPKLite');
  9085.             $this->_out('/SubFilter/adbe.pkcs7.detached');
  9086.             $this->_out('/Name(TCPDF)');
  9087.             $this->_out('/ByteRange[0 0 0 0]');
  9088.             $this->_out('/Contents<>');
  9089.             $this->_out('/M '.$this->_datastring('D:'.date('YmdHis')));
  9090.             $this->_out('/Reference');
  9091.             $this->_out('[');
  9092.             $this->_out('<<');
  9093.             $this->_out('/Type/SigRef');
  9094.             $this->_out('/TransformMethod/UR3');
  9095.             $this->_out('/TransformParams');
  9096.             $this->_out('<<');
  9097.             $this->_out('/Type/TransformParams');
  9098.             $this->_out('/V/2.2');
  9099.             if (!$this->empty_string($this->ur_document)) {
  9100.                 $this->_out('/Document['.$this->ur_document.']');
  9101.             }
  9102.             if (!$this->empty_string($this->ur_annots)) {
  9103.                 $this->_out('/Annots['.$this->ur_annots.']');
  9104.             }
  9105.             if (!$this->empty_string($this->ur_form)) {
  9106.                 $this->_out('/Form['.$this->ur_form.']');
  9107.             }
  9108.             if (!$this->empty_string($this->ur_signature)) {
  9109.                 $this->_out('/Signature['.$this->ur_signature.']');
  9110.             }            
  9111.             $this->_out('>>');
  9112.             $this->_out('>>');
  9113.             $this->_out(']');
  9114.             $this->_out('>>');
  9115.             $this->_out('>>');
  9116.         }
  9117.         
  9118.         /*
  9119.         * Set User's Rights for PDF Reader
  9120.         * Check the PDF Reference 8.7.1 Transform Methods, 
  9121.         * Table 8.105 Entries in the UR transform parameters dictionary
  9122.         * @param boolean $enable if true enable user's rights on PDF reader
  9123.         * @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.
  9124.         * @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.
  9125.         * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate 
  9126.         * @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.
  9127.         * @access public
  9128.         * @author Nicola Asuni
  9129.         * @since 2.9.000 (2008-03-26)
  9130.         */
  9131.         public function setUserRights(
  9132.                 $enable=true
  9133.                 $document='/FullSave',
  9134.                 $annots='/Create/Delete/Modify/Copy/Import/Export',
  9135.                 $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  9136.                 $signature='/Modify'{
  9137.             $this->ur $enable;
  9138.             $this->ur_document $document;
  9139.             $this->ur_annots $annots;
  9140.             $this->ur_form $form;
  9141.             $this->ur_signature $signature;
  9142.         }
  9143.         
  9144.         /*
  9145.         * Create a new page group.
  9146.         * NOTE: call this function before calling AddPage()
  9147.         * @param int $page starting group page (leave empty for next page).
  9148.         * @access public
  9149.         * @since 3.0.000 (2008-03-27)
  9150.         */
  9151.         public function startPageGroup($page=''{
  9152.             if (empty($page)) {
  9153.                 $page $this->page 1;
  9154.             }
  9155.             $this->newpagegroup[$pagetrue;
  9156.         }
  9157.  
  9158.         /**
  9159.         * Defines an alias for the total number of pages.
  9160.         * It will be substituted as the document is closed.
  9161.         * @param string $alias The alias.
  9162.         * @access public
  9163.         * @since 1.4
  9164.         * @see getAliasNbPages(), PageNo(), Footer()
  9165.         */
  9166.         public function AliasNbPages($alias='{nb}'{
  9167.             $this->AliasNbPages = $alias;
  9168.         }
  9169.         
  9170.         /**
  9171.          * Returns the string alias used for the total number of pages.
  9172.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  9173.          * @return string 
  9174.          * @access public
  9175.          * @since 4.0.018 (2008-08-08)
  9176.          * @see AliasNbPages(), PageNo(), Footer()
  9177.         */
  9178.         public function getAliasNbPages({
  9179.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  9180.                 return '{'.$this->AliasNbPages.'}';
  9181.             }
  9182.             return $this->AliasNbPages;
  9183.         }
  9184.  
  9185.         /**
  9186.         * Defines an alias for the page number.
  9187.         * It will be substituted as the document is closed.
  9188.         * @param string $alias The alias.
  9189.         * @access public
  9190.         * @since 4.5.000 (2009-01-02)
  9191.         * @see getAliasNbPages(), PageNo(), Footer()
  9192.         */
  9193.         public function AliasNumPage($alias='{pnb}'{
  9194.             //Define an alias for total number of pages
  9195.             $this->AliasNumPage = $alias;
  9196.         }
  9197.         
  9198.         /**
  9199.          * Returns the string alias used for the page number.
  9200.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  9201.          * @return string 
  9202.          * @access public
  9203.          * @since 4.5.000 (2009-01-02)
  9204.          * @see AliasNbPages(), PageNo(), Footer()
  9205.         */
  9206.         public function getAliasNumPage({
  9207.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  9208.                 return '{'.$this->AliasNumPage.'}';
  9209.             }
  9210.             return $this->AliasNumPage;
  9211.         }
  9212.         
  9213.         /*
  9214.         * Return the current page in the group.
  9215.         * @return current page in the group
  9216.         * @access public
  9217.         * @since 3.0.000 (2008-03-27)
  9218.         */
  9219.         public function getGroupPageNo({
  9220.             return $this->pagegroups[$this->currpagegroup];
  9221.         }
  9222.  
  9223.         /**
  9224.         * Returns the current group page number formatted as a string.
  9225.         * @access public
  9226.         * @since 4.3.003 (2008-11-18)
  9227.         * @see PaneNo(), formatPageNumber()
  9228.         */
  9229.         public function getGroupPageNoFormatted({
  9230.             return $this->formatPageNumber($this->getGroupPageNo());
  9231.         }
  9232.         
  9233.         /*
  9234.          * Return the alias of the current page group
  9235.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  9236.          * (will be replaced by the total number of pages in this group).
  9237.          * @return alias of the current page group
  9238.          * @access public
  9239.          * @since 3.0.000 (2008-03-27)
  9240.         */
  9241.         public function getPageGroupAlias({
  9242.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  9243.                 return '{'.$this->currpagegroup.'}';
  9244.             }
  9245.             return $this->currpagegroup;
  9246.         }
  9247.         
  9248.         /*
  9249.          * Return the alias for the page number on the current page group
  9250.          * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  9251.          * (will be replaced by the total number of pages in this group).
  9252.          * @return alias of the current page group
  9253.          * @access public
  9254.          * @since 4.5.000 (2009-01-02)
  9255.         */
  9256.         public function getPageNumGroupAlias({
  9257.             if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  9258.                 return '{'.str_replace('{nb''{pnb'$this->currpagegroup).'}';
  9259.             }
  9260.             return str_replace('{nb''{pnb'$this->currpagegroup);
  9261.         }
  9262.  
  9263.         /**
  9264.         * Format the page numbers.
  9265.         * This method can be overriden for custom formats.
  9266.         * @param int $num page number
  9267.         * @access protected
  9268.         * @since 4.2.005 (2008-11-06)
  9269.         */
  9270.         protected function formatPageNumber($num{
  9271.             return number_format((float)$num0'''.');
  9272.         }
  9273.  
  9274.         /**
  9275.         * Format the page numbers on the Table Of Content.
  9276.         * This method can be overriden for custom formats.
  9277.         * @param int $num page number
  9278.         * @access protected
  9279.         * @since 4.5.001 (2009-01-04)
  9280.         * @see addTOC()
  9281.         */
  9282.         protected function formatTOCPageNumber($num{
  9283.             return number_format((float)$num0'''.');
  9284.         }
  9285.  
  9286.         /**
  9287.         * Returns the current page number formatted as a string.
  9288.         * @access public
  9289.         * @since 4.2.005 (2008-11-06)
  9290.         * @see PaneNo(), formatPageNumber()
  9291.         */
  9292.         public function PageNoFormatted({
  9293.             return $this->formatPageNumber($this->PageNo());
  9294.         }
  9295.  
  9296.         /*
  9297.         * Put visibility settings.
  9298.         * @access protected
  9299.         * @since 3.0.000 (2008-03-27)
  9300.         */
  9301.         protected function _putocg({
  9302.             $this->_newobj();
  9303.             $this->n_ocg_print $this->n;
  9304.             $this->_out('<</Type /OCG /Name '.$this->_textstring('print'));
  9305.             $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
  9306.             $this->_out('endobj');
  9307.             $this->_newobj();
  9308.             $this->n_ocg_view=$this->n;
  9309.             $this->_out('<</Type /OCG /Name '.$this->_textstring('view'));
  9310.             $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
  9311.             $this->_out('endobj');
  9312.         }
  9313.         
  9314.         /*
  9315.         * Set the visibility of the successive elements.
  9316.         * This can be useful, for instance, to put a background 
  9317.         * image or color that will show on screen but won't print.
  9318.         * @param string $v visibility mode. Legal values are: all, print, screen.
  9319.         * @access public
  9320.         * @since 3.0.000 (2008-03-27)
  9321.         */
  9322.         public function setVisibility($v{
  9323.             if ($this->openMarkedContent{
  9324.                 // close existing open marked-content
  9325.                 $this->_out('EMC');
  9326.                 $this->openMarkedContent false;
  9327.             }
  9328.             switch($v{
  9329.                 case 'print'{
  9330.                     $this->_out('/OC /OC1 BDC');
  9331.                     $this->openMarkedContent true;
  9332.                     break;
  9333.                 }
  9334.                 case 'screen'{
  9335.                     $this->_out('/OC /OC2 BDC');
  9336.                     $this->openMarkedContent true;
  9337.                     break;
  9338.                 }
  9339.                 case 'all'{
  9340.                     $this->_out('');
  9341.                     break;
  9342.                 }
  9343.                 default{
  9344.                     $this->Error('Incorrect visibility: '.$v);
  9345.                     break;
  9346.                 }
  9347.             }
  9348.             $this->visibility $v;
  9349.         }
  9350.         
  9351.         /*
  9352.         * Add transparency parameters to the current extgstate
  9353.         * @param array $params parameters
  9354.         * @return the number of extgstates
  9355.         * @access protected
  9356.         * @since 3.0.000 (2008-03-27)
  9357.         */
  9358.         protected function addExtGState($parms{
  9359.             $n count($this->extgstates1;
  9360.             $this->extgstates[$n]['parms'$parms;
  9361.             return $n;
  9362.         }
  9363.         
  9364.         /*
  9365.         * Add an extgstate
  9366.         * @param array $gs extgstate
  9367.         * @access protected
  9368.         * @since 3.0.000 (2008-03-27)
  9369.         */
  9370.         protected function setExtGState($gs{
  9371.             $this->_out(sprintf('/GS%d gs'$gs));
  9372.         }
  9373.         
  9374.         /*
  9375.         * Put extgstates for object transparency
  9376.         * @param array $gs extgstate
  9377.         * @access protected
  9378.         * @since 3.0.000 (2008-03-27)
  9379.         */
  9380.         protected function _putextgstates({
  9381.             $ne count($this->extgstates);
  9382.             for ($i 1$i <= $ne++$i{
  9383.                 $this->_newobj();
  9384.                 $this->extgstates[$i]['n'$this->n;
  9385.                 $this->_out('<</Type /ExtGState');
  9386.                 foreach ($this->extgstates[$i]['parms'as $k => $v{
  9387.                     $this->_out('/'.$k.' '.$v);
  9388.                 }
  9389.                 $this->_out('>>');
  9390.                 $this->_out('endobj');
  9391.             }
  9392.         }
  9393.         
  9394.         /*
  9395.         * Set alpha for stroking (CA) and non-stroking (ca) operations.
  9396.         * @param float $alpha real value from 0 (transparent) to 1 (opaque)
  9397.         * @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
  9398.         * @access public
  9399.         * @since 3.0.000 (2008-03-27)
  9400.         */
  9401.         public function setAlpha($alpha$bm='Normal'{
  9402.             $gs $this->addExtGState(array('ca' => $alpha'CA' => $alpha'BM' => '/'.$bm));
  9403.             $this->setExtGState($gs);
  9404.         }
  9405.  
  9406.         /*
  9407.         * Set the default JPEG compression quality (1-100)
  9408.         * @param int $quality JPEG quality, integer between 1 and 100
  9409.         * @access public
  9410.         * @since 3.0.000 (2008-03-27)
  9411.         */
  9412.         public function setJPEGQuality($quality{
  9413.             if (($quality 1OR ($quality 100)) {
  9414.                 $quality 75;
  9415.             }
  9416.             $this->jpeg_quality intval($quality);
  9417.         }
  9418.         
  9419.         /*
  9420.         * Set the default number of columns in a row for HTML tables.
  9421.         * @param int $cols number of columns
  9422.         * @access public
  9423.         * @since 3.0.014 (2008-06-04)
  9424.         */
  9425.         public function setDefaultTableColumns($cols=4
  9426.             $this->default_table_columns intval($cols)
  9427.         }
  9428.         
  9429.         /*
  9430.         * Set the height of cell repect font height.
  9431.         * @param int $h cell proportion respect font height (typical value = 1.25).
  9432.         * @access public
  9433.         * @since 3.0.014 (2008-06-04)
  9434.         */
  9435.         public function setCellHeightRatio($h
  9436.             $this->cell_height_ratio $h
  9437.         }
  9438.         
  9439.         /*
  9440.         * return the height of cell repect font height.
  9441.         * @access public
  9442.         * @since 4.0.012 (2008-07-24)
  9443.         */
  9444.         public function getCellHeightRatio(
  9445.             return $this->cell_height_ratio
  9446.         }
  9447.         
  9448.         /*
  9449.         * Set the PDF version (check PDF reference for valid values).
  9450.         * Default value is 1.t
  9451.         * @access public
  9452.         * @since 3.1.000 (2008-06-09)
  9453.         */
  9454.         public function setPDFVersion($version='1.7'
  9455.             $this->PDFVersion $version;
  9456.         }
  9457.         
  9458.         /*
  9459.         * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  9460.         * (see Section 8.1 of PDF reference, "Viewer Preferences").
  9461.         * <ul>
  9462.         * <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>
  9463.         * <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>
  9464.         * <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>
  9465.         * <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>
  9466.         * <li>CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.</li>
  9467.         * <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>
  9468.         * <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>
  9469.         * <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>
  9470.         * <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>
  9471.         * <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>
  9472.         * <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>
  9473.         * <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>
  9474.         * <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>
  9475.         * <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>
  9476.         * <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>
  9477.         * <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>
  9478.         * </ul>
  9479.         * @param array $preferences array of options.
  9480.         * @author Nicola Asuni
  9481.         * @access public
  9482.         * @since 3.1.000 (2008-06-09)
  9483.         */
  9484.         public function setViewerPreferences($preferences
  9485.             $this->viewer_preferences $preferences;
  9486.         }
  9487.         
  9488.         /**
  9489.         * Paints a linear colour gradient.
  9490.         * @param float $x abscissa of the top left corner of the rectangle.
  9491.         * @param float $y ordinate of the top left corner of the rectangle.
  9492.         * @param float $w width of the rectangle.
  9493.         * @param float $h height of the rectangle.
  9494.         * @param array $col1 first color (RGB components).
  9495.         * @param array $col2 second color (RGB components).
  9496.         * @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).
  9497.         * @author Andreas Würmser, Nicola Asuni
  9498.         * @since 3.1.000 (2008-06-09)
  9499.         * @access public
  9500.         */
  9501.         public function LinearGradient($x$y$w$h$col1=array()$col2=array()$coords=array(0,0,1,0)) {
  9502.             $this->Clip($x$y$w$h);
  9503.             $this->Gradient(2$col1$col2$coords);
  9504.         }
  9505.         
  9506.         /**
  9507.         * Paints a radial colour gradient.
  9508.         * @param float $x abscissa of the top left corner of the rectangle.
  9509.         * @param float $y ordinate of the top left corner of the rectangle.
  9510.         * @param float $w width of the rectangle.
  9511.         * @param float $h height of the rectangle.
  9512.         * @param array $col1 first color (RGB components).
  9513.         * @param array $col2 second color (RGB components).
  9514.         * @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.
  9515.         * @author Andreas Würmser, Nicola Asuni
  9516.         * @since 3.1.000 (2008-06-09)
  9517.         * @access public
  9518.         */
  9519.         public function RadialGradient($x$y$w$h$col1=array()$col2=array()$coords=array(0.5,0.5,0.5,0.5,1)) {
  9520.             $this->Clip($x$y$w$h);
  9521.             $this->Gradient(3$col1$col2$coords);
  9522.         }
  9523.         
  9524.         /**
  9525.         * Paints a coons patch mesh.
  9526.         * @param float $x abscissa of the top left corner of the rectangle.
  9527.         * @param float $y ordinate of the top left corner of the rectangle.
  9528.         * @param float $w width of the rectangle.
  9529.         * @param float $h height of the rectangle.
  9530.         * @param array $col1 first color (lower left corner) (RGB components).
  9531.         * @param array $col2 second color (lower right corner) (RGB components).
  9532.         * @param array $col3 third color (upper right corner) (RGB components).
  9533.         * @param array $col4 fourth color (upper left corner) (RGB components).
  9534.         * @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>
  9535.         * @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
  9536.         * @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
  9537.         * @author Andreas Würmser, Nicola Asuni
  9538.         * @since 3.1.000 (2008-06-09)
  9539.         * @access public
  9540.         */
  9541.         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{
  9542.             $this->Clip($x$y$w$h);        
  9543.             $n count($this->gradients1;
  9544.             $this->gradients[$n]['type'6//coons patch mesh
  9545.             //check the coords array if it is the simple array or the multi patch array
  9546.             if (!isset($coords[0]['f'])) {
  9547.                 //simple array -> convert to multi patch array
  9548.                 if (!isset($col1[1])) {
  9549.                     $col1[1$col1[2$col1[0];
  9550.                 }
  9551.                 if (!isset($col2[1])) {
  9552.                     $col2[1$col2[2$col2[0];
  9553.                 }
  9554.                 if (!isset($col3[1])) {
  9555.                     $col3[1$col3[2$col3[0];
  9556.                 }
  9557.                 if (!isset($col4[1])) {
  9558.                     $col4[1$col4[2$col4[0];
  9559.                 }
  9560.                 $patch_array[0]['f'0;
  9561.                 $patch_array[0]['points'$coords;
  9562.                 $patch_array[0]['colors'][0]['r'$col1[0];
  9563.                 $patch_array[0]['colors'][0]['g'$col1[1];
  9564.                 $patch_array[0]['colors'][0]['b'$col1[2];
  9565.                 $patch_array[0]['colors'][1]['r'$col2[0];
  9566.                 $patch_array[0]['colors'][1]['g'$col2[1];
  9567.                 $patch_array[0]['colors'][1]['b'$col2[2];
  9568.                 $patch_array[0]['colors'][2]['r'$col3[0];
  9569.                 $patch_array[0]['colors'][2]['g'$col3[1];
  9570.                 $patch_array[0]['colors'][2]['b'$col3[2];
  9571.                 $patch_array[0]['colors'][3]['r'$col4[0];
  9572.                 $patch_array[0]['colors'][3]['g'$col4[1];
  9573.                 $patch_array[0]['colors'][3]['b'$col4[2];
  9574.             else {
  9575.                 //multi patch array
  9576.                 $patch_array $coords;
  9577.             }
  9578.             $bpcd 65535//16 BitsPerCoordinate
  9579.             //build the data stream
  9580.             $this->gradients[$n]['stream''';
  9581.             $count_patch count($patch_array);
  9582.             for($i=0$i $count_patch++$i{
  9583.                 $this->gradients[$n]['stream'.= chr($patch_array[$i]['f'])//start with the edge flag as 8 bit
  9584.                 $count_points count($patch_array[$i]['points']);
  9585.                 for($j=0$j $count_points++$j{
  9586.                     //each point as 16 bit
  9587.                     $patch_array[$i]['points'][$j(($patch_array[$i]['points'][$j$coords_min($coords_max $coords_min)) $bpcd;
  9588.                     if ($patch_array[$i]['points'][$j0{
  9589.                         $patch_array[$i]['points'][$j0;
  9590.                     }
  9591.                     if ($patch_array[$i]['points'][$j$bpcd{
  9592.                         $patch_array[$i]['points'][$j$bpcd;
  9593.                     }
  9594.                     $this->gradients[$n]['stream'.= chr(floor($patch_array[$i]['points'][$j256));
  9595.                     $this->gradients[$n]['stream'.= chr(floor($patch_array[$i]['points'][$j256));
  9596.                 }
  9597.                 $count_cols count($patch_array[$i]['colors']);
  9598.                 for($j=0$j $count_cols++$j{
  9599.                     //each color component as 8 bit
  9600.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['r']);
  9601.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['g']);
  9602.                     $this->gradients[$n]['stream'.= chr($patch_array[$i]['colors'][$j]['b']);
  9603.                 }
  9604.             }
  9605.             //paint the gradient
  9606.             $this->_out('/Sh'.$n.' sh');
  9607.             //restore previous Graphic State
  9608.             $this->_out('Q');
  9609.         }
  9610.         
  9611.         /**
  9612.         * Set a rectangular clipping area.
  9613.         * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  9614.         * @param float $y ordinate of the top left corner of the rectangle.
  9615.         * @param float $w width of the rectangle.
  9616.         * @param float $h height of the rectangle.
  9617.         * @author Andreas Würmser, Nicola Asuni
  9618.         * @since 3.1.000 (2008-06-09)
  9619.         * @access protected
  9620.         */
  9621.         protected function Clip($x$y$w$h{
  9622.             if ($this->rtl{
  9623.                 $x $this->w $x $w;
  9624.             }
  9625.             //save current Graphic State
  9626.             $s 'q';
  9627.             //set clipping area
  9628.             $s .= sprintf(' %.2F %.2F %.2F %.2F re W n'$x*$this->k($this->h-$y)*$this->k$w*$this->k-$h*$this->k);
  9629.             //set up transformation matrix for gradient
  9630.             $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm'$w*$this->k$h*$this->k$x*$this->k($this->h-($y+$h))*$this->k);
  9631.             $this->_out($s);
  9632.         }
  9633.                 
  9634.         /**
  9635.         * Output gradient.
  9636.         * @param int $type type of gradient.
  9637.         * @param array $col1 first color (RGB components).
  9638.         * @param array $col2 second color (RGB components).
  9639.         * @param array $coords array of coordinates.
  9640.         * @author Andreas Würmser, Nicola Asuni
  9641.         * @since 3.1.000 (2008-06-09)
  9642.         * @access protected
  9643.         */
  9644.         protected function Gradient($type$col1$col2$coords{
  9645.             $n count($this->gradients1;
  9646.             $this->gradients[$n]['type'$type;
  9647.             if (!isset($col1[1])) {
  9648.                 $col1[1]=$col1[2]=$col1[0];
  9649.             }
  9650.             $this->gradients[$n]['col1'sprintf('%.3F %.3F %.3F'($col1[0]/255)($col1[1]/255)($col1[2]/255));
  9651.             if (!isset($col2[1])) {
  9652.                 $col2[1$col2[2$col2[0];
  9653.             }
  9654.             $this->gradients[$n]['col2'sprintf('%.3F %.3F %.3F'($col2[0]/255)($col2[1]/255)($col2[2]/255));
  9655.             $this->gradients[$n]['coords'$coords;
  9656.             //paint the gradient
  9657.             $this->_out('/Sh'.$n.' sh');
  9658.             //restore previous Graphic State
  9659.             $this->_out('Q');
  9660.         }
  9661.         
  9662.         /**
  9663.         * Output shaders.
  9664.         * @author Andreas Würmser, Nicola Asuni
  9665.         * @since 3.1.000 (2008-06-09)
  9666.         * @access protected
  9667.         */
  9668.         function _putshaders({
  9669.             foreach ($this->gradients as $id => $grad{  
  9670.                 if (($grad['type'== 2OR ($grad['type'== 3)) {
  9671.                     $this->_newobj();
  9672.                     $this->_out('<<');
  9673.                     $this->_out('/FunctionType 2');
  9674.                     $this->_out('/Domain [0.0 1.0]');
  9675.                     $this->_out('/C0 ['.$grad['col1'].']');
  9676.                     $this->_out('/C1 ['.$grad['col2'].']');
  9677.                     $this->_out('/N 1');
  9678.                     $this->_out('>>');
  9679.                     $this->_out('endobj');
  9680.                     $f1 $this->n;
  9681.                 }
  9682.                 $this->_newobj();
  9683.                 $this->_out('<<');
  9684.                 $this->_out('/ShadingType '.$grad['type']);
  9685.                 $this->_out('/ColorSpace /DeviceRGB');
  9686.                 if ($grad['type'== 2{
  9687.                     $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]'$grad['coords'][0]$grad['coords'][1]$grad['coords'][2]$grad['coords'][3]));
  9688.                     $this->_out('/Function '.$f1.' 0 R');
  9689.                     $this->_out('/Extend [true true] ');
  9690.                     $this->_out('>>');
  9691.                 elseif ($grad['type'== 3{
  9692.                     //x0, y0, r0, x1, y1, r1
  9693.                     //at this this time radius of inner circle is 0
  9694.                     $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]));
  9695.                     $this->_out('/Function '.$f1.' 0 R');
  9696.                     $this->_out('/Extend [true true] ');
  9697.                     $this->_out('>>');
  9698.                 elseif ($grad['type'== 6{
  9699.                     $this->_out('/BitsPerCoordinate 16');
  9700.                     $this->_out('/BitsPerComponent 8');
  9701.                     $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]');
  9702.                     $this->_out('/BitsPerFlag 8');
  9703.                     $this->_out('/Length '.strlen($grad['stream']));
  9704.                     $this->_out('>>');
  9705.                     $this->_putstream($grad['stream']);
  9706.                 }
  9707.                 $this->_out('endobj');
  9708.                 $this->gradients[$id]['id'$this->n;
  9709.             }
  9710.         }
  9711.  
  9712.         /**
  9713.         * Output an arc
  9714.         * @author Maxime Delorme, Nicola Asuni
  9715.         * @since 3.1.000 (2008-06-09)
  9716.         * @access protected
  9717.         */
  9718.         protected function _outarc($x1$y1$x2$y2$x3$y3 {
  9719.             $h $this->h;
  9720.             $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));
  9721.         }
  9722.         
  9723.         /**
  9724.         * Draw the sector of a circle.
  9725.         * It can be used for instance to render pie charts.
  9726.         * @param float $xc abscissa of the center.
  9727.         * @param float $yc ordinate of the center.
  9728.         * @param float $r radius.
  9729.         * @param float $a start angle (in degrees).
  9730.         * @param float $b end angle (in degrees).
  9731.         * @param string $style: D, F, FD or DF (draw, fill, fill and draw). Default: FD.
  9732.         * @param float $cw: indicates whether to go clockwise (default: true).
  9733.         * @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.
  9734.         * @author Maxime Delorme, Nicola Asuni
  9735.         * @since 3.1.000 (2008-06-09)
  9736.         * @access public
  9737.         */
  9738.         public function PieSector($xc$yc$r$a$b$style='FD'$cw=true$o=90{
  9739.             if ($this->rtl{
  9740.                 $xc $this->w $xc;
  9741.             }
  9742.             if ($cw{
  9743.                 $d $b;
  9744.                 $b $o $a;
  9745.                 $a $o $d;
  9746.             else {
  9747.                 $b += $o;
  9748.                 $a += $o;
  9749.             }
  9750.             $a ($a 360360;
  9751.             $b ($b 360360;
  9752.             if ($a $b{
  9753.                 $b +=360;
  9754.             }
  9755.             $b $b 360 M_PI;
  9756.             $a $a 360 M_PI;
  9757.             $d $b $a;
  9758.             if ($d == {
  9759.                 $d M_PI;
  9760.             }
  9761.             $k $this->k;
  9762.             $hp $this->h;
  9763.             if ($style=='F'{
  9764.                 $op 'f';
  9765.             elseif ($style=='FD' or $style=='DF'{
  9766.                 $op 'b';
  9767.             else {
  9768.                 $op 's';
  9769.             }
  9770.             if (sin($d/2)) {
  9771.                 $MyArc 4/(cos($d/2)) sin($d/2$r;
  9772.             }
  9773.             //first put the center
  9774.             $this->_out(sprintf('%.2F %.2F m'($xc)*$k($hp-$yc)*$k));
  9775.             //put the first point
  9776.             $this->_out(sprintf('%.2F %.2F l'($xc+$r*cos($a))*$k(($hp-($yc-$r*sin($a)))*$k)));
  9777.             //draw the arc
  9778.             if ($d (M_PI/2)) {
  9779.                 $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));
  9780.             else {
  9781.                 $b $a $d/4;
  9782.                 $MyArc 4/3*(1-cos($d/8))/sin($d/8)*$r;
  9783.                 $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));
  9784.                 $a $b;
  9785.                 $b $a $d/4;
  9786.                 $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));
  9787.                 $a $b;
  9788.                 $b $a $d/4;
  9789.                 $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) );
  9790.                 $a $b;
  9791.                 $b $a $d/4;
  9792.                 $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));
  9793.             }
  9794.             //terminate drawing
  9795.             $this->_out($op);
  9796.         }
  9797.         
  9798.         /**
  9799.         * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  9800.         * Only vector drawing is supported, not text or bitmap.
  9801.         * 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).
  9802.         * @param string $file Name of the file containing the image.
  9803.         * @param float $x Abscissa of the upper-left corner.
  9804.         * @param float $y Ordinate of the upper-left corner.
  9805.         * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9806.         * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9807.         * @param mixed $link URL or identifier returned by AddLink().
  9808.         * @param boolean useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  9809.         * @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>
  9810.         * @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>
  9811.         * @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>
  9812.         * @author Valentin Schmidt, Nicola Asuni
  9813.         * @since 3.1.000 (2008-06-09)
  9814.         * @access public
  9815.         */
  9816.         public function ImageEps($file$x=''$y=''$w=0$h=0$link=''$useBoundingBox=true$align=''$palign=''$border=0{
  9817.             if ($x === ''{
  9818.                 $x $this->x;
  9819.             }
  9820.             if ($y === ''{
  9821.                 $y $this->y;
  9822.             }
  9823.             $k $this->k;
  9824.             $data file_get_contents($file);
  9825.             if ($data === false{
  9826.                 $this->Error('EPS file not found: '.$file);
  9827.             }
  9828.             $regs array();
  9829.             // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  9830.             preg_match("/%%Creator:([^\r\n]+)/"$data$regs)# find Creator
  9831.             if (count($regs1{
  9832.                 $version_str trim($regs[1])# e.g. "Adobe Illustrator(R) 8.0"
  9833.                 if (strpos($version_str'Adobe Illustrator'!== false{
  9834.                     $versexp explode(' '$version_str);
  9835.                     $version = (float)array_pop($versexp);
  9836.                     if ($version >= 9{
  9837.                         $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  9838.                     }
  9839.                 }
  9840.             }
  9841.             // strip binary bytes in front of PS-header
  9842.             $start strpos($data'%!PS-Adobe');
  9843.             if ($start 0{
  9844.                 $data substr($data$start);
  9845.             }
  9846.             // find BoundingBox params
  9847.             preg_match("/%%BoundingBox:([^\r\n]+)/"$data$regs);
  9848.             if (count($regs1{
  9849.                 list($x1$y1$x2$y2explode(' 'trim($regs[1]));
  9850.             else {
  9851.                 $this->Error('No BoundingBox found in EPS file: '.$file);
  9852.             }
  9853.             $start strpos($data'%%EndSetup');
  9854.             if ($start === false{
  9855.                 $start strpos($data'%%EndProlog');
  9856.             }
  9857.             if ($start === false{
  9858.                 $start strpos($data'%%BoundingBox');
  9859.             }
  9860.             $data substr($data$start);
  9861.             $end strpos($data'%%PageTrailer');
  9862.             if ($end===false{
  9863.                 $end strpos($data'showpage');
  9864.             }
  9865.             if ($end{
  9866.                 $data substr($data0$end);
  9867.             }
  9868.             if ($w 0{
  9869.                 $scale_x $w (($x2 $x1$k);
  9870.                 if ($h 0{
  9871.                     $scale_y $h (($y2 $y1$k);
  9872.                 else {
  9873.                     $scale_y $scale_x;
  9874.                     $h ($y2 $y1$k $scale_y;
  9875.                 }
  9876.             else {
  9877.                 if ($h 0{
  9878.                     $scale_y $h (($y2 $y1$k);
  9879.                     $scale_x $scale_y;
  9880.                     $w ($x2-$x1$k $scale_x;
  9881.                 else {
  9882.                     $w ($x2 $x1$k;
  9883.                     $h ($y2 $y1$k;
  9884.                 }
  9885.             }
  9886.             // Check whether we need a new page first as this does not fit
  9887.             if ((($y $h$this->PageBreakTriggerAND (!$this->InFooterAND $this->AcceptPageBreak()) {
  9888.                 // Automatic page break
  9889.                 $this->AddPage($this->CurOrientation);
  9890.                 // Reset Y coordinate to the top of next page
  9891.                 $y $this->GetY($this->cMargin;
  9892.             }
  9893.             // set bottomcoordinates
  9894.             $this->img_rb_y $y $h;
  9895.             // set alignment
  9896.             if ($this->rtl{
  9897.                 if ($palign == 'L'{
  9898.                     $ximg $this->lMargin;
  9899.                     // set right side coordinate
  9900.                     $this->img_rb_x $ximg $w;
  9901.                 elseif ($palign == 'C'{
  9902.                     $ximg ($this->w $x $w2;
  9903.                     // set right side coordinate
  9904.                     $this->img_rb_x $ximg $w;
  9905.                 else {
  9906.                     $ximg $this->w $x $w;
  9907.                     // set left side coordinate
  9908.                     $this->img_rb_x $ximg;
  9909.                 }
  9910.             else {
  9911.                 if ($palign == 'R'{
  9912.                     $ximg $this->w $this->rMargin $w;
  9913.                     // set left side coordinate
  9914.                     $this->img_rb_x $ximg;
  9915.                 elseif ($palign == 'C'{
  9916.                     $ximg ($this->w $x $w2;
  9917.                     // set right side coordinate
  9918.                     $this->img_rb_x $ximg $w;
  9919.                 else {
  9920.                     $ximg $x;
  9921.                     // set right side coordinate
  9922.                     $this->img_rb_x $ximg $w;
  9923.                 }
  9924.             }
  9925.             if ($useBoundingBox{
  9926.                 $dx $ximg $k $x1;
  9927.                 $dy $y $k $y1;
  9928.             else {
  9929.                 $dx $ximg $k;
  9930.                 $dy $y $k;
  9931.             }
  9932.             // save the current graphic state
  9933.             $this->_out('q'.$this->epsmarker);
  9934.             // translate
  9935.             $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'1001$dx$dy ($this->hPt ($y $k($y2 $y1))));
  9936.             // scale
  9937.             if (isset($scale_x)) {
  9938.                 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm'$scale_x00$scale_y$x1 ($scale_x)$y2 ($scale_y)));
  9939.             }
  9940.             // handle pc/unix/mac line endings
  9941.             preg_match('/[\r\n]+/s'$data$regs);
  9942.             $lines explode($regs[0]$data);
  9943.             $u=0;
  9944.             $cnt count($lines);
  9945.             for ($i=0$i $cnt++$i{
  9946.                 $line $lines[$i];
  9947.                 if (($line == ''OR ($line{0== '%')) {
  9948.                     continue;
  9949.                 }
  9950.                 $len strlen($line);
  9951.                 $chunks explode(' '$line);
  9952.                 $cmd array_pop($chunks);
  9953.                 // RGB
  9954.                 if (($cmd == 'Xa'OR ($cmd == 'XA')) {
  9955.                     $b array_pop($chunks)
  9956.                     $g array_pop($chunks)
  9957.                     $r array_pop($chunks);
  9958.                     $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!
  9959.                     continue;
  9960.                 }
  9961.                 switch ($cmd{
  9962.                     case 'm':
  9963.                     case 'l':
  9964.                     case 'v':
  9965.                     case 'y':
  9966.                     case 'c':
  9967.                     case 'k':
  9968.                     case 'K':
  9969.                     case 'g':
  9970.                     case 'G':
  9971.                     case 's':
  9972.                     case 'S':
  9973.                     case 'J':
  9974.                     case 'j':
  9975.                     case 'w':
  9976.                     case 'M':
  9977.                     case 'd':
  9978.                     case 'n':
  9979.                     case 'v'{
  9980.                         $this->_out($line);
  9981.                         break;
  9982.                     }
  9983.                     case 'x'{// custom fill color
  9984.                         list($c,$m,$y,$k$chunks;
  9985.                         $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' k');
  9986.                         break;
  9987.                     }
  9988.                     case 'X'// custom stroke color
  9989.                         list($c,$m,$y,$k$chunks;
  9990.                         $this->_out(''.$c.' '.$m.' '.$y.' '.$k.' K');
  9991.                         break;
  9992.                     }
  9993.                     case 'Y':
  9994.                     case 'N':
  9995.                     case 'V':
  9996.                     case 'L':
  9997.                     case 'C'{
  9998.                         $line{$len-1strtolower($cmd);
  9999.                         $this->_out($line);
  10000.                         break;
  10001.                     }
  10002.                     case 'b':
  10003.                     case 'B'{
  10004.                         $this->_out($cmd '*');
  10005.                         break;
  10006.                     }
  10007.                     case 'f':
  10008.                     case 'F'{
  10009.                         if ($u 0{
  10010.                             $isU false;
  10011.                             $max min($i+5$cnt);
  10012.                             for ($j=$i+1$j $max++$j)
  10013.                               $isU ($isU OR (($lines[$j== 'U'OR ($lines[$j== '*U')));
  10014.                             if ($isU{
  10015.                                 $this->_out('f*');
  10016.                             }
  10017.                         else {
  10018.                             $this->_out('f*');
  10019.                         }
  10020.                         break;
  10021.                     }
  10022.                     case '*u'{
  10023.                         ++$u;
  10024.                         break;
  10025.                     }
  10026.                     case '*U'{
  10027.                         --$u;
  10028.                         break;
  10029.                     }
  10030.                 }
  10031.             }
  10032.             // restore previous graphic state
  10033.             $this->_out($this->epsmarker.'Q');
  10034.             if (!empty($border)) {
  10035.                 $bx $x;
  10036.                 $by $y;
  10037.                 $this->x $x;
  10038.                 $this->y $y;
  10039.                 $this->Cell($w$h''$border0''0''0);
  10040.                 $this->x $bx;
  10041.                 $this->y $by;
  10042.             }
  10043.             if ($link{
  10044.                 $this->Link($ximg$y$w$h$link0);
  10045.             }
  10046.             // set pointer to align the successive text/objects
  10047.             switch($align{
  10048.                 case 'T':{
  10049.                     $this->y $y;
  10050.                     $this->x $this->img_rb_x;
  10051.                     break;
  10052.                 }
  10053.                 case 'M':{
  10054.                     $this->y $y round($h/2);
  10055.                     $this->x $this->img_rb_x;
  10056.                     break;
  10057.                 }
  10058.                 case 'B':{
  10059.                     $this->y $this->img_rb_y;
  10060.                     $this->x $this->img_rb_x;
  10061.                     break;
  10062.                 }
  10063.                 case 'N':{
  10064.                     $this->SetY($this->img_rb_y);
  10065.                     break;
  10066.                 }
  10067.                 default:{
  10068.                     break;
  10069.                 }
  10070.             }
  10071.             $this->endlinex $this->img_rb_x;
  10072.         }
  10073.         
  10074.         /**
  10075.           * Set document barcode.
  10076.          * @param string $bc barcode
  10077.          * @access public
  10078.          */
  10079.         public function setBarcode($bc=''{
  10080.             $this->barcode $bc;
  10081.         }
  10082.         
  10083.         /**
  10084.           * Get current barcode.
  10085.          * @return string 
  10086.          * @access public
  10087.          * @since 4.0.012 (2008-07-24)
  10088.          */
  10089.         public function getBarcode({
  10090.             return $this->barcode;
  10091.         }
  10092.         
  10093.         /**
  10094.           * Print a Linear Barcode.
  10095.           * @param string $code code to print
  10096.           * @param string $type type of barcode.
  10097.          * @param int $x x position in user units
  10098.          * @param int $y y position in user units
  10099.          * @param int $w width in user units
  10100.          * @param int $h height in user units
  10101.          * @param float $xres width of the smallest bar in user units
  10102.          * @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>
  10103.          * @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>
  10104.          * @author Nicola Asuni
  10105.          * @since 3.1.000 (2008-06-09)
  10106.          * @access public
  10107.          */
  10108.         public function write1DBarcode($code$type$x=''$y=''$w=''$h=''$xres=0.4$style=''$align=''{
  10109.             if ($this->empty_string($code)) {
  10110.                 return;
  10111.             }
  10112.             require_once(dirname(__FILE__).'/barcodes.php');
  10113.             // save current graphic settings
  10114.             $gvars $this->getGraphicVars();
  10115.             // create new barcode object
  10116.             $barcodeobj new TCPDFBarcode($code$type);
  10117.             $arrcode $barcodeobj->getBarcodeArray();
  10118.             if ($arrcode === false{
  10119.                 $this->Error('Error in 1D barcode string');
  10120.             }
  10121.             // set default values
  10122.             if (!isset($style['position'])) {
  10123.                 if ($this->rtl{
  10124.                     $style['position''R';
  10125.                 else {
  10126.                     $style['position''L';
  10127.                 }
  10128.             }
  10129.             if (!isset($style['padding'])) {
  10130.                 $style['padding'0;
  10131.             }
  10132.             if (!isset($style['fgcolor'])) {
  10133.                 $style['fgcolor'array(0,0,0)// default black
  10134.             }
  10135.             if (!isset($style['bgcolor'])) {
  10136.                 $style['bgcolor'false// default transparent
  10137.             }
  10138.             if (!isset($style['border'])) {
  10139.                 $style['border'false;
  10140.             }
  10141.             if (!isset($style['text'])) {
  10142.                 $style['text'false;
  10143.                 $fontsize 0;
  10144.             }
  10145.             if ($style['text'AND isset($style['font'])) {
  10146.                 if (isset($style['fontsize'])) {
  10147.                     $fontsize $style['fontsize'];
  10148.                 else {
  10149.                     $fontsize 0;
  10150.                 }
  10151.                 $this->SetFont($style['font']''$fontsize);
  10152.             }
  10153.             if (!isset($style['stretchtext'])) {
  10154.                 $style['stretchtext'4;
  10155.             }
  10156.             // set foreground color
  10157.             $this->SetDrawColorArray($style['fgcolor']);
  10158.             $this->SetTextColorArray($style['fgcolor']);
  10159.             if ($this->empty_string($wOR ($w <= 0)) {
  10160.                 if ($this->rtl{
  10161.                     $w $this->x $this->lMargin;
  10162.                 else {
  10163.                     $w $this->w $this->rMargin $this->x;
  10164.                 }
  10165.             }
  10166.             if ($this->empty_string($x)) {
  10167.                 $x $this->GetX();
  10168.             }
  10169.             if ($this->rtl{
  10170.                 $x $this->w $x;
  10171.             }
  10172.             if ($this->empty_string($y)) {
  10173.                 $y $this->GetY();
  10174.             }
  10175.             if ($this->empty_string($xres)) {
  10176.                 $xres 0.4;
  10177.             }
  10178.             $fbw ($arrcode['maxw'$xres($style['padding']);
  10179.             $extraspace ($this->cell_height_ratio $fontsize $this->k($style['padding']);
  10180.             if ($this->empty_string($hOR ($h <= 0)) {
  10181.                 $h 10 $extraspace;
  10182.             }
  10183.             if ($this->checkPageBreak($h)) {
  10184.                 $y $this->y;
  10185.             }
  10186.             // maximum bar heigth
  10187.             $barh $h $extraspace;
  10188.             switch ($style['position']{
  10189.                 case 'L'// left
  10190.                     if ($this->rtl{
  10191.                         $xpos $x $w;
  10192.                     else {
  10193.                         $xpos $x;
  10194.                     }
  10195.                     break;
  10196.                 }
  10197.                 case 'C'// center
  10198.                     $xdiff (($w $fbw2);
  10199.                     if ($this->rtl{
  10200.                         $xpos $x $w $xdiff;
  10201.                     else {
  10202.                         $xpos $x $xdiff;
  10203.                     }
  10204.                     break;
  10205.                 }
  10206.                 case 'R'// right
  10207.                     if ($this->rtl{
  10208.                         $xpos $x $fbw;
  10209.                     else {
  10210.                         $xpos $x $w $fbw;
  10211.                     }
  10212.                     break;
  10213.                 }
  10214.                 case 'S'// stretch
  10215.                     $fbw $w;
  10216.                     $xres ($w ($style['padding'])) $arrcode['maxw'];
  10217.                     if ($this->rtl{
  10218.                         $xpos $x $w;
  10219.                     else {
  10220.                         $xpos $x;
  10221.                     }
  10222.                     break;
  10223.                 }
  10224.             }
  10225.             $xpos_rect $xpos;
  10226.             $xpos $xpos_rect $style['padding'];
  10227.             $xpos_text $xpos;
  10228.             // barcode is always printed in LTR direction
  10229.             $tempRTL $this->rtl;
  10230.             $this->rtl false;
  10231.             // print background color
  10232.             if ($style['bgcolor']{
  10233.                 $this->Rect($xpos_rect$y$fbw$h'DF'''$style['bgcolor']);
  10234.             elseif ($style['border']{
  10235.                 $this->Rect($xpos_rect$y$fbw$h'D');
  10236.             }
  10237.             // print bars
  10238.             if ($arrcode !== false{
  10239.                 foreach ($arrcode['bcode'as $k => $v{
  10240.                     $bw ($v['w'$xres);
  10241.                     if ($v['t']{
  10242.                         // draw a vertical bar
  10243.                         $ypos $y $style['padding'($v['p'$barh $arrcode['maxh']);
  10244.                         $this->Rect($xpos$ypos$bw($v['h'$barh  $arrcode['maxh'])'F'array()$style['fgcolor']);
  10245.                     }
  10246.                     $xpos += $bw;
  10247.                 }
  10248.             }
  10249.             // print text
  10250.             if ($style['text']{
  10251.                 // print text
  10252.                 $this->x $xpos_text;
  10253.                 $this->y $y $style['padding'$barh
  10254.                 $this->Cell(($arrcode['maxw'$xres)($this->cell_height_ratio $fontsize $this->k)$code00'C'0''$style['stretchtext']);
  10255.             }
  10256.             // restore original direction
  10257.             $this->rtl $tempRTL;
  10258.             // restore previous settings
  10259.             $this->setGraphicVars($gvars);
  10260.             // set bottomcoordinates
  10261.             $this->img_rb_y $y $h;
  10262.             if ($this->rtl{
  10263.                 // set left side coordinate
  10264.                 $this->img_rb_x ($this->w $x $w);
  10265.             else {
  10266.                 // set right side coordinate
  10267.                 $this->img_rb_x $x $w;
  10268.             }
  10269.             // set pointer to align the successive text/objects
  10270.             switch($align{
  10271.                 case 'T':{
  10272.                     $this->y $y;
  10273.                     $this->x $this->img_rb_x;
  10274.                     break;
  10275.                 }
  10276.                 case 'M':{
  10277.                     $this->y $y round($h/2);
  10278.                     $this->x $this->img_rb_x;
  10279.                     break;
  10280.                 }
  10281.                 case 'B':{
  10282.                     $this->y $this->img_rb_y;
  10283.                     $this->x $this->img_rb_x;
  10284.                     break;
  10285.                 }
  10286.                 case 'N':{
  10287.                     $this->SetY($this->img_rb_y);
  10288.                     break;
  10289.                 }
  10290.                 default:{
  10291.                     break;
  10292.                 }
  10293.             }
  10294.         }
  10295.         
  10296.         /**
  10297.           * This function is DEPRECATED, please use the new write1DBarcode() function.
  10298.          * @param int $x x position in user units
  10299.          * @param int $y y position in user units
  10300.          * @param int $w width in user units
  10301.          * @param int $h height position in user units
  10302.          * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
  10303.          * @param string $style barcode style
  10304.          * @param string $font font for text
  10305.          * @param int $xres x resolution
  10306.          * @param string $code code to print
  10307.          * @deprecated deprecated since version 3.1.000 (2008-06-10)
  10308.          * @access public
  10309.          * @see write1DBarcode()
  10310.          */
  10311.         public function writeBarcode($x$y$w$h$type$style$font$xres$code{
  10312.             // convert old settings for the new write1DBarcode() function.
  10313.             $xres $xres;
  10314.             $newstyle array(
  10315.                 'position' => 'L',
  10316.                 'border' => false,
  10317.                 'padding' => 0,
  10318.                 'fgcolor' => array(0,0,0),
  10319.                 'bgcolor' => false,
  10320.                 'text' => true,
  10321.                 'font' => $font,
  10322.                 'fontsize' => 8,
  10323.                 'stretchtext' => 4
  10324.             );
  10325.             if ($style 1{
  10326.                 $newstyle['border'true;
  10327.             }
  10328.             if ($style 2{
  10329.                 $newstyle['bgcolor'false;
  10330.             }
  10331.             if ($style 4{
  10332.                 $newstyle['position''C';
  10333.             elseif ($style 8{
  10334.                 $newstyle['position''L';
  10335.             elseif ($style 16{
  10336.                 $newstyle['position''R';
  10337.             }
  10338.             if ($style 128{
  10339.                 $newstyle['text'true;
  10340.             }
  10341.             if ($style 256{
  10342.                 $newstyle['stretchtext'4;
  10343.             }
  10344.             $this->write1DBarcode($code$type$x$y$w$h$xres$newstyle'');
  10345.         }
  10346.         
  10347.         /**
  10348.           * Print 2D Barcode.
  10349.           * @param string $code code to print
  10350.           * @param string $type type of barcode.
  10351.          * @param int $x x position in user units
  10352.          * @param int $y y position in user units
  10353.          * @param int $w width in user units
  10354.          * @param int $h height in user units
  10355.          * @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>
  10356.          * @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>
  10357.          * @author Nicola Asuni
  10358.          * @since 4.5.037 (2009-04-07)
  10359.          * @access public
  10360.          */
  10361.         public function write2DBarcode($code$type$x=''$y=''$w=''$h=''$style=''$align=''{
  10362.             if ($this->empty_string($code)) {
  10363.                 return;
  10364.             }
  10365.             require_once(dirname(__FILE__).'/2dbarcodes.php');
  10366.             // save current graphic settings
  10367.             $gvars $this->getGraphicVars();
  10368.             // create new barcode object
  10369.             $barcodeobj new TCPDF2DBarcode($code$type);
  10370.             $arrcode $barcodeobj->getBarcodeArray();
  10371.             if ($arrcode === false{
  10372.                 $this->Error('Error in 2D barcode string');
  10373.             }
  10374.             // set default values
  10375.             if (!isset($style['padding'])) {
  10376.                 $style['padding'0;
  10377.             }
  10378.             if (!isset($style['fgcolor'])) {
  10379.                 $style['fgcolor'array(0,0,0)// default black
  10380.             }
  10381.             if (!isset($style['bgcolor'])) {
  10382.                 $style['bgcolor'false// default transparent
  10383.             }
  10384.             if (!isset($style['border'])) {
  10385.                 $style['border'false;
  10386.             }
  10387.             // set foreground color
  10388.             $this->SetDrawColorArray($style['fgcolor']);
  10389.             if ($this->empty_string($x)) {
  10390.                 $x $this->GetX();
  10391.             }
  10392.             if ($this->rtl{
  10393.                 $x $this->w $x;
  10394.             }
  10395.             if ($this->empty_string($y)) {
  10396.                 $y $this->GetY();
  10397.             }
  10398.             if ($this->empty_string($wOR ($w <= 0)) {
  10399.                 if ($this->rtl{
  10400.                     $w $x $this->lMargin;
  10401.                 else {
  10402.                     $w $this->w $this->rMargin $x;
  10403.                 }
  10404.             }
  10405.             if ($this->empty_string($hOR ($h <= 0)) {
  10406.                 // 2d barcodes are square by default
  10407.                 $h $w;
  10408.             }
  10409.             if ($this->checkPageBreak($h)) {
  10410.                 $y $this->y;
  10411.             }
  10412.             // calculate barcode size (excluding padding)
  10413.             $bw $w ($style['padding']);
  10414.             $bh $h ($style['padding']);
  10415.             // calculate starting coordinates
  10416.             if ($this->rtl{
  10417.                 $xpos $x $w;
  10418.             else {
  10419.                 $xpos $x;
  10420.             }
  10421.             $xpos += $style['padding'];
  10422.             $ypos $y $style['padding'];
  10423.             // barcode is always printed in LTR direction
  10424.             $tempRTL $this->rtl;
  10425.             $this->rtl false;
  10426.             // print background color
  10427.             if ($style['bgcolor']{
  10428.                 $this->Rect($x$y$w$h'DF'''$style['bgcolor']);
  10429.             elseif ($style['border']{
  10430.                 $this->Rect($x$y$w$h'D');
  10431.             }
  10432.             // print barcode cells
  10433.             if ($arrcode !== false{
  10434.                 $rows $arrcode['num_rows'];
  10435.                 $cols $arrcode['num_cols'];
  10436.                 // calculate dimension of single barcode cell
  10437.                 $cw $bw $cols;
  10438.                 $ch $bh $rows;
  10439.                 // for each row
  10440.                 for ($r 0$r $rows++$r{
  10441.                     $xr $xpos;
  10442.                     // for each column
  10443.                     for ($c 0$c $cols++$c{
  10444.                         if ($arrcode['bcode'][$r][$c== 1{
  10445.                             // draw a single barcode cell
  10446.                             $this->Rect($xr$ypos$cw$ch'F'array()$style['fgcolor']);
  10447.                         }
  10448.                         $xr += $cw;
  10449.                     }
  10450.                     $ypos += $ch;
  10451.                 }
  10452.             }
  10453.             // restore original direction
  10454.             $this->rtl $tempRTL;
  10455.             // restore previous settings
  10456.             $this->setGraphicVars($gvars);
  10457.             // set bottomcoordinates
  10458.             $this->img_rb_y $y $h;
  10459.             if ($this->rtl{
  10460.                 // set left side coordinate
  10461.                 $this->img_rb_x ($this->w $x $w);
  10462.             else {
  10463.                 // set right side coordinate
  10464.                 $this->img_rb_x $x $w;
  10465.             }
  10466.             // set pointer to align the successive text/objects
  10467.             switch($align{
  10468.                 case 'T':{
  10469.                     $this->y $y;
  10470.                     $this->x $this->img_rb_x;
  10471.                     break;
  10472.                 }
  10473.                 case 'M':{
  10474.                     $this->y $y round($h/2);
  10475.                     $this->x $this->img_rb_x;
  10476.                     break;
  10477.                 }
  10478.                 case 'B':{
  10479.                     $this->y $this->img_rb_y;
  10480.                     $this->x $this->img_rb_x;
  10481.                     break;
  10482.                 }
  10483.                 case 'N':{
  10484.                     $this->SetY($this->img_rb_y);
  10485.                     break;
  10486.                 }
  10487.                 default:{
  10488.                     break;
  10489.                 }
  10490.             }
  10491.         }
  10492.         
  10493.         /**
  10494.          * Returns an array containing current margins:
  10495.          * <ul>
  10496.                 <li>$ret['left'] = left  margin</li>
  10497.                 <li>$ret['right'] = right margin</li>
  10498.                 <li>$ret['top'] = top margin</li>
  10499.                 <li>$ret['bottom'] = bottom margin</li>
  10500.                 <li>$ret['header'] = header margin</li>
  10501.                 <li>$ret['footer'] = footer margin</li>
  10502.                 <li>$ret['cell'] = cell margin</li>
  10503.          * </ul>
  10504.          * @return array containing all margins measures
  10505.          * @access public
  10506.          * @since 3.2.000 (2008-06-23)
  10507.          */
  10508.         public function getMargins({
  10509.             $ret array(
  10510.                 'left' => $this->lMargin,
  10511.                 'right' => $this->rMargin,
  10512.                 'top' => $this->tMargin,
  10513.                 'bottom' => $this->bMargin,
  10514.                 'header' => $this->header_margin,
  10515.                 'footer' => $this->footer_margin,
  10516.                 'cell' => $this->cMargin,
  10517.             );
  10518.             return $ret;
  10519.         }
  10520.         
  10521.         /**
  10522.          * Returns an array containing original margins:
  10523.          * <ul>
  10524.                 <li>$ret['left'] = left  margin</li>
  10525.                 <li>$ret['right'] = right margin</li>
  10526.          * </ul>
  10527.          * @return array containing all margins measures
  10528.          * @access public
  10529.          * @since 4.0.012 (2008-07-24)
  10530.          */
  10531.         public function getOriginalMargins({
  10532.             $ret array(
  10533.                 'left' => $this->original_lMargin,
  10534.                 'right' => $this->original_rMargin
  10535.             );
  10536.             return $ret;
  10537.         }
  10538.         
  10539.         /**
  10540.          * Returns the current font size.
  10541.          * @return current font size
  10542.          * @access public
  10543.          * @since 3.2.000 (2008-06-23)
  10544.          */
  10545.         public function getFontSize({
  10546.             return $this->FontSize;
  10547.         }
  10548.         
  10549.         /**
  10550.          * Returns the current font size in points unit.
  10551.          * @return current font size in points unit
  10552.          * @access public
  10553.          * @since 3.2.000 (2008-06-23)
  10554.          */
  10555.         public function getFontSizePt({
  10556.             return $this->FontSizePt;
  10557.         }
  10558.  
  10559.         /**
  10560.          * Returns the current font family name.
  10561.          * @return string current font family name
  10562.          * @access public
  10563.          * @since 4.3.008 (2008-12-05)
  10564.          */
  10565.         public function getFontFamily({
  10566.             return $this->FontFamily;
  10567.         }
  10568.  
  10569.         /**
  10570.          * Returns the current font style.
  10571.          * @return string current font style
  10572.          * @access public
  10573.          * @since 4.3.008 (2008-12-05)
  10574.          */
  10575.         public function getFontStyle({
  10576.             return $this->FontStyle;
  10577.         }
  10578.         
  10579.         /**
  10580.          * Prints a cell (rectangular area) with optional borders, background color and html text string.
  10581.          * 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 />
  10582.          * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  10583.          * @param float $w Cell width. If 0, the cell extends up to the right margin.
  10584.          * @param float $h Cell minimum height. The cell extends automatically if needed.
  10585.          * @param float $x upper-left corner X coordinate
  10586.          * @param float $y upper-left corner Y coordinate
  10587.          * @param string $html html text to print. Default value: empty string.
  10588.          * @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>
  10589.          * @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>
  10590.     Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  10591.          * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  10592.          * @param boolean $reseth if true reset the last cell height (default true).
  10593.          * @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>
  10594.          * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  10595.          * @access public
  10596.          * @uses MultiCell()
  10597.          * @see Multicell(), writeHTML()
  10598.          */
  10599.         public function writeHTMLCell($w$h$x$y$html=''$border=0$ln=0$fill=0$reseth=true$align=''$autopadding=true{
  10600.             return $this->MultiCell($w$h$html$border$align$fill$ln$x$y$reseth0true$autopadding0);
  10601.         }
  10602.         
  10603.         /**
  10604.           * Returns the HTML DOM array.
  10605.           * <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>
  10606.          * @param string $html html code
  10607.          * @return array 
  10608.          * @access protected
  10609.          * @since 3.2.000 (2008-06-20)
  10610.          */
  10611.         protected function getHtmlDomArray($html{
  10612.             // remove all unsupported tags (the line below lists all supported tags)
  10613.             $html strip_tags($html'<marker/><a><b><blockquote><br><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>')
  10614.             //replace some blank characters
  10615.             $html preg_replace('@(\r\n|\r)@'"\n"$html);
  10616.             $repTable array("\t" => ' '"\0" => ' '"\x0B" => ' '"\\" => "\\\\");
  10617.             $html strtr($html$repTable);
  10618.             while (preg_match("'<pre([^\>]*)>(.*?)\n(.*?)</pre>'si"$html)) {
  10619.                 // preserve newlines on <pre> tag
  10620.                 $html preg_replace("'<pre([^\>]*)>(.*?)\n(.*?)</pre>'si""<pre\\1>\\2<br />\\3</pre>"$html);
  10621.             }
  10622.             $html str_replace("\n"' '$html);
  10623.             /*
  10624.             $html = preg_replace("'<div([^\>]*)>'si", "<br /><table><tr><td\\1>", $html);
  10625.             $html = preg_replace("'</div>'si", "</td></tr></table>", $html);
  10626.             $html = preg_replace("'<pre([^\>]*)>'si", "<table><tr><td\\1>", $html);
  10627.             $html = preg_replace("'</pre>'si", "</td></tr></table>", $html);
  10628.             */
  10629.             // remove extra spaces from code
  10630.             $html preg_replace('/[\s]*<\/table>[\s]*/''</table>'$html);
  10631.             $html preg_replace('/[\s]*<\/tr>[\s]*/''</tr>'$html);
  10632.             $html preg_replace('/[\s]*<tr/''<tr'$html);
  10633.             $html preg_replace('/[\s]*<\/th>[\s]*/''</th>'$html);
  10634.             $html preg_replace('/[\s]*<th/''<th'$html);
  10635.             $html preg_replace('/[\s]*<\/td>[\s]*/''</td>'$html);
  10636.             $html preg_replace('/[\s]*<td/''<td'$html);
  10637.             $html preg_replace('/<\/th>/''<marker style="font-size:0"/></th>'$html);
  10638.             $html preg_replace('/<\/td>/''<marker style="font-size:0"/></td>'$html);
  10639.             $html preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/''</table>'$html);
  10640.             $html preg_replace('/<img/'' <img'$html);
  10641.             $html preg_replace('/<img([^\>]*)>/xi''<img\\1><span></span>'$html);
  10642.             $html preg_replace('/[\s]+<ul/''<ul'$html);
  10643.             $html preg_replace('/[\s]+<ol/''<ol'$html);
  10644.             $html preg_replace('/[\s]+<li/''<li'$html);
  10645.             $html preg_replace('/[\s]*<\/li>[\s]*/''</li>'$html);
  10646.             $html preg_replace('/[\s]*<\/ul>[\s]*/''</ul>'$html);
  10647.             $html preg_replace('/[\s]*<\/ol>[\s]*/''</ol>'$html);
  10648.             $html preg_replace('/[\s]+<br/''<br'$html);
  10649.             // pattern for generic tag
  10650.             $tagpattern '/(<[^>]+>)/';
  10651.             // explodes the string
  10652.             $a preg_split($tagpattern$html-1PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_NO_EMPTY);
  10653.             // count elements
  10654.             $maxel count($a);
  10655.             $elkey 0;
  10656.             $key 0;
  10657.             // create an array of elements
  10658.             $dom array();
  10659.             $dom[$keyarray();
  10660.             // set first void element
  10661.             $dom[$key]['tag'false;
  10662.             $dom[$key]['value''';
  10663.             $dom[$key]['parent'0;
  10664.             $dom[$key]['fontname'$this->FontFamily;
  10665.             $dom[$key]['fontstyle'$this->FontStyle;
  10666.             $dom[$key]['fontsize'$this->FontSizePt;
  10667.             $dom[$key]['bgcolor'false;
  10668.             $dom[$key]['fgcolor'$this->fgcolor;
  10669.             $dom[$key]['align''';
  10670.             $dom[$key]['listtype''';
  10671.             $thead false// true when we are inside the THEAD tag
  10672.             ++$key;
  10673.             $level array();
  10674.             array_push($level0)// root
  10675.             while ($elkey $maxel{
  10676.                 $dom[$keyarray();
  10677.                 $element $a[$elkey];
  10678.                 $dom[$key]['elkey'$elkey;
  10679.                 if (preg_match($tagpattern$element)) {
  10680.                     // html tag
  10681.                     $element substr($element1-1);
  10682.                     // get tag name
  10683.                     preg_match('/[\/]?([a-zA-Z0-9]*)/'$element$tag);
  10684.                     $tagname strtolower($tag[1]);
  10685.                     // check if we are inside a table header
  10686.                     if ($tagname == 'thead'{
  10687.                         if ($element{0== '/'{
  10688.                             $thead false;
  10689.                         else {
  10690.                             $thead true;
  10691.                         }
  10692.                         ++$elkey;
  10693.                         continue;
  10694.                     }
  10695.                     $dom[$key]['tag'true;
  10696.                     $dom[$key]['value'$tagname;
  10697.                     if ($element{0== '/'{
  10698.                         // closing html tag
  10699.                         $dom[$key]['opening'false;
  10700.                         $dom[$key]['parent'end($level);
  10701.                         array_pop($level);
  10702.                         $dom[$key]['fontname'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  10703.                         $dom[$key]['fontstyle'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  10704.                         $dom[$key]['fontsize'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  10705.                         $dom[$key]['bgcolor'$dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  10706.                         $dom[$key]['fgcolor'$dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  10707.                         $dom[$key]['align'$dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  10708.                         if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  10709.                             $dom[$key]['listtype'$dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  10710.                         }
  10711.                         // set the number of columns in table tag
  10712.                         if (($dom[$key]['value'== 'tr'AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  10713.                             $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'$dom[($dom[$key]['parent'])]['cols'];
  10714.                         }
  10715.                         if (($dom[$key]['value'== 'td'OR ($dom[$key]['value'== 'th')) {
  10716.                             $dom[($dom[$key]['parent'])]['content''';
  10717.                             for ($i ($dom[$key]['parent'1)$i $key++$i{
  10718.                                 $dom[($dom[$key]['parent'])]['content'.= $a[$dom[$i]['elkey']];
  10719.                             }
  10720.                             $key $i;
  10721.                         }
  10722.                         // store header rows on a new table
  10723.                         if (($dom[$key]['value'== 'tr'AND ($dom[($dom[$key]['parent'])]['thead'== true)) {
  10724.                             if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  10725.                                 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  10726.                             }
  10727.                             for ($i $dom[$key]['parent']$i <= $key++$i{
  10728.                                 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'.= $a[$dom[$i]['elkey']];
  10729.                             }
  10730.                         }
  10731.                         if (($dom[$key]['value'== 'table'AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  10732.                             $dom[($dom[$key]['parent'])]['thead'.= '</table>';
  10733.                         }
  10734.                     else {
  10735.                         // opening html tag
  10736.                         $dom[$key]['opening'true;
  10737.                         $dom[$key]['parent'end($level);
  10738.                         if (substr($element-11!= '/'{
  10739.                             // not self-closing tag
  10740.                             array_push($level$key);
  10741.                             $dom[$key]['self'false;
  10742.                         else {
  10743.                             $dom[$key]['self'true;
  10744.                         }
  10745.                         // copy some values from parent
  10746.                         $parentkey 0;
  10747.                         if ($key 0{
  10748.                             $parentkey $dom[$key]['parent'];
  10749.                             $dom[$key]['fontname'$dom[$parentkey]['fontname'];
  10750.                             $dom[$key]['fontstyle'$dom[$parentkey]['fontstyle'];
  10751.                             $dom[$key]['fontsize'$dom[$parentkey]['fontsize'];
  10752.                             $dom[$key]['bgcolor'$dom[$parentkey]['bgcolor'];
  10753.                             $dom[$key]['fgcolor'$dom[$parentkey]['fgcolor'];
  10754.                             $dom[$key]['align'$dom[$parentkey]['align'];
  10755.                             $dom[$key]['listtype'$dom[$parentkey]['listtype'];
  10756.                         }
  10757.                         // get attributes
  10758.                         preg_match_all('/([^=\s]*)=["]?([^"]*)["]?/'$element$attr_arrayPREG_PATTERN_ORDER);
  10759.                         $dom[$key]['attribute'array()// reset attribute array
  10760.                         while (list($id$nameeach($attr_array[1])) {
  10761.                             $dom[$key]['attribute'][strtolower($name)$attr_array[2][$id];
  10762.                         }
  10763.                         // split style attributes
  10764.                         if (isset($dom[$key]['attribute']['style'])) {
  10765.                             // get style attributes
  10766.                             preg_match_all('/([^;:\s]*):([^;]*)/'$dom[$key]['attribute']['style']$style_arrayPREG_PATTERN_ORDER);
  10767.                             $dom[$key]['style'array()// reset style attribute array
  10768.                             while (list($id$nameeach($style_array[1])) {
  10769.                                 $dom[$key]['style'][strtolower($name)trim($style_array[2][$id]);
  10770.                             }
  10771.                             // --- get some style attributes ---
  10772.                             if (isset($dom[$key]['style']['font-family'])) {
  10773.                                 // font family
  10774.                                 if (isset($dom[$key]['style']['font-family'])) {
  10775.                                     $fontslist split(','strtolower($dom[$key]['style']['font-family']));
  10776.                                     foreach ($fontslist as $font{
  10777.                                         $font trim(strtolower($font));
  10778.                                         if (in_array($font$this->fontlistOR in_array($font$this->fontkeys)) {
  10779.                                             $dom[$key]['fontname'$font;
  10780.                                             break;
  10781.                                         }
  10782.                                     }
  10783.                                 }
  10784.                             }
  10785.                             // list-style-type
  10786.                             if (isset($dom[$key]['style']['list-style-type'])) {
  10787.                                 $dom[$key]['listtype'trim(strtolower($dom[$key]['style']['list-style-type']));
  10788.                                 if ($dom[$key]['listtype'== 'inherit'{
  10789.                                     $dom[$key]['listtype'$dom[$parentkey]['listtype'];
  10790.                                 }
  10791.                             }
  10792.                             // font size
  10793.                             if (isset($dom[$key]['style']['font-size'])) {
  10794.                                 $fsize trim($dom[$key]['style']['font-size']);
  10795.                                 switch ($fsize{
  10796.                                     // absolute-size
  10797.                                     case 'xx-small'{
  10798.                                         $dom[$key]['fontsize'$dom[0]['fontsize'4;
  10799.                                         break;
  10800.                                     }
  10801.                                     case 'x-small'{
  10802.                                         $dom[$key]['fontsize'$dom[0]['fontsize'3;
  10803.                                         break;
  10804.                                     }
  10805.                                     case 'small'{
  10806.                                         $dom[$key]['fontsize'$dom[0]['fontsize'2;
  10807.                                         break;
  10808.                                     }
  10809.                                     case 'medium'{
  10810.                                         $dom[$key]['fontsize'$dom[0]['fontsize'];
  10811.                                         break;
  10812.                                     }
  10813.                                     case 'large'{
  10814.                                         $dom[$key]['fontsize'$dom[0]['fontsize'2;
  10815.                                         break;
  10816.                                     }
  10817.                                     case 'x-large'{
  10818.                                         $dom[$key]['fontsize'$dom[0]['fontsize'4;
  10819.                                         break;
  10820.                                     }
  10821.                                     case 'xx-large'{
  10822.                                         $dom[$key]['fontsize'$dom[0]['fontsize'6;
  10823.                                         break;
  10824.                                     }
  10825.                                     // relative-size
  10826.                                     case 'smaller'{
  10827.                                         $dom[$key]['fontsize'$dom[$parentkey]['fontsize'3;
  10828.                                         break;
  10829.                                     }
  10830.                                     case 'larger'{
  10831.                                         $dom[$key]['fontsize'$dom[$parentkey]['fontsize'3;
  10832.                                         break;
  10833.                                     }
  10834.                                     default{
  10835.                                         $dom[$key]['fontsize'$this->getHTMLUnitToUnits($fsize$dom[$parentkey]['fontsize']'pt'true);
  10836.                                     }
  10837.                                 }
  10838.                             }
  10839.                             // font style
  10840.                             if (isset($dom[$key]['style']['font-weight']AND (strtolower($dom[$key]['style']['font-weight']{0}== 'b')) {
  10841.                                 $dom[$key]['fontstyle'.= 'B';
  10842.                             }
  10843.                             if (isset($dom[$key]['style']['font-style']AND (strtolower($dom[$key]['style']['font-style']{0}== 'i')) {
  10844.                                 $dom[$key]['fontstyle'.= '"I';
  10845.                             }
  10846.                             // font color
  10847.                             if (isset($dom[$key]['style']['color']AND (!$this->empty_string($dom[$key]['style']['color']))) {
  10848.                                 $dom[$key]['fgcolor'$this->convertHTMLColorToDec($dom[$key]['style']['color']);
  10849.                             }
  10850.                             // background color
  10851.                             if (isset($dom[$key]['style']['background-color']AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
  10852.                                 $dom[$key]['bgcolor'$this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  10853.                             }
  10854.                             // text-decoration
  10855.                             if (isset($dom[$key]['style']['text-decoration'])) {
  10856.                                 $decors explode(' 'strtolower($dom[$key]['style']['text-decoration']));
  10857.                                 foreach ($decors as $dec{
  10858.                                     $dec trim($dec);
  10859.                                     if (!$this->empty_string($dec)) {
  10860.                                         if ($dec{0== 'u'{
  10861.                                             $dom[$key]['fontstyle'.= 'U';
  10862.                                         elseif ($dec{0== 'l'{
  10863.                                             $dom[$key]['fontstyle'.= 'D';
  10864.                                         }
  10865.                                     }
  10866.                                 }
  10867.                             }
  10868.                             // check for width attribute
  10869.                             if (isset($dom[$key]['style']['width'])) {
  10870.                                 $dom[$key]['width'$dom[$key]['style']['width'];
  10871.                             }
  10872.                             // check for height attribute
  10873.                             if (isset($dom[$key]['style']['height'])) {
  10874.                                 $dom[$key]['height'$dom[$key]['style']['height'];
  10875.                             }
  10876.                             // check for text alignment
  10877.                             if (isset($dom[$key]['style']['text-align'])) {
  10878.                                 $dom[$key]['align'strtoupper($dom[$key]['style']['text-align']{0});
  10879.                             }
  10880.                             // check for border attribute
  10881.                             if (isset($dom[$key]['style']['border'])) {
  10882.                                 $dom[$key]['attribute']['border'$dom[$key]['style']['border'];
  10883.                             }
  10884.                         }
  10885.                         // check for font tag
  10886.                         if ($dom[$key]['value'== 'font'{
  10887.                             // font family
  10888.                             if (isset($dom[$key]['attribute']['face'])) {
  10889.                                 $fontslist split(','strtolower($dom[$key]['attribute']['face']));
  10890.                                 foreach ($fontslist as $font{
  10891.                                     $font trim(strtolower($font));
  10892.                                     if (in_array($font$this->fontlistOR in_array($font$this->fontkeys)) {
  10893.                                         $dom[$key]['fontname'$font;
  10894.                                         break;
  10895.                                     }
  10896.                                 }
  10897.                             }
  10898.                             // font size
  10899.                             if (isset($dom[$key]['attribute']['size'])) {
  10900.                                 if ($key 0{
  10901.                                     if ($dom[$key]['attribute']['size']{0== '+'{
  10902.                                         $dom[$key]['fontsize'$dom[($dom[$key]['parent'])]['fontsize'intval(substr($dom[$key]['attribute']['size']1));
  10903.                                     elseif ($dom[$key]['attribute']['size']{0== '-'{
  10904.                                         $dom[$key]['fontsize'$dom[($dom[$key]['parent'])]['fontsize'intval(substr($dom[$key]['attribute']['size']1));
  10905.                                     else {
  10906.                                         $dom[$key]['fontsize'intval($dom[$key]['attribute']['size']);
  10907.                                     }
  10908.                                 else {
  10909.                                     $dom[$key]['fontsize'intval($dom[$key]['attribute']['size']);
  10910.                                 }
  10911.                             }
  10912.                         }
  10913.                         // force natural alignment for lists
  10914.                         if ((($dom[$key]['value'== 'ul'OR ($dom[$key]['value'== 'ol'OR ($dom[$key]['value'== 'dl'))
  10915.                             AND (!isset($dom[$key]['align']OR $this->empty_string($dom[$key]['align']OR ($dom[$key]['align'!= 'J'))) {
  10916.                             if ($this->rtl{
  10917.                                 $dom[$key]['align''R';
  10918.                             else {
  10919.                                 $dom[$key]['align''L';
  10920.                             }
  10921.                         }
  10922.                         if (($dom[$key]['value'== 'small'OR ($dom[$key]['value'== 'sup'OR ($dom[$key]['value'== 'sub')) {
  10923.                             $dom[$key]['fontsize'$dom[$key]['fontsize'K_SMALL_RATIO;
  10924.                         }
  10925.                         if (($dom[$key]['value'== 'strong'OR ($dom[$key]['value'== 'b')) {
  10926.                             $dom[$key]['fontstyle'.= 'B';
  10927.                         }
  10928.                         if (($dom[$key]['value'== 'em'OR ($dom[$key]['value'== 'i')) {
  10929.                             $dom[$key]['fontstyle'.= 'I';
  10930.                         }
  10931.                         if ($dom[$key]['value'== 'u'{
  10932.                             $dom[$key]['fontstyle'.= 'U';
  10933.                         }
  10934.                         if ($dom[$key]['value'== 'del'{
  10935.                             $dom[$key]['fontstyle'.= 'D';
  10936.                         }
  10937.                         if (($dom[$key]['value'== 'pre'OR ($dom[$key]['value'== 'tt')) {
  10938.                             $dom[$key]['fontname'$this->default_monospaced_font;
  10939.                         }
  10940.                         if (($dom[$key]['value']{0== 'h'AND (intval($dom[$key]['value']{1}0AND (intval($dom[$key]['value']{1}7)) {
  10941.                             $headsize (intval($dom[$key]['value']{1})) 2;
  10942.                             $dom[$key]['fontsize'$dom[0]['fontsize'$headsize;
  10943.                             $dom[$key]['fontstyle'.= 'B';
  10944.                         }
  10945.                         if (($dom[$key]['value'== 'table')) {
  10946.                             $dom[$key]['rows'0// number of rows
  10947.                             $dom[$key]['trids'array()// IDs of TR elements
  10948.                             $dom[$key]['thead'''// table header rows
  10949.                         }
  10950.                         if (($dom[$key]['value'== 'tr')) {
  10951.                             $dom[$key]['cols'0;
  10952.                             // store the number of rows on table element
  10953.                             ++$dom[($dom[$key]['parent'])]['rows'];
  10954.                             // store the TR elements IDs on table element
  10955.                             array_push($dom[($dom[$key]['parent'])]['trids']$key);
  10956.                             if ($thead{
  10957.                                 $dom[$key]['thead'true;
  10958.                             else {
  10959.                                 $dom[$key]['thead'false;
  10960.                             }
  10961.                         }
  10962.                         if (($dom[$key]['value'== 'th'OR ($dom[$key]['value'== 'td')) {
  10963.                             if (isset($dom[$key]['attribute']['colspan'])) {
  10964.                                 $colspan intval($dom[$key]['attribute']['colspan']);
  10965.                             else {
  10966.                                 $colspan 1;
  10967.                             }
  10968.                             $dom[$key]['attribute']['colspan'$colspan;
  10969.                             $dom[($dom[$key]['parent'])]['cols'+= $colspan;
  10970.                         }
  10971.                         // set foreground color attribute
  10972.                         if (isset($dom[$key]['attribute']['color']AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
  10973.                             $dom[$key]['fgcolor'$this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  10974.                         }
  10975.                         // set background color attribute
  10976.                         if (isset($dom[$key]['attribute']['bgcolor']AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
  10977.                             $dom[$key]['bgcolor'$this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  10978.                         }
  10979.                         // check for width attribute
  10980.                         if (isset($dom[$key]['attribute']['width'])) {
  10981.                             $dom[$key]['width'$dom[$key]['attribute']['width'];
  10982.                         }
  10983.                         // check for height attribute
  10984.                         if (isset($dom[$key]['attribute']['height'])) {
  10985.                             $dom[$key]['height'$dom[$key]['attribute']['height'];
  10986.                         }
  10987.                         // check for text alignment
  10988.                         if (isset($dom[$key]['attribute']['align']AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'!== 'img')) {
  10989.                             $dom[$key]['align'strtoupper($dom[$key]['attribute']['align']{0});
  10990.                         }
  10991.                     // end opening tag
  10992.                 else {
  10993.                     // text
  10994.                     $dom[$key]['tag'false;
  10995.                     $dom[$key]['value'stripslashes($this->unhtmlentities($element));
  10996.                     $dom[$key]['parent'end($level);
  10997.                 }
  10998.                 ++$elkey;
  10999.                 ++$key;
  11000.             }
  11001.             return $dom;
  11002.         }
  11003.         
  11004.         /**
  11005.          * Allows to preserve some HTML formatting (limited support).<br />
  11006.          * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  11007.          * 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, small, span, strong, sub, sup, table, td, th, tr, u, ul,
  11008.          * @param string $html text to display
  11009.          * @param boolean $ln if true add a new line after text (default = true)
  11010.          * @param int $fill Indicates if the background must be painted (true) or transparent (false).
  11011.          * @param boolean $reseth if true reset the last cell height (default false).
  11012.          * @param boolean $cell if true add the default cMargin space to each Write (default false).
  11013.          * @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>
  11014.          * @access public
  11015.          */
  11016.         public function writeHTML($html$ln=true$fill=false$reseth=false$cell=false$align=''{
  11017.             $gvars $this->getGraphicVars();
  11018.             // store current values
  11019.             $prevPage $this->page;
  11020.             $prevlMargin $this->lMargin;
  11021.             $prevrMargin $this->rMargin;
  11022.             $curfontname $this->FontFamily;
  11023.             $curfontstyle $this->FontStyle;
  11024.             $curfontsize $this->FontSizePt;    
  11025.             $this->newline true;
  11026.             $minstartliney $this->y;
  11027.             $yshift 0;
  11028.             $startlinepage $this->page;
  11029.             $newline true;
  11030.             $loop 0;
  11031.             $curpos 0;
  11032.             $blocktags array('blockquote','br','dd','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','ul');
  11033.             $this->premode false;
  11034.             if (isset($this->PageAnnots[$this->page])) {
  11035.                 $pask count($this->PageAnnots[$this->page]);
  11036.             else {
  11037.                 $pask 0;
  11038.             }
  11039.             if (isset($this->footerlen[$this->page])) {
  11040.                 $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  11041.             else {
  11042.                 $this->footerpos[$this->page$this->pagelen[$this->page];
  11043.             }
  11044.             $startlinepos $this->footerpos[$this->page];
  11045.             $lalign $align;
  11046.             $plalign $align;
  11047.             if ($this->rtl{
  11048.                 $w $this->x $this->lMargin;
  11049.             else {
  11050.                 $w $this->w $this->rMargin $this->x;
  11051.             }
  11052.             $w -= ($this->cMargin);
  11053.             if ($cell{
  11054.                 if ($this->rtl{
  11055.                     $this->x -= $this->cMargin;
  11056.                 else {
  11057.                     $this->x += $this->cMargin;
  11058.                 }
  11059.             }
  11060.             if ($this->customlistindent >= 0{
  11061.                 $this->listindent $this->customlistindent;
  11062.             else {
  11063.                 $this->listindent $this->GetStringWidth('0000');
  11064.             }
  11065.             $this->listnum 0;
  11066.             if (($this->empty_string($this->lasth)) OR ($reseth)) {
  11067.                 //set row height
  11068.                 $this->lasth $this->FontSize $this->cell_height_ratio
  11069.             }
  11070.             $dom $this->getHtmlDomArray($html);
  11071.             $maxel count($dom);
  11072.             $key 0;
  11073.             while ($key $maxel{
  11074.                 if ($dom[$key]['tag'OR ($key == 0)) {
  11075.                     if ((($dom[$key]['value'== 'table'OR ($dom[$key]['value'== 'tr')) AND (isset($dom[$key]['align']))) {
  11076.                         $dom[$key]['align'($this->rtl'R' 'L';
  11077.                     }
  11078.                     // vertically align image in line
  11079.                     if ((!$this->newline)
  11080.                         AND ($dom[$key]['value'== 'img')
  11081.                         AND (isset($dom[$key]['attribute']['height']))
  11082.                         AND ($dom[$key]['attribute']['height'0)
  11083.                         AND (!((($this->y $this->getHTMLUnitToUnits($dom[$key]['attribute']['height']$this->lasth'px')) $this->PageBreakTrigger)
  11084.                             AND (!$this->InFooter)
  11085.                             AND $this->AcceptPageBreak()))
  11086.                         {
  11087.                         if ($this->page $startlinepage{
  11088.                             // fix lines splitted over two pages
  11089.                             if (isset($this->footerlen[$startlinepage])) {
  11090.                                 $curpos $this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11091.                             }
  11092.                             // line to be moved one page forward
  11093.                             $pagebuff $this->getPageBuffer($startlinepage);
  11094.                             $linebeg substr($pagebuff$startlinepos($curpos $startlinepos));
  11095.                             $tstart substr($pagebuff0$startlinepos);
  11096.                             $tend substr($this->getPageBuffer($startlinepage)$curpos);
  11097.                             // remove line start from previous page
  11098.                             $this->setPageBuffer($startlinepage$tstart.''.$tend);
  11099.                             $pagebuff $this->getPageBuffer($this->page);
  11100.                             $tstart substr($pagebuff0$this->intmrk[$this->page]);
  11101.                             $tend substr($pagebuff$this->intmrk[$this->page]);
  11102.                             // add line start to current page
  11103.                             $yshift $minstartliney $this->y;
  11104.                             $try sprintf('1 0 0 1 0 %.3F cm'($yshift $this->k));
  11105.                             $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  11106.                             // shift the annotations and links
  11107.                             if (isset($this->PageAnnots[$startlinepage])) {
  11108.                                 foreach ($this->PageAnnots[$startlinepageas $pak => $pac{
  11109.                                     if ($pak >= $pask{
  11110.                                         $this->PageAnnots[$this->page][$pac;
  11111.                                         unset($this->PageAnnots[$startlinepage][$pak]);
  11112.                                         $npak count($this->PageAnnots[$this->page]1;
  11113.                                         $this->PageAnnots[$this->page][$npak]['y'-= $yshift;
  11114.                                     }
  11115.                                 }
  11116.                             }
  11117.                         }
  11118.                         $this->y += (($curfontsize $this->k$this->getHTMLUnitToUnits($dom[$key]['attribute']['height']$this->lasth'px'));
  11119.                         $minstartliney min($this->y$minstartliney);
  11120.                     elseif (isset($dom[$key]['fontname']OR isset($dom[$key]['fontstyle']OR isset($dom[$key]['fontsize'])) {
  11121.                         // account for different font size
  11122.                         $pfontname $curfontname;
  11123.                         $pfontstyle $curfontstyle;
  11124.                         $pfontsize $curfontsize;
  11125.                         $fontname = isset($dom[$key]['fontname']$dom[$key]['fontname'$curfontname;
  11126.                         $fontstyle = isset($dom[$key]['fontstyle']$dom[$key]['fontstyle'$curfontstyle;
  11127.                         $fontsize = isset($dom[$key]['fontsize']$dom[$key]['fontsize'$curfontsize;
  11128.                         if (($fontname != $curfontnameOR ($fontstyle != $curfontstyleOR ($fontsize != $curfontsize)) {
  11129.                             $this->SetFont($fontname$fontstyle$fontsize);
  11130.                             $this->lasth $this->FontSize $this->cell_height_ratio;
  11131.                             if (is_numeric($fontsizeAND ($fontsize 0)
  11132.                                 AND is_numeric($curfontsizeAND ($curfontsize 0)
  11133.                                 AND ($fontsize != $curfontsizeAND (!$this->newline)
  11134.                                 AND ($key ($maxel 1))
  11135.                                 {
  11136.                                 if ((!$this->newlineAND ($this->page $startlinepage)) {
  11137.                                     // fix lines splitted over two pages
  11138.                                     if (isset($this->footerlen[$startlinepage])) {
  11139.                                         $curpos $this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11140.                                     }
  11141.                                     // line to be moved one page forward
  11142.                                     $pagebuff $this->getPageBuffer($startlinepage);
  11143.                                     $linebeg substr($pagebuff$startlinepos($curpos $startlinepos));
  11144.                                     $tstart substr($pagebuff0$startlinepos);
  11145.                                     $tend substr($this->getPageBuffer($startlinepage)$curpos);
  11146.                                     // remove line start from previous page
  11147.                                     $this->setPageBuffer($startlinepage$tstart.''.$tend);
  11148.                                     $pagebuff $this->getPageBuffer($this->page);
  11149.                                     $tstart substr($pagebuff0$this->intmrk[$this->page]);
  11150.                                     $tend substr($pagebuff$this->intmrk[$this->page]);
  11151.                                     // add line start to current page
  11152.                                     $yshift $minstartliney $this->y;
  11153.                                     $try sprintf('1 0 0 1 0 %.3F cm'($yshift $this->k));
  11154.                                     $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  11155.                                     // shift the annotations and links
  11156.                                     if (isset($this->PageAnnots[$startlinepage])) {
  11157.                                         foreach ($this->PageAnnots[$startlinepageas $pak => $pac{
  11158.                                             if ($pak >= $pask{
  11159.                                                 $this->PageAnnots[$this->page][$pac;
  11160.                                                 unset($this->PageAnnots[$startlinepage][$pak]);
  11161.                                                 $npak count($this->PageAnnots[$this->page]1;
  11162.                                                 $this->PageAnnots[$this->page][$npak]['y'-= $yshift;
  11163.                                             }
  11164.                                         }
  11165.                                     }
  11166.                                 }
  11167.                                 $this->y += (($curfontsize $fontsize$this->k);
  11168.                                 $minstartliney min($this->y$minstartliney);
  11169.                             }
  11170.                             $curfontname $fontname;
  11171.                             $curfontstyle $fontstyle;
  11172.                             $curfontsize $fontsize;
  11173.                         }
  11174.                     }
  11175.                     if (($plalign == 'J'AND (in_array($dom[$key]['value']$blocktags))) {
  11176.                         $plalign '';
  11177.                     }
  11178.                     // get current position on page buffer
  11179.                     $curpos $this->pagelen[$startlinepage];
  11180.                     if (isset($dom[$key]['bgcolor']AND ($dom[$key]['bgcolor'!== false)) {
  11181.                         $this->SetFillColorArray($dom[$key]['bgcolor']);
  11182.                         $wfill true;
  11183.                     else {
  11184.                         $wfill $fill false;
  11185.                     }
  11186.                     if (isset($dom[$key]['fgcolor']AND ($dom[$key]['fgcolor'!== false)) {
  11187.                         $this->SetTextColorArray($dom[$key]['fgcolor']);
  11188.                     }
  11189.                     if (isset($dom[$key]['align'])) {
  11190.                         $lalign $dom[$key]['align'];
  11191.                     }
  11192.                     if ($this->empty_string($lalign)) {
  11193.                         $lalign $align;
  11194.                     }
  11195.                 }
  11196.                 // align lines
  11197.                 if ($this->newline AND (strlen($dom[$key]['value']0AND ($dom[$key]['value'!= 'td'AND ($dom[$key]['value'!= 'th')) {
  11198.                     $newline true;
  11199.                     // we are at the beginning of a new line
  11200.                     if (isset($startlinex)) {
  11201.                         $yshift $minstartliney $startliney;
  11202.                         if (($yshift 0OR ($this->page $startlinepage)) {
  11203.                             $yshift 0;
  11204.                         }
  11205.                         if ((isset($plalignAND ((($plalign == 'C'OR ($plalign == 'J'OR (($plalign == 'R'AND (!$this->rtl)) OR (($plalign == 'L'AND ($this->rtl))))) OR ($yshift 0)) {
  11206.                             // the last line must be shifted to be aligned as requested
  11207.                             $linew abs($this->endlinex $startlinex);
  11208.                             $pstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  11209.                             if (isset($opentagposAND isset($this->footerlen[$startlinepage])) {
  11210.                                 $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11211.                                 $midpos min($opentagpos$this->footerpos[$startlinepage]);
  11212.                             elseif (isset($opentagpos)) {
  11213.                                 $midpos $opentagpos;
  11214.                             elseif (isset($this->footerlen[$startlinepage])) {
  11215.                                 $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11216.                                 $midpos $this->footerpos[$startlinepage];
  11217.                             else {
  11218.                                 $midpos 0;
  11219.                             }
  11220.                             if ($midpos 0{
  11221.                                 $pmid substr($this->getPageBuffer($startlinepage)$startlinepos($midpos $startlinepos));
  11222.                                 $pend substr($this->getPageBuffer($startlinepage)$midpos);
  11223.                             else {
  11224.                                 $pmid substr($this->getPageBuffer($startlinepage)$startlinepos);
  11225.                                 $pend '';
  11226.                             }
  11227.                             // calculate shifting amount
  11228.                             $tw $w;
  11229.                             if ($this->lMargin != $prevlMargin{
  11230.                                 $tw += ($prevlMargin $this->lMargin);
  11231.                             }
  11232.                             if ($this->rMargin != $prevrMargin{
  11233.                                 $tw += ($prevrMargin $this->rMargin);
  11234.                             }
  11235.                             $mdiff abs($tw $linew);
  11236.                             $t_x 0;
  11237.                             if ($plalign == 'C'{
  11238.                                 if ($this->rtl{
  11239.                                     $t_x = -($mdiff 2);
  11240.                                 else {
  11241.                                     $t_x ($mdiff 2);
  11242.                                 }
  11243.                             elseif (($plalign == 'R'AND (!$this->rtl)) {
  11244.                                 // right alignment on LTR document
  11245.                                 $t_x $mdiff;    
  11246.                             elseif (($plalign == 'L'AND ($this->rtl)) {
  11247.                                 // left alignment on RTL document
  11248.                                 $t_x = -$mdiff;
  11249.                             elseif (($plalign == 'J'AND ($plalign == $lalign)) {
  11250.                                 // Justification
  11251.                                 if ($this->rtl OR $this->tmprtl{
  11252.                                     $t_x $this->lMargin $this->endlinex;
  11253.                                 }
  11254.                                 $no 0;
  11255.                                 $ns 0;
  11256.  
  11257.                                 $pmidtemp $pmid;
  11258.                                 // escape special characters
  11259.                                 $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  11260.                                 $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  11261.                                 // search spaces
  11262.                                 if (preg_match_all('/\[\(([^\)]*)\)\]/x'$pmidtemp$lnstringPREG_PATTERN_ORDER)) {
  11263.                                     $maxkk count($lnstring[1]1;
  11264.                                     //foreach ($lnstring[1] as $kk => $value) {
  11265.                                     for ($kk=0$kk <= $maxkk++$kk{
  11266.                                         // restore special characters
  11267.                                         $lnstring[1][$kkstr_replace('#!#OP#!#''('$lnstring[1][$kk]);
  11268.                                         $lnstring[1][$kkstr_replace('#!#CP#!#'')'$lnstring[1][$kk]);
  11269.                                         if ($kk == $maxkk{
  11270.                                             if ($this->rtl OR $this->tmprtl{
  11271.                                                 $tvalue ltrim($lnstring[1][$kk]);
  11272.                                             else {
  11273.                                                 $tvalue rtrim($lnstring[1][$kk]);
  11274.                                             }
  11275.                                         else {
  11276.                                             $tvalue $lnstring[1][$kk];
  11277.                                         }
  11278.                                         // count spaces on line
  11279.                                         $no += substr_count($lnstring[1][$kk]chr(32));
  11280.                                         $ns += substr_count($tvaluechr(32));
  11281.                                     }
  11282.                                     if ($this->rtl OR $this->tmprtl{
  11283.                                         $t_x $this->lMargin $this->endlinex (($no $ns 1$this->GetStringWidth(chr(32)));
  11284.                                     }
  11285.                                     // calculate additional space to add to each space
  11286.                                     $spacewidth (($tw $linew (($no $ns$this->GetStringWidth(chr(32)))) ($ns?$ns:1)) $this->k;
  11287.                                     $spacewidthu ($tw $linew ($no $this->GetStringWidth(chr(32)))) ($ns?$ns:1$this->FontSize $this->k;
  11288.                                     $nsmax $ns;
  11289.                                     $ns 0;
  11290.                                     reset($lnstring);
  11291.                                     $offset 0;
  11292.                                     $strcount 0;
  11293.                                     $prev_epsposbeg 0;
  11294.                                     global $spacew;
  11295.                                     while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x'$pmid$strpiecePREG_OFFSET_CAPTURE$offset== 1{
  11296.                                         if ($this->rtl OR $this->tmprtl{
  11297.                                             $spacew ($spacewidth ($nsmax $ns));
  11298.                                         else {
  11299.                                             $spacew ($spacewidth $ns);
  11300.                                         }
  11301.                                         $offset $strpiece[2][1strlen($strpiece[2][0]);
  11302.                                         $epsposbeg strpos($pmid'q'.$this->epsmarker$offset);
  11303.                                         $epsposend strpos($pmid$this->epsmarker.'Q'$offsetstrlen($this->epsmarker.'Q');
  11304.                                         if ((($epsposbeg 0AND ($epsposend 0AND ($offset $epsposbegAND ($offset $epsposend))
  11305.                                             OR (($epsposbeg === falseAND ($epsposend 0AND ($offset $epsposend))) {
  11306.                                             // shift EPS images
  11307.                                             $trx sprintf('1 0 0 1 %.3F 0 cm'$spacew);
  11308.                                             $epsposbeg strpos($pmid'q'.$this->epsmarker($prev_epsposbeg 6));
  11309.                                             $pmid_b substr($pmid0$epsposbeg);
  11310.                                             $pmid_m substr($pmid$epsposbeg($epsposend $epsposbeg));
  11311.                                             $pmid_e substr($pmid$epsposend);
  11312.                                             $pmid $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  11313.                                             $offset $epsposend;
  11314.                                             continue;
  11315.                                         }
  11316.                                         $prev_epsposbeg $epsposbeg;
  11317.                                         $currentxpos 0;
  11318.                                         // shift blocks of code
  11319.                                         switch ($strpiece[2][0]{
  11320.                                             case 'Td':
  11321.                                             case 'cm':
  11322.                                             case 'm':
  11323.                                             case 'l'{
  11324.                                                 // get current X position
  11325.                                                 preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  11326.                                                 $currentxpos $xmatches[1];
  11327.                                                 if (($strcount <= $maxkkAND ($strpiece[2][0== 'Td')) {
  11328.                                                     if ($strcount == $maxkk{
  11329.                                                         if ($this->rtl OR $this->tmprtl{
  11330.                                                             $tvalue $lnstring[1][$strcount];
  11331.                                                         else {
  11332.                                                             $tvalue rtrim($lnstring[1][$strcount]);
  11333.                                                         }
  11334.                                                     else {
  11335.                                                         $tvalue $lnstring[1][$strcount];
  11336.                                                     }
  11337.                                                     $ns += substr_count($tvaluechr(32));
  11338.                                                     ++$strcount;
  11339.                                                 }
  11340.                                                 if ($this->rtl OR $this->tmprtl{
  11341.                                                     $spacew ($spacewidth ($nsmax $ns));
  11342.                                                 }
  11343.                                                 // justify block
  11344.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  11345.                                                     create_function('$matches''global $spacew;
  11346.                                                     $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
  11347.                                                     return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];')$pmid1);
  11348.                                                 break;
  11349.                                             }
  11350.                                             case 're'{
  11351.                                                 // get current X position
  11352.                                                 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  11353.                                                 $currentxpos $xmatches[1];
  11354.                                                 // justify block
  11355.                                                 $pmid preg_replace_callback('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  11356.                                                     create_function('$matches''global $spacew;
  11357.                                                     $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
  11358.                                                     return "".$newx." ".$matches[2]." ".$matches[3]." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];')$pmid1);
  11359.                                                 break;
  11360.                                             }
  11361.                                             case 'c'{
  11362.                                                 // get current X position
  11363.                                                 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);
  11364.                                                 $currentxpos $xmatches[1];
  11365.                                                 // justify block
  11366.                                                 $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',
  11367.                                                     create_function('$matches''global $spacew;
  11368.                                                     $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
  11369.                                                     $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
  11370.                                                     $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
  11371.                                                     return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];')$pmid1);
  11372.                                                 break;
  11373.                                             }
  11374.                                         }
  11375.                                         // shift the annotations and links
  11376.                                         if (isset($this->PageAnnots[$this->page])) {
  11377.                                             foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  11378.                                                 if (($pac['y'>= $minstartlineyAND (($pac['x'$this->k>= ($currentxpos $this->feps)) AND (($pac['x'$this->k<= ($currentxpos $this->feps))) {
  11379.                                                     $this->PageAnnots[$this->page][$pak]['x'+= ($spacew $this->k);
  11380.                                                     $this->PageAnnots[$this->page][$pak]['w'+= (($spacewidth $pac['numspaces']$this->k);
  11381.                                                     break;
  11382.                                                 }
  11383.                                             }
  11384.                                         }
  11385.                                     // end of while
  11386.                                     // remove markers
  11387.                                     $pmid str_replace('x*#!#*x'''$pmid);
  11388.                                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  11389.                                         // multibyte characters
  11390.                                         $spacew $spacewidthu;
  11391.                                         $pmidtemp $pmid;
  11392.                                         // escape special characters
  11393.                                         $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  11394.                                         $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  11395.                                         $pmid preg_replace_callback("/\[\(([^\)]*)\)\]/x",
  11396.                                                     create_function('$matches''global $spacew;
  11397.                                                     $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  11398.                                                     $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  11399.                                                     return "[(".str_replace(chr(0).chr(32), ") ".(-2830 * $spacew)." (", $matches[1]).")]";')$pmidtemp);
  11400.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\n".$pend);
  11401.                                         $endlinepos strlen($pstart."\n".$pmid."\n");
  11402.                                     else {
  11403.                                         // non-unicode (single-byte characters)
  11404.                                         $rs sprintf("%.3F Tw"$spacewidth);
  11405.                                         $pmid preg_replace("/\[\(/x"$rs.' [('$pmid);
  11406.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  11407.                                         $endlinepos strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  11408.                                     }
  11409.                                 }
  11410.                             // end of J
  11411.                             if (($t_x != 0OR ($yshift 0)) {
  11412.                                 // shift the line
  11413.                                 $trx sprintf('1 0 0 1 %.3F %.3F cm'($t_x $this->k)($yshift $this->k));
  11414.                                 $this->setPageBuffer($startlinepage$pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend);
  11415.                                 $endlinepos strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n");
  11416.                                 // shift the annotations and links
  11417.                                 if (isset($this->PageAnnots[$this->page])) {
  11418.                                     foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  11419.                                         if ($pak >= $pask{
  11420.                                             $this->PageAnnots[$this->page][$pak]['x'+= $t_x;
  11421.                                             $this->PageAnnots[$this->page][$pak]['y'-= $yshift;
  11422.                                         }
  11423.                                     }
  11424.                                 }
  11425.                                 $this->y -= $yshift;
  11426.                             }
  11427.                         }
  11428.                     }
  11429.                     $this->newline false;
  11430.                     $pbrk $this->checkPageBreak($this->lasth);
  11431.                     $this->SetFont($fontname$fontstyle$fontsize);
  11432.                     if ($wfill{
  11433.                         $this->SetFillColorArray($this->bgcolor);
  11434.                     }
  11435.                     $startlinex $this->x;
  11436.                     $startliney $this->y;
  11437.                     $minstartliney $this->y;
  11438.                     $startlinepage $this->page;
  11439.                     if (isset($endlineposAND (!$pbrk)) {
  11440.                         $startlinepos $endlinepos;
  11441.                         unset($endlinepos);
  11442.                     else {
  11443.                         if (isset($this->footerlen[$this->page])) {
  11444.                             $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  11445.                         else {
  11446.                             $this->footerpos[$this->page$this->pagelen[$this->page];
  11447.                         }
  11448.                         $startlinepos $this->footerpos[$this->page];
  11449.                     }
  11450.                     $plalign $lalign;
  11451.                     if (isset($this->PageAnnots[$this->page])) {
  11452.                         $pask count($this->PageAnnots[$this->page]);
  11453.                     else {
  11454.                         $pask 0;
  11455.                     }
  11456.                 }
  11457.                 if (isset($opentagpos)) {
  11458.                     unset($opentagpos);
  11459.                 }
  11460.                 if ($dom[$key]['tag']{
  11461.                     if ($dom[$key]['opening']{
  11462.                         if ($dom[$key]['value'== 'table'{
  11463.                             if ($this->rtl{
  11464.                                 $wtmp $this->x $this->lMargin;
  11465.                             else {
  11466.                                 $wtmp $this->w $this->rMargin $this->x;
  11467.                             }
  11468.                             $wtmp -= ($this->cMargin);
  11469.                             // calculate cell width
  11470.                             if (isset($dom[$key]['width'])) {
  11471.                                 $table_width $this->getHTMLUnitToUnits($dom[$key]['width']$wtmp'px');
  11472.                             else {
  11473.                                 $table_width $wtmp;
  11474.                             }
  11475.                         }
  11476.                         // table content is handled in a special way
  11477.                         if (($dom[$key]['value'== 'td'OR ($dom[$key]['value'== 'th')) {
  11478.                             $trid $dom[$key]['parent'];
  11479.                             $table_el $dom[$trid]['parent'];
  11480.                             if (!isset($dom[$table_el]['cols'])) {
  11481.                                 $dom[$table_el]['cols'$trid['cols'];
  11482.                             }
  11483.                             if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  11484.                                 $currentcmargin $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding']1'px');
  11485.                             else {
  11486.                                 $currentcmargin 0;        
  11487.                             }
  11488.                             $this->cMargin $currentcmargin;
  11489.                             if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellspacing'])) {
  11490.                                 $cellspacing $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellspacing']1'px');
  11491.                             else {
  11492.                                 $cellspacing 0;
  11493.                             }
  11494.                             if ($this->rtl{
  11495.                                 $cellspacingx = -$cellspacing;
  11496.                             else {
  11497.                                 $cellspacingx $cellspacing;
  11498.                             }
  11499.                             $colspan $dom[$key]['attribute']['colspan'];
  11500.                             $wtmp ($colspan ($table_width $dom[$table_el]['cols']));
  11501.                             if (isset($dom[$key]['width'])) {
  11502.                                 $cellw $this->getHTMLUnitToUnits($dom[$key]['width']$wtmp'px');
  11503.                             else {
  11504.                                 $cellw $wtmp;
  11505.                             }
  11506.                             if (isset($dom[$key]['height'])) {
  11507.                                 // minimum cell height
  11508.                                 $cellh $this->getHTMLUnitToUnits($dom[$key]['height']0'px');
  11509.                             else {
  11510.                                 $cellh 0;
  11511.                             }
  11512.                             $cellw -= $cellspacing;
  11513.                             if (isset($dom[$key]['content'])) {
  11514.                                 $cell_content $dom[$key]['content'];
  11515.                             else {
  11516.                                 $cell_content '&nbsp;';
  11517.                             }
  11518.                             $tagtype $dom[$key]['value'];
  11519.                             $parentid $key;
  11520.                             while (($key $maxelAND (!(($dom[$key]['tag']AND (!$dom[$key]['opening']AND ($dom[$key]['value'== $tagtypeAND ($dom[$key]['parent'== $parentid)))) {
  11521.                                 // move $key index forward
  11522.                                 ++$key;
  11523.                             }
  11524.                             if (!isset($dom[$trid]['startpage'])) {
  11525.                                 $dom[$trid]['startpage'$this->page;
  11526.                             else {
  11527.                                 $this->setPage($dom[$trid]['startpage']);
  11528.                             }
  11529.                             if (!isset($dom[$trid]['starty'])) {
  11530.                                 $dom[$trid]['starty'$this->y;
  11531.                             else {
  11532.                                 $this->y $dom[$trid]['starty'];
  11533.                             }
  11534.                             if (!isset($dom[$trid]['startx'])) {
  11535.                                 $dom[$trid]['startx'$this->x;
  11536.                             }
  11537.                             $this->x += ($cellspacingx 2);                        
  11538.                             if (isset($dom[$parentid]['attribute']['rowspan'])) {
  11539.                                 $rowspan intval($dom[$parentid]['attribute']['rowspan']);
  11540.                             else {
  11541.                                 $rowspan 1;
  11542.                             }
  11543.                             // skip row-spanned cells started on the previous rows
  11544.                             if (isset($dom[$table_el]['rowspans'])) {
  11545.                                 $rsk 0;
  11546.                                 $rskmax count($dom[$table_el]['rowspans']);
  11547.                                 while ($rsk $rskmax{
  11548.                                     $trwsp $dom[$table_el]['rowspans'][$rsk];
  11549.                                     $rsstartx $trwsp['startx'];
  11550.                                     $rsendx $trwsp['endx'];
  11551.                                     // account for margin changes
  11552.                                     if ($trwsp['startpage'$this->page{
  11553.                                         if (($this->rtlAND ($this->pagedim[$this->page]['orm'!= $this->pagedim[$trwsp['startpage']]['orm'])) {
  11554.                                             $dl ($this->pagedim[$this->page]['orm'$this->pagedim[$trwsp['startpage']]['orm']);
  11555.                                             $rsstartx -= $dl;
  11556.                                             $rsendx -= $dl;
  11557.                                         elseif ((!$this->rtlAND ($this->pagedim[$this->page]['olm'!= $this->pagedim[$trwsp['startpage']]['olm'])) {
  11558.                                             $dl ($this->pagedim[$this->page]['olm'$this->pagedim[$trwsp['startpage']]['olm']);
  11559.                                             $rsstartx += $dl;
  11560.                                             $rsendx += $dl;
  11561.                                         }
  11562.                                     }
  11563.                                     if  (($trwsp['rowspan'0)
  11564.                                         AND ($rsstartx ($this->x $cellspacing $currentcmargin $this->feps))
  11565.                                         AND ($rsstartx ($this->x $cellspacing $currentcmargin $this->feps))
  11566.                                         AND (($trwsp['starty'($this->y $this->feps)) OR ($trwsp['startpage'$this->page))) {
  11567.                                         // set the starting X position of the current cell
  11568.                                         $this->x $rsendx $cellspacingx;
  11569.                                         if (($trwsp['rowspan'== 1)
  11570.                                             AND (isset($dom[$trid]['endy']))
  11571.                                             AND (isset($dom[$trid]['endpage']))
  11572.                                             AND ($trwsp['endpage'== $dom[$trid]['endpage'])) {
  11573.                                             // set ending Y position for row
  11574.                                             $dom[$table_el]['rowspans'][$rsk]['endy'max($dom[$trid]['endy']$trwsp['endy']);
  11575.                                             $dom[$trid]['endy'$dom[$table_el]['rowspans'][$rsk]['endy'];
  11576.                                         }
  11577.                                         $rsk 0;
  11578.                                     else {
  11579.                                         ++$rsk;
  11580.                                     }
  11581.                                 }
  11582.                             }
  11583.                             // add rowspan information to table element
  11584.                             if ($rowspan 1{
  11585.                                 if (isset($this->footerlen[$this->page])) {
  11586.                                     $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  11587.                                 else {
  11588.                                     $this->footerpos[$this->page$this->pagelen[$this->page];
  11589.                                 }
  11590.                                 $trintmrkpos $this->footerpos[$this->page];
  11591.                                 $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));
  11592.                             }
  11593.                             $cellid array_push($dom[$trid]['cellpos']array('startx' => $this->x));
  11594.                             if ($rowspan 1{
  11595.                                 $dom[$trid]['cellpos'][($cellid 1)]['rowspanid'($trsid 1);
  11596.                             }
  11597.                             // push background colors
  11598.                             if (isset($dom[$parentid]['bgcolor']AND ($dom[$parentid]['bgcolor'!== false)) {
  11599.                                 $dom[$trid]['cellpos'][($cellid 1)]['bgcolor'$dom[$parentid]['bgcolor'];
  11600.                             }
  11601.                             $prevLastH $this->lasth;
  11602.                             // ****** write the cell content ******
  11603.                             $this->MultiCell($cellw$cellh$cell_contentfalse$lalignfalse2''''true0true);
  11604.                             $this->lasth $prevLastH;
  11605.                             $this->cMargin $currentcmargin;
  11606.                             $dom[$trid]['cellpos'][($cellid 1)]['endx'$this->x;
  11607.                             // update the end of row position
  11608.                             if ($rowspan <= 1{
  11609.                                 if (isset($dom[$trid]['endy'])) {
  11610.                                     if ($this->page == $dom[$trid]['endpage']{
  11611.                                         $dom[$trid]['endy'max($this->y$dom[$trid]['endy']);
  11612.                                     elseif ($this->page $dom[$trid]['endpage']{
  11613.                                         $dom[$trid]['endy'$this->y;
  11614.                                     }
  11615.                                 else {
  11616.                                     $dom[$trid]['endy'$this->y;
  11617.                                 }
  11618.                                 if (isset($dom[$trid]['endpage'])) {
  11619.                                     $dom[$trid]['endpage'max($this->page$dom[$trid]['endpage']);
  11620.                                 else {
  11621.                                     $dom[$trid]['endpage'$this->page;
  11622.                                 }                                
  11623.                             else {
  11624.                                 // account for row-spanned cells
  11625.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endx'$this->x;
  11626.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endy'$this->y;
  11627.                                 $dom[$table_el]['rowspans'][($trsid 1)]['endpage'$this->page;
  11628.                             }
  11629.                             if (isset($dom[$table_el]['rowspans'])) {
  11630.                                 // update endy and endpage on rowspanned cells
  11631.                                 foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  11632.                                     if ($trwsp['rowspan'0{
  11633.                                         if (isset($dom[$trid]['endpage'])) {
  11634.                                             if ($trwsp['endpage'== $dom[$trid]['endpage']{
  11635.                                                 $dom[$table_el]['rowspans'][$k]['endy'max($dom[$trid]['endy']$trwsp['endy']);
  11636.                                             elseif ($trwsp['endpage'$dom[$trid]['endpage']{
  11637.                                                 $dom[$table_el]['rowspans'][$k]['endy'$dom[$trid]['endy'];
  11638.                                                 $dom[$table_el]['rowspans'][$k]['endpage'$dom[$trid]['endpage'];
  11639.                                             else {
  11640.                                                 $dom[$trid]['endy'$this->pagedim[$dom[$trid]['endpage']]['hk'$this->pagedim[$dom[$trid]['endpage']]['bm'];
  11641.                                             }
  11642.                                         }
  11643.                                     }
  11644.                                 }
  11645.                             }
  11646.                             $this->x += ($cellspacingx 2);                            
  11647.                         else {
  11648.                             // opening tag (or self-closing tag)
  11649.                             if (!isset($opentagpos)) {
  11650.                                 if (!$this->InFooter{
  11651.                                     if (isset($this->footerlen[$this->page])) {
  11652.                                         $this->footerpos[$this->page$this->pagelen[$this->page$this->footerlen[$this->page];
  11653.                                     else {
  11654.                                         $this->footerpos[$this->page$this->pagelen[$this->page];
  11655.                                     }
  11656.                                 }
  11657.                                 $opentagpos $this->footerpos[$this->page];
  11658.                             }
  11659.                             $this->openHTMLTagHandler($dom$key$cell);
  11660.                         }
  11661.                     else {
  11662.                         // closing tag
  11663.                         $this->closeHTMLTagHandler($dom$key$cell);
  11664.                     }
  11665.                 elseif (strlen($dom[$key]['value']0{
  11666.                     // print list-item
  11667.                     if (!$this->empty_string($this->lispacer)) {
  11668.                         $this->SetFont($pfontname$pfontstyle$pfontsize);
  11669.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  11670.                         $minstartliney $this->y;
  11671.                         $this->putHtmlListBullet($this->listnum$this->lispacer$pfontsize);
  11672.                         $this->SetFont($curfontname$curfontstyle$curfontsize);
  11673.                         $this->lasth $this->FontSize $this->cell_height_ratio;
  11674.                         if (is_numeric($pfontsizeAND ($pfontsize 0AND is_numeric($curfontsizeAND ($curfontsize 0AND ($pfontsize != $curfontsize)) {
  11675.                             $this->y += (($pfontsize $curfontsize$this->k);
  11676.                             $minstartliney min($this->y$minstartliney);
  11677.                         }
  11678.                     }
  11679.                     // text
  11680.                     $this->htmlvspace 0;
  11681.                     if ((!$this->premodeAND ($this->rtl OR $this->tmprtl)) {
  11682.                         // reverse spaces order
  11683.                         $len1 strlen($dom[$key]['value']);
  11684.                         $lsp $len1 strlen(ltrim($dom[$key]['value']));
  11685.                         $rsp $len1 strlen(rtrim($dom[$key]['value']));
  11686.                         $tmpstr '';
  11687.                         if ($rsp 0{
  11688.                             $tmpstr .= substr($dom[$key]['value']-$rsp);
  11689.                         }
  11690.                         $tmpstr .= trim($dom[$key]['value']);
  11691.                         if ($lsp 0{
  11692.                             $tmpstr .= substr($dom[$key]['value']0$lsp);
  11693.                         }
  11694.                         $dom[$key]['value'$tmpstr;
  11695.                     }
  11696.                     if ($newline{
  11697.                         if (!$this->premode{
  11698.                             if (($this->rtl OR $this->tmprtl)) {
  11699.                                 $dom[$key]['value'rtrim($dom[$key]['value']);
  11700.                             else {
  11701.                                 $dom[$key]['value'ltrim($dom[$key]['value']);
  11702.                             }
  11703.                         }
  11704.                         $newline false;
  11705.                         $firstblock true;
  11706.                     else {
  11707.                         $firstblock false;
  11708.                     }
  11709.                     $strrest '';
  11710.                     if (!empty($this->HREF)) {
  11711.                         // HTML <a> Link
  11712.                         $strrest $this->addHtmlLink($this->HREF['url']$dom[$key]['value']$wfilltrue$this->HREF['color']$this->HREF['style']);
  11713.                     else {
  11714.                         $ctmpmargin $this->cMargin;
  11715.                         $this->cMargin 0;
  11716.                         // ****** write only until the end of the line and get the rest ******
  11717.                         $strrest $this->Write($this->lasth$dom[$key]['value']''$wfill''false0true$firstblock);
  11718.                         $this->cMargin $ctmpmargin;
  11719.                     }
  11720.                     if (strlen($strrest0{
  11721.                         // store the remaining string on the previous $key position
  11722.                         $this->newline true;
  11723.                         if ($cell{
  11724.                             if ($this->rtl{
  11725.                                 $this->x -= $this->cMargin;
  11726.                             else {
  11727.                                 $this->x += $this->cMargin;
  11728.                             }
  11729.                         }
  11730.                         if ($strrest == $dom[$key]['value']{
  11731.                             // used to avoid infinite loop
  11732.                             ++$loop;
  11733.                         else {
  11734.                             $loop 0;
  11735.                         }
  11736.                         $dom[$key]['value'ltrim($strrest);
  11737.                         if ($loop 3{
  11738.                             --$key;
  11739.                         }
  11740.                     else {
  11741.                         $loop 0;
  11742.                     }
  11743.                 }
  11744.                 ++$key;
  11745.             // end for each $key
  11746.             // align the last line
  11747.             if (isset($startlinex)) {
  11748.                 $yshift $minstartliney $startliney;
  11749.                 if (($yshift 0OR ($this->page $startlinepage)) {
  11750.                     $yshift 0;
  11751.                 }
  11752.                 if ((isset($plalignAND ((($plalign == 'C'OR ($plalign == 'J'OR (($plalign == 'R'AND (!$this->rtl)) OR (($plalign == 'L'AND ($this->rtl))))) OR ($yshift 0)) {
  11753.                     // the last line must be shifted to be aligned as requested
  11754.                     $linew abs($this->endlinex $startlinex);
  11755.                     $pstart substr($this->getPageBuffer($startlinepage)0$startlinepos);
  11756.                     if (isset($opentagposAND isset($this->footerlen[$startlinepage])) {
  11757.                         $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11758.                         $midpos min($opentagpos$this->footerpos[$startlinepage]);
  11759.                     elseif (isset($opentagpos)) {
  11760.                         $midpos $opentagpos;
  11761.                     elseif (isset($this->footerlen[$startlinepage])) {
  11762.                         $this->footerpos[$startlinepage$this->pagelen[$startlinepage$this->footerlen[$startlinepage];
  11763.                         $midpos $this->footerpos[$startlinepage];
  11764.                     else {
  11765.                         $midpos 0;
  11766.                     }
  11767.                     if ($midpos 0{
  11768.                         $pmid substr($this->getPageBuffer($startlinepage)$startlinepos($midpos $startlinepos));
  11769.                         $pend substr($this->getPageBuffer($startlinepage)$midpos);
  11770.                     else {
  11771.                         $pmid substr($this->getPageBuffer($startlinepage)$startlinepos);
  11772.                         $pend '';
  11773.                     }    
  11774.                     // calculate shifting amount
  11775.                     $tw $w;
  11776.                     if ($this->lMargin != $prevlMargin{
  11777.                         $tw += ($prevlMargin $this->lMargin);
  11778.                     }
  11779.                     if ($this->rMargin != $prevrMargin{
  11780.                         $tw += ($prevrMargin $this->rMargin);
  11781.                     }
  11782.                     $mdiff abs($tw $linew);
  11783.                     if ($plalign == 'C'{
  11784.                         if ($this->rtl{
  11785.                             $t_x = -($mdiff 2);
  11786.                         else {
  11787.                             $t_x ($mdiff 2);
  11788.                         }
  11789.                     elseif (($plalign == 'R'AND (!$this->rtl)) {
  11790.                         // right alignment on LTR document
  11791.                         $t_x $mdiff;
  11792.                     elseif (($plalign == 'L'AND ($this->rtl)) {
  11793.                         // left alignment on RTL document
  11794.                         $t_x = -$mdiff;
  11795.                     else {
  11796.                         $t_x 0;
  11797.                     }
  11798.                     if (($t_x != 0OR ($yshift 0)) {
  11799.                         // shift the line
  11800.                         $trx sprintf('1 0 0 1 %.3F %.3F cm'($t_x $this->k)($yshift $this->k));
  11801.                         $this->setPageBuffer($startlinepage$pstart."\nq\n".$trx."\n".$pmid."\nQ\n".$pend);
  11802.                         $endlinepos strlen($pstart."\nq\n".$trx."\n".$pmid."\nQ\n");                                        
  11803.                         // shift the annotations and links
  11804.                         if (isset($this->PageAnnots[$this->page])) {
  11805.                             foreach ($this->PageAnnots[$this->pageas $pak => $pac{
  11806.                                 if ($pak >= $pask{
  11807.                                     $this->PageAnnots[$this->page][$pak]['x'+= $t_x;
  11808.                                     $this->PageAnnots[$this->page][$pak]['y'-= $yshift;
  11809.                                 }
  11810.                             }
  11811.                         }
  11812.                         $this->y -= $yshift;
  11813.                     }
  11814.                 }
  11815.             }
  11816.             if ($ln AND (!($cell AND ($dom[$key-1]['value'== 'table')))) {
  11817.                 $this->Ln($this->lasth);
  11818.             }
  11819.             // restore previous values
  11820.             $this->setGraphicVars($gvars);
  11821.             if ($this->page $prevPage{
  11822.                 $this->lMargin $this->pagedim[$this->page]['olm'];
  11823.                 $this->rMargin $this->pagedim[$this->page]['orm'];
  11824.             }
  11825.             unset($dom);
  11826.         }
  11827.         
  11828.         /**
  11829.          * Process opening tags.
  11830.          * @param array $dom html dom array
  11831.          * @param int $key current element id
  11832.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  11833.          * @access protected
  11834.          */
  11835.         protected function openHTMLTagHandler(&$dom$key$cell=false{
  11836.             $tag $dom[$key];
  11837.             $parent $dom[($dom[$key]['parent'])];
  11838.             $firstorlast ($key == 1);
  11839.             // check for text direction attribute
  11840.             if (isset($tag['attribute']['dir'])) {
  11841.                 $this->tmprtl $tag['attribute']['dir'== 'rtl' 'R' 'L';
  11842.             else {
  11843.                 $this->tmprtl false;
  11844.             }
  11845.             //Opening tag
  11846.             switch($tag['value']{
  11847.                 case 'table'{
  11848.                     $cp 0;
  11849.                     $cs 0;
  11850.                     $dom[$key]['rowspans'array();
  11851.                     if (!$this->empty_string($dom[$key]['thead'])) {
  11852.                         // set table header
  11853.                         $this->thead $dom[$key]['thead'];
  11854.                     }
  11855.                     if (isset($tag['attribute']['cellpadding'])) {
  11856.                         $cp $this->getHTMLUnitToUnits($tag['attribute']['cellpadding']1'px');
  11857.                         $this->oldcMargin $this->cMargin;
  11858.                         $this->cMargin $cp;
  11859.                     }
  11860.                     if (isset($tag['attribute']['cellspacing'])) {
  11861.                         $cs $this->getHTMLUnitToUnits($tag['attribute']['cellspacing']1'px');
  11862.                     }
  11863.                     $this->checkPageBreak(($cp($cs$this->lasth);
  11864.                     break;
  11865.                 }
  11866.                 case 'tr'{
  11867.                     // array of columns positions
  11868.                     $dom[$key]['cellpos'array();
  11869.                     break;
  11870.                 }
  11871.                 case 'hr'{
  11872.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  11873.                     $this->htmlvspace 0;
  11874.                     $wtmp $this->w $this->lMargin $this->rMargin;
  11875.                     if ((isset($tag['attribute']['width'])) AND ($tag['attribute']['width'!= '')) {
  11876.                         $hrWidth $this->getHTMLUnitToUnits($tag['attribute']['width']$wtmp'px');
  11877.                     else {
  11878.                         $hrWidth $wtmp;
  11879.                     }
  11880.                     $x $this->GetX();
  11881.                     $y $this->GetY();
  11882.                     $prevlinewidth $this->GetLineWidth();
  11883.                     $this->Line($x$y$x $hrWidth$y);
  11884.                     $this->SetLineWidth($prevlinewidth);
  11885.                     $this->addHTMLVertSpace(1$cell''!isset($dom[($key 1)])$tag['value']false);
  11886.                     break;
  11887.                 }
  11888.                 case 'a'{
  11889.                     if (array_key_exists('href'$tag['attribute'])) {
  11890.                         $this->HREF['url'$tag['attribute']['href'];
  11891.                     }
  11892.                     $this->HREF['color'$this->htmlLinkColorArray;
  11893.                     $this->HREF['style'$this->htmlLinkFontStyle;
  11894.                     if (array_key_exists('style'$tag['attribute'])) {
  11895.                         // get style attributes
  11896.                         preg_match_all('/([^;:\s]*):([^;]*)/'$tag['attribute']['style']$style_arrayPREG_PATTERN_ORDER);
  11897.                         $astyle array();
  11898.                         while (list($id$nameeach($style_array[1])) {
  11899.                             $name strtolower($name);
  11900.                             $astyle[$nametrim($style_array[2][$id]);
  11901.                         }
  11902.                         if (isset($astyle['color'])) {
  11903.                             $this->HREF['color'$this->convertHTMLColorToDec($astyle['color']);
  11904.                         }
  11905.                         if (isset($astyle['text-decoration'])) {
  11906.                             $this->HREF['style''';
  11907.                             $decors explode(' 'strtolower($astyle['text-decoration']));
  11908.                             foreach ($decors as $dec{
  11909.                                 $dec trim($dec);
  11910.                                 if (!$this->empty_string($dec)) {
  11911.                                     if ($dec{0== 'u'{
  11912.                                         $this->HREF['style'.= 'U';
  11913.                                     elseif ($dec{0== 'l'{
  11914.                                         $this->HREF['style'.= 'D';
  11915.                                     }
  11916.                                 }
  11917.                             }
  11918.                         }
  11919.                     }        
  11920.                     break;
  11921.                 }
  11922.                 case 'img'{
  11923.                     if (isset($tag['attribute']['src'])) {
  11924.                         // replace relative path with real server path
  11925.                         if ($tag['attribute']['src'][0== '/'{
  11926.                             $tag['attribute']['src'$_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
  11927.                         }
  11928.                         $tag['attribute']['src'urldecode($tag['attribute']['src']);
  11929.                         $tag['attribute']['src'str_replace(K_PATH_URLK_PATH_MAIN$tag['attribute']['src']);
  11930.                         if (!isset($tag['attribute']['width'])) {
  11931.                             $tag['attribute']['width'0;
  11932.                         }
  11933.                         if (!isset($tag['attribute']['height'])) {
  11934.                             $tag['attribute']['height'0;
  11935.                         }
  11936.                         //if (!isset($tag['attribute']['align'])) {
  11937.                             // the only alignment supported is "bottom"
  11938.                             // further development is required for other modes.
  11939.                             $tag['attribute']['align''bottom';
  11940.                         //} 
  11941.                         switch($tag['attribute']['align']{
  11942.                             case 'top'{
  11943.                                 $align 'T';
  11944.                                 break;
  11945.                             }
  11946.                             case 'middle'{
  11947.                                 $align 'M';
  11948.                                 break;
  11949.                             }
  11950.                             case 'bottom'{
  11951.                                 $align 'B';
  11952.                                 break;
  11953.                             }
  11954.                             default{
  11955.                                 $align 'B';
  11956.                                 break;
  11957.                             }
  11958.                         }
  11959.                         $fileinfo pathinfo($tag['attribute']['src']);
  11960.                         if (isset($fileinfo['extension']AND (!$this->empty_string($fileinfo['extension']))) {
  11961.                             $type strtolower($fileinfo['extension']);
  11962.                         }
  11963.                         $prevy $this->y;
  11964.                         $xpos $this->GetX();
  11965.                         if (isset($dom[($key 1)]AND ($dom[($key 1)]['value'== ' ')) {
  11966.                             if ($this->rtl{
  11967.                                 $xpos += $this->GetStringWidth(' ');
  11968.                             else {
  11969.                                 $xpos -= $this->GetStringWidth(' ');
  11970.                             }
  11971.                         }
  11972.                         $imglink '';
  11973.                         if (isset($this->HREF['url']AND !$this->empty_string($this->HREF['url'])) {
  11974.                             $imglink $this->HREF['url'];
  11975.                             if ($imglink{0== '#'{
  11976.                                 // convert url to internal link
  11977.                                 $page intval(substr($imglink1));
  11978.                                 $imglink $this->AddLink();
  11979.                                 $this->SetLink($imglink0$page);
  11980.                             }
  11981.                         }
  11982.                         $border 0;
  11983.                         if (isset($tag['attribute']['border']AND !empty($tag['attribute']['border'])) {
  11984.                             // currently only support 1 (frame) or a combination of 'LTRB'
  11985.                             $border $tag['attribute']['border'];
  11986.                         }
  11987.                         if (($type == 'eps'OR ($type == 'ai')) {
  11988.                             $this->ImageEps($tag['attribute']['src']$xpos$this->GetY()$this->pixelsToUnits($tag['attribute']['width'])$this->pixelsToUnits($tag['attribute']['height'])$imglinktrue$align''$border);
  11989.                         else {
  11990.                             $this->Image($tag['attribute']['src']$xpos$this->GetY()$this->pixelsToUnits($tag['attribute']['width'])$this->pixelsToUnits($tag['attribute']['height'])''$imglink$alignfalse300''falsefalse$border);
  11991.                         }
  11992.                         switch($align{
  11993.                             case 'T'{
  11994.                                 $this->y $prevy;
  11995.                                 break;
  11996.                             }
  11997.                             case 'M'{
  11998.                                 $this->y (($this->img_rb_y $prevy ($tag['fontsize'$this->k)) 2;
  11999.                                 break;
  12000.                             }
  12001.                             case 'B'{
  12002.                                 $this->y $this->img_rb_y ($tag['fontsize'$this->k);
  12003.                                 break;
  12004.                             }
  12005.                         }
  12006.                     }
  12007.                     break;
  12008.                 }
  12009.                 case 'dl'{
  12010.                     ++$this->listnum;
  12011.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  12012.                     break;
  12013.                 }
  12014.                 case 'dt'{
  12015.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  12016.                     break;
  12017.                 }
  12018.                 case 'dd'{
  12019.                     if ($this->rtl{
  12020.                         $this->rMargin += $this->listindent;
  12021.                     else {
  12022.                         $this->lMargin += $this->listindent;
  12023.                     }
  12024.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  12025.                     break;
  12026.                 }
  12027.                 case 'ul':
  12028.                 case 'ol'{
  12029.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  12030.                     $this->htmlvspace 0;
  12031.                     ++$this->listnum;
  12032.                     if ($tag['value'== 'ol'{
  12033.                         $this->listordered[$this->listnumtrue;
  12034.                     else {
  12035.                         $this->listordered[$this->listnumfalse;
  12036.                     }
  12037.                     if (isset($tag['attribute']['start'])) {
  12038.                         $this->listcount[$this->listnumintval($tag['attribute']['start']1;
  12039.                     else {
  12040.                         $this->listcount[$this->listnum0;
  12041.                     }
  12042.                     if ($this->rtl{
  12043.                         $this->rMargin += $this->listindent;
  12044.                     else {
  12045.                         $this->lMargin += $this->listindent;
  12046.                     }
  12047.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']false);
  12048.                     $this->htmlvspace 0;
  12049.                     break;
  12050.                 }
  12051.                 case 'li'{
  12052.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  12053.                     if ($this->listordered[$this->listnum]{
  12054.                         // ordered item
  12055.                         if (isset($parent['attribute']['type']AND !$this->empty_string($parent['attribute']['type'])) {
  12056.                             $this->lispacer $parent['attribute']['type'];
  12057.                         elseif (isset($parent['listtype']AND !$this->empty_string($parent['listtype'])) {
  12058.                             $this->lispacer $parent['listtype'];
  12059.                         elseif (isset($this->lisymbolAND !$this->empty_string($this->lisymbol)) {
  12060.                             $this->lispacer $this->lisymbol;
  12061.                         else {
  12062.                             $this->lispacer '#';
  12063.                         }
  12064.                         ++$this->listcount[$this->listnum];
  12065.                         if (isset($tag['attribute']['value'])) {
  12066.                             $this->listcount[$this->listnumintval($tag['attribute']['value']);
  12067.                         }
  12068.                     else {
  12069.                         // unordered item
  12070.                         if (isset($parent['attribute']['type']AND !$this->empty_string($parent['attribute']['type'])) {
  12071.                             $this->lispacer $parent['attribute']['type'];
  12072.                         elseif (isset($parent['listtype']AND !$this->empty_string($parent['listtype'])) {
  12073.                             $this->lispacer $parent['listtype'];
  12074.                         elseif (isset($this->lisymbolAND !$this->empty_string($this->lisymbol)) {
  12075.                             $this->lispacer $this->lisymbol;
  12076.                         else {
  12077.                             $this->lispacer '!';
  12078.                         }
  12079.                     }
  12080.                     break;
  12081.                 }
  12082.                 case 'blockquote'{
  12083.                     if ($this->rtl{
  12084.                         $this->rMargin += $this->listindent;
  12085.                     else {
  12086.                         $this->lMargin += $this->listindent;
  12087.                     }
  12088.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']false);
  12089.                     break;
  12090.                 }
  12091.                 case 'br'{
  12092.                     $this->Ln(''$cell);
  12093.                     break;
  12094.                 }
  12095.                 case 'div'{
  12096.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  12097.                     break;
  12098.                 }
  12099.                 case 'p'{
  12100.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']false);
  12101.                     break;
  12102.                 }
  12103.                 case 'pre'{
  12104.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']false);
  12105.                     $this->premode true;
  12106.                     break;
  12107.                 }
  12108.                 case 'sup'{
  12109.                     $this->SetXY($this->GetX()$this->GetY(((0.7 $this->FontSizePt$this->k));
  12110.                     break;
  12111.                 }
  12112.                 case 'sub'{
  12113.                     $this->SetXY($this->GetX()$this->GetY(((0.3 $this->FontSizePt$this->k));
  12114.                     break;
  12115.                 }
  12116.                 case 'h1'
  12117.                 case 'h2'
  12118.                 case 'h3'
  12119.                 case 'h4'
  12120.                 case 'h5'
  12121.                 case 'h6'{
  12122.                     $this->addHTMLVertSpace(1$cell($tag['fontsize'1.5$this->k$firstorlast$tag['value']false);
  12123.                     break;
  12124.                 }
  12125.                 case 'tcpdf'{
  12126.                     // NOT HTML: used to call TCPDF methods
  12127.                     if (isset($tag['attribute']['method'])) {
  12128.                         $tcpdf_method $tag['attribute']['method'];
  12129.                         if (method_exists($this$tcpdf_method)) {
  12130.                             if (isset($tag['attribute']['params']AND (!empty($tag['attribute']['params']))) {
  12131.                                 eval('$params = array('.$tag['attribute']['params'].');');
  12132.                                 call_user_func_array(array($this$tcpdf_method)$params);
  12133.                             else {
  12134.                                 $this->$tcpdf_method();
  12135.                             }
  12136.                             $this->newline true;
  12137.                         }
  12138.                     }
  12139.                 }
  12140.                 default{
  12141.                     break;
  12142.                 }
  12143.             }
  12144.         }
  12145.         
  12146.         /**
  12147.          * Process closing tags.
  12148.          * @param array $dom html dom array
  12149.          * @param int $key current element id
  12150.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  12151.          * @access protected
  12152.          */
  12153.         protected function closeHTMLTagHandler(&$dom$key$cell=false{
  12154.             $tag $dom[$key];
  12155.             $parent $dom[($dom[$key]['parent'])];
  12156.             $firstorlast ((!isset($dom[($key 1)])) OR ((!isset($dom[($key 2)])) AND ($dom[($key 1)]['value'== 'marker')));
  12157.             //Closing tag
  12158.             switch($tag['value']{
  12159.                 case 'tr'{
  12160.                     $table_el $dom[($dom[$key]['parent'])]['parent'];
  12161.                     if(!isset($parent['endy'])) {
  12162.                         $dom[($dom[$key]['parent'])]['endy'$this->y;
  12163.                         $parent['endy'$this->y;
  12164.                     }
  12165.                     if(!isset($parent['endpage'])) {
  12166.                         $dom[($dom[$key]['parent'])]['endpage'$this->page;
  12167.                         $parent['endpage'$this->page;
  12168.                     }
  12169.                     // update row-spanned cells
  12170.                     if (isset($dom[$table_el]['rowspans'])) {
  12171.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  12172.                             $dom[$table_el]['rowspans'][$k]['rowspan'-= 1;
  12173.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  12174.                                 if ($dom[$table_el]['rowspans'][$k]['endpage'== $parent['endpage']{
  12175.                                     $dom[($dom[$key]['parent'])]['endy'max($dom[$table_el]['rowspans'][$k]['endy']$parent['endy']);
  12176.                                 elseif ($dom[$table_el]['rowspans'][$k]['endpage'$parent['endpage']{
  12177.                                     $dom[($dom[$key]['parent'])]['endy'$dom[$table_el]['rowspans'][$k]['endy'];
  12178.                                     $dom[($dom[$key]['parent'])]['endpage'$dom[$table_el]['rowspans'][$k]['endpage'];
  12179.                                 }
  12180.                             }
  12181.                         }
  12182.                         // report new endy and endpage to the rowspanned cells
  12183.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  12184.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  12185.                                 $dom[$table_el]['rowspans'][$k]['endpage'max($dom[$table_el]['rowspans'][$k]['endpage']$dom[($dom[$key]['parent'])]['endpage']);
  12186.                                 $dom[($dom[$key]['parent'])]['endpage'$dom[$table_el]['rowspans'][$k]['endpage'];
  12187.                                 $dom[$table_el]['rowspans'][$k]['endy'max($dom[$table_el]['rowspans'][$k]['endy']$dom[($dom[$key]['parent'])]['endy']);
  12188.                                 $dom[($dom[$key]['parent'])]['endy'$dom[$table_el]['rowspans'][$k]['endy'];
  12189.                             }
  12190.                         }
  12191.                         // update remaining rowspanned cells
  12192.                         foreach ($dom[$table_el]['rowspans'as $k => $trwsp{
  12193.                             if ($dom[$table_el]['rowspans'][$k]['rowspan'== 0{
  12194.                                 $dom[$table_el]['rowspans'][$k]['endpage'$dom[($dom[$key]['parent'])]['endpage'];
  12195.                                 $dom[$table_el]['rowspans'][$k]['endy'$dom[($dom[$key]['parent'])]['endy'];
  12196.                             }
  12197.                         }
  12198.                     }
  12199.                     $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  12200.                     $this->y $dom[($dom[$key]['parent'])]['endy'];                    
  12201.                     if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  12202.                         $cellspacing $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing']1'px');
  12203.                         $this->y += $cellspacing;
  12204.                     }                
  12205.                     $this->Ln(0$cell);
  12206.                     $this->x $parent['startx'];
  12207.                     // account for booklet mode
  12208.                     if ($this->page $parent['startpage']{
  12209.                         if (($this->rtlAND ($this->pagedim[$this->page]['orm'!= $this->pagedim[$parent['startpage']]['orm'])) {
  12210.                             $this->x += ($this->pagedim[$this->page]['orm'$this->pagedim[$parent['startpage']]['orm']);
  12211.                         elseif ((!$this->rtlAND ($this->pagedim[$this->page]['olm'!= $this->pagedim[$parent['startpage']]['olm'])) {
  12212.                             $this->x += ($this->pagedim[$this->page]['olm'$this->pagedim[$parent['startpage']]['olm']);
  12213.                         }
  12214.                     }
  12215.                     break;
  12216.                 }
  12217.                 case 'table'{
  12218.                     // draw borders
  12219.                     $table_el $parent;
  12220.                     if ((isset($table_el['attribute']['border']AND ($table_el['attribute']['border'0)) 
  12221.                         OR (isset($table_el['style']['border']AND ($table_el['style']['border'0))) {
  12222.                             $border 1;
  12223.                     else {
  12224.                         $border 0;
  12225.                     }
  12226.                     // fix bottom line alignment of last line before page break
  12227.                     foreach ($dom[($dom[$key]['parent'])]['trids'as $j => $trkey{
  12228.                         // update row-spanned cells
  12229.                         if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  12230.                             foreach ($dom[($dom[$key]['parent'])]['rowspans'as $k => $trwsp{
  12231.                                 if ($trwsp['trid'== $trkey{
  12232.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'-= 1;
  12233.                                 }
  12234.                                 if (isset($prevtrkeyAND ($trwsp['trid'== $prevtrkeyAND ($trwsp['mrowspan'>= 0)) {
  12235.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'$trkey;
  12236.                                 }
  12237.                             }
  12238.                         }
  12239.                         if (isset($prevtrkeyAND ($dom[$trkey]['startpage'$dom[$prevtrkey]['endpage'])) {
  12240.                             $pgendy $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'$this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  12241.                             $dom[$prevtrkey]['endy'$pgendy;
  12242.                             // update row-spanned cells
  12243.                             if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  12244.                                 foreach ($dom[($dom[$key]['parent'])]['rowspans'as $k => $trwsp{
  12245.                                     if (($trwsp['trid'== $trkeyAND ($trwsp['mrowspan'== 1AND ($trwsp['endpage'== $dom[$prevtrkey]['endpage'])) {
  12246.                                         $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'$pgendy;
  12247.                                         $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'= -1;
  12248.                                     }
  12249.                                 }
  12250.                             }
  12251.                         }
  12252.                         $prevtrkey $trkey;
  12253.                         $table_el $dom[($dom[$key]['parent'])];
  12254.                     }
  12255.                     // for each row
  12256.                     foreach ($table_el['trids'as $j => $trkey{
  12257.                         $parent $dom[$trkey];
  12258.                         // for each cell on the row
  12259.                         foreach ($parent['cellpos'as $k => $cellpos{
  12260.                             if (isset($cellpos['rowspanid']AND ($cellpos['rowspanid'>= 0)) {
  12261.                                 $cellpos['startx'$table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  12262.                                 $cellpos['endx'$table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  12263.                                 $endy $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  12264.                                 $startpage $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  12265.                                 $endpage $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  12266.                             else {
  12267.                                 $endy $parent['endy'];
  12268.                                 $startpage $parent['startpage'];
  12269.                                 $endpage $parent['endpage'];
  12270.                             }
  12271.                             if ($endpage $startpage{
  12272.                                 // design borders around HTML cells.
  12273.                                 for ($page=$startpage$page <= $endpage++$page{
  12274.                                     $this->setPage($page);
  12275.                                     if ($page == $startpage{
  12276.                                         $this->y $parent['starty']// put cursor at the beginning of row on the first page
  12277.                                         $ch $this->getPageHeight($parent['starty'$this->getBreakMargin();
  12278.                                         $cborder $this->getBorderMode($border$position='start');
  12279.                                     elseif ($page == $endpage{
  12280.                                         $this->y $this->tMargin// put cursor at the beginning of last page
  12281.                                         $ch $endy $this->tMargin;
  12282.                                         $cborder $this->getBorderMode($border$position='end');
  12283.                                     else {
  12284.                                         $this->y $this->tMargin// put cursor at the beginning of the current page
  12285.                                         $ch $this->getPageHeight($this->tMargin $this->getBreakMargin();
  12286.                                         $cborder $this->getBorderMode($border$position='middle');
  12287.                                     }
  12288.                                     if (isset($cellpos['bgcolor']AND ($cellpos['bgcolor']!== false{
  12289.                                         $this->SetFillColorArray($cellpos['bgcolor']);
  12290.                                         $fill true;
  12291.                                     else {
  12292.                                         $fill false;
  12293.                                     }
  12294.                                     $cw abs($cellpos['endx'$cellpos['startx']);
  12295.                                     $this->x $cellpos['startx'];
  12296.                                     // account for margin changes
  12297.                                     if ($page $startpage{
  12298.                                         if (($this->rtlAND ($this->pagedim[$page]['orm'!= $this->pagedim[$startpage]['orm'])) {
  12299.                                             $this->x -= ($this->pagedim[$page]['orm'$this->pagedim[$startpage]['orm']);
  12300.                                         elseif ((!$this->rtlAND ($this->pagedim[$page]['lm'!= $this->pagedim[$startpage]['olm'])) {
  12301.                                             $this->x += ($this->pagedim[$page]['olm'$this->pagedim[$startpage]['olm']);
  12302.                                         }
  12303.                                     }
  12304.                                     // design a cell around the text
  12305.                                     $ccode $this->FillColor."\n".$this->getCellCode($cw$ch''$cborder1''$fill''0true);
  12306.                                     if ($cborder OR $fill{
  12307.                                         $pagebuff $this->getPageBuffer($this->page);
  12308.                                         $pstart substr($pagebuff0$this->intmrk[$this->page]);
  12309.                                         $pend substr($pagebuff$this->intmrk[$this->page]);
  12310.                                         $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  12311.                                         $this->intmrk[$this->page+= strlen($ccode."\n");
  12312.                                     }
  12313.                                 }
  12314.                             else {
  12315.                                 $this->setPage($startpage);
  12316.                                 if (isset($cellpos['bgcolor']AND ($cellpos['bgcolor']!== false{
  12317.                                     $this->SetFillColorArray($cellpos['bgcolor']);
  12318.                                     $fill true;
  12319.                                 else {
  12320.                                     $fill false;
  12321.                                 }
  12322.                                 $this->x $cellpos['startx'];
  12323.                                 $this->y $parent['starty'];
  12324.                                 $cw abs($cellpos['endx'$cellpos['startx']);
  12325.                                 $ch $endy $parent['starty'];
  12326.                                 // design a cell around the text
  12327.                                 $ccode $this->FillColor."\n".$this->getCellCode($cw$ch''$border1''$fill''0true);
  12328.                                 if ($border OR $fill{
  12329.                                     if (end($this->transfmrk[$this->page]!== false{
  12330.                                         $pagemarkkey key($this->transfmrk[$this->page]);
  12331.                                         $pagemark &$this->transfmrk[$this->page][$pagemarkkey];
  12332.                                     elseif ($this->InFooter{
  12333.                                         $pagemark &$this->footerpos[$this->page];
  12334.                                     else {
  12335.                                         $pagemark &$this->intmrk[$this->page];
  12336.                                     }
  12337.                                     $pagebuff $this->getPageBuffer($this->page);
  12338.                                     $pstart substr($pagebuff0$pagemark);
  12339.                                     $pend substr($pagebuff$pagemark);
  12340.                                     $this->setPageBuffer($this->page$pstart.$ccode."\n".$pend);
  12341.                                     $pagemark += strlen($ccode."\n");
  12342.                                 }                    
  12343.                             }
  12344.                         }                    
  12345.                         if (isset($table_el['attribute']['cellspacing'])) {
  12346.                             $cellspacing $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing']1'px');
  12347.                             $this->y += $cellspacing;
  12348.                         }                
  12349.                         $this->Ln(0$cell);
  12350.                         $this->x $parent['startx'];
  12351.                         if ($endpage $startpage{
  12352.                             if (($this->rtlAND ($this->pagedim[$endpage]['orm'!= $this->pagedim[$startpage]['orm'])) {
  12353.                                 $this->x += ($this->pagedim[$endpage]['orm'$this->pagedim[$startpage]['orm']);
  12354.                             elseif ((!$this->rtlAND ($this->pagedim[$endpage]['olm'!= $this->pagedim[$startpage]['olm'])) {
  12355.                                 $this->x += ($this->pagedim[$endpage]['olm'$this->pagedim[$startpage]['olm']);
  12356.                             }
  12357.                         }
  12358.                     }
  12359.                     if (isset($parent['cellpadding'])) {
  12360.                         $this->cMargin $this->oldcMargin;
  12361.                     }
  12362.                     $this->lasth $this->FontSize $this->cell_height_ratio;
  12363.                     if (!$this->empty_string($table_el['thead']AND !$this->empty_string($this->theadMargin)) {
  12364.                         // reset table header
  12365.                         $this->thead '';
  12366.                         // restore top margin
  12367.                         $this->tMargin $this->theadMargin;
  12368.                         $this->pagedim[$this->page]['tm'$this->theadMargin;
  12369.                         $this->theadMargin '';
  12370.                     }
  12371.                     break;
  12372.                 }
  12373.                 case 'a'{
  12374.                     $this->HREF '';
  12375.                     break;
  12376.                 }
  12377.                 case 'sup'{
  12378.                     $this->SetXY($this->GetX()$this->GetY(((0.7 $parent['fontsize']$this->k));
  12379.                     break;
  12380.                 }
  12381.                 case 'sub'{
  12382.                     $this->SetXY($this->GetX()$this->GetY(((0.3 $parent['fontsize'])/$this->k));
  12383.                     break;
  12384.                 }
  12385.                 case 'div'{
  12386.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']true);
  12387.                     break;
  12388.                 }
  12389.                 case 'blockquote'{
  12390.                     if ($this->rtl{
  12391.                         $this->rMargin -= $this->listindent;
  12392.                     else {
  12393.                         $this->lMargin -= $this->listindent;
  12394.                     }
  12395.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  12396.                     break;
  12397.                 }
  12398.                 case 'p'{
  12399.                     $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  12400.                     break;
  12401.                 }
  12402.                 case 'pre'{
  12403.                     $this->addHTMLVertSpace(1$cell''$firstorlast$tag['value']true);
  12404.                     $this->premode false;
  12405.                     break;
  12406.                 }
  12407.                 case 'dl'{
  12408.                     --$this->listnum;
  12409.                     if ($this->listnum <= 0{
  12410.                         $this->listnum 0;
  12411.                         $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  12412.                     }
  12413.                     break;
  12414.                 }
  12415.                 case 'dt'{
  12416.                     $this->lispacer '';
  12417.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  12418.                     break;
  12419.                 }
  12420.                 case 'dd'{
  12421.                     $this->lispacer '';
  12422.                     if ($this->rtl{
  12423.                         $this->rMargin -= $this->listindent;
  12424.                     else {
  12425.                         $this->lMargin -= $this->listindent;
  12426.                     }
  12427.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  12428.                     break;
  12429.                 }
  12430.                 case 'ul':
  12431.                 case 'ol'{
  12432.                     --$this->listnum;
  12433.                     $this->lispacer '';
  12434.                     if ($this->rtl{
  12435.                         $this->rMargin -= $this->listindent;
  12436.                     else {
  12437.                         $this->lMargin -= $this->listindent;
  12438.                     }
  12439.                     if ($this->listnum <= 0{
  12440.                         $this->listnum 0;
  12441.                         $this->addHTMLVertSpace(2$cell''$firstorlast$tag['value']true);
  12442.                     }
  12443.                     $this->lasth $this->FontSize $this->cell_height_ratio;
  12444.                     break;
  12445.                 }
  12446.                 case 'li'{
  12447.                     $this->lispacer '';
  12448.                     $this->addHTMLVertSpace(0$cell''$firstorlast$tag['value']true);
  12449.                     break;
  12450.                 }
  12451.                 case 'h1'
  12452.                 case 'h2'
  12453.                 case 'h3'
  12454.                 case 'h4'
  12455.                 case 'h5'
  12456.                 case 'h6'{
  12457.                     $this->addHTMLVertSpace(1$cell($parent['fontsize'1.5$this->k$firstorlast$tag['value']true);
  12458.                     break;
  12459.                 }
  12460.                 default {
  12461.                     break;
  12462.                 }
  12463.             }
  12464.             $this->tmprtl false;
  12465.         }
  12466.         
  12467.         /**
  12468.          * Add vertical spaces if needed.
  12469.          * @param int $n number of spaces to add
  12470.          * @param boolean $cell if true add the default cMargin space to each new line (default false).
  12471.          * @param string $h The height of the break. By default, the value equals the height of the last printed cell.
  12472.          * @param boolean $firstorlast if true do not print additional empty lines.
  12473.          * @param string $tag HTML tag to which this space will be applied
  12474.          * @param boolean $closing true if this space will be applied to a closing tag, false otherwise
  12475.          * @access protected
  12476.          */
  12477.         protected function addHTMLVertSpace($n$cell=false$h=''$firstorlast=false$tag=''$closing=false{
  12478.             if ($firstorlast{
  12479.                 $this->Ln(0$cell);
  12480.                 $this->htmlvspace 0;
  12481.                 return;
  12482.             }
  12483.             if (isset($this->tagvspaces[$tag][intval($closing)]['n'])) {
  12484.                 $n $this->tagvspaces[$tag][intval($closing)]['n'];
  12485.             }
  12486.             if (isset($this->tagvspaces[$tag][intval($closing)]['h'])) {
  12487.                 $h $this->tagvspaces[$tag][intval($closing)]['h'];
  12488.             }
  12489.             if (is_string($h)) {
  12490.                 $vsize $n $this->lasth;
  12491.             else {
  12492.                 $vsize $n $h;
  12493.             }
  12494.             if ($vsize $this->htmlvspace{
  12495.                 $this->Ln(($vsize $this->htmlvspace)$cell);
  12496.                 $this->htmlvspace $vsize;
  12497.             }
  12498.         }
  12499.         
  12500.         /**
  12501.          * Set the default bullet to be used as LI bullet symbol
  12502.          * @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')
  12503.          * @access public
  12504.          * @since 4.0.028 (2008-09-26)
  12505.          */
  12506.         public function setLIsymbol($symbol='!'{
  12507.             $symbol strtolower($symbol);
  12508.             switch ($symbol{
  12509.                 case '!' :
  12510.                 case '#' :
  12511.                 case 'disc' :
  12512.                 case 'disc' :
  12513.                 case 'circle' :
  12514.                 case 'square' :
  12515.                 case '1':
  12516.                 case 'decimal':
  12517.                 case 'decimal-leading-zero':
  12518.                 case 'i':
  12519.                 case 'lower-roman':
  12520.                 case 'I':
  12521.                 case 'upper-roman':
  12522.                 case 'a':
  12523.                 case 'lower-alpha':
  12524.                 case 'lower-latin':
  12525.                 case 'A':
  12526.                 case 'upper-alpha':
  12527.                 case 'upper-latin':
  12528.                 case 'lower-greek'{
  12529.                     $this->lisymbol $symbol;
  12530.                     break;
  12531.                 }
  12532.                 default {
  12533.                     $this->lisymbol '';
  12534.                 }
  12535.             }
  12536.         }
  12537.         
  12538.         /**
  12539.         * Set the booklet mode for double-sided pages.
  12540.         * @param boolean $booklet true set the booklet mode on, fals eotherwise.
  12541.         * @param float $inner Inner page margin.
  12542.         * @param float $outer Outer page margin.
  12543.         * @access public
  12544.         * @since 4.2.000 (2008-10-29)
  12545.         */
  12546.         public function SetBooklet($booklet=true$inner=-1$outer=-1{
  12547.             $this->booklet $booklet;
  12548.             if ($inner >= 0{
  12549.                 $this->lMargin $inner;
  12550.             }
  12551.             if ($outer >= 0{
  12552.                 $this->rMargin $outer;
  12553.             }
  12554.         }
  12555.         
  12556.         /**
  12557.         * Swap the left and right margins.
  12558.         * @param boolean $reverse if true swap left and right margins.
  12559.         * @access protected
  12560.         * @since 4.2.000 (2008-10-29)
  12561.         */
  12562.         protected function swapMargins($reverse=true{
  12563.             if ($reverse{
  12564.                 // swap left and right margins
  12565.                 $mtemp $this->original_lMargin;
  12566.                 $this->original_lMargin $this->original_rMargin;
  12567.                 $this->original_rMargin $mtemp;
  12568.                 $deltam $this->original_lMargin $this->original_rMargin;
  12569.                 $this->lMargin += $deltam;
  12570.                 $this->rMargin -= $deltam;
  12571.             }
  12572.         }
  12573.  
  12574.         /**
  12575.         * Set the vertical spaces for HTML tags.
  12576.         * The array must have the following structure (example):
  12577.         * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  12578.         * The first array level contains the tag names,
  12579.         * the second level contains 0 for opening tags or 1 for closing tags,
  12580.         * the third level contains the vertical space unit (h) and the number spaces to add (n).
  12581.         * If the h parameter is not specified, default values are used.
  12582.         * @param array $tagvs array of tags and relative vertical spaces.
  12583.         * @access public
  12584.         * @since 4.2.001 (2008-10-30)
  12585.         */
  12586.         public function setHtmlVSpace($tagvs{
  12587.             $this->tagvspaces $tagvs;
  12588.         }
  12589.  
  12590.         /**
  12591.         * Set custom width for list indentation.
  12592.         * @param float $width width of the indentation. Use negative value to disable it.
  12593.         * @access public
  12594.         * @since 4.2.007 (2008-11-12)
  12595.         */
  12596.         public function setListIndentWidth($width{
  12597.             return $this->customlistindent floatval($width);
  12598.         }
  12599.  
  12600.         /**
  12601.         * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  12602.         * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  12603.         * @access public
  12604.         * @since 4.2.010 (2008-11-14)
  12605.         */
  12606.         public function setOpenCell($isopen{
  12607.             $this->opencell $isopen;
  12608.         }
  12609.  
  12610.         /**
  12611.         * Set the color and font style for HTML links.
  12612.         * @param array $color RGB array of colors
  12613.         * @param string $fontstyle additional font styles to add
  12614.         * @access public
  12615.         * @since 4.4.003 (2008-12-09)
  12616.         */
  12617.         public function setHtmlLinksStyle($color=array(0,0,255)$fontstyle='U'{
  12618.             $this->htmlLinkColorArray $color;
  12619.             $this->htmlLinkFontStyle $fontstyle;
  12620.         }
  12621.  
  12622.         /**
  12623.         * convert html string containing value and unit of measure to user's units or points.
  12624.         * @param string $htmlval string containing values and unit
  12625.         * @param string $refsize reference value in points
  12626.         * @param string $defaultunit default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  12627.         * @param boolean $point if true returns points, otherwise returns value in user's units
  12628.         * @return float value in user's unit or point if $points=true
  12629.         * @access public
  12630.         * @since 4.4.004 (2008-12-10)
  12631.         */
  12632.         public function getHTMLUnitToUnits($htmlval$refsize=1$defaultunit='px'$points=false{
  12633.             $supportedunits array('%''em''ex''px''in''cm''mm''pc''pt');
  12634.             $retval 0;
  12635.             $value 0;
  12636.             $unit 'px';
  12637.             $k $this->k;
  12638.             if ($points{
  12639.                 $k 1;
  12640.             }
  12641.             if (in_array($defaultunit$supportedunits)) {
  12642.                 $unit $defaultunit;
  12643.             }
  12644.             if (is_numeric($htmlval)) {
  12645.                 $value floatval($htmlval);
  12646.             elseif (preg_match('/([0-9\.]+)/'$htmlval$mnum)) {
  12647.                 $value floatval($mnum[1]);
  12648.                 if (preg_match('/([a-z%]+)/'$htmlval$munit)) {
  12649.                     if (in_array($munit[1]$supportedunits)) {
  12650.                         $unit $munit[1];
  12651.                     }
  12652.                 }
  12653.             }
  12654.             switch ($unit{
  12655.                 // percentage
  12656.                 case '%'{
  12657.                     $retval (($value $refsize100);
  12658.                     break;
  12659.                 }
  12660.                 // relative-size
  12661.                 case 'em'{
  12662.                     $retval ($value $refsize);
  12663.                     break;
  12664.                 }
  12665.                 case 'ex'{
  12666.                     $retval $value ($refsize 2);
  12667.                     break;
  12668.                 }
  12669.                 // absolute-size
  12670.                 case 'in'{
  12671.                     $retval ($value $this->dpi$k;
  12672.                     break;
  12673.                 }
  12674.                 case 'cm'{
  12675.                     $retval ($value 2.54 $this->dpi$k;
  12676.                     break;
  12677.                 }
  12678.                 case 'mm'{
  12679.                     $retval ($value 25.4 $this->dpi$k;
  12680.                     break;
  12681.                 }
  12682.                 case 'pc'{
  12683.                     // one pica is 12 points
  12684.                     $retval ($value 12$k;
  12685.                     break;
  12686.                 }
  12687.                 case 'px':
  12688.                 case 'pt'{
  12689.                     $retval $value $k;
  12690.                     break;
  12691.                 }
  12692.             }
  12693.             return $retval;
  12694.         }
  12695.  
  12696.         /**
  12697.         * Returns the Roman representation of an integer number
  12698.         * @param int number to convert
  12699.         * @return string roman representation of the specified number
  12700.         * @access public
  12701.         * @since 4.4.004 (2008-12-10)
  12702.         */
  12703.         public function intToRoman($number{
  12704.             $roman '';
  12705.             while ($number >= 1000{
  12706.                 $roman .= 'M';
  12707.                 $number -= 1000;
  12708.             }
  12709.             while ($number >= 900{
  12710.                 $roman .= 'CM';
  12711.                 $number -= 900;
  12712.             }
  12713.             while ($number >= 500{
  12714.                 $roman .= 'D';
  12715.                 $number -= 500;
  12716.             }
  12717.             while ($number >= 400{
  12718.                 $roman .= 'CD';
  12719.                 $number -= 400;
  12720.             }
  12721.             while ($number >= 100{
  12722.                 $roman .= 'C';
  12723.                 $number -= 100;
  12724.             }
  12725.             while ($number >= 90{
  12726.             $roman .= 'XC';
  12727.             $number -= 90;
  12728.             }
  12729.             while ($number >= 50{
  12730.                 $roman .= 'L';
  12731.                 $number -= 50;
  12732.             }
  12733.             while ($number >= 40{
  12734.                 $roman .= 'XL';
  12735.                 $number -= 40;
  12736.             }
  12737.             while ($number >= 10{
  12738.             $roman .= 'X';
  12739.             $number -= 10;
  12740.             }
  12741.             while ($number >= 9{
  12742.                 $roman .= 'IX';
  12743.                 $number -= 9;
  12744.             }
  12745.             while ($number >= 5{
  12746.                 $roman .= 'V';
  12747.                 $number -= 5;
  12748.             }
  12749.             while ($number >= 4{
  12750.             $roman .= 'IV';
  12751.             $number -= 4;
  12752.             }
  12753.             while ($number >= 1{
  12754.                 $roman .= 'I';
  12755.                 --$number;
  12756.             }
  12757.             return $roman;
  12758.         }
  12759.  
  12760.         /**
  12761.         * Output an HTML list bullet or ordered item symbol
  12762.         * @param int $listdepth list nesting level
  12763.         * @param string $listtype type of list
  12764.         * @param float $size current font size
  12765.         * @access protected
  12766.         * @since 4.4.004 (2008-12-10)
  12767.         */
  12768.         protected function putHtmlListBullet($listdepth$listtype=''$size=10{
  12769.             $size /= $this->k;
  12770.             $fill '';
  12771.             $color $this->fgcolor;
  12772.             $width 0;
  12773.             $textitem '';
  12774.             $tmpx $this->x;        
  12775.             $lspace $this->GetStringWidth('  ');
  12776.             if ($listtype == '!'{
  12777.                 // set default list type for unordered list
  12778.                 $deftypes array('disc''circle''square');
  12779.                 $listtype $deftypes[($listdepth 13];
  12780.             elseif ($listtype == '#'{
  12781.                 // set default list type for ordered list
  12782.                 $listtype 'decimal';
  12783.             }
  12784.             switch ($listtype{
  12785.                 // unordered types
  12786.                 case 'none'{
  12787.                     break;
  12788.                 }
  12789.                 case 'disc'{
  12790.                     $fill 'F';
  12791.                 }
  12792.                 case 'circle'{
  12793.                     $fill .= 'D';
  12794.                     $r $size 6;
  12795.                     $lspace += ($r);
  12796.                     if ($this->rtl{
  12797.                         $this->x += $lspace;
  12798.                     else {
  12799.                         $this->x -= $lspace;
  12800.                     }
  12801.                     $this->Circle(($this->x $r)($this->y ($this->lasth 2))$r0360$fillarray('color'=>$color)$color8);
  12802.                     break;
  12803.                 }
  12804.                 case 'square'{
  12805.                     $l $size 3;
  12806.                     $lspace += $l;
  12807.                     if ($this->rtl{
  12808.                         $this->x += $lspace;
  12809.                     else {
  12810.                         $this->x -= $lspace;
  12811.                     }
  12812.                     $this->Rect($this->x($this->y (($this->lasth $l)2))$l$l'F'array()$color);
  12813.                     break;
  12814.                 }
  12815.                 // ordered types
  12816.  
  12817.                 // $this->listcount[$this->listnum];
  12818.                 // $textitem
  12819.                 case '1':
  12820.                 case 'decimal'{
  12821.                     $textitem $this->listcount[$this->listnum];
  12822.                     break;
  12823.                 }
  12824.                 case 'decimal-leading-zero'{
  12825.                     $textitem sprintf("%02d"$this->listcount[$this->listnum]);
  12826.                     break;
  12827.                 }
  12828.                 case 'i':
  12829.                 case 'lower-roman'{
  12830.                     $textitem strtolower($this->intToRoman($this->listcount[$this->listnum]));
  12831.                     break;
  12832.                 }
  12833.                 case 'I':
  12834.                 case 'upper-roman'{
  12835.                     $textitem $this->intToRoman($this->listcount[$this->listnum]);
  12836.                     break;
  12837.                 }
  12838.                 case 'a':
  12839.                 case 'lower-alpha':
  12840.                 case 'lower-latin'{
  12841.                     $textitem chr(97 $this->listcount[$this->listnum1);
  12842.                     break;
  12843.                 }
  12844.                 case 'A':
  12845.                 case 'upper-alpha':
  12846.                 case 'upper-latin'{
  12847.                     $textitem chr(65 $this->listcount[$this->listnum1);
  12848.                     break;
  12849.                 }
  12850.                 case 'lower-greek'{
  12851.                     $textitem $this->unichr(945 $this->listcount[$this->listnum1);
  12852.                     break;
  12853.                 }
  12854.                 /*
  12855.                 // Types to be implemented (special handling)
  12856.                 case 'hebrew': {
  12857.                     break;
  12858.                 }
  12859.                 case 'armenian': {
  12860.                     break;
  12861.                 }
  12862.                 case 'georgian': {
  12863.                     break;
  12864.                 }
  12865.                 case 'cjk-ideographic': {
  12866.                     break;
  12867.                 }
  12868.                 case 'hiragana': {
  12869.                     break;
  12870.                 }
  12871.                 case 'katakana': {
  12872.                     break;
  12873.                 }
  12874.                 case 'hiragana-iroha': {
  12875.                     break;
  12876.                 }
  12877.                 case 'katakana-iroha': {
  12878.                     break;
  12879.                 }
  12880.                 */
  12881.                 default{
  12882.                     $textitem $this->listcount[$this->listnum];
  12883.                 }
  12884.             }
  12885.             if (!$this->empty_string($textitem)) {
  12886.                 // print ordered item
  12887.                 if ($this->rtl{
  12888.                     $textitem '.'.$textitem;
  12889.                 else {
  12890.                     $textitem $textitem.'.';
  12891.                 }
  12892.                 $lspace += $this->GetStringWidth($textitem);
  12893.                 if ($this->rtl{
  12894.                     $this->x += $lspace;
  12895.                 else {
  12896.                     $this->x -= $lspace;
  12897.                 }
  12898.                 $this->Write($this->lasth$textitem''false''false0false);
  12899.             }
  12900.             $this->x $tmpx;
  12901.             $this->lispacer '';
  12902.         }
  12903.  
  12904.         /**
  12905.         * Returns current graphic variables as array.
  12906.         * @return array graphic variables
  12907.         * @access protected
  12908.         * @since 4.2.010 (2008-11-14)
  12909.         */
  12910.         protected function getGraphicVars({
  12911.             $grapvars array(
  12912.                 'FontFamily' => $this->FontFamily,
  12913.                 'FontStyle' => $this->FontStyle,
  12914.                 'FontSizePt' => $this->FontSizePt,
  12915.                 'rMargin' => $this->rMargin,
  12916.                 'lMargin' => $this->lMargin,
  12917.                 'cMargin' => $this->cMargin,
  12918.                 'LineWidth' => $this->LineWidth,
  12919.                 'linestyleWidth' => $this->linestyleWidth,
  12920.                 'linestyleCap' => $this->linestyleCap,
  12921.                 'linestyleJoin' => $this->linestyleJoin,
  12922.                 'linestyleDash' => $this->linestyleDash,
  12923.                 'DrawColor' => $this->DrawColor,
  12924.                 'FillColor' => $this->FillColor,
  12925.                 'TextColor' => $this->TextColor,
  12926.                 'ColorFlag' => $this->ColorFlag,
  12927.                 'bgcolor' => $this->bgcolor,
  12928.                 'fgcolor' => $this->fgcolor,
  12929.                 'htmlvspace' => $this->htmlvspace,
  12930.                 'lasth' => $this->lasth
  12931.                 );
  12932.             return $grapvars;
  12933.         }
  12934.  
  12935.         /**
  12936.         * Set graphic variables.
  12937.         * @param $gvars array graphic variables
  12938.         * @access protected
  12939.         * @since 4.2.010 (2008-11-14)
  12940.         */
  12941.         protected function setGraphicVars($gvars{
  12942.             $this->FontFamily $gvars['FontFamily'];
  12943.             $this->FontStyle $gvars['FontStyle'];
  12944.             $this->FontSizePt $gvars['FontSizePt'];
  12945.             $this->rMargin $gvars['rMargin'];
  12946.             $this->lMargin $gvars['lMargin'];
  12947.             $this->cMargin $gvars['cMargin'];
  12948.             $this->LineWidth $gvars['LineWidth'];
  12949.             $this->linestyleWidth $gvars['linestyleWidth'];
  12950.             $this->linestyleCap $gvars['linestyleCap'];
  12951.             $this->linestyleJoin $gvars['linestyleJoin'];
  12952.             $this->linestyleDash $gvars['linestyleDash'];
  12953.             $this->DrawColor $gvars['DrawColor'];
  12954.             $this->FillColor $gvars['FillColor'];
  12955.             $this->TextColor $gvars['TextColor'];
  12956.             $this->ColorFlag $gvars['ColorFlag'];
  12957.             $this->bgcolor $gvars['bgcolor'];
  12958.             $this->fgcolor $gvars['fgcolor'];
  12959.             $this->htmlvspace $gvars['htmlvspace'];
  12960.             //$this->lasth = $gvars['lasth'];
  12961.             $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  12962.             if (!$this->empty_string($this->FontFamily)) {
  12963.                 $this->SetFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  12964.             }
  12965.         }
  12966.  
  12967.         /**
  12968.         * Returns a temporary filename for caching object on filesystem.
  12969.         * @param string $prefix prefix to add to filename
  12970.         *  return string filename.
  12971.         * @access protected
  12972.         * @since 4.5.000 (2008-12-31)
  12973.         */
  12974.         protected function getObjFilename($name{
  12975.             return tempnam(K_PATH_CACHE$name.'_');
  12976.         }
  12977.  
  12978.         /**
  12979.         * Writes data to a temporary file on filesystem.
  12980.         * @param string $file file name
  12981.         * @param mixed $data data to write on file
  12982.         * @param boolean $append if true append data, false replace.
  12983.         * @access protected
  12984.         * @since 4.5.000 (2008-12-31)
  12985.         */
  12986.         protected function writeDiskCache($filename$data$append=false{
  12987.             if ($append{
  12988.                 $fmode 'ab+';
  12989.             else {
  12990.                 $fmode 'wb+';
  12991.             }
  12992.             $f @fopen($filename$fmode);
  12993.             if (!$f{
  12994.                 $this->Error('Unable to write cache file: '.$filename);
  12995.             else {
  12996.                 fwrite($f$data);
  12997.                 fclose($f);
  12998.             }
  12999.             // update file lenght (needed for transactions)
  13000.             if (!isset($this->cache_file_lenght[$filename])) {
  13001.                 $this->cache_file_lenght[$filenamestrlen($data);
  13002.             else {
  13003.                 $this->cache_file_lenght[$filename+= strlen($data);
  13004.             }
  13005.         }
  13006.  
  13007.         /**
  13008.         * Read data from a temporary file on filesystem.
  13009.         * @param string $file file name
  13010.         * @return mixed retrieved data
  13011.         * @access protected
  13012.         * @since 4.5.000 (2008-12-31)
  13013.         */
  13014.         protected function readDiskCache($filename{
  13015.             return file_get_contents($filename);
  13016.         }
  13017.  
  13018.         /**
  13019.         * Set buffer content (always append data).
  13020.         * @param string $data data
  13021.         * @access protected
  13022.         * @since 4.5.000 (2009-01-02)
  13023.         */
  13024.         protected function setBuffer($data{
  13025.             $this->bufferlen += strlen($data);
  13026.             if ($this->diskcache{
  13027.                 if (!isset($this->bufferOR $this->empty_string($this->buffer)) {
  13028.                     $this->buffer $this->getObjFilename('buffer');
  13029.                 }
  13030.                 $this->writeDiskCache($this->buffer$datatrue);
  13031.             else {
  13032.                 $this->buffer .= $data;
  13033.             }
  13034.         }
  13035.  
  13036.         /**
  13037.         * Get buffer content.
  13038.         * @return string buffer content
  13039.         * @access protected
  13040.         * @since 4.5.000 (2009-01-02)
  13041.         */
  13042.         protected function getBuffer({
  13043.             if ($this->diskcache{
  13044.                 return $this->readDiskCache($this->buffer);
  13045.             else {
  13046.                 return $this->buffer;
  13047.             }
  13048.         }
  13049.  
  13050.         /**
  13051.         * Set page buffer content.
  13052.         * @param int $page page number
  13053.         * @param string $data page data
  13054.         * @param boolean $append if true append data, false replace.
  13055.         * @access protected
  13056.         * @since 4.5.000 (2008-12-31)
  13057.         */
  13058.         protected function setPageBuffer($page$data$append=false{
  13059.             if ($this->diskcache{
  13060.                 if (!isset($this->pages[$page])) {
  13061.                     $this->pages[$page$this->getObjFilename('page'.$page);
  13062.                 }
  13063.                 $this->writeDiskCache($this->pages[$page]$data$append);
  13064.             else {
  13065.                 if ($append{
  13066.                     $this->pages[$page.= $data;
  13067.                 else {
  13068.                     $this->pages[$page$data;
  13069.                 }
  13070.             }
  13071.             if ($append AND isset($this->pagelen[$page])) {
  13072.                 $this->pagelen[$page+= strlen($data);
  13073.             else {
  13074.                 $this->pagelen[$pagestrlen($data);
  13075.             }
  13076.         }
  13077.  
  13078.         /**
  13079.         * Get page buffer content.
  13080.         * @param int $page page number
  13081.         * @return string page buffer content or false in case of error
  13082.         * @access protected
  13083.         * @since 4.5.000 (2008-12-31)
  13084.         */
  13085.         protected function getPageBuffer($page{
  13086.             if ($this->diskcache{
  13087.                 return $this->readDiskCache($this->pages[$page]);
  13088.             elseif (isset($this->pages[$page])) {
  13089.                 return $this->pages[$page];
  13090.             }
  13091.             return false;
  13092.         }
  13093.  
  13094.         /**
  13095.         * Set image buffer content.
  13096.         * @param string $image image key
  13097.         * @param array $data image data
  13098.         * @access protected
  13099.         * @since 4.5.000 (2008-12-31)
  13100.         */
  13101.         protected function setImageBuffer($image$data{
  13102.             if ($this->diskcache{
  13103.                 if (!isset($this->images[$image])) {
  13104.                     $this->images[$image$this->getObjFilename('image'.$image);
  13105.                 }
  13106.                 $this->writeDiskCache($this->images[$image]serialize($data));
  13107.             else {
  13108.                 $this->images[$image$data;
  13109.             }
  13110.             if (!in_array($image$this->imagekeys)) {
  13111.                 $this->imagekeys[$image;
  13112.             }
  13113.             ++$this->numimages;
  13114.         }
  13115.  
  13116.         /**
  13117.         * Set image buffer content.
  13118.         * @param string $image image key
  13119.         * @param string $key image sub-key
  13120.         * @param array $data image data
  13121.         * @access protected
  13122.         * @since 4.5.000 (2008-12-31)
  13123.         */
  13124.         protected function setImageSubBuffer($image$key$data{
  13125.             if (!isset($this->images[$image])) {
  13126.                 $this->setImageBuffer($imagearray());
  13127.             }
  13128.             if ($this->diskcache{
  13129.                 $tmpimg $this->getImageBuffer($image);
  13130.                 $tmpimg[$key$data;
  13131.                 $this->writeDiskCache($this->images[$image]serialize($tmpimg));
  13132.             else {
  13133.                 $this->images[$image][$key$data;
  13134.             }
  13135.         }
  13136.  
  13137.         /**
  13138.         * Get page buffer content.
  13139.         * @param string $image image key
  13140.         * @return string image buffer content or false in case of error
  13141.         * @access protected
  13142.         * @since 4.5.000 (2008-12-31)
  13143.         */
  13144.         protected function getImageBuffer($image{
  13145.             if ($this->diskcache AND isset($this->images[$image])) {
  13146.                 return unserialize($this->readDiskCache($this->images[$image]));
  13147.             elseif (isset($this->images[$image])) {
  13148.                 return $this->images[$image];
  13149.             }
  13150.             return false;
  13151.         }
  13152.  
  13153.         /**
  13154.         * Set font buffer content.
  13155.         * @param string $font font key
  13156.         * @param array $data font data
  13157.         * @access protected
  13158.         * @since 4.5.000 (2009-01-02)
  13159.         */
  13160.         protected function setFontBuffer($font$data{
  13161.             if ($this->diskcache{
  13162.                 if (!isset($this->fonts[$font])) {
  13163.                     $this->fonts[$font$this->getObjFilename('font');
  13164.                 }
  13165.                 $this->writeDiskCache($this->fonts[$font]serialize($data));
  13166.             else {
  13167.                 $this->fonts[$font$data;
  13168.             }
  13169.             if (!in_array($font$this->fontkeys)) {
  13170.                 $this->fontkeys[$font;
  13171.             }
  13172.         }
  13173.  
  13174.         /**
  13175.         * Set font buffer content.
  13176.         * @param string $font font key
  13177.         * @param string $key font sub-key
  13178.         * @param array $data font data
  13179.         * @access protected
  13180.         * @since 4.5.000 (2009-01-02)
  13181.         */
  13182.         protected function setFontSubBuffer($font$key$data{
  13183.             if (!isset($this->fonts[$font])) {
  13184.                 $this->setFontBuffer($fontarray());
  13185.             }
  13186.             if ($this->diskcache{
  13187.                 $tmpfont $this->getFontBuffer($font);
  13188.                 $tmpfont[$key$data;
  13189.                 $this->writeDiskCache($this->fonts[$font]serialize($tmpfont));
  13190.             else {
  13191.                 $this->fonts[$font][$key$data;
  13192.             }
  13193.         }
  13194.  
  13195.         /**
  13196.         * Get font buffer content.
  13197.         * @param string $font font key
  13198.         * @return string font buffer content or false in case of error
  13199.         * @access protected
  13200.         * @since 4.5.000 (2009-01-02)
  13201.         */
  13202.         protected function getFontBuffer($font{
  13203.             if ($this->diskcache AND isset($this->fonts[$font])) {
  13204.                 return unserialize($this->readDiskCache($this->fonts[$font]));
  13205.             elseif (isset($this->fonts[$font])) {
  13206.                 return $this->fonts[$font];
  13207.             }
  13208.             return false;
  13209.         }
  13210.  
  13211.         /**
  13212.         * Move a page to a previous position.
  13213.         * Use this method just before Output().
  13214.         * @param int $frompage number of the source page
  13215.         * @param int $topage number of the destination page (must be less than $frompage)
  13216.         * @return true in case of success, false in case of error.
  13217.         * @access public
  13218.         * @since 4.5.000 (2009-01-02)
  13219.         */
  13220.         public function movePage($frompage$topage{
  13221.             if (($frompage $this->numpagesOR ($frompage <= $topage)) {
  13222.                 return false;
  13223.             }
  13224.             if ($frompage == $this->page{
  13225.                 // close the page before moving it
  13226.                 $this->endPage();
  13227.             }
  13228.             // move all page-related states
  13229.             $tmppage $this->pages[$frompage];
  13230.             $tmppagedim $this->pagedim[$frompage];
  13231.             $tmppagelen $this->pagelen[$frompage];
  13232.             $tmpintmrk $this->intmrk[$frompage];
  13233.             if (isset($this->footerpos[$frompage])) {
  13234.                 $tmpfooterpos $this->footerpos[$frompage];
  13235.             }
  13236.             if (isset($this->footerlen[$frompage])) {
  13237.                 $tmpfooterlen $this->footerlen[$frompage];
  13238.             }
  13239.             if (isset($this->transfmrk[$frompage])) {
  13240.                 $tmptransfmrk $this->transfmrk[$frompage];
  13241.             }
  13242.             if (isset($this->PageAnnots[$frompage])) {
  13243.                 $tmpannots $this->PageAnnots[$frompage];
  13244.             }
  13245.             if (isset($this->newpagegroup[$frompage])) {
  13246.                 $tmpnewpagegroup $this->newpagegroup[$frompage];
  13247.             }
  13248.             for ($i $frompage$i $topage$i--{
  13249.                 // shift pages down
  13250.                 $this->pages[$i$this->pages[($i 1)];
  13251.                 $this->pagedim[$i$this->pagedim[($i 1)];
  13252.                 $this->pagelen[$i$this->pagelen[($i 1)];
  13253.                 $this->intmrk[$i$this->intmrk[($i 1)];
  13254.                 if (isset($this->footerpos[($i 1)])) {
  13255.                     $this->footerpos[$i$this->footerpos[($i 1)];
  13256.                 elseif (isset($this->footerpos[$i])) {
  13257.                     unset($this->footerpos[$i]);
  13258.                 }
  13259.                 if (isset($this->footerlen[($i 1)])) {
  13260.                     $this->footerlen[$i$this->footerlen[($i 1)];
  13261.                 elseif (isset($this->footerlen[$i])) {
  13262.                     unset($this->footerlen[$i]);
  13263.                 }
  13264.                 if (isset($this->transfmrk[($i 1)])) {
  13265.                     $this->transfmrk[$i$this->transfmrk[($i 1)];
  13266.                 elseif (isset($this->transfmrk[$i])) {
  13267.                     unset($this->transfmrk[$i]);
  13268.                 }
  13269.                 if (isset($this->PageAnnots[($i 1)])) {
  13270.                     $this->PageAnnots[$i$this->PageAnnots[($i 1)];
  13271.                 elseif (isset($this->PageAnnots[$i])) {
  13272.                     unset($this->PageAnnots[$i]);
  13273.                 }
  13274.                 if (isset($this->newpagegroup[($i 1)])) {
  13275.                     $this->newpagegroup[$i$this->newpagegroup[($i 1)];
  13276.                 elseif (isset($this->newpagegroup[$i])) {
  13277.                     unset($this->newpagegroup[$i]);
  13278.                 }
  13279.             }
  13280.             $this->pages[$topage$tmppage;
  13281.             $this->pagedim[$topage$tmppagedim;
  13282.             $this->pagelen[$topage$tmppagelen;
  13283.             $this->intmrk[$topage$tmpintmrk;
  13284.             if (isset($tmpfooterpos)) {
  13285.                 $this->footerpos[$topage$tmpfooterpos;
  13286.             elseif (isset($this->footerpos[$topage])) {
  13287.                 unset($this->footerpos[$topage]);
  13288.             }
  13289.             if (isset($tmpfooterlen)) {
  13290.                 $this->footerlen[$topage$tmpfooterlen;
  13291.             elseif (isset($this->footerlen[$topage])) {
  13292.                 unset($this->footerlen[$topage]);
  13293.             }
  13294.             if (isset($tmptransfmrk)) {
  13295.                 $this->transfmrk[$topage$tmptransfmrk;
  13296.             elseif (isset($this->transfmrk[$topage])) {
  13297.                 unset($this->transfmrk[$topage]);
  13298.             }
  13299.             if (isset($tmpannots)) {
  13300.                 $this->PageAnnots[$topage$tmpannots;
  13301.             elseif (isset($this->PageAnnots[$topage])) {
  13302.                 unset($this->PageAnnots[$topage]);
  13303.             }
  13304.             if (isset($tmpnewpagegroup)) {
  13305.                 $this->newpagegroup[$topage$tmpnewpagegroup;
  13306.             elseif (isset($this->newpagegroup[$topage])) {
  13307.                 unset($this->newpagegroup[$topage]);
  13308.             }
  13309.             // adjust outlines
  13310.             $tmpoutlines $this->outlines;
  13311.             foreach ($tmpoutlines as $key => $outline{
  13312.                 if (($outline['p'>= $topageAND ($outline['p'$frompage)) {
  13313.                     $this->outlines[$key]['p'$outline['p'1;
  13314.                 elseif ($outline['p'== $frompage{
  13315.                     $this->outlines[$key]['p'$topage;
  13316.                 }
  13317.             }
  13318.             // adjust links
  13319.             $tmplinks $this->links;
  13320.             foreach ($tmplinks as $key => $link{
  13321.                 if (($link[0>= $topageAND ($link[0$frompage)) {
  13322.                     $this->links[$key][0$link[01;
  13323.                 elseif ($link[0== $frompage{
  13324.                     $this->links[$key][0$topage;
  13325.                 }
  13326.             }
  13327.             // adjust javascript
  13328.             $tmpjavascript $this->javascript;
  13329.             global $jfrompage$jtopage;
  13330.             $jfrompage $frompage;
  13331.             $jtopage $topage;
  13332.             $this->javascript preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  13333.                 create_function('$matches''global $jfrompage, $jtopage;
  13334.                 $pagenum = intval($matches[3]) + 1;
  13335.                 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  13336.                     $newpage = ($pagenum + 1);
  13337.                 } elseif ($pagenum == $jfrompage) {
  13338.                     $newpage = $jtopage;
  13339.                 } else {
  13340.                     $newpage = $pagenum;
  13341.                 }
  13342.                 --$newpage;
  13343.                 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";')$tmpjavascript);
  13344.             // return to last page
  13345.             $this->lastPage(true);
  13346.             return true;
  13347.         }
  13348.  
  13349.         /**
  13350.         * Output a Table of Content Index (TOC).
  13351.         * You can override this method to achieve different styles.
  13352.         * @param int $page page number where this TOC should be inserted (leave empty for current page).
  13353.         * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  13354.         * @param string $filler string used to fill the space between text and page number.
  13355.         * @access public
  13356.         * @author Nicola Asuni
  13357.         * @since 4.5.000 (2009-01-02)
  13358.         */
  13359.         public function addTOC($page=''$numbersfont=''$filler='.'{
  13360.             $fontsize $this->FontSizePt;
  13361.             $fontfamily $this->FontFamily;
  13362.             $fontstyle $this->FontStyle;
  13363.             $w $this->w $this->lMargin $this->rMargin;
  13364.             $spacer $this->GetStringWidth(' '4;
  13365.             $page_first $this->getPage();
  13366.             $lmargin $this->lMargin;
  13367.             $rmargin $this->rMargin;
  13368.             $x_start $this->GetX();
  13369.             if ($this->empty_string($numbersfont)) {
  13370.                 $numbersfont $this->default_monospaced_font;
  13371.             }
  13372.             if ($this->empty_string($filler)) {
  13373.                 $filler ' ';
  13374.             }
  13375.             if ($this->empty_string($page)) {
  13376.                 $gap ' ';
  13377.             else {
  13378.                 $gap '';
  13379.             }
  13380.             foreach ($this->outlines as $key => $outline{
  13381.                 if ($this->rtl{
  13382.                     $aligntext 'R';
  13383.                     $alignnum 'L';
  13384.                 else {
  13385.                     $aligntext 'L';
  13386.                     $alignnum 'R';
  13387.                 }
  13388.                 if ($outline['l'== 0{
  13389.                     $this->SetFont($fontfamily$fontstyle.'B'$fontsize);
  13390.                 else {
  13391.                     $this->SetFont($fontfamily$fontstyle$fontsize $outline['l']);
  13392.                 }
  13393.                 $indent ($spacer $outline['l']);
  13394.                 if ($this->rtl{
  13395.                     $this->rMargin += $indent;
  13396.                     $this->x -= $indent;
  13397.                 else {
  13398.                     $this->lMargin += $indent;
  13399.                     $this->x += $indent;
  13400.                 }
  13401.                 $link $this->AddLink();
  13402.                 $this->SetLink($link0$outline['p']);
  13403.                 // write the text
  13404.                 $this->Write(0$outline['t']$link0$aligntextfalse0falsefalse0);
  13405.                 $this->SetFont($numbersfont$fontstyle$fontsize);
  13406.                 if ($this->empty_string($page)) {
  13407.                     $pagenum $outline['p'];
  13408.                 else {
  13409.                     // placemark to be replaced with the correct number
  13410.                     $pagenum '{#'.($outline['p']).'}';
  13411.                     if (($this->CurrentFont['type'== 'TrueTypeUnicode'OR ($this->CurrentFont['type'== 'cidfont0')) {
  13412.                         $pagenum '{'.$pagenum.'}';
  13413.                     }
  13414.                 }
  13415.                 $numwidth $this->GetStringWidth($pagenum);
  13416.                 if ($this->rtl{
  13417.                     $tw $this->x $this->lMargin;
  13418.                 else {
  13419.                     $tw $this->w $this->rMargin $this->x;
  13420.                 }
  13421.                 $fw $tw $numwidth $this->GetStringWidth(' ');
  13422.                 $numfills floor($fw $this->GetStringWidth($filler));
  13423.                 if ($numfills 0{
  13424.                     $rowfill str_repeat($filler$numfills);
  13425.                 else {
  13426.                     $rowfill '';
  13427.                 }
  13428.                 if ($this->rtl{
  13429.                     $pagenum $pagenum.$gap.$rowfill.' ';
  13430.                 else {
  13431.                     $pagenum ' '.$rowfill.$gap.$pagenum;
  13432.                 }
  13433.                 // write the number
  13434.                 //$this->SetX($x_start);
  13435.                 $this->Cell($tw0$pagenum01$alignnum0$link0);
  13436.                 $this->SetX($x_start);
  13437.                 $this->lMargin $lmargin;
  13438.                 $this->rMargin $rmargin;
  13439.             }
  13440.             $page_last $this->getPage();
  13441.             $numpages $page_last $page_first 1;
  13442.             if (!$this->empty_string($page)) {
  13443.                 for($p $page_first$p <= $page_last++$p{
  13444.                     // get page data
  13445.                     $temppage $this->getPageBuffer($p);
  13446.                     for($n 1$n <= $this->numpages++$n{
  13447.                         // update page numbers
  13448.                         $k '{#'.$n.'}';
  13449.                         $ku '{'.$k.'}';
  13450.                         $alias_a $this->_escape($k);
  13451.                         $alias_au $this->_escape('{'.$k.'}');
  13452.                         if ($this->isunicode{
  13453.                             $alias_b $this->_escape($this->UTF8ToLatin1($k));
  13454.                             $alias_bu $this->_escape($this->UTF8ToLatin1($ku));
  13455.                             $alias_c $this->_escape($this->utf8StrRev($kfalse$this->tmprtl));
  13456.                             $alias_cu $this->_escape($this->utf8StrRev($kufalse$this->tmprtl));
  13457.                         }
  13458.                         if ($n >= $page{
  13459.                             $np $n $numpages;
  13460.                         else {
  13461.                             $np $n;
  13462.                         }
  13463.                         $ns $this->formatTOCPageNumber($np);
  13464.                         $nu $ns;
  13465.                         $sdiff strlen($kstrlen($ns1;
  13466.                         $sdiffu strlen($kustrlen($ns1;
  13467.                         $sfill str_repeat($filler$sdiff);
  13468.                         $sfillu str_repeat($filler$sdiffu);
  13469.                         if ($this->rtl{
  13470.                             $ns $ns.' '.$sfill;
  13471.                             $nu $nu.' '.$sfillu;
  13472.                         else {
  13473.                             $ns $sfill.' '.$ns;
  13474.                             $nu $sfillu.' '.$nu;
  13475.                         }
  13476.                         $nu $this->UTF8ToUTF16BE($nufalse);
  13477.                         $temppage str_replace($alias_au$nu$temppage);
  13478.                         if ($this->isunicode{
  13479.                             $temppage str_replace($alias_bu$nu$temppage);
  13480.                             $temppage str_replace($alias_cu$nu$temppage);
  13481.                             $temppage str_replace($alias_b$ns$temppage);
  13482.                             $temppage str_replace($alias_c$ns$temppage);
  13483.                         }
  13484.                         $temppage str_replace($alias_a$ns$temppage);
  13485.                     }
  13486.                     // save changes
  13487.                     $this->setPageBuffer($p$temppage);
  13488.                 }
  13489.                 // move pages
  13490.                 for ($i 0$i $numpages++$i{
  13491.                     $this->movePage($page_last$page);
  13492.                 }
  13493.             }
  13494.             $this->SetFont($fontfamily$fontstyle$fontsize);
  13495.         }
  13496.  
  13497.         /**
  13498.         * Stores a copy of the current TCPDF object.
  13499.         * @access public
  13500.         * @since 4.5.029 (2009-03-19)
  13501.         */
  13502.         public function startTransaction({
  13503.             if (isset($this->objcopy)) {
  13504.                 // remove previous copy
  13505.                 $this->commitTransaction();
  13506.             }
  13507.             // clone current object
  13508.             $this->objcopy $this->objclone($this);
  13509.         }
  13510.  
  13511.         /**
  13512.         * Delete the copy of the current TCPDF object
  13513.         * @access public
  13514.         * @since 4.5.029 (2009-03-19)
  13515.         */
  13516.         public function commitTransaction({
  13517.             if (isset($this->objcopy)) {
  13518.                 $this->objcopy->_destroy(truetrue);
  13519.                 unset($this->objcopy);
  13520.             }
  13521.         }
  13522.  
  13523.         /**
  13524.         * This method allows to encapsulate some TCPDF commands to be later commited or deleted.
  13525.         * @param string $action the action to be taken. Legal values are 'start' = starts a new transaction; 'commit' = commit the latest transaction; 'rollback' = undo the latest transaction.
  13526.         * @access public
  13527.         * @since 4.5.029 (2009-03-19)
  13528.         */
  13529.         public function rollbackTransaction({
  13530.             if (isset($this->objcopy)) {
  13531.                 if (isset($this->objcopy->diskcacheAND $this->objcopy->diskcache{
  13532.                     // truncate files to previous values
  13533.                     foreach ($this->objcopy->cache_file_lenght as $file => $lenght{
  13534.                         $handle fopen($file'r+');
  13535.                         ftruncate($handle$lenght);
  13536.                     }
  13537.                 }
  13538.                 $this->_destroy(truetrue);
  13539.                 return $this->objcopy;
  13540.             }
  13541.             return $this;
  13542.         }
  13543.  
  13544.         /**
  13545.         * Creates a copy of a class object
  13546.         * @param object $object class object to be cloned
  13547.         * @return cloned object
  13548.         * @access public
  13549.         * @since 4.5.029 (2009-03-19)
  13550.         */
  13551.         public function objclone($object{
  13552.             return @clone($object);
  13553.         }
  13554.  
  13555.         /**
  13556.         * Determine whether a string is empty.
  13557.         * @param srting $str string to be checked
  13558.         * @return boolean true if string is empty
  13559.         * @access public
  13560.         * @since 4.5.044 (2009-04-16)
  13561.         */
  13562.         public function empty_string($str{
  13563.             return (is_null($strOR (is_string($strAND (strlen($str== 0)));
  13564.         }
  13565.         
  13566.     // END OF TCPDF CLASS
  13567. }
  13568. //============================================================+
  13569. // END OF FILE
  13570. //============================================================+
  13571. ?>

Documentation generated on Wed, 22 Apr 2009 09:03:12 +0200 by phpDocumentor 1.4.1