vendor/tecnickcom/tcpdf/tcpdf.php line 7133

Open in your IDE?
  1. <?php
  2. //============================================================+
  3. // File name   : tcpdf.php
  4. // Version     : 6.6.5
  5. // Begin       : 2002-08-03
  6. // Last Update : 2023-09-06
  7. // Author      : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
  8. // License     : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2023 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. //   This is a PHP class for generating PDF documents without requiring external extensions.
  33. //
  34. // NOTE:
  35. //   This class was originally derived in 2002 from the Public
  36. //   Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  37. //   but now is almost entirely rewritten and contains thousands of
  38. //   new lines of code and hundreds new features.
  39. //
  40. // Main features:
  41. //  * no external libraries are required for the basic functions;
  42. //  * all standard page formats, custom page formats, custom margins and units of measure;
  43. //  * UTF-8 Unicode and Right-To-Left languages;
  44. //  * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
  45. //  * font subsetting;
  46. //  * methods to publish some XHTML + CSS code, Javascript and Forms;
  47. //  * images, graphic (geometric figures) and transformation methods;
  48. //  * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)
  49. //  * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. //  * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. //  * automatic page header and footer management;
  52. //  * document encryption up to 256 bit and digital signature certifications;
  53. //  * transactions to UNDO commands;
  54. //  * PDF annotations, including links, text and file attachments;
  55. //  * text rendering modes (fill, stroke and clipping);
  56. //  * multiple columns mode;
  57. //  * no-write page regions;
  58. //  * bookmarks, named destinations and table of content;
  59. //  * text hyphenation;
  60. //  * text stretching and spacing (tracking);
  61. //  * automatic page break, line break and text alignments including justification;
  62. //  * automatic page numbering and page groups;
  63. //  * move and delete pages;
  64. //  * page compression (requires php-zlib extension);
  65. //  * XOBject Templates;
  66. //  * Layers and object visibility.
  67. //    * PDF/A-1b support
  68. //============================================================+
  69. /**
  70.  * @file
  71.  * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  72.  * 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>
  73.  * <h3>TCPDF main features are:</h3>
  74.  * <ul>
  75.  * <li>no external libraries are required for the basic functions;</li>
  76.  * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  77.  * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  78.  * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  79.  * <li>font subsetting;</li>
  80.  * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  81.  * <li>images, graphic (geometric figures) and transformation methods;
  82.  * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)</li>
  83.  * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
  84.  * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  85.  * <li>automatic page header and footer management;</li>
  86.  * <li>document encryption up to 256 bit and digital signature certifications;</li>
  87.  * <li>transactions to UNDO commands;</li>
  88.  * <li>PDF annotations, including links, text and file attachments;</li>
  89.  * <li>text rendering modes (fill, stroke and clipping);</li>
  90.  * <li>multiple columns mode;</li>
  91.  * <li>no-write page regions;</li>
  92.  * <li>bookmarks, named destinations and table of content;</li>
  93.  * <li>text hyphenation;</li>
  94.  * <li>text stretching and spacing (tracking);</li>
  95.  * <li>automatic page break, line break and text alignments including justification;</li>
  96.  * <li>automatic page numbering and page groups;</li>
  97.  * <li>move and delete pages;</li>
  98.  * <li>page compression (requires php-zlib extension);</li>
  99.  * <li>XOBject Templates;</li>
  100.  * <li>Layers and object visibility;</li>
  101.  * <li>PDF/A-1b support.</li>
  102.  * </ul>
  103.  * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  104.  * @package com.tecnick.tcpdf
  105.  * @author Nicola Asuni
  106.  * @version 6.6.5
  107.  */
  108. // TCPDF configuration
  109. require_once(dirname(__FILE__).'/tcpdf_autoconfig.php');
  110. // TCPDF static font methods and data
  111. require_once(dirname(__FILE__).'/include/tcpdf_font_data.php');
  112. // TCPDF static font methods and data
  113. require_once(dirname(__FILE__).'/include/tcpdf_fonts.php');
  114. // TCPDF static color methods and data
  115. require_once(dirname(__FILE__).'/include/tcpdf_colors.php');
  116. // TCPDF static image methods and data
  117. require_once(dirname(__FILE__).'/include/tcpdf_images.php');
  118. // TCPDF static methods and data
  119. require_once(dirname(__FILE__).'/include/tcpdf_static.php');
  120. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  121. /**
  122.  * @class TCPDF
  123.  * PHP class for generating PDF documents without requiring external extensions.
  124.  * 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>
  125.  * @package com.tecnick.tcpdf
  126.  * @brief PHP class for generating PDF documents without requiring external extensions.
  127.  * @version 6.6.5
  128.  * @author Nicola Asuni - info@tecnick.com
  129.  * @IgnoreAnnotation("protected")
  130.  * @IgnoreAnnotation("public")
  131.  * @IgnoreAnnotation("pre")
  132.  */
  133. class TCPDF {
  134.     // Protected properties
  135.     /**
  136.      * Current page number.
  137.      * @protected
  138.      */
  139.     protected $page;
  140.     /**
  141.      * Current object number.
  142.      * @protected
  143.      */
  144.     protected $n;
  145.     /**
  146.      * Array of object offsets.
  147.      * @protected
  148.      */
  149.     protected $offsets = array();
  150.     /**
  151.      * Array of object IDs for each page.
  152.      * @protected
  153.      */
  154.     protected $pageobjects = array();
  155.     /**
  156.      * Buffer holding in-memory PDF.
  157.      * @protected
  158.      */
  159.     protected $buffer;
  160.     /**
  161.      * Array containing pages.
  162.      * @protected
  163.      */
  164.     protected $pages = array();
  165.     /**
  166.      * Current document state.
  167.      * @protected
  168.      */
  169.     protected $state;
  170.     /**
  171.      * Compression flag.
  172.      * @protected
  173.      */
  174.     protected $compress;
  175.     /**
  176.      * Current page orientation (P = Portrait, L = Landscape).
  177.      * @protected
  178.      */
  179.     protected $CurOrientation;
  180.     /**
  181.      * Page dimensions.
  182.      * @protected
  183.      */
  184.     protected $pagedim = array();
  185.     /**
  186.      * Scale factor (number of points in user unit).
  187.      * @protected
  188.      */
  189.     protected $k;
  190.     /**
  191.      * Width of page format in points.
  192.      * @protected
  193.      */
  194.     protected $fwPt;
  195.     /**
  196.      * Height of page format in points.
  197.      * @protected
  198.      */
  199.     protected $fhPt;
  200.     /**
  201.      * Current width of page in points.
  202.      * @protected
  203.      */
  204.     protected $wPt;
  205.     /**
  206.      * Current height of page in points.
  207.      * @protected
  208.      */
  209.     protected $hPt;
  210.     /**
  211.      * Current width of page in user unit.
  212.      * @protected
  213.      */
  214.     protected $w;
  215.     /**
  216.      * Current height of page in user unit.
  217.      * @protected
  218.      */
  219.     protected $h;
  220.     /**
  221.      * Left margin.
  222.      * @protected
  223.      */
  224.     protected $lMargin;
  225.     /**
  226.      * Right margin.
  227.      * @protected
  228.      */
  229.     protected $rMargin;
  230.     /**
  231.      * Cell left margin (used by regions).
  232.      * @protected
  233.      */
  234.     protected $clMargin;
  235.     /**
  236.      * Cell right margin (used by regions).
  237.      * @protected
  238.      */
  239.     protected $crMargin;
  240.     /**
  241.      * Top margin.
  242.      * @protected
  243.      */
  244.     protected $tMargin;
  245.     /**
  246.      * Page break margin.
  247.      * @protected
  248.      */
  249.     protected $bMargin;
  250.     /**
  251.      * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  252.      * @since 5.9.000 (2010-10-03)
  253.      * @protected
  254.      */
  255.     protected $cell_padding = array('T' => 0'R' => 0'B' => 0'L' => 0);
  256.     /**
  257.      * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  258.      * @since 5.9.000 (2010-10-04)
  259.      * @protected
  260.      */
  261.     protected $cell_margin = array('T' => 0'R' => 0'B' => 0'L' => 0);
  262.     /**
  263.      * Current horizontal position in user unit for cell positioning.
  264.      * @protected
  265.      */
  266.     protected $x;
  267.     /**
  268.      * Current vertical position in user unit for cell positioning.
  269.      * @protected
  270.      */
  271.     protected $y;
  272.     /**
  273.      * Height of last cell printed.
  274.      * @protected
  275.      */
  276.     protected $lasth;
  277.     /**
  278.      * Line width in user unit.
  279.      * @protected
  280.      */
  281.     protected $LineWidth;
  282.     /**
  283.      * Array of standard font names.
  284.      * @protected
  285.      */
  286.     protected $CoreFonts;
  287.     /**
  288.      * Array of used fonts.
  289.      * @protected
  290.      */
  291.     protected $fonts = array();
  292.     /**
  293.      * Array of font files.
  294.      * @protected
  295.      */
  296.     protected $FontFiles = array();
  297.     /**
  298.      * Array of encoding differences.
  299.      * @protected
  300.      */
  301.     protected $diffs = array();
  302.     /**
  303.      * Array of used images.
  304.      * @protected
  305.      */
  306.     protected $images = array();
  307.     /**
  308.      * Depth of the svg tag, to keep track if the svg tag is a subtag or the root tag.
  309.      * @protected
  310.      */
  311.     protected $svg_tag_depth 0;
  312.     /**
  313.      * Array of Annotations in pages.
  314.      * @protected
  315.      */
  316.     protected $PageAnnots = array();
  317.     /**
  318.      * Array of internal links.
  319.      * @protected
  320.      */
  321.     protected $links = array();
  322.     /**
  323.      * Current font family.
  324.      * @protected
  325.      */
  326.     protected $FontFamily;
  327.     /**
  328.      * Current font style.
  329.      * @protected
  330.      */
  331.     protected $FontStyle;
  332.     /**
  333.      * Current font ascent (distance between font top and baseline).
  334.      * @protected
  335.      * @since 2.8.000 (2007-03-29)
  336.      */
  337.     protected $FontAscent;
  338.     /**
  339.      * Current font descent (distance between font bottom and baseline).
  340.      * @protected
  341.      * @since 2.8.000 (2007-03-29)
  342.      */
  343.     protected $FontDescent;
  344.     /**
  345.      * Underlining flag.
  346.      * @protected
  347.      */
  348.     protected $underline;
  349.     /**
  350.      * Overlining flag.
  351.      * @protected
  352.      */
  353.     protected $overline;
  354.     /**
  355.      * Current font info.
  356.      * @protected
  357.      */
  358.     protected $CurrentFont;
  359.     /**
  360.      * Current font size in points.
  361.      * @protected
  362.      */
  363.     protected $FontSizePt;
  364.     /**
  365.      * Current font size in user unit.
  366.      * @protected
  367.      */
  368.     protected $FontSize;
  369.     /**
  370.      * Commands for drawing color.
  371.      * @protected
  372.      */
  373.     protected $DrawColor;
  374.     /**
  375.      * Commands for filling color.
  376.      * @protected
  377.      */
  378.     protected $FillColor;
  379.     /**
  380.      * Commands for text color.
  381.      * @protected
  382.      */
  383.     protected $TextColor;
  384.     /**
  385.      * Indicates whether fill and text colors are different.
  386.      * @protected
  387.      */
  388.     protected $ColorFlag;
  389.     /**
  390.      * Automatic page breaking.
  391.      * @protected
  392.      */
  393.     protected $AutoPageBreak;
  394.     /**
  395.      * Threshold used to trigger page breaks.
  396.      * @protected
  397.      */
  398.     protected $PageBreakTrigger;
  399.     /**
  400.      * Flag set when processing page header.
  401.      * @protected
  402.      */
  403.     protected $InHeader false;
  404.     /**
  405.      * Flag set when processing page footer.
  406.      * @protected
  407.      */
  408.     protected $InFooter false;
  409.     /**
  410.      * Zoom display mode.
  411.      * @protected
  412.      */
  413.     protected $ZoomMode;
  414.     /**
  415.      * Layout display mode.
  416.      * @protected
  417.      */
  418.     protected $LayoutMode;
  419.     /**
  420.      * If true set the document information dictionary in Unicode.
  421.      * @protected
  422.      */
  423.     protected $docinfounicode true;
  424.     /**
  425.      * Document title.
  426.      * @protected
  427.      */
  428.     protected $title '';
  429.     /**
  430.      * Document subject.
  431.      * @protected
  432.      */
  433.     protected $subject '';
  434.     /**
  435.      * Document author.
  436.      * @protected
  437.      */
  438.     protected $author '';
  439.     /**
  440.      * Document keywords.
  441.      * @protected
  442.      */
  443.     protected $keywords '';
  444.     /**
  445.      * Document creator.
  446.      * @protected
  447.      */
  448.     protected $creator '';
  449.     /**
  450.      * Starting page number.
  451.      * @protected
  452.      */
  453.     protected $starting_page_number 1;
  454.     /**
  455.      * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  456.      * @since 2002-07-31
  457.      * @author Nicola Asuni
  458.      * @protected
  459.      */
  460.     protected $img_rb_x;
  461.     /**
  462.      * The right-bottom corner Y coordinate of last inserted image.
  463.      * @since 2002-07-31
  464.      * @author Nicola Asuni
  465.      * @protected
  466.      */
  467.     protected $img_rb_y;
  468.     /**
  469.      * Adjusting factor to convert pixels to user units.
  470.      * @since 2004-06-14
  471.      * @author Nicola Asuni
  472.      * @protected
  473.      */
  474.     protected $imgscale 1;
  475.     /**
  476.      * Boolean flag set to true when the input text is unicode (require unicode fonts).
  477.      * @since 2005-01-02
  478.      * @author Nicola Asuni
  479.      * @protected
  480.      */
  481.     protected $isunicode false;
  482.     /**
  483.      * PDF version.
  484.      * @since 1.5.3
  485.      * @protected
  486.      */
  487.     protected $PDFVersion '1.7';
  488.     /**
  489.      * ID of the stored default header template (-1 = not set).
  490.      * @protected
  491.      */
  492.     protected $header_xobjid false;
  493.     /**
  494.      * If true reset the Header Xobject template at each page
  495.      * @protected
  496.      */
  497.     protected $header_xobj_autoreset false;
  498.     /**
  499.      * Minimum distance between header and top page margin.
  500.      * @protected
  501.      * @var float
  502.      */
  503.     protected $header_margin;
  504.     /**
  505.      * Minimum distance between footer and bottom page margin.
  506.      * @protected
  507.      * @var float
  508.      */
  509.     protected $footer_margin;
  510.     /**
  511.      * Original left margin value.
  512.      * @protected
  513.      * @since 1.53.0.TC013
  514.      */
  515.     protected $original_lMargin;
  516.     /**
  517.      * Original right margin value.
  518.      * @protected
  519.      * @since 1.53.0.TC013
  520.      */
  521.     protected $original_rMargin;
  522.     /**
  523.      * Default font used on page header.
  524.      * @protected
  525.      * @var array<int,string|float|null>
  526.      * @phpstan-var array{0: string, 1: string, 2: float|null}
  527.      */
  528.     protected $header_font;
  529.     /**
  530.      * Default font used on page footer.
  531.      * @protected
  532.      * @var array<int,string|float|null>
  533.      * @phpstan-var array{0: string, 1: string, 2: float|null}
  534.      */
  535.     protected $footer_font;
  536.     /**
  537.      * Language templates.
  538.      * @protected
  539.      */
  540.     protected $l;
  541.     /**
  542.      * Barcode to print on page footer (only if set).
  543.      * @protected
  544.      */
  545.     protected $barcode false;
  546.     /**
  547.      * Boolean flag to print/hide page header.
  548.      * @protected
  549.      */
  550.     protected $print_header true;
  551.     /**
  552.      * Boolean flag to print/hide page footer.
  553.      * @protected
  554.      */
  555.     protected $print_footer true;
  556.     /**
  557.      * Header image logo.
  558.      * @protected
  559.      */
  560.     protected $header_logo '';
  561.     /**
  562.      * Width of header image logo in user units.
  563.      * @protected
  564.      */
  565.     protected $header_logo_width 30;
  566.     /**
  567.      * Title to be printed on default page header.
  568.      * @protected
  569.      */
  570.     protected $header_title '';
  571.     /**
  572.      * String to print on page header after title.
  573.      * @protected
  574.      */
  575.     protected $header_string '';
  576.     /**
  577.      * Color for header text (RGB array).
  578.      * @since 5.9.174 (2012-07-25)
  579.      * @protected
  580.      * @var int[]
  581.      * @phpstan-var array{0: int, 1: int, 2: int}
  582.      */
  583.     protected $header_text_color = array(0,0,0);
  584.     /**
  585.      * Color for header line (RGB array).
  586.      * @since 5.9.174 (2012-07-25)
  587.      * @protected
  588.      * @var int[]
  589.      * @phpstan-var array{0: int, 1: int, 2: int}
  590.      */
  591.     protected $header_line_color = array(0,0,0);
  592.     /**
  593.      * Color for footer text (RGB array).
  594.      * @since 5.9.174 (2012-07-25)
  595.      * @protected
  596.      * @var int[]
  597.      * @phpstan-var array{0: int, 1: int, 2: int}
  598.      */
  599.     protected $footer_text_color = array(0,0,0);
  600.     /**
  601.      * Color for footer line (RGB array).
  602.      * @since 5.9.174 (2012-07-25)
  603.      * @protected
  604.      * @var int[]
  605.      * @phpstan-var array{0: int, 1: int, 2: int}
  606.      */
  607.     protected $footer_line_color = array(0,0,0);
  608.     /**
  609.      * Text shadow data array.
  610.      * @since 5.9.174 (2012-07-25)
  611.      * @protected
  612.      */
  613.     protected $txtshadow = array('enabled'=>false'depth_w'=>0'depth_h'=>0'color'=>false'opacity'=>1'blend_mode'=>'Normal');
  614.     /**
  615.      * Default number of columns for html table.
  616.      * @protected
  617.      */
  618.     protected $default_table_columns 4;
  619.     // variables for html parser
  620.     /**
  621.      * HTML PARSER: array to store current link and rendering styles.
  622.      * @protected
  623.      */
  624.     protected $HREF = array();
  625.     /**
  626.      * List of available fonts on filesystem.
  627.      * @protected
  628.      */
  629.     protected $fontlist = array();
  630.     /**
  631.      * Current foreground color.
  632.      * @protected
  633.      */
  634.     protected $fgcolor;
  635.     /**
  636.      * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  637.      * @protected
  638.      */
  639.     protected $listordered = array();
  640.     /**
  641.      * HTML PARSER: array count list items on nested lists.
  642.      * @protected
  643.      */
  644.     protected $listcount = array();
  645.     /**
  646.      * HTML PARSER: current list nesting level.
  647.      * @protected
  648.      */
  649.     protected $listnum 0;
  650.     /**
  651.      * HTML PARSER: indent amount for lists.
  652.      * @protected
  653.      */
  654.     protected $listindent 0;
  655.     /**
  656.      * HTML PARSER: current list indententation level.
  657.      * @protected
  658.      */
  659.     protected $listindentlevel 0;
  660.     /**
  661.      * Current background color.
  662.      * @protected
  663.      */
  664.     protected $bgcolor;
  665.     /**
  666.      * Temporary font size in points.
  667.      * @protected
  668.      */
  669.     protected $tempfontsize 10;
  670.     /**
  671.      * Spacer string for LI tags.
  672.      * @protected
  673.      */
  674.     protected $lispacer '';
  675.     /**
  676.      * Default encoding.
  677.      * @protected
  678.      * @since 1.53.0.TC010
  679.      */
  680.     protected $encoding 'UTF-8';
  681.     /**
  682.      * Boolean flag to indicate if the document language is Right-To-Left.
  683.      * @protected
  684.      * @since 2.0.000
  685.      */
  686.     protected $rtl false;
  687.     /**
  688.      * Boolean flag used to force RTL or LTR string direction.
  689.      * @protected
  690.      * @since 2.0.000
  691.      */
  692.     protected $tmprtl false;
  693.     // --- Variables used for document encryption:
  694.     /**
  695.      * IBoolean flag indicating whether document is protected.
  696.      * @protected
  697.      * @since 2.0.000 (2008-01-02)
  698.      */
  699.     protected $encrypted;
  700.     /**
  701.      * Array containing encryption settings.
  702.      * @protected
  703.      * @since 5.0.005 (2010-05-11)
  704.      */
  705.     protected $encryptdata = array();
  706.     /**
  707.      * Last RC4 key encrypted (cached for optimisation).
  708.      * @protected
  709.      * @since 2.0.000 (2008-01-02)
  710.      */
  711.     protected $last_enc_key;
  712.     /**
  713.      * Last RC4 computed key.
  714.      * @protected
  715.      * @since 2.0.000 (2008-01-02)
  716.      */
  717.     protected $last_enc_key_c;
  718.     /**
  719.      * File ID (used on document trailer).
  720.      * @protected
  721.      * @since 5.0.005 (2010-05-12)
  722.      */
  723.     protected $file_id;
  724.     // --- bookmark ---
  725.     /**
  726.      * Outlines for bookmark.
  727.      * @protected
  728.      * @since 2.1.002 (2008-02-12)
  729.      */
  730.     protected $outlines = array();
  731.     /**
  732.      * Outline root for bookmark.
  733.      * @protected
  734.      * @since 2.1.002 (2008-02-12)
  735.      */
  736.     protected $OutlineRoot;
  737.     // --- javascript and form ---
  738.     /**
  739.      * Javascript code.
  740.      * @protected
  741.      * @since 2.1.002 (2008-02-12)
  742.      */
  743.     protected $javascript '';
  744.     /**
  745.      * Javascript counter.
  746.      * @protected
  747.      * @since 2.1.002 (2008-02-12)
  748.      */
  749.     protected $n_js;
  750.     /**
  751.      * line through state
  752.      * @protected
  753.      * @since 2.8.000 (2008-03-19)
  754.      */
  755.     protected $linethrough;
  756.     /**
  757.      * Array with additional document-wide usage rights for the document.
  758.      * @protected
  759.      * @since 5.8.014 (2010-08-23)
  760.      */
  761.     protected $ur = array();
  762.     /**
  763.      * DPI (Dot Per Inch) Document Resolution (do not change).
  764.      * @protected
  765.      * @since 3.0.000 (2008-03-27)
  766.      */
  767.     protected $dpi 72;
  768.     /**
  769.      * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  770.      * @protected
  771.      * @since 3.0.000 (2008-03-27)
  772.      */
  773.     protected $newpagegroup = array();
  774.     /**
  775.      * Array that contains the number of pages in each page group.
  776.      * @protected
  777.      * @since 3.0.000 (2008-03-27)
  778.      */
  779.     protected $pagegroups = array();
  780.     /**
  781.      * Current page group number.
  782.      * @protected
  783.      * @since 3.0.000 (2008-03-27)
  784.      */
  785.     protected $currpagegroup 0;
  786.     /**
  787.      * Array of transparency objects and parameters.
  788.      * @protected
  789.      * @since 3.0.000 (2008-03-27)
  790.      */
  791.     protected $extgstates;
  792.     /**
  793.      * Set the default JPEG compression quality (1-100).
  794.      * @protected
  795.      * @since 3.0.000 (2008-03-27)
  796.      */
  797.     protected $jpeg_quality;
  798.     /**
  799.      * Default cell height ratio.
  800.      * @protected
  801.      * @since 3.0.014 (2008-05-23)
  802.      * @var float
  803.      */
  804.     protected $cell_height_ratio K_CELL_HEIGHT_RATIO;
  805.     /**
  806.      * PDF viewer preferences.
  807.      * @protected
  808.      * @since 3.1.000 (2008-06-09)
  809.      */
  810.     protected $viewer_preferences;
  811.     /**
  812.      * A name object specifying how the document should be displayed when opened.
  813.      * @protected
  814.      * @since 3.1.000 (2008-06-09)
  815.      */
  816.     protected $PageMode;
  817.     /**
  818.      * Array for storing gradient information.
  819.      * @protected
  820.      * @since 3.1.000 (2008-06-09)
  821.      */
  822.     protected $gradients = array();
  823.     /**
  824.      * Array used to store positions inside the pages buffer (keys are the page numbers).
  825.      * @protected
  826.      * @since 3.2.000 (2008-06-26)
  827.      */
  828.     protected $intmrk = array();
  829.     /**
  830.      * Array used to store positions inside the pages buffer (keys are the page numbers).
  831.      * @protected
  832.      * @since 5.7.000 (2010-08-03)
  833.      */
  834.     protected $bordermrk = array();
  835.     /**
  836.      * Array used to store page positions to track empty pages (keys are the page numbers).
  837.      * @protected
  838.      * @since 5.8.007 (2010-08-18)
  839.      */
  840.     protected $emptypagemrk = array();
  841.     /**
  842.      * Array used to store content positions inside the pages buffer (keys are the page numbers).
  843.      * @protected
  844.      * @since 4.6.021 (2009-07-20)
  845.      */
  846.     protected $cntmrk = array();
  847.     /**
  848.      * Array used to store footer positions of each page.
  849.      * @protected
  850.      * @since 3.2.000 (2008-07-01)
  851.      */
  852.     protected $footerpos = array();
  853.     /**
  854.      * Array used to store footer length of each page.
  855.      * @protected
  856.      * @since 4.0.014 (2008-07-29)
  857.      */
  858.     protected $footerlen = array();
  859.     /**
  860.      * Boolean flag to indicate if a new line is created.
  861.      * @protected
  862.      * @since 3.2.000 (2008-07-01)
  863.      */
  864.     protected $newline true;
  865.     /**
  866.      * End position of the latest inserted line.
  867.      * @protected
  868.      * @since 3.2.000 (2008-07-01)
  869.      */
  870.     protected $endlinex 0;
  871.     /**
  872.      * PDF string for width value of the last line.
  873.      * @protected
  874.      * @since 4.0.006 (2008-07-16)
  875.      */
  876.     protected $linestyleWidth '';
  877.     /**
  878.      * PDF string for CAP value of the last line.
  879.      * @protected
  880.      * @since 4.0.006 (2008-07-16)
  881.      */
  882.     protected $linestyleCap '0 J';
  883.     /**
  884.      * PDF string for join value of the last line.
  885.      * @protected
  886.      * @since 4.0.006 (2008-07-16)
  887.      */
  888.     protected $linestyleJoin '0 j';
  889.     /**
  890.      * PDF string for dash value of the last line.
  891.      * @protected
  892.      * @since 4.0.006 (2008-07-16)
  893.      */
  894.     protected $linestyleDash '[] 0 d';
  895.     /**
  896.      * Boolean flag to indicate if marked-content sequence is open.
  897.      * @protected
  898.      * @since 4.0.013 (2008-07-28)
  899.      */
  900.     protected $openMarkedContent false;
  901.     /**
  902.      * Count the latest inserted vertical spaces on HTML.
  903.      * @protected
  904.      * @since 4.0.021 (2008-08-24)
  905.      */
  906.     protected $htmlvspace 0;
  907.     /**
  908.      * Array of Spot colors.
  909.      * @protected
  910.      * @since 4.0.024 (2008-09-12)
  911.      */
  912.     protected $spot_colors = array();
  913.     /**
  914.      * Symbol used for HTML unordered list items.
  915.      * @protected
  916.      * @since 4.0.028 (2008-09-26)
  917.      */
  918.     protected $lisymbol '';
  919.     /**
  920.      * String used to mark the beginning and end of EPS image blocks.
  921.      * @protected
  922.      * @since 4.1.000 (2008-10-18)
  923.      */
  924.     protected $epsmarker 'x#!#EPS#!#x';
  925.     /**
  926.      * Array of transformation matrix.
  927.      * @protected
  928.      * @since 4.2.000 (2008-10-29)
  929.      */
  930.     protected $transfmatrix = array();
  931.     /**
  932.      * Current key for transformation matrix.
  933.      * @protected
  934.      * @since 4.8.005 (2009-09-17)
  935.      */
  936.     protected $transfmatrix_key 0;
  937.     /**
  938.      * Booklet mode for double-sided pages.
  939.      * @protected
  940.      * @since 4.2.000 (2008-10-29)
  941.      */
  942.     protected $booklet false;
  943.     /**
  944.      * Epsilon value used for float calculations.
  945.      * @protected
  946.      * @since 4.2.000 (2008-10-29)
  947.      */
  948.     protected $feps 0.005;
  949.     /**
  950.      * Array used for custom vertical spaces for HTML tags.
  951.      * @protected
  952.      * @since 4.2.001 (2008-10-30)
  953.      */
  954.     protected $tagvspaces = array();
  955.     /**
  956.      * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  957.      * @protected
  958.      * @since 4.2.007 (2008-11-12)
  959.      */
  960.     protected $customlistindent = -1;
  961.     /**
  962.      * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  963.      * @protected
  964.      * @since 4.2.010 (2008-11-14)
  965.      */
  966.     protected $opencell true;
  967.     /**
  968.      * Array of files to embedd.
  969.      * @protected
  970.      * @since 4.4.000 (2008-12-07)
  971.      */
  972.     protected $embeddedfiles = array();
  973.     /**
  974.      * Boolean flag to indicate if we are inside a PRE tag.
  975.      * @protected
  976.      * @since 4.4.001 (2008-12-08)
  977.      */
  978.     protected $premode false;
  979.     /**
  980.      * Array used to store positions of graphics transformation blocks inside the page buffer.
  981.      * keys are the page numbers
  982.      * @protected
  983.      * @since 4.4.002 (2008-12-09)
  984.      */
  985.     protected $transfmrk = array();
  986.     /**
  987.      * Default color for html links.
  988.      * @protected
  989.      * @since 4.4.003 (2008-12-09)
  990.      */
  991.     protected $htmlLinkColorArray = array(00255);
  992.     /**
  993.      * Default font style to add to html links.
  994.      * @protected
  995.      * @since 4.4.003 (2008-12-09)
  996.      */
  997.     protected $htmlLinkFontStyle 'U';
  998.     /**
  999.      * Counts the number of pages.
  1000.      * @protected
  1001.      * @since 4.5.000 (2008-12-31)
  1002.      */
  1003.     protected $numpages 0;
  1004.     /**
  1005.      * Array containing page lengths in bytes.
  1006.      * @protected
  1007.      * @since 4.5.000 (2008-12-31)
  1008.      */
  1009.     protected $pagelen = array();
  1010.     /**
  1011.      * Counts the number of pages.
  1012.      * @protected
  1013.      * @since 4.5.000 (2008-12-31)
  1014.      */
  1015.     protected $numimages 0;
  1016.     /**
  1017.      * Store the image keys.
  1018.      * @protected
  1019.      * @since 4.5.000 (2008-12-31)
  1020.      */
  1021.     protected $imagekeys = array();
  1022.     /**
  1023.      * Length of the buffer in bytes.
  1024.      * @protected
  1025.      * @since 4.5.000 (2008-12-31)
  1026.      */
  1027.     protected $bufferlen 0;
  1028.     /**
  1029.      * Counts the number of fonts.
  1030.      * @protected
  1031.      * @since 4.5.000 (2009-01-02)
  1032.      */
  1033.     protected $numfonts 0;
  1034.     /**
  1035.      * Store the font keys.
  1036.      * @protected
  1037.      * @since 4.5.000 (2009-01-02)
  1038.      */
  1039.     protected $fontkeys = array();
  1040.     /**
  1041.      * Store the font object IDs.
  1042.      * @protected
  1043.      * @since 4.8.001 (2009-09-09)
  1044.      */
  1045.     protected $font_obj_ids = array();
  1046.     /**
  1047.      * Store the fage status (true when opened, false when closed).
  1048.      * @protected
  1049.      * @since 4.5.000 (2009-01-02)
  1050.      */
  1051.     protected $pageopen = array();
  1052.     /**
  1053.      * Default monospace font.
  1054.      * @protected
  1055.      * @since 4.5.025 (2009-03-10)
  1056.      */
  1057.     protected $default_monospaced_font 'courier';
  1058.     /**
  1059.      * Cloned copy of the current class object.
  1060.      * @protected
  1061.      * @since 4.5.029 (2009-03-19)
  1062.      */
  1063.     protected $objcopy;
  1064.     /**
  1065.      * Array used to store the lengths of cache files.
  1066.      * @protected
  1067.      * @since 4.5.029 (2009-03-19)
  1068.      */
  1069.     protected $cache_file_length = array();
  1070.     /**
  1071.      * Table header content to be repeated on each new page.
  1072.      * @protected
  1073.      * @since 4.5.030 (2009-03-20)
  1074.      */
  1075.     protected $thead '';
  1076.     /**
  1077.      * Margins used for table header.
  1078.      * @protected
  1079.      * @since 4.5.030 (2009-03-20)
  1080.      */
  1081.     protected $theadMargins = array();
  1082.     /**
  1083.      * Boolean flag to enable document digital signature.
  1084.      * @protected
  1085.      * @since 4.6.005 (2009-04-24)
  1086.      */
  1087.     protected $sign false;
  1088.     /**
  1089.      * Digital signature data.
  1090.      * @protected
  1091.      * @since 4.6.005 (2009-04-24)
  1092.      */
  1093.     protected $signature_data = array();
  1094.     /**
  1095.      * Digital signature max length.
  1096.      * @protected
  1097.      * @since 4.6.005 (2009-04-24)
  1098.      */
  1099.     protected $signature_max_length 11742;
  1100.     /**
  1101.      * Data for digital signature appearance.
  1102.      * @protected
  1103.      * @since 5.3.011 (2010-06-16)
  1104.      */
  1105.     protected $signature_appearance = array('page' => 1'rect' => '0 0 0 0');
  1106.     /**
  1107.      * Array of empty digital signature appearances.
  1108.      * @protected
  1109.      * @since 5.9.101 (2011-07-06)
  1110.      */
  1111.     protected $empty_signature_appearance = array();
  1112.     /**
  1113.      * Boolean flag to enable document timestamping with TSA.
  1114.      * @protected
  1115.      * @since 6.0.085 (2014-06-19)
  1116.      */
  1117.     protected $tsa_timestamp false;
  1118.     /**
  1119.      * Timestamping data.
  1120.      * @protected
  1121.      * @since 6.0.085 (2014-06-19)
  1122.      */
  1123.     protected $tsa_data = array();
  1124.     /**
  1125.      * Regular expression used to find blank characters (required for word-wrapping).
  1126.      * @protected
  1127.      * @since 4.6.006 (2009-04-28)
  1128.      */
  1129.     protected $re_spaces '/[^\S\xa0]/';
  1130.     /**
  1131.      * Array of $re_spaces parts.
  1132.      * @protected
  1133.      * @since 5.5.011 (2010-07-09)
  1134.      */
  1135.     protected $re_space = array('p' => '[^\S\xa0]''m' => '');
  1136.     /**
  1137.      * Digital signature object ID.
  1138.      * @protected
  1139.      * @since 4.6.022 (2009-06-23)
  1140.      */
  1141.     protected $sig_obj_id 0;
  1142.     /**
  1143.      * ID of page objects.
  1144.      * @protected
  1145.      * @since 4.7.000 (2009-08-29)
  1146.      */
  1147.     protected $page_obj_id = array();
  1148.     /**
  1149.      * List of form annotations IDs.
  1150.      * @protected
  1151.      * @since 4.8.000 (2009-09-07)
  1152.      */
  1153.     protected $form_obj_id = array();
  1154.     /**
  1155.      * Deafult Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. Annotation options can be directly specified using the 'aopt' entry.
  1156.      * @protected
  1157.      * @since 4.8.000 (2009-09-07)
  1158.      */
  1159.     protected $default_form_prop = array('lineWidth'=>1'borderStyle'=>'solid''fillColor'=>array(255255255), 'strokeColor'=>array(128128128));
  1160.     /**
  1161.      * Javascript objects array.
  1162.      * @protected
  1163.      * @since 4.8.000 (2009-09-07)
  1164.      */
  1165.     protected $js_objects = array();
  1166.     /**
  1167.      * Current form action (used during XHTML rendering).
  1168.      * @protected
  1169.      * @since 4.8.000 (2009-09-07)
  1170.      */
  1171.     protected $form_action '';
  1172.     /**
  1173.      * Current form encryption type (used during XHTML rendering).
  1174.      * @protected
  1175.      * @since 4.8.000 (2009-09-07)
  1176.      */
  1177.     protected $form_enctype 'application/x-www-form-urlencoded';
  1178.     /**
  1179.      * Current method to submit forms.
  1180.      * @protected
  1181.      * @since 4.8.000 (2009-09-07)
  1182.      */
  1183.     protected $form_mode 'post';
  1184.     /**
  1185.      * List of fonts used on form fields (fontname => fontkey).
  1186.      * @protected
  1187.      * @since 4.8.001 (2009-09-09)
  1188.      */
  1189.     protected $annotation_fonts = array();
  1190.     /**
  1191.      * List of radio buttons parent objects.
  1192.      * @protected
  1193.      * @since 4.8.001 (2009-09-09)
  1194.      */
  1195.     protected $radiobutton_groups = array();
  1196.     /**
  1197.      * List of radio group objects IDs.
  1198.      * @protected
  1199.      * @since 4.8.001 (2009-09-09)
  1200.      */
  1201.     protected $radio_groups = array();
  1202.     /**
  1203.      * Text indentation value (used for text-indent CSS attribute).
  1204.      * @protected
  1205.      * @since 4.8.006 (2009-09-23)
  1206.      */
  1207.     protected $textindent 0;
  1208.     /**
  1209.      * Store page number when startTransaction() is called.
  1210.      * @protected
  1211.      * @since 4.8.006 (2009-09-23)
  1212.      */
  1213.     protected $start_transaction_page 0;
  1214.     /**
  1215.      * Store Y position when startTransaction() is called.
  1216.      * @protected
  1217.      * @since 4.9.001 (2010-03-28)
  1218.      */
  1219.     protected $start_transaction_y 0;
  1220.     /**
  1221.      * True when we are printing the thead section on a new page.
  1222.      * @protected
  1223.      * @since 4.8.027 (2010-01-25)
  1224.      */
  1225.     protected $inthead false;
  1226.     /**
  1227.      * Array of column measures (width, space, starting Y position).
  1228.      * @protected
  1229.      * @since 4.9.001 (2010-03-28)
  1230.      */
  1231.     protected $columns = array();
  1232.     /**
  1233.      * Number of colums.
  1234.      * @protected
  1235.      * @since 4.9.001 (2010-03-28)
  1236.      */
  1237.     protected $num_columns 1;
  1238.     /**
  1239.      * Current column number.
  1240.      * @protected
  1241.      * @since 4.9.001 (2010-03-28)
  1242.      */
  1243.     protected $current_column 0;
  1244.     /**
  1245.      * Starting page for columns.
  1246.      * @protected
  1247.      * @since 4.9.001 (2010-03-28)
  1248.      */
  1249.     protected $column_start_page 0;
  1250.     /**
  1251.      * Maximum page and column selected.
  1252.      * @protected
  1253.      * @since 5.8.000 (2010-08-11)
  1254.      */
  1255.     protected $maxselcol = array('page' => 0'column' => 0);
  1256.     /**
  1257.      * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1258.      * @protected
  1259.      * @since 5.8.000 (2010-08-11)
  1260.      */
  1261.     protected $colxshift = array('x' => 0's' => array('H' => 0'V' => 0), 'p' => array('L' => 0'T' => 0'R' => 0'B' => 0));
  1262.     /**
  1263.      * Text rendering mode: 0 = Fill text; 1 = Stroke text; 2 = Fill, then stroke text; 3 = Neither fill nor stroke text (invisible); 4 = Fill text and add to path for clipping; 5 = Stroke text and add to path for clipping; 6 = Fill, then stroke text and add to path for clipping; 7 = Add text to path for clipping.
  1264.      * @protected
  1265.      * @since 4.9.008 (2010-04-03)
  1266.      */
  1267.     protected $textrendermode 0;
  1268.     /**
  1269.      * Text stroke width in doc units.
  1270.      * @protected
  1271.      * @since 4.9.008 (2010-04-03)
  1272.      */
  1273.     protected $textstrokewidth 0;
  1274.     /**
  1275.      * Current stroke color.
  1276.      * @protected
  1277.      * @since 4.9.008 (2010-04-03)
  1278.      */
  1279.     protected $strokecolor;
  1280.     /**
  1281.      * Default unit of measure for document.
  1282.      * @protected
  1283.      * @since 5.0.000 (2010-04-22)
  1284.      */
  1285.     protected $pdfunit 'mm';
  1286.     /**
  1287.      * Boolean flag true when we are on TOC (Table Of Content) page.
  1288.      * @protected
  1289.      */
  1290.     protected $tocpage false;
  1291.     /**
  1292.      * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1293.      * @protected
  1294.      * @since 5.0.000 (2010-04-26)
  1295.      */
  1296.     protected $rasterize_vector_images false;
  1297.     /**
  1298.      * Boolean flag: if true enables font subsetting by default.
  1299.      * @protected
  1300.      * @since 5.3.002 (2010-06-07)
  1301.      */
  1302.     protected $font_subsetting true;
  1303.     /**
  1304.      * Array of default graphic settings.
  1305.      * @protected
  1306.      * @since 5.5.008 (2010-07-02)
  1307.      */
  1308.     protected $default_graphic_vars = array();
  1309.     /**
  1310.      * Array of XObjects.
  1311.      * @protected
  1312.      * @since 5.8.014 (2010-08-23)
  1313.      */
  1314.     protected $xobjects = array();
  1315.     /**
  1316.      * Boolean value true when we are inside an XObject.
  1317.      * @protected
  1318.      * @since 5.8.017 (2010-08-24)
  1319.      */
  1320.     protected $inxobj false;
  1321.     /**
  1322.      * Current XObject ID.
  1323.      * @protected
  1324.      * @since 5.8.017 (2010-08-24)
  1325.      */
  1326.     protected $xobjid '';
  1327.     /**
  1328.      * Percentage of character stretching.
  1329.      * @protected
  1330.      * @since 5.9.000 (2010-09-29)
  1331.      */
  1332.     protected $font_stretching 100;
  1333.     /**
  1334.      * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1335.      * @protected
  1336.      * @since 5.9.000 (2010-09-29)
  1337.      */
  1338.     protected $font_spacing 0;
  1339.     /**
  1340.      * Array of no-write regions.
  1341.      * ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right)
  1342.      * @protected
  1343.      * @since 5.9.003 (2010-10-14)
  1344.      */
  1345.     protected $page_regions = array();
  1346.     /**
  1347.      * Boolean value true when page region check is active.
  1348.      * @protected
  1349.      */
  1350.     protected $check_page_regions true;
  1351.     /**
  1352.      * Array of PDF layers data.
  1353.      * @protected
  1354.      * @since 5.9.102 (2011-07-13)
  1355.      */
  1356.     protected $pdflayers = array();
  1357.     /**
  1358.      * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1359.      * @protected
  1360.      * @since 5.9.097 (2011-06-23)
  1361.      */
  1362.     protected $dests = array();
  1363.     /**
  1364.      * Object ID for Named Destinations
  1365.      * @protected
  1366.      * @since 5.9.097 (2011-06-23)
  1367.      */
  1368.     protected $n_dests;
  1369.     /**
  1370.      * Embedded Files Names
  1371.      * @protected
  1372.      * @since 5.9.204 (2013-01-23)
  1373.      */
  1374.     protected $efnames = array();
  1375.     /**
  1376.      * Directory used for the last SVG image.
  1377.      * @protected
  1378.      * @since 5.0.000 (2010-05-05)
  1379.      */
  1380.     protected $svgdir '';
  1381.     /**
  1382.      *  Deafult unit of measure for SVG.
  1383.      * @protected
  1384.      * @since 5.0.000 (2010-05-02)
  1385.      */
  1386.     protected $svgunit 'px';
  1387.     /**
  1388.      * Array of SVG gradients.
  1389.      * @protected
  1390.      * @since 5.0.000 (2010-05-02)
  1391.      */
  1392.     protected $svggradients = array();
  1393.     /**
  1394.      * ID of last SVG gradient.
  1395.      * @protected
  1396.      * @since 5.0.000 (2010-05-02)
  1397.      */
  1398.     protected $svggradientid 0;
  1399.     /**
  1400.      * Boolean value true when in SVG defs group.
  1401.      * @protected
  1402.      * @since 5.0.000 (2010-05-02)
  1403.      */
  1404.     protected $svgdefsmode false;
  1405.     /**
  1406.      * Array of SVG defs.
  1407.      * @protected
  1408.      * @since 5.0.000 (2010-05-02)
  1409.      */
  1410.     protected $svgdefs = array();
  1411.     /**
  1412.      * Boolean value true when in SVG clipPath tag.
  1413.      * @protected
  1414.      * @since 5.0.000 (2010-04-26)
  1415.      */
  1416.     protected $svgclipmode false;
  1417.     /**
  1418.      * Array of SVG clipPath commands.
  1419.      * @protected
  1420.      * @since 5.0.000 (2010-05-02)
  1421.      */
  1422.     protected $svgclippaths = array();
  1423.     /**
  1424.      * Array of SVG clipPath tranformation matrix.
  1425.      * @protected
  1426.      * @since 5.8.022 (2010-08-31)
  1427.      */
  1428.     protected $svgcliptm = array();
  1429.     /**
  1430.      * ID of last SVG clipPath.
  1431.      * @protected
  1432.      * @since 5.0.000 (2010-05-02)
  1433.      */
  1434.     protected $svgclipid 0;
  1435.     /**
  1436.      * SVG text.
  1437.      * @protected
  1438.      * @since 5.0.000 (2010-05-02)
  1439.      */
  1440.     protected $svgtext '';
  1441.     /**
  1442.      * SVG text properties.
  1443.      * @protected
  1444.      * @since 5.8.013 (2010-08-23)
  1445.      */
  1446.     protected $svgtextmode = array();
  1447.     /**
  1448.      * Array of SVG properties.
  1449.      * @protected
  1450.      * @since 5.0.000 (2010-05-02)
  1451.      */
  1452.     protected $svgstyles = array(array(
  1453.         'alignment-baseline' => 'auto',
  1454.         'baseline-shift' => 'baseline',
  1455.         'clip' => 'auto',
  1456.         'clip-path' => 'none',
  1457.         'clip-rule' => 'nonzero',
  1458.         'color' => 'black',
  1459.         'color-interpolation' => 'sRGB',
  1460.         'color-interpolation-filters' => 'linearRGB',
  1461.         'color-profile' => 'auto',
  1462.         'color-rendering' => 'auto',
  1463.         'cursor' => 'auto',
  1464.         'direction' => 'ltr',
  1465.         'display' => 'inline',
  1466.         'dominant-baseline' => 'auto',
  1467.         'enable-background' => 'accumulate',
  1468.         'fill' => 'black',
  1469.         'fill-opacity' => 1,
  1470.         'fill-rule' => 'nonzero',
  1471.         'filter' => 'none',
  1472.         'flood-color' => 'black',
  1473.         'flood-opacity' => 1,
  1474.         'font' => '',
  1475.         'font-family' => 'helvetica',
  1476.         'font-size' => 'medium',
  1477.         'font-size-adjust' => 'none',
  1478.         'font-stretch' => 'normal',
  1479.         'font-style' => 'normal',
  1480.         'font-variant' => 'normal',
  1481.         'font-weight' => 'normal',
  1482.         'glyph-orientation-horizontal' => '0deg',
  1483.         'glyph-orientation-vertical' => 'auto',
  1484.         'image-rendering' => 'auto',
  1485.         'kerning' => 'auto',
  1486.         'letter-spacing' => 'normal',
  1487.         'lighting-color' => 'white',
  1488.         'marker' => '',
  1489.         'marker-end' => 'none',
  1490.         'marker-mid' => 'none',
  1491.         'marker-start' => 'none',
  1492.         'mask' => 'none',
  1493.         'opacity' => 1,
  1494.         'overflow' => 'auto',
  1495.         'pointer-events' => 'visiblePainted',
  1496.         'shape-rendering' => 'auto',
  1497.         'stop-color' => 'black',
  1498.         'stop-opacity' => 1,
  1499.         'stroke' => 'none',
  1500.         'stroke-dasharray' => 'none',
  1501.         'stroke-dashoffset' => 0,
  1502.         'stroke-linecap' => 'butt',
  1503.         'stroke-linejoin' => 'miter',
  1504.         'stroke-miterlimit' => 4,
  1505.         'stroke-opacity' => 1,
  1506.         'stroke-width' => 1,
  1507.         'text-anchor' => 'start',
  1508.         'text-decoration' => 'none',
  1509.         'text-rendering' => 'auto',
  1510.         'unicode-bidi' => 'normal',
  1511.         'visibility' => 'visible',
  1512.         'word-spacing' => 'normal',
  1513.         'writing-mode' => 'lr-tb',
  1514.         'text-color' => 'black',
  1515.         'transfmatrix' => array(100100)
  1516.         ));
  1517.     /**
  1518.      * If true force sRGB color profile for all document.
  1519.      * @protected
  1520.      * @since 5.9.121 (2011-09-28)
  1521.      */
  1522.     protected $force_srgb false;
  1523.     /**
  1524.      * If true set the document to PDF/A mode.
  1525.      * @protected
  1526.      * @since 5.9.121 (2011-09-27)
  1527.      */
  1528.     protected $pdfa_mode false;
  1529.     /**
  1530.      * version of PDF/A mode (1 - 3).
  1531.      * @protected
  1532.      * @since 6.2.26 (2019-03-12)
  1533.      */
  1534.     protected $pdfa_version 1;
  1535.     /**
  1536.      * Document creation date-time
  1537.      * @protected
  1538.      * @since 5.9.152 (2012-03-22)
  1539.      */
  1540.     protected $doc_creation_timestamp;
  1541.     /**
  1542.      * Document modification date-time
  1543.      * @protected
  1544.      * @since 5.9.152 (2012-03-22)
  1545.      */
  1546.     protected $doc_modification_timestamp;
  1547.     /**
  1548.      * Custom XMP data.
  1549.      * @protected
  1550.      * @since 5.9.128 (2011-10-06)
  1551.      */
  1552.     protected $custom_xmp '';
  1553.     /**
  1554.      * Custom XMP RDF data.
  1555.      * @protected
  1556.      * @since 6.3.0 (2019-09-19)
  1557.      */
  1558.     protected $custom_xmp_rdf '';
  1559.     /**
  1560.      * Overprint mode array.
  1561.      * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1562.      * @protected
  1563.      * @since 5.9.152 (2012-03-23)
  1564.      * @var array<string,bool|int>
  1565.      */
  1566.     protected $overprint = array('OP' => false'op' => false'OPM' => 0);
  1567.     /**
  1568.      * Alpha mode array.
  1569.      * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1570.      * @protected
  1571.      * @since 5.9.152 (2012-03-23)
  1572.      */
  1573.     protected $alpha = array('CA' => 1'ca' => 1'BM' => '/Normal''AIS' => false);
  1574.     /**
  1575.      * Define the page boundaries boxes to be set on document.
  1576.      * @protected
  1577.      * @since 5.9.152 (2012-03-23)
  1578.      */
  1579.     protected $page_boxes = array('MediaBox''CropBox''BleedBox''TrimBox''ArtBox');
  1580.     /**
  1581.      * If true print TCPDF meta link.
  1582.      * @protected
  1583.      * @since 5.9.152 (2012-03-23)
  1584.      */
  1585.     protected $tcpdflink true;
  1586.     /**
  1587.      * Cache array for computed GD gamma values.
  1588.      * @protected
  1589.      * @since 5.9.1632 (2012-06-05)
  1590.      */
  1591.     protected $gdgammacache = array();
  1592.     /**
  1593.      * Cache array for file content
  1594.      * @protected
  1595.      * @var array
  1596.      * @since 6.3.5 (2020-09-28)
  1597.      */
  1598.     protected $fileContentCache = array();
  1599.     /**
  1600.      * Whether to allow local file path in image html tags, when prefixed with file://
  1601.      *
  1602.      * @var bool
  1603.      * @protected
  1604.      * @since 6.4 (2020-07-23)
  1605.      */
  1606.     protected $allowLocalFiles false;
  1607.     //------------------------------------------------------------
  1608.     // METHODS
  1609.     //------------------------------------------------------------
  1610.     /**
  1611.      * This is the class constructor.
  1612.      * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1613.      *
  1614.      * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1615.      * @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.
  1616.      * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  1617.      * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1618.      * @param string $encoding Charset encoding (used only when converting back html entities); default is UTF-8.
  1619.      * @param boolean $diskcache DEPRECATED FEATURE
  1620.      * @param false|integer $pdfa If not false, set the document to PDF/A mode and the good version (1 or 3).
  1621.      * @public
  1622.      * @see getPageSizeFromFormat(), setPageFormat()
  1623.      */
  1624.     public function __construct($orientation='P'$unit='mm'$format='A4'$unicode=true$encoding='UTF-8'$diskcache=false$pdfa=false) {
  1625.         // set file ID for trailer
  1626.         $serformat = (is_array($format) ? json_encode($format) : $format);
  1627.         $this->file_id md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1628.         $this->font_obj_ids = array();
  1629.         $this->page_obj_id = array();
  1630.         $this->form_obj_id = array();
  1631.         // set pdf/a mode
  1632.         if ($pdfa != false) {
  1633.             $this->pdfa_mode true;
  1634.             $this->pdfa_version $pdfa;  // 1 or 3
  1635.         } else
  1636.             $this->pdfa_mode false;
  1637.         $this->force_srgb false;
  1638.         // set language direction
  1639.         $this->rtl false;
  1640.         $this->tmprtl false;
  1641.         // some checks
  1642.         $this->_dochecks();
  1643.         // initialization of properties
  1644.         $this->isunicode $unicode;
  1645.         $this->page 0;
  1646.         $this->transfmrk[0] = array();
  1647.         $this->pagedim = array();
  1648.         $this->2;
  1649.         $this->buffer '';
  1650.         $this->pages = array();
  1651.         $this->state 0;
  1652.         $this->fonts = array();
  1653.         $this->FontFiles = array();
  1654.         $this->diffs = array();
  1655.         $this->images = array();
  1656.         $this->links = array();
  1657.         $this->gradients = array();
  1658.         $this->InFooter false;
  1659.         $this->lasth 0;
  1660.         $this->FontFamily defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1661.         $this->FontStyle '';
  1662.         $this->FontSizePt 12;
  1663.         $this->underline false;
  1664.         $this->overline false;
  1665.         $this->linethrough false;
  1666.         $this->DrawColor '0 G';
  1667.         $this->FillColor '0 g';
  1668.         $this->TextColor '0 g';
  1669.         $this->ColorFlag false;
  1670.         $this->pdflayers = array();
  1671.         // encryption values
  1672.         $this->encrypted false;
  1673.         $this->last_enc_key '';
  1674.         // standard Unicode fonts
  1675.         $this->CoreFonts = array(
  1676.             'courier'=>'Courier',
  1677.             'courierB'=>'Courier-Bold',
  1678.             'courierI'=>'Courier-Oblique',
  1679.             'courierBI'=>'Courier-BoldOblique',
  1680.             'helvetica'=>'Helvetica',
  1681.             'helveticaB'=>'Helvetica-Bold',
  1682.             'helveticaI'=>'Helvetica-Oblique',
  1683.             'helveticaBI'=>'Helvetica-BoldOblique',
  1684.             'times'=>'Times-Roman',
  1685.             'timesB'=>'Times-Bold',
  1686.             'timesI'=>'Times-Italic',
  1687.             'timesBI'=>'Times-BoldItalic',
  1688.             'symbol'=>'Symbol',
  1689.             'zapfdingbats'=>'ZapfDingbats'
  1690.         );
  1691.         // set scale factor
  1692.         $this->setPageUnit($unit);
  1693.         // set page format and orientation
  1694.         $this->setPageFormat($format$orientation);
  1695.         // page margins (1 cm)
  1696.         $margin 28.35 $this->k;
  1697.         $this->setMargins($margin$margin);
  1698.         $this->clMargin $this->lMargin;
  1699.         $this->crMargin $this->rMargin;
  1700.         // internal cell padding
  1701.         $cpadding $margin 10;
  1702.         $this->setCellPaddings($cpadding0$cpadding0);
  1703.         // cell margins
  1704.         $this->setCellMargins(0000);
  1705.         // line width (0.2 mm)
  1706.         $this->LineWidth 0.57 $this->k;
  1707.         $this->linestyleWidth sprintf('%F w', ($this->LineWidth $this->k));
  1708.         $this->linestyleCap '0 J';
  1709.         $this->linestyleJoin '0 j';
  1710.         $this->linestyleDash '[] 0 d';
  1711.         // automatic page break
  1712.         $this->setAutoPageBreak(true, ($margin));
  1713.         // full width display mode
  1714.         $this->setDisplayMode('fullwidth');
  1715.         // compression
  1716.         $this->setCompression();
  1717.         // set default PDF version number
  1718.         $this->setPDFVersion();
  1719.         $this->tcpdflink true;
  1720.         $this->encoding $encoding;
  1721.         $this->HREF = array();
  1722.         $this->getFontsList();
  1723.         $this->fgcolor = array('R' => 0'G' => 0'B' => 0);
  1724.         $this->strokecolor = array('R' => 0'G' => 0'B' => 0);
  1725.         $this->bgcolor = array('R' => 255'G' => 255'B' => 255);
  1726.         $this->extgstates = array();
  1727.         $this->setTextShadow();
  1728.         // signature
  1729.         $this->sign false;
  1730.         $this->tsa_timestamp false;
  1731.         $this->tsa_data = array();
  1732.         $this->signature_appearance = array('page' => 1'rect' => '0 0 0 0''name' => 'Signature');
  1733.         $this->empty_signature_appearance = array();
  1734.         // user's rights
  1735.         $this->ur['enabled'] = false;
  1736.         $this->ur['document'] = '/FullSave';
  1737.         $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1738.         $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1739.         $this->ur['signature'] = '/Modify';
  1740.         $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1741.         $this->ur['formex'] = '';
  1742.         // set default JPEG quality
  1743.         $this->jpeg_quality 75;
  1744.         // initialize some settings
  1745.         TCPDF_FONTS::utf8Bidi(array(), ''false$this->isunicode$this->CurrentFont);
  1746.         // set default font
  1747.         $this->setFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  1748.         $this->setHeaderFont(array($this->FontFamily$this->FontStyle$this->FontSizePt));
  1749.         $this->setFooterFont(array($this->FontFamily$this->FontStyle$this->FontSizePt));
  1750.         // check if PCRE Unicode support is enabled
  1751.         if ($this->isunicode AND (@preg_match('/\pL/u''a') == 1)) {
  1752.             // PCRE unicode support is turned ON
  1753.             // \s     : any whitespace character
  1754.             // \p{Z}  : any separator
  1755.             // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  1756.             // \xa0   : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  1757.             //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
  1758.             $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
  1759.         } else {
  1760.             // PCRE unicode support is turned OFF
  1761.             $this->setSpacesRE('/[^\S\xa0]/');
  1762.         }
  1763.         $this->default_form_prop = array('lineWidth'=>1'borderStyle'=>'solid''fillColor'=>array(255255255), 'strokeColor'=>array(128128128));
  1764.         // set document creation and modification timestamp
  1765.         $this->doc_creation_timestamp time();
  1766.         $this->doc_modification_timestamp $this->doc_creation_timestamp;
  1767.         // get default graphic vars
  1768.         $this->default_graphic_vars $this->getGraphicVars();
  1769.         $this->header_xobj_autoreset false;
  1770.         $this->custom_xmp '';
  1771.         $this->custom_xmp_rdf '';
  1772.     }
  1773.     /**
  1774.      * Default destructor.
  1775.      * @public
  1776.      * @since 1.53.0.TC016
  1777.      */
  1778.     public function __destruct() {
  1779.         // cleanup
  1780.         $this->_destroy(true);
  1781.     }
  1782.     /**
  1783.      * Set the units of measure for the document.
  1784.      * @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.
  1785.      * @public
  1786.      * @since 3.0.015 (2008-06-06)
  1787.      */
  1788.     public function setPageUnit($unit) {
  1789.         $unit strtolower($unit);
  1790.         //Set scale factor
  1791.         switch ($unit) {
  1792.             // points
  1793.             case 'px':
  1794.             case 'pt': {
  1795.                 $this->1;
  1796.                 break;
  1797.             }
  1798.             // millimeters
  1799.             case 'mm': {
  1800.                 $this->$this->dpi 25.4;
  1801.                 break;
  1802.             }
  1803.             // centimeters
  1804.             case 'cm': {
  1805.                 $this->$this->dpi 2.54;
  1806.                 break;
  1807.             }
  1808.             // inches
  1809.             case 'in': {
  1810.                 $this->$this->dpi;
  1811.                 break;
  1812.             }
  1813.             // unsupported unit
  1814.             default : {
  1815.                 $this->Error('Incorrect unit: '.$unit);
  1816.                 break;
  1817.             }
  1818.         }
  1819.         $this->pdfunit $unit;
  1820.         if (isset($this->CurOrientation)) {
  1821.             $this->setPageOrientation($this->CurOrientation);
  1822.         }
  1823.     }
  1824.     /**
  1825.      * Change the format of the current page
  1826.      * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numbers (width, height) or an array containing the following measures and options:<ul>
  1827.      * <li>['format'] = page format name (one of the above);</li>
  1828.      * <li>['Rotate'] : The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li>
  1829.      * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1830.      * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1831.      * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
  1832.      * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
  1833.      * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
  1834.      * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
  1835.      * <li>['CropBox'] : the visible region of default user space:</li>
  1836.      * <li>['CropBox']['llx'] : lower-left x coordinate</li>
  1837.      * <li>['CropBox']['lly'] : lower-left y coordinate</li>
  1838.      * <li>['CropBox']['urx'] : upper-right x coordinate</li>
  1839.      * <li>['CropBox']['ury'] : upper-right y coordinate</li>
  1840.      * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1841.      * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
  1842.      * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
  1843.      * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
  1844.      * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
  1845.      * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1846.      * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
  1847.      * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
  1848.      * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
  1849.      * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
  1850.      * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1851.      * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
  1852.      * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
  1853.      * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
  1854.      * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
  1855.      * <li>['BoxColorInfo'] :specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for each of the possible page boundaries other than the MediaBox:</li>
  1856.      * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1857.      * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1858.      * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1859.      * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1860.      * <li>['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation</li>
  1861.      * <li>['trans']['Dur'] : The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li>
  1862.      * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1863.      * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1864.      * <li>['trans']['Dm'] : (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li>
  1865.      * <li>['trans']['M'] : (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li>
  1866.      * <li>['trans']['Di'] : (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li>
  1867.      * <li>['trans']['SS'] : (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0.</li>
  1868.      * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1869.      * </ul>
  1870.      * @param string $orientation page orientation. Possible values are (case insensitive):<ul>
  1871.      * <li>P or Portrait (default)</li>
  1872.      * <li>L or Landscape</li>
  1873.      * <li>'' (empty string) for automatic orientation</li>
  1874.      * </ul>
  1875.      * @protected
  1876.      * @since 3.0.015 (2008-06-06)
  1877.      * @see getPageSizeFromFormat()
  1878.      */
  1879.     protected function setPageFormat($format$orientation='P') {
  1880.         if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1881.             // remove inherited values
  1882.             unset($this->pagedim[$this->page]);
  1883.         }
  1884.         if (is_string($format)) {
  1885.             // get page measures from format name
  1886.             $pf TCPDF_STATIC::getPageSizeFromFormat($format);
  1887.             $this->fwPt $pf[0];
  1888.             $this->fhPt $pf[1];
  1889.         } else {
  1890.             // the boundaries of the physical medium on which the page shall be displayed or printed
  1891.             if (isset($format['MediaBox'])) {
  1892.                 $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'MediaBox'$format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false$this->k$this->pagedim);
  1893.                 $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1894.                 $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1895.             } else {
  1896.                 if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1897.                     $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1898.                 } else {
  1899.                     if (!isset($format['format'])) {
  1900.                         // default value
  1901.                         $format['format'] = 'A4';
  1902.                     }
  1903.                     $pf TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1904.                 }
  1905.                 $this->fwPt $pf[0];
  1906.                 $this->fhPt $pf[1];
  1907.                 $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'MediaBox'00$this->fwPt$this->fhPttrue$this->k$this->pagedim);
  1908.             }
  1909.             // the visible region of default user space
  1910.             if (isset($format['CropBox'])) {
  1911.                 $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'CropBox'$format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false$this->k$this->pagedim);
  1912.             }
  1913.             // the region to which the contents of the page shall be clipped when output in a production environment
  1914.             if (isset($format['BleedBox'])) {
  1915.                 $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'BleedBox'$format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false$this->k$this->pagedim);
  1916.             }
  1917.             // the intended dimensions of the finished page after trimming
  1918.             if (isset($format['TrimBox'])) {
  1919.                 $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'TrimBox'$format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false$this->k$this->pagedim);
  1920.             }
  1921.             // the page's meaningful content (including potential white space)
  1922.             if (isset($format['ArtBox'])) {
  1923.                 $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'ArtBox'$format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false$this->k$this->pagedim);
  1924.             }
  1925.             // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1926.             if (isset($format['BoxColorInfo'])) {
  1927.                 $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1928.             }
  1929.             if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1930.                 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1931.                 $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1932.             }
  1933.             if (isset($format['PZ'])) {
  1934.                 // The page's preferred zoom (magnification) factor
  1935.                 $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1936.             }
  1937.             if (isset($format['trans'])) {
  1938.                 // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1939.                 if (isset($format['trans']['Dur'])) {
  1940.                     // The page's display duration
  1941.                     $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1942.                 }
  1943.                 $stansition_styles = array('Split''Blinds''Box''Wipe''Dissolve''Glitter''R''Fly''Push''Cover''Uncover''Fade');
  1944.                 if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1945.                     // The transition style that shall be used when moving to this page from another during a presentation
  1946.                     $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1947.                     $valid_effect = array('Split''Blinds');
  1948.                     $valid_vals = array('H''V');
  1949.                     if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1950.                         $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1951.                     }
  1952.                     $valid_effect = array('Split''Box''Fly');
  1953.                     $valid_vals = array('I''O');
  1954.                     if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1955.                         $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1956.                     }
  1957.                     $valid_effect = array('Wipe''Glitter''Fly''Cover''Uncover''Push');
  1958.                     if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1959.                         if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1960.                             OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1961.                             OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1962.                             $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1963.                         }
  1964.                     }
  1965.                     if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1966.                         $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1967.                     }
  1968.                     if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1969.                         $this->pagedim[$this->page]['trans']['B'] = 'true';
  1970.                     }
  1971.                 } else {
  1972.                     $this->pagedim[$this->page]['trans']['S'] = 'R';
  1973.                 }
  1974.                 if (isset($format['trans']['D'])) {
  1975.                     // The duration of the transition effect, in seconds
  1976.                     $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1977.                 } else {
  1978.                     $this->pagedim[$this->page]['trans']['D'] = 1;
  1979.                 }
  1980.             }
  1981.         }
  1982.         $this->setPageOrientation($orientation);
  1983.     }
  1984.     /**
  1985.      * Set page orientation.
  1986.      * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1987.      * @param boolean|null $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1988.      * @param float|null $bottommargin bottom margin of the page.
  1989.      * @public
  1990.      * @since 3.0.015 (2008-06-06)
  1991.      */
  1992.     public function setPageOrientation($orientation$autopagebreak=null$bottommargin=null) {
  1993.         if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  1994.             // the boundaries of the physical medium on which the page shall be displayed or printed
  1995.             $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'MediaBox'00$this->fwPt$this->fhPttrue$this->k$this->pagedim);
  1996.         }
  1997.         if (!isset($this->pagedim[$this->page]['CropBox'])) {
  1998.             // the visible region of default user space
  1999.             $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'CropBox'$this->pagedim[$this->page]['MediaBox']['llx'], $this->pagedim[$this->page]['MediaBox']['lly'], $this->pagedim[$this->page]['MediaBox']['urx'], $this->pagedim[$this->page]['MediaBox']['ury'], true$this->k$this->pagedim);
  2000.         }
  2001.         if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  2002.             // the region to which the contents of the page shall be clipped when output in a production environment
  2003.             $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'BleedBox'$this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true$this->k$this->pagedim);
  2004.         }
  2005.         if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  2006.             // the intended dimensions of the finished page after trimming
  2007.             $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'TrimBox'$this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true$this->k$this->pagedim);
  2008.         }
  2009.         if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  2010.             // the page's meaningful content (including potential white space)
  2011.             $this->pagedim TCPDF_STATIC::setPageBoxes($this->page'ArtBox'$this->pagedim[$this->page]['CropBox']['llx'], $this->pagedim[$this->page]['CropBox']['lly'], $this->pagedim[$this->page]['CropBox']['urx'], $this->pagedim[$this->page]['CropBox']['ury'], true$this->k$this->pagedim);
  2012.         }
  2013.         if (!isset($this->pagedim[$this->page]['Rotate'])) {
  2014.             // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  2015.             $this->pagedim[$this->page]['Rotate'] = 0;
  2016.         }
  2017.         if (!isset($this->pagedim[$this->page]['PZ'])) {
  2018.             // The page's preferred zoom (magnification) factor
  2019.             $this->pagedim[$this->page]['PZ'] = 1;
  2020.         }
  2021.         if ($this->fwPt $this->fhPt) {
  2022.             // landscape
  2023.             $default_orientation 'L';
  2024.         } else {
  2025.             // portrait
  2026.             $default_orientation 'P';
  2027.         }
  2028.         $valid_orientations = array('P''L');
  2029.         if (empty($orientation)) {
  2030.             $orientation $default_orientation;
  2031.         } else {
  2032.             $orientation strtoupper($orientation[0]);
  2033.         }
  2034.         if (in_array($orientation$valid_orientations) AND ($orientation != $default_orientation)) {
  2035.             $this->CurOrientation $orientation;
  2036.             $this->wPt $this->fhPt;
  2037.             $this->hPt $this->fwPt;
  2038.         } else {
  2039.             $this->CurOrientation $default_orientation;
  2040.             $this->wPt $this->fwPt;
  2041.             $this->hPt $this->fhPt;
  2042.         }
  2043.         if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2044.             // swap X and Y coordinates (change page orientation)
  2045.             $this->pagedim TCPDF_STATIC::swapPageBoxCoordinates($this->page$this->pagedim);
  2046.         }
  2047.         $this->= ($this->wPt $this->k);
  2048.         $this->= ($this->hPt $this->k);
  2049.         if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2050.             if (isset($this->AutoPageBreak)) {
  2051.                 $autopagebreak $this->AutoPageBreak;
  2052.             } else {
  2053.                 $autopagebreak true;
  2054.             }
  2055.         }
  2056.         if (TCPDF_STATIC::empty_string($bottommargin)) {
  2057.             if (isset($this->bMargin)) {
  2058.                 $bottommargin $this->bMargin;
  2059.             } else {
  2060.                 // default value = 2 cm
  2061.                 $bottommargin 28.35 $this->k;
  2062.             }
  2063.         }
  2064.         $this->setAutoPageBreak($autopagebreak$bottommargin);
  2065.         // store page dimensions
  2066.         $this->pagedim[$this->page]['w'] = $this->wPt;
  2067.         $this->pagedim[$this->page]['h'] = $this->hPt;
  2068.         $this->pagedim[$this->page]['wk'] = $this->w;
  2069.         $this->pagedim[$this->page]['hk'] = $this->h;
  2070.         $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2071.         $this->pagedim[$this->page]['bm'] = $bottommargin;
  2072.         $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2073.         $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2074.         $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2075.         $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2076.         $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2077.         $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2078.     }
  2079.     /**
  2080.      * Set regular expression to detect withespaces or word separators.
  2081.      * The pattern delimiter must be the forward-slash character "/".
  2082.      * Some example patterns are:
  2083.      * <pre>
  2084.      * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2085.      * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
  2086.      * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
  2087.      * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2088.      *      \s     : any whitespace character
  2089.      *      \p{Z}  : any separator
  2090.      *      \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
  2091.      *      \xa0   : Unicode Character 'NO-BREAK SPACE' (U+00A0)
  2092.      * </pre>
  2093.      * @param string $re regular expression (leave empty for default).
  2094.      * @public
  2095.      * @since 4.6.016 (2009-06-15)
  2096.      */
  2097.     public function setSpacesRE($re='/[^\S\xa0]/') {
  2098.         $this->re_spaces $re;
  2099.         $re_parts explode('/'$re);
  2100.         // get pattern parts
  2101.         $this->re_space = array();
  2102.         if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2103.             $this->re_space['p'] = $re_parts[1];
  2104.         } else {
  2105.             $this->re_space['p'] = '[\s]';
  2106.         }
  2107.         // set pattern modifiers
  2108.         if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2109.             $this->re_space['m'] = $re_parts[2];
  2110.         } else {
  2111.             $this->re_space['m'] = '';
  2112.         }
  2113.     }
  2114.     /**
  2115.      * Enable or disable Right-To-Left language mode
  2116.      * @param boolean $enable if true enable Right-To-Left language mode.
  2117.      * @param boolean $resetx if true reset the X position on direction change.
  2118.      * @public
  2119.      * @since 2.0.000 (2008-01-03)
  2120.      */
  2121.     public function setRTL($enable$resetx=true) {
  2122.         $enable $enable true false;
  2123.         $resetx = ($resetx AND ($enable != $this->rtl));
  2124.         $this->rtl $enable;
  2125.         $this->tmprtl false;
  2126.         if ($resetx) {
  2127.             $this->Ln(0);
  2128.         }
  2129.     }
  2130.     /**
  2131.      * Return the RTL status
  2132.      * @return bool
  2133.      * @public
  2134.      * @since 4.0.012 (2008-07-24)
  2135.      */
  2136.     public function getRTL() {
  2137.         return $this->rtl;
  2138.     }
  2139.     /**
  2140.      * Force temporary RTL language direction
  2141.      * @param false|string $mode can be false, 'L' for LTR or 'R' for RTL
  2142.      * @public
  2143.      * @since 2.1.000 (2008-01-09)
  2144.      */
  2145.     public function setTempRTL($mode) {
  2146.         $newmode false;
  2147.         switch (strtoupper($mode)) {
  2148.             case 'LTR':
  2149.             case 'L': {
  2150.                 if ($this->rtl) {
  2151.                     $newmode 'L';
  2152.                 }
  2153.                 break;
  2154.             }
  2155.             case 'RTL':
  2156.             case 'R': {
  2157.                 if (!$this->rtl) {
  2158.                     $newmode 'R';
  2159.                 }
  2160.                 break;
  2161.             }
  2162.             case false:
  2163.             default: {
  2164.                 $newmode false;
  2165.                 break;
  2166.             }
  2167.         }
  2168.         $this->tmprtl $newmode;
  2169.     }
  2170.     /**
  2171.      * Return the current temporary RTL status
  2172.      * @return bool
  2173.      * @public
  2174.      * @since 4.8.014 (2009-11-04)
  2175.      */
  2176.     public function isRTLTextDir() {
  2177.         return ($this->rtl OR ($this->tmprtl == 'R'));
  2178.     }
  2179.     /**
  2180.      * Set the last cell height.
  2181.      * @param float $h cell height.
  2182.      * @author Nicola Asuni
  2183.      * @public
  2184.      * @since 1.53.0.TC034
  2185.      */
  2186.     public function setLastH($h) {
  2187.         $this->lasth $h;
  2188.     }
  2189.     /**
  2190.      * Return the cell height
  2191.      * @param int $fontsize Font size in internal units
  2192.      * @param boolean $padding If true add cell padding
  2193.      * @public
  2194.      * @return float
  2195.      */
  2196.     public function getCellHeight($fontsize$padding=TRUE) {
  2197.         $height = ($fontsize $this->cell_height_ratio);
  2198.         if ($padding && !empty($this->cell_padding)) {
  2199.             $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  2200.         }
  2201.         return round($height6);
  2202.     }
  2203.     /**
  2204.      * Reset the last cell height.
  2205.      * @public
  2206.      * @since 5.9.000 (2010-10-03)
  2207.      */
  2208.     public function resetLastH() {
  2209.         $this->lasth $this->getCellHeight($this->FontSize);
  2210.     }
  2211.     /**
  2212.      * Get the last cell height.
  2213.      * @return float last cell height
  2214.      * @public
  2215.      * @since 4.0.017 (2008-08-05)
  2216.      */
  2217.     public function getLastH() {
  2218.         return $this->lasth;
  2219.     }
  2220.     /**
  2221.      * Set the adjusting factor to convert pixels to user units.
  2222.      * @param float $scale adjusting factor to convert pixels to user units.
  2223.      * @author Nicola Asuni
  2224.      * @public
  2225.      * @since 1.5.2
  2226.      */
  2227.     public function setImageScale($scale) {
  2228.         $this->imgscale $scale;
  2229.     }
  2230.     /**
  2231.      * Returns the adjusting factor to convert pixels to user units.
  2232.      * @return float adjusting factor to convert pixels to user units.
  2233.      * @author Nicola Asuni
  2234.      * @public
  2235.      * @since 1.5.2
  2236.      */
  2237.     public function getImageScale() {
  2238.         return $this->imgscale;
  2239.     }
  2240.     /**
  2241.      * Returns an array of page dimensions:
  2242.      * <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 user units</li><li>$this->pagedim[$this->page]['hk'] = page height in user units</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><li>$this->pagedim[$this->page]['Rotate'] = The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li><li>$this->pagedim[$this->page]['PZ'] = The page's preferred zoom (magnification) factor.</li><li>$this->pagedim[$this->page]['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation<ul><li>$this->pagedim[$this->page]['trans']['Dur'] = The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li><li>$this->pagedim[$this->page]['trans']['S'] = transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li><li>$this->pagedim[$this->page]['trans']['D'] = The duration of the transition effect, in seconds.</li><li>$this->pagedim[$this->page]['trans']['Dm'] = (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li><li>$this->pagedim[$this->page]['trans']['M'] = (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li><li>$this->pagedim[$this->page]['trans']['Di'] = (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li><li>$this->pagedim[$this->page]['trans']['SS'] = (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0. </li><li>$this->pagedim[$this->page]['trans']['B'] = (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li></ul></li><li>$this->pagedim[$this->page]['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed<ul><li>$this->pagedim[$this->page]['MediaBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['CropBox'] : the visible region of default user space<ul><li>$this->pagedim[$this->page]['CropBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment<ul><li>$this->pagedim[$this->page]['BleedBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['TrimBox'] : the intended dimensions of the finished page after trimming<ul><li>$this->pagedim[$this->page]['TrimBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['ArtBox'] : the extent of the page's meaningful content<ul><li>$this->pagedim[$this->page]['ArtBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['ury'] = upper-right y coordinate in points</li></ul></li></ul>
  2243.      * @param int|null $pagenum page number (empty = current page)
  2244.      * @return array of page dimensions.
  2245.      * @author Nicola Asuni
  2246.      * @public
  2247.      * @since 4.5.027 (2009-03-16)
  2248.      */
  2249.     public function getPageDimensions($pagenum=null) {
  2250.         if (empty($pagenum)) {
  2251.             $pagenum $this->page;
  2252.         }
  2253.         return $this->pagedim[$pagenum];
  2254.     }
  2255.     /**
  2256.      * Returns the page width in units.
  2257.      * @param int|null $pagenum page number (empty = current page)
  2258.      * @return int|float page width.
  2259.      * @author Nicola Asuni
  2260.      * @public
  2261.      * @since 1.5.2
  2262.      * @see getPageDimensions()
  2263.      */
  2264.     public function getPageWidth($pagenum=null) {
  2265.         if (empty($pagenum)) {
  2266.             return $this->w;
  2267.         }
  2268.         return $this->pagedim[$pagenum]['w'];
  2269.     }
  2270.     /**
  2271.      * Returns the page height in units.
  2272.      * @param int|null $pagenum page number (empty = current page)
  2273.      * @return int|float page height.
  2274.      * @author Nicola Asuni
  2275.      * @public
  2276.      * @since 1.5.2
  2277.      * @see getPageDimensions()
  2278.      */
  2279.     public function getPageHeight($pagenum=null) {
  2280.         if (empty($pagenum)) {
  2281.             return $this->h;
  2282.         }
  2283.         return $this->pagedim[$pagenum]['h'];
  2284.     }
  2285.     /**
  2286.      * Returns the page break margin.
  2287.      * @param int|null $pagenum page number (empty = current page)
  2288.      * @return int|float page break margin.
  2289.      * @author Nicola Asuni
  2290.      * @public
  2291.      * @since 1.5.2
  2292.      * @see getPageDimensions()
  2293.      */
  2294.     public function getBreakMargin($pagenum=null) {
  2295.         if (empty($pagenum)) {
  2296.             return $this->bMargin;
  2297.         }
  2298.         return $this->pagedim[$pagenum]['bm'];
  2299.     }
  2300.     /**
  2301.      * Returns the scale factor (number of points in user unit).
  2302.      * @return int scale factor.
  2303.      * @author Nicola Asuni
  2304.      * @public
  2305.      * @since 1.5.2
  2306.      */
  2307.     public function getScaleFactor() {
  2308.         return $this->k;
  2309.     }
  2310.     /**
  2311.      * Defines the left, top and right margins.
  2312.      * @param int|float $left Left margin.
  2313.      * @param int|float $top Top margin.
  2314.      * @param int|float|null $right Right margin. Default value is the left one.
  2315.      * @param boolean $keepmargins if true overwrites the default page margins
  2316.      * @public
  2317.      * @since 1.0
  2318.      * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2319.      */
  2320.     public function setMargins($left$top$right=null$keepmargins=false) {
  2321.         //Set left, top and right margins
  2322.         $this->lMargin $left;
  2323.         $this->tMargin $top;
  2324.         if ($right == -OR $right === null) {
  2325.             $right $left;
  2326.         }
  2327.         $this->rMargin $right;
  2328.         if ($keepmargins) {
  2329.             // overwrite original values
  2330.             $this->original_lMargin $this->lMargin;
  2331.             $this->original_rMargin $this->rMargin;
  2332.         }
  2333.     }
  2334.     /**
  2335.      * 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.
  2336.      * @param int|float $margin The margin.
  2337.      * @public
  2338.      * @since 1.4
  2339.      * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2340.      */
  2341.     public function setLeftMargin($margin) {
  2342.         //Set left margin
  2343.         $this->lMargin $margin;
  2344.         if (($this->page 0) AND ($this->$margin)) {
  2345.             $this->$margin;
  2346.         }
  2347.     }
  2348.     /**
  2349.      * Defines the top margin. The method can be called before creating the first page.
  2350.      * @param int|float $margin The margin.
  2351.      * @public
  2352.      * @since 1.5
  2353.      * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2354.      */
  2355.     public function setTopMargin($margin) {
  2356.         //Set top margin
  2357.         $this->tMargin $margin;
  2358.         if (($this->page 0) AND ($this->$margin)) {
  2359.             $this->$margin;
  2360.         }
  2361.     }
  2362.     /**
  2363.      * Defines the right margin. The method can be called before creating the first page.
  2364.      * @param int|float $margin The margin.
  2365.      * @public
  2366.      * @since 1.5
  2367.      * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2368.      */
  2369.     public function setRightMargin($margin) {
  2370.         $this->rMargin $margin;
  2371.         if (($this->page 0) AND ($this->> ($this->$margin))) {
  2372.             $this->$this->$margin;
  2373.         }
  2374.     }
  2375.     /**
  2376.      * Set the same internal Cell padding for top, right, bottom, left-
  2377.      * @param int|float $pad internal padding.
  2378.      * @public
  2379.      * @since 2.1.000 (2008-01-09)
  2380.      * @see getCellPaddings(), setCellPaddings()
  2381.      */
  2382.     public function setCellPadding($pad) {
  2383.         if ($pad >= 0) {
  2384.             $this->cell_padding['L'] = $pad;
  2385.             $this->cell_padding['T'] = $pad;
  2386.             $this->cell_padding['R'] = $pad;
  2387.             $this->cell_padding['B'] = $pad;
  2388.         }
  2389.     }
  2390.     /**
  2391.      * Set the internal Cell paddings.
  2392.      * @param int|float|null $left left padding
  2393.      * @param int|float|null $top top padding
  2394.      * @param int|float|null $right right padding
  2395.      * @param int|float|null $bottom bottom padding
  2396.      * @public
  2397.      * @since 5.9.000 (2010-10-03)
  2398.      * @see getCellPaddings(), SetCellPadding()
  2399.      */
  2400.     public function setCellPaddings($left=null$top=null$right=null$bottom=null) {
  2401.         if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
  2402.             $this->cell_padding['L'] = $left;
  2403.         }
  2404.         if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
  2405.             $this->cell_padding['T'] = $top;
  2406.         }
  2407.         if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
  2408.             $this->cell_padding['R'] = $right;
  2409.         }
  2410.         if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
  2411.             $this->cell_padding['B'] = $bottom;
  2412.         }
  2413.     }
  2414.     /**
  2415.      * Get the internal Cell padding array.
  2416.      * @return array of padding values
  2417.      * @public
  2418.      * @since 5.9.000 (2010-10-03)
  2419.      * @see setCellPaddings(), SetCellPadding()
  2420.      */
  2421.     public function getCellPaddings() {
  2422.         return $this->cell_padding;
  2423.     }
  2424.     /**
  2425.      * Set the internal Cell margins.
  2426.      * @param int|float|null $left left margin
  2427.      * @param int|float|null $top top margin
  2428.      * @param int|float|null $right right margin
  2429.      * @param int|float|null $bottom bottom margin
  2430.      * @public
  2431.      * @since 5.9.000 (2010-10-03)
  2432.      * @see getCellMargins()
  2433.      */
  2434.     public function setCellMargins($left=null$top=null$right=null$bottom=null) {
  2435.         if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
  2436.             $this->cell_margin['L'] = $left;
  2437.         }
  2438.         if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
  2439.             $this->cell_margin['T'] = $top;
  2440.         }
  2441.         if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
  2442.             $this->cell_margin['R'] = $right;
  2443.         }
  2444.         if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
  2445.             $this->cell_margin['B'] = $bottom;
  2446.         }
  2447.     }
  2448.     /**
  2449.      * Get the internal Cell margin array.
  2450.      * @return array of margin values
  2451.      * @public
  2452.      * @since 5.9.000 (2010-10-03)
  2453.      * @see setCellMargins()
  2454.      */
  2455.     public function getCellMargins() {
  2456.         return $this->cell_margin;
  2457.     }
  2458.     /**
  2459.      * Adjust the internal Cell padding array to take account of the line width.
  2460.      * @param string|array|int|bool $brd Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  2461.      * @return void|array array of adjustments
  2462.      * @public
  2463.      * @since 5.9.000 (2010-10-03)
  2464.      */
  2465.     protected function adjustCellPadding($brd=0) {
  2466.         if (empty($brd)) {
  2467.             return;
  2468.         }
  2469.         if (is_string($brd)) {
  2470.             // convert string to array
  2471.             $slen strlen($brd);
  2472.             $newbrd = array();
  2473.             for ($i 0$i $slen; ++$i) {
  2474.                 $newbrd[$brd[$i]] = true;
  2475.             }
  2476.             $brd $newbrd;
  2477.         } elseif (
  2478.             ($brd === 1)
  2479.             || ($brd === true)
  2480.             || (is_numeric($brd) && ((int)$brd 0))
  2481.         ) {
  2482.             $brd = array('LRTB' => true);
  2483.         }
  2484.         if (!is_array($brd)) {
  2485.             return;
  2486.         }
  2487.         // store current cell padding
  2488.         $cp $this->cell_padding;
  2489.         // select border mode
  2490.         if (isset($brd['mode'])) {
  2491.             $mode $brd['mode'];
  2492.             unset($brd['mode']);
  2493.         } else {
  2494.             $mode 'normal';
  2495.         }
  2496.         // process borders
  2497.         foreach ($brd as $border => $style) {
  2498.             $line_width $this->LineWidth;
  2499.             if (is_array($style) && isset($style['width'])) {
  2500.                 // get border width
  2501.                 $line_width $style['width'];
  2502.             }
  2503.             $adj 0// line width inside the cell
  2504.             switch ($mode) {
  2505.                 case 'ext': {
  2506.                     $adj 0;
  2507.                     break;
  2508.                 }
  2509.                 case 'int': {
  2510.                     $adj $line_width;
  2511.                     break;
  2512.                 }
  2513.                 case 'normal':
  2514.                 default: {
  2515.                     $adj = ($line_width 2);
  2516.                     break;
  2517.                 }
  2518.             }
  2519.             // correct internal cell padding if required to avoid overlap between text and lines
  2520.             if (
  2521.                 is_numeric($this->cell_padding['T'])
  2522.                 && ($this->cell_padding['T'] < $adj)
  2523.                 && (strpos($border'T') !== false)
  2524.             ) {
  2525.                 $this->cell_padding['T'] = $adj;
  2526.             }
  2527.             if (
  2528.                 is_numeric($this->cell_padding['R'])
  2529.                 && ($this->cell_padding['R'] < $adj)
  2530.                 && (strpos($border'R') !== false)
  2531.             ) {
  2532.                 $this->cell_padding['R'] = $adj;
  2533.             }
  2534.             if (
  2535.                 is_numeric($this->cell_padding['B'])
  2536.                 && ($this->cell_padding['B'] < $adj)
  2537.                 && (strpos($border'B') !== false)
  2538.             ) {
  2539.                 $this->cell_padding['B'] = $adj;
  2540.             }
  2541.             if (
  2542.                 is_numeric($this->cell_padding['L'])
  2543.                 && ($this->cell_padding['L'] < $adj)
  2544.                 && (strpos($border'L') !== false)
  2545.             ) {
  2546.                 $this->cell_padding['L'] = $adj;
  2547.             }
  2548.         }
  2549.         return array(
  2550.             'T' => ($this->cell_padding['T'] - $cp['T']),
  2551.             'R' => ($this->cell_padding['R'] - $cp['R']),
  2552.             'B' => ($this->cell_padding['B'] - $cp['B']),
  2553.             'L' => ($this->cell_padding['L'] - $cp['L']),
  2554.         );
  2555.     }
  2556.     /**
  2557.      * 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.
  2558.      * @param boolean $auto Boolean indicating if mode should be on or off.
  2559.      * @param float $margin Distance from the bottom of the page.
  2560.      * @public
  2561.      * @since 1.0
  2562.      * @see Cell(), MultiCell(), AcceptPageBreak()
  2563.      */
  2564.     public function setAutoPageBreak($auto$margin=0) {
  2565.         $this->AutoPageBreak $auto true false;
  2566.         $this->bMargin $margin;
  2567.         $this->PageBreakTrigger $this->$margin;
  2568.     }
  2569.     /**
  2570.      * Return the auto-page-break mode (true or false).
  2571.      * @return bool auto-page-break mode
  2572.      * @public
  2573.      * @since 5.9.088
  2574.      */
  2575.     public function getAutoPageBreak() {
  2576.         return $this->AutoPageBreak;
  2577.     }
  2578.     /**
  2579.      * Defines the way the document is to be displayed by the viewer.
  2580.      * @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>
  2581.      * @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>
  2582.      * @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>
  2583.      * @public
  2584.      * @since 1.2
  2585.      */
  2586.     public function setDisplayMode($zoom$layout='SinglePage'$mode='UseNone') {
  2587.         if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2588.             $this->ZoomMode $zoom;
  2589.         } else {
  2590.             $this->Error('Incorrect zoom display mode: '.$zoom);
  2591.         }
  2592.         $this->LayoutMode TCPDF_STATIC::getPageLayoutMode($layout);
  2593.         $this->PageMode TCPDF_STATIC::getPageMode($mode);
  2594.     }
  2595.     /**
  2596.      * 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.
  2597.      * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2598.      * @param boolean $compress Boolean indicating if compression must be enabled.
  2599.      * @public
  2600.      * @since 1.4
  2601.      */
  2602.     public function setCompression($compress=true) {
  2603.         $this->compress false;
  2604.         if (function_exists('gzcompress')) {
  2605.             if ($compress) {
  2606.                 if ( !$this->pdfa_mode) {
  2607.                     $this->compress true;
  2608.                 }
  2609.             }
  2610.         }
  2611.     }
  2612.     /**
  2613.      * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2614.      * @param boolean $mode If true force sRGB output intent.
  2615.      * @public
  2616.      * @since 5.9.121 (2011-09-28)
  2617.      */
  2618.     public function setSRGBmode($mode=false) {
  2619.         $this->force_srgb $mode true false;
  2620.     }
  2621.     /**
  2622.      * Turn on/off Unicode mode for document information dictionary (meta tags).
  2623.      * This has effect only when unicode mode is set to false.
  2624.      * @param boolean $unicode if true set the meta information in Unicode
  2625.      * @since 5.9.027 (2010-12-01)
  2626.      * @public
  2627.      */
  2628.     public function setDocInfoUnicode($unicode=true) {
  2629.         $this->docinfounicode $unicode true false;
  2630.     }
  2631.     /**
  2632.      * Defines the title of the document.
  2633.      * @param string $title The title.
  2634.      * @public
  2635.      * @since 1.2
  2636.      * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2637.      */
  2638.     public function setTitle($title) {
  2639.         $this->title $title;
  2640.     }
  2641.     /**
  2642.      * Defines the subject of the document.
  2643.      * @param string $subject The subject.
  2644.      * @public
  2645.      * @since 1.2
  2646.      * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2647.      */
  2648.     public function setSubject($subject) {
  2649.         $this->subject $subject;
  2650.     }
  2651.     /**
  2652.      * Defines the author of the document.
  2653.      * @param string $author The name of the author.
  2654.      * @public
  2655.      * @since 1.2
  2656.      * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2657.      */
  2658.     public function setAuthor($author) {
  2659.         $this->author $author;
  2660.     }
  2661.     /**
  2662.      * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2663.      * @param string $keywords The list of keywords.
  2664.      * @public
  2665.      * @since 1.2
  2666.      * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2667.      */
  2668.     public function setKeywords($keywords) {
  2669.         $this->keywords $keywords;
  2670.     }
  2671.     /**
  2672.      * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2673.      * @param string $creator The name of the creator.
  2674.      * @public
  2675.      * @since 1.2
  2676.      * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2677.      */
  2678.     public function setCreator($creator) {
  2679.         $this->creator $creator;
  2680.     }
  2681.     /**
  2682.      * Whether to allow local file path in image html tags, when prefixed with file://
  2683.      *
  2684.      * @param bool $allowLocalFiles true, when local files should be allowed. Otherwise false.
  2685.      * @public
  2686.      * @since 6.4
  2687.      */
  2688.     public function setAllowLocalFiles($allowLocalFiles) {
  2689.         $this->allowLocalFiles = (bool) $allowLocalFiles;
  2690.     }
  2691.     /**
  2692.      * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2693.      * @param string $msg The error message
  2694.      * @public
  2695.      * @since 1.0
  2696.      */
  2697.     public function Error($msg) {
  2698.         // unset all class variables
  2699.         $this->_destroy(true);
  2700.         if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2701.             die('<strong>TCPDF ERROR: </strong>'.$msg);
  2702.         } else {
  2703.             throw new Exception('TCPDF ERROR: '.$msg);
  2704.         }
  2705.     }
  2706.     /**
  2707.      * This method begins the generation of the PDF document.
  2708.      * It is not necessary to call it explicitly because AddPage() does it automatically.
  2709.      * Note: no page is created by this method
  2710.      * @public
  2711.      * @since 1.0
  2712.      * @see AddPage(), Close()
  2713.      */
  2714.     public function Open() {
  2715.         $this->state 1;
  2716.     }
  2717.     /**
  2718.      * Terminates the PDF document.
  2719.      * It is not necessary to call this method explicitly because Output() does it automatically.
  2720.      * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2721.      * @public
  2722.      * @since 1.0
  2723.      * @see Open(), Output()
  2724.      */
  2725.     public function Close() {
  2726.         if ($this->state == 3) {
  2727.             return;
  2728.         }
  2729.         if ($this->page == 0) {
  2730.             $this->AddPage();
  2731.         }
  2732.         $this->endLayer();
  2733.         if ($this->tcpdflink) {
  2734.             // save current graphic settings
  2735.             $gvars $this->getGraphicVars();
  2736.             $this->setEqualColumns();
  2737.             $this->lastpage(true);
  2738.             $this->setAutoPageBreak(false);
  2739.             $this->0;
  2740.             $this->$this->- ($this->k);
  2741.             $this->lMargin 0;
  2742.             $this->_outSaveGraphicsState();
  2743.             $font defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2744.             $this->setFont($font''1);
  2745.             $this->setTextRenderingMode(0falsefalse);
  2746.             $msg "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
  2747.             $lnk "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2748.             $this->Cell(00$msg00'L'0$lnk0false'D''B');
  2749.             $this->_outRestoreGraphicsState();
  2750.             // restore graphic settings
  2751.             $this->setGraphicVars($gvars);
  2752.         }
  2753.         // close page
  2754.         $this->endPage();
  2755.         // close document
  2756.         $this->_enddoc();
  2757.         // unset all class variables (except critical ones)
  2758.         $this->_destroy(false);
  2759.     }
  2760.     /**
  2761.      * Move pointer at the specified document page and update page dimensions.
  2762.      * @param int $pnum page number (1 ... numpages)
  2763.      * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2764.      * @public
  2765.      * @since 2.1.000 (2008-01-07)
  2766.      * @see getPage(), lastpage(), getNumPages()
  2767.      */
  2768.     public function setPage($pnum$resetmargins=false) {
  2769.         if (($pnum == $this->page) AND ($this->state == 2)) {
  2770.             return;
  2771.         }
  2772.         if (($pnum 0) AND ($pnum <= $this->numpages)) {
  2773.             $this->state 2;
  2774.             // save current graphic settings
  2775.             //$gvars = $this->getGraphicVars();
  2776.             $oldpage $this->page;
  2777.             $this->page $pnum;
  2778.             $this->wPt $this->pagedim[$this->page]['w'];
  2779.             $this->hPt $this->pagedim[$this->page]['h'];
  2780.             $this->$this->pagedim[$this->page]['wk'];
  2781.             $this->$this->pagedim[$this->page]['hk'];
  2782.             $this->tMargin $this->pagedim[$this->page]['tm'];
  2783.             $this->bMargin $this->pagedim[$this->page]['bm'];
  2784.             $this->original_lMargin $this->pagedim[$this->page]['olm'];
  2785.             $this->original_rMargin $this->pagedim[$this->page]['orm'];
  2786.             $this->AutoPageBreak $this->pagedim[$this->page]['pb'];
  2787.             $this->CurOrientation $this->pagedim[$this->page]['or'];
  2788.             $this->setAutoPageBreak($this->AutoPageBreak$this->bMargin);
  2789.             // restore graphic settings
  2790.             //$this->setGraphicVars($gvars);
  2791.             if ($resetmargins) {
  2792.                 $this->lMargin $this->pagedim[$this->page]['olm'];
  2793.                 $this->rMargin $this->pagedim[$this->page]['orm'];
  2794.                 $this->setY($this->tMargin);
  2795.             } else {
  2796.                 // account for booklet mode
  2797.                 if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2798.                     $deltam $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2799.                     $this->lMargin += $deltam;
  2800.                     $this->rMargin -= $deltam;
  2801.                 }
  2802.             }
  2803.         } else {
  2804.             $this->Error('Wrong page number on setPage() function: '.$pnum);
  2805.         }
  2806.     }
  2807.     /**
  2808.      * Reset pointer to the last document page.
  2809.      * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  2810.      * @public
  2811.      * @since 2.0.000 (2008-01-04)
  2812.      * @see setPage(), getPage(), getNumPages()
  2813.      */
  2814.     public function lastPage($resetmargins=false) {
  2815.         $this->setPage($this->getNumPages(), $resetmargins);
  2816.     }
  2817.     /**
  2818.      * Get current document page number.
  2819.      * @return int page number
  2820.      * @public
  2821.      * @since 2.1.000 (2008-01-07)
  2822.      * @see setPage(), lastpage(), getNumPages()
  2823.      */
  2824.     public function getPage() {
  2825.         return $this->page;
  2826.     }
  2827.     /**
  2828.      * Get the total number of insered pages.
  2829.      * @return int number of pages
  2830.      * @public
  2831.      * @since 2.1.000 (2008-01-07)
  2832.      * @see setPage(), getPage(), lastpage()
  2833.      */
  2834.     public function getNumPages() {
  2835.         return $this->numpages;
  2836.     }
  2837.     /**
  2838.      * Adds a new TOC (Table Of Content) page to the document.
  2839.      * @param string $orientation page orientation.
  2840.      * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2841.      * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2842.      * @public
  2843.      * @since 5.0.001 (2010-05-06)
  2844.      * @see AddPage(), startPage(), endPage(), endTOCPage()
  2845.      */
  2846.     public function addTOCPage($orientation=''$format=''$keepmargins=false) {
  2847.         $this->AddPage($orientation$format$keepmarginstrue);
  2848.     }
  2849.     /**
  2850.      * Terminate the current TOC (Table Of Content) page
  2851.      * @public
  2852.      * @since 5.0.001 (2010-05-06)
  2853.      * @see AddPage(), startPage(), endPage(), addTOCPage()
  2854.      */
  2855.     public function endTOCPage() {
  2856.         $this->endPage(true);
  2857.     }
  2858.     /**
  2859.      * 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).
  2860.      * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2861.      * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2862.      * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2863.      * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  2864.      * @param boolean $tocpage if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2865.      * @public
  2866.      * @since 1.0
  2867.      * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2868.      */
  2869.     public function AddPage($orientation=''$format=''$keepmargins=false$tocpage=false) {
  2870.         if ($this->inxobj) {
  2871.             // we are inside an XObject template
  2872.             return;
  2873.         }
  2874.         if (!isset($this->original_lMargin) OR $keepmargins) {
  2875.             $this->original_lMargin $this->lMargin;
  2876.         }
  2877.         if (!isset($this->original_rMargin) OR $keepmargins) {
  2878.             $this->original_rMargin $this->rMargin;
  2879.         }
  2880.         // terminate previous page
  2881.         $this->endPage();
  2882.         // start new page
  2883.         $this->startPage($orientation$format$tocpage);
  2884.     }
  2885.     /**
  2886.      * Terminate the current page
  2887.      * @param boolean $tocpage if true set the tocpage state to false (end the page used to display Table Of Content).
  2888.      * @public
  2889.      * @since 4.2.010 (2008-11-14)
  2890.      * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2891.      */
  2892.     public function endPage($tocpage=false) {
  2893.         // check if page is already closed
  2894.         if (($this->page == 0) OR ($this->numpages $this->page) OR (!$this->pageopen[$this->page])) {
  2895.             return;
  2896.         }
  2897.         // print page footer
  2898.         $this->setFooter();
  2899.         // close page
  2900.         $this->_endpage();
  2901.         // mark page as closed
  2902.         $this->pageopen[$this->page] = false;
  2903.         if ($tocpage) {
  2904.             $this->tocpage false;
  2905.         }
  2906.     }
  2907.     /**
  2908.      * Starts a new page to the document. The page must be closed using the endPage() function.
  2909.      * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2910.      * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2911.      * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  2912.      * @param boolean $tocpage if true the page is designated to contain the Table-Of-Content.
  2913.      * @since 4.2.010 (2008-11-14)
  2914.      * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2915.      * @public
  2916.      */
  2917.     public function startPage($orientation=''$format=''$tocpage=false) {
  2918.         if ($tocpage) {
  2919.             $this->tocpage true;
  2920.         }
  2921.         // move page numbers of documents to be attached
  2922.         if ($this->tocpage) {
  2923.             // move reference to unexistent pages (used for page attachments)
  2924.             // adjust outlines
  2925.             $tmpoutlines $this->outlines;
  2926.             foreach ($tmpoutlines as $key => $outline) {
  2927.                 if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
  2928.                     $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2929.                 }
  2930.             }
  2931.             // adjust dests
  2932.             $tmpdests $this->dests;
  2933.             foreach ($tmpdests as $key => $dest) {
  2934.                 if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
  2935.                     $this->dests[$key]['p'] = ($dest['p'] + 1);
  2936.                 }
  2937.             }
  2938.             // adjust links
  2939.             $tmplinks $this->links;
  2940.             foreach ($tmplinks as $key => $link) {
  2941.                 if (!$link['f'] AND ($link['p'] > $this->numpages)) {
  2942.                     $this->links[$key]['p'] = ($link['p'] + 1);
  2943.                 }
  2944.             }
  2945.         }
  2946.         if ($this->numpages $this->page) {
  2947.             // this page has been already added
  2948.             $this->setPage($this->page 1);
  2949.             $this->setY($this->tMargin);
  2950.             return;
  2951.         }
  2952.         // start a new page
  2953.         if ($this->state == 0) {
  2954.             $this->Open();
  2955.         }
  2956.         ++$this->numpages;
  2957.         $this->swapMargins($this->booklet);
  2958.         // save current graphic settings
  2959.         $gvars $this->getGraphicVars();
  2960.         // start new page
  2961.         $this->_beginpage($orientation$format);
  2962.         // mark page as open
  2963.         $this->pageopen[$this->page] = true;
  2964.         // restore graphic settings
  2965.         $this->setGraphicVars($gvars);
  2966.         // mark this point
  2967.         $this->setPageMark();
  2968.         // print page header
  2969.         $this->setHeader();
  2970.         // restore graphic settings
  2971.         $this->setGraphicVars($gvars);
  2972.         // mark this point
  2973.         $this->setPageMark();
  2974.         // print table header (if any)
  2975.         $this->setTableHeader();
  2976.         // set mark for empty page check
  2977.         $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2978.     }
  2979.     /**
  2980.      * Set start-writing mark on current page stream used to put borders and fills.
  2981.      * Borders and fills are always created after content and inserted on the position marked by this method.
  2982.      * This function must be called after calling Image() function for a background image.
  2983.      * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2984.      * @public
  2985.      * @since 4.0.016 (2008-07-30)
  2986.      */
  2987.     public function setPageMark() {
  2988.         $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2989.         $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2990.         $this->setContentMark();
  2991.     }
  2992.     /**
  2993.      * Set start-writing mark on selected page.
  2994.      * Borders and fills are always created after content and inserted on the position marked by this method.
  2995.      * @param int $page page number (default is the current page)
  2996.      * @protected
  2997.      * @since 4.6.021 (2009-07-20)
  2998.      */
  2999.     protected function setContentMark($page=0) {
  3000.         if ($page <= 0) {
  3001.             $page $this->page;
  3002.         }
  3003.         if (isset($this->footerlen[$page])) {
  3004.             $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  3005.         } else {
  3006.             $this->cntmrk[$page] = $this->pagelen[$page];
  3007.         }
  3008.     }
  3009.     /**
  3010.      * Set header data.
  3011.      * @param string $ln header image logo
  3012.      * @param int $lw header image logo width in mm
  3013.      * @param string $ht string to print as title on document header
  3014.      * @param string $hs string to print on document header
  3015.      * @param int[] $tc RGB array color for text.
  3016.      * @param int[] $lc RGB array color for line.
  3017.      * @public
  3018.      */
  3019.     public function setHeaderData($ln=''$lw=0$ht=''$hs=''$tc=array(0,0,0), $lc=array(0,0,0)) {
  3020.         $this->header_logo $ln;
  3021.         $this->header_logo_width $lw;
  3022.         $this->header_title $ht;
  3023.         $this->header_string $hs;
  3024.         $this->header_text_color $tc;
  3025.         $this->header_line_color $lc;
  3026.     }
  3027.     /**
  3028.      * Set footer data.
  3029.      * @param int[] $tc RGB array color for text.
  3030.      * @param int[] $lc RGB array color for line.
  3031.      * @public
  3032.      */
  3033.     public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  3034.         $this->footer_text_color $tc;
  3035.         $this->footer_line_color $lc;
  3036.     }
  3037.     /**
  3038.      * Returns header data:
  3039.      * <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>
  3040.      * @return array<string,mixed>
  3041.      * @public
  3042.      * @since 4.0.012 (2008-07-24)
  3043.      */
  3044.     public function getHeaderData() {
  3045.         $ret = array();
  3046.         $ret['logo'] = $this->header_logo;
  3047.         $ret['logo_width'] = $this->header_logo_width;
  3048.         $ret['title'] = $this->header_title;
  3049.         $ret['string'] = $this->header_string;
  3050.         $ret['text_color'] = $this->header_text_color;
  3051.         $ret['line_color'] = $this->header_line_color;
  3052.         return $ret;
  3053.     }
  3054.     /**
  3055.      * Set header margin.
  3056.      * (minimum distance between header and top page margin)
  3057.      * @param float $hm distance in user units
  3058.      * @public
  3059.      */
  3060.     public function setHeaderMargin($hm=10) {
  3061.         $this->header_margin $hm;
  3062.     }
  3063.     /**
  3064.      * Returns header margin in user units.
  3065.      * @return float
  3066.      * @since 4.0.012 (2008-07-24)
  3067.      * @public
  3068.      */
  3069.     public function getHeaderMargin() {
  3070.         return $this->header_margin;
  3071.     }
  3072.     /**
  3073.      * Set footer margin.
  3074.      * (minimum distance between footer and bottom page margin)
  3075.      * @param float $fm distance in user units
  3076.      * @public
  3077.      */
  3078.     public function setFooterMargin($fm=10) {
  3079.         $this->footer_margin $fm;
  3080.     }
  3081.     /**
  3082.      * Returns footer margin in user units.
  3083.      * @return float
  3084.      * @since 4.0.012 (2008-07-24)
  3085.      * @public
  3086.      */
  3087.     public function getFooterMargin() {
  3088.         return $this->footer_margin;
  3089.     }
  3090.     /**
  3091.      * Set a flag to print page header.
  3092.      * @param boolean $val set to true to print the page header (default), false otherwise.
  3093.      * @public
  3094.      */
  3095.     public function setPrintHeader($val=true) {
  3096.         $this->print_header $val true false;
  3097.     }
  3098.     /**
  3099.      * Set a flag to print page footer.
  3100.      * @param boolean $val set to true to print the page footer (default), false otherwise.
  3101.      * @public
  3102.      */
  3103.     public function setPrintFooter($val=true) {
  3104.         $this->print_footer $val true false;
  3105.     }
  3106.     /**
  3107.      * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3108.      * @return float
  3109.      * @public
  3110.      */
  3111.     public function getImageRBX() {
  3112.         return $this->img_rb_x;
  3113.     }
  3114.     /**
  3115.      * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3116.      * @return float
  3117.      * @public
  3118.      */
  3119.     public function getImageRBY() {
  3120.         return $this->img_rb_y;
  3121.     }
  3122.     /**
  3123.      * Reset the xobject template used by Header() method.
  3124.      * @public
  3125.      */
  3126.     public function resetHeaderTemplate() {
  3127.         $this->header_xobjid false;
  3128.     }
  3129.     /**
  3130.      * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3131.      * @param boolean $val set to true to reset Header xobject template at each page, false otherwise.
  3132.      * @public
  3133.      */
  3134.     public function setHeaderTemplateAutoreset($val=true) {
  3135.         $this->header_xobj_autoreset $val true false;
  3136.     }
  3137.     /**
  3138.      * This method is used to render the page header.
  3139.      * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3140.      * @public
  3141.      */
  3142.     public function Header() {
  3143.         if ($this->header_xobjid === false) {
  3144.             // start a new XObject Template
  3145.             $this->header_xobjid $this->startTemplate($this->w$this->tMargin);
  3146.             $headerfont $this->getHeaderFont();
  3147.             $headerdata $this->getHeaderData();
  3148.             $this->$this->header_margin;
  3149.             if ($this->rtl) {
  3150.                 $this->$this->$this->original_rMargin;
  3151.             } else {
  3152.                 $this->$this->original_lMargin;
  3153.             }
  3154.             if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3155.                 $imgtype TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3156.                 if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3157.                     $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], ''''$headerdata['logo_width']);
  3158.                 } elseif ($imgtype == 'svg') {
  3159.                     $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], ''''$headerdata['logo_width']);
  3160.                 } else {
  3161.                     $this->Image(K_PATH_IMAGES.$headerdata['logo'], ''''$headerdata['logo_width']);
  3162.                 }
  3163.                 $imgy $this->getImageRBY();
  3164.             } else {
  3165.                 $imgy $this->y;
  3166.             }
  3167.             $cell_height $this->getCellHeight($headerfont[2] / $this->k);
  3168.             // set starting margin for text data cell
  3169.             if ($this->getRTL()) {
  3170.                 $header_x $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3171.             } else {
  3172.                 $header_x $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3173.             }
  3174.             $cw $this->$this->original_lMargin $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3175.             $this->setTextColorArray($this->header_text_color);
  3176.             // header title
  3177.             $this->setFont($headerfont[0], 'B'$headerfont[2] + 1);
  3178.             $this->setX($header_x);
  3179.             $this->Cell($cw$cell_height$headerdata['title'], 01''0''0);
  3180.             // header string
  3181.             $this->setFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3182.             $this->setX($header_x);
  3183.             $this->MultiCell($cw$cell_height$headerdata['string'], 0''01''''true0falsetrue0'T'false);
  3184.             // print an ending header line
  3185.             $this->setLineStyle(array('width' => 0.85 $this->k'cap' => 'butt''join' => 'miter''dash' => 0'color' => $headerdata['line_color']));
  3186.             $this->setY((2.835 $this->k) + max($imgy$this->y));
  3187.             if ($this->rtl) {
  3188.                 $this->setX($this->original_rMargin);
  3189.             } else {
  3190.                 $this->setX($this->original_lMargin);
  3191.             }
  3192.             $this->Cell(($this->$this->original_lMargin $this->original_rMargin), 0'''T'0'C');
  3193.             $this->endTemplate();
  3194.         }
  3195.         // print header template
  3196.         $x 0;
  3197.         $dx 0;
  3198.         if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page 2) == 0)) {
  3199.             // adjust margins for booklet mode
  3200.             $dx = ($this->original_lMargin $this->original_rMargin);
  3201.         }
  3202.         if ($this->rtl) {
  3203.             $x $this->$dx;
  3204.         } else {
  3205.             $x $dx;
  3206.         }
  3207.         $this->printTemplate($this->header_xobjid$x000''''false);
  3208.         if ($this->header_xobj_autoreset) {
  3209.             // reset header xobject template at each page
  3210.             $this->header_xobjid false;
  3211.         }
  3212.     }
  3213.     /**
  3214.      * This method is used to render the page footer.
  3215.      * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3216.      * @public
  3217.      */
  3218.     public function Footer() {
  3219.         $cur_y $this->y;
  3220.         $this->setTextColorArray($this->footer_text_color);
  3221.         //set style for cell border
  3222.         $line_width = (0.85 $this->k);
  3223.         $this->setLineStyle(array('width' => $line_width'cap' => 'butt''join' => 'miter''dash' => 0'color' => $this->footer_line_color));
  3224.         //print document barcode
  3225.         $barcode $this->getBarcode();
  3226.         if (!empty($barcode)) {
  3227.             $this->Ln($line_width);
  3228.             $barcode_width round(($this->$this->original_lMargin $this->original_rMargin) / 3);
  3229.             $style = array(
  3230.                 'position' => $this->rtl?'R':'L',
  3231.                 'align' => $this->rtl?'R':'L',
  3232.                 'stretch' => false,
  3233.                 'fitwidth' => true,
  3234.                 'cellfitalign' => '',
  3235.                 'border' => false,
  3236.                 'padding' => 0,
  3237.                 'fgcolor' => array(0,0,0),
  3238.                 'bgcolor' => false,
  3239.                 'text' => false
  3240.             );
  3241.             $this->write1DBarcode($barcode'C128'''$cur_y $line_width'', (($this->footer_margin 3) - $line_width), 0.3$style'');
  3242.         }
  3243.         $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' '';
  3244.         if (empty($this->pagegroups)) {
  3245.             $pagenumtxt $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3246.         } else {
  3247.             $pagenumtxt $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3248.         }
  3249.         $this->setY($cur_y);
  3250.         //Print page number
  3251.         if ($this->getRTL()) {
  3252.             $this->setX($this->original_rMargin);
  3253.             $this->Cell(00$pagenumtxt'T'0'L');
  3254.         } else {
  3255.             $this->setX($this->original_lMargin);
  3256.             $this->Cell(00$this->getAliasRightShift().$pagenumtxt'T'0'R');
  3257.         }
  3258.     }
  3259.     /**
  3260.      * This method is used to render the page header.
  3261.      * @protected
  3262.      * @since 4.0.012 (2008-07-24)
  3263.      */
  3264.     protected function setHeader() {
  3265.         if (!$this->print_header OR ($this->state != 2)) {
  3266.             return;
  3267.         }
  3268.         $this->InHeader true;
  3269.         $this->setGraphicVars($this->default_graphic_vars);
  3270.         $temp_thead $this->thead;
  3271.         $temp_theadMargins $this->theadMargins;
  3272.         $lasth $this->lasth;
  3273.         $newline $this->newline;
  3274.         $this->_outSaveGraphicsState();
  3275.         $this->rMargin $this->original_rMargin;
  3276.         $this->lMargin $this->original_lMargin;
  3277.         $this->setCellPadding(0);
  3278.         //set current position
  3279.         if ($this->rtl) {
  3280.             $this->setXY($this->original_rMargin$this->header_margin);
  3281.         } else {
  3282.             $this->setXY($this->original_lMargin$this->header_margin);
  3283.         }
  3284.         $this->setFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3285.         $this->Header();
  3286.         //restore position
  3287.         if ($this->rtl) {
  3288.             $this->setXY($this->original_rMargin$this->tMargin);
  3289.         } else {
  3290.             $this->setXY($this->original_lMargin$this->tMargin);
  3291.         }
  3292.         $this->_outRestoreGraphicsState();
  3293.         $this->lasth $lasth;
  3294.         $this->thead $temp_thead;
  3295.         $this->theadMargins $temp_theadMargins;
  3296.         $this->newline $newline;
  3297.         $this->InHeader false;
  3298.     }
  3299.     /**
  3300.      * This method is used to render the page footer.
  3301.      * @protected
  3302.      * @since 4.0.012 (2008-07-24)
  3303.      */
  3304.     protected function setFooter() {
  3305.         if ($this->state != 2) {
  3306.             return;
  3307.         }
  3308.         $this->InFooter true;
  3309.         // save current graphic settings
  3310.         $gvars $this->getGraphicVars();
  3311.         // mark this point
  3312.         $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3313.         $this->_out("\n");
  3314.         if ($this->print_footer) {
  3315.             $this->setGraphicVars($this->default_graphic_vars);
  3316.             $this->current_column 0;
  3317.             $this->num_columns 1;
  3318.             $temp_thead $this->thead;
  3319.             $temp_theadMargins $this->theadMargins;
  3320.             $lasth $this->lasth;
  3321.             $this->_outSaveGraphicsState();
  3322.             $this->rMargin $this->original_rMargin;
  3323.             $this->lMargin $this->original_lMargin;
  3324.             $this->setCellPadding(0);
  3325.             //set current position
  3326.             $footer_y $this->$this->footer_margin;
  3327.             if ($this->rtl) {
  3328.                 $this->setXY($this->original_rMargin$footer_y);
  3329.             } else {
  3330.                 $this->setXY($this->original_lMargin$footer_y);
  3331.             }
  3332.             $this->setFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3333.             $this->Footer();
  3334.             //restore position
  3335.             if ($this->rtl) {
  3336.                 $this->setXY($this->original_rMargin$this->tMargin);
  3337.             } else {
  3338.                 $this->setXY($this->original_lMargin$this->tMargin);
  3339.             }
  3340.             $this->_outRestoreGraphicsState();
  3341.             $this->lasth $lasth;
  3342.             $this->thead $temp_thead;
  3343.             $this->theadMargins $temp_theadMargins;
  3344.         }
  3345.         // restore graphic settings
  3346.         $this->setGraphicVars($gvars);
  3347.         $this->current_column $gvars['current_column'];
  3348.         $this->num_columns $gvars['num_columns'];
  3349.         // calculate footer length
  3350.         $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3351.         $this->InFooter false;
  3352.     }
  3353.     /**
  3354.      * Check if we are on the page body (excluding page header and footer).
  3355.      * @return bool true if we are not in page header nor in page footer, false otherwise.
  3356.      * @protected
  3357.      * @since 5.9.091 (2011-06-15)
  3358.      */
  3359.     protected function inPageBody() {
  3360.         return (($this->InHeader === false) AND ($this->InFooter === false));
  3361.     }
  3362.     /**
  3363.      * This method is used to render the table header on new page (if any).
  3364.      * @protected
  3365.      * @since 4.5.030 (2009-03-25)
  3366.      */
  3367.     protected function setTableHeader() {
  3368.         if ($this->num_columns 1) {
  3369.             // multi column mode
  3370.             return;
  3371.         }
  3372.         if (isset($this->theadMargins['top'])) {
  3373.             // restore the original top-margin
  3374.             $this->tMargin $this->theadMargins['top'];
  3375.             $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3376.             $this->$this->tMargin;
  3377.         }
  3378.         if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3379.             // set margins
  3380.             $prev_lMargin $this->lMargin;
  3381.             $prev_rMargin $this->rMargin;
  3382.             $prev_cell_padding $this->cell_padding;
  3383.             $this->lMargin $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3384.             $this->rMargin $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3385.             $this->cell_padding $this->theadMargins['cell_padding'];
  3386.             if ($this->rtl) {
  3387.                 $this->$this->$this->rMargin;
  3388.             } else {
  3389.                 $this->$this->lMargin;
  3390.             }
  3391.             // account for special "cell" mode
  3392.             if ($this->theadMargins['cell']) {
  3393.                 if ($this->rtl) {
  3394.                     $this->-= $this->cell_padding['R'];
  3395.                 } else {
  3396.                     $this->+= $this->cell_padding['L'];
  3397.                 }
  3398.             }
  3399.             $gvars $this->getGraphicVars();
  3400.             if (!empty($this->theadMargins['gvars'])) {
  3401.                 // set the correct graphic style
  3402.                 $this->setGraphicVars($this->theadMargins['gvars']);
  3403.                 $this->rMargin $gvars['rMargin'];
  3404.                 $this->lMargin $gvars['lMargin'];
  3405.             }
  3406.             // print table header
  3407.             $this->writeHTML($this->theadfalsefalsefalsefalse'');
  3408.             $this->setGraphicVars($gvars);
  3409.             // set new top margin to skip the table headers
  3410.             if (!isset($this->theadMargins['top'])) {
  3411.                 $this->theadMargins['top'] = $this->tMargin;
  3412.             }
  3413.             // store end of header position
  3414.             if (!isset($this->columns[0]['th'])) {
  3415.                 $this->columns[0]['th'] = array();
  3416.             }
  3417.             $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3418.             $this->tMargin $this->y;
  3419.             $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3420.             $this->lasth 0;
  3421.             $this->lMargin $prev_lMargin;
  3422.             $this->rMargin $prev_rMargin;
  3423.             $this->cell_padding $prev_cell_padding;
  3424.         }
  3425.     }
  3426.     /**
  3427.      * Returns the current page number.
  3428.      * @return int page number
  3429.      * @public
  3430.      * @since 1.0
  3431.      * @see getAliasNbPages()
  3432.      */
  3433.     public function PageNo() {
  3434.         return $this->page;
  3435.     }
  3436.     /**
  3437.      * Returns the array of spot colors.
  3438.      * @return array Spot colors array.
  3439.      * @public
  3440.      * @since 6.0.038 (2013-09-30)
  3441.      */
  3442.     public function getAllSpotColors() {
  3443.         return $this->spot_colors;
  3444.     }
  3445.     /**
  3446.      * Defines a new spot color.
  3447.      * It can be expressed in RGB components or gray scale.
  3448.      * The method can be called before the first page is created and the value is retained from page to page.
  3449.      * @param string $name Full name of the spot color.
  3450.      * @param float $c Cyan color for CMYK. Value between 0 and 100.
  3451.      * @param float $m Magenta color for CMYK. Value between 0 and 100.
  3452.      * @param float $y Yellow color for CMYK. Value between 0 and 100.
  3453.      * @param float $k Key (Black) color for CMYK. Value between 0 and 100.
  3454.      * @public
  3455.      * @since 4.0.024 (2008-09-12)
  3456.      * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3457.      */
  3458.     public function AddSpotColor($name$c$m$y$k) {
  3459.         if (!isset($this->spot_colors[$name])) {
  3460.             $i = (count($this->spot_colors));
  3461.             $this->spot_colors[$name] = array('C' => $c'M' => $m'Y' => $y'K' => $k'name' => $name'i' => $i);
  3462.         }
  3463.     }
  3464.     /**
  3465.      * Set the spot color for the specified type ('draw', 'fill', 'text').
  3466.      * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3467.      * @param string $name Name of the spot color.
  3468.      * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3469.      * @return string PDF color command.
  3470.      * @public
  3471.      * @since 5.9.125 (2011-10-03)
  3472.      */
  3473.     public function setSpotColor($type$name$tint=100) {
  3474.         $spotcolor TCPDF_COLORS::getSpotColor($name$this->spot_colors);
  3475.         if ($spotcolor === false) {
  3476.             $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3477.         }
  3478.         $tint = (max(0min(100$tint)) / 100);
  3479.         $pdfcolor sprintf('/CS%d '$this->spot_colors[$name]['i']);
  3480.         switch ($type) {
  3481.             case 'draw': {
  3482.                 $pdfcolor .= sprintf('CS %F SCN'$tint);
  3483.                 $this->DrawColor $pdfcolor;
  3484.                 $this->strokecolor $spotcolor;
  3485.                 break;
  3486.             }
  3487.             case 'fill': {
  3488.                 $pdfcolor .= sprintf('cs %F scn'$tint);
  3489.                 $this->FillColor $pdfcolor;
  3490.                 $this->bgcolor $spotcolor;
  3491.                 break;
  3492.             }
  3493.             case 'text': {
  3494.                 $pdfcolor .= sprintf('cs %F scn'$tint);
  3495.                 $this->TextColor $pdfcolor;
  3496.                 $this->fgcolor $spotcolor;
  3497.                 break;
  3498.             }
  3499.         }
  3500.         $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3501.         if ($this->state == 2) {
  3502.             $this->_out($pdfcolor);
  3503.         }
  3504.         if ($this->inxobj) {
  3505.             // we are inside an XObject template
  3506.             $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3507.         }
  3508.         return $pdfcolor;
  3509.     }
  3510.     /**
  3511.      * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3512.      * @param string $name Name of the spot color.
  3513.      * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3514.      * @public
  3515.      * @since 4.0.024 (2008-09-12)
  3516.      * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3517.      */
  3518.     public function setDrawSpotColor($name$tint=100) {
  3519.         $this->setSpotColor('draw'$name$tint);
  3520.     }
  3521.     /**
  3522.      * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3523.      * @param string $name Name of the spot color.
  3524.      * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3525.      * @public
  3526.      * @since 4.0.024 (2008-09-12)
  3527.      * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3528.      */
  3529.     public function setFillSpotColor($name$tint=100) {
  3530.         $this->setSpotColor('fill'$name$tint);
  3531.     }
  3532.     /**
  3533.      * Defines the spot color used for text.
  3534.      * @param string $name Name of the spot color.
  3535.      * @param int $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3536.      * @public
  3537.      * @since 4.0.024 (2008-09-12)
  3538.      * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3539.      */
  3540.     public function setTextSpotColor($name$tint=100) {
  3541.         $this->setSpotColor('text'$name$tint);
  3542.     }
  3543.     /**
  3544.      * Set the color array for the specified type ('draw', 'fill', 'text').
  3545.      * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3546.      * The method can be called before the first page is created and the value is retained from page to page.
  3547.      * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3548.      * @param array $color Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3549.      * @param boolean $ret If true do not send the PDF command.
  3550.      * @return string The PDF command or empty string.
  3551.      * @public
  3552.      * @since 3.1.000 (2008-06-11)
  3553.      */
  3554.     public function setColorArray($type$color$ret=false) {
  3555.         if (is_array($color)) {
  3556.             $color array_values($color);
  3557.             // component: grey, RGB red or CMYK cyan
  3558.             $c = isset($color[0]) ? $color[0] : -1;
  3559.             // component: RGB green or CMYK magenta
  3560.             $m = isset($color[1]) ? $color[1] : -1;
  3561.             // component: RGB blue or CMYK yellow
  3562.             $y = isset($color[2]) ? $color[2] : -1;
  3563.             // component: CMYK black
  3564.             $k = isset($color[3]) ? $color[3] : -1;
  3565.             // color name
  3566.             $name = isset($color[4]) ? $color[4] : '';
  3567.             if ($c >= 0) {
  3568.                 return $this->setColor($type$c$m$y$k$ret$name);
  3569.             }
  3570.         }
  3571.         return '';
  3572.     }
  3573.     /**
  3574.      * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3575.      * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3576.      * The method can be called before the first page is created and the value is retained from page to page.
  3577.      * @param array $color Array of colors (1, 3 or 4 values).
  3578.      * @param boolean $ret If true do not send the PDF command.
  3579.      * @return string the PDF command
  3580.      * @public
  3581.      * @since 3.1.000 (2008-06-11)
  3582.      * @see SetDrawColor()
  3583.      */
  3584.     public function setDrawColorArray($color$ret=false) {
  3585.         return $this->setColorArray('draw'$color$ret);
  3586.     }
  3587.     /**
  3588.      * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3589.      * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3590.      * The method can be called before the first page is created and the value is retained from page to page.
  3591.      * @param array $color Array of colors (1, 3 or 4 values).
  3592.      * @param boolean $ret If true do not send the PDF command.
  3593.      * @public
  3594.      * @since 3.1.000 (2008-6-11)
  3595.      * @see SetFillColor()
  3596.      */
  3597.     public function setFillColorArray($color$ret=false) {
  3598.         return $this->setColorArray('fill'$color$ret);
  3599.     }
  3600.     /**
  3601.      * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3602.      * The method can be called before the first page is created and the value is retained from page to page.
  3603.      * @param array $color Array of colors (1, 3 or 4 values).
  3604.      * @param boolean $ret If true do not send the PDF command.
  3605.      * @public
  3606.      * @since 3.1.000 (2008-6-11)
  3607.      * @see SetFillColor()
  3608.      */
  3609.     public function setTextColorArray($color$ret=false) {
  3610.         return $this->setColorArray('text'$color$ret);
  3611.     }
  3612.     /**
  3613.      * Defines the color used by the specified type ('draw', 'fill', 'text').
  3614.      * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
  3615.      * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3616.      * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3617.      * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3618.      * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3619.      * @param boolean $ret If true do not send the command.
  3620.      * @param string $name spot color name (if any)
  3621.      * @return string The PDF command or empty string.
  3622.      * @public
  3623.      * @since 5.9.125 (2011-10-03)
  3624.      */
  3625.     public function setColor($type$col1=0$col2=-1$col3=-1$col4=-1$ret=false$name='') {
  3626.         // set default values
  3627.         if (!is_numeric($col1)) {
  3628.             $col1 0;
  3629.         }
  3630.         if (!is_numeric($col2)) {
  3631.             $col2 = -1;
  3632.         }
  3633.         if (!is_numeric($col3)) {
  3634.             $col3 = -1;
  3635.         }
  3636.         if (!is_numeric($col4)) {
  3637.             $col4 = -1;
  3638.         }
  3639.         // set color by case
  3640.         $suffix '';
  3641.         if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3642.             // Grey scale
  3643.             $col1 max(0min(255$col1));
  3644.             $intcolor = array('G' => $col1);
  3645.             $pdfcolor sprintf('%F ', ($col1 255));
  3646.             $suffix 'g';
  3647.         } elseif ($col4 == -1) {
  3648.             // RGB
  3649.             $col1 max(0min(255$col1));
  3650.             $col2 max(0min(255$col2));
  3651.             $col3 max(0min(255$col3));
  3652.             $intcolor = array('R' => $col1'G' => $col2'B' => $col3);
  3653.             $pdfcolor sprintf('%F %F %F ', ($col1 255), ($col2 255), ($col3 255));
  3654.             $suffix 'rg';
  3655.         } else {
  3656.             $col1 max(0min(100$col1));
  3657.             $col2 max(0min(100$col2));
  3658.             $col3 max(0min(100$col3));
  3659.             $col4 max(0min(100$col4));
  3660.             if (empty($name)) {
  3661.                 // CMYK
  3662.                 $intcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4);
  3663.                 $pdfcolor sprintf('%F %F %F %F ', ($col1 100), ($col2 100), ($col3 100), ($col4 100));
  3664.                 $suffix 'k';
  3665.             } else {
  3666.                 // SPOT COLOR
  3667.                 $intcolor = array('C' => $col1'M' => $col2'Y' => $col3'K' => $col4'name' => $name);
  3668.                 $this->AddSpotColor($name$col1$col2$col3$col4);
  3669.                 $pdfcolor $this->setSpotColor($type$name100);
  3670.             }
  3671.         }
  3672.         switch ($type) {
  3673.             case 'draw': {
  3674.                 $pdfcolor .= strtoupper($suffix);
  3675.                 $this->DrawColor $pdfcolor;
  3676.                 $this->strokecolor $intcolor;
  3677.                 break;
  3678.             }
  3679.             case 'fill': {
  3680.                 $pdfcolor .= $suffix;
  3681.                 $this->FillColor $pdfcolor;
  3682.                 $this->bgcolor $intcolor;
  3683.                 break;
  3684.             }
  3685.             case 'text': {
  3686.                 $pdfcolor .= $suffix;
  3687.                 $this->TextColor $pdfcolor;
  3688.                 $this->fgcolor $intcolor;
  3689.                 break;
  3690.             }
  3691.         }
  3692.         $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3693.         if (($type != 'text') AND ($this->state == 2) AND $type !== 0) {
  3694.             if (!$ret) {
  3695.                 $this->_out($pdfcolor);
  3696.             }
  3697.             return $pdfcolor;
  3698.         }
  3699.         return '';
  3700.     }
  3701.     /**
  3702.      * 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.
  3703.      * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3704.      * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3705.      * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3706.      * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3707.      * @param boolean $ret If true do not send the command.
  3708.      * @param string $name spot color name (if any)
  3709.      * @return string the PDF command
  3710.      * @public
  3711.      * @since 1.3
  3712.      * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3713.      */
  3714.     public function setDrawColor($col1=0$col2=-1$col3=-1$col4=-1$ret=false$name='') {
  3715.         return $this->setColor('draw'$col1$col2$col3$col4$ret$name);
  3716.     }
  3717.     /**
  3718.      * 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.
  3719.      * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3720.      * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3721.      * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3722.      * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3723.      * @param boolean $ret If true do not send the command.
  3724.      * @param string $name Spot color name (if any).
  3725.      * @return string The PDF command.
  3726.      * @public
  3727.      * @since 1.3
  3728.      * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3729.      */
  3730.     public function setFillColor($col1=0$col2=-1$col3=-1$col4=-1$ret=false$name='') {
  3731.         return $this->setColor('fill'$col1$col2$col3$col4$ret$name);
  3732.     }
  3733.     /**
  3734.      * 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.
  3735.      * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3736.      * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3737.      * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3738.      * @param float $col4 KEY (BLACK) color for CMYK (0-100).
  3739.      * @param boolean $ret If true do not send the command.
  3740.      * @param string $name Spot color name (if any).
  3741.      * @return string Empty string.
  3742.      * @public
  3743.      * @since 1.3
  3744.      * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3745.      */
  3746.     public function setTextColor($col1=0$col2=-1$col3=-1$col4=-1$ret=false$name='') {
  3747.         return $this->setColor('text'$col1$col2$col3$col4$ret$name);
  3748.     }
  3749.     /**
  3750.      * Returns the length of a string in user unit. A font must be selected.<br>
  3751.      * @param string $s The string whose length is to be computed
  3752.      * @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.
  3753.      * @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-through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  3754.      * @param float $fontsize Font size in points. The default value is the current size.
  3755.      * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3756.      * @return float[]|float total string length or array of characted widths
  3757.      * @phpstan-return ($getarray is true ? float[] : float) total string length or array of characted widths
  3758.      * @author Nicola Asuni
  3759.      * @public
  3760.      * @since 1.2
  3761.      */
  3762.     public function GetStringWidth($s$fontname=''$fontstyle=''$fontsize=0$getarray=false) {
  3763.         return $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($s$this->isunicode$this->CurrentFont), $s$this->tmprtl$this->isunicode$this->CurrentFont), $fontname$fontstyle$fontsize$getarray);
  3764.     }
  3765.     /**
  3766.      * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3767.      * @param array $sa The array of chars whose total length is to be computed
  3768.      * @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.
  3769.      * @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 through</li><li>O: overline</li></ul> or any combination. The default value is regular.
  3770.      * @param float $fontsize Font size in points. The default value is the current size.
  3771.      * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  3772.      * @return float[]|float total string length or array of characted widths
  3773.      * @phpstan-return ($getarray is true ? float[] : float) total string length or array of characted widths
  3774.      * @author Nicola Asuni
  3775.      * @public
  3776.      * @since 2.4.000 (2008-03-06)
  3777.      */
  3778.     public function GetArrStringWidth($sa$fontname=''$fontstyle=''$fontsize=0$getarray=false) {
  3779.         // store current values
  3780.         if (!TCPDF_STATIC::empty_string($fontname)) {
  3781.             $prev_FontFamily $this->FontFamily;
  3782.             $prev_FontStyle $this->FontStyle;
  3783.             $prev_FontSizePt $this->FontSizePt;
  3784.             $this->setFont($fontname$fontstyle$fontsize'''default'false);
  3785.         }
  3786.         // convert UTF-8 array to Latin1 if required
  3787.         if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3788.             $sa TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3789.         }
  3790.         $w 0// total width
  3791.         $wa = array(); // array of characters widths
  3792.         foreach ($sa as $ck => $char) {
  3793.             // character width
  3794.             $cw $this->GetCharWidth($char, isset($sa[($ck 1)]));
  3795.             $wa[] = $cw;
  3796.             $w += $cw;
  3797.         }
  3798.         // restore previous values
  3799.         if (!TCPDF_STATIC::empty_string($fontname)) {
  3800.             $this->setFont($prev_FontFamily$prev_FontStyle$prev_FontSizePt'''default'false);
  3801.         }
  3802.         if ($getarray) {
  3803.             return $wa;
  3804.         }
  3805.         return $w;
  3806.     }
  3807.     /**
  3808.      * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3809.      * @param int $char The char code whose length is to be returned
  3810.      * @param boolean $notlast If false ignore the font-spacing.
  3811.      * @return float char width
  3812.      * @author Nicola Asuni
  3813.      * @public
  3814.      * @since 2.4.000 (2008-03-06)
  3815.      */
  3816.     public function GetCharWidth($char$notlast=true) {
  3817.         // get raw width
  3818.         $chw $this->getRawCharWidth($char);
  3819.         if (($this->font_spacing 0) OR (($this->font_spacing 0) AND $notlast)) {
  3820.             // increase/decrease font spacing
  3821.             $chw += $this->font_spacing;
  3822.         }
  3823.         if ($this->font_stretching != 100) {
  3824.             // fixed stretching mode
  3825.             $chw *= ($this->font_stretching 100);
  3826.         }
  3827.         return $chw;
  3828.     }
  3829.     /**
  3830.      * Returns the length of the char in user unit for the current font.
  3831.      * @param int $char The char code whose length is to be returned
  3832.      * @return float char width
  3833.      * @author Nicola Asuni
  3834.      * @public
  3835.      * @since 5.9.000 (2010-09-28)
  3836.      */
  3837.     public function getRawCharWidth($char) {
  3838.         if ($char == 173) {
  3839.             // SHY character will not be printed
  3840.             return (0);
  3841.         }
  3842.         if (isset($this->CurrentFont['cw'][intval($char)])) {
  3843.             $w $this->CurrentFont['cw'][intval($char)];
  3844.         } elseif (isset($this->CurrentFont['dw'])) {
  3845.             // default width
  3846.             $w $this->CurrentFont['dw'];
  3847.         } elseif (isset($this->CurrentFont['cw'][32])) {
  3848.             // default width
  3849.             $w $this->CurrentFont['cw'][32];
  3850.         } else {
  3851.             $w 600;
  3852.         }
  3853.         return $this->getAbsFontMeasure($w);
  3854.     }
  3855.     /**
  3856.      * Returns the numbero of characters in a string.
  3857.      * @param string $s The input string.
  3858.      * @return int number of characters
  3859.      * @public
  3860.      * @since 2.0.0001 (2008-01-07)
  3861.      */
  3862.     public function GetNumChars($s) {
  3863.         if ($this->isUnicodeFont()) {
  3864.             return count(TCPDF_FONTS::UTF8StringToArray($s$this->isunicode$this->CurrentFont));
  3865.         }
  3866.         return strlen($s);
  3867.     }
  3868.     /**
  3869.      * Fill the list of available fonts ($this->fontlist).
  3870.      * @protected
  3871.      * @since 4.0.013 (2008-07-28)
  3872.      */
  3873.     protected function getFontsList() {
  3874.         if (($fontsdir opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3875.             while (($file readdir($fontsdir)) !== false) {
  3876.                 if (substr($file, -4) == '.php') {
  3877.                     array_push($this->fontliststrtolower(basename($file'.php')));
  3878.                 }
  3879.             }
  3880.             closedir($fontsdir);
  3881.         }
  3882.     }
  3883.     /**
  3884.      * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3885.      * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3886.      * 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.
  3887.      * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3888.      * @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>
  3889.      * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3890.      * @return array|false array containing the font data, or false in case of error.
  3891.      * @param mixed $subset if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  3892.      * @public
  3893.      * @since 1.5
  3894.      * @see SetFont(), setFontSubsetting()
  3895.      */
  3896.     public function AddFont($family$style=''$fontfile=''$subset='default') {
  3897.         if ($subset === 'default') {
  3898.             $subset $this->font_subsetting;
  3899.         }
  3900.         if ($this->pdfa_mode) {
  3901.             $subset false;
  3902.         }
  3903.         if (TCPDF_STATIC::empty_string($family)) {
  3904.             if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3905.                 $family $this->FontFamily;
  3906.             } else {
  3907.                 $this->Error('Empty font family');
  3908.             }
  3909.         }
  3910.         // move embedded styles on $style
  3911.         if (substr($family, -1) == 'I') {
  3912.             $style .= 'I';
  3913.             $family substr($family0, -1);
  3914.         }
  3915.         if (substr($family, -1) == 'B') {
  3916.             $style .= 'B';
  3917.             $family substr($family0, -1);
  3918.         }
  3919.         // normalize family name
  3920.         $family strtolower($family);
  3921.         if ((!$this->isunicode) AND ($family == 'arial')) {
  3922.             $family 'helvetica';
  3923.         }
  3924.         if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3925.             $style '';
  3926.         }
  3927.         if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3928.             // all fonts must be embedded
  3929.             $family 'pdfa'.$family;
  3930.         }
  3931.         $tempstyle strtoupper($style === null '' $style);
  3932.         $style '';
  3933.         // underline
  3934.         if (strpos($tempstyle'U') !== false) {
  3935.             $this->underline true;
  3936.         } else {
  3937.             $this->underline false;
  3938.         }
  3939.         // line-through (deleted)
  3940.         if (strpos($tempstyle'D') !== false) {
  3941.             $this->linethrough true;
  3942.         } else {
  3943.             $this->linethrough false;
  3944.         }
  3945.         // overline
  3946.         if (strpos($tempstyle'O') !== false) {
  3947.             $this->overline true;
  3948.         } else {
  3949.             $this->overline false;
  3950.         }
  3951.         // bold
  3952.         if (strpos($tempstyle'B') !== false) {
  3953.             $style .= 'B';
  3954.         }
  3955.         // oblique
  3956.         if (strpos($tempstyle'I') !== false) {
  3957.             $style .= 'I';
  3958.         }
  3959.         $bistyle $style;
  3960.         $fontkey $family.$style;
  3961.         $font_style $style.($this->underline 'U' '').($this->linethrough 'D' '').($this->overline 'O' '');
  3962.         $fontdata = array('fontkey' => $fontkey'family' => $family'style' => $font_style);
  3963.         // check if the font has been already added
  3964.         $fb $this->getFontBuffer($fontkey);
  3965.         if ($fb !== false) {
  3966.             if ($this->inxobj) {
  3967.                 // we are inside an XObject template
  3968.                 $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  3969.             }
  3970.             return $fontdata;
  3971.         }
  3972.         // get specified font directory (if any)
  3973.         $fontdir false;
  3974.         if (!TCPDF_STATIC::empty_string($fontfile)) {
  3975.             $fontdir dirname($fontfile);
  3976.             if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  3977.                 $fontdir '';
  3978.             } else {
  3979.                 $fontdir .= '/';
  3980.             }
  3981.         }
  3982.         // true when the font style variation is missing
  3983.         $missing_style false;
  3984.         // search and include font file
  3985.         if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
  3986.             // build a standard filenames for specified font
  3987.             $tmp_fontfile str_replace(' '''$family).strtolower($style).'.php';
  3988.             $fontfile TCPDF_FONTS::getFontFullPath($tmp_fontfile$fontdir);
  3989.             if (TCPDF_STATIC::empty_string($fontfile)) {
  3990.                 $missing_style true;
  3991.                 // try to remove the style part
  3992.                 $tmp_fontfile str_replace(' '''$family).'.php';
  3993.                 $fontfile TCPDF_FONTS::getFontFullPath($tmp_fontfile$fontdir);
  3994.             }
  3995.         }
  3996.         // include font file
  3997.         if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
  3998.             $type=null;
  3999.             $name=null;
  4000.             $desc=null;
  4001.             $up=-null;
  4002.             $ut=null;
  4003.             $cw=null;
  4004.             $cbbox=null;
  4005.             $dw=null;
  4006.             $enc=null;
  4007.             $cidinfo=null;
  4008.             $file=null;
  4009.             $ctg=null;
  4010.             $diff=null;
  4011.             $originalsize=null;
  4012.             $size1=null;
  4013.             $size2=null;
  4014.             include($fontfile);
  4015.         } else {
  4016.             $this->Error('Could not include font definition file: '.$family.'');
  4017.         }
  4018.         // check font parameters
  4019.         if ((!isset($type)) OR (!isset($cw))) {
  4020.             $this->Error('The font definition file has a bad format: '.$fontfile.'');
  4021.         }
  4022.         // SET default parameters
  4023.         if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  4024.             $file '';
  4025.         }
  4026.         if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  4027.             $enc '';
  4028.         }
  4029.         if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  4030.             $cidinfo = array('Registry'=>'Adobe''Ordering'=>'Identity''Supplement'=>0);
  4031.             $cidinfo['uni2cid'] = array();
  4032.         }
  4033.         if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  4034.             $ctg '';
  4035.         }
  4036.         if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  4037.             $desc = array();
  4038.         }
  4039.         if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  4040.             $up = -100;
  4041.         }
  4042.         if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  4043.             $ut 50;
  4044.         }
  4045.         if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  4046.             $cw = array();
  4047.         }
  4048.         if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  4049.             // set default width
  4050.             if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  4051.                 $dw $desc['MissingWidth'];
  4052.             } elseif (isset($cw[32])) {
  4053.                 $dw $cw[32];
  4054.             } else {
  4055.                 $dw 600;
  4056.             }
  4057.         }
  4058.         ++$this->numfonts;
  4059.         if ($type == 'core') {
  4060.             $name $this->CoreFonts[$fontkey];
  4061.             $subset false;
  4062.         } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  4063.             $subset false;
  4064.         } elseif ($type == 'TrueTypeUnicode') {
  4065.             $enc 'Identity-H';
  4066.         } elseif ($type == 'cidfont0') {
  4067.             if ($this->pdfa_mode) {
  4068.                 $this->Error('All fonts must be embedded in PDF/A mode!');
  4069.             }
  4070.         } else {
  4071.             $this->Error('Unknow font type: '.$type.'');
  4072.         }
  4073.         // set name if unset
  4074.         if (!isset($name) OR empty($name)) {
  4075.             $name $fontkey;
  4076.         }
  4077.         // create artificial font style variations if missing (only works with non-embedded fonts)
  4078.         if (($type != 'core') AND $missing_style) {
  4079.             // style variations
  4080.             $styles = array('' => '''B' => ',Bold''I' => ',Italic''BI' => ',BoldItalic');
  4081.             $name .= $styles[$bistyle];
  4082.             // artificial bold
  4083.             if (strpos($bistyle'B') !== false) {
  4084.                 if (isset($desc['StemV'])) {
  4085.                     // from normal to bold
  4086.                     $desc['StemV'] = round($desc['StemV'] * 1.75);
  4087.                 } else {
  4088.                     // bold
  4089.                     $desc['StemV'] = 123;
  4090.                 }
  4091.             }
  4092.             // artificial italic
  4093.             if (strpos($bistyle'I') !== false) {
  4094.                 if (isset($desc['ItalicAngle'])) {
  4095.                     $desc['ItalicAngle'] -= 11;
  4096.                 } else {
  4097.                     $desc['ItalicAngle'] = -11;
  4098.                 }
  4099.                 if (isset($desc['Flags'])) {
  4100.                     $desc['Flags'] |= 64//bit 7
  4101.                 } else {
  4102.                     $desc['Flags'] = 64;
  4103.                 }
  4104.             }
  4105.         }
  4106.         // check if the array of characters bounding boxes is defined
  4107.         if (!isset($cbbox)) {
  4108.             $cbbox = array();
  4109.         }
  4110.         // initialize subsetchars
  4111.         $subsetchars array_fill(0255true);
  4112.         $this->setFontBuffer($fontkey, array('fontkey' => $fontkey'i' => $this->numfonts'type' => $type'name' => $name'desc' => $desc'up' => $up'ut' => $ut'cw' => $cw'cbbox' => $cbbox'dw' => $dw'enc' => $enc'cidinfo' => $cidinfo'file' => $file'ctg' => $ctg'subset' => $subset'subsetchars' => $subsetchars));
  4113.         if ($this->inxobj) {
  4114.             // we are inside an XObject template
  4115.             $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4116.         }
  4117.         if (isset($diff) AND (!empty($diff))) {
  4118.             //Search existing encodings
  4119.             $d 0;
  4120.             $nb count($this->diffs);
  4121.             for ($i=1$i <= $nb; ++$i) {
  4122.                 if ($this->diffs[$i] == $diff) {
  4123.                     $d $i;
  4124.                     break;
  4125.                 }
  4126.             }
  4127.             if ($d == 0) {
  4128.                 $d $nb 1;
  4129.                 $this->diffs[$d] = $diff;
  4130.             }
  4131.             $this->setFontSubBuffer($fontkey'diff'$d);
  4132.         }
  4133.         if (!TCPDF_STATIC::empty_string($file)) {
  4134.             if (!isset($this->FontFiles[$file])) {
  4135.                 if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type'TrueTypeUnicode') == 0)) {
  4136.                     $this->FontFiles[$file] = array('length1' => $originalsize'fontdir' => $fontdir'subset' => $subset'fontkeys' => array($fontkey));
  4137.                 } elseif ($type != 'core') {
  4138.                     $this->FontFiles[$file] = array('length1' => $size1'length2' => $size2'fontdir' => $fontdir'subset' => $subset'fontkeys' => array($fontkey));
  4139.                 }
  4140.             } else {
  4141.                 // update fontkeys that are sharing this font file
  4142.                 $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4143.                 if (!in_array($fontkey$this->FontFiles[$file]['fontkeys'])) {
  4144.                     $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4145.                 }
  4146.             }
  4147.         }
  4148.         return $fontdata;
  4149.     }
  4150.     /**
  4151.      * Sets the font used to print character strings.
  4152.      * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4153.      * The method can be called before the first page is created and the font is retained from page to page.
  4154.      * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4155.      * 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 />
  4156.      * @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.
  4157.      * @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 through</li><li>O: overline</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.
  4158.      * @param float|null $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
  4159.      * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4160.      * @param mixed $subset if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  4161.      * @param boolean $out if true output the font size command, otherwise only set the font properties.
  4162.      * @author Nicola Asuni
  4163.      * @public
  4164.      * @since 1.0
  4165.      * @see AddFont(), SetFontSize()
  4166.      */
  4167.     public function setFont($family$style=''$size=null$fontfile=''$subset='default'$out=true) {
  4168.         //Select a font; size given in points
  4169.         if ($size === null) {
  4170.             $size $this->FontSizePt;
  4171.         }
  4172.         if ($size 0) {
  4173.             $size 0;
  4174.         }
  4175.         // try to add font (if not already added)
  4176.         $fontdata $this->AddFont($family$style$fontfile$subset);
  4177.         $this->FontFamily $fontdata['family'];
  4178.         $this->FontStyle $fontdata['style'];
  4179.         if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4180.             // save subset chars of the previous font
  4181.             $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars'$this->CurrentFont['subsetchars']);
  4182.         }
  4183.         $this->CurrentFont $this->getFontBuffer($fontdata['fontkey']);
  4184.         $this->setFontSize($size$out);
  4185.     }
  4186.     /**
  4187.      * Defines the size of the current font.
  4188.      * @param float $size The font size in points.
  4189.      * @param boolean $out if true output the font size command, otherwise only set the font properties.
  4190.      * @public
  4191.      * @since 1.0
  4192.      * @see SetFont()
  4193.      */
  4194.     public function setFontSize($size$out=true) {
  4195.         $size = (float)$size;
  4196.         // font size in points
  4197.         $this->FontSizePt $size;
  4198.         // font size in user units
  4199.         $this->FontSize $size $this->k;
  4200.         // calculate some font metrics
  4201.         if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4202.             $bbox explode(' 'substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4203.             $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size 1000);
  4204.         } else {
  4205.             $font_height $size 1.219;
  4206.         }
  4207.         if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4208.             $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size 1000);
  4209.         }
  4210.         if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4211.             $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size 1000);
  4212.         }
  4213.         if (!isset($font_ascent) AND !isset($font_descent)) {
  4214.             // core font
  4215.             $font_ascent 0.76 $font_height;
  4216.             $font_descent $font_height $font_ascent;
  4217.         } elseif (!isset($font_descent)) {
  4218.             $font_descent $font_height $font_ascent;
  4219.         } elseif (!isset($font_ascent)) {
  4220.             $font_ascent $font_height $font_descent;
  4221.         }
  4222.         $this->FontAscent = ($font_ascent $this->k);
  4223.         $this->FontDescent = ($font_descent $this->k);
  4224.         if ($out AND ($this->page 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4225.             $this->_out(sprintf('BT /F%d %F Tf ET'$this->CurrentFont['i'], $this->FontSizePt));
  4226.         }
  4227.     }
  4228.     /**
  4229.      * Returns the bounding box of the current font in user units.
  4230.      * @return array
  4231.      * @public
  4232.      * @since 5.9.152 (2012-03-23)
  4233.      */
  4234.     public function getFontBBox() {
  4235.         $fbbox = array();
  4236.         if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4237.             $tmpbbox explode(' 'substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4238.             $fbbox array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4239.         } else {
  4240.             // Find max width
  4241.             if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4242.                 $maxw $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4243.             } else {
  4244.                 $maxw 0;
  4245.                 if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4246.                     $maxw max($maxw$this->CurrentFont['desc']['MissingWidth']);
  4247.                 }
  4248.                 if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4249.                     $maxw max($maxw$this->CurrentFont['desc']['AvgWidth']);
  4250.                 }
  4251.                 if (isset($this->CurrentFont['dw'])) {
  4252.                     $maxw max($maxw$this->CurrentFont['dw']);
  4253.                 }
  4254.                 foreach ($this->CurrentFont['cw'] as $char => $w) {
  4255.                     $maxw max($maxw$w);
  4256.                 }
  4257.                 if ($maxw == 0) {
  4258.                     $maxw 600;
  4259.                 }
  4260.                 $maxw $this->getAbsFontMeasure($maxw);
  4261.             }
  4262.             $fbbox = array(0, ($this->FontDescent), $maxw$this->FontAscent);
  4263.         }
  4264.         return $fbbox;
  4265.     }
  4266.     /**
  4267.      * Convert a relative font measure into absolute value.
  4268.      * @param int $s Font measure.
  4269.      * @return float Absolute measure.
  4270.      * @since 5.9.186 (2012-09-13)
  4271.      */
  4272.     public function getAbsFontMeasure($s) {
  4273.         return ($s $this->FontSize 1000);
  4274.     }
  4275.     /**
  4276.      * Returns the glyph bounding box of the specified character in the current font in user units.
  4277.      * @param int $char Input character code.
  4278.      * @return false|array array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4279.      * @since 5.9.186 (2012-09-13)
  4280.      */
  4281.     public function getCharBBox($char) {
  4282.         $c intval($char);
  4283.         if (isset($this->CurrentFont['cw'][$c])) {
  4284.             // glyph is defined ... use zero width & height for glyphs without outlines
  4285.             $result = array(0,0,0,0);
  4286.             if (isset($this->CurrentFont['cbbox'][$c])) {
  4287.                 $result $this->CurrentFont['cbbox'][$c];
  4288.             }
  4289.             return array_map(array($this,'getAbsFontMeasure'), $result);
  4290.         }
  4291.         return false;
  4292.     }
  4293.     /**
  4294.      * Return the font descent value
  4295.      * @param string $font font name
  4296.      * @param string $style font style
  4297.      * @param float $size The size (in points)
  4298.      * @return int font descent
  4299.      * @public
  4300.      * @author Nicola Asuni
  4301.      * @since 4.9.003 (2010-03-30)
  4302.      */
  4303.     public function getFontDescent($font$style=''$size=0) {
  4304.         $fontdata $this->AddFont($font$style);
  4305.         $fontinfo $this->getFontBuffer($fontdata['fontkey']);
  4306.         if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4307.             $descent = (- $fontinfo['desc']['Descent'] * $size 1000);
  4308.         } else {
  4309.             $descent = (1.219 0.24 $size);
  4310.         }
  4311.         return ($descent $this->k);
  4312.     }
  4313.     /**
  4314.      * Return the font ascent value.
  4315.      * @param string $font font name
  4316.      * @param string $style font style
  4317.      * @param float $size The size (in points)
  4318.      * @return int font ascent
  4319.      * @public
  4320.      * @author Nicola Asuni
  4321.      * @since 4.9.003 (2010-03-30)
  4322.      */
  4323.     public function getFontAscent($font$style=''$size=0) {
  4324.         $fontdata $this->AddFont($font$style);
  4325.         $fontinfo $this->getFontBuffer($fontdata['fontkey']);
  4326.         if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4327.             $ascent = ($fontinfo['desc']['Ascent'] * $size 1000);
  4328.         } else {
  4329.             $ascent 1.219 0.76 $size;
  4330.         }
  4331.         return ($ascent $this->k);
  4332.     }
  4333.     /**
  4334.      * Return true in the character is present in the specified font.
  4335.      * @param mixed $char Character to check (integer value or string)
  4336.      * @param string $font Font name (family name).
  4337.      * @param string $style Font style.
  4338.      * @return bool true if the char is defined, false otherwise.
  4339.      * @public
  4340.      * @since 5.9.153 (2012-03-28)
  4341.      */
  4342.     public function isCharDefined($char$font=''$style='') {
  4343.         if (is_string($char)) {
  4344.             // get character code
  4345.             $char TCPDF_FONTS::UTF8StringToArray($char$this->isunicode$this->CurrentFont);
  4346.             $char $char[0];
  4347.         }
  4348.         if (TCPDF_STATIC::empty_string($font)) {
  4349.             if (TCPDF_STATIC::empty_string($style)) {
  4350.                 return (isset($this->CurrentFont['cw'][intval($char)]));
  4351.             }
  4352.             $font $this->FontFamily;
  4353.         }
  4354.         $fontdata $this->AddFont($font$style);
  4355.         $fontinfo $this->getFontBuffer($fontdata['fontkey']);
  4356.         return (isset($fontinfo['cw'][intval($char)]));
  4357.     }
  4358.     /**
  4359.      * Replace missing font characters on selected font with specified substitutions.
  4360.      * @param string $text Text to process.
  4361.      * @param string $font Font name (family name).
  4362.      * @param string $style Font style.
  4363.      * @param array $subs Array of possible character substitutions. The key is the character to check (integer value) and the value is a single intege value or an array of possible substitutes.
  4364.      * @return string Processed text.
  4365.      * @public
  4366.      * @since 5.9.153 (2012-03-28)
  4367.      */
  4368.     public function replaceMissingChars($text$font=''$style=''$subs=array()) {
  4369.         if (empty($subs)) {
  4370.             return $text;
  4371.         }
  4372.         if (TCPDF_STATIC::empty_string($font)) {
  4373.             $font $this->FontFamily;
  4374.         }
  4375.         $fontdata $this->AddFont($font$style);
  4376.         $fontinfo $this->getFontBuffer($fontdata['fontkey']);
  4377.         $uniarr TCPDF_FONTS::UTF8StringToArray($text$this->isunicode$this->CurrentFont);
  4378.         foreach ($uniarr as $k => $chr) {
  4379.             if (!isset($fontinfo['cw'][$chr])) {
  4380.                 // this character is missing on the selected font
  4381.                 if (isset($subs[$chr])) {
  4382.                     // we have available substitutions
  4383.                     if (is_array($subs[$chr])) {
  4384.                         foreach($subs[$chr] as $s) {
  4385.                             if (isset($fontinfo['cw'][$s])) {
  4386.                                 $uniarr[$k] = $s;
  4387.                                 break;
  4388.                             }
  4389.                         }
  4390.                     } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4391.                         $uniarr[$k] = $subs[$chr];
  4392.                     }
  4393.                 }
  4394.             }
  4395.         }
  4396.         return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr$this->isunicode));
  4397.     }
  4398.     /**
  4399.      * Defines the default monospaced font.
  4400.      * @param string $font Font name.
  4401.      * @public
  4402.      * @since 4.5.025
  4403.      */
  4404.     public function setDefaultMonospacedFont($font) {
  4405.         $this->default_monospaced_font $font;
  4406.     }
  4407.     /**
  4408.      * 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 />
  4409.      * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4410.      * @public
  4411.      * @since 1.5
  4412.      * @see Cell(), Write(), Image(), Link(), SetLink()
  4413.      */
  4414.     public function AddLink() {
  4415.         // create a new internal link
  4416.         $n count($this->links) + 1;
  4417.         $this->links[$n] = array('p' => 0'y' => 0'f' => false);
  4418.         return $n;
  4419.     }
  4420.     /**
  4421.      * Defines the page and position a link points to.
  4422.      * @param int $link The link identifier returned by AddLink()
  4423.      * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4424.      * @param int|string $page Number of target page; -1 indicates the current page (default value). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  4425.      * @public
  4426.      * @since 1.5
  4427.      * @see AddLink()
  4428.      */
  4429.     public function setLink($link$y=0$page=-1) {
  4430.         $fixed false;
  4431.         if (!empty($page) AND (substr($page01) == '*')) {
  4432.             $page intval(substr($page1));
  4433.             // this page number will not be changed when moving/add/deleting pages
  4434.             $fixed true;
  4435.         }
  4436.         if ($page 0) {
  4437.             $page $this->page;
  4438.         }
  4439.         if ($y == -1) {
  4440.             $y $this->y;
  4441.         }
  4442.         $this->links[$link] = array('p' => $page'y' => $y'f' => $fixed);
  4443.     }
  4444.     /**
  4445.      * Puts a link on a rectangular area of the page.
  4446.      * 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.
  4447.      * @param float $x Abscissa of the upper-left corner of the rectangle
  4448.      * @param float $y Ordinate of the upper-left corner of the rectangle
  4449.      * @param float $w Width of the rectangle
  4450.      * @param float $h Height of the rectangle
  4451.      * @param mixed $link URL or identifier returned by AddLink()
  4452.      * @param int $spaces number of spaces on the text to link
  4453.      * @public
  4454.      * @since 1.5
  4455.      * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4456.      */
  4457.     public function Link($x$y$w$h$link$spaces=0) {
  4458.         $this->Annotation($x$y$w$h$link, array('Subtype'=>'Link'), $spaces);
  4459.     }
  4460.     /**
  4461.      * Puts a markup annotation on a rectangular area of the page.
  4462.      * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4463.      * @param float $x Abscissa of the upper-left corner of the rectangle
  4464.      * @param float $y Ordinate of the upper-left corner of the rectangle
  4465.      * @param float $w Width of the rectangle
  4466.      * @param float $h Height of the rectangle
  4467.      * @param string $text annotation text or alternate content
  4468.      * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  4469.      * @param int $spaces number of spaces on the text to link
  4470.      * @public
  4471.      * @since 4.0.018 (2008-08-06)
  4472.      */
  4473.     public function Annotation($x$y$w$h$text$opt=array('Subtype'=>'Text'), $spaces=0) {
  4474.         if ($this->inxobj) {
  4475.             // store parameters for later use on template
  4476.             $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x'y' => $y'w' => $w'h' => $h'text' => $text'opt' => $opt'spaces' => $spaces);
  4477.             return;
  4478.         }
  4479.         if ($x === '') {
  4480.             $x $this->x;
  4481.         }
  4482.         if ($y === '') {
  4483.             $y $this->y;
  4484.         }
  4485.         // check page for no-write regions and adapt page margins if necessary
  4486.         list($x$y) = $this->checkPageRegions($h$x$y);
  4487.         // recalculate coordinates to account for graphic transformations
  4488.         if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4489.             for ($i=$this->transfmatrix_key$i 0; --$i) {
  4490.                 $maxid count($this->transfmatrix[$i]) - 1;
  4491.                 for ($j=$maxid$j >= 0; --$j) {
  4492.                     $ctm $this->transfmatrix[$i][$j];
  4493.                     if (isset($ctm['a'])) {
  4494.                         $x $x $this->k;
  4495.                         $y = ($this->$y) * $this->k;
  4496.                         $w $w $this->k;
  4497.                         $h $h $this->k;
  4498.                         // top left
  4499.                         $xt $x;
  4500.                         $yt $y;
  4501.                         $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4502.                         $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4503.                         // top right
  4504.                         $xt $x $w;
  4505.                         $yt $y;
  4506.                         $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4507.                         $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4508.                         // bottom left
  4509.                         $xt $x;
  4510.                         $yt $y $h;
  4511.                         $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4512.                         $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4513.                         // bottom right
  4514.                         $xt $x $w;
  4515.                         $yt $y $h;
  4516.                         $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4517.                         $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4518.                         // new coordinates (rectangle area)
  4519.                         $x min($x1$x2$x3$x4);
  4520.                         $y max($y1$y2$y3$y4);
  4521.                         $w = (max($x1$x2$x3$x4) - $x) / $this->k;
  4522.                         $h = ($y min($y1$y2$y3$y4)) / $this->k;
  4523.                         $x $x $this->k;
  4524.                         $y $this->- ($y $this->k);
  4525.                     }
  4526.                 }
  4527.             }
  4528.         }
  4529.         if ($this->page <= 0) {
  4530.             $page 1;
  4531.         } else {
  4532.             $page $this->page;
  4533.         }
  4534.         if (!isset($this->PageAnnots[$page])) {
  4535.             $this->PageAnnots[$page] = array();
  4536.         }
  4537.         $this->PageAnnots[$page][] = array('n' => ++$this->n'x' => $x'y' => $y'w' => $w'h' => $h'txt' => $text'opt' => $opt'numspaces' => $spaces);
  4538.         if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) {
  4539.             if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4540.                 AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4541.                 AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4542.                 $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n'n' => ++$this->n'file' => $opt['FS']);
  4543.             }
  4544.         }
  4545.         // Add widgets annotation's icons
  4546.         if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
  4547.             $this->Image($opt['mk']['i'], ''''1010''''''false300''falsefalse0falsetrue);
  4548.         }
  4549.         if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
  4550.             $this->Image($opt['mk']['ri'], ''''00''''''false300''falsefalse0falsetrue);
  4551.         }
  4552.         if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
  4553.             $this->Image($opt['mk']['ix'], ''''00''''''false300''falsefalse0falsetrue);
  4554.         }
  4555.     }
  4556.     /**
  4557.      * Embedd the attached files.
  4558.      * @since 4.4.000 (2008-12-07)
  4559.      * @protected
  4560.      * @see Annotation()
  4561.      */
  4562.     protected function _putEmbeddedFiles() {
  4563.         if ($this->pdfa_mode && $this->pdfa_version != 3)  {
  4564.             // embedded files are not allowed in PDF/A mode version 1 and 2
  4565.             return;
  4566.         }
  4567.         reset($this->embeddedfiles);
  4568.         foreach ($this->embeddedfiles as $filename => $filedata) {
  4569.             $data $this->getCachedFileContents($filedata['file']);
  4570.             if ($data !== FALSE) {
  4571.                 $rawsize strlen($data);
  4572.                 if ($rawsize 0) {
  4573.                     // update name tree
  4574.                     $this->efnames[$filename] = $filedata['f'].' 0 R';
  4575.                     // embedded file specification object
  4576.                     $out $this->_getobj($filedata['f'])."\n";
  4577.                     $out .= '<</Type /Filespec /F '.$this->_datastring($filename$filedata['f']);
  4578.                     $out .= ' /UF '.$this->_datastring($filename$filedata['f']);
  4579.                     $out .= ' /AFRelationship /Source';
  4580.                     $out .= ' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4581.                     $out .= "\n".'endobj';
  4582.                     $this->_out($out);
  4583.                     // embedded file object
  4584.                     $filter '';
  4585.                     if ($this->compress) {
  4586.                         $data gzcompress($data);
  4587.                         $filter ' /Filter /FlateDecode';
  4588.                     }
  4589.                     if ($this->pdfa_version == 3) {
  4590.                         $filter ' /Subtype /text#2Fxml';
  4591.                     }
  4592.                     $stream $this->_getrawstream($data$filedata['n']);
  4593.                     $out $this->_getobj($filedata['n'])."\n";
  4594.                     $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4595.                     $out .= ' stream'."\n".$stream."\n".'endstream';
  4596.                     $out .= "\n".'endobj';
  4597.                     $this->_out($out);
  4598.                 }
  4599.             }
  4600.         }
  4601.     }
  4602.     /**
  4603.      * Prints a text cell at the specified position.
  4604.      * This method allows to place a string precisely on the page.
  4605.      * @param float $x Abscissa of the cell origin
  4606.      * @param float $y Ordinate of the cell origin
  4607.      * @param string $txt String to print
  4608.      * @param int $fstroke outline size in user units (0 = disable)
  4609.      * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4610.      * @param boolean $ffill if true fills the text
  4611.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4612.      * @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.
  4613.      * @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>
  4614.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4615.      * @param mixed $link URL or identifier returned by AddLink().
  4616.      * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4617.      * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4618.      * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
  4619.      * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4620.      * @param boolean $rtloff if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4621.      * @public
  4622.      * @since 1.0
  4623.      * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4624.      */
  4625.     public function Text($x$y$txt$fstroke=0$fclip=false$ffill=true$border=0$ln=0$align=''$fill=false$link=''$stretch=0$ignore_min_height=false$calign='T'$valign='M'$rtloff=false) {
  4626.         $textrendermode $this->textrendermode;
  4627.         $textstrokewidth $this->textstrokewidth;
  4628.         $this->setTextRenderingMode($fstroke$ffill$fclip);
  4629.         $this->setXY($x$y$rtloff);
  4630.         $this->Cell(00$txt$border$ln$align$fill$link$stretch$ignore_min_height$calign$valign);
  4631.         // restore previous rendering mode
  4632.         $this->textrendermode $textrendermode;
  4633.         $this->textstrokewidth $textstrokewidth;
  4634.     }
  4635.     /**
  4636.      * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4637.      * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4638.      * This method is called automatically and should not be called directly by the application.
  4639.      * @return bool
  4640.      * @public
  4641.      * @since 1.4
  4642.      * @see SetAutoPageBreak()
  4643.      */
  4644.     public function AcceptPageBreak() {
  4645.         if ($this->num_columns 1) {
  4646.             // multi column mode
  4647.             if ($this->current_column < ($this->num_columns 1)) {
  4648.                 // go to next column
  4649.                 $this->selectColumn($this->current_column 1);
  4650.             } elseif ($this->AutoPageBreak) {
  4651.                 // add a new page
  4652.                 $this->AddPage();
  4653.                 // set first column
  4654.                 $this->selectColumn(0);
  4655.             }
  4656.             // avoid page breaking from checkPageBreak()
  4657.             return false;
  4658.         }
  4659.         return $this->AutoPageBreak;
  4660.     }
  4661.     /**
  4662.      * Add page if needed.
  4663.      * @param float $h Cell height. Default value: 0.
  4664.      * @param float|null $y starting y position, leave empty for current position.
  4665.      * @param bool  $addpage if true add a page, otherwise only return the true/false state
  4666.      * @return bool true in case of page break, false otherwise.
  4667.      * @since 3.2.000 (2008-07-01)
  4668.      * @protected
  4669.      */
  4670.     protected function checkPageBreak($h=0$y=null$addpage=true) {
  4671.         if (TCPDF_STATIC::empty_string($y)) {
  4672.             $y $this->y;
  4673.         }
  4674.         $current_page $this->page;
  4675.         if ((($y $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4676.             if ($addpage) {
  4677.                 //Automatic page break
  4678.                 $x $this->x;
  4679.                 $this->AddPage($this->CurOrientation);
  4680.                 $this->$this->tMargin;
  4681.                 $oldpage $this->page 1;
  4682.                 if ($this->rtl) {
  4683.                     if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4684.                         $this->$x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4685.                     } else {
  4686.                         $this->$x;
  4687.                     }
  4688.                 } else {
  4689.                     if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4690.                         $this->$x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4691.                     } else {
  4692.                         $this->$x;
  4693.                     }
  4694.                 }
  4695.             }
  4696.             return true;
  4697.         }
  4698.         if ($current_page != $this->page) {
  4699.             // account for columns mode
  4700.             return true;
  4701.         }
  4702.         return false;
  4703.     }
  4704.     /**
  4705.      * 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 />
  4706.      * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4707.      * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4708.      * @param float $h Cell height. Default value: 0.
  4709.      * @param string $txt String to print. Default value: empty string.
  4710.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4711.      * @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.
  4712.      * @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>
  4713.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4714.      * @param mixed $link URL or identifier returned by AddLink().
  4715.      * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4716.      * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4717.      * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  4718.      * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4719.      * @public
  4720.      * @since 1.0
  4721.      * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4722.      */
  4723.     public function Cell($w$h=0$txt=''$border=0$ln=0$align=''$fill=false$link=''$stretch=0$ignore_min_height=false$calign='T'$valign='M') {
  4724.         $prev_cell_margin $this->cell_margin;
  4725.         $prev_cell_padding $this->cell_padding;
  4726.         $this->adjustCellPadding($border);
  4727.         if (!$ignore_min_height) {
  4728.             $min_cell_height $this->getCellHeight($this->FontSize);
  4729.             if ($h $min_cell_height) {
  4730.                 $h $min_cell_height;
  4731.             }
  4732.         }
  4733.         $this->checkPageBreak($h $this->cell_margin['T'] + $this->cell_margin['B']);
  4734.         // apply text shadow if enabled
  4735.         if ($this->txtshadow['enabled']) {
  4736.             // save data
  4737.             $x $this->x;
  4738.             $y $this->y;
  4739.             $bc $this->bgcolor;
  4740.             $fc $this->fgcolor;
  4741.             $sc $this->strokecolor;
  4742.             $alpha $this->alpha;
  4743.             // print shadow
  4744.             $this->+= $this->txtshadow['depth_w'];
  4745.             $this->+= $this->txtshadow['depth_h'];
  4746.             $this->setFillColorArray($this->txtshadow['color']);
  4747.             $this->setTextColorArray($this->txtshadow['color']);
  4748.             $this->setDrawColorArray($this->txtshadow['color']);
  4749.             if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4750.                 $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4751.             }
  4752.             if ($this->state == 2) {
  4753.                 $this->_out($this->getCellCode($w$h$txt$border$ln$align$fill$link$stretchtrue$calign$valign));
  4754.             }
  4755.             //restore data
  4756.             $this->$x;
  4757.             $this->$y;
  4758.             $this->setFillColorArray($bc);
  4759.             $this->setTextColorArray($fc);
  4760.             $this->setDrawColorArray($sc);
  4761.             if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4762.                 $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4763.             }
  4764.         }
  4765.         if ($this->state == 2) {
  4766.             $this->_out($this->getCellCode($w$h$txt$border$ln$align$fill$link$stretchtrue$calign$valign));
  4767.         }
  4768.         $this->cell_padding $prev_cell_padding;
  4769.         $this->cell_margin $prev_cell_margin;
  4770.     }
  4771.     /**
  4772.      * 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 />
  4773.      * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4774.      * @param float $w Cell width. If 0, the cell extends up to the right margin.
  4775.      * @param float $h Cell height. Default value: 0.
  4776.      * @param string $txt String to print. Default value: empty string.
  4777.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4778.      * @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.
  4779.      * @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>
  4780.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  4781.      * @param mixed $link URL or identifier returned by AddLink().
  4782.      * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  4783.      * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  4784.      * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  4785.      * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  4786.      * @return string containing cell code
  4787.      * @protected
  4788.      * @since 1.0
  4789.      * @see Cell()
  4790.      */
  4791.     protected function getCellCode($w$h=0$txt=''$border=0$ln=0$align=''$fill=false$link=''$stretch=0$ignore_min_height=false$calign='T'$valign='M') {
  4792.         // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4793.         $txt is_null($txt) ? '' $txt;
  4794.         $txt str_replace(TCPDF_FONTS::unichr(160$this->isunicode), ' '$txt);
  4795.         $prev_cell_margin $this->cell_margin;
  4796.         $prev_cell_padding $this->cell_padding;
  4797.         $txt TCPDF_STATIC::removeSHY($txt$this->isunicode);
  4798.         $rs ''//string to be returned
  4799.         $this->adjustCellPadding($border);
  4800.         if (!$ignore_min_height) {
  4801.             $min_cell_height $this->getCellHeight($this->FontSize);
  4802.             if ($h $min_cell_height) {
  4803.                 $h $min_cell_height;
  4804.             }
  4805.         }
  4806.         $k $this->k;
  4807.         // check page for no-write regions and adapt page margins if necessary
  4808.         list($this->x$this->y) = $this->checkPageRegions($h$this->x$this->y);
  4809.         if ($this->rtl) {
  4810.             $x $this->$this->cell_margin['R'];
  4811.         } else {
  4812.             $x $this->$this->cell_margin['L'];
  4813.         }
  4814.         $y $this->$this->cell_margin['T'];
  4815.         $prev_font_stretching $this->font_stretching;
  4816.         $prev_font_spacing $this->font_spacing;
  4817.         // cell vertical alignment
  4818.         switch ($calign) {
  4819.             case 'A': {
  4820.                 // font top
  4821.                 switch ($valign) {
  4822.                     case 'T': {
  4823.                         // top
  4824.                         $y -= $this->cell_padding['T'];
  4825.                         break;
  4826.                     }
  4827.                     case 'B': {
  4828.                         // bottom
  4829.                         $y -= ($h $this->cell_padding['B'] - $this->FontAscent $this->FontDescent);
  4830.                         break;
  4831.                     }
  4832.                     default:
  4833.                     case 'C':
  4834.                     case 'M': {
  4835.                         // center
  4836.                         $y -= (($h $this->FontAscent $this->FontDescent) / 2);
  4837.                         break;
  4838.                     }
  4839.                 }
  4840.                 break;
  4841.             }
  4842.             case 'L': {
  4843.                 // font baseline
  4844.                 switch ($valign) {
  4845.                     case 'T': {
  4846.                         // top
  4847.                         $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4848.                         break;
  4849.                     }
  4850.                     case 'B': {
  4851.                         // bottom
  4852.                         $y -= ($h $this->cell_padding['B'] - $this->FontDescent);
  4853.                         break;
  4854.                     }
  4855.                     default:
  4856.                     case 'C':
  4857.                     case 'M': {
  4858.                         // center
  4859.                         $y -= (($h $this->FontAscent $this->FontDescent) / 2);
  4860.                         break;
  4861.                     }
  4862.                 }
  4863.                 break;
  4864.             }
  4865.             case 'D': {
  4866.                 // font bottom
  4867.                 switch ($valign) {
  4868.                     case 'T': {
  4869.                         // top
  4870.                         $y -= ($this->cell_padding['T'] + $this->FontAscent $this->FontDescent);
  4871.                         break;
  4872.                     }
  4873.                     case 'B': {
  4874.                         // bottom
  4875.                         $y -= ($h $this->cell_padding['B']);
  4876.                         break;
  4877.                     }
  4878.                     default:
  4879.                     case 'C':
  4880.                     case 'M': {
  4881.                         // center
  4882.                         $y -= (($h $this->FontAscent $this->FontDescent) / 2);
  4883.                         break;
  4884.                     }
  4885.                 }
  4886.                 break;
  4887.             }
  4888.             case 'B': {
  4889.                 // cell bottom
  4890.                 $y -= $h;
  4891.                 break;
  4892.             }
  4893.             case 'C':
  4894.             case 'M': {
  4895.                 // cell center
  4896.                 $y -= ($h 2);
  4897.                 break;
  4898.             }
  4899.             default:
  4900.             case 'T': {
  4901.                 // cell top
  4902.                 break;
  4903.             }
  4904.         }
  4905.         // text vertical alignment
  4906.         switch ($valign) {
  4907.             case 'T': {
  4908.                 // top
  4909.                 $yt $y $this->cell_padding['T'];
  4910.                 break;
  4911.             }
  4912.             case 'B': {
  4913.                 // bottom
  4914.                 $yt $y $h $this->cell_padding['B'] - $this->FontAscent $this->FontDescent;
  4915.                 break;
  4916.             }
  4917.             default:
  4918.             case 'C':
  4919.             case 'M': {
  4920.                 // center
  4921.                 $yt $y + (($h $this->FontAscent $this->FontDescent) / 2);
  4922.                 break;
  4923.             }
  4924.         }
  4925.         $basefonty $yt $this->FontAscent;
  4926.         if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4927.             if ($this->rtl) {
  4928.                 $w $x $this->lMargin;
  4929.             } else {
  4930.                 $w $this->$this->rMargin $x;
  4931.             }
  4932.         }
  4933.         $s '';
  4934.         // fill and borders
  4935.         if (is_string($border) AND (strlen($border) == 4)) {
  4936.             // full border
  4937.             $border 1;
  4938.         }
  4939.         if ($fill OR ($border == 1)) {
  4940.             if ($fill) {
  4941.                 $op = ($border == 1) ? 'B' 'f';
  4942.             } else {
  4943.                 $op 'S';
  4944.             }
  4945.             if ($this->rtl) {
  4946.                 $xk = (($x $w) * $k);
  4947.             } else {
  4948.                 $xk = ($x $k);
  4949.             }
  4950.             $s .= sprintf('%F %F %F %F re %s '$xk, (($this->$y) * $k), ($w $k), (-$h $k), $op);
  4951.         }
  4952.         // draw borders
  4953.         $s .= $this->getCellBorder($x$y$w$h$border);
  4954.         if ($txt != '') {
  4955.             $txt2 $txt;
  4956.             if ($this->isunicode) {
  4957.                 if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  4958.                     $txt2 TCPDF_FONTS::UTF8ToLatin1($txt2$this->isunicode$this->CurrentFont);
  4959.                 } else {
  4960.                     $unicode TCPDF_FONTS::UTF8StringToArray($txt$this->isunicode$this->CurrentFont); // array of UTF-8 unicode values
  4961.                     $unicode TCPDF_FONTS::utf8Bidi($unicode''$this->tmprtl$this->isunicode$this->CurrentFont);
  4962.                     // replace thai chars (if any)
  4963.                     if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  4964.                         // number of chars
  4965.                         $numchars count($unicode);
  4966.                         // po pla, for far, for fan
  4967.                         $longtail = array(0x0e1b0x0e1d0x0e1f);
  4968.                         // do chada, to patak
  4969.                         $lowtail = array(0x0e0e0x0e0f);
  4970.                         // mai hun arkad, sara i, sara ii, sara ue, sara uee
  4971.                         $upvowel = array(0x0e310x0e340x0e350x0e360x0e37);
  4972.                         // mai ek, mai tho, mai tri, mai chattawa, karan
  4973.                         $tonemark = array(0x0e480x0e490x0e4a0x0e4b0x0e4c);
  4974.                         // sara u, sara uu, pinthu
  4975.                         $lowvowel = array(0x0e380x0e390x0e3a);
  4976.                         $output = array();
  4977.                         for ($i 0$i $numchars$i++) {
  4978.                             if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  4979.                                 $ch0 $unicode[$i];
  4980.                                 $ch1 = ($i 0) ? $unicode[($i 1)] : 0;
  4981.                                 $ch2 = ($i 1) ? $unicode[($i 2)] : 0;
  4982.                                 $chn = ($i < ($numchars 1)) ? $unicode[($i 1)] : 0;
  4983.                                 if (in_array($ch0$tonemark)) {
  4984.                                     if ($chn == 0x0e33) {
  4985.                                         // sara um
  4986.                                         if (in_array($ch1$longtail)) {
  4987.                                             // tonemark at upper left
  4988.                                             $output[] = $this->replaceChar($ch0, (0xf713 $ch0 0x0e48));
  4989.                                         } else {
  4990.                                             // tonemark at upper right (normal position)
  4991.                                             $output[] = $ch0;
  4992.                                         }
  4993.                                     } elseif (in_array($ch1$longtail) OR (in_array($ch2$longtail) AND in_array($ch1$lowvowel))) {
  4994.                                         // tonemark at lower left
  4995.                                         $output[] = $this->replaceChar($ch0, (0xf705 $ch0 0x0e48));
  4996.                                     } elseif (in_array($ch1$upvowel)) {
  4997.                                         if (in_array($ch2$longtail)) {
  4998.                                             // tonemark at upper left
  4999.                                             $output[] = $this->replaceChar($ch0, (0xf713 $ch0 0x0e48));
  5000.                                         } else {
  5001.                                             // tonemark at upper right (normal position)
  5002.                                             $output[] = $ch0;
  5003.                                         }
  5004.                                     } else {
  5005.                                         // tonemark at lower right
  5006.                                         $output[] = $this->replaceChar($ch0, (0xf70a $ch0 0x0e48));
  5007.                                     }
  5008.                                 } elseif (($ch0 == 0x0e33) AND (in_array($ch1$longtail) OR (in_array($ch2$longtail) AND in_array($ch1$tonemark)))) {
  5009.                                     // add lower left nikhahit and sara aa
  5010.                                     if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  5011.                                         $output[] = 0xf711;
  5012.                                         $this->CurrentFont['subsetchars'][0xf711] = true;
  5013.                                         $output[] = 0x0e32;
  5014.                                         $this->CurrentFont['subsetchars'][0x0e32] = true;
  5015.                                     } else {
  5016.                                         $output[] = $ch0;
  5017.                                     }
  5018.                                 } elseif (in_array($ch1$longtail)) {
  5019.                                     if ($ch0 == 0x0e31) {
  5020.                                         // lower left mai hun arkad
  5021.                                         $output[] = $this->replaceChar($ch00xf710);
  5022.                                     } elseif (in_array($ch0$upvowel)) {
  5023.                                         // lower left
  5024.                                         $output[] = $this->replaceChar($ch0, (0xf701 $ch0 0x0e34));
  5025.                                     } elseif ($ch0 == 0x0e47) {
  5026.                                         // lower left mai tai koo
  5027.                                         $output[] = $this->replaceChar($ch00xf712);
  5028.                                     } else {
  5029.                                         // normal character
  5030.                                         $output[] = $ch0;
  5031.                                     }
  5032.                                 } elseif (in_array($ch1$lowtail) AND in_array($ch0$lowvowel)) {
  5033.                                     // lower vowel
  5034.                                     $output[] = $this->replaceChar($ch0, (0xf718 $ch0 0x0e38));
  5035.                                 } elseif (($ch0 == 0x0e0d) AND in_array($chn$lowvowel)) {
  5036.                                     // yo ying without lower part
  5037.                                     $output[] = $this->replaceChar($ch00xf70f);
  5038.                                 } elseif (($ch0 == 0x0e10) AND in_array($chn$lowvowel)) {
  5039.                                     // tho santan without lower part
  5040.                                     $output[] = $this->replaceChar($ch00xf700);
  5041.                                 } else {
  5042.                                     $output[] = $ch0;
  5043.                                 }
  5044.                             } else {
  5045.                                 // non-thai character
  5046.                                 $output[] = $unicode[$i];
  5047.                             }
  5048.                         }
  5049.                         $unicode $output;
  5050.                         // update font subsetchars
  5051.                         $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars'$this->CurrentFont['subsetchars']);
  5052.                     } // end of K_THAI_TOPCHARS
  5053.                     $txt2 TCPDF_FONTS::arrUTF8ToUTF16BE($unicodefalse);
  5054.                 }
  5055.             }
  5056.             $txt2 TCPDF_STATIC::_escape($txt2);
  5057.             // get current text width (considering general font stretching and spacing)
  5058.             $txwidth $this->GetStringWidth($txt);
  5059.             $width $txwidth;
  5060.             // check for stretch mode
  5061.             if ($stretch 0) {
  5062.                 // calculate ratio between cell width and text width
  5063.                 if ($width <= 0) {
  5064.                     $ratio 1;
  5065.                 } else {
  5066.                     $ratio = (($w $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  5067.                 }
  5068.                 // check if stretching is required
  5069.                 if (($ratio 1) OR (($ratio 1) AND (($stretch 2) == 0))) {
  5070.                     // the text will be stretched to fit cell width
  5071.                     if ($stretch 2) {
  5072.                         // set new character spacing
  5073.                         $this->font_spacing += ($w $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching 100));
  5074.                     } else {
  5075.                         // set new horizontal stretching
  5076.                         $this->font_stretching *= $ratio;
  5077.                     }
  5078.                     // recalculate text width (the text fills the entire cell)
  5079.                     $width $w $this->cell_padding['L'] - $this->cell_padding['R'];
  5080.                     // reset alignment
  5081.                     $align '';
  5082.                 }
  5083.             }
  5084.             if ($this->font_stretching != 100) {
  5085.                 // apply font stretching
  5086.                 $rs .= sprintf('BT %F Tz ET '$this->font_stretching);
  5087.             }
  5088.             if ($this->font_spacing != 0) {
  5089.                 // increase/decrease font spacing
  5090.                 $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing $this->k));
  5091.             }
  5092.             if ($this->ColorFlag AND ($this->textrendermode 4)) {
  5093.                 $s .= 'q '.$this->TextColor.' ';
  5094.             }
  5095.             // rendering mode
  5096.             $s .= sprintf('BT %d Tr %F w ET '$this->textrendermode, ($this->textstrokewidth $this->k));
  5097.             // count number of spaces
  5098.             $ns substr_count($txtchr(32));
  5099.             // Justification
  5100.             $spacewidth 0;
  5101.             if (($align == 'J') AND ($ns 0)) {
  5102.                 if ($this->isUnicodeFont()) {
  5103.                     // get string width without spaces
  5104.                     $width $this->GetStringWidth(str_replace(' '''$txt));
  5105.                     // calculate average space width
  5106.                     $spacewidth = -1000 * ($w $width $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  5107.                     if ($this->font_stretching != 100) {
  5108.                         // word spacing is affected by stretching
  5109.                         $spacewidth /= ($this->font_stretching 100);
  5110.                     }
  5111.                     // set word position to be used with TJ operator
  5112.                     $txt2 str_replace(chr(0).chr(32), ') '.sprintf('%F'$spacewidth).' ('$txt2);
  5113.                     $unicode_justification true;
  5114.                 } else {
  5115.                     // get string width
  5116.                     $width $txwidth;
  5117.                     // new space width
  5118.                     $spacewidth = (($w $width $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5119.                     if ($this->font_stretching != 100) {
  5120.                         // word spacing (Tw) is affected by stretching
  5121.                         $spacewidth /= ($this->font_stretching 100);
  5122.                     }
  5123.                     // set word spacing
  5124.                     $rs .= sprintf('BT %F Tw ET '$spacewidth);
  5125.                 }
  5126.                 $width $w $this->cell_padding['L'] - $this->cell_padding['R'];
  5127.             }
  5128.             // replace carriage return characters
  5129.             $txt2 str_replace("\r"' '$txt2);
  5130.             switch ($align) {
  5131.                 case 'C': {
  5132.                     $dx = ($w $width) / 2;
  5133.                     break;
  5134.                 }
  5135.                 case 'R': {
  5136.                     if ($this->rtl) {
  5137.                         $dx $this->cell_padding['R'];
  5138.                     } else {
  5139.                         $dx $w $width $this->cell_padding['R'];
  5140.                     }
  5141.                     break;
  5142.                 }
  5143.                 case 'L': {
  5144.                     if ($this->rtl) {
  5145.                         $dx $w $width $this->cell_padding['L'];
  5146.                     } else {
  5147.                         $dx $this->cell_padding['L'];
  5148.                     }
  5149.                     break;
  5150.                 }
  5151.                 case 'J':
  5152.                 default: {
  5153.                     if ($this->rtl) {
  5154.                         $dx $this->cell_padding['R'];
  5155.                     } else {
  5156.                         $dx $this->cell_padding['L'];
  5157.                     }
  5158.                     break;
  5159.                 }
  5160.             }
  5161.             if ($this->rtl) {
  5162.                 $xdx $x $dx $width;
  5163.             } else {
  5164.                 $xdx $x $dx;
  5165.             }
  5166.             $xdk $xdx $k;
  5167.             // print text
  5168.             $s .= sprintf('BT %F %F Td [(%s)] TJ ET'$xdk, (($this->$basefonty) * $k), $txt2);
  5169.             if (isset($uniblock)) { // @phpstan-ignore-line
  5170.                 // print overlapping characters as separate string
  5171.                 $xshift 0// horizontal shift
  5172.                 $ty = (($this->$basefonty + (0.2 $this->FontSize)) * $k);
  5173.                 $spw = (($w $txwidth $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5174.                 foreach ($uniblock as $uk => $uniarr) { // @phpstan-ignore-line
  5175.                     if (($uk 2) == 0) {
  5176.                         // x space to skip
  5177.                         if ($spacewidth != 0) {
  5178.                             // justification shift
  5179.                             $xshift += (count(array_keys($uniarr32)) * $spw);
  5180.                         }
  5181.                         $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5182.                     } else {
  5183.                         // character to print
  5184.                         $topchr TCPDF_FONTS::arrUTF8ToUTF16BE($uniarrfalse);
  5185.                         $topchr TCPDF_STATIC::_escape($topchr);
  5186.                         $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift $k)), $ty$topchr);
  5187.                     }
  5188.                 }
  5189.             }
  5190.             if ($this->underline) {
  5191.                 $s .= ' '.$this->_dounderlinew($xdx$basefonty$width);
  5192.             }
  5193.             if ($this->linethrough) {
  5194.                 $s .= ' '.$this->_dolinethroughw($xdx$basefonty$width);
  5195.             }
  5196.             if ($this->overline) {
  5197.                 $s .= ' '.$this->_dooverlinew($xdx$basefonty$width);
  5198.             }
  5199.             if ($this->ColorFlag AND ($this->textrendermode 4)) {
  5200.                 $s .= ' Q';
  5201.             }
  5202.             if ($link) {
  5203.                 $this->Link($xdx$yt$width, ($this->FontAscent $this->FontDescent), $link$ns);
  5204.             }
  5205.         }
  5206.         // output cell
  5207.         if ($s) {
  5208.             // output cell
  5209.             $rs .= $s;
  5210.             if ($this->font_spacing != 0) {
  5211.                 // reset font spacing mode
  5212.                 $rs .= ' BT 0 Tc ET';
  5213.             }
  5214.             if ($this->font_stretching != 100) {
  5215.                 // reset font stretching mode
  5216.                 $rs .= ' BT 100 Tz ET';
  5217.             }
  5218.         }
  5219.         // reset word spacing
  5220.         if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5221.             $rs .= ' BT 0 Tw ET';
  5222.         }
  5223.         // reset stretching and spacing
  5224.         $this->font_stretching $prev_font_stretching;
  5225.         $this->font_spacing $prev_font_spacing;
  5226.         $this->lasth $h;
  5227.         if ($ln 0) {
  5228.             //Go to the beginning of the next line
  5229.             $this->$y $h $this->cell_margin['B'];
  5230.             if ($ln == 1) {
  5231.                 if ($this->rtl) {
  5232.                     $this->$this->$this->rMargin;
  5233.                 } else {
  5234.                     $this->$this->lMargin;
  5235.                 }
  5236.             }
  5237.         } else {
  5238.             // go left or right by case
  5239.             if ($this->rtl) {
  5240.                 $this->$x $w $this->cell_margin['L'];
  5241.             } else {
  5242.                 $this->$x $w $this->cell_margin['R'];
  5243.             }
  5244.         }
  5245.         $gstyles ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5246.         $rs $gstyles.$rs;
  5247.         $this->cell_padding $prev_cell_padding;
  5248.         $this->cell_margin $prev_cell_margin;
  5249.         return $rs;
  5250.     }
  5251.     /**
  5252.      * Replace a char if is defined on the current font.
  5253.      * @param int $oldchar Integer code (unicode) of the character to replace.
  5254.      * @param int $newchar Integer code (unicode) of the new character.
  5255.      * @return int the replaced char or the old char in case the new char i not defined
  5256.      * @protected
  5257.      * @since 5.9.167 (2012-06-22)
  5258.      */
  5259.     protected function replaceChar($oldchar$newchar) {
  5260.         if ($this->isCharDefined($newchar)) {
  5261.             // add the new char on the subset list
  5262.             $this->CurrentFont['subsetchars'][$newchar] = true;
  5263.             // return the new character
  5264.             return $newchar;
  5265.         }
  5266.         // return the old char
  5267.         return $oldchar;
  5268.     }
  5269.     /**
  5270.      * Returns the code to draw the cell border
  5271.      * @param float $x X coordinate.
  5272.      * @param float $y Y coordinate.
  5273.      * @param float $w Cell width.
  5274.      * @param float $h Cell height.
  5275.      * @param string|array|int $brd Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5276.      * @return string containing cell border code
  5277.      * @protected
  5278.      * @see SetLineStyle()
  5279.      * @since 5.7.000 (2010-08-02)
  5280.      */
  5281.     protected function getCellBorder($x$y$w$h$brd) {
  5282.         $s ''// string to be returned
  5283.         if (empty($brd)) {
  5284.             return $s;
  5285.         }
  5286.         if ($brd == 1) {
  5287.             $brd = array('LRTB' => true);
  5288.         }
  5289.         // calculate coordinates for border
  5290.         $k $this->k;
  5291.         if ($this->rtl) {
  5292.             $xeL = ($x $w) * $k;
  5293.             $xeR $x $k;
  5294.         } else {
  5295.             $xeL $x $k;
  5296.             $xeR = ($x $w) * $k;
  5297.         }
  5298.         $yeL = (($this->- ($y $h)) * $k);
  5299.         $yeT = (($this->$y) * $k);
  5300.         $xeT $xeL;
  5301.         $xeB $xeR;
  5302.         $yeR $yeT;
  5303.         $yeB $yeL;
  5304.         if (is_string($brd)) {
  5305.             // convert string to array
  5306.             $slen strlen($brd);
  5307.             $newbrd = array();
  5308.             for ($i 0$i $slen; ++$i) {
  5309.                 $newbrd[$brd[$i]] = array('cap' => 'square''join' => 'miter');
  5310.             }
  5311.             $brd $newbrd;
  5312.         }
  5313.         if (isset($brd['mode'])) {
  5314.             $mode $brd['mode'];
  5315.             unset($brd['mode']);
  5316.         } else {
  5317.             $mode 'normal';
  5318.         }
  5319.         foreach ($brd as $border => $style) {
  5320.             if (is_array($style) AND !empty($style)) {
  5321.                 // apply border style
  5322.                 $prev_style $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5323.                 $s .= $this->setLineStyle($styletrue)."\n";
  5324.             }
  5325.             switch ($mode) {
  5326.                 case 'ext': {
  5327.                     $off = (($this->LineWidth 2) * $k);
  5328.                     $xL $xeL $off;
  5329.                     $xR $xeR $off;
  5330.                     $yT $yeT $off;
  5331.                     $yL $yeL $off;
  5332.                     $xT $xL;
  5333.                     $xB $xR;
  5334.                     $yR $yT;
  5335.                     $yB $yL;
  5336.                     $w += $this->LineWidth;
  5337.                     $h += $this->LineWidth;
  5338.                     break;
  5339.                 }
  5340.                 case 'int': {
  5341.                     $off = ($this->LineWidth 2) * $k;
  5342.                     $xL $xeL $off;
  5343.                     $xR $xeR $off;
  5344.                     $yT $yeT $off;
  5345.                     $yL $yeL $off;
  5346.                     $xT $xL;
  5347.                     $xB $xR;
  5348.                     $yR $yT;
  5349.                     $yB $yL;
  5350.                     $w -= $this->LineWidth;
  5351.                     $h -= $this->LineWidth;
  5352.                     break;
  5353.                 }
  5354.                 case 'normal':
  5355.                 default: {
  5356.                     $xL $xeL;
  5357.                     $xT $xeT;
  5358.                     $xB $xeB;
  5359.                     $xR $xeR;
  5360.                     $yL $yeL;
  5361.                     $yT $yeT;
  5362.                     $yB $yeB;
  5363.                     $yR $yeR;
  5364.                     break;
  5365.                 }
  5366.             }
  5367.             // draw borders by case
  5368.             if (strlen($border) == 4) {
  5369.                 $s .= sprintf('%F %F %F %F re S '$xT$yT, ($w $k), (-$h $k));
  5370.             } elseif (strlen($border) == 3) {
  5371.                 if (strpos($border,'B') === false) { // LTR
  5372.                     $s .= sprintf('%F %F m '$xL$yL);
  5373.                     $s .= sprintf('%F %F l '$xT$yT);
  5374.                     $s .= sprintf('%F %F l '$xR$yR);
  5375.                     $s .= sprintf('%F %F l '$xB$yB);
  5376.                     $s .= 'S ';
  5377.                 } elseif (strpos($border,'L') === false) { // TRB
  5378.                     $s .= sprintf('%F %F m '$xT$yT);
  5379.                     $s .= sprintf('%F %F l '$xR$yR);
  5380.                     $s .= sprintf('%F %F l '$xB$yB);
  5381.                     $s .= sprintf('%F %F l '$xL$yL);
  5382.                     $s .= 'S ';
  5383.                 } elseif (strpos($border,'T') === false) { // RBL
  5384.                     $s .= sprintf('%F %F m '$xR$yR);
  5385.                     $s .= sprintf('%F %F l '$xB$yB);
  5386.                     $s .= sprintf('%F %F l '$xL$yL);
  5387.                     $s .= sprintf('%F %F l '$xT$yT);
  5388.                     $s .= 'S ';
  5389.                 } elseif (strpos($border,'R') === false) { // BLT
  5390.                     $s .= sprintf('%F %F m '$xB$yB);
  5391.                     $s .= sprintf('%F %F l '$xL$yL);
  5392.                     $s .= sprintf('%F %F l '$xT$yT);
  5393.                     $s .= sprintf('%F %F l '$xR$yR);
  5394.                     $s .= 'S ';
  5395.                 }
  5396.             } elseif (strlen($border) == 2) {
  5397.                 if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5398.                     $s .= sprintf('%F %F m '$xL$yL);
  5399.                     $s .= sprintf('%F %F l '$xT$yT);
  5400.                     $s .= sprintf('%F %F l '$xR$yR);
  5401.                     $s .= 'S ';
  5402.                 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5403.                     $s .= sprintf('%F %F m '$xT$yT);
  5404.                     $s .= sprintf('%F %F l '$xR$yR);
  5405.                     $s .= sprintf('%F %F l '$xB$yB);
  5406.                     $s .= 'S ';
  5407.                 } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5408.                     $s .= sprintf('%F %F m '$xR$yR);
  5409.                     $s .= sprintf('%F %F l '$xB$yB);
  5410.                     $s .= sprintf('%F %F l '$xL$yL);
  5411.                     $s .= 'S ';
  5412.                 } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5413.                     $s .= sprintf('%F %F m '$xB$yB);
  5414.                     $s .= sprintf('%F %F l '$xL$yL);
  5415.                     $s .= sprintf('%F %F l '$xT$yT);
  5416.                     $s .= 'S ';
  5417.                 } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5418.                     $s .= sprintf('%F %F m '$xL$yL);
  5419.                     $s .= sprintf('%F %F l '$xT$yT);
  5420.                     $s .= 'S ';
  5421.                     $s .= sprintf('%F %F m '$xR$yR);
  5422.                     $s .= sprintf('%F %F l '$xB$yB);
  5423.                     $s .= 'S ';
  5424.                 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5425.                     $s .= sprintf('%F %F m '$xT$yT);
  5426.                     $s .= sprintf('%F %F l '$xR$yR);
  5427.                     $s .= 'S ';
  5428.                     $s .= sprintf('%F %F m '$xB$yB);
  5429.                     $s .= sprintf('%F %F l '$xL$yL);
  5430.                     $s .= 'S ';
  5431.                 }
  5432.             } else { // strlen($border) == 1
  5433.                 if (strpos($border,'L') !== false) { // L
  5434.                     $s .= sprintf('%F %F m '$xL$yL);
  5435.                     $s .= sprintf('%F %F l '$xT$yT);
  5436.                     $s .= 'S ';
  5437.                 } elseif (strpos($border,'T') !== false) { // T
  5438.                     $s .= sprintf('%F %F m '$xT$yT);
  5439.                     $s .= sprintf('%F %F l '$xR$yR);
  5440.                     $s .= 'S ';
  5441.                 } elseif (strpos($border,'R') !== false) { // R
  5442.                     $s .= sprintf('%F %F m '$xR$yR);
  5443.                     $s .= sprintf('%F %F l '$xB$yB);
  5444.                     $s .= 'S ';
  5445.                 } elseif (strpos($border,'B') !== false) { // B
  5446.                     $s .= sprintf('%F %F m '$xB$yB);
  5447.                     $s .= sprintf('%F %F l '$xL$yL);
  5448.                     $s .= 'S ';
  5449.                 }
  5450.             }
  5451.             if (is_array($style) AND !empty($style)) {
  5452.                 // reset border style to previous value
  5453.                 $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5454.             }
  5455.         }
  5456.         return $s;
  5457.     }
  5458.     /**
  5459.      * This method allows printing text with line breaks.
  5460.      * 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 />
  5461.      * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5462.      * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5463.      * @param float $h Cell minimum height. The cell extends automatically if needed.
  5464.      * @param string $txt String to print
  5465.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5466.      * @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>
  5467.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  5468.      * @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>
  5469.      * @param float|null $x x position in user units
  5470.      * @param float|null $y y position in user units
  5471.      * @param boolean $reseth if true reset the last cell height (default true).
  5472.      * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  5473.      * @param boolean $ishtml INTERNAL USE ONLY -- set to true if $txt is HTML content (default = false). Never set this parameter to true, use instead writeHTMLCell() or writeHTML() methods.
  5474.      * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  5475.      * @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.
  5476.      * @param string $valign Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false and the cell must fit in a single page.
  5477.      * @param boolean $fitcell if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode). $maxh must be greater than 0 and equal to $h.
  5478.      * @return int Return the number of cells or 1 for html mode.
  5479.      * @public
  5480.      * @since 1.3
  5481.      * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5482.      */
  5483.     public function MultiCell($w$h$txt$border=0$align='J'$fill=false$ln=1$x=null$y=null$reseth=true$stretch=0$ishtml=false$autopadding=true$maxh=0$valign='T'$fitcell=false) {
  5484.         $prev_cell_margin $this->cell_margin;
  5485.         $prev_cell_padding $this->cell_padding;
  5486.         // adjust internal padding
  5487.         $this->adjustCellPadding($border);
  5488.         $mc_padding $this->cell_padding;
  5489.         $mc_margin $this->cell_margin;
  5490.         $this->cell_padding['T'] = 0;
  5491.         $this->cell_padding['B'] = 0;
  5492.         $this->setCellMargins(0000);
  5493.         if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5494.             // reset row height
  5495.             $this->resetLastH();
  5496.         }
  5497.         if (!TCPDF_STATIC::empty_string($y)) {
  5498.             $this->setY($y); // set y in order to convert negative y values to positive ones
  5499.         }
  5500.         $y $this->GetY();
  5501.         $resth 0;
  5502.         if (($h 0) AND $this->inPageBody() AND (($y $h $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5503.             // spit cell in more pages/columns
  5504.             $newh = ($this->PageBreakTrigger $y);
  5505.             $resth = ($h $newh); // cell to be printed on the next page/column
  5506.             $h $newh;
  5507.         }
  5508.         // get current page number
  5509.         $startpage $this->page;
  5510.         // get current column
  5511.         $startcolumn $this->current_column;
  5512.         if (!TCPDF_STATIC::empty_string($x)) {
  5513.             $this->setX($x);
  5514.         } else {
  5515.             $x $this->GetX();
  5516.         }
  5517.         // check page for no-write regions and adapt page margins if necessary
  5518.         list($x$y) = $this->checkPageRegions(0$x$y);
  5519.         // apply margins
  5520.         $oy $y $mc_margin['T'];
  5521.         if ($this->rtl) {
  5522.             $ox = ($this->$x $mc_margin['R']);
  5523.         } else {
  5524.             $ox = ($x $mc_margin['L']);
  5525.         }
  5526.         $this->$ox;
  5527.         $this->$oy;
  5528.         // set width
  5529.         if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5530.             if ($this->rtl) {
  5531.                 $w = ($this->$this->lMargin $mc_margin['L']);
  5532.             } else {
  5533.                 $w = ($this->$this->$this->rMargin $mc_margin['R']);
  5534.             }
  5535.         }
  5536.         // store original margin values
  5537.         $lMargin $this->lMargin;
  5538.         $rMargin $this->rMargin;
  5539.         if ($this->rtl) {
  5540.             $this->rMargin = ($this->$this->x);
  5541.             $this->lMargin = ($this->$w);
  5542.         } else {
  5543.             $this->lMargin = ($this->x);
  5544.             $this->rMargin = ($this->$this->$w);
  5545.         }
  5546.         $this->clMargin $this->lMargin;
  5547.         $this->crMargin $this->rMargin;
  5548.         if ($autopadding) {
  5549.             // add top padding
  5550.             $this->+= $mc_padding['T'];
  5551.         }
  5552.         if ($ishtml) { // ******* Write HTML text
  5553.             $this->writeHTML($txttruefalse$resethtrue$align);
  5554.             $nl 1;
  5555.         } else { // ******* Write simple text
  5556.             $prev_FontSizePt $this->FontSizePt;
  5557.             if ($fitcell) {
  5558.                 // ajust height values
  5559.                 $tobottom = ($this->$this->$this->bMargin $this->cell_padding['T'] - $this->cell_padding['B']);
  5560.                 $h $maxh max(min($h$tobottom), min($maxh$tobottom));
  5561.             }
  5562.             // vertical alignment
  5563.             if ($maxh 0) {
  5564.                 // get text height
  5565.                 $text_height $this->getStringHeight($w$txt$reseth$autopadding$mc_padding$border);
  5566.                 if ($fitcell AND ($text_height $maxh) AND ($this->FontSizePt 1)) {
  5567.                     // try to reduce font size to fit text on cell (use a quick search algorithm)
  5568.                     $fmin 1;
  5569.                     $fmax $this->FontSizePt;
  5570.                     $diff_epsilon = ($this->k); // one point (min resolution)
  5571.                     $maxit = (min(100max(10intval($fmax)))); // max number of iterations
  5572.                     while ($maxit >= 0) {
  5573.                         $fmid = (($fmax $fmin) / 2);
  5574.                         $this->setFontSize($fmidfalse);
  5575.                         $this->resetLastH();
  5576.                         $text_height $this->getStringHeight($w$txt$reseth$autopadding$mc_padding$border);
  5577.                         $diff = ($maxh $text_height);
  5578.                         if ($diff >= 0) {
  5579.                             if ($diff <= $diff_epsilon) {
  5580.                                 break;
  5581.                             }
  5582.                             $fmin $fmid;
  5583.                         } else {
  5584.                             $fmax $fmid;
  5585.                         }
  5586.                         --$maxit;
  5587.                     }
  5588.                     if ($maxit 0) {
  5589.                         // premature exit, we get the minimum font value to fit the cell
  5590.                         $this->setFontSize($fmin);
  5591.                         $this->resetLastH();
  5592.                         $text_height $this->getStringHeight($w$txt$reseth$autopadding$mc_padding$border);
  5593.                     } else {
  5594.                         $this->setFontSize($fmid);
  5595.                         $this->resetLastH();
  5596.                     }
  5597.                 }
  5598.                 if ($text_height $maxh) {
  5599.                     if ($valign == 'M') {
  5600.                         // text vertically centered
  5601.                         $this->+= (($maxh $text_height) / 2);
  5602.                     } elseif ($valign == 'B') {
  5603.                         // text vertically aligned on bottom
  5604.                         $this->+= ($maxh $text_height);
  5605.                     }
  5606.                 }
  5607.             }
  5608.             $nl $this->Write($this->lasth$txt''0$aligntrue$stretchfalsetrue$maxh0$mc_margin);
  5609.             if ($fitcell) {
  5610.                 // restore font size
  5611.                 $this->setFontSize($prev_FontSizePt);
  5612.             }
  5613.         }
  5614.         if ($autopadding) {
  5615.             // add bottom padding
  5616.             $this->+= $mc_padding['B'];
  5617.         }
  5618.         // Get end-of-text Y position
  5619.         $currentY $this->y;
  5620.         // get latest page number
  5621.         $endpage $this->page;
  5622.         if ($resth 0) {
  5623.             $skip = ($endpage $startpage);
  5624.             $tmpresth $resth;
  5625.             while ($tmpresth 0) {
  5626.                 if ($skip <= 0) {
  5627.                     // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5628.                     $this->checkPageBreak($this->PageBreakTrigger 1);
  5629.                 }
  5630.                 if ($this->num_columns 1) {
  5631.                     $tmpresth -= ($this->$this->$this->bMargin);
  5632.                 } else {
  5633.                     $tmpresth -= ($this->$this->tMargin $this->bMargin);
  5634.                 }
  5635.                 --$skip;
  5636.             }
  5637.             $currentY $this->y;
  5638.             $endpage $this->page;
  5639.         }
  5640.         // get latest column
  5641.         $endcolumn $this->current_column;
  5642.         if ($this->num_columns == 0) {
  5643.             $this->num_columns 1;
  5644.         }
  5645.         // disable page regions check
  5646.         $check_page_regions $this->check_page_regions;
  5647.         $this->check_page_regions false;
  5648.         // get border modes
  5649.         $border_start TCPDF_STATIC::getBorderMode($border$position='start'$this->opencell);
  5650.         $border_end TCPDF_STATIC::getBorderMode($border$position='end'$this->opencell);
  5651.         $border_middle TCPDF_STATIC::getBorderMode($border$position='middle'$this->opencell);
  5652.         // design borders around HTML cells.
  5653.         for ($page $startpage$page <= $endpage; ++$page) { // for each page
  5654.             $ccode '';
  5655.             $this->setPage($page);
  5656.             if ($this->num_columns 2) {
  5657.                 // single-column mode
  5658.                 $this->setX($x);
  5659.                 $this->$this->tMargin;
  5660.             }
  5661.             // account for margin changes
  5662.             if ($page $startpage) {
  5663.                 if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5664.                     $this->-= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5665.                 } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5666.                     $this->+= ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5667.                 }
  5668.             }
  5669.             if ($startpage == $endpage) {
  5670.                 // single page
  5671.                 for ($column $startcolumn$column <= $endcolumn; ++$column) { // for each column
  5672.                     if ($column != $this->current_column) {
  5673.                         $this->selectColumn($column);
  5674.                     }
  5675.                     if ($this->rtl) {
  5676.                         $this->-= $mc_margin['R'];
  5677.                     } else {
  5678.                         $this->+= $mc_margin['L'];
  5679.                     }
  5680.                     if ($startcolumn == $endcolumn) { // single column
  5681.                         $cborder $border;
  5682.                         $h max($h, ($currentY $oy));
  5683.                         $this->$oy;
  5684.                     } elseif ($column == $startcolumn) { // first column
  5685.                         $cborder $border_start;
  5686.                         $this->$oy;
  5687.                         $h $this->$this->$this->bMargin;
  5688.                     } elseif ($column == $endcolumn) { // end column
  5689.                         $cborder $border_end;
  5690.                         $h $currentY $this->y;
  5691.                         if ($resth $h) {
  5692.                             $h $resth;
  5693.                         }
  5694.                     } else { // middle column
  5695.                         $cborder $border_middle;
  5696.                         $h $this->$this->$this->bMargin;
  5697.                         $resth -= $h;
  5698.                     }
  5699.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  5700.                 } // end for each column
  5701.             } elseif ($page == $startpage) { // first page
  5702.                 for ($column $startcolumn$column $this->num_columns; ++$column) { // for each column
  5703.                     if ($column != $this->current_column) {
  5704.                         $this->selectColumn($column);
  5705.                     }
  5706.                     if ($this->rtl) {
  5707.                         $this->-= $mc_margin['R'];
  5708.                     } else {
  5709.                         $this->+= $mc_margin['L'];
  5710.                     }
  5711.                     if ($column == $startcolumn) { // first column
  5712.                         $cborder $border_start;
  5713.                         $this->$oy;
  5714.                         $h $this->$this->$this->bMargin;
  5715.                     } else { // middle column
  5716.                         $cborder $border_middle;
  5717.                         $h $this->$this->$this->bMargin;
  5718.                         $resth -= $h;
  5719.                     }
  5720.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  5721.                 } // end for each column
  5722.             } elseif ($page == $endpage) { // last page
  5723.                 for ($column 0$column <= $endcolumn; ++$column) { // for each column
  5724.                     if ($column != $this->current_column) {
  5725.                         $this->selectColumn($column);
  5726.                     }
  5727.                     if ($this->rtl) {
  5728.                         $this->-= $mc_margin['R'];
  5729.                     } else {
  5730.                         $this->+= $mc_margin['L'];
  5731.                     }
  5732.                     if ($column == $endcolumn) {
  5733.                         // end column
  5734.                         $cborder $border_end;
  5735.                         $h $currentY $this->y;
  5736.                         if ($resth $h) {
  5737.                             $h $resth;
  5738.                         }
  5739.                     } else {
  5740.                         // middle column
  5741.                         $cborder $border_middle;
  5742.                         $h $this->$this->$this->bMargin;
  5743.                         $resth -= $h;
  5744.                     }
  5745.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  5746.                 } // end for each column
  5747.             } else { // middle page
  5748.                 for ($column 0$column $this->num_columns; ++$column) { // for each column
  5749.                     $this->selectColumn($column);
  5750.                     if ($this->rtl) {
  5751.                         $this->-= $mc_margin['R'];
  5752.                     } else {
  5753.                         $this->+= $mc_margin['L'];
  5754.                     }
  5755.                     $cborder $border_middle;
  5756.                     $h $this->$this->$this->bMargin;
  5757.                     $resth -= $h;
  5758.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  5759.                 } // end for each column
  5760.             }
  5761.             if ($cborder OR $fill) {
  5762.                 $offsetlen strlen($ccode);
  5763.                 // draw border and fill
  5764.                 if ($this->inxobj) {
  5765.                     // we are inside an XObject template
  5766.                     if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5767.                         $pagemarkkey key($this->xobjects[$this->xobjid]['transfmrk']);
  5768.                         $pagemark $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5769.                         $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5770.                     } else {
  5771.                         $pagemark $this->xobjects[$this->xobjid]['intmrk'];
  5772.                         $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5773.                     }
  5774.                     $pagebuff $this->xobjects[$this->xobjid]['outdata'];
  5775.                     $pstart substr($pagebuff0$pagemark);
  5776.                     $pend substr($pagebuff$pagemark);
  5777.                     $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5778.                 } else {
  5779.                     if (end($this->transfmrk[$this->page]) !== false) {
  5780.                         $pagemarkkey key($this->transfmrk[$this->page]);
  5781.                         $pagemark $this->transfmrk[$this->page][$pagemarkkey];
  5782.                         $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5783.                     } elseif ($this->InFooter) {
  5784.                         $pagemark $this->footerpos[$this->page];
  5785.                         $this->footerpos[$this->page] += $offsetlen;
  5786.                     } else {
  5787.                         $pagemark $this->intmrk[$this->page];
  5788.                         $this->intmrk[$this->page] += $offsetlen;
  5789.                     }
  5790.                     $pagebuff $this->getPageBuffer($this->page);
  5791.                     $pstart substr($pagebuff0$pagemark);
  5792.                     $pend substr($pagebuff$pagemark);
  5793.                     $this->setPageBuffer($this->page$pstart.$ccode.$pend);
  5794.                 }
  5795.             }
  5796.         } // end for each page
  5797.         // restore page regions check
  5798.         $this->check_page_regions $check_page_regions;
  5799.         // Get end-of-cell Y position
  5800.         $currentY $this->GetY();
  5801.         // restore previous values
  5802.         if ($this->num_columns 1) {
  5803.             $this->selectColumn();
  5804.         } else {
  5805.             // restore original margins
  5806.             $this->lMargin $lMargin;
  5807.             $this->rMargin $rMargin;
  5808.             if ($this->page $startpage) {
  5809.                 // check for margin variations between pages (i.e. booklet mode)
  5810.                 $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5811.                 $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5812.                 if (($dl != 0) OR ($dr != 0)) {
  5813.                     $this->lMargin += $dl;
  5814.                     $this->rMargin += $dr;
  5815.                 }
  5816.             }
  5817.         }
  5818.         if ($ln 0) {
  5819.             //Go to the beginning of the next line
  5820.             $this->setY($currentY $mc_margin['B']);
  5821.             if ($ln == 2) {
  5822.                 $this->setX($x $w $mc_margin['L'] + $mc_margin['R']);
  5823.             }
  5824.         } else {
  5825.             // go left or right by case
  5826.             $this->setPage($startpage);
  5827.             $this->$y;
  5828.             $this->setX($x $w $mc_margin['L'] + $mc_margin['R']);
  5829.         }
  5830.         $this->setContentMark();
  5831.         $this->cell_padding $prev_cell_padding;
  5832.         $this->cell_margin $prev_cell_margin;
  5833.         $this->clMargin $this->lMargin;
  5834.         $this->crMargin $this->rMargin;
  5835.         return $nl;
  5836.     }
  5837.     /**
  5838.      * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5839.      * @param string $txt String for calculating his height
  5840.      * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5841.      * @param boolean $reseth if true reset the last cell height (default false).
  5842.      * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  5843.      * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
  5844.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5845.      * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5846.      * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5847.      * @public
  5848.      * @since 4.5.011
  5849.      */
  5850.     public function getNumLines($txt$w=0$reseth=false$autopadding=true$cellpadding=null$border=0) {
  5851.         if ($txt === NULL) {
  5852.             return 0;
  5853.         }
  5854.         if ($txt === '') {
  5855.             // empty string
  5856.             return 1;
  5857.         }
  5858.         // adjust internal padding
  5859.         $prev_cell_padding $this->cell_padding;
  5860.         $prev_lasth $this->lasth;
  5861.         if (is_array($cellpadding)) {
  5862.             $this->cell_padding $cellpadding;
  5863.         }
  5864.         $this->adjustCellPadding($border);
  5865.         if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5866.             if ($this->rtl) {
  5867.                 $w $this->$this->lMargin;
  5868.             } else {
  5869.                 $w $this->$this->rMargin $this->x;
  5870.             }
  5871.         }
  5872.         $wmax $w $this->cell_padding['L'] - $this->cell_padding['R'];
  5873.         if ($reseth) {
  5874.             // reset row height
  5875.             $this->resetLastH();
  5876.         }
  5877.         $lines 1;
  5878.         $sum 0;
  5879.         $chars TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt$this->isunicode$this->CurrentFont), $txt$this->tmprtl$this->isunicode$this->CurrentFont);
  5880.         $charsWidth $this->GetArrStringWidth($chars''''0true);
  5881.         $length count($chars);
  5882.         $lastSeparator = -1;
  5883.         for ($i 0$i $length; ++$i) {
  5884.             $c $chars[$i];
  5885.             $charWidth $charsWidth[$i];
  5886.             if (($c != 160)
  5887.                     AND (($c == 173)
  5888.                         OR preg_match($this->re_spacesTCPDF_FONTS::unichr($c$this->isunicode))
  5889.                         OR (($c == 45)
  5890.                             AND ($i 0) AND ($i < ($length 1))
  5891.                             AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i 1)], $this->isunicode))
  5892.                             AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i 1)], $this->isunicode))
  5893.                         )
  5894.                     )
  5895.                 ) {
  5896.                 $lastSeparator $i;
  5897.             }
  5898.             if ((($sum $charWidth) > $wmax) OR ($c == 10)) {
  5899.                 ++$lines;
  5900.                 if ($c == 10) {
  5901.                     $lastSeparator = -1;
  5902.                     $sum 0;
  5903.                 } elseif ($lastSeparator != -1) {
  5904.                     $i $lastSeparator;
  5905.                     $lastSeparator = -1;
  5906.                     $sum 0;
  5907.                 } else {
  5908.                     $sum $charWidth;
  5909.                 }
  5910.             } else {
  5911.                 $sum += $charWidth;
  5912.             }
  5913.         }
  5914.         if ($chars[($length 1)] == 10) {
  5915.             --$lines;
  5916.         }
  5917.         $this->cell_padding $prev_cell_padding;
  5918.         $this->lasth $prev_lasth;
  5919.         return $lines;
  5920.     }
  5921.     /**
  5922.      * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5923.      * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5924.      * @pre
  5925.      *  // store current object
  5926.      *  $pdf->startTransaction();
  5927.      *  // store starting values
  5928.      *  $start_y = $pdf->GetY();
  5929.      *  $start_page = $pdf->getPage();
  5930.      *  // call your printing functions with your parameters
  5931.      *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5932.      *  $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x=null, $y=null, $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  5933.      *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5934.      *  // get the new Y
  5935.      *  $end_y = $pdf->GetY();
  5936.      *  $end_page = $pdf->getPage();
  5937.      *  // calculate height
  5938.      *  $height = 0;
  5939.      *  if ($end_page == $start_page) {
  5940.      *      $height = $end_y - $start_y;
  5941.      *  } else {
  5942.      *      for ($page=$start_page; $page <= $end_page; ++$page) {
  5943.      *          $this->setPage($page);
  5944.      *          if ($page == $start_page) {
  5945.      *              // first page
  5946.      *              $height += $this->h - $start_y - $this->bMargin;
  5947.      *          } elseif ($page == $end_page) {
  5948.      *              // last page
  5949.      *              $height += $end_y - $this->tMargin;
  5950.      *          } else {
  5951.      *              $height += $this->h - $this->tMargin - $this->bMargin;
  5952.      *          }
  5953.      *      }
  5954.      *  }
  5955.      *  // restore previous object
  5956.      *  $pdf = $pdf->rollbackTransaction();
  5957.      *
  5958.      * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  5959.      * @param string $txt String for calculating his height
  5960.      * @param boolean $reseth if true reset the last cell height (default false).
  5961.      * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  5962.      * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
  5963.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  5964.      * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5965.      * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  5966.      * @public
  5967.      */
  5968.     public function getStringHeight($w$txt$reseth=false$autopadding=true$cellpadding=null$border=0) {
  5969.         // adjust internal padding
  5970.         $prev_cell_padding $this->cell_padding;
  5971.         $prev_lasth $this->lasth;
  5972.         if (is_array($cellpadding)) {
  5973.             $this->cell_padding $cellpadding;
  5974.         }
  5975.         $this->adjustCellPadding($border);
  5976.         $lines $this->getNumLines($txt$w$reseth$autopadding$cellpadding$border);
  5977.         $height $this->getCellHeight(($lines $this->FontSize), $autopadding);
  5978.         $this->cell_padding $prev_cell_padding;
  5979.         $this->lasth $prev_lasth;
  5980.         return $height;
  5981.     }
  5982.     /**
  5983.      * This method prints text from the current position.<br />
  5984.      * @param float $h Line height
  5985.      * @param string $txt String to print
  5986.      * @param mixed $link URL or identifier returned by AddLink()
  5987.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  5988.      * @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>
  5989.      * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  5990.      * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  5991.      * @param boolean $firstline if true prints only the first line and return the remaining string.
  5992.      * @param boolean $firstblock if true the string is the starting of a line.
  5993.      * @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.
  5994.      * @param float $wadj first line width will be reduced by this amount (used in HTML mode).
  5995.      * @param array|null $margin margin array of the parent container
  5996.      * @return mixed Return the number of cells or the remaining string if $firstline = true.
  5997.      * @public
  5998.      * @since 1.5
  5999.      */
  6000.     public function Write($h$txt$link=''$fill=false$align=''$ln=false$stretch=0$firstline=false$firstblock=false$maxh=0$wadj=0$margin=null) {
  6001.         // check page for no-write regions and adapt page margins if necessary
  6002.         list($this->x$this->y) = $this->checkPageRegions($h$this->x$this->y);
  6003.         if (strlen($txt) == 0) {
  6004.             // fix empty text
  6005.             $txt ' ';
  6006.         }
  6007.         if (!is_array($margin)) {
  6008.             // set default margins
  6009.             $margin $this->cell_margin;
  6010.         }
  6011.         // remove carriage returns
  6012.         $s str_replace("\r"''$txt);
  6013.         // check if string contains arabic text
  6014.         if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC$s)) {
  6015.             $arabic true;
  6016.         } else {
  6017.             $arabic false;
  6018.         }
  6019.         // check if string contains RTL text
  6020.         if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL$s)) {
  6021.             $rtlmode true;
  6022.         } else {
  6023.             $rtlmode false;
  6024.         }
  6025.         // get a char width
  6026.         $chrwidth $this->GetCharWidth(46); // dot character
  6027.         // get array of unicode values
  6028.         $chars TCPDF_FONTS::UTF8StringToArray($s$this->isunicode$this->CurrentFont);
  6029.         // calculate maximum width for a single character on string
  6030.         $chrw $this->GetArrStringWidth($chars''''0true);
  6031.         array_walk($chrw, array($this'getRawCharWidth'));
  6032.         $maxchwidth = ((is_array($chrw) || $chrw instanceof Countable) && count($chrw) > 0) ? max($chrw) : 0;
  6033.         // get array of chars
  6034.         $uchars TCPDF_FONTS::UTF8ArrayToUniArray($chars$this->isunicode);
  6035.         // get the number of characters
  6036.         $nb count($chars);
  6037.         // replacement for SHY character (minus symbol)
  6038.         $shy_replacement 45;
  6039.         $shy_replacement_char TCPDF_FONTS::unichr($shy_replacement$this->isunicode);
  6040.         // widht for SHY replacement
  6041.         $shy_replacement_width $this->GetCharWidth($shy_replacement);
  6042.         // page width
  6043.         $pw $w $this->$this->lMargin $this->rMargin;
  6044.         // calculate remaining line width ($w)
  6045.         if ($this->rtl) {
  6046.             $w $this->$this->lMargin;
  6047.         } else {
  6048.             $w $this->$this->rMargin $this->x;
  6049.         }
  6050.         // max column width
  6051.         $wmax = ($w $wadj);
  6052.         if (!$firstline) {
  6053.             $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  6054.         }
  6055.         if ((!$firstline) AND (($chrwidth $wmax) OR ($maxchwidth $wmax))) {
  6056.             // the maximum width character do not fit on column
  6057.             return '';
  6058.         }
  6059.         // minimum row height
  6060.         $row_height max($h$this->getCellHeight($this->FontSize));
  6061.         // max Y
  6062.         $maxy $this->$maxh max($row_height$h);
  6063.         $start_page $this->page;
  6064.         $i 0// character position
  6065.         $j 0// current starting position
  6066.         $sep = -1// position of the last blank space
  6067.         $prevsep $sep// previous separator
  6068.         $shy false// true if the last blank is a soft hypen (SHY)
  6069.         $prevshy $shy// previous shy mode
  6070.         $l 0// current string length
  6071.         $nl 0//number of lines
  6072.         $linebreak false;
  6073.         $pc 0// previous character
  6074.         // for each character
  6075.         while ($i $nb) {
  6076.             if (($maxh 0) AND ($this->$maxy) ) {
  6077.                 break;
  6078.             }
  6079.             //Get the current character
  6080.             $c $chars[$i];
  6081.             if ($c == 10) { // 10 = "\n" = new line
  6082.                 //Explicit line break
  6083.                 if ($align == 'J') {
  6084.                     if ($this->rtl) {
  6085.                         $talign 'R';
  6086.                     } else {
  6087.                         $talign 'L';
  6088.                     }
  6089.                 } else {
  6090.                     $talign $align;
  6091.                 }
  6092.                 $tmpstr TCPDF_FONTS::UniArrSubString($uchars$j$i);
  6093.                 if ($firstline) {
  6094.                     $startx $this->x;
  6095.                     $tmparr array_slice($chars$j, ($i $j));
  6096.                     if ($rtlmode) {
  6097.                         $tmparr TCPDF_FONTS::utf8Bidi($tmparr$tmpstr$this->tmprtl$this->isunicode$this->CurrentFont);
  6098.                     }
  6099.                     $linew $this->GetArrStringWidth($tmparr);
  6100.                     unset($tmparr);
  6101.                     if ($this->rtl) {
  6102.                         $this->endlinex $startx $linew;
  6103.                     } else {
  6104.                         $this->endlinex $startx $linew;
  6105.                     }
  6106.                     $w $linew;
  6107.                     $tmpcellpadding $this->cell_padding;
  6108.                     if ($maxh == 0) {
  6109.                         $this->setCellPadding(0);
  6110.                     }
  6111.                 }
  6112.                 if ($firstblock AND $this->isRTLTextDir()) {
  6113.                     $tmpstr $this->stringRightTrim($tmpstr);
  6114.                 }
  6115.                 // Skip newlines at the beginning of a page or column
  6116.                 if (!empty($tmpstr) OR ($this->< ($this->PageBreakTrigger $row_height))) {
  6117.                     $this->Cell($w$h$tmpstr01$talign$fill$link$stretch);
  6118.                 }
  6119.                 unset($tmpstr);
  6120.                 if ($firstline) {
  6121.                     $this->cell_padding $tmpcellpadding;
  6122.                     return (TCPDF_FONTS::UniArrSubString($uchars$i));
  6123.                 }
  6124.                 ++$nl;
  6125.                 $j $i 1;
  6126.                 $l 0;
  6127.                 $sep = -1;
  6128.                 $prevsep $sep;
  6129.                 $shy false;
  6130.                 // account for margin changes
  6131.                 if ((($this->$this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6132.                     if ($this->AcceptPageBreak())
  6133.                     {
  6134.                         if ($this->rtl) {
  6135.                             $this->-= $margin['R'];
  6136.                         } else {
  6137.                             $this->+= $margin['L'];
  6138.                         }
  6139.                         $this->lMargin += $margin['L'];
  6140.                         $this->rMargin += $margin['R'];
  6141.                     }
  6142.                 }
  6143.                 $w $this->getRemainingWidth();
  6144.                 $wmax = ($w $this->cell_padding['L'] - $this->cell_padding['R']);
  6145.             } else {
  6146.                 // 160 is the non-breaking space.
  6147.                 // 173 is SHY (Soft Hypen).
  6148.                 // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6149.                 // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6150.                 // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6151.                 if (($c != 160)
  6152.                     AND (($c == 173)
  6153.                         OR preg_match($this->re_spacesTCPDF_FONTS::unichr($c$this->isunicode))
  6154.                         OR (($c == 45)
  6155.                             AND ($i < ($nb 1))
  6156.                             AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc$this->isunicode))
  6157.                             AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i 1)], $this->isunicode))
  6158.                         )
  6159.                     )
  6160.                 ) {
  6161.                     // update last blank space position
  6162.                     $prevsep $sep;
  6163.                     $sep $i;
  6164.                     // check if is a SHY
  6165.                     if (($c == 173) OR ($c == 45)) {
  6166.                         $prevshy $shy;
  6167.                         $shy true;
  6168.                         if ($pc == 45) {
  6169.                             $tmp_shy_replacement_width 0;
  6170.                             $tmp_shy_replacement_char '';
  6171.                         } else {
  6172.                             $tmp_shy_replacement_width $shy_replacement_width;
  6173.                             $tmp_shy_replacement_char $shy_replacement_char;
  6174.                         }
  6175.                     } else {
  6176.                         $shy false;
  6177.                     }
  6178.                 }
  6179.                 // update string length
  6180.                 if ($this->isUnicodeFont() AND ($arabic)) {
  6181.                     // with bidirectional algorithm some chars may be changed affecting the line length
  6182.                     // *** very slow ***
  6183.                     $l $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars$j, ($i $j)), ''$this->tmprtl$this->isunicode$this->CurrentFont));
  6184.                 } else {
  6185.                     $l += $this->GetCharWidth($c, ($i+$nb));
  6186.                 }
  6187.                 if (($l $wmax) OR (($c == 173) AND (($l $tmp_shy_replacement_width) >= $wmax))) {
  6188.                     if (($c == 173) AND (($l $tmp_shy_replacement_width) > $wmax)) {
  6189.                         $sep $prevsep;
  6190.                         $shy $prevshy;
  6191.                     }
  6192.                     // we have reached the end of column
  6193.                     if ($sep == -1) {
  6194.                         // check if the line was already started
  6195.                         if (($this->rtl AND ($this-><= ($this->$this->rMargin $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6196.                             OR ((!$this->rtl) AND ($this->>= ($this->lMargin $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6197.                             // print a void cell and go to next line
  6198.                             $this->Cell($w$h''01);
  6199.                             $linebreak true;
  6200.                             if ($firstline) {
  6201.                                 return (TCPDF_FONTS::UniArrSubString($uchars$j));
  6202.                             }
  6203.                         } else {
  6204.                             // truncate the word because do not fit on column
  6205.                             $tmpstr TCPDF_FONTS::UniArrSubString($uchars$j$i);
  6206.                             if ($firstline) {
  6207.                                 $startx $this->x;
  6208.                                 $tmparr array_slice($chars$j, ($i $j));
  6209.                                 if ($rtlmode) {
  6210.                                     $tmparr TCPDF_FONTS::utf8Bidi($tmparr$tmpstr$this->tmprtl$this->isunicode$this->CurrentFont);
  6211.                                 }
  6212.                                 $linew $this->GetArrStringWidth($tmparr);
  6213.                                 unset($tmparr);
  6214.                                 if ($this->rtl) {
  6215.                                     $this->endlinex $startx $linew;
  6216.                                 } else {
  6217.                                     $this->endlinex $startx $linew;
  6218.                                 }
  6219.                                 $w $linew;
  6220.                                 $tmpcellpadding $this->cell_padding;
  6221.                                 if ($maxh == 0) {
  6222.                                     $this->setCellPadding(0);
  6223.                                 }
  6224.                             }
  6225.                             if ($firstblock AND $this->isRTLTextDir()) {
  6226.                                 $tmpstr $this->stringRightTrim($tmpstr);
  6227.                             }
  6228.                             $this->Cell($w$h$tmpstr01$align$fill$link$stretch);
  6229.                             unset($tmpstr);
  6230.                             if ($firstline) {
  6231.                                 $this->cell_padding $tmpcellpadding;
  6232.                                 return (TCPDF_FONTS::UniArrSubString($uchars$i));
  6233.                             }
  6234.                             $j $i;
  6235.                             --$i;
  6236.                         }
  6237.                     } else {
  6238.                         // word wrapping
  6239.                         if ($this->rtl AND (!$firstblock) AND ($sep $i)) {
  6240.                             $endspace 1;
  6241.                         } else {
  6242.                             $endspace 0;
  6243.                         }
  6244.                         // check the length of the next string
  6245.                         $strrest TCPDF_FONTS::UniArrSubString($uchars, ($sep $endspace));
  6246.                         $nextstr TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/'$this->re_space['m'], $this->stringTrim($strrest));
  6247.                         if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6248.                             // truncate the word because do not fit on a full page width
  6249.                             $tmpstr TCPDF_FONTS::UniArrSubString($uchars$j$i);
  6250.                             if ($firstline) {
  6251.                                 $startx $this->x;
  6252.                                 $tmparr array_slice($chars$j, ($i $j));
  6253.                                 if ($rtlmode) {
  6254.                                     $tmparr TCPDF_FONTS::utf8Bidi($tmparr$tmpstr$this->tmprtl$this->isunicode$this->CurrentFont);
  6255.                                 }
  6256.                                 $linew $this->GetArrStringWidth($tmparr);
  6257.                                 unset($tmparr);
  6258.                                 if ($this->rtl) {
  6259.                                     $this->endlinex = ($startx $linew);
  6260.                                 } else {
  6261.                                     $this->endlinex = ($startx $linew);
  6262.                                 }
  6263.                                 $w $linew;
  6264.                                 $tmpcellpadding $this->cell_padding;
  6265.                                 if ($maxh == 0) {
  6266.                                     $this->setCellPadding(0);
  6267.                                 }
  6268.                             }
  6269.                             if ($firstblock AND $this->isRTLTextDir()) {
  6270.                                 $tmpstr $this->stringRightTrim($tmpstr);
  6271.                             }
  6272.                             $this->Cell($w$h$tmpstr01$align$fill$link$stretch);
  6273.                             unset($tmpstr);
  6274.                             if ($firstline) {
  6275.                                 $this->cell_padding $tmpcellpadding;
  6276.                                 return (TCPDF_FONTS::UniArrSubString($uchars$i));
  6277.                             }
  6278.                             $j $i;
  6279.                             --$i;
  6280.                         } else {
  6281.                             // word wrapping
  6282.                             if ($shy) {
  6283.                                 // add hypen (minus symbol) at the end of the line
  6284.                                 $shy_width $tmp_shy_replacement_width;
  6285.                                 if ($this->rtl) {
  6286.                                     $shy_char_left $tmp_shy_replacement_char;
  6287.                                     $shy_char_right '';
  6288.                                 } else {
  6289.                                     $shy_char_left '';
  6290.                                     $shy_char_right $tmp_shy_replacement_char;
  6291.                                 }
  6292.                             } else {
  6293.                                 $shy_width 0;
  6294.                                 $shy_char_left '';
  6295.                                 $shy_char_right '';
  6296.                             }
  6297.                             $tmpstr TCPDF_FONTS::UniArrSubString($uchars$j, ($sep $endspace));
  6298.                             if ($firstline) {
  6299.                                 $startx $this->x;
  6300.                                 $tmparr array_slice($chars$j, (($sep $endspace) - $j));
  6301.                                 if ($rtlmode) {
  6302.                                     $tmparr TCPDF_FONTS::utf8Bidi($tmparr$tmpstr$this->tmprtl$this->isunicode$this->CurrentFont);
  6303.                                 }
  6304.                                 $linew $this->GetArrStringWidth($tmparr);
  6305.                                 unset($tmparr);
  6306.                                 if ($this->rtl) {
  6307.                                     $this->endlinex $startx $linew $shy_width;
  6308.                                 } else {
  6309.                                     $this->endlinex $startx $linew $shy_width;
  6310.                                 }
  6311.                                 $w $linew;
  6312.                                 $tmpcellpadding $this->cell_padding;
  6313.                                 if ($maxh == 0) {
  6314.                                     $this->setCellPadding(0);
  6315.                                 }
  6316.                             }
  6317.                             // print the line
  6318.                             if ($firstblock AND $this->isRTLTextDir()) {
  6319.                                 $tmpstr $this->stringRightTrim($tmpstr);
  6320.                             }
  6321.                             $this->Cell($w$h$shy_char_left.$tmpstr.$shy_char_right01$align$fill$link$stretch);
  6322.                             unset($tmpstr);
  6323.                             if ($firstline) {
  6324.                                 if ($chars[$sep] == 45) {
  6325.                                     $endspace += 1;
  6326.                                 }
  6327.                                 // return the remaining text
  6328.                                 $this->cell_padding $tmpcellpadding;
  6329.                                 return (TCPDF_FONTS::UniArrSubString($uchars, ($sep $endspace)));
  6330.                             }
  6331.                             $i $sep;
  6332.                             $sep = -1;
  6333.                             $shy false;
  6334.                             $j = ($i 1);
  6335.                         }
  6336.                     }
  6337.                     // account for margin changes
  6338.                     if ((($this->$this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6339.                         if ($this->AcceptPageBreak())
  6340.                         {
  6341.                             if ($this->rtl) {
  6342.                                 $this->-= $margin['R'];
  6343.                             } else {
  6344.                                 $this->+= $margin['L'];
  6345.                             }
  6346.                             $this->lMargin += $margin['L'];
  6347.                             $this->rMargin += $margin['R'];
  6348.                         }
  6349.                     }
  6350.                     $w $this->getRemainingWidth();
  6351.                     $wmax $w $this->cell_padding['L'] - $this->cell_padding['R'];
  6352.                     if ($linebreak) {
  6353.                         $linebreak false;
  6354.                     } else {
  6355.                         ++$nl;
  6356.                         $l 0;
  6357.                     }
  6358.                 }
  6359.             }
  6360.             // save last character
  6361.             $pc $c;
  6362.             ++$i;
  6363.         } // end while i < nb
  6364.         // print last substring (if any)
  6365.         if ($l 0) {
  6366.             switch ($align) {
  6367.                 case 'J':
  6368.                 case 'C': {
  6369.                     break;
  6370.                 }
  6371.                 case 'L': {
  6372.                     if (!$this->rtl) {
  6373.                         $w $l;
  6374.                     }
  6375.                     break;
  6376.                 }
  6377.                 case 'R': {
  6378.                     if ($this->rtl) {
  6379.                         $w $l;
  6380.                     }
  6381.                     break;
  6382.                 }
  6383.                 default: {
  6384.                     $w $l;
  6385.                     break;
  6386.                 }
  6387.             }
  6388.             $tmpstr TCPDF_FONTS::UniArrSubString($uchars$j$nb);
  6389.             if ($firstline) {
  6390.                 $startx $this->x;
  6391.                 $tmparr array_slice($chars$j, ($nb $j));
  6392.                 if ($rtlmode) {
  6393.                     $tmparr TCPDF_FONTS::utf8Bidi($tmparr$tmpstr$this->tmprtl$this->isunicode$this->CurrentFont);
  6394.                 }
  6395.                 $linew $this->GetArrStringWidth($tmparr);
  6396.                 unset($tmparr);
  6397.                 if ($this->rtl) {
  6398.                     $this->endlinex $startx $linew;
  6399.                 } else {
  6400.                     $this->endlinex $startx $linew;
  6401.                 }
  6402.                 $w $linew;
  6403.                 $tmpcellpadding $this->cell_padding;
  6404.                 if ($maxh == 0) {
  6405.                     $this->setCellPadding(0);
  6406.                 }
  6407.             }
  6408.             if ($firstblock AND $this->isRTLTextDir()) {
  6409.                 $tmpstr $this->stringRightTrim($tmpstr);
  6410.             }
  6411.             $this->Cell($w$h$tmpstr0$ln$align$fill$link$stretch);
  6412.             unset($tmpstr);
  6413.             if ($firstline) {
  6414.                 $this->cell_padding $tmpcellpadding;
  6415.                 return (TCPDF_FONTS::UniArrSubString($uchars$nb));
  6416.             }
  6417.             ++$nl;
  6418.         }
  6419.         if ($firstline) {
  6420.             return '';
  6421.         }
  6422.         return $nl;
  6423.     }
  6424.     /**
  6425.      * Returns the remaining width between the current position and margins.
  6426.      * @return float Return the remaining width
  6427.      * @protected
  6428.      */
  6429.     protected function getRemainingWidth() {
  6430.         list($this->x$this->y) = $this->checkPageRegions(0$this->x$this->y);
  6431.         if ($this->rtl) {
  6432.             return ($this->$this->lMargin);
  6433.         } else {
  6434.             return ($this->$this->rMargin $this->x);
  6435.         }
  6436.     }
  6437.     /**
  6438.      * Set the block dimensions accounting for page breaks and page/column fitting
  6439.      * @param float $w width
  6440.      * @param float $h height
  6441.      * @param float $x X coordinate
  6442.      * @param float $y Y coodiante
  6443.      * @param boolean $fitonpage if true the block is resized to not exceed page dimensions.
  6444.      * @return array array($w, $h, $x, $y)
  6445.      * @protected
  6446.      * @since 5.5.009 (2010-07-05)
  6447.      */
  6448.     protected function fitBlock($w$h$x$y$fitonpage=false) {
  6449.         if ($w <= 0) {
  6450.             // set maximum width
  6451.             $w = ($this->$this->lMargin $this->rMargin);
  6452.             if ($w <= 0) {
  6453.                 $w 1;
  6454.             }
  6455.         }
  6456.         if ($h <= 0) {
  6457.             // set maximum height
  6458.             $h = ($this->PageBreakTrigger $this->tMargin);
  6459.             if ($h <= 0) {
  6460.                 $h 1;
  6461.             }
  6462.         }
  6463.         // resize the block to be vertically contained on a single page or single column
  6464.         if ($fitonpage OR $this->AutoPageBreak) {
  6465.             $ratio_wh = ($w $h);
  6466.             if ($h > ($this->PageBreakTrigger $this->tMargin)) {
  6467.                 $h $this->PageBreakTrigger $this->tMargin;
  6468.                 $w = ($h $ratio_wh);
  6469.             }
  6470.             // resize the block to be horizontally contained on a single page or single column
  6471.             if ($fitonpage) {
  6472.                 $maxw = ($this->$this->lMargin $this->rMargin);
  6473.                 if ($w $maxw) {
  6474.                     $w $maxw;
  6475.                     $h = ($w $ratio_wh);
  6476.                 }
  6477.             }
  6478.         }
  6479.         // Check whether we need a new page or new column first as this does not fit
  6480.         $prev_x $this->x;
  6481.         $prev_y $this->y;
  6482.         if ($this->checkPageBreak($h$y) OR ($this->$prev_y)) {
  6483.             $y $this->y;
  6484.             if ($this->rtl) {
  6485.                 $x += ($prev_x $this->x);
  6486.             } else {
  6487.                 $x += ($this->$prev_x);
  6488.             }
  6489.             $this->newline true;
  6490.         }
  6491.         // resize the block to be contained on the remaining available page or column space
  6492.         if ($fitonpage) {
  6493.             // fallback to avoid division by zero
  6494.             $h $h == $h;
  6495.             $ratio_wh = ($w $h);
  6496.             if (($y $h) > $this->PageBreakTrigger) {
  6497.                 $h $this->PageBreakTrigger $y;
  6498.                 $w = ($h $ratio_wh);
  6499.             }
  6500.             if ((!$this->rtl) AND (($x $w) > ($this->$this->rMargin))) {
  6501.                 $w $this->$this->rMargin $x;
  6502.                 $h = ($w $ratio_wh);
  6503.             } elseif (($this->rtl) AND (($x $w) < ($this->lMargin))) {
  6504.                 $w $x $this->lMargin;
  6505.                 $h = ($w $ratio_wh);
  6506.             }
  6507.         }
  6508.         return array($w$h$x$y);
  6509.     }
  6510.     /**
  6511.      * Puts an image in the page.
  6512.      * The upper-left corner must be given.
  6513.      * The dimensions can be specified in different ways:<ul>
  6514.      * <li>explicit width and height (expressed in user unit)</li>
  6515.      * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6516.      * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6517.      * 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;
  6518.      * The format can be specified explicitly or inferred from the file extension.<br />
  6519.      * It is possible to put a link on the image.<br />
  6520.      * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6521.      * @param string $file Name of the file containing the image or a '@' character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: '*http://www.example.com/image.jpg').
  6522.      * @param float|null $x Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6523.      * @param float|null $y Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6524.      * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6525.      * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6526.      * @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.
  6527.      * @param mixed $link URL or identifier returned by AddLink().
  6528.      * @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>
  6529.      * @param mixed $resize If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
  6530.      * @param int $dpi dot-per-inch resolution used on resize
  6531.      * @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>
  6532.      * @param boolean $ismask true if this image is a mask, false otherwise
  6533.      * @param mixed $imgmask image object returned by this function or false
  6534.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6535.      * @param mixed $fitbox If not false scale image dimensions proportionally to fit within the ($w, $h) box. $fitbox can be true or a 2 characters string indicating the image alignment inside the box. The first character indicate the horizontal alignment (L = left, C = center, R = right) the second character indicate the vertical algnment (T = top, M = middle, B = bottom).
  6536.      * @param boolean $hidden If true do not display the image.
  6537.      * @param boolean $fitonpage If true the image is resized to not exceed page dimensions.
  6538.      * @param boolean $alt If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6539.      * @param array $altimgs Array of alternate images IDs. Each alternative image must be an array with two values: an integer representing the image ID (the value returned by the Image method) and a boolean value to indicate if the image is the default for printing.
  6540.      * @return mixed|false image information
  6541.      * @public
  6542.      * @since 1.1
  6543.      */
  6544.     public function Image($file$x=null$y=null$w=0$h=0$type=''$link=''$align=''$resize=false$dpi=300$palign=''$ismask=false$imgmask=false$border=0$fitbox=false$hidden=false$fitonpage=false$alt=false$altimgs=array()) {
  6545.         if ($this->state != 2) {
  6546.             return false;
  6547.         }
  6548.         if (TCPDF_STATIC::empty_string($x)) {
  6549.             $x $this->x;
  6550.         }
  6551.         if (TCPDF_STATIC::empty_string($y)) {
  6552.             $y $this->y;
  6553.         }
  6554.         // check page for no-write regions and adapt page margins if necessary
  6555.         list($x$y) = $this->checkPageRegions($h$x$y);
  6556.         $exurl ''// external streams
  6557.         $imsize FALSE;
  6558.         // Make sure the file variable is not empty or null because accessing $file[0] later
  6559.         // results in error when running PHP 7.4
  6560.         if (empty($file)) {
  6561.             return false;
  6562.         }
  6563.         // check if we are passing an image as file or string
  6564.         if ($file[0] === '@') {
  6565.             // image from string
  6566.             $imgdata substr($file1);
  6567.         } else { // image file
  6568.             if ($file[0] === '*') {
  6569.                 // image as external stream
  6570.                 $file substr($file1);
  6571.                 $exurl $file;
  6572.             }
  6573.             // check if file exist and it is valid
  6574.             if (!@$this->fileExists($file)) {
  6575.                 return false;
  6576.             }
  6577.             if (false !== $info $this->getImageBuffer($file)) {
  6578.                 $imsize = array($info['w'], $info['h']);
  6579.             } elseif (($imsize = @getimagesize($file)) === FALSE && strpos($file'__tcpdf_'.$this->file_id.'_img') === FALSE){
  6580.                 $imgdata $this->getCachedFileContents($file);
  6581.             }
  6582.         }
  6583.         if (!empty($imgdata)) {
  6584.             // copy image to cache
  6585.             $original_file $file;
  6586.             $file TCPDF_STATIC::getObjFilename('img'$this->file_id);
  6587.             $fp TCPDF_STATIC::fopenLocal($file'w');
  6588.             if (!$fp) {
  6589.                 $this->Error('Unable to write file: '.$file);
  6590.             }
  6591.             fwrite($fp$imgdata);
  6592.             fclose($fp);
  6593.             unset($imgdata);
  6594.             $imsize = @getimagesize($file);
  6595.             if ($imsize === FALSE) {
  6596.                 unlink($file);
  6597.                 $file $original_file;
  6598.             }
  6599.         }
  6600.         if ($imsize === FALSE) {
  6601.             if (($w 0) AND ($h 0)) {
  6602.                 // get measures from specified data
  6603.                 $pw $this->getHTMLUnitToUnits($w0$this->pdfunittrue) * $this->imgscale $this->k;
  6604.                 $ph $this->getHTMLUnitToUnits($h0$this->pdfunittrue) * $this->imgscale $this->k;
  6605.                 $imsize = array($pw$ph);
  6606.             } else {
  6607.                 $this->Error('[Image] Unable to get the size of the image: '.$file);
  6608.             }
  6609.         }
  6610.         // file hash
  6611.         $filehash md5($file);
  6612.         // get original image width and height in pixels
  6613.         list($pixw$pixh) = $imsize;
  6614.         // calculate image width and height on document
  6615.         if (($w <= 0) AND ($h <= 0)) {
  6616.             // convert image size to document unit
  6617.             $w $this->pixelsToUnits($pixw);
  6618.             $h $this->pixelsToUnits($pixh);
  6619.         } elseif ($w <= 0) {
  6620.             $w $h $pixw $pixh;
  6621.         } elseif ($h <= 0) {
  6622.             $h $w $pixh $pixw;
  6623.         } elseif (($fitbox !== false) AND ($w 0) AND ($h 0)) {
  6624.             if (strlen($fitbox) !== 2) {
  6625.                 // set default alignment
  6626.                 $fitbox '--';
  6627.             }
  6628.             // scale image dimensions proportionally to fit within the ($w, $h) box
  6629.             if ((($w $pixh) / ($h $pixw)) < 1) {
  6630.                 // store current height
  6631.                 $oldh $h;
  6632.                 // calculate new height
  6633.                 $h $w $pixh $pixw;
  6634.                 // height difference
  6635.                 $hdiff = ($oldh $h);
  6636.                 // vertical alignment
  6637.                 switch (strtoupper($fitbox[1])) {
  6638.                     case 'T': {
  6639.                         break;
  6640.                     }
  6641.                     case 'M': {
  6642.                         $y += ($hdiff 2);
  6643.                         break;
  6644.                     }
  6645.                     case 'B': {
  6646.                         $y += $hdiff;
  6647.                         break;
  6648.                     }
  6649.                 }
  6650.             } else {
  6651.                 // store current width
  6652.                 $oldw $w;
  6653.                 // calculate new width
  6654.                 $w $h $pixw $pixh;
  6655.                 // width difference
  6656.                 $wdiff = ($oldw $w);
  6657.                 // horizontal alignment
  6658.                 switch (strtoupper($fitbox[0])) {
  6659.                     case 'L': {
  6660.                         if ($this->rtl) {
  6661.                             $x -= $wdiff;
  6662.                         }
  6663.                         break;
  6664.                     }
  6665.                     case 'C': {
  6666.                         if ($this->rtl) {
  6667.                             $x -= ($wdiff 2);
  6668.                         } else {
  6669.                             $x += ($wdiff 2);
  6670.                         }
  6671.                         break;
  6672.                     }
  6673.                     case 'R': {
  6674.                         if (!$this->rtl) {
  6675.                             $x += $wdiff;
  6676.                         }
  6677.                         break;
  6678.                     }
  6679.                 }
  6680.             }
  6681.         }
  6682.         // fit the image on available space
  6683.         list($w$h$x$y) = $this->fitBlock($w$h$x$y$fitonpage);
  6684.         // calculate new minimum dimensions in pixels
  6685.         $neww round($w $this->$dpi $this->dpi);
  6686.         $newh round($h $this->$dpi $this->dpi);
  6687.         // check if resize is necessary (resize is used only to reduce the image)
  6688.         $newsize = ($neww $newh);
  6689.         $pixsize = ($pixw $pixh);
  6690.         if (intval($resize) == 2) {
  6691.             $resize true;
  6692.         } elseif ($newsize >= $pixsize) {
  6693.             $resize false;
  6694.         }
  6695.         // check if image has been already added on document
  6696.         $newimage true;
  6697.         if (in_array($file$this->imagekeys)) {
  6698.             $newimage false;
  6699.             // get existing image data
  6700.             $info $this->getImageBuffer($file);
  6701.             if (strpos($file'__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) {
  6702.                 // check if the newer image is larger
  6703.                 $oldsize = ($info['w'] * $info['h']);
  6704.                 if ((($oldsize $newsize) AND ($resize)) OR (($oldsize $pixsize) AND (!$resize))) {
  6705.                     $newimage true;
  6706.                 }
  6707.             }
  6708.         } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file'__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) {
  6709.             // create temp image file (without alpha channel)
  6710.             $tempfile_plain K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6711.             // create temp alpha file
  6712.             $tempfile_alpha K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6713.             // check for cached images
  6714.             if (in_array($tempfile_plain$this->imagekeys)) {
  6715.                 // get existing image data
  6716.                 $info $this->getImageBuffer($tempfile_plain);
  6717.                 // check if the newer image is larger
  6718.                 $oldsize = ($info['w'] * $info['h']);
  6719.                 if ((($oldsize $newsize) AND ($resize)) OR (($oldsize $pixsize) AND (!$resize))) {
  6720.                     $newimage true;
  6721.                 } else {
  6722.                     $newimage false;
  6723.                     // embed mask image
  6724.                     $imgmask $this->Image($tempfile_alpha$x$y$w$h'PNG'''''$resize$dpi''truefalse);
  6725.                     // embed image, masked with previously embedded mask
  6726.                     return $this->Image($tempfile_plain$x$y$w$h$type$link$align$resize$dpi$palignfalse$imgmask);
  6727.                 }
  6728.             }
  6729.         }
  6730.         if ($newimage) {
  6731.             //First use of image, get info
  6732.             $type strtolower($type);
  6733.             if ($type == '') {
  6734.                 $type TCPDF_IMAGES::getImageFileType($file$imsize);
  6735.             } elseif ($type == 'jpg') {
  6736.                 $type 'jpeg';
  6737.             }
  6738.             // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6739.             $mtd '_parse'.$type;
  6740.             // GD image handler function
  6741.             $gdfunction 'imagecreatefrom'.$type;
  6742.             $info false;
  6743.             if ((method_exists('TCPDF_IMAGES'$mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6744.                 // TCPDF image functions
  6745.                 $info TCPDF_IMAGES::$mtd($file);
  6746.                 if (($ismask === false) AND ($imgmask === false) AND (strpos($file'__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)
  6747.                     AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6748.                     return $this->ImagePngAlpha($file$x$y$pixw$pixh$w$h'PNG'$link$align$resize$dpi$palign$filehash);
  6749.                 }
  6750.             }
  6751.             if (($info === false) AND function_exists($gdfunction)) {
  6752.                 try {
  6753.                     // GD library
  6754.                     $img $gdfunction($file);
  6755.                     if ($img !== false) {
  6756.                         if ($resize) {
  6757.                             $imgr imagecreatetruecolor($neww$newh);
  6758.                             if (($type == 'gif') OR ($type == 'png')) {
  6759.                                 $imgr TCPDF_IMAGES::setGDImageTransparency($imgr$img);
  6760.                             }
  6761.                             imagecopyresampled($imgr$img0000$neww$newh$pixw$pixh);
  6762.                             $img $imgr;
  6763.                         }
  6764.                         if (($type == 'gif') OR ($type == 'png')) {
  6765.                             $info TCPDF_IMAGES::_toPNG($imgTCPDF_STATIC::getObjFilename('img'$this->file_id));
  6766.                         } else {
  6767.                             $info TCPDF_IMAGES::_toJPEG($img$this->jpeg_qualityTCPDF_STATIC::getObjFilename('img'$this->file_id));
  6768.                         }
  6769.                     }
  6770.                 } catch(Exception $e) {
  6771.                     $info false;
  6772.                 }
  6773.             }
  6774.             if (($info === false) AND extension_loaded('imagick')) {
  6775.                 try {
  6776.                     // ImageMagick library
  6777.                     $img = new Imagick();
  6778.                     if ($type == 'svg') {
  6779.                         if ($file[0] === '@') {
  6780.                             // image from string
  6781.                             $svgimg substr($file1);
  6782.                         } else {
  6783.                             // get SVG file content
  6784.                             $svgimg $this->getCachedFileContents($file);
  6785.                         }
  6786.                         if ($svgimg !== FALSE) {
  6787.                             // get width and height
  6788.                             $regs = array();
  6789.                             if (preg_match('/<svg([^\>]*)>/si'$svgimg$regs)) {
  6790.                                 $svgtag $regs[1];
  6791.                                 $tmp = array();
  6792.                                 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si'$svgtag$tmp)) {
  6793.                                     $ow $this->getHTMLUnitToUnits($tmp[1], 1$this->svgunitfalse);
  6794.                                     $owu sprintf('%F', ($ow $dpi 72)).$this->pdfunit;
  6795.                                     $svgtag preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si'' width="'.$owu.'"'$svgtag1);
  6796.                                 } else {
  6797.                                     $ow $w;
  6798.                                 }
  6799.                                 $tmp = array();
  6800.                                 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si'$svgtag$tmp)) {
  6801.                                     $oh $this->getHTMLUnitToUnits($tmp[1], 1$this->svgunitfalse);
  6802.                                     $ohu sprintf('%F', ($oh $dpi 72)).$this->pdfunit;
  6803.                                     $svgtag preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si'' height="'.$ohu.'"'$svgtag1);
  6804.                                 } else {
  6805.                                     $oh $h;
  6806.                                 }
  6807.                                 $tmp = array();
  6808.                                 if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si'$svgtag$tmp)) {
  6809.                                     $vbw = ($ow $this->imgscale $this->k);
  6810.                                     $vbh = ($oh $this->imgscale $this->k);
  6811.                                     $vbox sprintf(' viewBox="0 0 %F %F" '$vbw$vbh);
  6812.                                     $svgtag $vbox.$svgtag;
  6813.                                 }
  6814.                                 $svgimg preg_replace('/<svg([^\>]*)>/si''<svg'.$svgtag.'>'$svgimg1);
  6815.                             }
  6816.                             $img->readImageBlob($svgimg);
  6817.                         }
  6818.                     } else {
  6819.                         $img->readImage($file);
  6820.                     }
  6821.                     if ($resize) {
  6822.                         $img->resizeImage($neww$newh101false);
  6823.                     }
  6824.                     $img->setCompressionQuality($this->jpeg_quality);
  6825.                     $img->setImageFormat('jpeg');
  6826.                     $tempname TCPDF_STATIC::getObjFilename('img'$this->file_id);
  6827.                     $img->writeImage($tempname);
  6828.                     $info TCPDF_IMAGES::_parsejpeg($tempname);
  6829.                     unlink($tempname);
  6830.                     $img->destroy();
  6831.                 } catch(Exception $e) {
  6832.                     $info false;
  6833.                 }
  6834.             }
  6835.             if ($info === false) {
  6836.                 // unable to process image
  6837.                 return false;
  6838.             }
  6839.             if ($ismask) {
  6840.                 // force grayscale
  6841.                 $info['cs'] = 'DeviceGray';
  6842.             }
  6843.             if ($imgmask !== false) {
  6844.                 $info['masked'] = $imgmask;
  6845.             }
  6846.             if (!empty($exurl)) {
  6847.                 $info['exurl'] = $exurl;
  6848.             }
  6849.             // array of alternative images
  6850.             $info['altimgs'] = $altimgs;
  6851.             // add image to document
  6852.             $info['i'] = $this->setImageBuffer($file$info);
  6853.         }
  6854.         // set alignment
  6855.         $this->img_rb_x $x $w;
  6856.         $this->img_rb_y $y $h;
  6857.         // set alignment
  6858.         if ($palign == 'L') {
  6859.             $ximg $this->lMargin;
  6860.         } elseif ($palign == 'C') {
  6861.             $ximg = ($this->$this->lMargin $this->rMargin $w) / 2;
  6862.         } elseif ($palign == 'R') {
  6863.             $ximg $this->$this->rMargin $w;
  6864.         } else {
  6865.             $ximg $this->rtl $x $w $x;
  6866.         }
  6867.         if ($ismask OR $hidden) {
  6868.             // image is not displayed
  6869.             return $info['i'];
  6870.         }
  6871.         $xkimg $ximg $this->k;
  6872.         if (!$alt) {
  6873.             // only non-alternative immages will be set
  6874.             $this->_out(sprintf('q %F 0 0 %F %F %F cm /I%u Do Q', ($w $this->k), ($h $this->k), $xkimg, (($this->- ($y $h)) * $this->k), $info['i']));
  6875.         }
  6876.         if (!empty($border)) {
  6877.             $bx $this->x;
  6878.             $by $this->y;
  6879.             $this->$ximg;
  6880.             if ($this->rtl) {
  6881.                 $this->+= $w;
  6882.             }
  6883.             $this->$y;
  6884.             $this->Cell($w$h''$border0''0''0true);
  6885.             $this->$bx;
  6886.             $this->$by;
  6887.         }
  6888.         if ($link) {
  6889.             $this->Link($ximg$y$w$h$link0);
  6890.         }
  6891.         // set pointer to align the next text/objects
  6892.         switch($align) {
  6893.             case 'T': {
  6894.                 $this->$y;
  6895.                 $this->$this->img_rb_x;
  6896.                 break;
  6897.             }
  6898.             case 'M': {
  6899.                 $this->$y round($h/2);
  6900.                 $this->$this->img_rb_x;
  6901.                 break;
  6902.             }
  6903.             case 'B': {
  6904.                 $this->$this->img_rb_y;
  6905.                 $this->$this->img_rb_x;
  6906.                 break;
  6907.             }
  6908.             case 'N': {
  6909.                 $this->setY($this->img_rb_y);
  6910.                 break;
  6911.             }
  6912.             default:{
  6913.                 break;
  6914.             }
  6915.         }
  6916.         $this->endlinex $this->img_rb_x;
  6917.         if ($this->inxobj) {
  6918.             // we are inside an XObject template
  6919.             $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6920.         }
  6921.         return $info['i'];
  6922.     }
  6923.     /**
  6924.      * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  6925.      * @param string $file Name of the file containing the image.
  6926.      * @param float $x Abscissa of the upper-left corner.
  6927.      * @param float $y Ordinate of the upper-left corner.
  6928.      * @param float $wpx Original width of the image in pixels.
  6929.      * @param float $hpx original height of the image in pixels.
  6930.      * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6931.      * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6932.      * @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.
  6933.      * @param mixed $link URL or identifier returned by AddLink().
  6934.      * @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>
  6935.      * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  6936.      * @param int $dpi dot-per-inch resolution used on resize
  6937.      * @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>
  6938.      * @param string $filehash File hash used to build unique file names.
  6939.      * @author Nicola Asuni
  6940.      * @protected
  6941.      * @since 4.3.007 (2008-12-04)
  6942.      * @see Image()
  6943.      */
  6944.     protected function ImagePngAlpha($file$x$y$wpx$hpx$w$h$type$link$align$resize$dpi$palign$filehash='') {
  6945.         // create temp images
  6946.         if (empty($filehash)) {
  6947.             $filehash md5($file);
  6948.         }
  6949.         // create temp image file (without alpha channel)
  6950.         $tempfile_plain K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
  6951.         // create temp alpha file
  6952.         $tempfile_alpha K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
  6953.         $parsed false;
  6954.         $parse_error '';
  6955.         // ImageMagick extension
  6956.         if (($parsed === false) AND extension_loaded('imagick')) {
  6957.             try {
  6958.                 // ImageMagick library
  6959.                 $img = new Imagick();
  6960.                 $img->readImage($file);
  6961.                 // clone image object
  6962.                 $imga TCPDF_STATIC::objclone($img);
  6963.                 // extract alpha channel
  6964.                 if (method_exists($img'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  6965.                     $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  6966.                 } else {
  6967.                     $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  6968.                     $img->negateImage(true);
  6969.                 }
  6970.                 $img->setImageFormat('png');
  6971.                 $img->writeImage($tempfile_alpha);
  6972.                 // remove alpha channel
  6973.                 if (method_exists($imga'setImageMatte')) {
  6974.                     $imga->setImageMatte(false);
  6975.                 } else {
  6976.                     $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  6977.                 }
  6978.                 $imga->setImageFormat('png');
  6979.                 $imga->writeImage($tempfile_plain);
  6980.                 $parsed true;
  6981.             } catch (Exception $e) {
  6982.                 // Imagemagick fails, try with GD
  6983.                 $parse_error 'Imagick library error: '.$e->getMessage();
  6984.             }
  6985.         }
  6986.         // GD extension
  6987.         if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  6988.             try {
  6989.                 // generate images
  6990.                 $img imagecreatefrompng($file);
  6991.                 $imgalpha imagecreate($wpx$hpx);
  6992.                 // generate gray scale palette (0 -> 255)
  6993.                 for ($c 0$c 256; ++$c) {
  6994.                     ImageColorAllocate($imgalpha$c$c$c);
  6995.                 }
  6996.                 // extract alpha channel
  6997.                 for ($xpx 0$xpx $wpx; ++$xpx) {
  6998.                     for ($ypx 0$ypx $hpx; ++$ypx) {
  6999.                         $color imagecolorat($img$xpx$ypx);
  7000.                         // get and correct gamma color
  7001.                         $alpha $this->getGDgamma($img$color);
  7002.                         imagesetpixel($imgalpha, (int) $xpx, (int) $ypx, (int) $alpha);
  7003.                     }
  7004.                 }
  7005.                 imagepng($imgalpha$tempfile_alpha);
  7006.                 imagedestroy($imgalpha);
  7007.                 // extract image without alpha channel
  7008.                 $imgplain imagecreatetruecolor($wpx$hpx);
  7009.                 imagecopy($imgplain$img0000$wpx$hpx);
  7010.                 imagepng($imgplain$tempfile_plain);
  7011.                 imagedestroy($imgplain);
  7012.                 $parsed true;
  7013.             } catch (Exception $e) {
  7014.                 // GD fails
  7015.                 $parse_error 'GD library error: '.$e->getMessage();
  7016.             }
  7017.         }
  7018.         if ($parsed === false) {
  7019.             if (empty($parse_error)) {
  7020.                 $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  7021.             } else {
  7022.                 $this->Error($parse_error);
  7023.             }
  7024.         }
  7025.         // embed mask image
  7026.         $imgmask $this->Image($tempfile_alpha$x$y$w$h'PNG'''''$resize$dpi''truefalse);
  7027.         // embed image, masked with previously embedded mask
  7028.         $this->Image($tempfile_plain$x$y$w$h$type$link$align$resize$dpi$palignfalse$imgmask);
  7029.     }
  7030.     /**
  7031.      * Get the GD-corrected PNG gamma value from alpha color
  7032.      * @param resource $img GD image Resource ID.
  7033.      * @param int $c alpha color
  7034.      * @protected
  7035.      * @since 4.3.007 (2008-12-04)
  7036.      */
  7037.     protected function getGDgamma($img$c) {
  7038.         if (!isset($this->gdgammacache['#'.$c])) {
  7039.             $colors imagecolorsforindex($img$c);
  7040.             // GD alpha is only 7 bit (0 -> 127)
  7041.             $this->gdgammacache['#'.$c] = (int) (((127 $colors['alpha']) / 127) * 255);
  7042.             // correct gamma
  7043.             $this->gdgammacache['#'.$c] = (int) (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  7044.             // store the latest values on cache to improve performances
  7045.             if (count($this->gdgammacache) > 8) {
  7046.                 // remove one element from the cache array
  7047.                 array_shift($this->gdgammacache);
  7048.             }
  7049.         }
  7050.         return $this->gdgammacache['#'.$c];
  7051.     }
  7052.     /**
  7053.      * Performs a line break.
  7054.      * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  7055.      * @param float|null $h The height of the break. By default, the value equals the height of the last printed cell.
  7056.      * @param boolean $cell if true add the current left (or right o for RTL) padding to the X coordinate
  7057.      * @public
  7058.      * @since 1.0
  7059.      * @see Cell()
  7060.      */
  7061.     public function Ln($h=null$cell=false) {
  7062.         if (($this->num_columns 1) AND ($this->== $this->columns[$this->current_column]['y']) AND isset($this->columns[$this->current_column]['x']) AND ($this->== $this->columns[$this->current_column]['x'])) {
  7063.             // revove vertical space from the top of the column
  7064.             return;
  7065.         }
  7066.         if ($cell) {
  7067.             if ($this->rtl) {
  7068.                 $cellpadding $this->cell_padding['R'];
  7069.             } else {
  7070.                 $cellpadding $this->cell_padding['L'];
  7071.             }
  7072.         } else {
  7073.             $cellpadding 0;
  7074.         }
  7075.         if ($this->rtl) {
  7076.             $this->$this->$this->rMargin $cellpadding;
  7077.         } else {
  7078.             $this->$this->lMargin $cellpadding;
  7079.         }
  7080.         if (TCPDF_STATIC::empty_string($h)) {
  7081.             $h $this->lasth;
  7082.         }
  7083.         $this->+= $h;
  7084.         $this->newline true;
  7085.     }
  7086.     /**
  7087.      * Returns the relative X value of current position.
  7088.      * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  7089.      * @return float
  7090.      * @public
  7091.      * @since 1.2
  7092.      * @see SetX(), GetY(), SetY()
  7093.      */
  7094.     public function GetX() {
  7095.         //Get x position
  7096.         if ($this->rtl) {
  7097.             return ($this->$this->x);
  7098.         } else {
  7099.             return $this->x;
  7100.         }
  7101.     }
  7102.     /**
  7103.      * Returns the absolute X value of current position.
  7104.      * @return float
  7105.      * @public
  7106.      * @since 1.2
  7107.      * @see SetX(), GetY(), SetY()
  7108.      */
  7109.     public function GetAbsX() {
  7110.         return $this->x;
  7111.     }
  7112.     /**
  7113.      * Returns the ordinate of the current position.
  7114.      * @return float
  7115.      * @public
  7116.      * @since 1.0
  7117.      * @see SetY(), GetX(), SetX()
  7118.      */
  7119.     public function GetY() {
  7120.         return $this->y;
  7121.     }
  7122.     /**
  7123.      * Defines the abscissa of the current position.
  7124.      * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  7125.      * @param float $x The value of the abscissa in user units.
  7126.      * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7127.      * @public
  7128.      * @since 1.2
  7129.      * @see GetX(), GetY(), SetY(), SetXY()
  7130.      */
  7131.     public function setX($x$rtloff=false) {
  7132.         $x floatval($x);
  7133.         if (!$rtloff AND $this->rtl) {
  7134.             if ($x >= 0) {
  7135.                 $this->$this->$x;
  7136.             } else {
  7137.                 $this->abs($x);
  7138.             }
  7139.         } else {
  7140.             if ($x >= 0) {
  7141.                 $this->$x;
  7142.             } else {
  7143.                 $this->$this->$x;
  7144.             }
  7145.         }
  7146.         if ($this->0) {
  7147.             $this->0;
  7148.         }
  7149.         if ($this->$this->w) {
  7150.             $this->$this->w;
  7151.         }
  7152.     }
  7153.     /**
  7154.      * Moves the current abscissa back to the left margin and sets the ordinate.
  7155.      * If the passed value is negative, it is relative to the bottom of the page.
  7156.      * @param float $y The value of the ordinate in user units.
  7157.      * @param bool $resetx if true (default) reset the X position.
  7158.      * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7159.      * @public
  7160.      * @since 1.0
  7161.      * @see GetX(), GetY(), SetY(), SetXY()
  7162.      */
  7163.     public function setY($y$resetx=true$rtloff=false) {
  7164.         $y floatval($y);
  7165.         if ($resetx) {
  7166.             //reset x
  7167.             if (!$rtloff AND $this->rtl) {
  7168.                 $this->$this->$this->rMargin;
  7169.             } else {
  7170.                 $this->$this->lMargin;
  7171.             }
  7172.         }
  7173.         if ($y >= 0) {
  7174.             $this->$y;
  7175.         } else {
  7176.             $this->$this->$y;
  7177.         }
  7178.         if ($this->0) {
  7179.             $this->0;
  7180.         }
  7181.         if ($this->$this->h) {
  7182.             $this->$this->h;
  7183.         }
  7184.     }
  7185.     /**
  7186.      * Defines the abscissa and ordinate of the current position.
  7187.      * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7188.      * @param float $x The value of the abscissa.
  7189.      * @param float $y The value of the ordinate.
  7190.      * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  7191.      * @public
  7192.      * @since 1.2
  7193.      * @see SetX(), SetY()
  7194.      */
  7195.     public function setXY($x$y$rtloff=false) {
  7196.         $this->setY($yfalse$rtloff);
  7197.         $this->setX($x$rtloff);
  7198.     }
  7199.     /**
  7200.      * Set the absolute X coordinate of the current pointer.
  7201.      * @param float $x The value of the abscissa in user units.
  7202.      * @public
  7203.      * @since 5.9.186 (2012-09-13)
  7204.      * @see setAbsX(), setAbsY(), SetAbsXY()
  7205.      */
  7206.     public function setAbsX($x) {
  7207.         $this->floatval($x);
  7208.     }
  7209.     /**
  7210.      * Set the absolute Y coordinate of the current pointer.
  7211.      * @param float $y (float) The value of the ordinate in user units.
  7212.      * @public
  7213.      * @since 5.9.186 (2012-09-13)
  7214.      * @see setAbsX(), setAbsY(), SetAbsXY()
  7215.      */
  7216.     public function setAbsY($y) {
  7217.         $this->floatval($y);
  7218.     }
  7219.     /**
  7220.      * Set the absolute X and Y coordinates of the current pointer.
  7221.      * @param float $x The value of the abscissa in user units.
  7222.      * @param float $y (float) The value of the ordinate in user units.
  7223.      * @public
  7224.      * @since 5.9.186 (2012-09-13)
  7225.      * @see setAbsX(), setAbsY(), SetAbsXY()
  7226.      */
  7227.     public function setAbsXY($x$y) {
  7228.         $this->setAbsX($x);
  7229.         $this->setAbsY($y);
  7230.     }
  7231.     /**
  7232.      * Send the document to a given destination: string, local file or browser.
  7233.      * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7234.      * The method first calls Close() if necessary to terminate the document.
  7235.      * @param string $name The name of the file when saved
  7236.      * @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 server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as base64 mime multi-part email attachment (RFC 2045)</li></ul>
  7237.      * @return string
  7238.      * @public
  7239.      * @since 1.0
  7240.      * @see Close()
  7241.      */
  7242.     public function Output($name='doc.pdf'$dest='I') {
  7243.         //Output PDF to some destination
  7244.         //Finish document if necessary
  7245.         if ($this->state 3) {
  7246.             $this->Close();
  7247.         }
  7248.         //Normalize parameters
  7249.         if (is_bool($dest)) {
  7250.             $dest $dest 'D' 'F';
  7251.         }
  7252.         $dest strtoupper($dest);
  7253.         if ($this->sign) {
  7254.             // *** apply digital signature to the document ***
  7255.             // get the document content
  7256.             $pdfdoc $this->getBuffer();
  7257.             // remove last newline
  7258.             $pdfdoc substr($pdfdoc0, -1);
  7259.             // remove filler space
  7260.             $byterange_string_len strlen(TCPDF_STATIC::$byterange_string);
  7261.             // define the ByteRange
  7262.             $byte_range = array();
  7263.             $byte_range[0] = 0;
  7264.             $byte_range[1] = strpos($pdfdocTCPDF_STATIC::$byterange_string) + $byterange_string_len 10;
  7265.             $byte_range[2] = $byte_range[1] + $this->signature_max_length 2;
  7266.             $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7267.             $pdfdoc substr($pdfdoc0$byte_range[1]).substr($pdfdoc$byte_range[2]);
  7268.             // replace the ByteRange
  7269.             $byterange sprintf('/ByteRange[0 %u %u %u]'$byte_range[1], $byte_range[2], $byte_range[3]);
  7270.             $byterange .= str_repeat(' ', ($byterange_string_len strlen($byterange)));
  7271.             $pdfdoc str_replace(TCPDF_STATIC::$byterange_string$byterange$pdfdoc);
  7272.             // write the document to a temporary folder
  7273.             $tempdoc TCPDF_STATIC::getObjFilename('doc'$this->file_id);
  7274.             $f TCPDF_STATIC::fopenLocal($tempdoc'wb');
  7275.             if (!$f) {
  7276.                 $this->Error('Unable to create temporary file: '.$tempdoc);
  7277.             }
  7278.             $pdfdoc_length strlen($pdfdoc);
  7279.             fwrite($f$pdfdoc$pdfdoc_length);
  7280.             fclose($f);
  7281.             // get digital signature via openssl library
  7282.             $tempsign TCPDF_STATIC::getObjFilename('sig'$this->file_id);
  7283.             if (empty($this->signature_data['extracerts'])) {
  7284.                 openssl_pkcs7_sign($tempdoc$tempsign$this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY PKCS7_DETACHED);
  7285.             } else {
  7286.                 openssl_pkcs7_sign($tempdoc$tempsign$this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY PKCS7_DETACHED$this->signature_data['extracerts']);
  7287.             }
  7288.             // read signature
  7289.             $signature file_get_contents($tempsign);
  7290.             // extract signature
  7291.             $signature substr($signature$pdfdoc_length);
  7292.             $signature substr($signature, (strpos($signature"%%EOF\n\n------") + 13));
  7293.             $tmparr explode("\n\n"$signature);
  7294.             $signature $tmparr[1];
  7295.             // decode signature
  7296.             $signature base64_decode(trim($signature));
  7297.             // add TSA timestamp to signature
  7298.             $signature $this->applyTSA($signature);
  7299.             // convert signature to hex
  7300.             $signature current(unpack('H*'$signature));
  7301.             $signature str_pad($signature$this->signature_max_length'0');
  7302.             // Add signature to the document
  7303.             $this->buffer substr($pdfdoc0$byte_range[1]).'<'.$signature.'>'.substr($pdfdoc$byte_range[1]);
  7304.             $this->bufferlen strlen($this->buffer);
  7305.         }
  7306.         switch($dest) {
  7307.             case 'I': {
  7308.                 // Send PDF to the standard output
  7309.                 if (ob_get_contents()) {
  7310.                     $this->Error('Some data has already been output, can\'t send PDF file');
  7311.                 }
  7312.                 if (php_sapi_name() != 'cli') {
  7313.                     // send output to a browser
  7314.                     header('Content-Type: application/pdf');
  7315.                     if (headers_sent()) {
  7316.                         $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7317.                     }
  7318.                     header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7319.                     //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7320.                     header('Pragma: public');
  7321.                     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7322.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7323.                     header('Content-Disposition: inline; filename="' rawurlencode(basename($name)) . '"; ' .
  7324.                         'filename*=UTF-8\'\'' rawurlencode(basename($name)));
  7325.                     TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7326.                 } else {
  7327.                     echo $this->getBuffer();
  7328.                 }
  7329.                 break;
  7330.             }
  7331.             case 'D': {
  7332.                 // download PDF as file
  7333.                 if (ob_get_contents()) {
  7334.                     $this->Error('Some data has already been output, can\'t send PDF file');
  7335.                 }
  7336.                 header('Content-Description: File Transfer');
  7337.                 if (headers_sent()) {
  7338.                     $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7339.                 }
  7340.                 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7341.                 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7342.                 header('Pragma: public');
  7343.                 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7344.                 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7345.                 // force download dialog
  7346.                 if (strpos(php_sapi_name(), 'cgi') === false) {
  7347.                     header('Content-Type: application/force-download');
  7348.                     header('Content-Type: application/octet-stream'false);
  7349.                     header('Content-Type: application/download'false);
  7350.                     header('Content-Type: application/pdf'false);
  7351.                 } else {
  7352.                     header('Content-Type: application/pdf');
  7353.                 }
  7354.                 // use the Content-Disposition header to supply a recommended filename
  7355.                 header('Content-Disposition: attachment; filename="' rawurlencode(basename($name)) . '"; ' .
  7356.                     'filename*=UTF-8\'\'' rawurlencode(basename($name)));
  7357.                 header('Content-Transfer-Encoding: binary');
  7358.                 TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7359.                 break;
  7360.             }
  7361.             case 'F':
  7362.             case 'FI':
  7363.             case 'FD': {
  7364.                 // save PDF to a local file
  7365.                 $f TCPDF_STATIC::fopenLocal($name'wb');
  7366.                 if (!$f) {
  7367.                     $this->Error('Unable to create output file: '.$name);
  7368.                 }
  7369.                 fwrite($f$this->getBuffer(), $this->bufferlen);
  7370.                 fclose($f);
  7371.                 if ($dest == 'FI') {
  7372.                     // send headers to browser
  7373.                     header('Content-Type: application/pdf');
  7374.                     header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7375.                     //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7376.                     header('Pragma: public');
  7377.                     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7378.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7379.                     header('Content-Disposition: inline; filename="'.basename($name).'"');
  7380.                     TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7381.                 } elseif ($dest == 'FD') {
  7382.                     // send headers to browser
  7383.                     if (ob_get_contents()) {
  7384.                         $this->Error('Some data has already been output, can\'t send PDF file');
  7385.                     }
  7386.                     header('Content-Description: File Transfer');
  7387.                     if (headers_sent()) {
  7388.                         $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7389.                     }
  7390.                     header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7391.                     header('Pragma: public');
  7392.                     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7393.                     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7394.                     // force download dialog
  7395.                     if (strpos(php_sapi_name(), 'cgi') === false) {
  7396.                         header('Content-Type: application/force-download');
  7397.                         header('Content-Type: application/octet-stream'false);
  7398.                         header('Content-Type: application/download'false);
  7399.                         header('Content-Type: application/pdf'false);
  7400.                     } else {
  7401.                         header('Content-Type: application/pdf');
  7402.                     }
  7403.                     // use the Content-Disposition header to supply a recommended filename
  7404.                     header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7405.                     header('Content-Transfer-Encoding: binary');
  7406.                     TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7407.                 }
  7408.                 break;
  7409.             }
  7410.             case 'E': {
  7411.                 // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7412.                 $retval 'Content-Type: application/pdf;'."\r\n";
  7413.                 $retval .= ' name="'.$name.'"'."\r\n";
  7414.                 $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7415.                 $retval .= 'Content-Disposition: attachment;'."\r\n";
  7416.                 $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7417.                 $retval .= chunk_split(base64_encode($this->getBuffer()), 76"\r\n");
  7418.                 return $retval;
  7419.             }
  7420.             case 'S': {
  7421.                 // returns PDF as a string
  7422.                 return $this->getBuffer();
  7423.             }
  7424.             default: {
  7425.                 $this->Error('Incorrect output destination: '.$dest);
  7426.             }
  7427.         }
  7428.         return '';
  7429.     }
  7430.     protected static $cleaned_ids = array();
  7431.     /**
  7432.      * Unset all class variables except the following critical variables.
  7433.      * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  7434.      * @param boolean $preserve_objcopy if true preserves the objcopy variable
  7435.      * @public
  7436.      * @since 4.5.016 (2009-02-24)
  7437.      */
  7438.     public function _destroy($destroyall=false$preserve_objcopy=false) {
  7439.         if (isset(self::$cleaned_ids[$this->file_id])) {
  7440.             $destroyall false;
  7441.         }
  7442.         if ($destroyall AND !$preserve_objcopy && isset($this->file_id)) {
  7443.             self::$cleaned_ids[$this->file_id] = true;
  7444.             // remove all temporary files
  7445.             if ($handle = @opendir(K_PATH_CACHE)) {
  7446.                 while ( false !== ( $file_name readdir$handle ) ) ) {
  7447.                     if (strpos($file_name'__tcpdf_'.$this->file_id.'_') === 0) {
  7448.                         unlink(K_PATH_CACHE.$file_name);
  7449.                     }
  7450.                 }
  7451.                 closedir($handle);
  7452.             }
  7453.             if (isset($this->imagekeys)) {
  7454.                 foreach($this->imagekeys as $file) {
  7455.                     if (strpos($fileK_PATH_CACHE) === && TCPDF_STATIC::file_exists($file)) {
  7456.                         @unlink($file);
  7457.                     }
  7458.                 }
  7459.             }
  7460.         }
  7461.         $preserve = array(
  7462.             'file_id',
  7463.             'state',
  7464.             'bufferlen',
  7465.             'buffer',
  7466.             'cached_files',
  7467.             'imagekeys',
  7468.             'sign',
  7469.             'signature_data',
  7470.             'signature_max_length',
  7471.             'byterange_string',
  7472.             'tsa_timestamp',
  7473.             'tsa_data'
  7474.         );
  7475.         foreach (array_keys(get_object_vars($this)) as $val) {
  7476.             if ($destroyall OR !in_array($val$preserve)) {
  7477.                 if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
  7478.                     unset($this->$val);
  7479.                 }
  7480.             }
  7481.         }
  7482.     }
  7483.     /**
  7484.      * Check for locale-related bug
  7485.      * @protected
  7486.      */
  7487.     protected function _dochecks() {
  7488.         //Check for locale-related bug
  7489.         if (1.1 == 1) {
  7490.             $this->Error('Don\'t alter the locale before including class file');
  7491.         }
  7492.         //Check for decimal separator
  7493.         if (sprintf('%.1F'1.0) != '1.0') {
  7494.             setlocale(LC_NUMERIC'C');
  7495.         }
  7496.     }
  7497.     /**
  7498.      * Return an array containing variations for the basic page number alias.
  7499.      * @param string $a Base alias.
  7500.      * @return array of page number aliases
  7501.      * @protected
  7502.      */
  7503.     protected function getInternalPageNumberAliases($a'') {
  7504.         $alias = array();
  7505.         // build array of Unicode + ASCII variants (the order is important)
  7506.         $alias = array('u' => array(), 'a' => array());
  7507.         $u '{'.$a.'}';
  7508.         $alias['u'][] = TCPDF_STATIC::_escape($u);
  7509.         if ($this->isunicode) {
  7510.             $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u$this->isunicode$this->CurrentFont));
  7511.             $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($ufalse$this->tmprtl$this->isunicode$this->CurrentFont));
  7512.             $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a$this->isunicode$this->CurrentFont));
  7513.             $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($afalse$this->tmprtl$this->isunicode$this->CurrentFont));
  7514.         }
  7515.         $alias['a'][] = TCPDF_STATIC::_escape($a);
  7516.         return $alias;
  7517.     }
  7518.     /**
  7519.      * Return an array containing all internal page aliases.
  7520.      * @return array of page number aliases
  7521.      * @protected
  7522.      */
  7523.     protected function getAllInternalPageNumberAliases() {
  7524.         $basic_alias = array(TCPDF_STATIC::$alias_tot_pagesTCPDF_STATIC::$alias_num_pageTCPDF_STATIC::$alias_group_tot_pagesTCPDF_STATIC::$alias_group_num_pageTCPDF_STATIC::$alias_right_shift);
  7525.         $pnalias = array();
  7526.         foreach($basic_alias as $k => $a) {
  7527.             $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7528.         }
  7529.         return $pnalias;
  7530.     }
  7531.     /**
  7532.      * Replace right shift page number aliases with spaces to correct right alignment.
  7533.      * This works perfectly only when using monospaced fonts.
  7534.      * @param string $page Page content.
  7535.      * @param array $aliases Array of page aliases.
  7536.      * @param int $diff initial difference to add.
  7537.      * @return string replaced page content.
  7538.      * @protected
  7539.      */
  7540.     protected function replaceRightShiftPageNumAliases($page$aliases$diff) {
  7541.         foreach ($aliases as $type => $alias) {
  7542.             foreach ($alias as $a) {
  7543.                 // find position of compensation factor
  7544.                 $startnum = (strpos($a':') + 1);
  7545.                 $a substr($a0$startnum);
  7546.                 if (($pos strpos($page$a)) !== false) {
  7547.                     // end of alias
  7548.                     $endnum strpos($page'}'$pos);
  7549.                     // string to be replaced
  7550.                     $aa substr($page$pos, ($endnum $pos 1));
  7551.                     // get compensation factor
  7552.                     $ratio substr($page, ($pos $startnum), ($endnum $pos $startnum));
  7553.                     $ratio preg_replace('/[^0-9\.]/'''$ratio);
  7554.                     $ratio floatval($ratio);
  7555.                     if ($type == 'u') {
  7556.                         $chrdiff floor(($diff 12) * $ratio);
  7557.                         $shift str_repeat(' '$chrdiff);
  7558.                         $shift TCPDF_FONTS::UTF8ToUTF16BE($shiftfalse$this->isunicode$this->CurrentFont);
  7559.                     } else {
  7560.                         $chrdiff floor(($diff 11) * $ratio);
  7561.                         $shift str_repeat(' '$chrdiff);
  7562.                     }
  7563.                     $page str_replace($aa$shift$page);
  7564.                 }
  7565.             }
  7566.         }
  7567.         return $page;
  7568.     }
  7569.     /**
  7570.      * Set page boxes to be included on page descriptions.
  7571.      * @param array $boxes Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7572.      * @protected
  7573.      */
  7574.     protected function setPageBoxTypes($boxes) {
  7575.         $this->page_boxes = array();
  7576.         foreach ($boxes as $box) {
  7577.             if (in_array($boxTCPDF_STATIC::$pageboxes)) {
  7578.                 $this->page_boxes[] = $box;
  7579.             }
  7580.         }
  7581.     }
  7582.     /**
  7583.      * Output pages (and replace page number aliases).
  7584.      * @protected
  7585.      */
  7586.     protected function _putpages() {
  7587.         $filter = ($this->compress) ? '/Filter /FlateDecode ' '';
  7588.         // get internal aliases for page numbers
  7589.         $pnalias $this->getAllInternalPageNumberAliases();
  7590.         $num_pages $this->numpages;
  7591.         $ptpa TCPDF_STATIC::formatPageNumber(($this->starting_page_number $num_pages 1));
  7592.         $ptpu TCPDF_FONTS::UTF8ToUTF16BE($ptpafalse$this->isunicode$this->CurrentFont);
  7593.         $ptp_num_chars $this->GetNumChars($ptpa);
  7594.         $pagegroupnum 0;
  7595.         $groupnum 0;
  7596.         $ptgu 1;
  7597.         $ptga 1;
  7598.         $ptg_num_chars 1;
  7599.         for ($n 1$n <= $num_pages; ++$n) {
  7600.             // get current page
  7601.             $temppage $this->getPageBuffer($n);
  7602.             $pagelen strlen($temppage);
  7603.             // set replacements for total pages number
  7604.             $pnpa TCPDF_STATIC::formatPageNumber(($this->starting_page_number $n 1));
  7605.             $pnpu TCPDF_FONTS::UTF8ToUTF16BE($pnpafalse$this->isunicode$this->CurrentFont);
  7606.             $pnp_num_chars $this->GetNumChars($pnpa);
  7607.             $pdiff 0// difference used for right shift alignment of page numbers
  7608.             $gdiff 0// difference used for right shift alignment of page group numbers
  7609.             if (!empty($this->pagegroups)) {
  7610.                 if (isset($this->newpagegroup[$n])) {
  7611.                     $pagegroupnum 0;
  7612.                     ++$groupnum;
  7613.                     $ptga TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7614.                     $ptgu TCPDF_FONTS::UTF8ToUTF16BE($ptgafalse$this->isunicode$this->CurrentFont);
  7615.                     $ptg_num_chars $this->GetNumChars($ptga);
  7616.                 }
  7617.                 ++$pagegroupnum;
  7618.                 $pnga TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7619.                 $pngu TCPDF_FONTS::UTF8ToUTF16BE($pngafalse$this->isunicode$this->CurrentFont);
  7620.                 $png_num_chars $this->GetNumChars($pnga);
  7621.                 // replace page numbers
  7622.                 $replace = array();
  7623.                 $replace[] = array($ptgu$ptg_num_chars9$pnalias[2]['u']);
  7624.                 $replace[] = array($ptga$ptg_num_chars7$pnalias[2]['a']);
  7625.                 $replace[] = array($pngu$png_num_chars9$pnalias[3]['u']);
  7626.                 $replace[] = array($pnga$png_num_chars7$pnalias[3]['a']);
  7627.                 list($temppage$gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage$replace$gdiff);
  7628.             }
  7629.             // replace page numbers
  7630.             $replace = array();
  7631.             $replace[] = array($ptpu$ptp_num_chars9$pnalias[0]['u']);
  7632.             $replace[] = array($ptpa$ptp_num_chars7$pnalias[0]['a']);
  7633.             $replace[] = array($pnpu$pnp_num_chars9$pnalias[1]['u']);
  7634.             $replace[] = array($pnpa$pnp_num_chars7$pnalias[1]['a']);
  7635.             list($temppage$pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage$replace$pdiff);
  7636.             // replace right shift alias
  7637.             $temppage $this->replaceRightShiftPageNumAliases($temppage$pnalias[4], max($pdiff$gdiff));
  7638.             // replace EPS marker
  7639.             $temppage str_replace($this->epsmarker''$temppage);
  7640.             //Page
  7641.             $this->page_obj_id[$n] = $this->_newobj();
  7642.             $out '<<';
  7643.             $out .= ' /Type /Page';
  7644.             $out .= ' /Parent 1 0 R';
  7645.             if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  7646.                 $out .= ' /LastModified '.$this->_datestring(0$this->doc_modification_timestamp);
  7647.             }
  7648.             $out .= ' /Resources 2 0 R';
  7649.             foreach ($this->page_boxes as $box) {
  7650.                 $out .= ' /'.$box;
  7651.                 $out .= sprintf(' [%F %F %F %F]'$this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  7652.             }
  7653.             if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7654.                 $out .= ' /BoxColorInfo <<';
  7655.                 foreach ($this->page_boxes as $box) {
  7656.                     if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7657.                         $out .= ' /'.$box.' <<';
  7658.                         if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7659.                             $color $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7660.                             $out .= ' /C [';
  7661.                             $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7662.                             $out .= ' ]';
  7663.                         }
  7664.                         if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7665.                             $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7666.                         }
  7667.                         if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7668.                             $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7669.                         }
  7670.                         if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7671.                             $dashes $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7672.                             $out .= ' /D [';
  7673.                             foreach ($dashes as $dash) {
  7674.                                 $out .= sprintf(' %F', ($dash $this->k));
  7675.                             }
  7676.                             $out .= ' ]';
  7677.                         }
  7678.                         $out .= ' >>';
  7679.                     }
  7680.                 }
  7681.                 $out .= ' >>';
  7682.             }
  7683.             $out .= ' /Contents '.($this->1).' 0 R';
  7684.             $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7685.             if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  7686.                 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7687.             }
  7688.             if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7689.                 // page transitions
  7690.                 if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7691.                     $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7692.                 }
  7693.                 $out .= ' /Trans <<';
  7694.                 $out .= ' /Type /Trans';
  7695.                 if (isset($this->pagedim[$n]['trans']['S'])) {
  7696.                     $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7697.                 }
  7698.                 if (isset($this->pagedim[$n]['trans']['D'])) {
  7699.                     $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7700.                 }
  7701.                 if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7702.                     $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7703.                 }
  7704.                 if (isset($this->pagedim[$n]['trans']['M'])) {
  7705.                     $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7706.                 }
  7707.                 if (isset($this->pagedim[$n]['trans']['Di'])) {
  7708.                     $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7709.                 }
  7710.                 if (isset($this->pagedim[$n]['trans']['SS'])) {
  7711.                     $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7712.                 }
  7713.                 if (isset($this->pagedim[$n]['trans']['B'])) {
  7714.                     $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7715.                 }
  7716.                 $out .= ' >>';
  7717.             }
  7718.             $out .= $this->_getannotsrefs($n);
  7719.             $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7720.             $out .= ' >>';
  7721.             $out .= "\n".'endobj';
  7722.             $this->_out($out);
  7723.             //Page content
  7724.             $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7725.             $this->_newobj();
  7726.             $p $this->_getrawstream($p);
  7727.             $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7728.         }
  7729.         //Pages root
  7730.         $out $this->_getobj(1)."\n";
  7731.         $out .= '<< /Type /Pages /Kids [';
  7732.         foreach($this->page_obj_id as $page_obj) {
  7733.             $out .= ' '.$page_obj.' 0 R';
  7734.         }
  7735.         $out .= ' ] /Count '.$num_pages.' >>';
  7736.         $out .= "\n".'endobj';
  7737.         $this->_out($out);
  7738.     }
  7739.     /**
  7740.      * Get references to page annotations.
  7741.      * @param int $n page number
  7742.      * @return string
  7743.      * @protected
  7744.      * @author Nicola Asuni
  7745.      * @since 5.0.010 (2010-05-17)
  7746.      */
  7747.     protected function _getannotsrefs($n) {
  7748.         if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7749.             return '';
  7750.         }
  7751.         $out ' /Annots [';
  7752.         if (isset($this->PageAnnots[$n])) {
  7753.             foreach ($this->PageAnnots[$n] as $key => $val) {
  7754.                 if (!in_array($val['n'], $this->radio_groups)) {
  7755.                     $out .= ' '.$val['n'].' 0 R';
  7756.                 }
  7757.             }
  7758.             // add radiobutton groups
  7759.             if (isset($this->radiobutton_groups[$n])) {
  7760.                 foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7761.                     if (isset($data['n'])) {
  7762.                         $out .= ' '.$data['n'].' 0 R';
  7763.                     }
  7764.                 }
  7765.             }
  7766.         }
  7767.         if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7768.             // set reference for signature object
  7769.             $out .= ' '.$this->sig_obj_id.' 0 R';
  7770.         }
  7771.         if (!empty($this->empty_signature_appearance)) {
  7772.             foreach ($this->empty_signature_appearance as $esa) {
  7773.                 if ($esa['page'] == $n) {
  7774.                     // set reference for empty signature objects
  7775.                     $out .= ' '.$esa['objid'].' 0 R';
  7776.                 }
  7777.             }
  7778.         }
  7779.         $out .= ' ]';
  7780.         return $out;
  7781.     }
  7782.     /**
  7783.      * Output annotations objects for all pages.
  7784.      * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7785.      * See section 12.5 of PDF 32000_2008 reference.
  7786.      * @protected
  7787.      * @author Nicola Asuni
  7788.      * @since 4.0.018 (2008-08-06)
  7789.      */
  7790.     protected function _putannotsobjs() {
  7791.         // reset object counter
  7792.         for ($n=1$n <= $this->numpages; ++$n) {
  7793.             if (isset($this->PageAnnots[$n])) {
  7794.                 // set page annotations
  7795.                 foreach ($this->PageAnnots[$n] as $key => $pl) {
  7796.                     $annot_obj_id $this->PageAnnots[$n][$key]['n'];
  7797.                     // create annotation object for grouping radiobuttons
  7798.                     if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7799.                         $radio_button_obj_id $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7800.                         $annots '<<';
  7801.                         $annots .= ' /Type /Annot';
  7802.                         $annots .= ' /Subtype /Widget';
  7803.                         $annots .= ' /Rect [0 0 0 0]';
  7804.                         if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7805.                             // read only
  7806.                             $annots .= ' /F 68';
  7807.                             $annots .= ' /Ff 49153';
  7808.                         } else {
  7809.                             $annots .= ' /F 4'// default print for PDF/A
  7810.                             $annots .= ' /Ff 49152';
  7811.                         }
  7812.                         $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7813.                         if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7814.                             $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7815.                         }
  7816.                         $annots .= ' /FT /Btn';
  7817.                         $annots .= ' /Kids [';
  7818.                         $defval '';
  7819.                         foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7820.                             if (isset($data['kid'])) {
  7821.                                 $annots .= ' '.$data['kid'].' 0 R';
  7822.                                 if ($data['def'] !== 'Off') {
  7823.                                     $defval $data['def'];
  7824.                                 }
  7825.                             }
  7826.                         }
  7827.                         $annots .= ' ]';
  7828.                         if (!empty($defval)) {
  7829.                             $annots .= ' /V /'.$defval;
  7830.                         }
  7831.                         $annots .= ' >>';
  7832.                         $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7833.                         $this->form_obj_id[] = $radio_button_obj_id;
  7834.                         // store object id to be used on Parent entry of Kids
  7835.                         $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7836.                     }
  7837.                     $formfield false;
  7838.                     $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7839.                     $a $pl['x'] * $this->k;
  7840.                     $b $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7841.                     $c $pl['w'] * $this->k;
  7842.                     $d $pl['h'] * $this->k;
  7843.                     $rect sprintf('%F %F %F %F'$a$b$a+$c$b+$d);
  7844.                     // create new annotation object
  7845.                     $annots '<</Type /Annot';
  7846.                     $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7847.                     $annots .= ' /Rect ['.$rect.']';
  7848.                     $ft = array('Btn''Tx''Ch''Sig');
  7849.                     if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7850.                         $annots .= ' /FT /'.$pl['opt']['ft'];
  7851.                         $formfield true;
  7852.                     }
  7853.                     if ($pl['opt']['subtype'] !== 'Link') {
  7854.                         $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7855.                     }
  7856.                     $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7857.                     $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u'$n$key), $annot_obj_id);
  7858.                     $annots .= ' /M '.$this->_datestring($annot_obj_id$this->doc_modification_timestamp);
  7859.                     if (isset($pl['opt']['f'])) {
  7860.                         $fval 0;
  7861.                         if (is_array($pl['opt']['f'])) {
  7862.                             foreach ($pl['opt']['f'] as $f) {
  7863.                                 switch (strtolower($f)) {
  7864.                                     case 'invisible': {
  7865.                                         $fval += << 0;
  7866.                                         break;
  7867.                                     }
  7868.                                     case 'hidden': {
  7869.                                         $fval += << 1;
  7870.                                         break;
  7871.                                     }
  7872.                                     case 'print': {
  7873.                                         $fval += << 2;
  7874.                                         break;
  7875.                                     }
  7876.                                     case 'nozoom': {
  7877.                                         $fval += << 3;
  7878.                                         break;
  7879.                                     }
  7880.                                     case 'norotate': {
  7881.                                         $fval += << 4;
  7882.                                         break;
  7883.                                     }
  7884.                                     case 'noview': {
  7885.                                         $fval += << 5;
  7886.                                         break;
  7887.                                     }
  7888.                                     case 'readonly': {
  7889.                                         $fval += << 6;
  7890.                                         break;
  7891.                                     }
  7892.                                     case 'locked': {
  7893.                                         $fval += << 8;
  7894.                                         break;
  7895.                                     }
  7896.                                     case 'togglenoview': {
  7897.                                         $fval += << 9;
  7898.                                         break;
  7899.                                     }
  7900.                                     case 'lockedcontents': {
  7901.                                         $fval += << 10;
  7902.                                         break;
  7903.                                     }
  7904.                                     default: {
  7905.                                         break;
  7906.                                     }
  7907.                                 }
  7908.                             }
  7909.                         } else {
  7910.                             $fval intval($pl['opt']['f']);
  7911.                         }
  7912.                     } else {
  7913.                         $fval 4;
  7914.                     }
  7915.                     if ($this->pdfa_mode) {
  7916.                         // force print flag for PDF/A mode
  7917.                         $fval |= 4;
  7918.                     }
  7919.                     $annots .= ' /F '.intval($fval);
  7920.                     if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  7921.                         $annots .= ' /AS /'.$pl['opt']['as'];
  7922.                     }
  7923.                     if (isset($pl['opt']['ap'])) {
  7924.                         // appearance stream
  7925.                         $annots .= ' /AP <<';
  7926.                         if (is_array($pl['opt']['ap'])) {
  7927.                             foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  7928.                                 // $apmode can be: n = normal; r = rollover; d = down;
  7929.                                 $annots .= ' /'.strtoupper($apmode);
  7930.                                 if (is_array($apdef)) {
  7931.                                     $annots .= ' <<';
  7932.                                     foreach ($apdef as $apstate => $stream) {
  7933.                                         // reference to XObject that define the appearance for this mode-state
  7934.                                         $apsobjid $this->_putAPXObject($c$d$stream);
  7935.                                         $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  7936.                                     }
  7937.                                     $annots .= ' >>';
  7938.                                 } else {
  7939.                                     // reference to XObject that define the appearance for this mode
  7940.                                     $apsobjid $this->_putAPXObject($c$d$apdef);
  7941.                                     $annots .= ' '.$apsobjid.' 0 R';
  7942.                                 }
  7943.                             }
  7944.                         } else {
  7945.                             $annots .= $pl['opt']['ap'];
  7946.                         }
  7947.                         $annots .= ' >>';
  7948.                     }
  7949.                     if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  7950.                         $annots .= ' /BS <<';
  7951.                         $annots .= ' /Type /Border';
  7952.                         if (isset($pl['opt']['bs']['w'])) {
  7953.                             $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  7954.                         }
  7955.                         $bstyles = array('S''D''B''I''U');
  7956.                         if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  7957.                             $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7958.                         }
  7959.                         if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  7960.                             $annots .= ' /D [';
  7961.                             foreach ($pl['opt']['bs']['d'] as $cord) {
  7962.                                 $annots .= ' '.intval($cord);
  7963.                             }
  7964.                             $annots .= ']';
  7965.                         }
  7966.                         $annots .= ' >>';
  7967.                     } else {
  7968.                         $annots .= ' /Border [';
  7969.                         if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  7970.                             $annots .= intval($pl['opt']['border'][0]).' ';
  7971.                             $annots .= intval($pl['opt']['border'][1]).' ';
  7972.                             $annots .= intval($pl['opt']['border'][2]);
  7973.                             if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  7974.                                 $annots .= ' [';
  7975.                                 foreach ($pl['opt']['border'][3] as $dash) {
  7976.                                     $annots .= intval($dash).' ';
  7977.                                 }
  7978.                                 $annots .= ']';
  7979.                             }
  7980.                         } else {
  7981.                             $annots .= '0 0 0';
  7982.                         }
  7983.                         $annots .= ']';
  7984.                     }
  7985.                     if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  7986.                         $annots .= ' /BE <<';
  7987.                         $bstyles = array('S''C');
  7988.                         if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  7989.                             $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7990.                         } else {
  7991.                             $annots .= ' /S /S';
  7992.                         }
  7993.                         if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  7994.                             $annots .= ' /I '.sprintf(' %F'$pl['opt']['be']['i']);
  7995.                         }
  7996.                         $annots .= '>>';
  7997.                     }
  7998.                     if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  7999.                         $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  8000.                     }
  8001.                     //$annots .= ' /StructParent ';
  8002.                     //$annots .= ' /OC ';
  8003.                     $markups = array('text''freetext''line''square''circle''polygon''polyline''highlight''underline''squiggly''strikeout''stamp''caret''ink''fileattachment''sound');
  8004.                     if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  8005.                         // this is a markup type
  8006.                         if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8007.                             $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  8008.                         }
  8009.                         //$annots .= ' /Popup ';
  8010.                         if (isset($pl['opt']['ca'])) {
  8011.                             $annots .= ' /CA '.sprintf('%F'floatval($pl['opt']['ca']));
  8012.                         }
  8013.                         if (isset($pl['opt']['rc'])) {
  8014.                             $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8015.                         }
  8016.                         $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id$this->doc_creation_timestamp);
  8017.                         //$annots .= ' /IRT ';
  8018.                         if (isset($pl['opt']['subj'])) {
  8019.                             $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  8020.                         }
  8021.                         //$annots .= ' /RT ';
  8022.                         //$annots .= ' /IT ';
  8023.                         //$annots .= ' /ExData ';
  8024.                     }
  8025.                     $lineendings = array('Square''Circle''Diamond''OpenArrow''ClosedArrow''None''Butt''ROpenArrow''RClosedArrow''Slash');
  8026.                     // Annotation types
  8027.                     switch (strtolower($pl['opt']['subtype'])) {
  8028.                         case 'text': {
  8029.                             if (isset($pl['opt']['open'])) {
  8030.                                 $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' 'true' 'false');
  8031.                             }
  8032.                             $iconsapp = array('Comment''Help''Insert''Key''NewParagraph''Note''Paragraph');
  8033.                             if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8034.                                 $annots .= ' /Name /'.$pl['opt']['name'];
  8035.                             } else {
  8036.                                 $annots .= ' /Name /Note';
  8037.                             }
  8038.                             $hasStateModel = isset($pl['opt']['statemodel']);
  8039.                             $hasState = isset($pl['opt']['state']);
  8040.                             $statemodels = array('Marked''Review');
  8041.                             if (!$hasStateModel && !$hasState) {
  8042.                                 break;
  8043.                             }
  8044.                             if ($hasStateModel AND in_array($pl['opt']['statemodel'], $statemodels)) {
  8045.                                 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8046.                             } else {
  8047.                                 $pl['opt']['statemodel'] = 'Marked';
  8048.                                 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  8049.                             }
  8050.                             if ($pl['opt']['statemodel'] == 'Marked') {
  8051.                                 $states = array('Accepted''Unmarked');
  8052.                             } else {
  8053.                                 $states = array('Accepted''Rejected''Cancelled''Completed''None');
  8054.                             }
  8055.                             if ($hasState AND in_array($pl['opt']['state'], $states)) {
  8056.                                 $annots .= ' /State /'.$pl['opt']['state'];
  8057.                             } else {
  8058.                                 if ($pl['opt']['statemodel'] == 'Marked') {
  8059.                                     $annots .= ' /State /Unmarked';
  8060.                                 } else {
  8061.                                     $annots .= ' /State /None';
  8062.                                 }
  8063.                             }
  8064.                             break;
  8065.                         }
  8066.                         case 'link': {
  8067.                             if (is_string($pl['txt']) && !empty($pl['txt'])) {
  8068.                                 if ($pl['txt'][0] == '#') {
  8069.                                     // internal destination
  8070.                                     $annots .= ' /A <</S /GoTo /D /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1)).'>>';
  8071.                                 } elseif ($pl['txt'][0] == '%') {
  8072.                                     // embedded PDF file
  8073.                                     $filename basename(substr($pl['txt'], 1));
  8074.                                     $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  8075.                                 } elseif ($pl['txt'][0] == '*') {
  8076.                                     // embedded generic file
  8077.                                     $filename basename(substr($pl['txt'], 1));
  8078.                                     $jsa 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
  8079.                                     $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa$annot_obj_id).'>>';
  8080.                                 } else {
  8081.                                     $parsedUrl parse_url($pl['txt']);
  8082.                                     if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
  8083.                                         // relative link to a PDF file
  8084.                                         $dest '[0 /Fit]'// default page 0
  8085.                                         if (!empty($parsedUrl['fragment'])) {
  8086.                                             // check for named destination
  8087.                                             $tmp explode('='$parsedUrl['fragment']);
  8088.                                             $dest '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')';
  8089.                                         }
  8090.                                         $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
  8091.                                     } else {
  8092.                                         // external URI link
  8093.                                         $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  8094.                                     }
  8095.                                 }
  8096.                             } elseif (isset($this->links[$pl['txt']])) {
  8097.                                 // internal link ID
  8098.                                 $l $this->links[$pl['txt']];
  8099.                                 if (isset($this->page_obj_id[($l['p'])])) {
  8100.                                     $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]'$this->page_obj_id[($l['p'])], ($this->pagedim[$l['p']]['h'] - ($l['y'] * $this->k)));
  8101.                                 }
  8102.                             }
  8103.                             $hmodes = array('N''I''O''P');
  8104.                             if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  8105.                                 $annots .= ' /H /'.$pl['opt']['h'];
  8106.                             } else {
  8107.                                 $annots .= ' /H /I';
  8108.                             }
  8109.                             //$annots .= ' /PA ';
  8110.                             //$annots .= ' /Quadpoints ';
  8111.                             break;
  8112.                         }
  8113.                         case 'freetext': {
  8114.                             if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8115.                                 $annots .= ' /DA ('.$pl['opt']['da'].')';
  8116.                             }
  8117.                             if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8118.                                 $annots .= ' /Q '.intval($pl['opt']['q']);
  8119.                             }
  8120.                             if (isset($pl['opt']['rc'])) {
  8121.                                 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  8122.                             }
  8123.                             if (isset($pl['opt']['ds'])) {
  8124.                                 $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  8125.                             }
  8126.                             if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  8127.                                 $annots .= ' /CL [';
  8128.                                 foreach ($pl['opt']['cl'] as $cl) {
  8129.                                     $annots .= sprintf('%F '$cl $this->k);
  8130.                                 }
  8131.                                 $annots .= ']';
  8132.                             }
  8133.                             $tfit = array('FreeText''FreeTextCallout''FreeTextTypeWriter');
  8134.                             if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  8135.                                 $annots .= ' /IT /'.$pl['opt']['it'];
  8136.                             }
  8137.                             if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  8138.                                 $l $pl['opt']['rd'][0] * $this->k;
  8139.                                 $r $pl['opt']['rd'][1] * $this->k;
  8140.                                 $t $pl['opt']['rd'][2] * $this->k;
  8141.                                 $b $pl['opt']['rd'][3] * $this->k;
  8142.                                 $annots .= ' /RD ['.sprintf('%F %F %F %F'$l$r$t$b).']';
  8143.                             }
  8144.                             if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8145.                                 $annots .= ' /LE /'.$pl['opt']['le'];
  8146.                             }
  8147.                             break;
  8148.                         }
  8149.                         case 'line': {
  8150.                             break;
  8151.                         }
  8152.                         case 'square': {
  8153.                             break;
  8154.                         }
  8155.                         case 'circle': {
  8156.                             break;
  8157.                         }
  8158.                         case 'polygon': {
  8159.                             break;
  8160.                         }
  8161.                         case 'polyline': {
  8162.                             break;
  8163.                         }
  8164.                         case 'highlight': {
  8165.                             break;
  8166.                         }
  8167.                         case 'underline': {
  8168.                             break;
  8169.                         }
  8170.                         case 'squiggly': {
  8171.                             break;
  8172.                         }
  8173.                         case 'strikeout': {
  8174.                             break;
  8175.                         }
  8176.                         case 'stamp': {
  8177.                             break;
  8178.                         }
  8179.                         case 'caret': {
  8180.                             break;
  8181.                         }
  8182.                         case 'ink': {
  8183.                             break;
  8184.                         }
  8185.                         case 'popup': {
  8186.                             break;
  8187.                         }
  8188.                         case 'fileattachment': {
  8189.                             if ($this->pdfa_mode && $this->pdfa_version != 3) {
  8190.                                 // embedded files are not allowed in PDF/A mode version 1 and 2
  8191.                                 break;
  8192.                             }
  8193.                             if (!isset($pl['opt']['fs'])) {
  8194.                                 break;
  8195.                             }
  8196.                             $filename basename($pl['opt']['fs']);
  8197.                             if (isset($this->embeddedfiles[$filename]['f'])) {
  8198.                                 $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8199.                                 $iconsapp = array('Graph''Paperclip''PushPin''Tag');
  8200.                                 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8201.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  8202.                                 } else {
  8203.                                     $annots .= ' /Name /PushPin';
  8204.                                 }
  8205.                                 // index (zero-based) of the annotation in the Annots array of this page
  8206.                                 $this->embeddedfiles[$filename]['a'] = $key;
  8207.                             }
  8208.                             break;
  8209.                         }
  8210.                         case 'sound': {
  8211.                             if (!isset($pl['opt']['fs'])) {
  8212.                                 break;
  8213.                             }
  8214.                             $filename basename($pl['opt']['fs']);
  8215.                             if (isset($this->embeddedfiles[$filename]['f'])) {
  8216.                                 // ... TO BE COMPLETED ...
  8217.                                 // /R /C /B /E /CO /CP
  8218.                                 $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8219.                                 $iconsapp = array('Speaker''Mic');
  8220.                                 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8221.                                     $annots .= ' /Name /'.$pl['opt']['name'];
  8222.                                 } else {
  8223.                                     $annots .= ' /Name /Speaker';
  8224.                                 }
  8225.                             }
  8226.                             break;
  8227.                         }
  8228.                         case 'movie': {
  8229.                             break;
  8230.                         }
  8231.                         case 'widget': {
  8232.                             $hmode = array('N''I''O''P''T');
  8233.                             if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8234.                                 $annots .= ' /H /'.$pl['opt']['h'];
  8235.                             }
  8236.                             if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8237.                                 $annots .= ' /MK <<';
  8238.                                 if (isset($pl['opt']['mk']['r'])) {
  8239.                                     $annots .= ' /R '.$pl['opt']['mk']['r'];
  8240.                                 }
  8241.                                 if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8242.                                     $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8243.                                 }
  8244.                                 if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8245.                                     $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8246.                                 }
  8247.                                 if (isset($pl['opt']['mk']['ca'])) {
  8248.                                     $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8249.                                 }
  8250.                                 if (isset($pl['opt']['mk']['rc'])) {
  8251.                                     $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8252.                                 }
  8253.                                 if (isset($pl['opt']['mk']['ac'])) {
  8254.                                     $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8255.                                 }
  8256.                                 if (isset($pl['opt']['mk']['i'])) {
  8257.                                     $info $this->getImageBuffer($pl['opt']['mk']['i']);
  8258.                                     if ($info !== false) {
  8259.                                         $annots .= ' /I '.$info['n'].' 0 R';
  8260.                                     }
  8261.                                 }
  8262.                                 if (isset($pl['opt']['mk']['ri'])) {
  8263.                                     $info $this->getImageBuffer($pl['opt']['mk']['ri']);
  8264.                                     if ($info !== false) {
  8265.                                         $annots .= ' /RI '.$info['n'].' 0 R';
  8266.                                     }
  8267.                                 }
  8268.                                 if (isset($pl['opt']['mk']['ix'])) {
  8269.                                     $info $this->getImageBuffer($pl['opt']['mk']['ix']);
  8270.                                     if ($info !== false) {
  8271.                                         $annots .= ' /IX '.$info['n'].' 0 R';
  8272.                                     }
  8273.                                 }
  8274.                                 if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8275.                                     $annots .= ' /IF <<';
  8276.                                     $if_sw = array('A''B''S''N');
  8277.                                     if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8278.                                         $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8279.                                     }
  8280.                                     $if_s = array('A''P');
  8281.                                     if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8282.                                         $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8283.                                     }
  8284.                                     if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8285.                                         $annots .= sprintf(' /A [%F %F]'$pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8286.                                     }
  8287.                                     if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8288.                                         $annots .= ' /FB true';
  8289.                                     }
  8290.                                     $annots .= '>>';
  8291.                                 }
  8292.                                 if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8293.                                     $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8294.                                 }
  8295.                                 $annots .= '>>';
  8296.                             } // end MK
  8297.                             // --- Entries for field dictionaries ---
  8298.                             if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8299.                                 // set parent
  8300.                                 $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8301.                             }
  8302.                             if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8303.                                 $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8304.                             }
  8305.                             if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8306.                                 $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8307.                             }
  8308.                             if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8309.                                 $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8310.                             }
  8311.                             if (isset($pl['opt']['ff'])) {
  8312.                                 if (is_array($pl['opt']['ff'])) {
  8313.                                     // array of bit settings
  8314.                                     $flag 0;
  8315.                                     foreach($pl['opt']['ff'] as $val) {
  8316.                                         $flag += << ($val 1);
  8317.                                     }
  8318.                                 } else {
  8319.                                     $flag intval($pl['opt']['ff']);
  8320.                                 }
  8321.                                 $annots .= ' /Ff '.$flag;
  8322.                             }
  8323.                             if (isset($pl['opt']['maxlen'])) {
  8324.                                 $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8325.                             }
  8326.                             if (isset($pl['opt']['v'])) {
  8327.                                 $annots .= ' /V';
  8328.                                 if (is_array($pl['opt']['v'])) {
  8329.                                     foreach ($pl['opt']['v'] AS $optval) {
  8330.                                         if (is_float($optval)) {
  8331.                                             $optval sprintf('%F'$optval);
  8332.                                         }
  8333.                                         $annots .= ' '.$optval;
  8334.                                     }
  8335.                                 } else {
  8336.                                     $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8337.                                 }
  8338.                             }
  8339.                             if (isset($pl['opt']['dv'])) {
  8340.                                 $annots .= ' /DV';
  8341.                                 if (is_array($pl['opt']['dv'])) {
  8342.                                     foreach ($pl['opt']['dv'] AS $optval) {
  8343.                                         if (is_float($optval)) {
  8344.                                             $optval sprintf('%F'$optval);
  8345.                                         }
  8346.                                         $annots .= ' '.$optval;
  8347.                                     }
  8348.                                 } else {
  8349.                                     $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8350.                                 }
  8351.                             }
  8352.                             if (isset($pl['opt']['rv'])) {
  8353.                                 $annots .= ' /RV';
  8354.                                 if (is_array($pl['opt']['rv'])) {
  8355.                                     foreach ($pl['opt']['rv'] AS $optval) {
  8356.                                         if (is_float($optval)) {
  8357.                                             $optval sprintf('%F'$optval);
  8358.                                         }
  8359.                                         $annots .= ' '.$optval;
  8360.                                     }
  8361.                                 } else {
  8362.                                     $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8363.                                 }
  8364.                             }
  8365.                             if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8366.                                 $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8367.                             }
  8368.                             if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8369.                                 $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8370.                             }
  8371.                             if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8372.                                 $annots .= ' /DA ('.$pl['opt']['da'].')';
  8373.                             }
  8374.                             if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8375.                                 $annots .= ' /Q '.intval($pl['opt']['q']);
  8376.                             }
  8377.                             if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8378.                                 $annots .= ' /Opt [';
  8379.                                 foreach($pl['opt']['opt'] AS $copt) {
  8380.                                     if (is_array($copt)) {
  8381.                                         $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8382.                                     } else {
  8383.                                         $annots .= ' '.$this->_textstring($copt$annot_obj_id);
  8384.                                     }
  8385.                                 }
  8386.                                 $annots .= ']';
  8387.                             }
  8388.                             if (isset($pl['opt']['ti'])) {
  8389.                                 $annots .= ' /TI '.intval($pl['opt']['ti']);
  8390.                             }
  8391.                             if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8392.                                 $annots .= ' /I [';
  8393.                                 foreach($pl['opt']['i'] AS $copt) {
  8394.                                     $annots .= intval($copt).' ';
  8395.                                 }
  8396.                                 $annots .= ']';
  8397.                             }
  8398.                             break;
  8399.                         }
  8400.                         case 'screen': {
  8401.                             break;
  8402.                         }
  8403.                         case 'printermark': {
  8404.                             break;
  8405.                         }
  8406.                         case 'trapnet': {
  8407.                             break;
  8408.                         }
  8409.                         case 'watermark': {
  8410.                             break;
  8411.                         }
  8412.                         case '3d': {
  8413.                             break;
  8414.                         }
  8415.                         default: {
  8416.                             break;
  8417.                         }
  8418.                     }
  8419.                     $annots .= '>>';
  8420.                     // create new annotation object
  8421.                     $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8422.                     if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8423.                         // store reference of form object
  8424.                         $this->form_obj_id[] = $annot_obj_id;
  8425.                     }
  8426.                 }
  8427.             }
  8428.         } // end for each page
  8429.     }
  8430.     /**
  8431.      * Put appearance streams XObject used to define annotation's appearance states.
  8432.      * @param int $w annotation width
  8433.      * @param int $h annotation height
  8434.      * @param string $stream appearance stream
  8435.      * @return int object ID
  8436.      * @protected
  8437.      * @since 4.8.001 (2009-09-09)
  8438.      */
  8439.     protected function _putAPXObject($w=0$h=0$stream='') {
  8440.         $stream trim($stream);
  8441.         $out $this->_getobj()."\n";
  8442.         $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8443.         $out .= '<<';
  8444.         $out .= ' /Type /XObject';
  8445.         $out .= ' /Subtype /Form';
  8446.         $out .= ' /FormType 1';
  8447.         if ($this->compress) {
  8448.             $stream gzcompress($stream);
  8449.             $out .= ' /Filter /FlateDecode';
  8450.         }
  8451.         $rect sprintf('%F %F'$w$h);
  8452.         $out .= ' /BBox [0 0 '.$rect.']';
  8453.         $out .= ' /Matrix [1 0 0 1 0 0]';
  8454.         $out .= ' /Resources 2 0 R';
  8455.         $stream $this->_getrawstream($stream);
  8456.         $out .= ' /Length '.strlen($stream);
  8457.         $out .= ' >>';
  8458.         $out .= ' stream'."\n".$stream."\n".'endstream';
  8459.         $out .= "\n".'endobj';
  8460.         $this->_out($out);
  8461.         return $this->n;
  8462.     }
  8463.     /**
  8464.      * Output fonts.
  8465.      * @author Nicola Asuni
  8466.      * @protected
  8467.      */
  8468.     protected function _putfonts() {
  8469.         $nf $this->n;
  8470.         foreach ($this->diffs as $diff) {
  8471.             //Encodings
  8472.             $this->_newobj();
  8473.             $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8474.         }
  8475.         foreach ($this->FontFiles as $file => $info) {
  8476.             // search and get font file to embedd
  8477.             $fontfile TCPDF_FONTS::getFontFullPath($file$info['fontdir']);
  8478.             if (!TCPDF_STATIC::empty_string($fontfile)) {
  8479.                 $font file_get_contents($fontfile);
  8480.                 $compressed = (substr($file, -2) == '.z');
  8481.                 if ((!$compressed) AND (isset($info['length2']))) {
  8482.                     $header = (ord($font[0]) == 128);
  8483.                     if ($header) {
  8484.                         // strip first binary header
  8485.                         $font substr($font6);
  8486.                     }
  8487.                     if ($header AND (ord($font[$info['length1']]) == 128)) {
  8488.                         // strip second binary header
  8489.                         $font substr($font0$info['length1']).substr($font, ($info['length1'] + 6));
  8490.                     }
  8491.                 } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8492.                     if ($compressed) {
  8493.                         // uncompress font
  8494.                         $font gzuncompress($font);
  8495.                     }
  8496.                     // merge subset characters
  8497.                     $subsetchars = array(); // used chars
  8498.                     foreach ($info['fontkeys'] as $fontkey) {
  8499.                         $fontinfo $this->getFontBuffer($fontkey);
  8500.                         $subsetchars += $fontinfo['subsetchars'];
  8501.                     }
  8502.                     // rebuild a font subset
  8503.                     $font TCPDF_FONTS::_getTrueTypeFontSubset($font$subsetchars);
  8504.                     // calculate new font length
  8505.                     $info['length1'] = strlen($font);
  8506.                     if ($compressed) {
  8507.                         // recompress font
  8508.                         $font gzcompress($font);
  8509.                     }
  8510.                 }
  8511.                 $this->_newobj();
  8512.                 $this->FontFiles[$file]['n'] = $this->n;
  8513.                 $stream $this->_getrawstream($font);
  8514.                 $out '<< /Length '.strlen($stream);
  8515.                 if ($compressed) {
  8516.                     $out .= ' /Filter /FlateDecode';
  8517.                 }
  8518.                 $out .= ' /Length1 '.$info['length1'];
  8519.                 if (isset($info['length2'])) {
  8520.                     $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8521.                 }
  8522.                 $out .= ' >>';
  8523.                 $out .= ' stream'."\n".$stream."\n".'endstream';
  8524.                 $out .= "\n".'endobj';
  8525.                 $this->_out($out);
  8526.             }
  8527.         }
  8528.         foreach ($this->fontkeys as $k) {
  8529.             //Font objects
  8530.             $font $this->getFontBuffer($k);
  8531.             $type $font['type'];
  8532.             $name $font['name'];
  8533.             if ($type == 'core') {
  8534.                 // standard core font
  8535.                 $out $this->_getobj($this->font_obj_ids[$k])."\n";
  8536.                 $out .= '<</Type /Font';
  8537.                 $out .= ' /Subtype /Type1';
  8538.                 $out .= ' /BaseFont /'.$name;
  8539.                 $out .= ' /Name /F'.$font['i'];
  8540.                 if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8541.                     $out .= ' /Encoding /WinAnsiEncoding';
  8542.                 }
  8543.                 if ($k == 'helvetica') {
  8544.                     // add default font for annotations
  8545.                     $this->annotation_fonts[$k] = $font['i'];
  8546.                 }
  8547.                 $out .= ' >>';
  8548.                 $out .= "\n".'endobj';
  8549.                 $this->_out($out);
  8550.             } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8551.                 // additional Type1 or TrueType font
  8552.                 $out $this->_getobj($this->font_obj_ids[$k])."\n";
  8553.                 $out .= '<</Type /Font';
  8554.                 $out .= ' /Subtype /'.$type;
  8555.                 $out .= ' /BaseFont /'.$name;
  8556.                 $out .= ' /Name /F'.$font['i'];
  8557.                 $out .= ' /FirstChar 32 /LastChar 255';
  8558.                 $out .= ' /Widths '.($this->1).' 0 R';
  8559.                 $out .= ' /FontDescriptor '.($this->2).' 0 R';
  8560.                 if ($font['enc']) {
  8561.                     if (isset($font['diff'])) {
  8562.                         $out .= ' /Encoding '.($nf $font['diff']).' 0 R';
  8563.                     } else {
  8564.                         $out .= ' /Encoding /WinAnsiEncoding';
  8565.                     }
  8566.                 }
  8567.                 $out .= ' >>';
  8568.                 $out .= "\n".'endobj';
  8569.                 $this->_out($out);
  8570.                 // Widths
  8571.                 $this->_newobj();
  8572.                 $s '[';
  8573.                 for ($i 32$i 256; ++$i) {
  8574.                     if (isset($font['cw'][$i])) {
  8575.                         $s .= $font['cw'][$i].' ';
  8576.                     } else {
  8577.                         $s .= $font['dw'].' ';
  8578.                     }
  8579.                 }
  8580.                 $s .= ']';
  8581.                 $s .= "\n".'endobj';
  8582.                 $this->_out($s);
  8583.                 //Descriptor
  8584.                 $this->_newobj();
  8585.                 $s '<</Type /FontDescriptor /FontName /'.$name;
  8586.                 foreach ($font['desc'] as $fdk => $fdv) {
  8587.                     if (is_float($fdv)) {
  8588.                         $fdv sprintf('%F'$fdv);
  8589.                     }
  8590.                     $s .= ' /'.$fdk.' '.$fdv.'';
  8591.                 }
  8592.                 if (!TCPDF_STATIC::empty_string($font['file'])) {
  8593.                     $s .= ' /FontFile'.($type == 'Type1' '' '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8594.                 }
  8595.                 $s .= '>>';
  8596.                 $s .= "\n".'endobj';
  8597.                 $this->_out($s);
  8598.             } else {
  8599.                 // additional types
  8600.                 $mtd '_put'.strtolower($type);
  8601.                 if (!method_exists($this$mtd)) {
  8602.                     $this->Error('Unsupported font type: '.$type);
  8603.                 }
  8604.                 $this->$mtd($font);
  8605.             }
  8606.         }
  8607.     }
  8608.     /**
  8609.      * Adds unicode fonts.<br>
  8610.      * Based on PDF Reference 1.3 (section 5)
  8611.      * @param array $font font data
  8612.      * @protected
  8613.      * @author Nicola Asuni
  8614.      * @since 1.52.0.TC005 (2005-01-05)
  8615.      */
  8616.     protected function _puttruetypeunicode($font) {
  8617.         $fontname '';
  8618.         if ($font['subset']) {
  8619.             // change name for font subsetting
  8620.             $subtag sprintf('%06u'$font['i']);
  8621.             $subtag strtr($subtag'0123456789''ABCDEFGHIJ');
  8622.             $fontname .= $subtag.'+';
  8623.         }
  8624.         $fontname .= $font['name'];
  8625.         // Type0 Font
  8626.         // A composite font composed of other fonts, organized hierarchically
  8627.         $out $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8628.         $out .= '<< /Type /Font';
  8629.         $out .= ' /Subtype /Type0';
  8630.         $out .= ' /BaseFont /'.$fontname;
  8631.         $out .= ' /Name /F'.$font['i'];
  8632.         $out .= ' /Encoding /'.$font['enc'];
  8633.         $out .= ' /ToUnicode '.($this->1).' 0 R';
  8634.         $out .= ' /DescendantFonts ['.($this->2).' 0 R]';
  8635.         $out .= ' >>';
  8636.         $out .= "\n".'endobj';
  8637.         $this->_out($out);
  8638.         // ToUnicode map for Identity-H
  8639.         $stream TCPDF_FONT_DATA::$uni_identity_h;
  8640.         // ToUnicode Object
  8641.         $this->_newobj();
  8642.         $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8643.         $filter = ($this->compress) ? '/Filter /FlateDecode ' '';
  8644.         $stream $this->_getrawstream($stream);
  8645.         $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8646.         // CIDFontType2
  8647.         // A CIDFont whose glyph descriptions are based on TrueType font technology
  8648.         $oid $this->_newobj();
  8649.         $out '<< /Type /Font';
  8650.         $out .= ' /Subtype /CIDFontType2';
  8651.         $out .= ' /BaseFont /'.$fontname;
  8652.         // A dictionary containing entries that define the character collection of the CIDFont.
  8653.         $cidinfo '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8654.         $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8655.         $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8656.         $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8657.         $out .= ' /FontDescriptor '.($this->1).' 0 R';
  8658.         $out .= ' /DW '.$font['dw']; // default width
  8659.         $out .= "\n".TCPDF_FONTS::_putfontwidths($font0);
  8660.         if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8661.             $out .= "\n".'/CIDToGIDMap '.($this->2).' 0 R';
  8662.         }
  8663.         $out .= ' >>';
  8664.         $out .= "\n".'endobj';
  8665.         $this->_out($out);
  8666.         // Font descriptor
  8667.         // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8668.         $this->_newobj();
  8669.         $out '<< /Type /FontDescriptor';
  8670.         $out .= ' /FontName /'.$fontname;
  8671.         foreach ($font['desc'] as $key => $value) {
  8672.             if (is_float($value)) {
  8673.                 $value sprintf('%F'$value);
  8674.             }
  8675.             $out .= ' /'.$key.' '.$value;
  8676.         }
  8677.         $fontdir false;
  8678.         if (!TCPDF_STATIC::empty_string($font['file'])) {
  8679.             // A stream containing a TrueType font
  8680.             $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8681.             $fontdir $this->FontFiles[$font['file']]['fontdir'];
  8682.         }
  8683.         $out .= ' >>';
  8684.         $out .= "\n".'endobj';
  8685.         $this->_out($out);
  8686.         if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8687.             $this->_newobj();
  8688.             // Embed CIDToGIDMap
  8689.             // A specification of the mapping from CIDs to glyph indices
  8690.             // search and get CTG font file to embedd
  8691.             $ctgfile strtolower($font['ctg']);
  8692.             // search and get ctg font file to embedd
  8693.             $fontfile TCPDF_FONTS::getFontFullPath($ctgfile$fontdir);
  8694.             if (TCPDF_STATIC::empty_string($fontfile)) {
  8695.                 $this->Error('Font file not found: '.$ctgfile);
  8696.             }
  8697.             $stream $this->_getrawstream(file_get_contents($fontfile));
  8698.             $out '<< /Length '.strlen($stream).'';
  8699.             if (substr($fontfile, -2) == '.z') { // check file extension
  8700.                 // Decompresses data encoded using the public-domain
  8701.                 // zlib/deflate compression method, reproducing the
  8702.                 // original text or binary data
  8703.                 $out .= ' /Filter /FlateDecode';
  8704.             }
  8705.             $out .= ' >>';
  8706.             $out .= ' stream'."\n".$stream."\n".'endstream';
  8707.             $out .= "\n".'endobj';
  8708.             $this->_out($out);
  8709.         }
  8710.     }
  8711.     /**
  8712.      * Output CID-0 fonts.
  8713.      * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8714.      * @param array $font font data
  8715.      * @protected
  8716.      * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8717.      * @since 3.2.000 (2008-06-23)
  8718.      */
  8719.     protected function _putcidfont0($font) {
  8720.         $cidoffset 0;
  8721.         if (!isset($font['cw'][1])) {
  8722.             $cidoffset 31;
  8723.         }
  8724.         if (isset($font['cidinfo']['uni2cid'])) {
  8725.             // convert unicode to cid.
  8726.             $uni2cid $font['cidinfo']['uni2cid'];
  8727.             $cw = array();
  8728.             foreach ($font['cw'] as $uni => $width) {
  8729.                 if (isset($uni2cid[$uni])) {
  8730.                     $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8731.                 } elseif ($uni 256) {
  8732.                     $cw[$uni] = $width;
  8733.                 } // else unknown character
  8734.             }
  8735.             $font array_merge($font, array('cw' => $cw));
  8736.         }
  8737.         $name $font['name'];
  8738.         $enc $font['enc'];
  8739.         if ($enc) {
  8740.             $longname $name.'-'.$enc;
  8741.         } else {
  8742.             $longname $name;
  8743.         }
  8744.         $out $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8745.         $out .= '<</Type /Font';
  8746.         $out .= ' /Subtype /Type0';
  8747.         $out .= ' /BaseFont /'.$longname;
  8748.         $out .= ' /Name /F'.$font['i'];
  8749.         if ($enc) {
  8750.             $out .= ' /Encoding /'.$enc;
  8751.         }
  8752.         $out .= ' /DescendantFonts ['.($this->1).' 0 R]';
  8753.         $out .= ' >>';
  8754.         $out .= "\n".'endobj';
  8755.         $this->_out($out);
  8756.         $oid $this->_newobj();
  8757.         $out '<</Type /Font';
  8758.         $out .= ' /Subtype /CIDFontType0';
  8759.         $out .= ' /BaseFont /'.$name;
  8760.         $cidinfo '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8761.         $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8762.         $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8763.         $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8764.         $out .= ' /FontDescriptor '.($this->1).' 0 R';
  8765.         $out .= ' /DW '.$font['dw'];
  8766.         $out .= "\n".TCPDF_FONTS::_putfontwidths($font$cidoffset);
  8767.         $out .= ' >>';
  8768.         $out .= "\n".'endobj';
  8769.         $this->_out($out);
  8770.         $this->_newobj();
  8771.         $s '<</Type /FontDescriptor /FontName /'.$name;
  8772.         foreach ($font['desc'] as $k => $v) {
  8773.             if ($k != 'Style') {
  8774.                 if (is_float($v)) {
  8775.                     $v sprintf('%F'$v);
  8776.                 }
  8777.                 $s .= ' /'.$k.' '.$v.'';
  8778.             }
  8779.         }
  8780.         $s .= '>>';
  8781.         $s .= "\n".'endobj';
  8782.         $this->_out($s);
  8783.     }
  8784.     /**
  8785.      * Output images.
  8786.      * @protected
  8787.      */
  8788.     protected function _putimages() {
  8789.         $filter = ($this->compress) ? '/Filter /FlateDecode ' '';
  8790.         foreach ($this->imagekeys as $file) {
  8791.             $info $this->getImageBuffer($file);
  8792.             // set object for alternate images array
  8793.             $altoid null;
  8794.             if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8795.                 $altoid $this->_newobj();
  8796.                 $out '[';
  8797.                 foreach ($info['altimgs'] as $altimage) {
  8798.                     if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8799.                         $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8800.                         $out .= ' /DefaultForPrinting';
  8801.                         if ($altimage[1] === true) {
  8802.                             $out .= ' true';
  8803.                         } else {
  8804.                             $out .= ' false';
  8805.                         }
  8806.                         $out .= ' >>';
  8807.                     }
  8808.                 }
  8809.                 $out .= ' ]';
  8810.                 $out .= "\n".'endobj';
  8811.                 $this->_out($out);
  8812.             }
  8813.             // set image object
  8814.             $oid $this->_newobj();
  8815.             $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8816.             $this->setImageSubBuffer($file'n'$this->n);
  8817.             $out '<</Type /XObject';
  8818.             $out .= ' /Subtype /Image';
  8819.             $out .= ' /Width '.$info['w'];
  8820.             $out .= ' /Height '.$info['h'];
  8821.             if (array_key_exists('masked'$info)) {
  8822.                 $out .= ' /SMask '.($this->1).' 0 R';
  8823.             }
  8824.             // set color space
  8825.             $icc false;
  8826.             if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8827.                 // ICC Colour Space
  8828.                 $icc true;
  8829.                 $out .= ' /ColorSpace [/ICCBased '.($this->1).' 0 R]';
  8830.             } elseif ($info['cs'] == 'Indexed') {
  8831.                 // Indexed Colour Space
  8832.                 $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->1).' 0 R]';
  8833.             } else {
  8834.                 // Device Colour Space
  8835.                 $out .= ' /ColorSpace /'.$info['cs'];
  8836.             }
  8837.             if ($info['cs'] == 'DeviceCMYK') {
  8838.                 $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8839.             }
  8840.             $out .= ' /BitsPerComponent '.$info['bpc'];
  8841.             if ($altoid 0) {
  8842.                 // reference to alternate images dictionary
  8843.                 $out .= ' /Alternates '.$altoid.' 0 R';
  8844.             }
  8845.             if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8846.                 // external stream
  8847.                 $out .= ' /Length 0';
  8848.                 $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8849.                 if (isset($info['f'])) {
  8850.                     $out .= ' /FFilter /'.$info['f'];
  8851.                 }
  8852.                 $out .= ' >>';
  8853.                 $out .= ' stream'."\n".'endstream';
  8854.             } else {
  8855.                 if (isset($info['f'])) {
  8856.                     $out .= ' /Filter /'.$info['f'];
  8857.                 }
  8858.                 if (isset($info['parms'])) {
  8859.                     $out .= ' '.$info['parms'];
  8860.                 }
  8861.                 if (isset($info['trns']) AND is_array($info['trns'])) {
  8862.                     $trns '';
  8863.                     $count_info count($info['trns']);
  8864.                     if ($info['cs'] == 'Indexed') {
  8865.                         $maxval =(pow(2$info['bpc']) - 1);
  8866.                         for ($i 0$i $count_info; ++$i) {
  8867.                             if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
  8868.                                 // this is not a binary type mask @TODO: create a SMask
  8869.                                 $trns '';
  8870.                                 break;
  8871.                             } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
  8872.                                 // store the first fully transparent value
  8873.                                 $trns .= $i.' '.$i.' ';
  8874.                             }
  8875.                         }
  8876.                     } else {
  8877.                         // grayscale or RGB
  8878.                         for ($i 0$i $count_info; ++$i) {
  8879.                             if ($info['trns'][$i] == 0) {
  8880.                                 $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8881.                             }
  8882.                         }
  8883.                     }
  8884.                     // Colour Key Masking
  8885.                     if (!empty($trns)) {
  8886.                         $out .= ' /Mask ['.$trns.']';
  8887.                     }
  8888.                 }
  8889.                 $stream $this->_getrawstream($info['data']);
  8890.                 $out .= ' /Length '.strlen($stream).' >>';
  8891.                 $out .= ' stream'."\n".$stream."\n".'endstream';
  8892.             }
  8893.             $out .= "\n".'endobj';
  8894.             $this->_out($out);
  8895.             if ($icc) {
  8896.                 // ICC colour profile
  8897.                 $this->_newobj();
  8898.                 $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  8899.                 $icc $this->_getrawstream($icc);
  8900.                 $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  8901.             } elseif ($info['cs'] == 'Indexed') {
  8902.                 // colour palette
  8903.                 $this->_newobj();
  8904.                 $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8905.                 $pal $this->_getrawstream($pal);
  8906.                 $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  8907.             }
  8908.         }
  8909.     }
  8910.     /**
  8911.      * Output Form XObjects Templates.
  8912.      * @author Nicola Asuni
  8913.      * @since 5.8.017 (2010-08-24)
  8914.      * @protected
  8915.      * @see startTemplate(), endTemplate(), printTemplate()
  8916.      */
  8917.     protected function _putxobjects() {
  8918.         foreach ($this->xobjects as $key => $data) {
  8919.             if (isset($data['outdata'])) {
  8920.                 $stream str_replace($this->epsmarker''trim($data['outdata']));
  8921.                 $out $this->_getobj($data['n'])."\n";
  8922.                 $out .= '<<';
  8923.                 $out .= ' /Type /XObject';
  8924.                 $out .= ' /Subtype /Form';
  8925.                 $out .= ' /FormType 1';
  8926.                 if ($this->compress) {
  8927.                     $stream gzcompress($stream);
  8928.                     $out .= ' /Filter /FlateDecode';
  8929.                 }
  8930.                 $out .= sprintf(' /BBox [%F %F %F %F]', ($data['x'] * $this->k), (-$data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
  8931.                 $out .= ' /Matrix [1 0 0 1 0 0]';
  8932.                 $out .= ' /Resources <<';
  8933.                 $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8934.                 if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  8935.                     // transparency
  8936.                     if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  8937.                         $out .= ' /ExtGState <<';
  8938.                         foreach ($data['extgstates'] as $k => $extgstate) {
  8939.                             if (isset($this->extgstates[$k]['name'])) {
  8940.                                 $out .= ' /'.$this->extgstates[$k]['name'];
  8941.                             } else {
  8942.                                 $out .= ' /GS'.$k;
  8943.                             }
  8944.                             $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  8945.                         }
  8946.                         $out .= ' >>';
  8947.                     }
  8948.                     if (isset($data['gradients']) AND !empty($data['gradients'])) {
  8949.                         $gp '';
  8950.                         $gs '';
  8951.                         foreach ($data['gradients'] as $id => $grad) {
  8952.                             // gradient patterns
  8953.                             $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  8954.                             // gradient shadings
  8955.                             $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  8956.                         }
  8957.                         $out .= ' /Pattern <<'.$gp.' >>';
  8958.                         $out .= ' /Shading <<'.$gs.' >>';
  8959.                     }
  8960.                 }
  8961.                 // spot colors
  8962.                 if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  8963.                     $out .= ' /ColorSpace <<';
  8964.                     foreach ($data['spot_colors'] as $name => $color) {
  8965.                         $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  8966.                     }
  8967.                     $out .= ' >>';
  8968.                 }
  8969.                 // fonts
  8970.                 if (!empty($data['fonts'])) {
  8971.                     $out .= ' /Font <<';
  8972.                     foreach ($data['fonts'] as $fontkey => $fontid) {
  8973.                         $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8974.                     }
  8975.                     $out .= ' >>';
  8976.                 }
  8977.                 // images or nested xobjects
  8978.                 if (!empty($data['images']) OR !empty($data['xobjects'])) {
  8979.                     $out .= ' /XObject <<';
  8980.                     foreach ($data['images'] as $imgid) {
  8981.                         $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  8982.                     }
  8983.                     foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  8984.                         $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  8985.                     }
  8986.                     $out .= ' >>';
  8987.                 }
  8988.                 $out .= ' >>'//end resources
  8989.                 if (isset($data['group']) AND ($data['group'] !== false)) {
  8990.                     // set transparency group
  8991.                     $out .= ' /Group << /Type /Group /S /Transparency';
  8992.                     if (is_array($data['group'])) {
  8993.                         if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  8994.                             $out .= ' /CS /'.$data['group']['CS'];
  8995.                         }
  8996.                         if (isset($data['group']['I'])) {
  8997.                             $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  8998.                         }
  8999.                         if (isset($data['group']['K'])) {
  9000.                             $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  9001.                         }
  9002.                     }
  9003.                     $out .= ' >>';
  9004.                 }
  9005.                 $stream $this->_getrawstream($stream$data['n']);
  9006.                 $out .= ' /Length '.strlen($stream);
  9007.                 $out .= ' >>';
  9008.                 $out .= ' stream'."\n".$stream."\n".'endstream';
  9009.                 $out .= "\n".'endobj';
  9010.                 $this->_out($out);
  9011.             }
  9012.         }
  9013.     }
  9014.     /**
  9015.      * Output Spot Colors Resources.
  9016.      * @protected
  9017.      * @since 4.0.024 (2008-09-12)
  9018.      */
  9019.     protected function _putspotcolors() {
  9020.         foreach ($this->spot_colors as $name => $color) {
  9021.             $this->_newobj();
  9022.             $this->spot_colors[$name]['n'] = $this->n;
  9023.             $out '[/Separation /'.str_replace(' ''#20'$name);
  9024.             $out .= ' /DeviceCMYK <<';
  9025.             $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  9026.             $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  9027.             $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  9028.             $out .= "\n".'endobj';
  9029.             $this->_out($out);
  9030.         }
  9031.     }
  9032.     /**
  9033.      * Return XObjects Dictionary.
  9034.      * @return string XObjects dictionary
  9035.      * @protected
  9036.      * @since 5.8.014 (2010-08-23)
  9037.      */
  9038.     protected function _getxobjectdict() {
  9039.         $out '';
  9040.         foreach ($this->xobjects as $id => $objid) {
  9041.             $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  9042.         }
  9043.         return $out;
  9044.     }
  9045.     /**
  9046.      * Output Resources Dictionary.
  9047.      * @protected
  9048.      */
  9049.     protected function _putresourcedict() {
  9050.         $out $this->_getobj(2)."\n";
  9051.         $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  9052.         $out .= ' /Font <<';
  9053.         foreach ($this->fontkeys as $fontkey) {
  9054.             $font $this->getFontBuffer($fontkey);
  9055.             $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  9056.         }
  9057.         $out .= ' >>';
  9058.         $out .= ' /XObject <<';
  9059.         $out .= $this->_getxobjectdict();
  9060.         $out .= ' >>';
  9061.         // layers
  9062.         if (!empty($this->pdflayers)) {
  9063.             $out .= ' /Properties <<';
  9064.             foreach ($this->pdflayers as $layer) {
  9065.                 $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  9066.             }
  9067.             $out .= ' >>';
  9068.         }
  9069.         if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
  9070.             // transparency
  9071.             if (isset($this->extgstates) AND !empty($this->extgstates)) {
  9072.                 $out .= ' /ExtGState <<';
  9073.                 foreach ($this->extgstates as $k => $extgstate) {
  9074.                     if (isset($extgstate['name'])) {
  9075.                         $out .= ' /'.$extgstate['name'];
  9076.                     } else {
  9077.                         $out .= ' /GS'.$k;
  9078.                     }
  9079.                     $out .= ' '.$extgstate['n'].' 0 R';
  9080.                 }
  9081.                 $out .= ' >>';
  9082.             }
  9083.             if (isset($this->gradients) AND !empty($this->gradients)) {
  9084.                 $gp '';
  9085.                 $gs '';
  9086.                 foreach ($this->gradients as $id => $grad) {
  9087.                     // gradient patterns
  9088.                     $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  9089.                     // gradient shadings
  9090.                     $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  9091.                 }
  9092.                 $out .= ' /Pattern <<'.$gp.' >>';
  9093.                 $out .= ' /Shading <<'.$gs.' >>';
  9094.             }
  9095.         }
  9096.         // spot colors
  9097.         if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  9098.             $out .= ' /ColorSpace <<';
  9099.             foreach ($this->spot_colors as $color) {
  9100.                 $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  9101.             }
  9102.             $out .= ' >>';
  9103.         }
  9104.         $out .= ' >>';
  9105.         $out .= "\n".'endobj';
  9106.         $this->_out($out);
  9107.     }
  9108.     /**
  9109.      * Output Resources.
  9110.      * @protected
  9111.      */
  9112.     protected function _putresources() {
  9113.         $this->_putextgstates();
  9114.         $this->_putocg();
  9115.         $this->_putfonts();
  9116.         $this->_putimages();
  9117.         $this->_putspotcolors();
  9118.         $this->_putshaders();
  9119.         $this->_putxobjects();
  9120.         $this->_putresourcedict();
  9121.         $this->_putdests();
  9122.         $this->_putEmbeddedFiles();
  9123.         $this->_putannotsobjs();
  9124.         $this->_putjavascript();
  9125.         $this->_putbookmarks();
  9126.         $this->_putencryption();
  9127.     }
  9128.     /**
  9129.      * Adds some Metadata information (Document Information Dictionary)
  9130.      * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  9131.      * @return int object id
  9132.      * @protected
  9133.      */
  9134.     protected function _putinfo() {
  9135.         $oid $this->_newobj();
  9136.         $out '<<';
  9137.         // store current isunicode value
  9138.         $prev_isunicode $this->isunicode;
  9139.         if ($this->docinfounicode) {
  9140.             $this->isunicode true;
  9141.         }
  9142.         if (!TCPDF_STATIC::empty_string($this->title)) {
  9143.             // The document's title.
  9144.             $out .= ' /Title '.$this->_textstring($this->title$oid);
  9145.         }
  9146.         if (!TCPDF_STATIC::empty_string($this->author)) {
  9147.             // The name of the person who created the document.
  9148.             $out .= ' /Author '.$this->_textstring($this->author$oid);
  9149.         }
  9150.         if (!TCPDF_STATIC::empty_string($this->subject)) {
  9151.             // The subject of the document.
  9152.             $out .= ' /Subject '.$this->_textstring($this->subject$oid);
  9153.         }
  9154.         if (!TCPDF_STATIC::empty_string($this->keywords)) {
  9155.             // Keywords associated with the document.
  9156.             $out .= ' /Keywords '.$this->_textstring($this->keywords$oid);
  9157.         }
  9158.         if (!TCPDF_STATIC::empty_string($this->creator)) {
  9159.             // If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted.
  9160.             $out .= ' /Creator '.$this->_textstring($this->creator$oid);
  9161.         }
  9162.         // restore previous isunicode value
  9163.         $this->isunicode $prev_isunicode;
  9164.         // default producer
  9165.         $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9166.         // The date and time the document was created, in human-readable form
  9167.         $out .= ' /CreationDate '.$this->_datestring(0$this->doc_creation_timestamp);
  9168.         // The date and time the document was most recently modified, in human-readable form
  9169.         $out .= ' /ModDate '.$this->_datestring(0$this->doc_modification_timestamp);
  9170.         // A name object indicating whether the document has been modified to include trapping information
  9171.         $out .= ' /Trapped /False';
  9172.         $out .= ' >>';
  9173.         $out .= "\n".'endobj';
  9174.         $this->_out($out);
  9175.         return $oid;
  9176.     }
  9177.     /**
  9178.      * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9179.      * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9180.      * @param string $xmp Custom XMP data.
  9181.      * @since 5.9.128 (2011-10-06)
  9182.      * @public
  9183.      */
  9184.     public function setExtraXMP($xmp) {
  9185.         $this->custom_xmp $xmp;
  9186.     }
  9187.     /**
  9188.      * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag.
  9189.      * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9190.      * @param string $xmp Custom XMP RDF data.
  9191.      * @since 6.3.0 (2019-09-19)
  9192.      * @public
  9193.      */
  9194.     public function setExtraXMPRDF($xmp) {
  9195.         $this->custom_xmp_rdf $xmp;
  9196.     }
  9197.     /**
  9198.      * Put XMP data object and return ID.
  9199.      * @return int The object ID.
  9200.      * @since 5.9.121 (2011-09-28)
  9201.      * @protected
  9202.      */
  9203.     protected function _putXMP() {
  9204.         $oid $this->_newobj();
  9205.         // store current isunicode value
  9206.         $prev_isunicode $this->isunicode;
  9207.         $this->isunicode true;
  9208.         $prev_encrypted $this->encrypted;
  9209.         $this->encrypted false;
  9210.         // set XMP data
  9211.         $xmp '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff$this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9212.         $xmp .= '<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04">'."\n";
  9213.         $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9214.         $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9215.         $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9216.         $xmp .= "\t\t\t".'<dc:title>'."\n";
  9217.         $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9218.         $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9219.         $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9220.         $xmp .= "\t\t\t".'</dc:title>'."\n";
  9221.         $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9222.         $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9223.         $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9224.         $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9225.         $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9226.         $xmp .= "\t\t\t".'<dc:description>'."\n";
  9227.         $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9228.         $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9229.         $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9230.         $xmp .= "\t\t\t".'</dc:description>'."\n";
  9231.         $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9232.         $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9233.         $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9234.         $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9235.         $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9236.         $xmp .= "\t\t".'</rdf:Description>'."\n";
  9237.         // convert doc creation date format
  9238.         $dcdate TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9239.         $doccreationdate substr($dcdate04).'-'.substr($dcdate42).'-'.substr($dcdate62);
  9240.         $doccreationdate .= 'T'.substr($dcdate82).':'.substr($dcdate102).':'.substr($dcdate122);
  9241.         $doccreationdate .= substr($dcdate143).':'.substr($dcdate182);
  9242.         $doccreationdate TCPDF_STATIC::_escapeXML($doccreationdate);
  9243.         // convert doc modification date format
  9244.         $dmdate TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9245.         $docmoddate substr($dmdate04).'-'.substr($dmdate42).'-'.substr($dmdate62);
  9246.         $docmoddate .= 'T'.substr($dmdate82).':'.substr($dmdate102).':'.substr($dmdate122);
  9247.         $docmoddate .= substr($dmdate143).':'.substr($dmdate182);
  9248.         $docmoddate TCPDF_STATIC::_escapeXML($docmoddate);
  9249.         $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9250.         $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9251.         $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9252.         $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9253.         $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9254.         $xmp .= "\t\t".'</rdf:Description>'."\n";
  9255.         $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9256.         $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9257.         $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9258.         $xmp .= "\t\t".'</rdf:Description>'."\n";
  9259.         $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9260.         $uuid 'uuid:'.substr($this->file_id08).'-'.substr($this->file_id84).'-'.substr($this->file_id124).'-'.substr($this->file_id164).'-'.substr($this->file_id2012);
  9261.         $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9262.         $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9263.         $xmp .= "\t\t".'</rdf:Description>'."\n";
  9264.         if ($this->pdfa_mode) {
  9265.             $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9266.             $xmp .= "\t\t\t".'<pdfaid:part>'.$this->pdfa_version.'</pdfaid:part>'."\n";
  9267.             $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9268.             $xmp .= "\t\t".'</rdf:Description>'."\n";
  9269.         }
  9270.         // XMP extension schemas
  9271.         $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">'."\n";
  9272.         $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9273.         $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9274.         $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9275.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9276.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9277.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9278.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9279.         $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9280.         $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9281.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9282.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Adobe PDF Schema</pdfaProperty:description>'."\n";
  9283.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9284.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9285.         $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9286.         $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9287.         $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9288.         $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9289.         $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9290.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9291.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9292.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9293.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9294.         $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9295.         $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9296.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9297.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9298.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9299.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9300.         $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9301.         $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9302.         $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9303.         $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9304.         $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9305.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9306.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9307.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9308.         $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9309.         $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9310.         $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9311.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9312.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9313.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9314.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9315.         $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9316.         $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9317.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9318.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9319.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9320.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9321.         $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9322.         $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9323.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9324.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9325.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9326.         $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9327.         $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9328.         $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9329.         $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9330.         $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9331.         $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9332.         $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9333.         $xmp .= "\t\t".'</rdf:Description>'."\n";
  9334.         $xmp .= $this->custom_xmp_rdf;
  9335.         $xmp .= "\t".'</rdf:RDF>'."\n";
  9336.         $xmp .= $this->custom_xmp;
  9337.         $xmp .= '</x:xmpmeta>'."\n";
  9338.         $xmp .= '<?xpacket end="w"?>';
  9339.         $out '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9340.         // restore previous isunicode value
  9341.         $this->isunicode $prev_isunicode;
  9342.         $this->encrypted $prev_encrypted;
  9343.         $this->_out($out);
  9344.         return $oid;
  9345.     }
  9346.     /**
  9347.      * Output Catalog.
  9348.      * @return int object id
  9349.      * @protected
  9350.      */
  9351.     protected function _putcatalog() {
  9352.         // put XMP
  9353.         $xmpobj $this->_putXMP();
  9354.         // if required, add standard sRGB ICC colour profile
  9355.         if ($this->pdfa_mode OR $this->force_srgb) {
  9356.             $iccobj $this->_newobj();
  9357.             $icc file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9358.             $filter '';
  9359.             if ($this->compress) {
  9360.                 $filter ' /Filter /FlateDecode';
  9361.                 $icc gzcompress($icc);
  9362.             }
  9363.             $icc $this->_getrawstream($icc);
  9364.             $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9365.         }
  9366.         // start catalog
  9367.         $oid $this->_newobj();
  9368.         $out '<< /Type /Catalog';
  9369.         $out .= ' /Version /'.$this->PDFVersion;
  9370.         //$out .= ' /Extensions <<>>';
  9371.         $out .= ' /Pages 1 0 R';
  9372.         //$out .= ' /PageLabels ' //...;
  9373.         $out .= ' /Names <<';
  9374.         if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9375.             $out .= ' /JavaScript '.$this->n_js;
  9376.         }
  9377.         if (!empty($this->efnames)) {
  9378.             $out .= ' /EmbeddedFiles <</Names [';
  9379.             foreach ($this->efnames AS $fn => $fref) {
  9380.                 $out .= ' '.$this->_datastring($fn).' '.$fref;
  9381.             }
  9382.             $out .= ' ]>>';
  9383.         }
  9384.         $out .= ' >>';
  9385.         if (!empty($this->dests)) {
  9386.             $out .= ' /Dests '.($this->n_dests).' 0 R';
  9387.         }
  9388.         $out .= $this->_putviewerpreferences();
  9389.         if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9390.             $out .= ' /PageLayout /'.$this->LayoutMode;
  9391.         }
  9392.         if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9393.             $out .= ' /PageMode /'.$this->PageMode;
  9394.         }
  9395.         if (count($this->outlines) > 0) {
  9396.             $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9397.             $out .= ' /PageMode /UseOutlines';
  9398.         }
  9399.         //$out .= ' /Threads []';
  9400.         if ($this->ZoomMode == 'fullpage') {
  9401.             $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9402.         } elseif ($this->ZoomMode == 'fullwidth') {
  9403.             $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9404.         } elseif ($this->ZoomMode == 'real') {
  9405.             $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9406.         } elseif (!is_string($this->ZoomMode)) {
  9407.             $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode 100));
  9408.         }
  9409.         //$out .= ' /AA <<>>';
  9410.         //$out .= ' /URI <<>>';
  9411.         $out .= ' /Metadata '.$xmpobj.' 0 R';
  9412.         //$out .= ' /StructTreeRoot <<>>';
  9413.         //$out .= ' /MarkInfo <<>>';
  9414.         if (isset($this->l['a_meta_language'])) {
  9415.             $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9416.         }
  9417.         //$out .= ' /SpiderInfo <<>>';
  9418.         // set OutputIntent to sRGB IEC61966-2.1 if required
  9419.         if ($this->pdfa_mode OR $this->force_srgb) {
  9420.             $out .= ' /OutputIntents [<<';
  9421.             $out .= ' /Type /OutputIntent';
  9422.             $out .= ' /S /GTS_PDFA1';
  9423.             $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1'$oid);
  9424.             $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1'$oid);
  9425.             $out .= ' /RegistryName '.$this->_textstring('http://www.color.org'$oid);
  9426.             $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1'$oid);
  9427.             $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9428.             $out .= ' >>]';
  9429.         }
  9430.         //$out .= ' /PieceInfo <<>>';
  9431.         if (!empty($this->pdflayers)) {
  9432.             $lyrobjs '';
  9433.             $lyrobjs_off '';
  9434.             $lyrobjs_lock '';
  9435.             foreach ($this->pdflayers as $layer) {
  9436.                 $layer_obj_ref ' '.$layer['objid'].' 0 R';
  9437.                 $lyrobjs .= $layer_obj_ref;
  9438.                 if ($layer['view'] === false) {
  9439.                     $lyrobjs_off .= $layer_obj_ref;
  9440.                 }
  9441.                 if ($layer['lock']) {
  9442.                     $lyrobjs_lock .= $layer_obj_ref;
  9443.                 }
  9444.             }
  9445.             $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9446.             $out .= ' /D <<';
  9447.             $out .= ' /Name '.$this->_textstring('Layers'$oid);
  9448.             $out .= ' /Creator '.$this->_textstring('TCPDF'$oid);
  9449.             $out .= ' /BaseState /ON';
  9450.             $out .= ' /OFF ['.$lyrobjs_off.']';
  9451.             $out .= ' /Locked ['.$lyrobjs_lock.']';
  9452.             $out .= ' /Intent /View';
  9453.             $out .= ' /AS [';
  9454.             $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9455.             $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9456.             $out .= ' ]';
  9457.             $out .= ' /Order ['.$lyrobjs.']';
  9458.             $out .= ' /ListMode /AllPages';
  9459.             //$out .= ' /RBGroups ['..']';
  9460.             //$out .= ' /Locked ['..']';
  9461.             $out .= ' >>';
  9462.             $out .= ' >>';
  9463.         }
  9464.         // AcroForm
  9465.         if (!empty($this->form_obj_id)
  9466.             OR ($this->sign AND isset($this->signature_data['cert_type']))
  9467.             OR !empty($this->empty_signature_appearance)) {
  9468.             $out .= ' /AcroForm <<';
  9469.             $objrefs '';
  9470.             if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9471.                 // set reference for signature object
  9472.                 $objrefs .= $this->sig_obj_id.' 0 R';
  9473.             }
  9474.             if (!empty($this->empty_signature_appearance)) {
  9475.                 foreach ($this->empty_signature_appearance as $esa) {
  9476.                     // set reference for empty signature objects
  9477.                     $objrefs .= ' '.$esa['objid'].' 0 R';
  9478.                 }
  9479.             }
  9480.             if (!empty($this->form_obj_id)) {
  9481.                 foreach($this->form_obj_id as $objid) {
  9482.                     $objrefs .= ' '.$objid.' 0 R';
  9483.                 }
  9484.             }
  9485.             $out .= ' /Fields ['.$objrefs.']';
  9486.             // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9487.             if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  9488.                 $out .= ' /NeedAppearances false';
  9489.             }
  9490.             if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9491.                 if ($this->signature_data['cert_type'] > 0) {
  9492.                     $out .= ' /SigFlags 3';
  9493.                 } else {
  9494.                     $out .= ' /SigFlags 1';
  9495.                 }
  9496.             }
  9497.             //$out .= ' /CO ';
  9498.             if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9499.                 $out .= ' /DR <<';
  9500.                 $out .= ' /Font <<';
  9501.                 foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9502.                     $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9503.                 }
  9504.                 $out .= ' >> >>';
  9505.             }
  9506.             $font $this->getFontBuffer((($this->pdfa_mode) ? 'pdfa' '') .'helvetica');
  9507.             $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9508.             $out .= ' /Q '.(($this->rtl)?'2':'0');
  9509.             //$out .= ' /XFA ';
  9510.             $out .= ' >>';
  9511.             // signatures
  9512.             if ($this->sign AND isset($this->signature_data['cert_type'])
  9513.                 AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
  9514.                 if ($this->signature_data['cert_type'] > 0) {
  9515.                     $out .= ' /Perms << /DocMDP '.($this->sig_obj_id 1).' 0 R >>';
  9516.                 } else {
  9517.                     $out .= ' /Perms << /UR3 '.($this->sig_obj_id 1).' 0 R >>';
  9518.                 }
  9519.             }
  9520.         }
  9521.         //$out .= ' /Legal <<>>';
  9522.         //$out .= ' /Requirements []';
  9523.         //$out .= ' /Collection <<>>';
  9524.         //$out .= ' /NeedsRendering true';
  9525.         $out .= ' >>';
  9526.         $out .= "\n".'endobj';
  9527.         $this->_out($out);
  9528.         return $oid;
  9529.     }
  9530.     /**
  9531.      * Output viewer preferences.
  9532.      * @return string for viewer preferences
  9533.      * @author Nicola asuni
  9534.      * @since 3.1.000 (2008-06-09)
  9535.      * @protected
  9536.      */
  9537.     protected function _putviewerpreferences() {
  9538.         $vp $this->viewer_preferences;
  9539.         $out ' /ViewerPreferences <<';
  9540.         if ($this->rtl) {
  9541.             $out .= ' /Direction /R2L';
  9542.         } else {
  9543.             $out .= ' /Direction /L2R';
  9544.         }
  9545.         if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9546.             $out .= ' /HideToolbar true';
  9547.         }
  9548.         if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9549.             $out .= ' /HideMenubar true';
  9550.         }
  9551.         if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9552.             $out .= ' /HideWindowUI true';
  9553.         }
  9554.         if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9555.             $out .= ' /FitWindow true';
  9556.         }
  9557.         if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9558.             $out .= ' /CenterWindow true';
  9559.         }
  9560.         if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9561.             $out .= ' /DisplayDocTitle true';
  9562.         }
  9563.         if (isset($vp['NonFullScreenPageMode'])) {
  9564.             $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9565.         }
  9566.         if (isset($vp['ViewArea'])) {
  9567.             $out .= ' /ViewArea /'.$vp['ViewArea'];
  9568.         }
  9569.         if (isset($vp['ViewClip'])) {
  9570.             $out .= ' /ViewClip /'.$vp['ViewClip'];
  9571.         }
  9572.         if (isset($vp['PrintArea'])) {
  9573.             $out .= ' /PrintArea /'.$vp['PrintArea'];
  9574.         }
  9575.         if (isset($vp['PrintClip'])) {
  9576.             $out .= ' /PrintClip /'.$vp['PrintClip'];
  9577.         }
  9578.         if (isset($vp['PrintScaling'])) {
  9579.             $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9580.         }
  9581.         if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9582.             $out .= ' /Duplex /'.$vp['Duplex'];
  9583.         }
  9584.         if (isset($vp['PickTrayByPDFSize'])) {
  9585.             if ($vp['PickTrayByPDFSize']) {
  9586.                 $out .= ' /PickTrayByPDFSize true';
  9587.             } else {
  9588.                 $out .= ' /PickTrayByPDFSize false';
  9589.             }
  9590.         }
  9591.         if (isset($vp['PrintPageRange'])) {
  9592.             $PrintPageRangeNum '';
  9593.             foreach ($vp['PrintPageRange'] as $k => $v) {
  9594.                 $PrintPageRangeNum .= ' '.($v 1).'';
  9595.             }
  9596.             $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  9597.         }
  9598.         if (isset($vp['NumCopies'])) {
  9599.             $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9600.         }
  9601.         $out .= ' >>';
  9602.         return $out;
  9603.     }
  9604.     /**
  9605.      * Output PDF File Header (7.5.2).
  9606.      * @protected
  9607.      */
  9608.     protected function _putheader() {
  9609.         $this->_out('%PDF-'.$this->PDFVersion);
  9610.         $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9611.     }
  9612.     /**
  9613.      * Output end of document (EOF).
  9614.      * @protected
  9615.      */
  9616.     protected function _enddoc() {
  9617.         if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9618.             // save subset chars of the previous font
  9619.             $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars'$this->CurrentFont['subsetchars']);
  9620.         }
  9621.         $this->state 1;
  9622.         $this->_putheader();
  9623.         $this->_putpages();
  9624.         $this->_putresources();
  9625.         // empty signature fields
  9626.         if (!empty($this->empty_signature_appearance)) {
  9627.             foreach ($this->empty_signature_appearance as $key => $esa) {
  9628.                 // widget annotation for empty signature
  9629.                 $out $this->_getobj($esa['objid'])."\n";
  9630.                 $out .= '<< /Type /Annot';
  9631.                 $out .= ' /Subtype /Widget';
  9632.                 $out .= ' /Rect ['.$esa['rect'].']';
  9633.                 $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'// link to signature appearance page
  9634.                 $out .= ' /F 4';
  9635.                 $out .= ' /FT /Sig';
  9636.                 $signame $esa['name'].sprintf(' [%03d]', ($key 1));
  9637.                 $out .= ' /T '.$this->_textstring($signame$esa['objid']);
  9638.                 $out .= ' /Ff 0';
  9639.                 $out .= ' >>';
  9640.                 $out .= "\n".'endobj';
  9641.                 $this->_out($out);
  9642.             }
  9643.         }
  9644.         // Signature
  9645.         if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9646.             // widget annotation for signature
  9647.             $out $this->_getobj($this->sig_obj_id)."\n";
  9648.             $out .= '<< /Type /Annot';
  9649.             $out .= ' /Subtype /Widget';
  9650.             $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9651.             $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'// link to signature appearance page
  9652.             $out .= ' /F 4';
  9653.             $out .= ' /FT /Sig';
  9654.             $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9655.             $out .= ' /Ff 0';
  9656.             $out .= ' /V '.($this->sig_obj_id 1).' 0 R';
  9657.             $out .= ' >>';
  9658.             $out .= "\n".'endobj';
  9659.             $this->_out($out);
  9660.             // signature
  9661.             $this->_putsignature();
  9662.         }
  9663.         // Info
  9664.         $objid_info $this->_putinfo();
  9665.         // Catalog
  9666.         $objid_catalog $this->_putcatalog();
  9667.         // Cross-ref
  9668.         $o $this->bufferlen;
  9669.         // XREF section
  9670.         $this->_out('xref');
  9671.         $this->_out('0 '.($this->1));
  9672.         $this->_out('0000000000 65535 f ');
  9673.         $freegen = ($this->2);
  9674.         for ($i=1$i <= $this->n; ++$i) {
  9675.             if (!isset($this->offsets[$i]) AND ($i 1)) {
  9676.                 $this->_out(sprintf('0000000000 %05d f '$freegen));
  9677.                 ++$freegen;
  9678.             } else {
  9679.                 $this->_out(sprintf('%010d 00000 n '$this->offsets[$i]));
  9680.             }
  9681.         }
  9682.         // TRAILER
  9683.         $out 'trailer'."\n";
  9684.         $out .= '<<';
  9685.         $out .= ' /Size '.($this->1);
  9686.         $out .= ' /Root '.$objid_catalog.' 0 R';
  9687.         $out .= ' /Info '.$objid_info.' 0 R';
  9688.         if ($this->encrypted) {
  9689.             $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9690.         }
  9691.         $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9692.         $out .= ' >>';
  9693.         $this->_out($out);
  9694.         $this->_out('startxref');
  9695.         $this->_out($o);
  9696.         $this->_out('%%EOF');
  9697.         $this->state 3// end-of-doc
  9698.     }
  9699.     /**
  9700.      * Initialize a new page.
  9701.      * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9702.      * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  9703.      * @protected
  9704.      * @see getPageSizeFromFormat(), setPageFormat()
  9705.      */
  9706.     protected function _beginpage($orientation=''$format='') {
  9707.         ++$this->page;
  9708.         $this->pageobjects[$this->page] = array();
  9709.         $this->setPageBuffer($this->page'');
  9710.         // initialize array for graphics tranformation positions inside a page buffer
  9711.         $this->transfmrk[$this->page] = array();
  9712.         $this->state 2;
  9713.         if (TCPDF_STATIC::empty_string($orientation)) {
  9714.             if (isset($this->CurOrientation)) {
  9715.                 $orientation $this->CurOrientation;
  9716.             } elseif ($this->fwPt $this->fhPt) {
  9717.                 // landscape
  9718.                 $orientation 'L';
  9719.             } else {
  9720.                 // portrait
  9721.                 $orientation 'P';
  9722.             }
  9723.         }
  9724.         if (TCPDF_STATIC::empty_string($format)) {
  9725.             $this->pagedim[$this->page] = $this->pagedim[($this->page 1)];
  9726.             $this->setPageOrientation($orientation);
  9727.         } else {
  9728.             $this->setPageFormat($format$orientation);
  9729.         }
  9730.         if ($this->rtl) {
  9731.             $this->$this->$this->rMargin;
  9732.         } else {
  9733.             $this->$this->lMargin;
  9734.         }
  9735.         $this->$this->tMargin;
  9736.         if (isset($this->newpagegroup[$this->page])) {
  9737.             // start a new group
  9738.             $this->currpagegroup $this->newpagegroup[$this->page];
  9739.             $this->pagegroups[$this->currpagegroup] = 1;
  9740.         } elseif (isset($this->currpagegroup) AND ($this->currpagegroup 0)) {
  9741.             ++$this->pagegroups[$this->currpagegroup];
  9742.         }
  9743.     }
  9744.     /**
  9745.      * Mark end of page.
  9746.      * @protected
  9747.      */
  9748.     protected function _endpage() {
  9749.         $this->setVisibility('all');
  9750.         $this->state 1;
  9751.     }
  9752.     /**
  9753.      * Begin a new object and return the object number.
  9754.      * @return int object number
  9755.      * @protected
  9756.      */
  9757.     protected function _newobj() {
  9758.         $this->_out($this->_getobj());
  9759.         return $this->n;
  9760.     }
  9761.     /**
  9762.      * Return the starting object string for the selected object ID.
  9763.      * @param int|null $objid Object ID (leave empty to get a new ID).
  9764.      * @return string the starting object string
  9765.      * @protected
  9766.      * @since 5.8.009 (2010-08-20)
  9767.      */
  9768.     protected function _getobj($objid=null) {
  9769.         if (TCPDF_STATIC::empty_string($objid)) {
  9770.             ++$this->n;
  9771.             $objid $this->n;
  9772.         }
  9773.         $this->offsets[$objid] = $this->bufferlen;
  9774.         $this->pageobjects[$this->page][] = $objid;
  9775.         return $objid.' 0 obj';
  9776.     }
  9777.     /**
  9778.      * Underline text.
  9779.      * @param int $x X coordinate
  9780.      * @param int $y Y coordinate
  9781.      * @param string $txt text to underline
  9782.      * @protected
  9783.      */
  9784.     protected function _dounderline($x$y$txt) {
  9785.         $w $this->GetStringWidth($txt);
  9786.         return $this->_dounderlinew($x$y$w);
  9787.     }
  9788.     /**
  9789.      * Underline for rectangular text area.
  9790.      * @param int $x X coordinate
  9791.      * @param int $y Y coordinate
  9792.      * @param int $w width to underline
  9793.      * @protected
  9794.      * @since 4.8.008 (2009-09-29)
  9795.      */
  9796.     protected function _dounderlinew($x$y$w) {
  9797.         $linew = - $this->CurrentFont['ut'] / 1000 $this->FontSizePt;
  9798.         return sprintf('%F %F %F %F re f'$x $this->k, ((($this->$y) * $this->k) + $linew), $w $this->k$linew);
  9799.     }
  9800.     /**
  9801.      * Line through text.
  9802.      * @param int $x X coordinate
  9803.      * @param int $y Y coordinate
  9804.      * @param string $txt text to linethrough
  9805.      * @protected
  9806.      */
  9807.     protected function _dolinethrough($x$y$txt) {
  9808.         $w $this->GetStringWidth($txt);
  9809.         return $this->_dolinethroughw($x$y$w);
  9810.     }
  9811.     /**
  9812.      * Line through for rectangular text area.
  9813.      * @param int $x X coordinate
  9814.      * @param int $y Y coordinate
  9815.      * @param int $w line length (width)
  9816.      * @protected
  9817.      * @since 4.9.008 (2009-09-29)
  9818.      */
  9819.     protected function _dolinethroughw($x$y$w) {
  9820.         $linew = - $this->CurrentFont['ut'] / 1000 $this->FontSizePt;
  9821.         return sprintf('%F %F %F %F re f'$x $this->k, ((($this->$y) * $this->k) + $linew + ($this->FontSizePt 3)), $w $this->k$linew);
  9822.     }
  9823.     /**
  9824.      * Overline text.
  9825.      * @param int $x X coordinate
  9826.      * @param int $y Y coordinate
  9827.      * @param string $txt text to overline
  9828.      * @protected
  9829.      * @since 4.9.015 (2010-04-19)
  9830.      */
  9831.     protected function _dooverline($x$y$txt) {
  9832.         $w $this->GetStringWidth($txt);
  9833.         return $this->_dooverlinew($x$y$w);
  9834.     }
  9835.     /**
  9836.      * Overline for rectangular text area.
  9837.      * @param int $x X coordinate
  9838.      * @param int $y Y coordinate
  9839.      * @param int $w width to overline
  9840.      * @protected
  9841.      * @since 4.9.015 (2010-04-19)
  9842.      */
  9843.     protected function _dooverlinew($x$y$w) {
  9844.         $linew = - $this->CurrentFont['ut'] / 1000 $this->FontSizePt;
  9845.         return sprintf('%F %F %F %F re f'$x $this->k, (($this->$y $this->FontAscent) * $this->k) - $linew$w $this->k$linew);
  9846.     }
  9847.     /**
  9848.      * Format a data string for meta information
  9849.      * @param string $s data string to escape.
  9850.      * @param int $n object ID
  9851.      * @return string escaped string.
  9852.      * @protected
  9853.      */
  9854.     protected function _datastring($s$n=0) {
  9855.         if ($n == 0) {
  9856.             $n $this->n;
  9857.         }
  9858.         $s $this->_encrypt_data($n$s);
  9859.         return '('TCPDF_STATIC::_escape($s).')';
  9860.     }
  9861.     /**
  9862.      * Set the document creation timestamp
  9863.      * @param mixed $time Document creation timestamp in seconds or date-time string.
  9864.      * @public
  9865.      * @since 5.9.152 (2012-03-23)
  9866.      */
  9867.     public function setDocCreationTimestamp($time) {
  9868.         if (is_string($time)) {
  9869.             $time TCPDF_STATIC::getTimestamp($time);
  9870.         }
  9871.         $this->doc_creation_timestamp intval($time);
  9872.     }
  9873.     /**
  9874.      * Set the document modification timestamp
  9875.      * @param mixed $time Document modification timestamp in seconds or date-time string.
  9876.      * @public
  9877.      * @since 5.9.152 (2012-03-23)
  9878.      */
  9879.     public function setDocModificationTimestamp($time) {
  9880.         if (is_string($time)) {
  9881.             $time TCPDF_STATIC::getTimestamp($time);
  9882.         }
  9883.         $this->doc_modification_timestamp intval($time);
  9884.     }
  9885.     /**
  9886.      * Returns document creation timestamp in seconds.
  9887.      * @return int Creation timestamp in seconds.
  9888.      * @public
  9889.      * @since 5.9.152 (2012-03-23)
  9890.      */
  9891.     public function getDocCreationTimestamp() {
  9892.         return $this->doc_creation_timestamp;
  9893.     }
  9894.     /**
  9895.      * Returns document modification timestamp in seconds.
  9896.      * @return int Modfication timestamp in seconds.
  9897.      * @public
  9898.      * @since 5.9.152 (2012-03-23)
  9899.      */
  9900.     public function getDocModificationTimestamp() {
  9901.         return $this->doc_modification_timestamp;
  9902.     }
  9903.     /**
  9904.      * Returns a formatted date for meta information
  9905.      * @param int $n Object ID.
  9906.      * @param int $timestamp Timestamp to convert.
  9907.      * @return string escaped date string.
  9908.      * @protected
  9909.      * @since 4.6.028 (2009-08-25)
  9910.      */
  9911.     protected function _datestring($n=0$timestamp=0) {
  9912.         if ((empty($timestamp)) OR ($timestamp 0)) {
  9913.             $timestamp $this->doc_creation_timestamp;
  9914.         }
  9915.         return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  9916.     }
  9917.     /**
  9918.      * Format a text string for meta information
  9919.      * @param string $s string to escape.
  9920.      * @param int $n object ID
  9921.      * @return string escaped string.
  9922.      * @protected
  9923.      */
  9924.     protected function _textstring($s$n=0) {
  9925.         if ($this->isunicode) {
  9926.             //Convert string to UTF-16BE
  9927.             $s TCPDF_FONTS::UTF8ToUTF16BE($strue$this->isunicode$this->CurrentFont);
  9928.         }
  9929.         return $this->_datastring($s$n);
  9930.     }
  9931.     /**
  9932.      * get raw output stream.
  9933.      * @param string $s string to output.
  9934.      * @param int $n object reference for encryption mode
  9935.      * @protected
  9936.      * @author Nicola Asuni
  9937.      * @since 5.5.000 (2010-06-22)
  9938.      */
  9939.     protected function _getrawstream($s$n=0) {
  9940.         if ($n <= 0) {
  9941.             // default to current object
  9942.             $n $this->n;
  9943.         }
  9944.         return $this->_encrypt_data($n$s);
  9945.     }
  9946.     /**
  9947.      * Output a string to the document.
  9948.      * @param string $s string to output.
  9949.      * @protected
  9950.      */
  9951.     protected function _out($s) {
  9952.         if ($this->state == 2) {
  9953.             if ($this->inxobj) {
  9954.                 // we are inside an XObject template
  9955.                 $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  9956.             } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  9957.                 // puts data before page footer
  9958.                 $pagebuff $this->getPageBuffer($this->page);
  9959.                 $page substr($pagebuff0, -$this->footerlen[$this->page]);
  9960.                 $footer substr($pagebuff, -$this->footerlen[$this->page]);
  9961.                 $this->setPageBuffer($this->page$page.$s."\n".$footer);
  9962.                 // update footer position
  9963.                 $this->footerpos[$this->page] += strlen($s."\n");
  9964.             } else {
  9965.                 // set page data
  9966.                 $this->setPageBuffer($this->page$s."\n"true);
  9967.             }
  9968.         } elseif ($this->state 0) {
  9969.             // set general data
  9970.             $this->setBuffer($s."\n");
  9971.         }
  9972.     }
  9973.     /**
  9974.      * Set header font.
  9975.      * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
  9976.      * @phpstan-param array{0: string, 1: string, 2: float|null} $font
  9977.      * @public
  9978.      * @since 1.1
  9979.      */
  9980.     public function setHeaderFont($font) {
  9981.         $this->header_font $font;
  9982.     }
  9983.     /**
  9984.      * Get header font.
  9985.      * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
  9986.      * @phpstan-return array{0: string, 1: string, 2: float|null}
  9987.      * @public
  9988.      * @since 4.0.012 (2008-07-24)
  9989.      */
  9990.     public function getHeaderFont() {
  9991.         return $this->header_font;
  9992.     }
  9993.     /**
  9994.      * Set footer font.
  9995.      * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
  9996.      * @phpstan-param array{0: string, 1: string, 2: float|null} $font
  9997.      * @public
  9998.      * @since 1.1
  9999.      */
  10000.     public function setFooterFont($font) {
  10001.         $this->footer_font $font;
  10002.     }
  10003.     /**
  10004.      * Get Footer font.
  10005.      * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
  10006.      * @phpstan-return array{0: string, 1: string, 2: float|null} $font
  10007.      * @public
  10008.      * @since 4.0.012 (2008-07-24)
  10009.      */
  10010.     public function getFooterFont() {
  10011.         return $this->footer_font;
  10012.     }
  10013.     /**
  10014.      * Set language array.
  10015.      * @param array $language
  10016.      * @public
  10017.      * @since 1.1
  10018.      */
  10019.     public function setLanguageArray($language) {
  10020.         $this->$language;
  10021.         if (isset($this->l['a_meta_dir'])) {
  10022.             $this->rtl $this->l['a_meta_dir']=='rtl' true false;
  10023.         } else {
  10024.             $this->rtl false;
  10025.         }
  10026.     }
  10027.     /**
  10028.      * Returns the PDF data.
  10029.      * @public
  10030.      */
  10031.     public function getPDFData() {
  10032.         if ($this->state 3) {
  10033.             $this->Close();
  10034.         }
  10035.         return $this->buffer;
  10036.     }
  10037.     /**
  10038.      * Output anchor link.
  10039.      * @param string $url link URL or internal link (i.e.: &lt;a href="#23,4.5"&gt;link to page 23 at 4.5 Y position&lt;/a&gt;)
  10040.      * @param string $name link name
  10041.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  10042.      * @param boolean $firstline if true prints only the first line and return the remaining string.
  10043.      * @param array|null $color array of RGB text color
  10044.      * @param string $style font style (U, D, B, I)
  10045.      * @param boolean $firstblock if true the string is the starting of a line.
  10046.      * @return int the number of cells used or the remaining text if $firstline = true;
  10047.      * @public
  10048.      */
  10049.     public function addHtmlLink($url$name$fill=false$firstline=false$color=null$style=-1$firstblock=false) {
  10050.         if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  10051.             // convert url to internal link
  10052.             $lnkdata explode(','$url);
  10053.             if (isset($lnkdata[0]) ) {
  10054.                 $page substr($lnkdata[0], 1);
  10055.                 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  10056.                     $lnky floatval($lnkdata[1]);
  10057.                 } else {
  10058.                     $lnky 0;
  10059.                 }
  10060.                 $url $this->AddLink();
  10061.                 $this->setLink($url$lnky$page);
  10062.             }
  10063.         }
  10064.         // store current settings
  10065.         $prevcolor $this->fgcolor;
  10066.         $prevstyle $this->FontStyle;
  10067.         if (empty($color)) {
  10068.             $this->setTextColorArray($this->htmlLinkColorArray);
  10069.         } else {
  10070.             $this->setTextColorArray($color);
  10071.         }
  10072.         if ($style == -1) {
  10073.             $this->setFont(''$this->FontStyle.$this->htmlLinkFontStyle);
  10074.         } else {
  10075.             $this->setFont(''$this->FontStyle.$style);
  10076.         }
  10077.         $ret $this->Write($this->lasth$name$url$fill''false0$firstline$firstblock0);
  10078.         // restore settings
  10079.         $this->setFont(''$prevstyle);
  10080.         $this->setTextColorArray($prevcolor);
  10081.         return $ret;
  10082.     }
  10083.     /**
  10084.      * Converts pixels to User's Units.
  10085.      * @param int $px pixels
  10086.      * @return float value in user's unit
  10087.      * @public
  10088.      * @see setImageScale(), getImageScale()
  10089.      */
  10090.     public function pixelsToUnits($px) {
  10091.         return ($px / ($this->imgscale $this->k));
  10092.     }
  10093.     /**
  10094.      * Reverse function for htmlentities.
  10095.      * Convert entities in UTF-8.
  10096.      * @param string $text_to_convert Text to convert.
  10097.      * @return string converted text string
  10098.      * @public
  10099.      */
  10100.     public function unhtmlentities($text_to_convert) {
  10101.         return @html_entity_decode($text_to_convertENT_QUOTES$this->encoding);
  10102.     }
  10103.     // ENCRYPTION METHODS ----------------------------------
  10104.     /**
  10105.      * Compute encryption key depending on object number where the encrypted data is stored.
  10106.      * This is used for all strings and streams without crypt filter specifier.
  10107.      * @param int $n object number
  10108.      * @return int object key
  10109.      * @protected
  10110.      * @author Nicola Asuni
  10111.      * @since 2.0.000 (2008-01-02)
  10112.      */
  10113.     protected function _objectkey($n) {
  10114.         $objkey $this->encryptdata['key'].pack('VXxx'$n);
  10115.         if ($this->encryptdata['mode'] == 2) { // AES-128
  10116.             // AES padding
  10117.             $objkey .= "\x73\x41\x6C\x54"// sAlT
  10118.         }
  10119.         $objkey substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  10120.         $objkey substr($objkey016);
  10121.         return $objkey;
  10122.     }
  10123.     /**
  10124.      * Encrypt the input string.
  10125.      * @param int $n object number
  10126.      * @param string $s data string to encrypt
  10127.      * @return string encrypted string
  10128.      * @protected
  10129.      * @author Nicola Asuni
  10130.      * @since 5.0.005 (2010-05-11)
  10131.      */
  10132.     protected function _encrypt_data($n$s) {
  10133.         if (!$this->encrypted) {
  10134.             return $s;
  10135.         }
  10136.         switch ($this->encryptdata['mode']) {
  10137.             case 0:   // RC4-40
  10138.             case 1: { // RC4-128
  10139.                 $s TCPDF_STATIC::_RC4($this->_objectkey($n), $s$this->last_enc_key$this->last_enc_key_c);
  10140.                 break;
  10141.             }
  10142.             case 2: { // AES-128
  10143.                 $s TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10144.                 break;
  10145.             }
  10146.             case 3: { // AES-256
  10147.                 $s TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10148.                 break;
  10149.             }
  10150.         }
  10151.         return $s;
  10152.     }
  10153.     /**
  10154.      * Put encryption on PDF document.
  10155.      * @protected
  10156.      * @author Nicola Asuni
  10157.      * @since 2.0.000 (2008-01-02)
  10158.      */
  10159.     protected function _putencryption() {
  10160.         if (!$this->encrypted) {
  10161.             return;
  10162.         }
  10163.         $this->encryptdata['objid'] = $this->_newobj();
  10164.         $out '<<';
  10165.         if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10166.             $this->encryptdata['Filter'] = 'Standard';
  10167.         }
  10168.         $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10169.         if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10170.             $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10171.         }
  10172.         if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10173.             $this->encryptdata['V'] = 1;
  10174.         }
  10175.         // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10176.         $out .= ' /V '.$this->encryptdata['V'];
  10177.         if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10178.             // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10179.             $out .= ' /Length '.$this->encryptdata['Length'];
  10180.         } else {
  10181.             $out .= ' /Length 40';
  10182.         }
  10183.         if ($this->encryptdata['V'] >= 4) {
  10184.             if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10185.                 $this->encryptdata['StmF'] = 'Identity';
  10186.             }
  10187.             if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10188.                 // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10189.                 $this->encryptdata['StrF'] = 'Identity';
  10190.             }
  10191.             // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10192.             if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10193.                 $out .= ' /CF <<';
  10194.                 $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10195.                 $out .= ' /Type /CryptFilter';
  10196.                 if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10197.                     // The method used
  10198.                     $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10199.                     if ($this->encryptdata['pubkey']) {
  10200.                         $out .= ' /Recipients [';
  10201.                         foreach ($this->encryptdata['Recipients'] as $rec) {
  10202.                             $out .= ' <'.$rec.'>';
  10203.                         }
  10204.                         $out .= ' ]';
  10205.                         if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10206.                             $out .= ' /EncryptMetadata false';
  10207.                         } else {
  10208.                             $out .= ' /EncryptMetadata true';
  10209.                         }
  10210.                     }
  10211.                 } else {
  10212.                     $out .= ' /CFM /None';
  10213.                 }
  10214.                 if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10215.                     // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10216.                     $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10217.                 } else {
  10218.                     $out .= ' /AuthEvent /DocOpen';
  10219.                 }
  10220.                 if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10221.                     // The bit length of the encryption key.
  10222.                     $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10223.                 }
  10224.                 $out .= ' >> >>';
  10225.             }
  10226.             // The name of the crypt filter that shall be used by default when decrypting streams.
  10227.             $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10228.             // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10229.             $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10230.             if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10231.                 // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10232.                 $out .= ' /EFF /'.$this->encryptdata[''];
  10233.             }
  10234.         }
  10235.         // Additional encryption dictionary entries for the standard security handler
  10236.         if ($this->encryptdata['pubkey']) {
  10237.             if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10238.                 $out .= ' /Recipients [';
  10239.                 foreach ($this->encryptdata['Recipients'] as $rec) {
  10240.                     $out .= ' <'.$rec.'>';
  10241.                 }
  10242.                 $out .= ' ]';
  10243.             }
  10244.         } else {
  10245.             $out .= ' /R';
  10246.             if ($this->encryptdata['V'] == 5) { // AES-256
  10247.                 $out .= ' 5';
  10248.                 $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10249.                 $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10250.                 $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10251.             } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10252.                 $out .= ' 4';
  10253.             } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10254.                 $out .= ' 2';
  10255.             } else { // RC-128
  10256.                 $out .= ' 3';
  10257.             }
  10258.             $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10259.             $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10260.             $out .= ' /P '.$this->encryptdata['P'];
  10261.             if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10262.                 $out .= ' /EncryptMetadata false';
  10263.             } else {
  10264.                 $out .= ' /EncryptMetadata true';
  10265.             }
  10266.         }
  10267.         $out .= ' >>';
  10268.         $out .= "\n".'endobj';
  10269.         $this->_out($out);
  10270.     }
  10271.     /**
  10272.      * Compute U value (used for encryption)
  10273.      * @return string U value
  10274.      * @protected
  10275.      * @since 2.0.000 (2008-01-02)
  10276.      * @author Nicola Asuni
  10277.      */
  10278.     protected function _Uvalue() {
  10279.         if ($this->encryptdata['mode'] == 0) { // RC4-40
  10280.             return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding$this->last_enc_key$this->last_enc_key_c);
  10281.         } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10282.             $tmp TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10283.             $enc TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp$this->last_enc_key$this->last_enc_key_c);
  10284.             $len strlen($tmp);
  10285.             for ($i 1$i <= 19; ++$i) {
  10286.                 $ek '';
  10287.                 for ($j 0$j $len; ++$j) {
  10288.                     $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10289.                 }
  10290.                 $enc TCPDF_STATIC::_RC4($ek$enc$this->last_enc_key$this->last_enc_key_c);
  10291.             }
  10292.             $enc .= str_repeat("\x00"16);
  10293.             return substr($enc032);
  10294.         } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10295.             $seed TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10296.             // User Validation Salt
  10297.             $this->encryptdata['UVS'] = substr($seed08);
  10298.             // User Key Salt
  10299.             $this->encryptdata['UKS'] = substr($seed816);
  10300.             return hash('sha256'$this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10301.         }
  10302.     }
  10303.     /**
  10304.      * Compute UE value (used for encryption)
  10305.      * @return string UE value
  10306.      * @protected
  10307.      * @since 5.9.006 (2010-10-19)
  10308.      * @author Nicola Asuni
  10309.      */
  10310.     protected function _UEvalue() {
  10311.         $hashkey hash('sha256'$this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10312.         return TCPDF_STATIC::_AESnopad($hashkey$this->encryptdata['key']);
  10313.     }
  10314.     /**
  10315.      * Compute O value (used for encryption)
  10316.      * @return string O value
  10317.      * @protected
  10318.      * @since 2.0.000 (2008-01-02)
  10319.      * @author Nicola Asuni
  10320.      */
  10321.     protected function _Ovalue() {
  10322.         if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10323.             $tmp TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10324.             if ($this->encryptdata['mode'] > 0) {
  10325.                 for ($i 0$i 50; ++$i) {
  10326.                     $tmp TCPDF_STATIC::_md5_16($tmp);
  10327.                 }
  10328.             }
  10329.             $owner_key substr($tmp0, ($this->encryptdata['Length'] / 8));
  10330.             $enc TCPDF_STATIC::_RC4($owner_key$this->encryptdata['user_password'], $this->last_enc_key$this->last_enc_key_c);
  10331.             if ($this->encryptdata['mode'] > 0) {
  10332.                 $len strlen($owner_key);
  10333.                 for ($i 1$i <= 19; ++$i) {
  10334.                     $ek '';
  10335.                     for ($j 0$j $len; ++$j) {
  10336.                         $ek .= chr(ord($owner_key[$j]) ^ $i);
  10337.                     }
  10338.                     $enc TCPDF_STATIC::_RC4($ek$enc$this->last_enc_key$this->last_enc_key_c);
  10339.                 }
  10340.             }
  10341.             return $enc;
  10342.         } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10343.             $seed TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10344.             // Owner Validation Salt
  10345.             $this->encryptdata['OVS'] = substr($seed08);
  10346.             // Owner Key Salt
  10347.             $this->encryptdata['OKS'] = substr($seed816);
  10348.             return hash('sha256'$this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10349.         }
  10350.     }
  10351.     /**
  10352.      * Compute OE value (used for encryption)
  10353.      * @return string OE value
  10354.      * @protected
  10355.      * @since 5.9.006 (2010-10-19)
  10356.      * @author Nicola Asuni
  10357.      */
  10358.     protected function _OEvalue() {
  10359.         $hashkey hash('sha256'$this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10360.         return TCPDF_STATIC::_AESnopad($hashkey$this->encryptdata['key']);
  10361.     }
  10362.     /**
  10363.      * Convert password for AES-256 encryption mode
  10364.      * @param string $password password
  10365.      * @return string password
  10366.      * @protected
  10367.      * @since 5.9.006 (2010-10-19)
  10368.      * @author Nicola Asuni
  10369.      */
  10370.     protected function _fixAES256Password($password) {
  10371.         $psw ''// password to be returned
  10372.         $psw_array TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password$this->isunicode$this->CurrentFont), $password$this->rtl$this->isunicode$this->CurrentFont);
  10373.         foreach ($psw_array as $c) {
  10374.             $psw .= TCPDF_FONTS::unichr($c$this->isunicode);
  10375.         }
  10376.         return substr($psw0127);
  10377.     }
  10378.     /**
  10379.      * Compute encryption key
  10380.      * @protected
  10381.      * @since 2.0.000 (2008-01-02)
  10382.      * @author Nicola Asuni
  10383.      */
  10384.     protected function _generateencryptionkey() {
  10385.         $keybytelen = ($this->encryptdata['Length'] / 8);
  10386.         if (!$this->encryptdata['pubkey']) { // standard mode
  10387.             if ($this->encryptdata['mode'] == 3) { // AES-256
  10388.                 // generate 256 bit random key
  10389.                 $this->encryptdata['key'] = substr(hash('sha256'TCPDF_STATIC::getRandomSeed(), true), 0$keybytelen);
  10390.                 // truncate passwords
  10391.                 $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10392.                 $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10393.                 // Compute U value
  10394.                 $this->encryptdata['U'] = $this->_Uvalue();
  10395.                 // Compute UE value
  10396.                 $this->encryptdata['UE'] = $this->_UEvalue();
  10397.                 // Compute O value
  10398.                 $this->encryptdata['O'] = $this->_Ovalue();
  10399.                 // Compute OE value
  10400.                 $this->encryptdata['OE'] = $this->_OEvalue();
  10401.                 // Compute P value
  10402.                 $this->encryptdata['P'] = $this->encryptdata['protection'];
  10403.                 // Computing the encryption dictionary's Perms (permissions) value
  10404.                 $perms TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10405.                 $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10406.                 if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10407.                     $perms .= 'F';
  10408.                 } else {
  10409.                     $perms .= 'T';
  10410.                 }
  10411.                 $perms .= 'adb'// bytes 9-11
  10412.                 $perms .= 'nick'// bytes 12-15
  10413.                 $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
  10414.             } else { // RC4-40, RC4-128, AES-128
  10415.                 // Pad passwords
  10416.                 $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding032);
  10417.                 $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding032);
  10418.                 // Compute O value
  10419.                 $this->encryptdata['O'] = $this->_Ovalue();
  10420.                 // get default permissions (reverse byte order)
  10421.                 $permissions TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10422.                 // Compute encryption key
  10423.                 $tmp TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10424.                 if ($this->encryptdata['mode'] > 0) {
  10425.                     for ($i 0$i 50; ++$i) {
  10426.                         $tmp TCPDF_STATIC::_md5_16(substr($tmp0$keybytelen));
  10427.                     }
  10428.                 }
  10429.                 $this->encryptdata['key'] = substr($tmp0$keybytelen);
  10430.                 // Compute U value
  10431.                 $this->encryptdata['U'] = $this->_Uvalue();
  10432.                 // Compute P value
  10433.                 $this->encryptdata['P'] = $this->encryptdata['protection'];
  10434.             }
  10435.         } else { // Public-Key mode
  10436.             // random 20-byte seed
  10437.             $seed sha1(TCPDF_STATIC::getRandomSeed(), true);
  10438.             $recipient_bytes '';
  10439.             foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10440.                 // for each public certificate
  10441.                 if (isset($pubkey['p'])) {
  10442.                     $pkprotection TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10443.                 } else {
  10444.                     $pkprotection $this->encryptdata['protection'];
  10445.                 }
  10446.                 // get default permissions (reverse byte order)
  10447.                 $pkpermissions TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10448.                 // envelope data
  10449.                 $envelope $seed.$pkpermissions;
  10450.                 // write the envelope data to a temporary file
  10451.                 $tempkeyfile TCPDF_STATIC::getObjFilename('key'$this->file_id);
  10452.                 $f TCPDF_STATIC::fopenLocal($tempkeyfile'wb');
  10453.                 if (!$f) {
  10454.                     $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10455.                 }
  10456.                 $envelope_length strlen($envelope);
  10457.                 fwrite($f$envelope$envelope_length);
  10458.                 fclose($f);
  10459.                 $tempencfile TCPDF_STATIC::getObjFilename('enc'$this->file_id);
  10460.                 if (!openssl_pkcs7_encrypt($tempkeyfile$tempencfile$pubkey['c'], array(), PKCS7_BINARY PKCS7_DETACHED)) {
  10461.                     $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10462.                 }
  10463.                 // read encryption signature
  10464.                 $signature file_get_contents($tempencfilefalsenull$envelope_length);
  10465.                 // extract signature
  10466.                 $signature substr($signaturestrpos($signature'Content-Disposition'));
  10467.                 $tmparr explode("\n\n"$signature);
  10468.                 $signature trim($tmparr[1]);
  10469.                 unset($tmparr);
  10470.                 // decode signature
  10471.                 $signature base64_decode($signature);
  10472.                 // convert signature to hex
  10473.                 $hexsignature current(unpack('H*'$signature));
  10474.                 // store signature on recipients array
  10475.                 $this->encryptdata['Recipients'][] = $hexsignature;
  10476.                 // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10477.                 $recipient_bytes .= $signature;
  10478.             }
  10479.             // calculate encryption key
  10480.             if ($this->encryptdata['mode'] == 3) { // AES-256
  10481.                 $this->encryptdata['key'] = substr(hash('sha256'$seed.$recipient_bytestrue), 0$keybytelen);
  10482.             } else { // RC4-40, RC4-128, AES-128
  10483.                 $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytestrue), 0$keybytelen);
  10484.             }
  10485.         }
  10486.     }
  10487.     /**
  10488.      * Set document protection
  10489.      * Remark: the protection against modification is for people who have the full Acrobat product.
  10490.      * 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.
  10491.      * 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.
  10492.      * @param array $permissions the set of permissions (specify the ones you want to block):<ul><li>print : Print the document;</li><li>modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';</li><li>copy : Copy or otherwise extract text and graphics from the document;</li><li>annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);</li><li>fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;</li><li>extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);</li><li>assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;</li><li>print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.</li><li>owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.</li></ul>
  10493.      * @param string $user_pass user password. Empty by default.
  10494.      * @param string|null $owner_pass owner password. If not specified, a random value is used.
  10495.      * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10496.      * @param array|null $pubkeys array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
  10497.      * @public
  10498.      * @since 2.0.000 (2008-01-02)
  10499.      * @author Nicola Asuni
  10500.      */
  10501.     public function setProtection($permissions=array('print''modify''copy''annot-forms''fill-forms''extract''assemble''print-high'), $user_pass=''$owner_pass=null$mode=0$pubkeys=null) {
  10502.         if ($this->pdfa_mode) {
  10503.             // encryption is not allowed in PDF/A mode
  10504.             return;
  10505.         }
  10506.         $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions$mode);
  10507.         if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10508.             // public-key mode
  10509.             $this->encryptdata['pubkeys'] = $pubkeys;
  10510.             if ($mode == 0) {
  10511.                 // public-Key Security requires at least 128 bit
  10512.                 $mode 1;
  10513.             }
  10514.             if (!function_exists('openssl_pkcs7_encrypt')) {
  10515.                 $this->Error('Public-Key Security requires openssl library.');
  10516.             }
  10517.             // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10518.             $this->encryptdata['pubkey'] = true;
  10519.             $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10520.             $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10521.             $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10522.         } else {
  10523.             // standard mode (password mode)
  10524.             $this->encryptdata['pubkey'] = false;
  10525.             $this->encryptdata['Filter'] = 'Standard';
  10526.             $this->encryptdata['StmF'] = 'StdCF';
  10527.             $this->encryptdata['StrF'] = 'StdCF';
  10528.         }
  10529.         if ($mode 1) { // AES
  10530.             if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
  10531.                 $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10532.             }
  10533.             if (extension_loaded('openssl') && !in_array('aes-256-cbc'openssl_get_cipher_methods())) {
  10534.                 $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
  10535.             }
  10536.             if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10537.                 $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10538.             }
  10539.             if (($mode == 3) AND !function_exists('hash')) {
  10540.                 // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10541.                 $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10542.             }
  10543.         }
  10544.         if ($owner_pass === null) {
  10545.             $owner_pass md5(TCPDF_STATIC::getRandomSeed());
  10546.         }
  10547.         $this->encryptdata['user_password'] = $user_pass;
  10548.         $this->encryptdata['owner_password'] = $owner_pass;
  10549.         $this->encryptdata['mode'] = $mode;
  10550.         switch ($mode) {
  10551.             case 0: { // RC4 40 bit
  10552.                 $this->encryptdata['V'] = 1;
  10553.                 $this->encryptdata['Length'] = 40;
  10554.                 $this->encryptdata['CF']['CFM'] = 'V2';
  10555.                 break;
  10556.             }
  10557.             case 1: { // RC4 128 bit
  10558.                 $this->encryptdata['V'] = 2;
  10559.                 $this->encryptdata['Length'] = 128;
  10560.                 $this->encryptdata['CF']['CFM'] = 'V2';
  10561.                 if ($this->encryptdata['pubkey']) {
  10562.                     $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10563.                     $this->encryptdata['Recipients'] = array();
  10564.                 }
  10565.                 break;
  10566.             }
  10567.             case 2: { // AES 128 bit
  10568.                 $this->encryptdata['V'] = 4;
  10569.                 $this->encryptdata['Length'] = 128;
  10570.                 $this->encryptdata['CF']['CFM'] = 'AESV2';
  10571.                 $this->encryptdata['CF']['Length'] = 128;
  10572.                 if ($this->encryptdata['pubkey']) {
  10573.                     $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10574.                     $this->encryptdata['Recipients'] = array();
  10575.                 }
  10576.                 break;
  10577.             }
  10578.             case 3: { // AES 256 bit
  10579.                 $this->encryptdata['V'] = 5;
  10580.                 $this->encryptdata['Length'] = 256;
  10581.                 $this->encryptdata['CF']['CFM'] = 'AESV3';
  10582.                 $this->encryptdata['CF']['Length'] = 256;
  10583.                 if ($this->encryptdata['pubkey']) {
  10584.                     $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10585.                     $this->encryptdata['Recipients'] = array();
  10586.                 }
  10587.                 break;
  10588.             }
  10589.         }
  10590.         $this->encrypted true;
  10591.         $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10592.         $this->_generateencryptionkey();
  10593.     }
  10594.     // END OF ENCRYPTION FUNCTIONS -------------------------
  10595.     // START TRANSFORMATIONS SECTION -----------------------
  10596.     /**
  10597.      * Starts a 2D tranformation saving current graphic state.
  10598.      * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10599.      * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10600.      * @public
  10601.      * @since 2.1.000 (2008-01-07)
  10602.      * @see StartTransform(), StopTransform()
  10603.      */
  10604.     public function StartTransform() {
  10605.         if ($this->state != 2) {
  10606.             return;
  10607.         }
  10608.         $this->_outSaveGraphicsState();
  10609.         if ($this->inxobj) {
  10610.             // we are inside an XObject template
  10611.             $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10612.         } else {
  10613.             $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10614.         }
  10615.         ++$this->transfmatrix_key;
  10616.         $this->transfmatrix[$this->transfmatrix_key] = array();
  10617.     }
  10618.     /**
  10619.      * Stops a 2D tranformation restoring previous graphic state.
  10620.      * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10621.      * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10622.      * @public
  10623.      * @since 2.1.000 (2008-01-07)
  10624.      * @see StartTransform(), StopTransform()
  10625.      */
  10626.     public function StopTransform() {
  10627.         if ($this->state != 2) {
  10628.             return;
  10629.         }
  10630.         $this->_outRestoreGraphicsState();
  10631.         if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10632.             array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10633.             --$this->transfmatrix_key;
  10634.         }
  10635.         if ($this->inxobj) {
  10636.             // we are inside an XObject template
  10637.             array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10638.         } else {
  10639.             array_pop($this->transfmrk[$this->page]);
  10640.         }
  10641.     }
  10642.     /**
  10643.      * Horizontal Scaling.
  10644.      * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  10645.      * @param int $x abscissa of the scaling center. Default is current x position
  10646.      * @param int $y ordinate of the scaling center. Default is current y position
  10647.      * @public
  10648.      * @since 2.1.000 (2008-01-07)
  10649.      * @see StartTransform(), StopTransform()
  10650.      */
  10651.     public function ScaleX($s_x$x=''$y='') {
  10652.         $this->Scale($s_x100$x$y);
  10653.     }
  10654.     /**
  10655.      * Vertical Scaling.
  10656.      * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  10657.      * @param int $x abscissa of the scaling center. Default is current x position
  10658.      * @param int $y ordinate of the scaling center. Default is current y position
  10659.      * @public
  10660.      * @since 2.1.000 (2008-01-07)
  10661.      * @see StartTransform(), StopTransform()
  10662.      */
  10663.     public function ScaleY($s_y$x=''$y='') {
  10664.         $this->Scale(100$s_y$x$y);
  10665.     }
  10666.     /**
  10667.      * Vertical and horizontal proportional Scaling.
  10668.      * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  10669.      * @param int $x abscissa of the scaling center. Default is current x position
  10670.      * @param int $y ordinate of the scaling center. Default is current y position
  10671.      * @public
  10672.      * @since 2.1.000 (2008-01-07)
  10673.      * @see StartTransform(), StopTransform()
  10674.      */
  10675.     public function ScaleXY($s$x=''$y='') {
  10676.         $this->Scale($s$s$x$y);
  10677.     }
  10678.     /**
  10679.      * Vertical and horizontal non-proportional Scaling.
  10680.      * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  10681.      * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  10682.      * @param float|null $x abscissa of the scaling center. Default is current x position
  10683.      * @param float|null $y ordinate of the scaling center. Default is current y position
  10684.      * @public
  10685.      * @since 2.1.000 (2008-01-07)
  10686.      * @see StartTransform(), StopTransform()
  10687.      */
  10688.     public function Scale($s_x$s_y$x=null$y=null) {
  10689.         if (TCPDF_STATIC::empty_string($x)) {
  10690.             $x $this->x;
  10691.         }
  10692.         if (TCPDF_STATIC::empty_string($y)) {
  10693.             $y $this->y;
  10694.         }
  10695.         if (($s_x == 0) OR ($s_y == 0)) {
  10696.             $this->Error('Please do not use values equal to zero for scaling');
  10697.         }
  10698.         $y = ($this->$y) * $this->k;
  10699.         $x *= $this->k;
  10700.         //calculate elements of transformation matrix
  10701.         $s_x /= 100;
  10702.         $s_y /= 100;
  10703.         $tm = array();
  10704.         $tm[0] = $s_x;
  10705.         $tm[1] = 0;
  10706.         $tm[2] = 0;
  10707.         $tm[3] = $s_y;
  10708.         $tm[4] = $x * ($s_x);
  10709.         $tm[5] = $y * ($s_y);
  10710.         //scale the coordinate system
  10711.         $this->Transform($tm);
  10712.     }
  10713.     /**
  10714.      * Horizontal Mirroring.
  10715.      * @param float|null $x abscissa of the point. Default is current x position
  10716.      * @public
  10717.      * @since 2.1.000 (2008-01-07)
  10718.      * @see StartTransform(), StopTransform()
  10719.      */
  10720.     public function MirrorH($x=null) {
  10721.         $this->Scale(-100100$x);
  10722.     }
  10723.     /**
  10724.      * Verical Mirroring.
  10725.      * @param float|null $y ordinate of the point. Default is current y position
  10726.      * @public
  10727.      * @since 2.1.000 (2008-01-07)
  10728.      * @see StartTransform(), StopTransform()
  10729.      */
  10730.     public function MirrorV($y=null) {
  10731.         $this->Scale(100, -100null$y);
  10732.     }
  10733.     /**
  10734.      * Point reflection mirroring.
  10735.      * @param float|null $x abscissa of the point. Default is current x position
  10736.      * @param float|null $y ordinate of the point. Default is current y position
  10737.      * @public
  10738.      * @since 2.1.000 (2008-01-07)
  10739.      * @see StartTransform(), StopTransform()
  10740.      */
  10741.     public function MirrorP($x=null,$y=null) {
  10742.         $this->Scale(-100, -100$x$y);
  10743.     }
  10744.     /**
  10745.      * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10746.      * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  10747.      * @param float|null $x abscissa of the point. Default is current x position
  10748.      * @param float|null $y ordinate of the point. Default is current y position
  10749.      * @public
  10750.      * @since 2.1.000 (2008-01-07)
  10751.      * @see StartTransform(), StopTransform()
  10752.      */
  10753.     public function MirrorL($angle=0$x=null,$y=null) {
  10754.         $this->Scale(-100100$x$y);
  10755.         $this->Rotate(-2*($angle-90), $x$y);
  10756.     }
  10757.     /**
  10758.      * Translate graphic object horizontally.
  10759.      * @param int $t_x movement to the right (or left for RTL)
  10760.      * @public
  10761.      * @since 2.1.000 (2008-01-07)
  10762.      * @see StartTransform(), StopTransform()
  10763.      */
  10764.     public function TranslateX($t_x) {
  10765.         $this->Translate($t_x0);
  10766.     }
  10767.     /**
  10768.      * Translate graphic object vertically.
  10769.      * @param int $t_y movement to the bottom
  10770.      * @public
  10771.      * @since 2.1.000 (2008-01-07)
  10772.      * @see StartTransform(), StopTransform()
  10773.      */
  10774.     public function TranslateY($t_y) {
  10775.         $this->Translate(0$t_y);
  10776.     }
  10777.     /**
  10778.      * Translate graphic object horizontally and vertically.
  10779.      * @param int $t_x movement to the right
  10780.      * @param int $t_y movement to the bottom
  10781.      * @public
  10782.      * @since 2.1.000 (2008-01-07)
  10783.      * @see StartTransform(), StopTransform()
  10784.      */
  10785.     public function Translate($t_x$t_y) {
  10786.         //calculate elements of transformation matrix
  10787.         $tm = array();
  10788.         $tm[0] = 1;
  10789.         $tm[1] = 0;
  10790.         $tm[2] = 0;
  10791.         $tm[3] = 1;
  10792.         $tm[4] = $t_x $this->k;
  10793.         $tm[5] = -$t_y $this->k;
  10794.         //translate the coordinate system
  10795.         $this->Transform($tm);
  10796.     }
  10797.     /**
  10798.      * Rotate object.
  10799.      * @param float $angle angle in degrees for counter-clockwise rotation
  10800.      * @param float|null $x abscissa of the rotation center. Default is current x position
  10801.      * @param float|null $y ordinate of the rotation center. Default is current y position
  10802.      * @public
  10803.      * @since 2.1.000 (2008-01-07)
  10804.      * @see StartTransform(), StopTransform()
  10805.      */
  10806.     public function Rotate($angle$x=null$y=null) {
  10807.         if (TCPDF_STATIC::empty_string($x)) {
  10808.             $x $this->x;
  10809.         }
  10810.         if (TCPDF_STATIC::empty_string($y)) {
  10811.             $y $this->y;
  10812.         }
  10813.         $y = ($this->$y) * $this->k;
  10814.         $x *= $this->k;
  10815.         //calculate elements of transformation matrix
  10816.         $tm = array();
  10817.         $tm[0] = cos(deg2rad($angle));
  10818.         $tm[1] = sin(deg2rad($angle));
  10819.         $tm[2] = -$tm[1];
  10820.         $tm[3] = $tm[0];
  10821.         $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10822.         $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10823.         //rotate the coordinate system around ($x,$y)
  10824.         $this->Transform($tm);
  10825.     }
  10826.     /**
  10827.      * Skew horizontally.
  10828.      * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10829.      * @param float|null $x abscissa of the skewing center. default is current x position
  10830.      * @param float|null $y ordinate of the skewing center. default is current y position
  10831.      * @public
  10832.      * @since 2.1.000 (2008-01-07)
  10833.      * @see StartTransform(), StopTransform()
  10834.      */
  10835.     public function SkewX($angle_x$x=null$y=null) {
  10836.         $this->Skew($angle_x0$x$y);
  10837.     }
  10838.     /**
  10839.      * Skew vertically.
  10840.      * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10841.      * @param float|null $x abscissa of the skewing center. default is current x position
  10842.      * @param float|null $y ordinate of the skewing center. default is current y position
  10843.      * @public
  10844.      * @since 2.1.000 (2008-01-07)
  10845.      * @see StartTransform(), StopTransform()
  10846.      */
  10847.     public function SkewY($angle_y$x=null$y=null) {
  10848.         $this->Skew(0$angle_y$x$y);
  10849.     }
  10850.     /**
  10851.      * Skew.
  10852.      * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10853.      * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10854.      * @param float|null $x abscissa of the skewing center. default is current x position
  10855.      * @param float|null $y ordinate of the skewing center. default is current y position
  10856.      * @public
  10857.      * @since 2.1.000 (2008-01-07)
  10858.      * @see StartTransform(), StopTransform()
  10859.      */
  10860.     public function Skew($angle_x$angle_y$x=null$y=null) {
  10861.         if (TCPDF_STATIC::empty_string($x)) {
  10862.             $x $this->x;
  10863.         }
  10864.         if (TCPDF_STATIC::empty_string($y)) {
  10865.             $y $this->y;
  10866.         }
  10867.         if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  10868.             $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  10869.         }
  10870.         $x *= $this->k;
  10871.         $y = ($this->$y) * $this->k;
  10872.         //calculate elements of transformation matrix
  10873.         $tm = array();
  10874.         $tm[0] = 1;
  10875.         $tm[1] = tan(deg2rad($angle_y));
  10876.         $tm[2] = tan(deg2rad($angle_x));
  10877.         $tm[3] = 1;
  10878.         $tm[4] = -$tm[2] * $y;
  10879.         $tm[5] = -$tm[1] * $x;
  10880.         //skew the coordinate system
  10881.         $this->Transform($tm);
  10882.     }
  10883.     /**
  10884.      * Apply graphic transformations.
  10885.      * @param array $tm transformation matrix
  10886.      * @protected
  10887.      * @since 2.1.000 (2008-01-07)
  10888.      * @see StartTransform(), StopTransform()
  10889.      */
  10890.     protected function Transform($tm) {
  10891.         if ($this->state != 2) {
  10892.             return;
  10893.         }
  10894.         $this->_out(sprintf('%F %F %F %F %F %F cm'$tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  10895.         // add tranformation matrix
  10896.         $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  10897.         // update transformation mark
  10898.         if ($this->inxobj) {
  10899.             // we are inside an XObject template
  10900.             if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  10901.                 $key key($this->xobjects[$this->xobjid]['transfmrk']);
  10902.                 $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10903.             }
  10904.         } elseif (end($this->transfmrk[$this->page]) !== false) {
  10905.             $key key($this->transfmrk[$this->page]);
  10906.             $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  10907.         }
  10908.     }
  10909.     // END TRANSFORMATIONS SECTION -------------------------
  10910.     // START GRAPHIC FUNCTIONS SECTION ---------------------
  10911.     // The following section is based on the code provided by David Hernandez Sanz
  10912.     /**
  10913.      * 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.
  10914.      * @param float $width The width.
  10915.      * @public
  10916.      * @since 1.0
  10917.      * @see Line(), Rect(), Cell(), MultiCell()
  10918.      */
  10919.     public function setLineWidth($width) {
  10920.         //Set line width
  10921.         $this->LineWidth $width;
  10922.         $this->linestyleWidth sprintf('%F w', ($width $this->k));
  10923.         if ($this->state == 2) {
  10924.             $this->_out($this->linestyleWidth);
  10925.         }
  10926.     }
  10927.     /**
  10928.      * Returns the current the line width.
  10929.      * @return int Line width
  10930.      * @public
  10931.      * @since 2.1.000 (2008-01-07)
  10932.      * @see Line(), SetLineWidth()
  10933.      */
  10934.     public function GetLineWidth() {
  10935.         return $this->LineWidth;
  10936.     }
  10937.     /**
  10938.      * Set line style.
  10939.      * @param array $style Line style. Array with keys among the following:
  10940.      * <ul>
  10941.      *     <li>width (float): Width of the line in user units.</li>
  10942.      *     <li>cap (string): Type of cap to put on the line. Possible values are:
  10943.      * butt, round, square. The difference between "square" and "butt" is that
  10944.      * "square" projects a flat end past the end of the line.</li>
  10945.      *     <li>join (string): Type of join. Possible values are: miter, round,
  10946.      * bevel.</li>
  10947.      *     <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  10948.      * series of length values, which are the lengths of the on and off dashes.
  10949.      * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  10950.      * 1 off, 2 on, 1 off, ...</li>
  10951.      *     <li>phase (integer): Modifier on the dash pattern which is used to shift
  10952.      * the point at which the pattern starts.</li>
  10953.      *     <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName).</li>
  10954.      * </ul>
  10955.      * @param boolean $ret if true do not send the command.
  10956.      * @return string the PDF command
  10957.      * @public
  10958.      * @since 2.1.000 (2008-01-08)
  10959.      */
  10960.     public function setLineStyle($style$ret=false) {
  10961.         $s ''// string to be returned
  10962.         if (!is_array($style)) {
  10963.             return $s;
  10964.         }
  10965.         if (isset($style['width'])) {
  10966.             $this->LineWidth $style['width'];
  10967.             $this->linestyleWidth sprintf('%F w', ($style['width'] * $this->k));
  10968.             $s .= $this->linestyleWidth.' ';
  10969.         }
  10970.         if (isset($style['cap'])) {
  10971.             $ca = array('butt' => 0'round'=> 1'square' => 2);
  10972.             if (isset($ca[$style['cap']])) {
  10973.                 $this->linestyleCap $ca[$style['cap']].' J';
  10974.                 $s .= $this->linestyleCap.' ';
  10975.             }
  10976.         }
  10977.         if (isset($style['join'])) {
  10978.             $ja = array('miter' => 0'round' => 1'bevel' => 2);
  10979.             if (isset($ja[$style['join']])) {
  10980.                 $this->linestyleJoin $ja[$style['join']].' j';
  10981.                 $s .= $this->linestyleJoin.' ';
  10982.             }
  10983.         }
  10984.         if (isset($style['dash'])) {
  10985.             $dash_string '';
  10986.             if ($style['dash']) {
  10987.                 if (preg_match('/^.+,/'$style['dash']) > 0) {
  10988.                     $tab explode(','$style['dash']);
  10989.                 } else {
  10990.                     $tab = array($style['dash']);
  10991.                 }
  10992.                 $dash_string '';
  10993.                 foreach ($tab as $i => $v) {
  10994.                     if ($i) {
  10995.                         $dash_string .= ' ';
  10996.                     }
  10997.                     $dash_string .= sprintf('%F'$v);
  10998.                 }
  10999.             }
  11000.             if (!isset($style['phase']) OR !$style['dash']) {
  11001.                 $style['phase'] = 0;
  11002.             }
  11003.             $this->linestyleDash sprintf('[%s] %F d'$dash_string$style['phase']);
  11004.             $s .= $this->linestyleDash.' ';
  11005.         }
  11006.         if (isset($style['color'])) {
  11007.             $s .= $this->setDrawColorArray($style['color'], true).' ';
  11008.         }
  11009.         if (!$ret AND ($this->state == 2)) {
  11010.             $this->_out($s);
  11011.         }
  11012.         return $s;
  11013.     }
  11014.     /**
  11015.      * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  11016.      * @param float $x Abscissa of point.
  11017.      * @param float $y Ordinate of point.
  11018.      * @protected
  11019.      * @since 2.1.000 (2008-01-08)
  11020.      */
  11021.     protected function _outPoint($x$y) {
  11022.         if ($this->state == 2) {
  11023.             $this->_out(sprintf('%F %F m', ($x $this->k), (($this->$y) * $this->k)));
  11024.         }
  11025.     }
  11026.     /**
  11027.      * Append a straight line segment from the current point to the point (x, y).
  11028.      * The new current point shall be (x, y).
  11029.      * @param float $x Abscissa of end point.
  11030.      * @param float $y Ordinate of end point.
  11031.      * @protected
  11032.      * @since 2.1.000 (2008-01-08)
  11033.      */
  11034.     protected function _outLine($x$y) {
  11035.         if ($this->state == 2) {
  11036.             $this->_out(sprintf('%F %F l', ($x $this->k), (($this->$y) * $this->k)));
  11037.         }
  11038.     }
  11039.     /**
  11040.      * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  11041.      * @param float $x Abscissa of upper-left corner.
  11042.      * @param float $y Ordinate of upper-left corner.
  11043.      * @param float $w Width.
  11044.      * @param float $h Height.
  11045.      * @param string $op options
  11046.      * @protected
  11047.      * @since 2.1.000 (2008-01-08)
  11048.      */
  11049.     protected function _outRect($x$y$w$h$op) {
  11050.         if ($this->state == 2) {
  11051.             $this->_out(sprintf('%F %F %F %F re %s', ($x $this->k), (($this->$y) * $this->k), ($w $this->k), (-$h $this->k), $op));
  11052.         }
  11053.     }
  11054.     /**
  11055.      * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x2, y2) as the Bezier control points.
  11056.      * The new current point shall be (x3, y3).
  11057.      * @param float $x1 Abscissa of control point 1.
  11058.      * @param float $y1 Ordinate of control point 1.
  11059.      * @param float $x2 Abscissa of control point 2.
  11060.      * @param float $y2 Ordinate of control point 2.
  11061.      * @param float $x3 Abscissa of end point.
  11062.      * @param float $y3 Ordinate of end point.
  11063.      * @protected
  11064.      * @since 2.1.000 (2008-01-08)
  11065.      */
  11066.     protected function _outCurve($x1$y1$x2$y2$x3$y3) {
  11067.         if ($this->state == 2) {
  11068.             $this->_out(sprintf('%F %F %F %F %F %F c', ($x1 $this->k), (($this->$y1) * $this->k), ($x2 $this->k), (($this->$y2) * $this->k), ($x3 $this->k), (($this->$y3) * $this->k)));
  11069.         }
  11070.     }
  11071.     /**
  11072.      * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bezier control points.
  11073.      * The new current point shall be (x3, y3).
  11074.      * @param float $x2 Abscissa of control point 2.
  11075.      * @param float $y2 Ordinate of control point 2.
  11076.      * @param float $x3 Abscissa of end point.
  11077.      * @param float $y3 Ordinate of end point.
  11078.      * @protected
  11079.      * @since 4.9.019 (2010-04-26)
  11080.      */
  11081.     protected function _outCurveV($x2$y2$x3$y3) {
  11082.         if ($this->state == 2) {
  11083.             $this->_out(sprintf('%F %F %F %F v', ($x2 $this->k), (($this->$y2) * $this->k), ($x3 $this->k), (($this->$y3) * $this->k)));
  11084.         }
  11085.     }
  11086.     /**
  11087.      * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bezier control points.
  11088.      * The new current point shall be (x3, y3).
  11089.      * @param float $x1 Abscissa of control point 1.
  11090.      * @param float $y1 Ordinate of control point 1.
  11091.      * @param float $x3 Abscissa of end point.
  11092.      * @param float $y3 Ordinate of end point.
  11093.      * @protected
  11094.      * @since 2.1.000 (2008-01-08)
  11095.      */
  11096.     protected function _outCurveY($x1$y1$x3$y3) {
  11097.         if ($this->state == 2) {
  11098.             $this->_out(sprintf('%F %F %F %F y', ($x1 $this->k), (($this->$y1) * $this->k), ($x3 $this->k), (($this->$y3) * $this->k)));
  11099.         }
  11100.     }
  11101.     /**
  11102.      * Draws a line between two points.
  11103.      * @param float $x1 Abscissa of first point.
  11104.      * @param float $y1 Ordinate of first point.
  11105.      * @param float $x2 Abscissa of second point.
  11106.      * @param float $y2 Ordinate of second point.
  11107.      * @param array $style Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  11108.      * @public
  11109.      * @since 1.0
  11110.      * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  11111.      */
  11112.     public function Line($x1$y1$x2$y2$style=array()) {
  11113.         if ($this->state != 2) {
  11114.             return;
  11115.         }
  11116.         if (is_array($style)) {
  11117.             $this->setLineStyle($style);
  11118.         }
  11119.         $this->_outPoint($x1$y1);
  11120.         $this->_outLine($x2$y2);
  11121.         $this->_out('S');
  11122.     }
  11123.     /**
  11124.      * Draws a rectangle.
  11125.      * @param float $x Abscissa of upper-left corner.
  11126.      * @param float $y Ordinate of upper-left corner.
  11127.      * @param float $w Width.
  11128.      * @param float $h Height.
  11129.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11130.      * @param array $border_style Border style of rectangle. Array with keys among the following:
  11131.      * <ul>
  11132.      *     <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11133.      *     <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11134.      * </ul>
  11135.      * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11136.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11137.      * @public
  11138.      * @since 1.0
  11139.      * @see SetLineStyle()
  11140.      */
  11141.     public function Rect($x$y$w$h$style=''$border_style=array(), $fill_color=array()) {
  11142.         if ($this->state != 2) {
  11143.             return;
  11144.         }
  11145.         if (empty($style)) {
  11146.             $style 'S';
  11147.         }
  11148.         if (!(strpos($style'F') === false) AND !empty($fill_color)) {
  11149.             // set background color
  11150.             $this->setFillColorArray($fill_color);
  11151.         }
  11152.         if (!empty($border_style)) {
  11153.             if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11154.                 //set global style for border
  11155.                 $this->setLineStyle($border_style['all']);
  11156.                 $border_style = array();
  11157.             } else {
  11158.                 // remove stroke operator from style
  11159.                 $opnostroke = array('S' => '''D' => '''s' => '''d' => '''B' => 'F''FD' => 'F''DF' => 'F''B*' => 'F*''F*D' => 'F*''DF*' => 'F*''b' => 'f''fd' => 'f''df' => 'f''b*' => 'f*''f*d' => 'f*''df*' => 'f*' );
  11160.                 if (isset($opnostroke[$style])) {
  11161.                     $style $opnostroke[$style];
  11162.                 }
  11163.             }
  11164.         }
  11165.         if (!empty($style)) {
  11166.             $op TCPDF_STATIC::getPathPaintOperator($style);
  11167.             $this->_outRect($x$y$w$h$op);
  11168.         }
  11169.         if (!empty($border_style)) {
  11170.             $border_style2 = array();
  11171.             foreach ($border_style as $line => $value) {
  11172.                 $length strlen($line);
  11173.                 for ($i 0$i $length; ++$i) {
  11174.                     $border_style2[$line[$i]] = $value;
  11175.                 }
  11176.             }
  11177.             $border_style $border_style2;
  11178.             if (isset($border_style['L']) AND $border_style['L']) {
  11179.                 $this->Line($x$y$x$y $h$border_style['L']);
  11180.             }
  11181.             if (isset($border_style['T']) AND $border_style['T']) {
  11182.                 $this->Line($x$y$x $w$y$border_style['T']);
  11183.             }
  11184.             if (isset($border_style['R']) AND $border_style['R']) {
  11185.                 $this->Line($x $w$y$x $w$y $h$border_style['R']);
  11186.             }
  11187.             if (isset($border_style['B']) AND $border_style['B']) {
  11188.                 $this->Line($x$y $h$x $w$y $h$border_style['B']);
  11189.             }
  11190.         }
  11191.     }
  11192.     /**
  11193.      * Draws a Bezier curve.
  11194.      * The Bezier curve is a tangent to the line between the control points at
  11195.      * either end of the curve.
  11196.      * @param float $x0 Abscissa of start point.
  11197.      * @param float $y0 Ordinate of start point.
  11198.      * @param float $x1 Abscissa of control point 1.
  11199.      * @param float $y1 Ordinate of control point 1.
  11200.      * @param float $x2 Abscissa of control point 2.
  11201.      * @param float $y2 Ordinate of control point 2.
  11202.      * @param float $x3 Abscissa of end point.
  11203.      * @param float $y3 Ordinate of end point.
  11204.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11205.      * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11206.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11207.      * @public
  11208.      * @see SetLineStyle()
  11209.      * @since 2.1.000 (2008-01-08)
  11210.      */
  11211.     public function Curve($x0$y0$x1$y1$x2$y2$x3$y3$style=''$line_style=array(), $fill_color=array()) {
  11212.         if ($this->state != 2) {
  11213.             return;
  11214.         }
  11215.         if (!(false === strpos($style'F')) AND is_array($fill_color)) {
  11216.             $this->setFillColorArray($fill_color);
  11217.         }
  11218.         $op TCPDF_STATIC::getPathPaintOperator($style);
  11219.         if ($line_style) {
  11220.             $this->setLineStyle($line_style);
  11221.         }
  11222.         $this->_outPoint($x0$y0);
  11223.         $this->_outCurve($x1$y1$x2$y2$x3$y3);
  11224.         $this->_out($op);
  11225.     }
  11226.     /**
  11227.      * Draws a poly-Bezier curve.
  11228.      * Each Bezier curve segment is a tangent to the line between the control points at
  11229.      * either end of the curve.
  11230.      * @param float $x0 Abscissa of start point.
  11231.      * @param float $y0 Ordinate of start point.
  11232.      * @param float[] $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11233.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11234.      * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11235.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11236.      * @public
  11237.      * @see SetLineStyle()
  11238.      * @since 3.0008 (2008-05-12)
  11239.      */
  11240.     public function Polycurve($x0$y0$segments$style=''$line_style=array(), $fill_color=array()) {
  11241.         if ($this->state != 2) {
  11242.             return;
  11243.         }
  11244.         if (!(false === strpos($style'F')) AND is_array($fill_color)) {
  11245.             $this->setFillColorArray($fill_color);
  11246.         }
  11247.         $op TCPDF_STATIC::getPathPaintOperator($style);
  11248.         if ($op == 'f') {
  11249.             $line_style = array();
  11250.         }
  11251.         if ($line_style) {
  11252.             $this->setLineStyle($line_style);
  11253.         }
  11254.         $this->_outPoint($x0$y0);
  11255.         foreach ($segments as $segment) {
  11256.             list($x1$y1$x2$y2$x3$y3) = $segment;
  11257.             $this->_outCurve($x1$y1$x2$y2$x3$y3);
  11258.         }
  11259.         $this->_out($op);
  11260.     }
  11261.     /**
  11262.      * Draws an ellipse.
  11263.      * An ellipse is formed from n Bezier curves.
  11264.      * @param float $x0 Abscissa of center point.
  11265.      * @param float $y0 Ordinate of center point.
  11266.      * @param float $rx Horizontal radius.
  11267.      * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11268.      * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11269.      * @param float $astart Angle start of draw line. Default value: 0.
  11270.      * @param float $afinish Angle finish of draw line. Default value: 360.
  11271.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11272.      * @param array $line_style Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11273.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11274.      * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  11275.      * @author Nicola Asuni
  11276.      * @public
  11277.      * @since 2.1.000 (2008-01-08)
  11278.      */
  11279.     public function Ellipse($x0$y0$rx$ry=0$angle=0$astart=0$afinish=360$style=''$line_style=array(), $fill_color=array(), $nc=2) {
  11280.         if ($this->state != 2) {
  11281.             return;
  11282.         }
  11283.         if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11284.             $ry $rx;
  11285.         }
  11286.         if (!(false === strpos($style'F')) AND is_array($fill_color)) {
  11287.             $this->setFillColorArray($fill_color);
  11288.         }
  11289.         $op TCPDF_STATIC::getPathPaintOperator($style);
  11290.         if ($op == 'f') {
  11291.             $line_style = array();
  11292.         }
  11293.         if ($line_style) {
  11294.             $this->setLineStyle($line_style);
  11295.         }
  11296.         $this->_outellipticalarc($x0$y0$rx$ry$angle$astart$afinishfalse$nctruetruefalse);
  11297.         $this->_out($op);
  11298.     }
  11299.     /**
  11300.      * Append an elliptical arc to the current path.
  11301.      * An ellipse is formed from n Bezier curves.
  11302.      * @param float $xc Abscissa of center point.
  11303.      * @param float $yc Ordinate of center point.
  11304.      * @param float $rx Horizontal radius.
  11305.      * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11306.      * @param float $xang Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11307.      * @param float $angs Angle start of draw line. Default value: 0.
  11308.      * @param float $angf Angle finish of draw line. Default value: 360.
  11309.      * @param boolean $pie if true do not mark the border point (used to draw pie sectors).
  11310.      * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  11311.      * @param boolean $startpoint if true output a starting point.
  11312.      * @param boolean $ccw if true draws in counter-clockwise.
  11313.      * @param boolean $svg if true the angles are in svg mode (already calculated).
  11314.      * @return array bounding box coordinates (x min, y min, x max, y max)
  11315.      * @author Nicola Asuni
  11316.      * @protected
  11317.      * @since 4.9.019 (2010-04-26)
  11318.      */
  11319.     protected function _outellipticalarc($xc$yc$rx$ry$xang=0$angs=0$angf=360$pie=false$nc=2$startpoint=true$ccw=true$svg=false) {
  11320.         if (($rx <= 0) OR ($ry 0)) {
  11321.             return;
  11322.         }
  11323.         $k $this->k;
  11324.         if ($nc 2) {
  11325.             $nc 2;
  11326.         }
  11327.         $xmin 2147483647;
  11328.         $ymin 2147483647;
  11329.         $xmax 0;
  11330.         $ymax 0;
  11331.         if ($pie) {
  11332.             // center of the arc
  11333.             $this->_outPoint($xc$yc);
  11334.         }
  11335.         $xang deg2rad((float) $xang);
  11336.         $angs deg2rad((float) $angs);
  11337.         $angf deg2rad((float) $angf);
  11338.         if ($svg) {
  11339.             $as $angs;
  11340.             $af $angf;
  11341.         } else {
  11342.             $as atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11343.             $af atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11344.         }
  11345.         if ($as 0) {
  11346.             $as += (M_PI);
  11347.         }
  11348.         if ($af 0) {
  11349.             $af += (M_PI);
  11350.         }
  11351.         if ($ccw AND ($as $af)) {
  11352.             // reverse rotation
  11353.             $as -= (M_PI);
  11354.         } elseif (!$ccw AND ($as $af)) {
  11355.             // reverse rotation
  11356.             $af -= (M_PI);
  11357.         }
  11358.         $total_angle = ($af $as);
  11359.         if ($nc 2) {
  11360.             $nc 2;
  11361.         }
  11362.         // total arcs to draw
  11363.         $nc *= (abs($total_angle) / M_PI);
  11364.         $nc round($nc) + 1;
  11365.         // angle of each arc
  11366.         $arcang = ($total_angle $nc);
  11367.         // center point in PDF coordinates
  11368.         $x0 $xc;
  11369.         $y0 = ($this->$yc);
  11370.         // starting angle
  11371.         $ang $as;
  11372.         $alpha sin($arcang) * ((sqrt(+ (pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11373.         $cos_xang cos($xang);
  11374.         $sin_xang sin($xang);
  11375.         $cos_ang cos($ang);
  11376.         $sin_ang sin($ang);
  11377.         // first arc point
  11378.         $px1 $x0 + ($rx $cos_xang $cos_ang) - ($ry $sin_xang $sin_ang);
  11379.         $py1 $y0 + ($rx $sin_xang $cos_ang) + ($ry $cos_xang $sin_ang);
  11380.         // first Bezier control point
  11381.         $qx1 = ($alpha * ((-$rx $cos_xang $sin_ang) - ($ry $sin_xang $cos_ang)));
  11382.         $qy1 = ($alpha * ((-$rx $sin_xang $sin_ang) + ($ry $cos_xang $cos_ang)));
  11383.         if ($pie) {
  11384.             // line from center to arc starting point
  11385.             $this->_outLine($px1$this->$py1);
  11386.         } elseif ($startpoint) {
  11387.             // arc starting point
  11388.             $this->_outPoint($px1$this->$py1);
  11389.         }
  11390.         // draw arcs
  11391.         for ($i 1$i <= $nc; ++$i) {
  11392.             // starting angle
  11393.             $ang $as + ($i $arcang);
  11394.             if ($i == $nc) {
  11395.                 $ang $af;
  11396.             }
  11397.             $cos_ang cos($ang);
  11398.             $sin_ang sin($ang);
  11399.             // second arc point
  11400.             $px2 $x0 + ($rx $cos_xang $cos_ang) - ($ry $sin_xang $sin_ang);
  11401.             $py2 $y0 + ($rx $sin_xang $cos_ang) + ($ry $cos_xang $sin_ang);
  11402.             // second Bezier control point
  11403.             $qx2 = ($alpha * ((-$rx $cos_xang $sin_ang) - ($ry $sin_xang $cos_ang)));
  11404.             $qy2 = ($alpha * ((-$rx $sin_xang $sin_ang) + ($ry $cos_xang $cos_ang)));
  11405.             // draw arc
  11406.             $cx1 = ($px1 $qx1);
  11407.             $cy1 = ($this->- ($py1 $qy1));
  11408.             $cx2 = ($px2 $qx2);
  11409.             $cy2 = ($this->- ($py2 $qy2));
  11410.             $cx3 $px2;
  11411.             $cy3 = ($this->$py2);
  11412.             $this->_outCurve($cx1$cy1$cx2$cy2$cx3$cy3);
  11413.             // get bounding box coordinates
  11414.             $xmin min($xmin$cx1$cx2$cx3);
  11415.             $ymin min($ymin$cy1$cy2$cy3);
  11416.             $xmax max($xmax$cx1$cx2$cx3);
  11417.             $ymax max($ymax$cy1$cy2$cy3);
  11418.             // move to next point
  11419.             $px1 $px2;
  11420.             $py1 $py2;
  11421.             $qx1 $qx2;
  11422.             $qy1 $qy2;
  11423.         }
  11424.         if ($pie) {
  11425.             $this->_outLine($xc$yc);
  11426.             // get bounding box coordinates
  11427.             $xmin min($xmin$xc);
  11428.             $ymin min($ymin$yc);
  11429.             $xmax max($xmax$xc);
  11430.             $ymax max($ymax$yc);
  11431.         }
  11432.         return array($xmin$ymin$xmax$ymax);
  11433.     }
  11434.     /**
  11435.      * Draws a circle.
  11436.      * A circle is formed from n Bezier curves.
  11437.      * @param float $x0 Abscissa of center point.
  11438.      * @param float $y0 Ordinate of center point.
  11439.      * @param float $r Radius.
  11440.      * @param float $angstr Angle start of draw line. Default value: 0.
  11441.      * @param float $angend Angle finish of draw line. Default value: 360.
  11442.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11443.      * @param array $line_style Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11444.      * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11445.      * @param integer $nc Number of curves used to draw a 90 degrees portion of circle.
  11446.      * @public
  11447.      * @since 2.1.000 (2008-01-08)
  11448.      */
  11449.     public function Circle($x0$y0$r$angstr=0$angend=360$style=''$line_style=array(), $fill_color=array(), $nc=2) {
  11450.         $this->Ellipse($x0$y0$r$r0$angstr$angend$style$line_style$fill_color$nc);
  11451.     }
  11452.     /**
  11453.      * Draws a polygonal line
  11454.      * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11455.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11456.      * @param array $line_style Line style of polygon. Array with keys among the following:
  11457.      * <ul>
  11458.      *     <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11459.      *     <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11460.      * </ul>
  11461.      * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11462.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11463.      * @since 4.8.003 (2009-09-15)
  11464.      * @public
  11465.      */
  11466.     public function PolyLine($p$style=''$line_style=array(), $fill_color=array()) {
  11467.         $this->Polygon($p$style$line_style$fill_colorfalse);
  11468.     }
  11469.     /**
  11470.      * Draws a polygon.
  11471.      * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11472.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11473.      * @param array $line_style Line style of polygon. Array with keys among the following:
  11474.      * <ul>
  11475.      *     <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11476.      *     <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11477.      * </ul>
  11478.      * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11479.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11480.      * @param boolean $closed if true the polygon is closes, otherwise will remain open
  11481.      * @public
  11482.      * @since 2.1.000 (2008-01-08)
  11483.      */
  11484.     public function Polygon($p$style=''$line_style=array(), $fill_color=array(), $closed=true) {
  11485.         if ($this->state != 2) {
  11486.             return;
  11487.         }
  11488.         $nc count($p); // number of coordinates
  11489.         $np $nc 2// number of points
  11490.         if ($closed) {
  11491.             // close polygon by adding the first 2 points at the end (one line)
  11492.             for ($i 0$i 4; ++$i) {
  11493.                 $p[$nc $i] = $p[$i];
  11494.             }
  11495.             // copy style for the last added line
  11496.             if (isset($line_style[0])) {
  11497.                 $line_style[$np] = $line_style[0];
  11498.             }
  11499.             $nc += 4;
  11500.         }
  11501.         if (!(false === strpos($style'F')) AND is_array($fill_color)) {
  11502.             $this->setFillColorArray($fill_color);
  11503.         }
  11504.         $op TCPDF_STATIC::getPathPaintOperator($style);
  11505.         if ($op == 'f') {
  11506.             $line_style = array();
  11507.         }
  11508.         $draw true;
  11509.         if ($line_style) {
  11510.             if (isset($line_style['all'])) {
  11511.                 $this->setLineStyle($line_style['all']);
  11512.             } else {
  11513.                 $draw false;
  11514.                 if ($op == 'B') {
  11515.                     // draw fill
  11516.                     $op 'f';
  11517.                     $this->_outPoint($p[0], $p[1]);
  11518.                     for ($i 2$i $nc$i $i 2) {
  11519.                         $this->_outLine($p[$i], $p[$i 1]);
  11520.                     }
  11521.                     $this->_out($op);
  11522.                 }
  11523.                 // draw outline
  11524.                 $this->_outPoint($p[0], $p[1]);
  11525.                 for ($i 2$i $nc$i $i 2) {
  11526.                     $line_num = ($i 2) - 1;
  11527.                     if (isset($line_style[$line_num])) {
  11528.                         if ($line_style[$line_num] != 0) {
  11529.                             if (is_array($line_style[$line_num])) {
  11530.                                 $this->_out('S');
  11531.                                 $this->setLineStyle($line_style[$line_num]);
  11532.                                 $this->_outPoint($p[$i 2], $p[$i 1]);
  11533.                                 $this->_outLine($p[$i], $p[$i 1]);
  11534.                                 $this->_out('S');
  11535.                                 $this->_outPoint($p[$i], $p[$i 1]);
  11536.                             } else {
  11537.                                 $this->_outLine($p[$i], $p[$i 1]);
  11538.                             }
  11539.                         }
  11540.                     } else {
  11541.                         $this->_outLine($p[$i], $p[$i 1]);
  11542.                     }
  11543.                 }
  11544.                 $this->_out($op);
  11545.             }
  11546.         }
  11547.         if ($draw) {
  11548.             $this->_outPoint($p[0], $p[1]);
  11549.             for ($i 2$i $nc$i $i 2) {
  11550.                 $this->_outLine($p[$i], $p[$i 1]);
  11551.             }
  11552.             $this->_out($op);
  11553.         }
  11554.     }
  11555.     /**
  11556.      * Draws a regular polygon.
  11557.      * @param float $x0 Abscissa of center point.
  11558.      * @param float $y0 Ordinate of center point.
  11559.      * @param float $r Radius of inscribed circle.
  11560.      * @param integer $ns Number of sides.
  11561.      * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11562.      * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  11563.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11564.      * @param array $line_style Line style of polygon sides. Array with keys among the following:
  11565.      * <ul>
  11566.      *     <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11567.      *     <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11568.      * </ul>
  11569.      * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11570.      * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11571.      * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  11572.      * <ul>
  11573.      *     <li>D or empty string: Draw (default).</li>
  11574.      *     <li>F: Fill.</li>
  11575.      *     <li>DF or FD: Draw and fill.</li>
  11576.      *     <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11577.      *     <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11578.      * </ul>
  11579.      * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11580.      * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11581.      * @public
  11582.      * @since 2.1.000 (2008-01-08)
  11583.      */
  11584.     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()) {
  11585.         if ($ns) {
  11586.             $ns 3;
  11587.         }
  11588.         if ($draw_circle) {
  11589.             $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  11590.         }
  11591.         $p = array();
  11592.         for ($i 0$i $ns; ++$i) {
  11593.             $a $angle + ($i 360 $ns);
  11594.             $a_rad deg2rad((float) $a);
  11595.             $p[] = $x0 + ($r sin($a_rad));
  11596.             $p[] = $y0 + ($r cos($a_rad));
  11597.         }
  11598.         $this->Polygon($p$style$line_style$fill_color);
  11599.     }
  11600.     /**
  11601.      * Draws a star polygon
  11602.      * @param float $x0 Abscissa of center point.
  11603.      * @param float $y0 Ordinate of center point.
  11604.      * @param float $r Radius of inscribed circle.
  11605.      * @param integer $nv Number of vertices.
  11606.      * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11607.      * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  11608.      * @param boolean $draw_circle Draw inscribed circle or not. Default value is false.
  11609.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11610.      * @param array $line_style Line style of polygon sides. Array with keys among the following:
  11611.      * <ul>
  11612.      *     <li>all: Line style of all sides. Array like for
  11613.      * SetLineStyle().</li>
  11614.      *     <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11615.      * </ul>
  11616.      * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11617.      * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11618.      * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  11619.      * <ul>
  11620.      *     <li>D or empty string: Draw (default).</li>
  11621.      *     <li>F: Fill.</li>
  11622.      *     <li>DF or FD: Draw and fill.</li>
  11623.      *     <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11624.      *     <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11625.      * </ul>
  11626.      * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11627.      * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11628.      * @public
  11629.      * @since 2.1.000 (2008-01-08)
  11630.      */
  11631.     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()) {
  11632.         if ($nv 2) {
  11633.             $nv 2;
  11634.         }
  11635.         if ($draw_circle) {
  11636.             $this->Circle($x0$y0$r0360$circle_style$circle_outLine_style$circle_fill_color);
  11637.         }
  11638.         $p2 = array();
  11639.         $visited = array();
  11640.         for ($i 0$i $nv; ++$i) {
  11641.             $a $angle + ($i 360 $nv);
  11642.             $a_rad deg2rad((float) $a);
  11643.             $p2[] = $x0 + ($r sin($a_rad));
  11644.             $p2[] = $y0 + ($r cos($a_rad));
  11645.             $visited[] = false;
  11646.         }
  11647.         $p = array();
  11648.         $i 0;
  11649.         do {
  11650.             $p[] = $p2[$i 2];
  11651.             $p[] = $p2[($i 2) + 1];
  11652.             $visited[$i] = true;
  11653.             $i += $ng;
  11654.             $i %= $nv;
  11655.         } while (!$visited[$i]);
  11656.         $this->Polygon($p$style$line_style$fill_color);
  11657.     }
  11658.     /**
  11659.      * Draws a rounded rectangle.
  11660.      * @param float $x Abscissa of upper-left corner.
  11661.      * @param float $y Ordinate of upper-left corner.
  11662.      * @param float $w Width.
  11663.      * @param float $h Height.
  11664.      * @param float $r the radius of the circle used to round off the corners of the rectangle.
  11665.      * @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 right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  11666.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11667.      * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11668.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11669.      * @public
  11670.      * @since 2.1.000 (2008-01-08)
  11671.      */
  11672.     public function RoundedRect($x$y$w$h$r$round_corner='1111'$style=''$border_style=array(), $fill_color=array()) {
  11673.         $this->RoundedRectXY($x$y$w$h$r$r$round_corner$style$border_style$fill_color);
  11674.     }
  11675.     /**
  11676.      * Draws a rounded rectangle.
  11677.      * @param float $x Abscissa of upper-left corner.
  11678.      * @param float $y Ordinate of upper-left corner.
  11679.      * @param float $w Width.
  11680.      * @param float $h Height.
  11681.      * @param float $rx the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11682.      * @param float $ry the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11683.      * @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 right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
  11684.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  11685.      * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11686.      * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
  11687.      * @public
  11688.      * @since 4.9.019 (2010-04-22)
  11689.      */
  11690.     public function RoundedRectXY($x$y$w$h$rx$ry$round_corner='1111'$style=''$border_style=array(), $fill_color=array()) {
  11691.         if ($this->state != 2) {
  11692.             return;
  11693.         }
  11694.         if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11695.             // Not rounded
  11696.             $this->Rect($x$y$w$h$style$border_style$fill_color);
  11697.             return;
  11698.         }
  11699.         // Rounded
  11700.         if (!(false === strpos($style'F')) AND is_array($fill_color)) {
  11701.             $this->setFillColorArray($fill_color);
  11702.         }
  11703.         $op TCPDF_STATIC::getPathPaintOperator($style);
  11704.         if ($op == 'f') {
  11705.             $border_style = array();
  11706.         }
  11707.         if ($border_style) {
  11708.             $this->setLineStyle($border_style);
  11709.         }
  11710.         $MyArc * (sqrt(2) - 1);
  11711.         $this->_outPoint($x $rx$y);
  11712.         $xc $x $w $rx;
  11713.         $yc $y $ry;
  11714.         $this->_outLine($xc$y);
  11715.         if ($round_corner[0]) {
  11716.             $this->_outCurve($xc + ($rx $MyArc), $yc $ry$xc $rx$yc - ($ry $MyArc), $xc $rx$yc);
  11717.         } else {
  11718.             $this->_outLine($x $w$y);
  11719.         }
  11720.         $xc $x $w $rx;
  11721.         $yc $y $h $ry;
  11722.         $this->_outLine($x $w$yc);
  11723.         if ($round_corner[1]) {
  11724.             $this->_outCurve($xc $rx$yc + ($ry $MyArc), $xc + ($rx $MyArc), $yc $ry$xc$yc $ry);
  11725.         } else {
  11726.             $this->_outLine($x $w$y $h);
  11727.         }
  11728.         $xc $x $rx;
  11729.         $yc $y $h $ry;
  11730.         $this->_outLine($xc$y $h);
  11731.         if ($round_corner[2]) {
  11732.             $this->_outCurve($xc - ($rx $MyArc), $yc $ry$xc $rx$yc + ($ry $MyArc), $xc $rx$yc);
  11733.         } else {
  11734.             $this->_outLine($x$y $h);
  11735.         }
  11736.         $xc $x $rx;
  11737.         $yc $y $ry;
  11738.         $this->_outLine($x$yc);
  11739.         if ($round_corner[3]) {
  11740.             $this->_outCurve($xc $rx$yc - ($ry $MyArc), $xc - ($rx $MyArc), $yc $ry$xc$yc $ry);
  11741.         } else {
  11742.             $this->_outLine($x$y);
  11743.             $this->_outLine($x $rx$y);
  11744.         }
  11745.         $this->_out($op);
  11746.     }
  11747.     /**
  11748.      * Draws a grahic arrow.
  11749.      * @param float $x0 Abscissa of first point.
  11750.      * @param float $y0 Ordinate of first point.
  11751.      * @param float $x1 Abscissa of second point.
  11752.      * @param float $y1 Ordinate of second point.
  11753.      * @param int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11754.      * @param float $arm_size length of arrowhead arms
  11755.      * @param int $arm_angle angle between an arm and the shaft
  11756.      * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11757.      * @since 4.6.018 (2009-07-10)
  11758.      */
  11759.     public function Arrow($x0$y0$x1$y1$head_style=0$arm_size=5$arm_angle=15) {
  11760.         // getting arrow direction angle
  11761.         // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11762.         $dir_angle atan2(($y0 $y1), ($x0 $x1));
  11763.         if ($dir_angle 0) {
  11764.             $dir_angle += (M_PI);
  11765.         }
  11766.         $arm_angle deg2rad($arm_angle);
  11767.         $sx1 $x1;
  11768.         $sy1 $y1;
  11769.         if ($head_style 0) {
  11770.             // calculate the stopping point for the arrow shaft
  11771.             $sx1 $x1 + (($arm_size $this->LineWidth) * cos($dir_angle));
  11772.             $sy1 $y1 + (($arm_size $this->LineWidth) * sin($dir_angle));
  11773.         }
  11774.         // main arrow line / shaft
  11775.         $this->Line($x0$y0$sx1$sy1);
  11776.         // left arrowhead arm tip
  11777.         $x2L $x1 + ($arm_size cos($dir_angle $arm_angle));
  11778.         $y2L $y1 + ($arm_size sin($dir_angle $arm_angle));
  11779.         // right arrowhead arm tip
  11780.         $x2R $x1 + ($arm_size cos($dir_angle $arm_angle));
  11781.         $y2R $y1 + ($arm_size sin($dir_angle $arm_angle));
  11782.         $mode 'D';
  11783.         $style = array();
  11784.         switch ($head_style) {
  11785.             case 0: {
  11786.                 // draw only arrowhead arms
  11787.                 $mode 'D';
  11788.                 $style = array(110);
  11789.                 break;
  11790.             }
  11791.             case 1: {
  11792.                 // draw closed arrowhead, but no fill
  11793.                 $mode 'D';
  11794.                 break;
  11795.             }
  11796.             case 2: {
  11797.                 // closed and filled arrowhead
  11798.                 $mode 'DF';
  11799.                 break;
  11800.             }
  11801.             case 3: {
  11802.                 // filled arrowhead
  11803.                 $mode 'F';
  11804.                 break;
  11805.             }
  11806.         }
  11807.         $this->Polygon(array($x2L$y2L$x1$y1$x2R$y2R), $mode$style, array());
  11808.     }
  11809.     // END GRAPHIC FUNCTIONS SECTION -----------------------
  11810.     /**
  11811.      * Add a Named Destination.
  11812.      * NOTE: destination names are unique, so only last entry will be saved.
  11813.      * @param string $name Destination name.
  11814.      * @param float $y Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  11815.      * @param int|string $page Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  11816.      * @param float $x X position in user units of the destiantion on the selected page (default = -1 = current position;).
  11817.      * @return string|false Stripped named destination identifier or false in case of error.
  11818.      * @public
  11819.      * @author Christian Deligant, Nicola Asuni
  11820.      * @since 5.9.097 (2011-06-23)
  11821.      */
  11822.     public function setDestination($name$y=-1$page=''$x=-1) {
  11823.         // remove unsupported characters
  11824.         $name TCPDF_STATIC::encodeNameObject($name);
  11825.         if (TCPDF_STATIC::empty_string($name)) {
  11826.             return false;
  11827.         }
  11828.         if ($y == -1) {
  11829.             $y $this->GetY();
  11830.         } elseif ($y 0) {
  11831.             $y 0;
  11832.         } elseif ($y $this->h) {
  11833.             $y $this->h;
  11834.         }
  11835.         if ($x == -1) {
  11836.             $x $this->GetX();
  11837.         } elseif ($x 0) {
  11838.             $x 0;
  11839.         } elseif ($x $this->w) {
  11840.             $x $this->w;
  11841.         }
  11842.         $fixed false;
  11843.         if (!empty($page) AND (substr($page01) == '*')) {
  11844.             $page intval(substr($page1));
  11845.             // this page number will not be changed when moving/add/deleting pages
  11846.             $fixed true;
  11847.         }
  11848.         if (empty($page)) {
  11849.             $page $this->PageNo();
  11850.             if (empty($page)) {
  11851.                 return;
  11852.             }
  11853.         }
  11854.         $this->dests[$name] = array('x' => $x'y' => $y'p' => $page'f' => $fixed);
  11855.         return $name;
  11856.     }
  11857.     /**
  11858.      * Return the Named Destination array.
  11859.      * @return array Named Destination array.
  11860.      * @public
  11861.      * @author Nicola Asuni
  11862.      * @since 5.9.097 (2011-06-23)
  11863.      */
  11864.     public function getDestination() {
  11865.         return $this->dests;
  11866.     }
  11867.     /**
  11868.      * Insert Named Destinations.
  11869.      * @protected
  11870.      * @author Johannes G\FCntert, Nicola Asuni
  11871.      * @since 5.9.098 (2011-06-23)
  11872.      */
  11873.     protected function _putdests() {
  11874.         if (empty($this->dests)) {
  11875.             return;
  11876.         }
  11877.         $this->n_dests $this->_newobj();
  11878.         $out ' <<';
  11879.         foreach($this->dests as $name => $o) {
  11880.             $out .= ' /'.$name.' '.sprintf('[%u 0 R /XYZ %F %F null]'$this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  11881.         }
  11882.         $out .= ' >>';
  11883.         $out .= "\n".'endobj';
  11884.         $this->_out($out);
  11885.     }
  11886.     /**
  11887.      * Adds a bookmark - alias for Bookmark().
  11888.      * @param string $txt Bookmark description.
  11889.      * @param int $level Bookmark level (minimum value is 0).
  11890.      * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11891.      * @param int|string $page Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  11892.      * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11893.      * @param array $color RGB color array (values from 0 to 255).
  11894.      * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11895.      * @param mixed $link URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11896.      * @public
  11897.      */
  11898.     public function setBookmark($txt$level=0$y=-1$page=''$style=''$color=array(0,0,0), $x=-1$link='') {
  11899.         $this->Bookmark($txt$level$y$page$style$color$x$link);
  11900.     }
  11901.     /**
  11902.      * Adds a bookmark.
  11903.      * @param string $txt Bookmark description.
  11904.      * @param int $level Bookmark level (minimum value is 0).
  11905.      * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11906.      * @param int|string $page Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
  11907.      * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11908.      * @param array $color RGB color array (values from 0 to 255).
  11909.      * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11910.      * @param mixed $link URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11911.      * @public
  11912.      * @since 2.1.002 (2008-02-12)
  11913.      */
  11914.     public function Bookmark($txt$level=0$y=-1$page=''$style=''$color=array(0,0,0), $x=-1$link='') {
  11915.         if ($level 0) {
  11916.             $level 0;
  11917.         }
  11918.         if (isset($this->outlines[0])) {
  11919.             $lastoutline end($this->outlines);
  11920.             $maxlevel $lastoutline['l'] + 1;
  11921.         } else {
  11922.             $maxlevel 0;
  11923.         }
  11924.         if ($level $maxlevel) {
  11925.             $level $maxlevel;
  11926.         }
  11927.         if ($y == -1) {
  11928.             $y $this->GetY();
  11929.         } elseif ($y 0) {
  11930.             $y 0;
  11931.         } elseif ($y $this->h) {
  11932.             $y $this->h;
  11933.         }
  11934.         if ($x == -1) {
  11935.             $x $this->GetX();
  11936.         } elseif ($x 0) {
  11937.             $x 0;
  11938.         } elseif ($x $this->w) {
  11939.             $x $this->w;
  11940.         }
  11941.         $fixed false;
  11942.         $pageAsString = (string) $page;
  11943.         if ($pageAsString && $pageAsString[0] == '*') {
  11944.             $page intval(substr($page1));
  11945.             // this page number will not be changed when moving/add/deleting pages
  11946.             $fixed true;
  11947.         }
  11948.         if (empty($page)) {
  11949.             $page $this->PageNo();
  11950.             if (empty($page)) {
  11951.                 return;
  11952.             }
  11953.         }
  11954.         $this->outlines[] = array('t' => $txt'l' => $level'x' => $x'y' => $y'p' => $page'f' => $fixed's' => strtoupper($style), 'c' => $color'u' => $link);
  11955.     }
  11956.     /**
  11957.      * Sort bookmarks for page and key.
  11958.      * @protected
  11959.      * @since 5.9.119 (2011-09-19)
  11960.      */
  11961.     protected function sortBookmarks() {
  11962.         // get sorting columns
  11963.         $outline_p = array();
  11964.         $outline_y = array();
  11965.         foreach ($this->outlines as $key => $row) {
  11966.             $outline_p[$key] = $row['p'];
  11967.             $outline_k[$key] = $key;
  11968.         }
  11969.         // sort outlines by page and original position
  11970.         array_multisort($outline_pSORT_NUMERICSORT_ASC$outline_kSORT_NUMERICSORT_ASC$this->outlines);
  11971.     }
  11972.     /**
  11973.      * Create a bookmark PDF string.
  11974.      * @protected
  11975.      * @author Olivier Plathey, Nicola Asuni
  11976.      * @since 2.1.002 (2008-02-12)
  11977.      */
  11978.     protected function _putbookmarks() {
  11979.         $nb count($this->outlines);
  11980.         if ($nb == 0) {
  11981.             return;
  11982.         }
  11983.         // sort bookmarks
  11984.         $this->sortBookmarks();
  11985.         $lru = array();
  11986.         $level 0;
  11987.         foreach ($this->outlines as $i => $o) {
  11988.             if ($o['l'] > 0) {
  11989.                 $parent $lru[($o['l'] - 1)];
  11990.                 //Set parent and last pointers
  11991.                 $this->outlines[$i]['parent'] = $parent;
  11992.                 $this->outlines[$parent]['last'] = $i;
  11993.                 if ($o['l'] > $level) {
  11994.                     //Level increasing: set first pointer
  11995.                     $this->outlines[$parent]['first'] = $i;
  11996.                 }
  11997.             } else {
  11998.                 $this->outlines[$i]['parent'] = $nb;
  11999.             }
  12000.             if (($o['l'] <= $level) AND ($i 0)) {
  12001.                 //Set prev and next pointers
  12002.                 $prev $lru[$o['l']];
  12003.                 $this->outlines[$prev]['next'] = $i;
  12004.                 $this->outlines[$i]['prev'] = $prev;
  12005.             }
  12006.             $lru[$o['l']] = $i;
  12007.             $level $o['l'];
  12008.         }
  12009.         //Outline items
  12010.         $n $this->1;
  12011.         $nltags '/<br[\s]?\/>|<\/(blockquote|dd|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|ul|tcpdf|table|tr|td)>/si';
  12012.         foreach ($this->outlines as $i => $o) {
  12013.             $oid $this->_newobj();
  12014.             // covert HTML title to string
  12015.             $title preg_replace($nltags"\n"$o['t']);
  12016.             $title preg_replace("/[\r]+/si"''$title);
  12017.             $title preg_replace("/[\n]+/si""\n"$title);
  12018.             $title strip_tags($title);
  12019.             $title $this->stringTrim($title);
  12020.             $out '<</Title '.$this->_textstring($title$oid);
  12021.             $out .= ' /Parent '.($n $o['parent']).' 0 R';
  12022.             if (isset($o['prev'])) {
  12023.                 $out .= ' /Prev '.($n $o['prev']).' 0 R';
  12024.             }
  12025.             if (isset($o['next'])) {
  12026.                 $out .= ' /Next '.($n $o['next']).' 0 R';
  12027.             }
  12028.             if (isset($o['first'])) {
  12029.                 $out .= ' /First '.($n $o['first']).' 0 R';
  12030.             }
  12031.             if (isset($o['last'])) {
  12032.                 $out .= ' /Last '.($n $o['last']).' 0 R';
  12033.             }
  12034.             if (isset($o['u']) AND !empty($o['u'])) {
  12035.                 // link
  12036.                 if (is_string($o['u'])) {
  12037.                     if ($o['u'][0] == '#') {
  12038.                         // internal destination
  12039.                         $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  12040.                     } elseif ($o['u'][0] == '%') {
  12041.                         // embedded PDF file
  12042.                         $filename basename(substr($o['u'], 1));
  12043.                         $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  12044.                     } elseif ($o['u'][0] == '*') {
  12045.                         // embedded generic file
  12046.                         $filename basename(substr($o['u'], 1));
  12047.                         $jsa 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
  12048.                         $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa$oid).'>>';
  12049.                     } else {
  12050.                         // external URI link
  12051.                         $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  12052.                     }
  12053.                 } elseif (isset($this->links[$o['u']])) {
  12054.                     // internal link ID
  12055.                     $l $this->links[$o['u']];
  12056.                     if (isset($this->page_obj_id[($l['p'])])) {
  12057.                         $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]'$this->page_obj_id[($l['p'])], ($this->pagedim[$l['p']]['h'] - ($l['y'] * $this->k)));
  12058.                     }
  12059.                 }
  12060.             } elseif (isset($this->page_obj_id[($o['p'])])) {
  12061.                 // link to a page
  12062.                 $out .= ' '.sprintf('/Dest [%u 0 R /XYZ %F %F null]'$this->page_obj_id[($o['p'])], ($o['x'] * $this->k), ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  12063.             }
  12064.             // set font style
  12065.             $style 0;
  12066.             if (!empty($o['s'])) {
  12067.                 // bold
  12068.                 if (strpos($o['s'], 'B') !== false) {
  12069.                     $style |= 2;
  12070.                 }
  12071.                 // oblique
  12072.                 if (strpos($o['s'], 'I') !== false) {
  12073.                     $style |= 1;
  12074.                 }
  12075.             }
  12076.             $out .= sprintf(' /F %d'$style);
  12077.             // set bookmark color
  12078.             if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  12079.                 $color array_values($o['c']);
  12080.                 $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  12081.             } else {
  12082.                 // black
  12083.                 $out .= ' /C [0.0 0.0 0.0]';
  12084.             }
  12085.             $out .= ' /Count 0'// normally closed item
  12086.             $out .= ' >>';
  12087.             $out .= "\n".'endobj';
  12088.             $this->_out($out);
  12089.         }
  12090.         //Outline root
  12091.         $this->OutlineRoot $this->_newobj();
  12092.         $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n $lru[0]).' 0 R >>'."\n".'endobj');
  12093.     }
  12094.     // --- JAVASCRIPT ------------------------------------------------------
  12095.     /**
  12096.      * Adds a javascript
  12097.      * @param string $script Javascript code
  12098.      * @public
  12099.      * @author Johannes G\FCntert, Nicola Asuni
  12100.      * @since 2.1.002 (2008-02-12)
  12101.      */
  12102.     public function IncludeJS($script) {
  12103.         $this->javascript .= $script;
  12104.     }
  12105.     /**
  12106.      * Adds a javascript object and return object ID
  12107.      * @param string $script Javascript code
  12108.      * @param boolean $onload if true executes this object when opening the document
  12109.      * @return int internal object ID
  12110.      * @public
  12111.      * @author Nicola Asuni
  12112.      * @since 4.8.000 (2009-09-07)
  12113.      */
  12114.     public function addJavascriptObject($script$onload=false) {
  12115.         if ($this->pdfa_mode) {
  12116.             // javascript is not allowed in PDF/A mode
  12117.             return false;
  12118.         }
  12119.         ++$this->n;
  12120.         $this->js_objects[$this->n] = array('n' => $this->n'js' => $script'onload' => $onload);
  12121.         return $this->n;
  12122.     }
  12123.     /**
  12124.      * Create a javascript PDF string.
  12125.      * @protected
  12126.      * @author Johannes G\FCntert, Nicola Asuni
  12127.      * @since 2.1.002 (2008-02-12)
  12128.      */
  12129.     protected function _putjavascript() {
  12130.         if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  12131.             return;
  12132.         }
  12133.         if (strpos($this->javascript'this.addField') > 0) {
  12134.             if (!$this->ur['enabled']) {
  12135.                 //$this->setUserRights();
  12136.             }
  12137.             // the following two lines are used to avoid form fields duplication after saving
  12138.             // The addField method only works when releasing user rights (UR3)
  12139.             $jsa sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);"'tcpdfdocsaved''text'00101);
  12140.             $jsb "getField('tcpdfdocsaved').value='saved';";
  12141.             $this->javascript $jsa."\n".$this->javascript."\n".$jsb;
  12142.         }
  12143.         // name tree for javascript
  12144.         $this->n_js '<< /Names [';
  12145.         if (!empty($this->javascript)) {
  12146.             $this->n_js .= ' (EmbeddedJS) '.($this->1).' 0 R';
  12147.         }
  12148.         if (!empty($this->js_objects)) {
  12149.             foreach ($this->js_objects as $key => $val) {
  12150.                 if ($val['onload']) {
  12151.                     $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12152.                 }
  12153.             }
  12154.         }
  12155.         $this->n_js .= ' ] >>';
  12156.         // default Javascript object
  12157.         if (!empty($this->javascript)) {
  12158.             $obj_id $this->_newobj();
  12159.             $out '<< /S /JavaScript';
  12160.             $out .= ' /JS '.$this->_textstring($this->javascript$obj_id);
  12161.             $out .= ' >>';
  12162.             $out .= "\n".'endobj';
  12163.             $this->_out($out);
  12164.         }
  12165.         // additional Javascript objects
  12166.         if (!empty($this->js_objects)) {
  12167.             foreach ($this->js_objects as $key => $val) {
  12168.                 $out $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12169.                 $this->_out($out);
  12170.             }
  12171.         }
  12172.     }
  12173.     /**
  12174.      * Adds a javascript form field.
  12175.      * @param string $type field type
  12176.      * @param string $name field name
  12177.      * @param int $x horizontal position
  12178.      * @param int $y vertical position
  12179.      * @param int $w width
  12180.      * @param int $h height
  12181.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12182.      * @protected
  12183.      * @author Denis Van Nuffelen, Nicola Asuni
  12184.      * @since 2.1.002 (2008-02-12)
  12185.      */
  12186.     protected function _addfield($type$name$x$y$w$h$prop) {
  12187.         if ($this->rtl) {
  12188.             $x $x $w;
  12189.         }
  12190.         // the followind avoid fields duplication after saving the document
  12191.         $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12192.         $k $this->k;
  12193.         $this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%F,%F,%F,%F]);"$name$type$this->PageNo()-1$x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
  12194.         $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12195.         foreach($prop as $key => $val) {
  12196.             if (strcmp(substr($key, -5), 'Color') == 0) {
  12197.                 $val TCPDF_COLORS::_JScolor($val);
  12198.             } else {
  12199.                 $val "'".$val."'";
  12200.             }
  12201.             $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12202.         }
  12203.         if ($this->rtl) {
  12204.             $this->-= $w;
  12205.         } else {
  12206.             $this->+= $w;
  12207.         }
  12208.         $this->javascript .= '}';
  12209.     }
  12210.     // --- FORM FIELDS -----------------------------------------------------
  12211.     /**
  12212.      * Set default properties for form fields.
  12213.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12214.      * @public
  12215.      * @author Nicola Asuni
  12216.      * @since 4.8.000 (2009-09-06)
  12217.      */
  12218.     public function setFormDefaultProp($prop=array()) {
  12219.         $this->default_form_prop $prop;
  12220.     }
  12221.     /**
  12222.      * Return the default properties for form fields.
  12223.      * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12224.      * @public
  12225.      * @author Nicola Asuni
  12226.      * @since 4.8.000 (2009-09-06)
  12227.      */
  12228.     public function getFormDefaultProp() {
  12229.         return $this->default_form_prop;
  12230.     }
  12231.     /**
  12232.      * Creates a text field
  12233.      * @param string $name field name
  12234.      * @param float $w Width of the rectangle
  12235.      * @param float $h Height of the rectangle
  12236.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12237.      * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12238.      * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12239.      * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12240.      * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12241.      * @public
  12242.      * @author Nicola Asuni
  12243.      * @since 4.8.000 (2009-09-07)
  12244.      */
  12245.     public function TextField($name$w$h$prop=array(), $opt=array(), $x=null$y=null$js=false) {
  12246.         if (TCPDF_STATIC::empty_string($x)) {
  12247.             $x $this->x;
  12248.         }
  12249.         if (TCPDF_STATIC::empty_string($y)) {
  12250.             $y $this->y;
  12251.         }
  12252.         // check page for no-write regions and adapt page margins if necessary
  12253.         list($x$y) = $this->checkPageRegions($h$x$y);
  12254.         if ($js) {
  12255.             $this->_addfield('text'$name$x$y$w$h$prop);
  12256.             return;
  12257.         }
  12258.         // get default style
  12259.         $prop array_merge($this->getFormDefaultProp(), $prop);
  12260.         // get annotation data
  12261.         $popt TCPDF_STATIC::getAnnotOptFromJSProp($prop$this->spot_colors$this->rtl);
  12262.         // set default appearance stream
  12263.         $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12264.         $fontstyle sprintf('/F%d %F Tf %s'$this->CurrentFont['i'], $this->FontSizePt$this->TextColor);
  12265.         $popt['da'] = $fontstyle;
  12266.         // build appearance stream
  12267.         $popt['ap'] = array();
  12268.         $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12269.         $text '';
  12270.         if (isset($prop['value']) AND !empty($prop['value'])) {
  12271.             $text $prop['value'];
  12272.         } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12273.             $text $opt['v'];
  12274.         }
  12275.         $tmpid $this->startTemplate($w$hfalse);
  12276.         $align '';
  12277.         if (isset($popt['q'])) {
  12278.             switch ($popt['q']) {
  12279.                 case 0: {
  12280.                     $align 'L';
  12281.                     break;
  12282.                 }
  12283.                 case 1: {
  12284.                     $align 'C';
  12285.                     break;
  12286.                 }
  12287.                 case 2: {
  12288.                     $align 'R';
  12289.                     break;
  12290.                 }
  12291.                 default: {
  12292.                     $align '';
  12293.                     break;
  12294.                 }
  12295.             }
  12296.         }
  12297.         $this->MultiCell($w$h$text0$alignfalse000true0falsetrue0'T'false);
  12298.         $this->endTemplate();
  12299.         --$this->n;
  12300.         $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12301.         unset($this->xobjects[$tmpid]);
  12302.         $popt['ap']['n'] .= 'Q EMC';
  12303.         // merge options
  12304.         $opt array_merge($popt$opt);
  12305.         // remove some conflicting options
  12306.         unset($opt['bs']);
  12307.         // set remaining annotation data
  12308.         $opt['Subtype'] = 'Widget';
  12309.         $opt['ft'] = 'Tx';
  12310.         $opt['t'] = $name;
  12311.         // Additional annotation's parameters (check _putannotsobj() method):
  12312.         //$opt['f']
  12313.         //$opt['as']
  12314.         //$opt['bs']
  12315.         //$opt['be']
  12316.         //$opt['c']
  12317.         //$opt['border']
  12318.         //$opt['h']
  12319.         //$opt['mk'];
  12320.         //$opt['mk']['r']
  12321.         //$opt['mk']['bc'];
  12322.         //$opt['mk']['bg'];
  12323.         unset($opt['mk']['ca']);
  12324.         unset($opt['mk']['rc']);
  12325.         unset($opt['mk']['ac']);
  12326.         unset($opt['mk']['i']);
  12327.         unset($opt['mk']['ri']);
  12328.         unset($opt['mk']['ix']);
  12329.         unset($opt['mk']['if']);
  12330.         //$opt['mk']['if']['sw'];
  12331.         //$opt['mk']['if']['s'];
  12332.         //$opt['mk']['if']['a'];
  12333.         //$opt['mk']['if']['fb'];
  12334.         unset($opt['mk']['tp']);
  12335.         //$opt['tu']
  12336.         //$opt['tm']
  12337.         //$opt['ff']
  12338.         //$opt['v']
  12339.         //$opt['dv']
  12340.         //$opt['a']
  12341.         //$opt['aa']
  12342.         //$opt['q']
  12343.         $this->Annotation($x$y$w$h$name$opt0);
  12344.         if ($this->rtl) {
  12345.             $this->-= $w;
  12346.         } else {
  12347.             $this->+= $w;
  12348.         }
  12349.     }
  12350.     /**
  12351.      * Creates a RadioButton field.
  12352.      * @param string $name Field name.
  12353.      * @param int $w Width of the radio button.
  12354.      * @param array $prop Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12355.      * @param array $opt Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12356.      * @param string $onvalue Value to be returned if selected.
  12357.      * @param boolean $checked Define the initial state.
  12358.      * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12359.      * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12360.      * @param boolean $js If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12361.      * @public
  12362.      * @author Nicola Asuni
  12363.      * @since 4.8.000 (2009-09-07)
  12364.      */
  12365.     public function RadioButton($name$w$prop=array(), $opt=array(), $onvalue='On'$checked=false$x=null$y=null$js=false) {
  12366.         if (TCPDF_STATIC::empty_string($x)) {
  12367.             $x $this->x;
  12368.         }
  12369.         if (TCPDF_STATIC::empty_string($y)) {
  12370.             $y $this->y;
  12371.         }
  12372.         // check page for no-write regions and adapt page margins if necessary
  12373.         list($x$y) = $this->checkPageRegions($w$x$y);
  12374.         if ($js) {
  12375.             $this->_addfield('radiobutton'$name$x$y$w$w$prop);
  12376.             return;
  12377.         }
  12378.         if (TCPDF_STATIC::empty_string($onvalue)) {
  12379.             $onvalue 'On';
  12380.         }
  12381.         if ($checked) {
  12382.             $defval $onvalue;
  12383.         } else {
  12384.             $defval 'Off';
  12385.         }
  12386.         // set font
  12387.         $font 'zapfdingbats';
  12388.         if ($this->pdfa_mode) {
  12389.             // all fonts must be embedded
  12390.             $font 'pdfa'.$font;
  12391.         }
  12392.         $this->AddFont($font);
  12393.         $tmpfont $this->getFontBuffer($font);
  12394.         // set data for parent group
  12395.         if (!isset($this->radiobutton_groups[$this->page])) {
  12396.             $this->radiobutton_groups[$this->page] = array();
  12397.         }
  12398.         if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12399.             $this->radiobutton_groups[$this->page][$name] = array();
  12400.             ++$this->n;
  12401.             $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12402.             $this->radio_groups[] = $this->n;
  12403.         }
  12404.         $kid = ($this->1);
  12405.         // save object ID to be added on Kids entry on parent object
  12406.         $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid'def' => $defval);
  12407.         // get default style
  12408.         $prop array_merge($this->getFormDefaultProp(), $prop);
  12409.         $prop['NoToggleToOff'] = 'true';
  12410.         $prop['Radio'] = 'true';
  12411.         $prop['borderStyle'] = 'inset';
  12412.         // get annotation data
  12413.         $popt TCPDF_STATIC::getAnnotOptFromJSProp($prop$this->spot_colors$this->rtl);
  12414.         // set additional default options
  12415.         $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12416.         $fontstyle sprintf('/F%d %F Tf %s'$tmpfont['i'], $this->FontSizePt$this->TextColor);
  12417.         $popt['da'] = $fontstyle;
  12418.         // build appearance stream
  12419.         $popt['ap'] = array();
  12420.         $popt['ap']['n'] = array();
  12421.         $fx = ((($w $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12422.         $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt 1000) / $this->k)) * $this->k);
  12423.         $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(108).') Tj ET Q'$this->TextColor$tmpfont['i'], $this->FontSizePt$fx$fy);
  12424.         $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(109).') Tj ET Q'$this->TextColor$tmpfont['i'], $this->FontSizePt$fx$fy);
  12425.         if (!isset($popt['mk'])) {
  12426.             $popt['mk'] = array();
  12427.         }
  12428.         $popt['mk']['ca'] = '(l)';
  12429.         // merge options
  12430.         $opt array_merge($popt$opt);
  12431.         // set remaining annotation data
  12432.         $opt['Subtype'] = 'Widget';
  12433.         $opt['ft'] = 'Btn';
  12434.         if ($checked) {
  12435.             $opt['v'] = array('/'.$onvalue);
  12436.             $opt['as'] = $onvalue;
  12437.         } else {
  12438.             $opt['as'] = 'Off';
  12439.         }
  12440.         // store readonly flag
  12441.         if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12442.             $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12443.         }
  12444.         $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12445.         $this->Annotation($x$y$w$w$name$opt0);
  12446.         if ($this->rtl) {
  12447.             $this->-= $w;
  12448.         } else {
  12449.             $this->+= $w;
  12450.         }
  12451.     }
  12452.     /**
  12453.      * Creates a List-box field
  12454.      * @param string $name field name
  12455.      * @param int $w width
  12456.      * @param int $h height
  12457.      * @param array $values array containing the list of values.
  12458.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12459.      * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12460.      * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12461.      * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12462.      * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12463.      * @public
  12464.      * @author Nicola Asuni
  12465.      * @since 4.8.000 (2009-09-07)
  12466.      */
  12467.     public function ListBox($name$w$h$values$prop=array(), $opt=array(), $x=null$y=null$js=false) {
  12468.         if (TCPDF_STATIC::empty_string($x)) {
  12469.             $x $this->x;
  12470.         }
  12471.         if (TCPDF_STATIC::empty_string($y)) {
  12472.             $y $this->y;
  12473.         }
  12474.         // check page for no-write regions and adapt page margins if necessary
  12475.         list($x$y) = $this->checkPageRegions($h$x$y);
  12476.         if ($js) {
  12477.             $this->_addfield('listbox'$name$x$y$w$h$prop);
  12478.             $s '';
  12479.             foreach ($values as $value) {
  12480.                 if (is_array($value)) {
  12481.                     $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12482.                 } else {
  12483.                     $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12484.                 }
  12485.             }
  12486.             $this->javascript .= 'f'.$name.'.setItems('.substr($s1).');'."\n";
  12487.             return;
  12488.         }
  12489.         // get default style
  12490.         $prop array_merge($this->getFormDefaultProp(), $prop);
  12491.         // get annotation data
  12492.         $popt TCPDF_STATIC::getAnnotOptFromJSProp($prop$this->spot_colors$this->rtl);
  12493.         // set additional default values
  12494.         $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12495.         $fontstyle sprintf('/F%d %F Tf %s'$this->CurrentFont['i'], $this->FontSizePt$this->TextColor);
  12496.         $popt['da'] = $fontstyle;
  12497.         // build appearance stream
  12498.         $popt['ap'] = array();
  12499.         $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12500.         $text '';
  12501.         foreach($values as $item) {
  12502.             if (is_array($item)) {
  12503.                 $text .= $item[1]."\n";
  12504.             } else {
  12505.                 $text .= $item."\n";
  12506.             }
  12507.         }
  12508.         $tmpid $this->startTemplate($w$hfalse);
  12509.         $this->MultiCell($w$h$text0''false000true0falsetrue0'T'false);
  12510.         $this->endTemplate();
  12511.         --$this->n;
  12512.         $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12513.         unset($this->xobjects[$tmpid]);
  12514.         $popt['ap']['n'] .= 'Q EMC';
  12515.         // merge options
  12516.         $opt array_merge($popt$opt);
  12517.         // set remaining annotation data
  12518.         $opt['Subtype'] = 'Widget';
  12519.         $opt['ft'] = 'Ch';
  12520.         $opt['t'] = $name;
  12521.         $opt['opt'] = $values;
  12522.         unset($opt['mk']['ca']);
  12523.         unset($opt['mk']['rc']);
  12524.         unset($opt['mk']['ac']);
  12525.         unset($opt['mk']['i']);
  12526.         unset($opt['mk']['ri']);
  12527.         unset($opt['mk']['ix']);
  12528.         unset($opt['mk']['if']);
  12529.         unset($opt['mk']['tp']);
  12530.         $this->Annotation($x$y$w$h$name$opt0);
  12531.         if ($this->rtl) {
  12532.             $this->-= $w;
  12533.         } else {
  12534.             $this->+= $w;
  12535.         }
  12536.     }
  12537.     /**
  12538.      * Creates a Combo-box field
  12539.      * @param string $name field name
  12540.      * @param int $w width
  12541.      * @param int $h height
  12542.      * @param array $values array containing the list of values.
  12543.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12544.      * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12545.      * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12546.      * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12547.      * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12548.      * @public
  12549.      * @author Nicola Asuni
  12550.      * @since 4.8.000 (2009-09-07)
  12551.      */
  12552.     public function ComboBox($name$w$h$values$prop=array(), $opt=array(), $x=null$y=null$js=false) {
  12553.         if (TCPDF_STATIC::empty_string($x)) {
  12554.             $x $this->x;
  12555.         }
  12556.         if (TCPDF_STATIC::empty_string($y)) {
  12557.             $y $this->y;
  12558.         }
  12559.         // check page for no-write regions and adapt page margins if necessary
  12560.         list($x$y) = $this->checkPageRegions($h$x$y);
  12561.         if ($js) {
  12562.             $this->_addfield('combobox'$name$x$y$w$h$prop);
  12563.             $s '';
  12564.             foreach ($values as $value) {
  12565.                 if (is_array($value)) {
  12566.                     $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12567.                 } else {
  12568.                     $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12569.                 }
  12570.             }
  12571.             $this->javascript .= 'f'.$name.'.setItems('.substr($s1).');'."\n";
  12572.             return;
  12573.         }
  12574.         // get default style
  12575.         $prop array_merge($this->getFormDefaultProp(), $prop);
  12576.         $prop['Combo'] = true;
  12577.         // get annotation data
  12578.         $popt TCPDF_STATIC::getAnnotOptFromJSProp($prop$this->spot_colors$this->rtl);
  12579.         // set additional default options
  12580.         $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12581.         $fontstyle sprintf('/F%d %F Tf %s'$this->CurrentFont['i'], $this->FontSizePt$this->TextColor);
  12582.         $popt['da'] = $fontstyle;
  12583.         // build appearance stream
  12584.         $popt['ap'] = array();
  12585.         $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12586.         $text '';
  12587.         foreach($values as $item) {
  12588.             if (is_array($item)) {
  12589.                 $text .= $item[1]."\n";
  12590.             } else {
  12591.                 $text .= $item."\n";
  12592.             }
  12593.         }
  12594.         $tmpid $this->startTemplate($w$hfalse);
  12595.         $this->MultiCell($w$h$text0''false000true0falsetrue0'T'false);
  12596.         $this->endTemplate();
  12597.         --$this->n;
  12598.         $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12599.         unset($this->xobjects[$tmpid]);
  12600.         $popt['ap']['n'] .= 'Q EMC';
  12601.         // merge options
  12602.         $opt array_merge($popt$opt);
  12603.         // set remaining annotation data
  12604.         $opt['Subtype'] = 'Widget';
  12605.         $opt['ft'] = 'Ch';
  12606.         $opt['t'] = $name;
  12607.         $opt['opt'] = $values;
  12608.         unset($opt['mk']['ca']);
  12609.         unset($opt['mk']['rc']);
  12610.         unset($opt['mk']['ac']);
  12611.         unset($opt['mk']['i']);
  12612.         unset($opt['mk']['ri']);
  12613.         unset($opt['mk']['ix']);
  12614.         unset($opt['mk']['if']);
  12615.         unset($opt['mk']['tp']);
  12616.         $this->Annotation($x$y$w$h$name$opt0);
  12617.         if ($this->rtl) {
  12618.             $this->-= $w;
  12619.         } else {
  12620.             $this->+= $w;
  12621.         }
  12622.     }
  12623.     /**
  12624.      * Creates a CheckBox field
  12625.      * @param string $name field name
  12626.      * @param int $w width
  12627.      * @param boolean $checked define the initial state.
  12628.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12629.      * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12630.      * @param string $onvalue value to be returned if selected.
  12631.      * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12632.      * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12633.      * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12634.      * @public
  12635.      * @author Nicola Asuni
  12636.      * @since 4.8.000 (2009-09-07)
  12637.      */
  12638.     public function CheckBox($name$w$checked=false$prop=array(), $opt=array(), $onvalue='Yes'$x=null$y=null$js=false) {
  12639.         if (TCPDF_STATIC::empty_string($x)) {
  12640.             $x $this->x;
  12641.         }
  12642.         if (TCPDF_STATIC::empty_string($y)) {
  12643.             $y $this->y;
  12644.         }
  12645.         // check page for no-write regions and adapt page margins if necessary
  12646.         list($x$y) = $this->checkPageRegions($w$x$y);
  12647.         if ($js) {
  12648.             $this->_addfield('checkbox'$name$x$y$w$w$prop);
  12649.             return;
  12650.         }
  12651.         if (!isset($prop['value'])) {
  12652.             $prop['value'] = array('Yes');
  12653.         }
  12654.         // get default style
  12655.         $prop array_merge($this->getFormDefaultProp(), $prop);
  12656.         $prop['borderStyle'] = 'inset';
  12657.         // get annotation data
  12658.         $popt TCPDF_STATIC::getAnnotOptFromJSProp($prop$this->spot_colors$this->rtl);
  12659.         // set additional default options
  12660.         $font 'zapfdingbats';
  12661.         if ($this->pdfa_mode) {
  12662.             // all fonts must be embedded
  12663.             $font 'pdfa'.$font;
  12664.         }
  12665.         $this->AddFont($font);
  12666.         $tmpfont $this->getFontBuffer($font);
  12667.         $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12668.         $fontstyle sprintf('/F%d %F Tf %s'$tmpfont['i'], $this->FontSizePt$this->TextColor);
  12669.         $popt['da'] = $fontstyle;
  12670.         // build appearance stream
  12671.         $popt['ap'] = array();
  12672.         $popt['ap']['n'] = array();
  12673.         $fx = ((($w $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12674.         $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt 1000) / $this->k)) * $this->k);
  12675.         $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(110).') Tj ET Q'$this->TextColor$tmpfont['i'], $this->FontSizePt$fx$fy);
  12676.         $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(111).') Tj ET Q'$this->TextColor$tmpfont['i'], $this->FontSizePt$fx$fy);
  12677.         // merge options
  12678.         $opt array_merge($popt$opt);
  12679.         // set remaining annotation data
  12680.         $opt['Subtype'] = 'Widget';
  12681.         $opt['ft'] = 'Btn';
  12682.         $opt['t'] = $name;
  12683.         if (TCPDF_STATIC::empty_string($onvalue)) {
  12684.             $onvalue 'Yes';
  12685.         }
  12686.         $opt['opt'] = array($onvalue);
  12687.         if ($checked) {
  12688.             $opt['v'] = array('/Yes');
  12689.             $opt['as'] = 'Yes';
  12690.         } else {
  12691.             $opt['v'] = array('/Off');
  12692.             $opt['as'] = 'Off';
  12693.         }
  12694.         $this->Annotation($x$y$w$w$name$opt0);
  12695.         if ($this->rtl) {
  12696.             $this->-= $w;
  12697.         } else {
  12698.             $this->+= $w;
  12699.         }
  12700.     }
  12701.     /**
  12702.      * Creates a button field
  12703.      * @param string $name field name
  12704.      * @param int $w width
  12705.      * @param int $h height
  12706.      * @param string $caption caption.
  12707.      * @param mixed $action action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008.
  12708.      * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12709.      * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12710.      * @param float|null $x Abscissa of the upper-left corner of the rectangle
  12711.      * @param float|null $y Ordinate of the upper-left corner of the rectangle
  12712.      * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12713.      * @public
  12714.      * @author Nicola Asuni
  12715.      * @since 4.8.000 (2009-09-07)
  12716.      */
  12717.     public function Button($name$w$h$caption$action$prop=array(), $opt=array(), $x=null$y=null$js=false) {
  12718.         if (TCPDF_STATIC::empty_string($x)) {
  12719.             $x $this->x;
  12720.         }
  12721.         if (TCPDF_STATIC::empty_string($y)) {
  12722.             $y $this->y;
  12723.         }
  12724.         // check page for no-write regions and adapt page margins if necessary
  12725.         list($x$y) = $this->checkPageRegions($h$x$y);
  12726.         if ($js) {
  12727.             $this->_addfield('button'$name$this->x$this->y$w$h$prop);
  12728.             $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12729.             $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12730.             $this->javascript .= 'f'.$name.".highlight='push';\n";
  12731.             $this->javascript .= 'f'.$name.".print=false;\n";
  12732.             return;
  12733.         }
  12734.         // get default style
  12735.         $prop array_merge($this->getFormDefaultProp(), $prop);
  12736.         $prop['Pushbutton'] = 'true';
  12737.         $prop['highlight'] = 'push';
  12738.         $prop['display'] = 'display.noPrint';
  12739.         // get annotation data
  12740.         $popt TCPDF_STATIC::getAnnotOptFromJSProp($prop$this->spot_colors$this->rtl);
  12741.         $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12742.         $fontstyle sprintf('/F%d %F Tf %s'$this->CurrentFont['i'], $this->FontSizePt$this->TextColor);
  12743.         $popt['da'] = $fontstyle;
  12744.         // build appearance stream
  12745.         $popt['ap'] = array();
  12746.         $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12747.         $tmpid $this->startTemplate($w$hfalse);
  12748.         $bw = ($this->k); // border width
  12749.         $border = array(
  12750.             'L' => array('width' => $bw'cap' => 'square''join' => 'miter''dash' => 0'color' => array(231)),
  12751.             'R' => array('width' => $bw'cap' => 'square''join' => 'miter''dash' => 0'color' => array(51)),
  12752.             'T' => array('width' => $bw'cap' => 'square''join' => 'miter''dash' => 0'color' => array(231)),
  12753.             'B' => array('width' => $bw'cap' => 'square''join' => 'miter''dash' => 0'color' => array(51)));
  12754.         $this->setFillColor(204);
  12755.         $this->Cell($w$h$caption$border0'C'true''1false'T''M');
  12756.         $this->endTemplate();
  12757.         --$this->n;
  12758.         $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12759.         unset($this->xobjects[$tmpid]);
  12760.         $popt['ap']['n'] .= 'Q EMC';
  12761.         // set additional default options
  12762.         if (!isset($popt['mk'])) {
  12763.             $popt['mk'] = array();
  12764.         }
  12765.         $ann_obj_id = ($this->1);
  12766.         if (!empty($action) AND !is_array($action)) {
  12767.             $ann_obj_id = ($this->2);
  12768.         }
  12769.         $popt['mk']['ca'] = $this->_textstring($caption$ann_obj_id);
  12770.         $popt['mk']['rc'] = $this->_textstring($caption$ann_obj_id);
  12771.         $popt['mk']['ac'] = $this->_textstring($caption$ann_obj_id);
  12772.         // merge options
  12773.         $opt array_merge($popt$opt);
  12774.         // set remaining annotation data
  12775.         $opt['Subtype'] = 'Widget';
  12776.         $opt['ft'] = 'Btn';
  12777.         $opt['t'] = $caption;
  12778.         $opt['v'] = $name;
  12779.         if (!empty($action)) {
  12780.             if (is_array($action)) {
  12781.                 // form action options as on section 12.7.5 of PDF32000_2008.
  12782.                 $opt['aa'] = '/D <<';
  12783.                 $bmode = array('SubmitForm''ResetForm''ImportData');
  12784.                 foreach ($action AS $key => $val) {
  12785.                     if (($key == 'S') AND in_array($val$bmode)) {
  12786.                         $opt['aa'] .= ' /S /'.$val;
  12787.                     } elseif (($key == 'F') AND (!empty($val))) {
  12788.                         $opt['aa'] .= ' /F '.$this->_datastring($val$ann_obj_id);
  12789.                     } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12790.                         $opt['aa'] .= ' /Fields [';
  12791.                         foreach ($val AS $field) {
  12792.                             $opt['aa'] .= ' '.$this->_textstring($field$ann_obj_id);
  12793.                         }
  12794.                         $opt['aa'] .= ']';
  12795.                     } elseif (($key == 'Flags')) {
  12796.                         $ff 0;
  12797.                         if (is_array($val)) {
  12798.                             foreach ($val AS $flag) {
  12799.                                 switch ($flag) {
  12800.                                     case 'Include/Exclude': {
  12801.                                         $ff += << 0;
  12802.                                         break;
  12803.                                     }
  12804.                                     case 'IncludeNoValueFields': {
  12805.                                         $ff += << 1;
  12806.                                         break;
  12807.                                     }
  12808.                                     case 'ExportFormat': {
  12809.                                         $ff += << 2;
  12810.                                         break;
  12811.                                     }
  12812.                                     case 'GetMethod': {
  12813.                                         $ff += << 3;
  12814.                                         break;
  12815.                                     }
  12816.                                     case 'SubmitCoordinates': {
  12817.                                         $ff += << 4;
  12818.                                         break;
  12819.                                     }
  12820.                                     case 'XFDF': {
  12821.                                         $ff += << 5;
  12822.                                         break;
  12823.                                     }
  12824.                                     case 'IncludeAppendSaves': {
  12825.                                         $ff += << 6;
  12826.                                         break;
  12827.                                     }
  12828.                                     case 'IncludeAnnotations': {
  12829.                                         $ff += << 7;
  12830.                                         break;
  12831.                                     }
  12832.                                     case 'SubmitPDF': {
  12833.                                         $ff += << 8;
  12834.                                         break;
  12835.                                     }
  12836.                                     case 'CanonicalFormat': {
  12837.                                         $ff += << 9;
  12838.                                         break;
  12839.                                     }
  12840.                                     case 'ExclNonUserAnnots': {
  12841.                                         $ff += << 10;
  12842.                                         break;
  12843.                                     }
  12844.                                     case 'ExclFKey': {
  12845.                                         $ff += << 11;
  12846.                                         break;
  12847.                                     }
  12848.                                     case 'EmbedForm': {
  12849.                                         $ff += << 13;
  12850.                                         break;
  12851.                                     }
  12852.                                 }
  12853.                             }
  12854.                         } else {
  12855.                             $ff intval($val);
  12856.                         }
  12857.                         $opt['aa'] .= ' /Flags '.$ff;
  12858.                     }
  12859.                 }
  12860.                 $opt['aa'] .= ' >>';
  12861.             } else {
  12862.                 // Javascript action or raw action command
  12863.                 $js_obj_id $this->addJavascriptObject($action);
  12864.                 $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  12865.             }
  12866.         }
  12867.         $this->Annotation($x$y$w$h$name$opt0);
  12868.         if ($this->rtl) {
  12869.             $this->-= $w;
  12870.         } else {
  12871.             $this->+= $w;
  12872.         }
  12873.     }
  12874.     // --- END FORMS FIELDS ------------------------------------------------
  12875.     /**
  12876.      * Add certification signature (DocMDP or UR3)
  12877.      * You can set only one signature type
  12878.      * @protected
  12879.      * @author Nicola Asuni
  12880.      * @since 4.6.008 (2009-05-07)
  12881.      */
  12882.     protected function _putsignature() {
  12883.         if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  12884.             return;
  12885.         }
  12886.         $sigobjid = ($this->sig_obj_id 1);
  12887.         $out $this->_getobj($sigobjid)."\n";
  12888.         $out .= '<< /Type /Sig';
  12889.         $out .= ' /Filter /Adobe.PPKLite';
  12890.         $out .= ' /SubFilter /adbe.pkcs7.detached';
  12891.         $out .= ' '.TCPDF_STATIC::$byterange_string;
  12892.         $out .= ' /Contents<'.str_repeat('0'$this->signature_max_length).'>';
  12893.         if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
  12894.             $out .= ' /Reference ['// array of signature reference dictionaries
  12895.             $out .= ' << /Type /SigRef';
  12896.             if ($this->signature_data['cert_type'] > 0) {
  12897.                 $out .= ' /TransformMethod /DocMDP';
  12898.                 $out .= ' /TransformParams <<';
  12899.                 $out .= ' /Type /TransformParams';
  12900.                 $out .= ' /P '.$this->signature_data['cert_type'];
  12901.                 $out .= ' /V /1.2';
  12902.             } else {
  12903.                 $out .= ' /TransformMethod /UR3';
  12904.                 $out .= ' /TransformParams <<';
  12905.                 $out .= ' /Type /TransformParams';
  12906.                 $out .= ' /V /2.2';
  12907.                 if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  12908.                     $out .= ' /Document['.$this->ur['document'].']';
  12909.                 }
  12910.                 if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  12911.                     $out .= ' /Form['.$this->ur['form'].']';
  12912.                 }
  12913.                 if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  12914.                     $out .= ' /Signature['.$this->ur['signature'].']';
  12915.                 }
  12916.                 if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  12917.                     $out .= ' /Annots['.$this->ur['annots'].']';
  12918.                 }
  12919.                 if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  12920.                     $out .= ' /EF['.$this->ur['ef'].']';
  12921.                 }
  12922.                 if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  12923.                     $out .= ' /FormEX['.$this->ur['formex'].']';
  12924.                 }
  12925.             }
  12926.             $out .= ' >>'// close TransformParams
  12927.             // optional digest data (values must be calculated and replaced later)
  12928.             //$out .= ' /Data ********** 0 R';
  12929.             //$out .= ' /DigestMethod/MD5';
  12930.             //$out .= ' /DigestLocation[********** 34]';
  12931.             //$out .= ' /DigestValue<********************************>';
  12932.             $out .= ' >>';
  12933.             $out .= ' ]'// end of reference
  12934.         }
  12935.         if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  12936.             $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  12937.         }
  12938.         if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  12939.             $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  12940.         }
  12941.         if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  12942.             $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  12943.         }
  12944.         if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  12945.             $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  12946.         }
  12947.         $out .= ' /M '.$this->_datestring($sigobjid$this->doc_modification_timestamp);
  12948.         $out .= ' >>';
  12949.         $out .= "\n".'endobj';
  12950.         $this->_out($out);
  12951.     }
  12952.     /**
  12953.      * Set User's Rights for PDF Reader
  12954.      * WARNING: This is experimental and currently do not work.
  12955.      * Check the PDF Reference 8.7.1 Transform Methods,
  12956.      * Table 8.105 Entries in the UR transform parameters dictionary
  12957.      * @param boolean $enable if true enable user's rights on PDF reader
  12958.      * @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.
  12959.      * @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.
  12960.      * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  12961.      * @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.
  12962.      * @param string $ef Names specifying additional usage rights for named embedded files in the document. Valid names are /Create/Delete/Modify/Import, which permit the user to perform the named operation on named embedded files
  12963.      Names specifying additional embedded-files-related usage rights for the document.
  12964.      * @param string $formex Names specifying additional form-field-related usage rights. The only valid name is BarcodePlaintext, which permits text form field data to be encoded as a plaintext two-dimensional barcode.
  12965.      * @public
  12966.      * @author Nicola Asuni
  12967.      * @since 2.9.000 (2008-03-26)
  12968.      */
  12969.     public function setUserRights(
  12970.             $enable=true,
  12971.             $document='/FullSave',
  12972.             $annots='/Create/Delete/Modify/Copy/Import/Export',
  12973.             $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  12974.             $signature='/Modify',
  12975.             $ef='/Create/Delete/Modify/Import',
  12976.             $formex='') {
  12977.         $this->ur['enabled'] = $enable;
  12978.         $this->ur['document'] = $document;
  12979.         $this->ur['annots'] = $annots;
  12980.         $this->ur['form'] = $form;
  12981.         $this->ur['signature'] = $signature;
  12982.         $this->ur['ef'] = $ef;
  12983.         $this->ur['formex'] = $formex;
  12984.         if (!$this->sign) {
  12985.             $this->setSignature(''''''''0, array());
  12986.         }
  12987.     }
  12988.     /**
  12989.      * Enable document signature (requires the OpenSSL Library).
  12990.      * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  12991.      * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12992.      * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12993.      * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  12994.      * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
  12995.      * @param mixed $private_key private key (string or filename prefixed with 'file://')
  12996.      * @param string $private_key_password password
  12997.      * @param string $extracerts specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.
  12998.      * @param int $cert_type The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
  12999.      * @param array $info array of option information: Name, Location, Reason, ContactInfo.
  13000.      * @param string $approval Enable approval signature eg. for PDF incremental update
  13001.      * @public
  13002.      * @author Nicola Asuni
  13003.      * @since 4.6.005 (2009-04-24)
  13004.      */
  13005.     public function setSignature($signing_cert=''$private_key=''$private_key_password=''$extracerts=''$cert_type=2$info=array(), $approval='') {
  13006.         // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  13007.         // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  13008.         // to convert pfx certificate to pem: openssl
  13009.         //     OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  13010.         $this->sign true;
  13011.         ++$this->n;
  13012.         $this->sig_obj_id $this->n// signature widget
  13013.         ++$this->n// signature object ($this->sig_obj_id + 1)
  13014.         $this->signature_data = array();
  13015.         if (strlen($signing_cert) == 0) {
  13016.             $this->Error('Please provide a certificate file and password!');
  13017.         }
  13018.         if (strlen($private_key) == 0) {
  13019.             $private_key $signing_cert;
  13020.         }
  13021.         $this->signature_data['signcert'] = $signing_cert;
  13022.         $this->signature_data['privkey'] = $private_key;
  13023.         $this->signature_data['password'] = $private_key_password;
  13024.         $this->signature_data['extracerts'] = $extracerts;
  13025.         $this->signature_data['cert_type'] = $cert_type;
  13026.         $this->signature_data['info'] = $info;
  13027.         $this->signature_data['approval'] = $approval;
  13028.     }
  13029.     /**
  13030.      * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  13031.      * @param float $x Abscissa of the upper-left corner.
  13032.      * @param float $y Ordinate of the upper-left corner.
  13033.      * @param float $w Width of the signature area.
  13034.      * @param float $h Height of the signature area.
  13035.      * @param int $page option page number (if < 0 the current page is used).
  13036.      * @param string $name Name of the signature.
  13037.      * @public
  13038.      * @author Nicola Asuni
  13039.      * @since 5.3.011 (2010-06-17)
  13040.      */
  13041.     public function setSignatureAppearance($x=0$y=0$w=0$h=0$page=-1$name='') {
  13042.         $this->signature_appearance $this->getSignatureAppearanceArray($x$y$w$h$page$name);
  13043.     }
  13044.     /**
  13045.      * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  13046.      * @param float $x Abscissa of the upper-left corner.
  13047.      * @param float $y Ordinate of the upper-left corner.
  13048.      * @param float $w Width of the signature area.
  13049.      * @param float $h Height of the signature area.
  13050.      * @param int $page option page number (if < 0 the current page is used).
  13051.      * @param string $name Name of the signature.
  13052.      * @public
  13053.      * @author Nicola Asuni
  13054.      * @since 5.9.101 (2011-07-06)
  13055.      */
  13056.     public function addEmptySignatureAppearance($x=0$y=0$w=0$h=0$page=-1$name='') {
  13057.         ++$this->n;
  13058.         $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x$y$w$h$page$name);
  13059.     }
  13060.     /**
  13061.      * Get the array that defines the signature appearance (page and rectangle coordinates).
  13062.      * @param float $x Abscissa of the upper-left corner.
  13063.      * @param float $y Ordinate of the upper-left corner.
  13064.      * @param float $w Width of the signature area.
  13065.      * @param float $h Height of the signature area.
  13066.      * @param int $page option page number (if < 0 the current page is used).
  13067.      * @param string $name Name of the signature.
  13068.      * @return array Array defining page and rectangle coordinates of signature appearance.
  13069.      * @protected
  13070.      * @author Nicola Asuni
  13071.      * @since 5.9.101 (2011-07-06)
  13072.      */
  13073.     protected function getSignatureAppearanceArray($x=0$y=0$w=0$h=0$page=-1$name='') {
  13074.         $sigapp = array();
  13075.         if (($page 1) OR ($page $this->numpages)) {
  13076.             $sigapp['page'] = $this->page;
  13077.         } else {
  13078.             $sigapp['page'] = intval($page);
  13079.         }
  13080.         if (empty($name)) {
  13081.             $sigapp['name'] = 'Signature';
  13082.         } else {
  13083.             $sigapp['name'] = $name;
  13084.         }
  13085.         $a $x $this->k;
  13086.         $b $this->pagedim[($sigapp['page'])]['h'] - (($y $h) * $this->k);
  13087.         $c $w $this->k;
  13088.         $d $h $this->k;
  13089.         $sigapp['rect'] = sprintf('%F %F %F %F'$a$b, ($a $c), ($b $d));
  13090.         return $sigapp;
  13091.     }
  13092.     /**
  13093.      * Enable document timestamping (requires the OpenSSL Library).
  13094.      * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
  13095.      * Use with digital signature only!
  13096.      * @param string $tsa_host Time Stamping Authority (TSA) server (prefixed with 'https://')
  13097.      * @param string $tsa_username Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
  13098.      * @param string $tsa_password Specifies the password for TSA authorization (optional)
  13099.      * @param string $tsa_cert Specifies the location of TSA certificate for authorization (optional for cURL)
  13100.      * @public
  13101.      * @author Richard Stockinger
  13102.      * @since 6.0.090 (2014-06-16)
  13103.      */
  13104.     public function setTimeStamp($tsa_host=''$tsa_username=''$tsa_password=''$tsa_cert='') {
  13105.         $this->tsa_data = array();
  13106.         if (!function_exists('curl_init')) {
  13107.             $this->Error('Please enable cURL PHP extension!');
  13108.         }
  13109.         if (strlen($tsa_host) == 0) {
  13110.             $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
  13111.         }
  13112.         $this->tsa_data['tsa_host'] = $tsa_host;
  13113.         if (is_file($tsa_username)) {
  13114.             $this->tsa_data['tsa_auth'] = $tsa_username;
  13115.         } else {
  13116.             $this->tsa_data['tsa_username'] = $tsa_username;
  13117.         }
  13118.         $this->tsa_data['tsa_password'] = $tsa_password;
  13119.         $this->tsa_data['tsa_cert'] = $tsa_cert;
  13120.         $this->tsa_timestamp true;
  13121.     }
  13122.     /**
  13123.      * NOT YET IMPLEMENTED
  13124.      * Request TSA for a timestamp
  13125.      * @param string $signature Digital signature as binary string
  13126.      * @return string Timestamped digital signature
  13127.      * @protected
  13128.      * @author Richard Stockinger
  13129.      * @since 6.0.090 (2014-06-16)
  13130.      */
  13131.     protected function applyTSA($signature) {
  13132.         if (!$this->tsa_timestamp) {
  13133.             return $signature;
  13134.         }
  13135.         //@TODO: implement this feature
  13136.         return $signature;
  13137.     }
  13138.     /**
  13139.      * Create a new page group.
  13140.      * NOTE: call this function before calling AddPage()
  13141.      * @param int|null $page starting group page (leave empty for next page).
  13142.      * @public
  13143.      * @since 3.0.000 (2008-03-27)
  13144.      */
  13145.     public function startPageGroup($page=null) {
  13146.         if (empty($page)) {
  13147.             $page $this->page 1;
  13148.         }
  13149.         $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  13150.     }
  13151.     /**
  13152.      * Set the starting page number.
  13153.      * @param int $num Starting page number.
  13154.      * @since 5.9.093 (2011-06-16)
  13155.      * @public
  13156.      */
  13157.     public function setStartingPageNumber($num=1) {
  13158.         $this->starting_page_number max(0intval($num));
  13159.     }
  13160.     /**
  13161.      * Returns the string alias used right align page numbers.
  13162.      * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  13163.      * @return string
  13164.      * @since 5.9.099 (2011-06-27)
  13165.      * @public
  13166.      */
  13167.     public function getAliasRightShift() {
  13168.         // calculate aproximatively the ratio between widths of aliases and replacements.
  13169.         $ref '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  13170.         $rep str_repeat(' '$this->GetNumChars($ref));
  13171.         $wrep $this->GetStringWidth($rep);
  13172.         if ($wrep 0) {
  13173.             $wdiff max(1, ($this->GetStringWidth($ref) / $wrep));
  13174.         } else {
  13175.             $wdiff 1;
  13176.         }
  13177.         $sdiff sprintf('%F'$wdiff);
  13178.         $alias TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  13179.         if ($this->isUnicodeFont()) {
  13180.             $alias '{'.$alias;
  13181.         }
  13182.         return $alias;
  13183.     }
  13184.     /**
  13185.      * Returns the string alias used for the total number of pages.
  13186.      * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13187.      * This alias will be replaced by the total number of pages in the document.
  13188.      * @return string
  13189.      * @since 4.0.018 (2008-08-08)
  13190.      * @public
  13191.      */
  13192.     public function getAliasNbPages() {
  13193.         if ($this->isUnicodeFont()) {
  13194.             return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13195.         }
  13196.         return TCPDF_STATIC::$alias_tot_pages;
  13197.     }
  13198.     /**
  13199.      * Returns the string alias used for the page number.
  13200.      * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13201.      * This alias will be replaced by the page number.
  13202.      * @return string
  13203.      * @since 4.5.000 (2009-01-02)
  13204.      * @public
  13205.      */
  13206.     public function getAliasNumPage() {
  13207.         if ($this->isUnicodeFont()) {
  13208.             return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13209.         }
  13210.         return TCPDF_STATIC::$alias_num_page;
  13211.     }
  13212.     /**
  13213.      * Return the alias for the total number of pages in the current page group.
  13214.      * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13215.      * This alias will be replaced by the total number of pages in this group.
  13216.      * @return string alias of the current page group
  13217.      * @public
  13218.      * @since 3.0.000 (2008-03-27)
  13219.      */
  13220.     public function getPageGroupAlias() {
  13221.         if ($this->isUnicodeFont()) {
  13222.             return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13223.         }
  13224.         return TCPDF_STATIC::$alias_group_tot_pages;
  13225.     }
  13226.     /**
  13227.      * Return the alias for the page number on the current page group.
  13228.      * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13229.      * This alias will be replaced by the page number (relative to the belonging group).
  13230.      * @return string alias of the current page group
  13231.      * @public
  13232.      * @since 4.5.000 (2009-01-02)
  13233.      */
  13234.     public function getPageNumGroupAlias() {
  13235.         if ($this->isUnicodeFont()) {
  13236.             return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13237.         }
  13238.         return TCPDF_STATIC::$alias_group_num_page;
  13239.     }
  13240.     /**
  13241.      * Return the current page in the group.
  13242.      * @return int current page in the group
  13243.      * @public
  13244.      * @since 3.0.000 (2008-03-27)
  13245.      */
  13246.     public function getGroupPageNo() {
  13247.         return $this->pagegroups[$this->currpagegroup];
  13248.     }
  13249.     /**
  13250.      * Returns the current group page number formatted as a string.
  13251.      * @public
  13252.      * @since 4.3.003 (2008-11-18)
  13253.      * @see PaneNo(), formatPageNumber()
  13254.      */
  13255.     public function getGroupPageNoFormatted() {
  13256.         return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13257.     }
  13258.     /**
  13259.      * Returns the current page number formatted as a string.
  13260.      * @public
  13261.      * @since 4.2.005 (2008-11-06)
  13262.      * @see PaneNo(), formatPageNumber()
  13263.      */
  13264.     public function PageNoFormatted() {
  13265.         return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13266.     }
  13267.     /**
  13268.      * Put pdf layers.
  13269.      * @protected
  13270.      * @since 3.0.000 (2008-03-27)
  13271.      */
  13272.     protected function _putocg() {
  13273.         if (empty($this->pdflayers)) {
  13274.             return;
  13275.         }
  13276.         foreach ($this->pdflayers as $key => $layer) {
  13277.              $this->pdflayers[$key]['objid'] = $this->_newobj();
  13278.              $out '<< /Type /OCG';
  13279.              $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13280.              $out .= ' /Usage <<';
  13281.              if (isset($layer['print']) AND ($layer['print'] !== NULL)) {
  13282.                 $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13283.              }
  13284.              $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13285.              $out .= ' >> >>';
  13286.              $out .= "\n".'endobj';
  13287.              $this->_out($out);
  13288.         }
  13289.     }
  13290.     /**
  13291.      * Start a new pdf layer.
  13292.      * @param string $name Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13293.      * @param boolean|null $print Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
  13294.      * @param boolean $view Set to true to view this layer.
  13295.      * @param boolean $lock If true lock the layer
  13296.      * @public
  13297.      * @since 5.9.102 (2011-07-13)
  13298.      */
  13299.     public function startLayer($name=''$print=true$view=true$lock=true) {
  13300.         if ($this->state != 2) {
  13301.             return;
  13302.         }
  13303.         $layer sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13304.         if (empty($name)) {
  13305.             $name $layer;
  13306.         } else {
  13307.             $name preg_replace('/[^a-zA-Z0-9_\-]/'''$name);
  13308.         }
  13309.         $this->pdflayers[] = array('layer' => $layer'name' => $name'print' => $print'view' => $view'lock' => $lock);
  13310.         $this->openMarkedContent true;
  13311.         $this->_out('/OC /'.$layer.' BDC');
  13312.     }
  13313.     /**
  13314.      * End the current PDF layer.
  13315.      * @public
  13316.      * @since 5.9.102 (2011-07-13)
  13317.      */
  13318.     public function endLayer() {
  13319.         if ($this->state != 2) {
  13320.             return;
  13321.         }
  13322.         if ($this->openMarkedContent) {
  13323.             // close existing open marked-content layer
  13324.             $this->_out('EMC');
  13325.             $this->openMarkedContent false;
  13326.         }
  13327.     }
  13328.     /**
  13329.      * Set the visibility of the successive elements.
  13330.      * This can be useful, for instance, to put a background
  13331.      * image or color that will show on screen but won't print.
  13332.      * @param string $v visibility mode. Legal values are: all, print, screen or view.
  13333.      * @public
  13334.      * @since 3.0.000 (2008-03-27)
  13335.      */
  13336.     public function setVisibility($v) {
  13337.         if ($this->state != 2) {
  13338.             return;
  13339.         }
  13340.         $this->endLayer();
  13341.         switch($v) {
  13342.             case 'print': {
  13343.                 $this->startLayer('Print'truefalse);
  13344.                 break;
  13345.             }
  13346.             case 'view':
  13347.             case 'screen': {
  13348.                 $this->startLayer('View'falsetrue);
  13349.                 break;
  13350.             }
  13351.             case 'all': {
  13352.                 $this->_out('');
  13353.                 break;
  13354.             }
  13355.             default: {
  13356.                 $this->Error('Incorrect visibility: '.$v);
  13357.                 break;
  13358.             }
  13359.         }
  13360.     }
  13361.     /**
  13362.      * Add transparency parameters to the current extgstate
  13363.      * @param array $parms parameters
  13364.      * @return int|void the number of extgstates
  13365.      * @protected
  13366.      * @since 3.0.000 (2008-03-27)
  13367.      */
  13368.     protected function addExtGState($parms) {
  13369.         if ($this->pdfa_mode || $this->pdfa_version >= 2) {
  13370.             // transparencies are not allowed in PDF/A mode
  13371.             return;
  13372.         }
  13373.         // check if this ExtGState already exist
  13374.         foreach ($this->extgstates as $i => $ext) {
  13375.             if ($ext['parms'] == $parms) {
  13376.                 if ($this->inxobj) {
  13377.                     // we are inside an XObject template
  13378.                     $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13379.                 }
  13380.                 // return reference to existing ExtGState
  13381.                 return $i;
  13382.             }
  13383.         }
  13384.         $n = (count($this->extgstates) + 1);
  13385.         $this->extgstates[$n] = array('parms' => $parms);
  13386.         if ($this->inxobj) {
  13387.             // we are inside an XObject template
  13388.             $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13389.         }
  13390.         return $n;
  13391.     }
  13392.     /**
  13393.      * Add an extgstate
  13394.      * @param int $gs extgstate
  13395.      * @protected
  13396.      * @since 3.0.000 (2008-03-27)
  13397.      */
  13398.     protected function setExtGState($gs) {
  13399.         if (($this->pdfa_mode && $this->pdfa_version 2) OR ($this->state != 2)) {
  13400.             // transparency is not allowed in PDF/A-1 mode
  13401.             return;
  13402.         }
  13403.         $this->_out(sprintf('/GS%d gs'$gs));
  13404.     }
  13405.     /**
  13406.      * Put extgstates for object transparency
  13407.      * @protected
  13408.      * @since 3.0.000 (2008-03-27)
  13409.      */
  13410.     protected function _putextgstates() {
  13411.         foreach ($this->extgstates as $i => $ext) {
  13412.             $this->extgstates[$i]['n'] = $this->_newobj();
  13413.             $out '<< /Type /ExtGState';
  13414.             foreach ($ext['parms'] as $k => $v) {
  13415.                 if (is_float($v)) {
  13416.                     $v sprintf('%F'$v);
  13417.                 } elseif ($v === true) {
  13418.                     $v 'true';
  13419.                 } elseif ($v === false) {
  13420.                     $v 'false';
  13421.                 }
  13422.                 $out .= ' /'.$k.' '.$v;
  13423.             }
  13424.             $out .= ' >>';
  13425.             $out .= "\n".'endobj';
  13426.             $this->_out($out);
  13427.         }
  13428.     }
  13429.     /**
  13430.      * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13431.      * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13432.      * @param boolean $stroking If true apply overprint for stroking operations.
  13433.      * @param boolean|null $nonstroking If true apply overprint for painting operations other than stroking.
  13434.      * @param integer $mode Overprint mode: (0 = each source colour component value replaces the value previously painted for the corresponding device colorant; 1 = a tint value of 0.0 for a source colour component shall leave the corresponding component of the previously painted colour unchanged).
  13435.      * @public
  13436.      * @since 5.9.152 (2012-03-23)
  13437.      */
  13438.     public function setOverprint($stroking=true$nonstroking=null$mode=0) {
  13439.         if ($this->state != 2) {
  13440.             return;
  13441.         }
  13442.         $stroking $stroking true false;
  13443.         if (TCPDF_STATIC::empty_string($nonstroking)) {
  13444.             // default value if not set
  13445.             $nonstroking $stroking;
  13446.         } else {
  13447.             $nonstroking $nonstroking true false;
  13448.         }
  13449.         if (($mode != 0) AND ($mode != 1)) {
  13450.             $mode 0;
  13451.         }
  13452.         $this->overprint = array('OP' => $stroking'op' => $nonstroking'OPM' => $mode);
  13453.         $gs $this->addExtGState($this->overprint);
  13454.         $this->setExtGState($gs);
  13455.     }
  13456.     /**
  13457.      * Get the overprint mode array (OP, op, OPM).
  13458.      * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13459.      * @return array<string,bool|int>
  13460.      * @public
  13461.      * @since 5.9.152 (2012-03-23)
  13462.      */
  13463.     public function getOverprint() {
  13464.         return $this->overprint;
  13465.     }
  13466.     /**
  13467.      * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13468.      * @param float $stroking Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13469.      * @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
  13470.      * @param float|null $nonstroking Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13471.      * @param boolean $ais
  13472.      * @public
  13473.      * @since 3.0.000 (2008-03-27)
  13474.      */
  13475.     public function setAlpha($stroking=1$bm='Normal'$nonstroking=null$ais=false) {
  13476.         if ($this->pdfa_mode && $this->pdfa_version 2) {
  13477.             // transparency is not allowed in PDF/A-1 mode
  13478.             return;
  13479.         }
  13480.         $stroking floatval($stroking);
  13481.         if (TCPDF_STATIC::empty_string($nonstroking)) {
  13482.             // default value if not set
  13483.             $nonstroking $stroking;
  13484.         } else {
  13485.             $nonstroking floatval($nonstroking);
  13486.         }
  13487.         if ($bm[0] == '/') {
  13488.             // remove trailing slash
  13489.             $bm substr($bm1);
  13490.         }
  13491.         if (!in_array($bm, array('Normal''Multiply''Screen''Overlay''Darken''Lighten''ColorDodge''ColorBurn''HardLight''SoftLight''Difference''Exclusion''Hue''Saturation''Color''Luminosity'))) {
  13492.             $bm 'Normal';
  13493.         }
  13494.         $ais $ais true false;
  13495.         $this->alpha = array('CA' => $stroking'ca' => $nonstroking'BM' => '/'.$bm'AIS' => $ais);
  13496.         $gs $this->addExtGState($this->alpha);
  13497.         $this->setExtGState($gs);
  13498.     }
  13499.     /**
  13500.      * Get the alpha mode array (CA, ca, BM, AIS).
  13501.      * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13502.      * @return array<string,bool|string>
  13503.      * @public
  13504.      * @since 5.9.152 (2012-03-23)
  13505.      */
  13506.     public function getAlpha() {
  13507.         return $this->alpha;
  13508.     }
  13509.     /**
  13510.      * Set the default JPEG compression quality (1-100)
  13511.      * @param int $quality JPEG quality, integer between 1 and 100
  13512.      * @public
  13513.      * @since 3.0.000 (2008-03-27)
  13514.      */
  13515.     public function setJPEGQuality($quality) {
  13516.         if (($quality 1) OR ($quality 100)) {
  13517.             $quality 75;
  13518.         }
  13519.         $this->jpeg_quality intval($quality);
  13520.     }
  13521.     /**
  13522.      * Set the default number of columns in a row for HTML tables.
  13523.      * @param int $cols number of columns
  13524.      * @public
  13525.      * @since 3.0.014 (2008-06-04)
  13526.      */
  13527.     public function setDefaultTableColumns($cols=4) {
  13528.         $this->default_table_columns intval($cols);
  13529.     }
  13530.     /**
  13531.      * Set the height of the cell (line height) respect the font height.
  13532.      * @param float $h cell proportion respect font height (typical value = 1.25).
  13533.      * @public
  13534.      * @since 3.0.014 (2008-06-04)
  13535.      */
  13536.     public function setCellHeightRatio($h) {
  13537.         $this->cell_height_ratio $h;
  13538.     }
  13539.     /**
  13540.      * return the height of cell repect font height.
  13541.      * @public
  13542.      * @return float
  13543.      * @since 4.0.012 (2008-07-24)
  13544.      */
  13545.     public function getCellHeightRatio() {
  13546.         return $this->cell_height_ratio;
  13547.     }
  13548.     /**
  13549.      * Set the PDF version (check PDF reference for valid values).
  13550.      * @param string $version PDF document version.
  13551.      * @public
  13552.      * @since 3.1.000 (2008-06-09)
  13553.      */
  13554.     public function setPDFVersion($version='1.7') {
  13555.         if ($this->pdfa_mode && $this->pdfa_version == ) {
  13556.             // PDF/A-1 mode
  13557.             $this->PDFVersion '1.4';
  13558.         } elseif ($this->pdfa_mode && $this->pdfa_version >= ) {
  13559.             // PDF/A-2 mode
  13560.             $this->PDFVersion '1.7';
  13561.         } else {
  13562.             $this->PDFVersion $version;
  13563.         }
  13564.     }
  13565.     /**
  13566.      * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13567.      * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13568.      * <ul><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><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><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><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><li>CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.</li><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><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><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><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><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><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><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><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><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><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><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></ul>
  13569.      * @param array $preferences array of options.
  13570.      * @author Nicola Asuni
  13571.      * @public
  13572.      * @since 3.1.000 (2008-06-09)
  13573.      */
  13574.     public function setViewerPreferences($preferences) {
  13575.         $this->viewer_preferences $preferences;
  13576.     }
  13577.     /**
  13578.      * Paints color transition registration bars
  13579.      * @param float $x abscissa of the top left corner of the rectangle.
  13580.      * @param float $y ordinate of the top left corner of the rectangle.
  13581.      * @param float $w width of the rectangle.
  13582.      * @param float $h height of the rectangle.
  13583.      * @param boolean $transition if true prints tcolor transitions to white.
  13584.      * @param boolean $vertical if true prints bar vertically.
  13585.      * @param string $colors colors to print separated by comma. Valid values are: A,W,R,G,B,C,M,Y,K,RGB,CMYK,ALL,ALLSPOT,<SPOT_COLOR_NAME>. Where: A = grayscale black, W = grayscale white, R = RGB red, G RGB green, B RGB blue, C = CMYK cyan, M = CMYK magenta, Y = CMYK yellow, K = CMYK key/black, RGB = RGB registration color, CMYK = CMYK registration color, ALL = Spot registration color, ALLSPOT = print all defined spot colors, <SPOT_COLOR_NAME> = name of the spot color to print.
  13586.      * @author Nicola Asuni
  13587.      * @since 4.9.000 (2010-03-26)
  13588.      * @public
  13589.      */
  13590.     public function colorRegistrationBar($x$y$w$h$transition=true$vertical=false$colors='A,R,G,B,C,M,Y,K') {
  13591.         if (strpos($colors'ALLSPOT') !== false) {
  13592.             // expand spot colors
  13593.             $spot_colors '';
  13594.             foreach ($this->spot_colors as $spot_color_name => $v) {
  13595.                 $spot_colors .= ','.$spot_color_name;
  13596.             }
  13597.             if (!empty($spot_colors)) {
  13598.                 $spot_colors substr($spot_colors1);
  13599.                 $colors str_replace('ALLSPOT'$spot_colors$colors);
  13600.             } else {
  13601.                 $colors str_replace('ALLSPOT''NONE'$colors);
  13602.             }
  13603.         }
  13604.         $bars explode(','$colors);
  13605.         $numbars count($bars); // number of bars to print
  13606.         if ($numbars <= 0) {
  13607.             return;
  13608.         }
  13609.         // set bar measures
  13610.         if ($vertical) {
  13611.             $coords = array(0001);
  13612.             $wb $w $numbars// bar width
  13613.             $hb $h// bar height
  13614.             $xd $wb// delta x
  13615.             $yd 0// delta y
  13616.         } else {
  13617.             $coords = array(1000);
  13618.             $wb $w// bar width
  13619.             $hb $h $numbars// bar height
  13620.             $xd 0// delta x
  13621.             $yd $hb// delta y
  13622.         }
  13623.         $xb $x;
  13624.         $yb $y;
  13625.         foreach ($bars as $col) {
  13626.             switch ($col) {
  13627.                 // set transition colors
  13628.                 case 'A': { // BLACK (GRAYSCALE)
  13629.                     $col_a = array(255);
  13630.                     $col_b = array(0);
  13631.                     break;
  13632.                 }
  13633.                 case 'W': { // WHITE (GRAYSCALE)
  13634.                     $col_a = array(0);
  13635.                     $col_b = array(255);
  13636.                     break;
  13637.                 }
  13638.                 case 'R': { // RED (RGB)
  13639.                     $col_a = array(255,255,255);
  13640.                     $col_b = array(255,0,0);
  13641.                     break;
  13642.                 }
  13643.                 case 'G': { // GREEN (RGB)
  13644.                     $col_a = array(255,255,255);
  13645.                     $col_b = array(0,255,0);
  13646.                     break;
  13647.                 }
  13648.                 case 'B': { // BLUE (RGB)
  13649.                     $col_a = array(255,255,255);
  13650.                     $col_b = array(0,0,255);
  13651.                     break;
  13652.                 }
  13653.                 case 'C': { // CYAN (CMYK)
  13654.                     $col_a = array(0,0,0,0);
  13655.                     $col_b = array(100,0,0,0);
  13656.                     break;
  13657.                 }
  13658.                 case 'M': { // MAGENTA (CMYK)
  13659.                     $col_a = array(0,0,0,0);
  13660.                     $col_b = array(0,100,0,0);
  13661.                     break;
  13662.                 }
  13663.                 case 'Y': { // YELLOW (CMYK)
  13664.                     $col_a = array(0,0,0,0);
  13665.                     $col_b = array(0,0,100,0);
  13666.                     break;
  13667.                 }
  13668.                 case 'K': { // KEY - BLACK (CMYK)
  13669.                     $col_a = array(0,0,0,0);
  13670.                     $col_b = array(0,0,0,100);
  13671.                     break;
  13672.                 }
  13673.                 case 'RGB': { // BLACK REGISTRATION (RGB)
  13674.                     $col_a = array(255,255,255);
  13675.                     $col_b = array(0,0,0);
  13676.                     break;
  13677.                 }
  13678.                 case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13679.                     $col_a = array(0,0,0,0);
  13680.                     $col_b = array(100,100,100,100);
  13681.                     break;
  13682.                 }
  13683.                 case 'ALL': { // SPOT COLOR REGISTRATION
  13684.                     $col_a = array(0,0,0,0,'None');
  13685.                     $col_b = array(100,100,100,100,'All');
  13686.                     break;
  13687.                 }
  13688.                 case 'NONE': { // SKIP THIS COLOR
  13689.                     $col_a = array(0,0,0,0,'None');
  13690.                     $col_b = array(0,0,0,0,'None');
  13691.                     break;
  13692.                 }
  13693.                 default: { // SPECIFIC SPOT COLOR NAME
  13694.                     $col_a = array(0,0,0,0,'None');
  13695.                     $col_b TCPDF_COLORS::getSpotColor($col$this->spot_colors);
  13696.                     if ($col_b === false) {
  13697.                         // in case of error defaults to the registration color
  13698.                         $col_b = array(100,100,100,100,'All');
  13699.                     }
  13700.                     break;
  13701.                 }
  13702.             }
  13703.             if ($col != 'NONE') {
  13704.                 if ($transition) {
  13705.                     // color gradient
  13706.                     $this->LinearGradient($xb$yb$wb$hb$col_a$col_b$coords);
  13707.                 } else {
  13708.                     $this->setFillColorArray($col_b);
  13709.                     // colored rectangle
  13710.                     $this->Rect($xb$yb$wb$hb'F', array());
  13711.                 }
  13712.                 $xb += $xd;
  13713.                 $yb += $yd;
  13714.             }
  13715.         }
  13716.     }
  13717.     /**
  13718.      * Paints crop marks.
  13719.      * @param float $x abscissa of the crop mark center.
  13720.      * @param float $y ordinate of the crop mark center.
  13721.      * @param float $w width of the crop mark.
  13722.      * @param float $h height of the crop mark.
  13723.      * @param string $type type of crop mark, one symbol per type separated by comma: T = TOP, F = BOTTOM, L = LEFT, R = RIGHT, TL = A = TOP-LEFT, TR = B = TOP-RIGHT, BL = C = BOTTOM-LEFT, BR = D = BOTTOM-RIGHT.
  13724.      * @param array $color crop mark color (default spot registration color).
  13725.      * @author Nicola Asuni
  13726.      * @since 4.9.000 (2010-03-26)
  13727.      * @public
  13728.      */
  13729.     public function cropMark($x$y$w$h$type='T,R,B,L'$color=array(100,100,100,100,'All')) {
  13730.         $this->setLineStyle(array('width' => (0.5 $this->k), 'cap' => 'butt''join' => 'miter''dash' => 0'color' => $color));
  13731.         $type strtoupper($type);
  13732.         $type preg_replace('/[^A-Z\-\,]*/'''$type);
  13733.         // split type in single components
  13734.         $type str_replace('-'','$type);
  13735.         $type str_replace('TL''T,L'$type);
  13736.         $type str_replace('TR''T,R'$type);
  13737.         $type str_replace('BL''F,L'$type);
  13738.         $type str_replace('BR''F,R'$type);
  13739.         $type str_replace('A''T,L'$type);
  13740.         $type str_replace('B''T,R'$type);
  13741.         $type str_replace('T,RO''BO'$type);
  13742.         $type str_replace('C''F,L'$type);
  13743.         $type str_replace('D''F,R'$type);
  13744.         $crops explode(','strtoupper($type));
  13745.         // remove duplicates
  13746.         $crops array_unique($crops);
  13747.         $dw = ($w 4); // horizontal space to leave before the intersection point
  13748.         $dh = ($h 4); // vertical space to leave before the intersection point
  13749.         foreach ($crops as $crop) {
  13750.             switch ($crop) {
  13751.                 case 'T':
  13752.                 case 'TOP': {
  13753.                     $x1 $x;
  13754.                     $y1 = ($y $h);
  13755.                     $x2 $x;
  13756.                     $y2 = ($y $dh);
  13757.                     break;
  13758.                 }
  13759.                 case 'F':
  13760.                 case 'BOTTOM': {
  13761.                     $x1 $x;
  13762.                     $y1 = ($y $dh);
  13763.                     $x2 $x;
  13764.                     $y2 = ($y $h);
  13765.                     break;
  13766.                 }
  13767.                 case 'L':
  13768.                 case 'LEFT': {
  13769.                     $x1 = ($x $w);
  13770.                     $y1 $y;
  13771.                     $x2 = ($x $dw);
  13772.                     $y2 $y;
  13773.                     break;
  13774.                 }
  13775.                 case 'R':
  13776.                 case 'RIGHT': {
  13777.                     $x1 = ($x $dw);
  13778.                     $y1 $y;
  13779.                     $x2 = ($x $w);
  13780.                     $y2 $y;
  13781.                     break;
  13782.                 }
  13783.             }
  13784.             $this->Line($x1$y1$x2$y2);
  13785.         }
  13786.     }
  13787.     /**
  13788.      * Paints a registration mark
  13789.      * @param float $x abscissa of the registration mark center.
  13790.      * @param float $y ordinate of the registration mark center.
  13791.      * @param float $r radius of the crop mark.
  13792.      * @param boolean $double if true print two concentric crop marks.
  13793.      * @param array $cola crop mark color (default spot registration color 'All').
  13794.      * @param array $colb second crop mark color (default spot registration color 'None').
  13795.      * @author Nicola Asuni
  13796.      * @since 4.9.000 (2010-03-26)
  13797.      * @public
  13798.      */
  13799.     public function registrationMark($x$y$r$double=false$cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
  13800.         $line_style = array('width' => max((0.5 $this->k),($r 30)), 'cap' => 'butt''join' => 'miter''dash' => 0'color' => $cola);
  13801.         $this->setFillColorArray($cola);
  13802.         $this->PieSector($x$y$r90180'F');
  13803.         $this->PieSector($x$y$r270360'F');
  13804.         $this->Circle($x$y$r0360'C'$line_style, array(), 8);
  13805.         if ($double) {
  13806.             $ri $r 0.5;
  13807.             $this->setFillColorArray($colb);
  13808.             $this->PieSector($x$y$ri90180'F');
  13809.             $this->PieSector($x$y$ri270360'F');
  13810.             $this->setFillColorArray($cola);
  13811.             $this->PieSector($x$y$ri090'F');
  13812.             $this->PieSector($x$y$ri180270'F');
  13813.             $this->Circle($x$y$ri0360'C'$line_style, array(), 8);
  13814.         }
  13815.     }
  13816.     /**
  13817.      * Paints a CMYK registration mark
  13818.      * @param float $x abscissa of the registration mark center.
  13819.      * @param float $y ordinate of the registration mark center.
  13820.      * @param float $r radius of the crop mark.
  13821.      * @author Nicola Asuni
  13822.      * @since 6.0.038 (2013-09-30)
  13823.      * @public
  13824.      */
  13825.     public function registrationMarkCMYK($x$y$r) {
  13826.         // line width
  13827.         $lw max((0.5 $this->k),($r 8));
  13828.         // internal radius
  13829.         $ri = ($r 0.6);
  13830.         // external radius
  13831.         $re = ($r 1.3);
  13832.         // Cyan
  13833.         $this->setFillColorArray(array(100,0,0,0));
  13834.         $this->PieSector($x$y$ri270360'F');
  13835.         // Magenta
  13836.         $this->setFillColorArray(array(0,100,0,0));
  13837.         $this->PieSector($x$y$ri090'F');
  13838.         // Yellow
  13839.         $this->setFillColorArray(array(0,0,100,0));
  13840.         $this->PieSector($x$y$ri90180'F');
  13841.         // Key - black
  13842.         $this->setFillColorArray(array(0,0,0,100));
  13843.         $this->PieSector($x$y$ri180270'F');
  13844.         // registration color
  13845.         $line_style = array('width' => $lw'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(100,100,100,100,'All'));
  13846.         $this->setFillColorArray(array(100,100,100,100,'All'));
  13847.         // external circle
  13848.         $this->Circle($x$y$r0360'C'$line_style, array(), 8);
  13849.         // cross lines
  13850.         $this->Line($x, ($y $re), $x, ($y $ri));
  13851.         $this->Line($x, ($y $ri), $x, ($y $re));
  13852.         $this->Line(($x $re), $y, ($x $ri), $y);
  13853.         $this->Line(($x $ri), $y, ($x $re), $y);
  13854.     }
  13855.     /**
  13856.      * Paints a linear colour gradient.
  13857.      * @param float $x abscissa of the top left corner of the rectangle.
  13858.      * @param float $y ordinate of the top left corner of the rectangle.
  13859.      * @param float $w width of the rectangle.
  13860.      * @param float $h height of the rectangle.
  13861.      * @param array $col1 first color (Grayscale, RGB or CMYK components).
  13862.      * @param array $col2 second color (Grayscale, RGB or CMYK components).
  13863.      * @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).
  13864.      * @author Andreas W\FCrmser, Nicola Asuni
  13865.      * @since 3.1.000 (2008-06-09)
  13866.      * @public
  13867.      */
  13868.     public function LinearGradient($x$y$w$h$col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  13869.         $this->Clip($x$y$w$h);
  13870.         $this->Gradient(2$coords, array(array('color' => $col1'offset' => 0'exponent' => 1), array('color' => $col2'offset' => 1'exponent' => 1)), array(), false);
  13871.     }
  13872.     /**
  13873.      * Paints a radial colour gradient.
  13874.      * @param float $x abscissa of the top left corner of the rectangle.
  13875.      * @param float $y ordinate of the top left corner of the rectangle.
  13876.      * @param float $w width of the rectangle.
  13877.      * @param float $h height of the rectangle.
  13878.      * @param array $col1 first color (Grayscale, RGB or CMYK components).
  13879.      * @param array $col2 second color (Grayscale, RGB or CMYK components).
  13880.      * @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.
  13881.      * @author Andreas W\FCrmser, Nicola Asuni
  13882.      * @since 3.1.000 (2008-06-09)
  13883.      * @public
  13884.      */
  13885.     public function RadialGradient($x$y$w$h$col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  13886.         $this->Clip($x$y$w$h);
  13887.         $this->Gradient(3$coords, array(array('color' => $col1'offset' => 0'exponent' => 1), array('color' => $col2'offset' => 1'exponent' => 1)), array(), false);
  13888.     }
  13889.     /**
  13890.      * Paints a coons patch mesh.
  13891.      * @param float $x abscissa of the top left corner of the rectangle.
  13892.      * @param float $y ordinate of the top left corner of the rectangle.
  13893.      * @param float $w width of the rectangle.
  13894.      * @param float $h height of the rectangle.
  13895.      * @param array $col1 first color (lower left corner) (RGB components).
  13896.      * @param array $col2 second color (lower right corner) (RGB components).
  13897.      * @param array $col3 third color (upper right corner) (RGB components).
  13898.      * @param array $col4 fourth color (upper left corner) (RGB components).
  13899.      * @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>
  13900.      * @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
  13901.      * @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
  13902.      * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13903.      * @author Andreas W\FCrmser, Nicola Asuni
  13904.      * @since 3.1.000 (2008-06-09)
  13905.      * @public
  13906.      */
  13907.     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$antialias=false) {
  13908.         if (($this->pdfa_mode && $this->pdfa_version 2) OR ($this->state != 2)) {
  13909.             return;
  13910.         }
  13911.         $this->Clip($x$y$w$h);
  13912.         $n count($this->gradients) + 1;
  13913.         $this->gradients[$n] = array();
  13914.         $this->gradients[$n]['type'] = 6//coons patch mesh
  13915.         $this->gradients[$n]['coords'] = array();
  13916.         $this->gradients[$n]['antialias'] = $antialias;
  13917.         $this->gradients[$n]['colors'] = array();
  13918.         $this->gradients[$n]['transparency'] = false;
  13919.         //check the coords array if it is the simple array or the multi patch array
  13920.         if (!isset($coords[0]['f'])) {
  13921.             //simple array -> convert to multi patch array
  13922.             if (!isset($col1[1])) {
  13923.                 $col1[1] = $col1[2] = $col1[0];
  13924.             }
  13925.             if (!isset($col2[1])) {
  13926.                 $col2[1] = $col2[2] = $col2[0];
  13927.             }
  13928.             if (!isset($col3[1])) {
  13929.                 $col3[1] = $col3[2] = $col3[0];
  13930.             }
  13931.             if (!isset($col4[1])) {
  13932.                 $col4[1] = $col4[2] = $col4[0];
  13933.             }
  13934.             $patch_array[0]['f'] = 0;
  13935.             $patch_array[0]['points'] = $coords;
  13936.             $patch_array[0]['colors'][0]['r'] = $col1[0];
  13937.             $patch_array[0]['colors'][0]['g'] = $col1[1];
  13938.             $patch_array[0]['colors'][0]['b'] = $col1[2];
  13939.             $patch_array[0]['colors'][1]['r'] = $col2[0];
  13940.             $patch_array[0]['colors'][1]['g'] = $col2[1];
  13941.             $patch_array[0]['colors'][1]['b'] = $col2[2];
  13942.             $patch_array[0]['colors'][2]['r'] = $col3[0];
  13943.             $patch_array[0]['colors'][2]['g'] = $col3[1];
  13944.             $patch_array[0]['colors'][2]['b'] = $col3[2];
  13945.             $patch_array[0]['colors'][3]['r'] = $col4[0];
  13946.             $patch_array[0]['colors'][3]['g'] = $col4[1];
  13947.             $patch_array[0]['colors'][3]['b'] = $col4[2];
  13948.         } else {
  13949.             //multi patch array
  13950.             $patch_array $coords;
  13951.         }
  13952.         $bpcd 65535//16 bits per coordinate
  13953.         //build the data stream
  13954.         $this->gradients[$n]['stream'] = '';
  13955.         $count_patch count($patch_array);
  13956.         for ($i=0$i $count_patch; ++$i) {
  13957.             $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  13958.             $count_points count($patch_array[$i]['points']);
  13959.             for ($j=0$j $count_points; ++$j) {
  13960.                 //each point as 16 bit
  13961.                 $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max $coords_min)) * $bpcd;
  13962.                 if ($patch_array[$i]['points'][$j] < 0) {
  13963.                     $patch_array[$i]['points'][$j] = 0;
  13964.                 }
  13965.                 if ($patch_array[$i]['points'][$j] > $bpcd) {
  13966.                     $patch_array[$i]['points'][$j] = $bpcd;
  13967.                 }
  13968.                 $this->gradients[$n]['stream'] .= chr((int) floor($patch_array[$i]['points'][$j] / 256));
  13969.                 $this->gradients[$n]['stream'] .= chr((int) floor(intval($patch_array[$i]['points'][$j]) % 256));
  13970.             }
  13971.             $count_cols count($patch_array[$i]['colors']);
  13972.             for ($j=0$j $count_cols; ++$j) {
  13973.                 //each color component as 8 bit
  13974.                 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  13975.                 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  13976.                 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  13977.             }
  13978.         }
  13979.         //paint the gradient
  13980.         $this->_out('/Sh'.$n.' sh');
  13981.         //restore previous Graphic State
  13982.         $this->_outRestoreGraphicsState();
  13983.         if ($this->inxobj) {
  13984.             // we are inside an XObject template
  13985.             $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13986.         }
  13987.     }
  13988.     /**
  13989.      * Set a rectangular clipping area.
  13990.      * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  13991.      * @param float $y ordinate of the top left corner of the rectangle.
  13992.      * @param float $w width of the rectangle.
  13993.      * @param float $h height of the rectangle.
  13994.      * @author Andreas W\FCrmser, Nicola Asuni
  13995.      * @since 3.1.000 (2008-06-09)
  13996.      * @protected
  13997.      */
  13998.     protected function Clip($x$y$w$h) {
  13999.         if ($this->state != 2) {
  14000.              return;
  14001.         }
  14002.         if ($this->rtl) {
  14003.             $x $this->$x $w;
  14004.         }
  14005.         //save current Graphic State
  14006.         $s 'q';
  14007.         //set clipping area
  14008.         $s .= sprintf(' %F %F %F %F re W n'$x*$this->k, ($this->h-$y)*$this->k$w*$this->k, -$h*$this->k);
  14009.         //set up transformation matrix for gradient
  14010.         $s .= sprintf(' %F 0 0 %F %F %F cm'$w*$this->k$h*$this->k$x*$this->k, ($this->h-($y+$h))*$this->k);
  14011.         $this->_out($s);
  14012.     }
  14013.     /**
  14014.      * Output gradient.
  14015.      * @param int $type type of gradient (1 Function-based shading; 2 Axial shading; 3 Radial shading; 4 Free-form Gouraud-shaded triangle mesh; 5 Lattice-form Gouraud-shaded triangle mesh; 6 Coons patch mesh; 7 Tensor-product patch mesh). (Not all types are currently supported)
  14016.      * @param array $coords array of coordinates.
  14017.      * @param array $stops array gradient color components: color = array of GRAY, RGB or CMYK color components; offset = (0 to 1) represents a location along the gradient vector; exponent = exponent of the exponential interpolation function (default = 1).
  14018.      * @param array $background An array of colour components appropriate to the colour space, specifying a single background colour value.
  14019.      * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  14020.      * @author Nicola Asuni
  14021.      * @since 3.1.000 (2008-06-09)
  14022.      * @public
  14023.      */
  14024.     public function Gradient($type$coords$stops$background=array(), $antialias=false) {
  14025.         if (($this->pdfa_mode && $this->pdfa_version 2) OR ($this->state != 2)) {
  14026.             return;
  14027.         }
  14028.         $n count($this->gradients) + 1;
  14029.         $this->gradients[$n] = array();
  14030.         $this->gradients[$n]['type'] = $type;
  14031.         $this->gradients[$n]['coords'] = $coords;
  14032.         $this->gradients[$n]['antialias'] = $antialias;
  14033.         $this->gradients[$n]['colors'] = array();
  14034.         $this->gradients[$n]['transparency'] = false;
  14035.         // color space
  14036.         $numcolspace count($stops[0]['color']);
  14037.         $bcolor array_values($background);
  14038.         switch($numcolspace) {
  14039.             case 5:   // SPOT
  14040.             case 4: { // CMYK
  14041.                 $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  14042.                 if (!empty($background)) {
  14043.                     $this->gradients[$n]['background'] = sprintf('%F %F %F %F'$bcolor[0]/100$bcolor[1]/100$bcolor[2]/100$bcolor[3]/100);
  14044.                 }
  14045.                 break;
  14046.             }
  14047.             case 3: { // RGB
  14048.                 $this->gradients[$n]['colspace'] = 'DeviceRGB';
  14049.                 if (!empty($background)) {
  14050.                     $this->gradients[$n]['background'] = sprintf('%F %F %F'$bcolor[0]/255$bcolor[1]/255$bcolor[2]/255);
  14051.                 }
  14052.                 break;
  14053.             }
  14054.             case 1: { // GRAY SCALE
  14055.                 $this->gradients[$n]['colspace'] = 'DeviceGray';
  14056.                 if (!empty($background)) {
  14057.                     $this->gradients[$n]['background'] = sprintf('%F'$bcolor[0]/255);
  14058.                 }
  14059.                 break;
  14060.             }
  14061.         }
  14062.         $num_stops count($stops);
  14063.         $last_stop_id $num_stops 1;
  14064.         foreach ($stops as $key => $stop) {
  14065.             $this->gradients[$n]['colors'][$key] = array();
  14066.             // offset represents a location along the gradient vector
  14067.             if (isset($stop['offset'])) {
  14068.                 $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  14069.             } else {
  14070.                 if ($key == 0) {
  14071.                     $this->gradients[$n]['colors'][$key]['offset'] = 0;
  14072.                 } elseif ($key == $last_stop_id) {
  14073.                     $this->gradients[$n]['colors'][$key]['offset'] = 1;
  14074.                 } else {
  14075.                     $offsetstep = ($this->gradients[$n]['colors'][($key 1)]['offset']) / ($num_stops $key);
  14076.                     $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key 1)]['offset'] + $offsetstep;
  14077.                 }
  14078.             }
  14079.             if (isset($stop['opacity'])) {
  14080.                 $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  14081.                 if ((!($this->pdfa_mode && $this->pdfa_version 2)) AND ($stop['opacity'] < 1)) {
  14082.                     $this->gradients[$n]['transparency'] = true;
  14083.                 }
  14084.             } else {
  14085.                 $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  14086.             }
  14087.             // exponent for the exponential interpolation function
  14088.             if (isset($stop['exponent'])) {
  14089.                 $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  14090.             } else {
  14091.                 $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  14092.             }
  14093.             // set colors
  14094.             $color array_values($stop['color']);
  14095.             switch($numcolspace) {
  14096.                 case 5:   // SPOT
  14097.                 case 4: { // CMYK
  14098.                     $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F'$color[0]/100$color[1]/100$color[2]/100$color[3]/100);
  14099.                     break;
  14100.                 }
  14101.                 case 3: { // RGB
  14102.                     $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F'$color[0]/255$color[1]/255$color[2]/255);
  14103.                     break;
  14104.                 }
  14105.                 case 1: { // GRAY SCALE
  14106.                     $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F'$color[0]/255);
  14107.                     break;
  14108.                 }
  14109.             }
  14110.         }
  14111.         if ($this->gradients[$n]['transparency']) {
  14112.             // paint luminosity gradient
  14113.             $this->_out('/TGS'.$n.' gs');
  14114.         }
  14115.         //paint the gradient
  14116.         $this->_out('/Sh'.$n.' sh');
  14117.         //restore previous Graphic State
  14118.         $this->_outRestoreGraphicsState();
  14119.         if ($this->inxobj) {
  14120.             // we are inside an XObject template
  14121.             $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  14122.         }
  14123.     }
  14124.     /**
  14125.      * Output gradient shaders.
  14126.      * @author Nicola Asuni
  14127.      * @since 3.1.000 (2008-06-09)
  14128.      * @protected
  14129.      */
  14130.     function _putshaders() {
  14131.         if ($this->pdfa_mode && $this->pdfa_version 2) {
  14132.             return;
  14133.         }
  14134.         $idt count($this->gradients); //index for transparency gradients
  14135.         foreach ($this->gradients as $id => $grad) {
  14136.             if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  14137.                 $fc $this->_newobj();
  14138.                 $out '<<';
  14139.                 $out .= ' /FunctionType 3';
  14140.                 $out .= ' /Domain [0 1]';
  14141.                 $functions '';
  14142.                 $bounds '';
  14143.                 $encode '';
  14144.                 $i 1;
  14145.                 $num_cols count($grad['colors']);
  14146.                 $lastcols $num_cols 1;
  14147.                 for ($i 1$i $num_cols; ++$i) {
  14148.                     $functions .= ($fc $i).' 0 R ';
  14149.                     if ($i $lastcols) {
  14150.                         $bounds .= sprintf('%F '$grad['colors'][$i]['offset']);
  14151.                     }
  14152.                     $encode .= '0 1 ';
  14153.                 }
  14154.                 $out .= ' /Functions ['.trim($functions).']';
  14155.                 $out .= ' /Bounds ['.trim($bounds).']';
  14156.                 $out .= ' /Encode ['.trim($encode).']';
  14157.                 $out .= ' >>';
  14158.                 $out .= "\n".'endobj';
  14159.                 $this->_out($out);
  14160.                 for ($i 1$i $num_cols; ++$i) {
  14161.                     $this->_newobj();
  14162.                     $out '<<';
  14163.                     $out .= ' /FunctionType 2';
  14164.                     $out .= ' /Domain [0 1]';
  14165.                     $out .= ' /C0 ['.$grad['colors'][($i 1)]['color'].']';
  14166.                     $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  14167.                     $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14168.                     $out .= ' >>';
  14169.                     $out .= "\n".'endobj';
  14170.                     $this->_out($out);
  14171.                 }
  14172.                 // set transparency functions
  14173.                 if ($grad['transparency']) {
  14174.                     $ft $this->_newobj();
  14175.                     $out '<<';
  14176.                     $out .= ' /FunctionType 3';
  14177.                     $out .= ' /Domain [0 1]';
  14178.                     $functions '';
  14179.                     $i 1;
  14180.                     $num_cols count($grad['colors']);
  14181.                     for ($i 1$i $num_cols; ++$i) {
  14182.                         $functions .= ($ft $i).' 0 R ';
  14183.                     }
  14184.                     $out .= ' /Functions ['.trim($functions).']';
  14185.                     $out .= ' /Bounds ['.trim($bounds).']';
  14186.                     $out .= ' /Encode ['.trim($encode).']';
  14187.                     $out .= ' >>';
  14188.                     $out .= "\n".'endobj';
  14189.                     $this->_out($out);
  14190.                     for ($i 1$i $num_cols; ++$i) {
  14191.                         $this->_newobj();
  14192.                         $out '<<';
  14193.                         $out .= ' /FunctionType 2';
  14194.                         $out .= ' /Domain [0 1]';
  14195.                         $out .= ' /C0 ['.$grad['colors'][($i 1)]['opacity'].']';
  14196.                         $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  14197.                         $out .= ' /N '.$grad['colors'][$i]['exponent'];
  14198.                         $out .= ' >>';
  14199.                         $out .= "\n".'endobj';
  14200.                         $this->_out($out);
  14201.                     }
  14202.                 }
  14203.             }
  14204.             // set shading object
  14205.             $this->_newobj();
  14206.             $out '<< /ShadingType '.$grad['type'];
  14207.             if (isset($grad['colspace'])) {
  14208.                 $out .= ' /ColorSpace /'.$grad['colspace'];
  14209.             } else {
  14210.                 $out .= ' /ColorSpace /DeviceRGB';
  14211.             }
  14212.             if (isset($grad['background']) AND !empty($grad['background'])) {
  14213.                 $out .= ' /Background ['.$grad['background'].']';
  14214.             }
  14215.             if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14216.                 $out .= ' /AntiAlias true';
  14217.             }
  14218.             if ($grad['type'] == 2) {
  14219.                 $out .= ' '.sprintf('/Coords [%F %F %F %F]'$grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14220.                 $out .= ' /Domain [0 1]';
  14221.                 $out .= ' /Function '.$fc.' 0 R';
  14222.                 $out .= ' /Extend [true true]';
  14223.                 $out .= ' >>';
  14224.             } elseif ($grad['type'] == 3) {
  14225.                 //x0, y0, r0, x1, y1, r1
  14226.                 //at this this time radius of inner circle is 0
  14227.                 $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]'$grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14228.                 $out .= ' /Domain [0 1]';
  14229.                 $out .= ' /Function '.$fc.' 0 R';
  14230.                 $out .= ' /Extend [true true]';
  14231.                 $out .= ' >>';
  14232.             } elseif ($grad['type'] == 6) {
  14233.                 $out .= ' /BitsPerCoordinate 16';
  14234.                 $out .= ' /BitsPerComponent 8';
  14235.                 $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14236.                 $out .= ' /BitsPerFlag 8';
  14237.                 $stream $this->_getrawstream($grad['stream']);
  14238.                 $out .= ' /Length '.strlen($stream);
  14239.                 $out .= ' >>';
  14240.                 $out .= ' stream'."\n".$stream."\n".'endstream';
  14241.             }
  14242.             $out .= "\n".'endobj';
  14243.             $this->_out($out);
  14244.             if ($grad['transparency']) {
  14245.                 $shading_transparency preg_replace('/\/ColorSpace \/[^\s]+/si''/ColorSpace /DeviceGray'$out);
  14246.                 $shading_transparency preg_replace('/\/Function [0-9]+ /si''/Function '.$ft.' '$shading_transparency);
  14247.             }
  14248.             $this->gradients[$id]['id'] = $this->n;
  14249.             // set pattern object
  14250.             $this->_newobj();
  14251.             $out '<< /Type /Pattern /PatternType 2';
  14252.             $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14253.             $out .= ' >>';
  14254.             $out .= "\n".'endobj';
  14255.             $this->_out($out);
  14256.             $this->gradients[$id]['pattern'] = $this->n;
  14257.             // set shading and pattern for transparency mask
  14258.             if ($grad['transparency']) {
  14259.                 // luminosity pattern
  14260.                 $idgs $id $idt;
  14261.                 $this->_newobj();
  14262.                 $this->_out($shading_transparency);
  14263.                 $this->gradients[$idgs]['id'] = $this->n;
  14264.                 $this->_newobj();
  14265.                 $out '<< /Type /Pattern /PatternType 2';
  14266.                 $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14267.                 $out .= ' >>';
  14268.                 $out .= "\n".'endobj';
  14269.                 $this->_out($out);
  14270.                 $this->gradients[$idgs]['pattern'] = $this->n;
  14271.                 // luminosity XObject
  14272.                 $oid $this->_newobj();
  14273.                 $this->xobjects['LX'.$oid] = array('n' => $oid);
  14274.                 $filter '';
  14275.                 $stream 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14276.                 if ($this->compress) {
  14277.                     $filter ' /Filter /FlateDecode';
  14278.                     $stream gzcompress($stream);
  14279.                 }
  14280.                 $stream $this->_getrawstream($stream);
  14281.                 $out '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14282.                 $out .= ' /Length '.strlen($stream);
  14283.                 $rect sprintf('%F %F'$this->wPt$this->hPt);
  14284.                 $out .= ' /BBox [0 0 '.$rect.']';
  14285.                 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14286.                 $out .= ' /Resources <<';
  14287.                 $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14288.                 $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14289.                 $out .= ' >>';
  14290.                 $out .= ' >> ';
  14291.                 $out .= ' stream'."\n".$stream."\n".'endstream';
  14292.                 $out .= "\n".'endobj';
  14293.                 $this->_out($out);
  14294.                 // SMask
  14295.                 $this->_newobj();
  14296.                 $out '<< /Type /Mask /S /Luminosity /G '.($this->1).' 0 R >>'."\n".'endobj';
  14297.                 $this->_out($out);
  14298.                 // ExtGState
  14299.                 $this->_newobj();
  14300.                 $out '<< /Type /ExtGState /SMask '.($this->1).' 0 R /AIS false >>'."\n".'endobj';
  14301.                 $this->_out($out);
  14302.                 $this->extgstates[] = array('n' => $this->n'name' => 'TGS'.$id);
  14303.             }
  14304.         }
  14305.     }
  14306.     /**
  14307.      * Draw the sector of a circle.
  14308.      * It can be used for instance to render pie charts.
  14309.      * @param float $xc abscissa of the center.
  14310.      * @param float $yc ordinate of the center.
  14311.      * @param float $r radius.
  14312.      * @param float $a start angle (in degrees).
  14313.      * @param float $b end angle (in degrees).
  14314.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  14315.      * @param float $cw indicates whether to go clockwise (default: true).
  14316.      * @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.
  14317.      * @author Maxime Delorme, Nicola Asuni
  14318.      * @since 3.1.000 (2008-06-09)
  14319.      * @public
  14320.      */
  14321.     public function PieSector($xc$yc$r$a$b$style='FD'$cw=true$o=90) {
  14322.         $this->PieSectorXY($xc$yc$r$r$a$b$style$cw$o);
  14323.     }
  14324.     /**
  14325.      * Draw the sector of an ellipse.
  14326.      * It can be used for instance to render pie charts.
  14327.      * @param float $xc abscissa of the center.
  14328.      * @param float $yc ordinate of the center.
  14329.      * @param float $rx the x-axis radius.
  14330.      * @param float $ry the y-axis radius.
  14331.      * @param float $a start angle (in degrees).
  14332.      * @param float $b end angle (in degrees).
  14333.      * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  14334.      * @param float $cw indicates whether to go clockwise.
  14335.      * @param float $o origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14336.      * @param integer $nc Number of curves used to draw a 90 degrees portion of arc.
  14337.      * @author Maxime Delorme, Nicola Asuni
  14338.      * @since 3.1.000 (2008-06-09)
  14339.      * @public
  14340.      */
  14341.     public function PieSectorXY($xc$yc$rx$ry$a$b$style='FD'$cw=false$o=0$nc=2) {
  14342.         if ($this->state != 2) {
  14343.              return;
  14344.         }
  14345.         if ($this->rtl) {
  14346.             $xc = ($this->$xc);
  14347.         }
  14348.         $op TCPDF_STATIC::getPathPaintOperator($style);
  14349.         if ($op == 'f') {
  14350.             $line_style = array();
  14351.         }
  14352.         if ($cw) {
  14353.             $d $b;
  14354.             $b = (360 $a $o);
  14355.             $a = (360 $d $o);
  14356.         } else {
  14357.             $b += $o;
  14358.             $a += $o;
  14359.         }
  14360.         $this->_outellipticalarc($xc$yc$rx$ry0$a$btrue$nc);
  14361.         $this->_out($op);
  14362.     }
  14363.     /**
  14364.      * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14365.      * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14366.      * Only vector drawing is supported, not text or bitmap.
  14367.      * 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).
  14368.      * @param string $file Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14369.      * @param float|null $x Abscissa of the upper-left corner.
  14370.      * @param float|null $y Ordinate of the upper-left corner.
  14371.      * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14372.      * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14373.      * @param mixed $link URL or identifier returned by AddLink().
  14374.      * @param boolean $useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14375.      * @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>
  14376.      * @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>
  14377.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  14378.      * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  14379.      * @param boolean $fixoutvals if true remove values outside the bounding box.
  14380.      * @author Valentin Schmidt, Nicola Asuni
  14381.      * @since 3.1.000 (2008-06-09)
  14382.      * @public
  14383.      */
  14384.     public function ImageEps($file$x=null$y=null$w=0$h=0$link=''$useBoundingBox=true$align=''$palign=''$border=0$fitonpage=false$fixoutvals=false) {
  14385.         if ($this->state != 2) {
  14386.              return;
  14387.         }
  14388.         if ($this->rasterize_vector_images AND ($w 0) AND ($h 0)) {
  14389.             // convert EPS to raster image using GD or ImageMagick libraries
  14390.             return $this->Image($file$x$y$w$h'EPS'$link$aligntrue300$palignfalsefalse$borderfalsefalse$fitonpage);
  14391.         }
  14392.         if (TCPDF_STATIC::empty_string($x)) {
  14393.             $x $this->x;
  14394.         }
  14395.         if (TCPDF_STATIC::empty_string($y)) {
  14396.             $y $this->y;
  14397.         }
  14398.         // check page for no-write regions and adapt page margins if necessary
  14399.         list($x$y) = $this->checkPageRegions($h$x$y);
  14400.         $k $this->k;
  14401.         if ($file[0] === '@') { // image from string
  14402.             $data substr($file1);
  14403.         } else { // EPS/AI file
  14404.             $data $this->getCachedFileContents($file);
  14405.         }
  14406.         if ($data === FALSE) {
  14407.             $this->Error('EPS file not found: '.$file);
  14408.         }
  14409.         $regs = array();
  14410.         // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14411.         preg_match("/%%Creator:([^\r\n]+)/"$data$regs); # find Creator
  14412.         if (count($regs) > 1) {
  14413.             $version_str trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  14414.             if (strpos($version_str'Adobe Illustrator') !== false) {
  14415.                 $versexp explode(' '$version_str);
  14416.                 $version = (float)array_pop($versexp);
  14417.                 if ($version >= 9) {
  14418.                     $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14419.                 }
  14420.             }
  14421.         }
  14422.         // strip binary bytes in front of PS-header
  14423.         $start strpos($data'%!PS-Adobe');
  14424.         if ($start 0) {
  14425.             $data substr($data$start);
  14426.         }
  14427.         // find BoundingBox params
  14428.         preg_match("/%%BoundingBox:([^\r\n]+)/"$data$regs);
  14429.         if (count($regs) > 1) {
  14430.             list($x1$y1$x2$y2) = explode(' 'trim($regs[1]));
  14431.         } else {
  14432.             $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14433.         }
  14434.         $start strpos($data'%%EndSetup');
  14435.         if ($start === false) {
  14436.             $start strpos($data'%%EndProlog');
  14437.         }
  14438.         if ($start === false) {
  14439.             $start strpos($data'%%BoundingBox');
  14440.         }
  14441.         $data substr($data$start);
  14442.         $end strpos($data'%%PageTrailer');
  14443.         if ($end===false) {
  14444.             $end strpos($data'showpage');
  14445.         }
  14446.         if ($end) {
  14447.             $data substr($data0$end);
  14448.         }
  14449.         // calculate image width and height on document
  14450.         if (($w <= 0) AND ($h <= 0)) {
  14451.             $w = ($x2 $x1) / $k;
  14452.             $h = ($y2 $y1) / $k;
  14453.         } elseif ($w <= 0) {
  14454.             $w = ($x2-$x1) / $k * ($h / (($y2 $y1) / $k));
  14455.         } elseif ($h <= 0) {
  14456.             $h = ($y2 $y1) / $k * ($w / (($x2 $x1) / $k));
  14457.         }
  14458.         // fit the image on available space
  14459.         list($w$h$x$y) = $this->fitBlock($w$h$x$y$fitonpage);
  14460.         if ($this->rasterize_vector_images) {
  14461.             // convert EPS to raster image using GD or ImageMagick libraries
  14462.             return $this->Image($file$x$y$w$h'EPS'$link$aligntrue300$palignfalsefalse$borderfalsefalse$fitonpage);
  14463.         }
  14464.         // set scaling factors
  14465.         $scale_x $w / (($x2 $x1) / $k);
  14466.         $scale_y $h / (($y2 $y1) / $k);
  14467.         // set alignment
  14468.         $this->img_rb_y $y $h;
  14469.         // set alignment
  14470.         if ($this->rtl) {
  14471.             if ($palign == 'L') {
  14472.                 $ximg $this->lMargin;
  14473.             } elseif ($palign == 'C') {
  14474.                 $ximg = ($this->$this->lMargin $this->rMargin $w) / 2;
  14475.             } elseif ($palign == 'R') {
  14476.                 $ximg $this->$this->rMargin $w;
  14477.             } else {
  14478.                 $ximg $x $w;
  14479.             }
  14480.             $this->img_rb_x $ximg;
  14481.         } else {
  14482.             if ($palign == 'L') {
  14483.                 $ximg $this->lMargin;
  14484.             } elseif ($palign == 'C') {
  14485.                 $ximg = ($this->$this->lMargin $this->rMargin $w) / 2;
  14486.             } elseif ($palign == 'R') {
  14487.                 $ximg $this->$this->rMargin $w;
  14488.             } else {
  14489.                 $ximg $x;
  14490.             }
  14491.             $this->img_rb_x $ximg $w;
  14492.         }
  14493.         if ($useBoundingBox) {
  14494.             $dx $ximg $k $x1;
  14495.             $dy $y $k $y1;
  14496.         } else {
  14497.             $dx $ximg $k;
  14498.             $dy $y $k;
  14499.         }
  14500.         // save the current graphic state
  14501.         $this->_out('q'.$this->epsmarker);
  14502.         // translate
  14503.         $this->_out(sprintf('%F %F %F %F %F %F cm'1001$dx$dy + ($this->hPt - ($y $k) - ($y2 $y1))));
  14504.         // scale
  14505.         $this->_out(sprintf('%F %F %F %F %F %F cm'$scale_x00$scale_y$x1 * ($scale_x), $y2 * ($scale_y)));
  14506.         // handle pc/unix/mac line endings
  14507.         $lines preg_split('/[\r\n]+/si'$data, -1PREG_SPLIT_NO_EMPTY);
  14508.         $u=0;
  14509.         $cnt count($lines);
  14510.         for ($i=0$i $cnt; ++$i) {
  14511.             $line $lines[$i];
  14512.             if (($line == '') OR ($line[0] == '%')) {
  14513.                 continue;
  14514.             }
  14515.             $len strlen($line);
  14516.             // check for spot color names
  14517.             $color_name '';
  14518.             if (strcasecmp('x'substr(trim($line), -1)) == 0) {
  14519.                 if (preg_match('/\([^\)]*\)/'$line$matches) > 0) {
  14520.                     // extract spot color name
  14521.                     $color_name $matches[0];
  14522.                     // remove color name from string
  14523.                     $line str_replace(' '.$color_name''$line);
  14524.                     // remove pharentesis from color name
  14525.                     $color_name substr($color_name1, -1);
  14526.                 }
  14527.             }
  14528.             $chunks explode(' '$line);
  14529.             $cmd trim(array_pop($chunks));
  14530.             // RGB
  14531.             if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14532.                 $b array_pop($chunks);
  14533.                 $g array_pop($chunks);
  14534.                 $r array_pop($chunks);
  14535.                 $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!
  14536.                 continue;
  14537.             }
  14538.             $skip false;
  14539.             if ($fixoutvals) {
  14540.                 // check for values outside the bounding box
  14541.                 switch ($cmd) {
  14542.                     case 'm':
  14543.                     case 'l':
  14544.                     case 'L': {
  14545.                         // skip values outside bounding box
  14546.                         foreach ($chunks as $key => $val) {
  14547.                             if ((($key 2) == 0) AND (($val $x1) OR ($val $x2))) {
  14548.                                 $skip true;
  14549.                             } elseif ((($key 2) != 0) AND (($val $y1) OR ($val $y2))) {
  14550.                                 $skip true;
  14551.                             }
  14552.                         }
  14553.                     }
  14554.                 }
  14555.             }
  14556.             switch ($cmd) {
  14557.                 case 'm':
  14558.                 case 'l':
  14559.                 case 'v':
  14560.                 case 'y':
  14561.                 case 'c':
  14562.                 case 'k':
  14563.                 case 'K':
  14564.                 case 'g':
  14565.                 case 'G':
  14566.                 case 's':
  14567.                 case 'S':
  14568.                 case 'J':
  14569.                 case 'j':
  14570.                 case 'w':
  14571.                 case 'M':
  14572.                 case 'd':
  14573.                 case 'n': {
  14574.                     if ($skip) {
  14575.                         break;
  14576.                     }
  14577.                     $this->_out($line);
  14578.                     break;
  14579.                 }
  14580.                 case 'x': {// custom fill color
  14581.                     if (empty($color_name)) {
  14582.                         // CMYK color
  14583.                         list($col_c$col_m$col_y$col_k) = $chunks;
  14584.                         $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14585.                     } else {
  14586.                         // Spot Color (CMYK + tint)
  14587.                         list($col_c$col_m$col_y$col_k$col_t) = $chunks;
  14588.                         $this->AddSpotColor($color_name, ($col_c 100), ($col_m 100), ($col_y 100), ($col_k 100));
  14589.                         $color_cmd sprintf('/CS%d cs %F scn'$this->spot_colors[$color_name]['i'], ($col_t));
  14590.                         $this->_out($color_cmd);
  14591.                     }
  14592.                     break;
  14593.                 }
  14594.                 case 'X': { // custom stroke color
  14595.                     if (empty($color_name)) {
  14596.                         // CMYK color
  14597.                         list($col_c$col_m$col_y$col_k) = $chunks;
  14598.                         $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14599.                     } else {
  14600.                         // Spot Color (CMYK + tint)
  14601.                         list($col_c$col_m$col_y$col_k$col_t) = $chunks;
  14602.                         $this->AddSpotColor($color_name, ($col_c 100), ($col_m 100), ($col_y 100), ($col_k 100));
  14603.                         $color_cmd sprintf('/CS%d CS %F SCN'$this->spot_colors[$color_name]['i'], ($col_t));
  14604.                         $this->_out($color_cmd);
  14605.                     }
  14606.                     break;
  14607.                 }
  14608.                 case 'Y':
  14609.                 case 'N':
  14610.                 case 'V':
  14611.                 case 'L':
  14612.                 case 'C': {
  14613.                     if ($skip) {
  14614.                         break;
  14615.                     }
  14616.                     $line[($len 1)] = strtolower($cmd);
  14617.                     $this->_out($line);
  14618.                     break;
  14619.                 }
  14620.                 case 'b':
  14621.                 case 'B': {
  14622.                     $this->_out($cmd '*');
  14623.                     break;
  14624.                 }
  14625.                 case 'f':
  14626.                 case 'F': {
  14627.                     if ($u 0) {
  14628.                         $isU false;
  14629.                         $max min(($i 5), $cnt);
  14630.                         for ($j = ($i 1); $j $max; ++$j) {
  14631.                             $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14632.                         }
  14633.                         if ($isU) {
  14634.                             $this->_out('f*');
  14635.                         }
  14636.                     } else {
  14637.                         $this->_out('f*');
  14638.                     }
  14639.                     break;
  14640.                 }
  14641.                 case '*u': {
  14642.                     ++$u;
  14643.                     break;
  14644.                 }
  14645.                 case '*U': {
  14646.                     --$u;
  14647.                     break;
  14648.                 }
  14649.             }
  14650.         }
  14651.         // restore previous graphic state
  14652.         $this->_out($this->epsmarker.'Q');
  14653.         if (!empty($border)) {
  14654.             $bx $this->x;
  14655.             $by $this->y;
  14656.             $this->$ximg;
  14657.             if ($this->rtl) {
  14658.                 $this->+= $w;
  14659.             }
  14660.             $this->$y;
  14661.             $this->Cell($w$h''$border0''0''0true);
  14662.             $this->$bx;
  14663.             $this->$by;
  14664.         }
  14665.         if ($link) {
  14666.             $this->Link($ximg$y$w$h$link0);
  14667.         }
  14668.         // set pointer to align the next text/objects
  14669.         switch($align) {
  14670.             case 'T':{
  14671.                 $this->$y;
  14672.                 $this->$this->img_rb_x;
  14673.                 break;
  14674.             }
  14675.             case 'M':{
  14676.                 $this->$y round($h/2);
  14677.                 $this->$this->img_rb_x;
  14678.                 break;
  14679.             }
  14680.             case 'B':{
  14681.                 $this->$this->img_rb_y;
  14682.                 $this->$this->img_rb_x;
  14683.                 break;
  14684.             }
  14685.             case 'N':{
  14686.                 $this->setY($this->img_rb_y);
  14687.                 break;
  14688.             }
  14689.             default:{
  14690.                 break;
  14691.             }
  14692.         }
  14693.         $this->endlinex $this->img_rb_x;
  14694.     }
  14695.     /**
  14696.      * Set document barcode.
  14697.      * @param string $bc barcode
  14698.      * @public
  14699.      */
  14700.     public function setBarcode($bc='') {
  14701.         $this->barcode $bc;
  14702.     }
  14703.     /**
  14704.      * Get current barcode.
  14705.      * @return string
  14706.      * @public
  14707.      * @since 4.0.012 (2008-07-24)
  14708.      */
  14709.     public function getBarcode() {
  14710.         return $this->barcode;
  14711.     }
  14712.     /**
  14713.      * Print a Linear Barcode.
  14714.      * @param string $code code to print
  14715.      * @param string $type type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14716.      * @param float|null $x x position in user units (null = current x position)
  14717.      * @param float|null $y y position in user units (null = current y position)
  14718.      * @param float|null $w width in user units (null = remaining page width)
  14719.      * @param float|null $h height in user units (null = remaining page height)
  14720.      * @param float|null $xres width of the smallest bar in user units (null = default value = 0.4mm)
  14721.      * @param array $style array of options:<ul>
  14722.      * <li>boolean $style['border'] if true prints a border</li>
  14723.      * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14724.      * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14725.      * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14726.      * <li>array $style['fgcolor'] color array for bars and text</li>
  14727.      * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14728.      * <li>boolean $style['text'] if true prints text below the barcode</li>
  14729.      * <li>string $style['label'] override default label</li>
  14730.      * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14731.      * <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>
  14732.      * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14733.      * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14734.      * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14735.      * <li>string $style['fitwidth'] if true reduce the width to fit the barcode width + padding. When this option is enabled the 'stretch' option is automatically disabled.</li>
  14736.      * <li>string $style['cellfitalign'] this option works only when 'fitwidth' is true and 'position' is unset or empty. Set the horizontal position of the containing barcode cell inside the specified rectangle: L = left; C = center; R = right.</li></ul>
  14737.      * @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>
  14738.      * @author Nicola Asuni
  14739.      * @since 3.1.000 (2008-06-09)
  14740.      * @public
  14741.      */
  14742.     public function write1DBarcode($code$type$x=null$y=null$w=null$h=null$xres=null$style=array(), $align='') {
  14743.         if (TCPDF_STATIC::empty_string(trim($code))) {
  14744.             return;
  14745.         }
  14746.         require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
  14747.         // save current graphic settings
  14748.         $gvars $this->getGraphicVars();
  14749.         // create new barcode object
  14750.         $barcodeobj = new TCPDFBarcode($code$type);
  14751.         $arrcode $barcodeobj->getBarcodeArray();
  14752.         if (empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  14753.             $this->Error('Error in 1D barcode string');
  14754.         }
  14755.         if ($arrcode['maxh'] <= 0) {
  14756.             $arrcode['maxh'] = 1;
  14757.         }
  14758.         // set default values
  14759.         if (!isset($style['position'])) {
  14760.             $style['position'] = '';
  14761.         } elseif ($style['position'] == 'S') {
  14762.             // keep this for backward compatibility
  14763.             $style['position'] = '';
  14764.             $style['stretch'] = true;
  14765.         }
  14766.         if (!isset($style['fitwidth'])) {
  14767.             if (!isset($style['stretch'])) {
  14768.                 $style['fitwidth'] = true;
  14769.             } else {
  14770.                 $style['fitwidth'] = false;
  14771.             }
  14772.         }
  14773.         if ($style['fitwidth']) {
  14774.             // disable stretch
  14775.             $style['stretch'] = false;
  14776.         }
  14777.         if (!isset($style['stretch'])) {
  14778.             if (($w === '') OR ($w <= 0)) {
  14779.                 $style['stretch'] = false;
  14780.             } else {
  14781.                 $style['stretch'] = true;
  14782.             }
  14783.         }
  14784.         if (!isset($style['fgcolor'])) {
  14785.             $style['fgcolor'] = array(0,0,0); // default black
  14786.         }
  14787.         if (!isset($style['bgcolor'])) {
  14788.             $style['bgcolor'] = false// default transparent
  14789.         }
  14790.         if (!isset($style['border'])) {
  14791.             $style['border'] = false;
  14792.         }
  14793.         $fontsize 0;
  14794.         if (!isset($style['text'])) {
  14795.             $style['text'] = false;
  14796.         }
  14797.         if ($style['text'] AND isset($style['font'])) {
  14798.             if (isset($style['fontsize'])) {
  14799.                 $fontsize $style['fontsize'];
  14800.             }
  14801.             $this->setFont($style['font'], ''$fontsize);
  14802.         }
  14803.         if (!isset($style['stretchtext'])) {
  14804.             $style['stretchtext'] = 4;
  14805.         }
  14806.         if (TCPDF_STATIC::empty_string($x)) {
  14807.             $x $this->x;
  14808.         }
  14809.         if (TCPDF_STATIC::empty_string($y)) {
  14810.             $y $this->y;
  14811.         }
  14812.         // check page for no-write regions and adapt page margins if necessary
  14813.         list($x$y) = $this->checkPageRegions($h$x$y);
  14814.         if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  14815.             if ($this->rtl) {
  14816.                 $w $x $this->lMargin;
  14817.             } else {
  14818.                 $w $this->$this->rMargin $x;
  14819.             }
  14820.         }
  14821.         // padding
  14822.         if (!isset($style['padding'])) {
  14823.             $padding 0;
  14824.         } elseif ($style['padding'] === 'auto') {
  14825.             $padding 10 * ($w / ($arrcode['maxw'] + 20));
  14826.         } else {
  14827.             $padding floatval($style['padding']);
  14828.         }
  14829.         // horizontal padding
  14830.         if (!isset($style['hpadding'])) {
  14831.             $hpadding $padding;
  14832.         } elseif ($style['hpadding'] === 'auto') {
  14833.             $hpadding 10 * ($w / ($arrcode['maxw'] + 20));
  14834.         } else {
  14835.             $hpadding floatval($style['hpadding']);
  14836.         }
  14837.         // vertical padding
  14838.         if (!isset($style['vpadding'])) {
  14839.             $vpadding $padding;
  14840.         } elseif ($style['vpadding'] === 'auto') {
  14841.             $vpadding = ($hpadding 2);
  14842.         } else {
  14843.             $vpadding floatval($style['vpadding']);
  14844.         }
  14845.         // calculate xres (single bar width)
  14846.         $max_xres = ($w - ($hpadding)) / $arrcode['maxw'];
  14847.         if ($style['stretch']) {
  14848.             $xres $max_xres;
  14849.         } else {
  14850.             if (TCPDF_STATIC::empty_string($xres)) {
  14851.                 $xres = (0.141 $this->k); // default bar width = 0.4 mm
  14852.             }
  14853.             if ($xres $max_xres) {
  14854.                 // correct xres to fit on $w
  14855.                 $xres $max_xres;
  14856.             }
  14857.             if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  14858.                 OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  14859.                 $hpadding 10 $xres;
  14860.                 if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  14861.                     $vpadding = ($hpadding 2);
  14862.                 }
  14863.             }
  14864.         }
  14865.         if ($style['fitwidth']) {
  14866.             $wold $w;
  14867.             $w = (($arrcode['maxw'] * $xres) + ($hpadding));
  14868.             if (isset($style['cellfitalign'])) {
  14869.                 switch ($style['cellfitalign']) {
  14870.                     case 'L': {
  14871.                         if ($this->rtl) {
  14872.                             $x -= ($wold $w);
  14873.                         }
  14874.                         break;
  14875.                     }
  14876.                     case 'R': {
  14877.                         if (!$this->rtl) {
  14878.                             $x += ($wold $w);
  14879.                         }
  14880.                         break;
  14881.                     }
  14882.                     case 'C': {
  14883.                         if ($this->rtl) {
  14884.                             $x -= (($wold $w) / 2);
  14885.                         } else {
  14886.                             $x += (($wold $w) / 2);
  14887.                         }
  14888.                         break;
  14889.                     }
  14890.                     default : {
  14891.                         break;
  14892.                     }
  14893.                 }
  14894.             }
  14895.         }
  14896.         $text_height $this->getCellHeight($fontsize $this->k);
  14897.         // height
  14898.         if (TCPDF_STATIC::empty_string($h) OR ($h <= 0)) {
  14899.             // set default height
  14900.             $h = (($arrcode['maxw'] * $xres) / 3) + ($vpadding) + $text_height;
  14901.         }
  14902.         $barh $h $text_height - ($vpadding);
  14903.         if ($barh <=0) {
  14904.             // try to reduce font or padding to fit barcode on available height
  14905.             if ($text_height $h) {
  14906.                 $fontsize = (($h $this->k) / ($this->cell_height_ratio));
  14907.                 $text_height $this->getCellHeight($fontsize $this->k);
  14908.                 $this->setFont($style['font'], ''$fontsize);
  14909.             }
  14910.             if ($vpadding 0) {
  14911.                 $vpadding = (($h $text_height) / 4);
  14912.             }
  14913.             $barh $h $text_height - ($vpadding);
  14914.         }
  14915.         // fit the barcode on available space
  14916.         list($w$h$x$y) = $this->fitBlock($w$h$x$yfalse);
  14917.         // set alignment
  14918.         $this->img_rb_y $y $h;
  14919.         // set alignment
  14920.         if ($this->rtl) {
  14921.             if ($style['position'] == 'L') {
  14922.                 $xpos $this->lMargin;
  14923.             } elseif ($style['position'] == 'C') {
  14924.                 $xpos = ($this->$this->lMargin $this->rMargin $w) / 2;
  14925.             } elseif ($style['position'] == 'R') {
  14926.                 $xpos $this->$this->rMargin $w;
  14927.             } else {
  14928.                 $xpos $x $w;
  14929.             }
  14930.             $this->img_rb_x $xpos;
  14931.         } else {
  14932.             if ($style['position'] == 'L') {
  14933.                 $xpos $this->lMargin;
  14934.             } elseif ($style['position'] == 'C') {
  14935.                 $xpos = ($this->$this->lMargin $this->rMargin $w) / 2;
  14936.             } elseif ($style['position'] == 'R') {
  14937.                 $xpos $this->$this->rMargin $w;
  14938.             } else {
  14939.                 $xpos $x;
  14940.             }
  14941.             $this->img_rb_x $xpos $w;
  14942.         }
  14943.         $xpos_rect $xpos;
  14944.         if (!isset($style['align'])) {
  14945.             $style['align'] = 'C';
  14946.         }
  14947.         switch ($style['align']) {
  14948.             case 'L': {
  14949.                 $xpos $xpos_rect $hpadding;
  14950.                 break;
  14951.             }
  14952.             case 'R': {
  14953.                 $xpos $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  14954.                 break;
  14955.             }
  14956.             case 'C':
  14957.             default : {
  14958.                 $xpos $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  14959.                 break;
  14960.             }
  14961.         }
  14962.         $xpos_text $xpos;
  14963.         // barcode is always printed in LTR direction
  14964.         $tempRTL $this->rtl;
  14965.         $this->rtl false;
  14966.         // print background color
  14967.         if ($style['bgcolor']) {
  14968.             $this->Rect($xpos_rect$y$w$h$style['border'] ? 'DF' 'F'''$style['bgcolor']);
  14969.         } elseif ($style['border']) {
  14970.             $this->Rect($xpos_rect$y$w$h'D');
  14971.         }
  14972.         // set foreground color
  14973.         $this->setDrawColorArray($style['fgcolor']);
  14974.         $this->setTextColorArray($style['fgcolor']);
  14975.         // print bars
  14976.         foreach ($arrcode['bcode'] as $k => $v) {
  14977.             $bw = ($v['w'] * $xres);
  14978.             if ($v['t']) {
  14979.                 // draw a vertical bar
  14980.                 $ypos $y $vpadding + ($v['p'] * $barh $arrcode['maxh']);
  14981.                 $this->Rect($xpos$ypos$bw, ($v['h'] * $barh $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  14982.             }
  14983.             $xpos += $bw;
  14984.         }
  14985.         // print text
  14986.         if ($style['text']) {
  14987.             if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  14988.                 $label $style['label'];
  14989.             } else {
  14990.                 $label $code;
  14991.             }
  14992.             $txtwidth = ($arrcode['maxw'] * $xres);
  14993.             if ($this->GetStringWidth($label) > $txtwidth) {
  14994.                 $style['stretchtext'] = 2;
  14995.             }
  14996.             // print text
  14997.             $this->$xpos_text;
  14998.             $this->$y $vpadding $barh;
  14999.             $cellpadding $this->cell_padding;
  15000.             $this->setCellPadding(0);
  15001.             $this->Cell($txtwidth0$label00'C'false''$style['stretchtext'], false'T''T');
  15002.             $this->cell_padding $cellpadding;
  15003.         }
  15004.         // restore original direction
  15005.         $this->rtl $tempRTL;
  15006.         // restore previous settings
  15007.         $this->setGraphicVars($gvars);
  15008.         // set pointer to align the next text/objects
  15009.         switch($align) {
  15010.             case 'T':{
  15011.                 $this->$y;
  15012.                 $this->$this->img_rb_x;
  15013.                 break;
  15014.             }
  15015.             case 'M':{
  15016.                 $this->$y round($h 2);
  15017.                 $this->$this->img_rb_x;
  15018.                 break;
  15019.             }
  15020.             case 'B':{
  15021.                 $this->$this->img_rb_y;
  15022.                 $this->$this->img_rb_x;
  15023.                 break;
  15024.             }
  15025.             case 'N':{
  15026.                 $this->setY($this->img_rb_y);
  15027.                 break;
  15028.             }
  15029.             default:{
  15030.                 break;
  15031.             }
  15032.         }
  15033.         $this->endlinex $this->img_rb_x;
  15034.     }
  15035.     /**
  15036.      * Print 2D Barcode.
  15037.      * @param string $code code to print
  15038.      * @param string $type type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  15039.      * @param float|null $x x position in user units
  15040.      * @param float|null $y y position in user units
  15041.      * @param float|null $w width in user units
  15042.      * @param float|null $h height in user units
  15043.      * @param array $style array of options:<ul>
  15044.      * <li>boolean $style['border'] if true prints a border around the barcode</li>
  15045.      * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  15046.      * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  15047.      * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  15048.      * <li>int $style['module_width'] width of a single module in points</li>
  15049.      * <li>int $style['module_height'] height of a single module in points</li>
  15050.      * <li>array $style['fgcolor'] color array for bars and text</li>
  15051.      * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  15052.      * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li>
  15053.      * @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>
  15054.      * @param boolean $distort if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  15055.      * @author Nicola Asuni
  15056.      * @since 4.5.037 (2009-04-07)
  15057.      * @public
  15058.      */
  15059.     public function write2DBarcode($code$type$x=null$y=null$w=null$h=null$style=array(), $align=''$distort=false) {
  15060.         if (TCPDF_STATIC::empty_string(trim($code))) {
  15061.             return;
  15062.         }
  15063.         require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
  15064.         // save current graphic settings
  15065.         $gvars $this->getGraphicVars();
  15066.         // create new barcode object
  15067.         $barcodeobj = new TCPDF2DBarcode($code$type);
  15068.         $arrcode $barcodeobj->getBarcodeArray();
  15069.         if (empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  15070.             $this->Error('Error in 2D barcode string');
  15071.         }
  15072.         // set default values
  15073.         if (!isset($style['position'])) {
  15074.             $style['position'] = '';
  15075.         }
  15076.         if (!isset($style['fgcolor'])) {
  15077.             $style['fgcolor'] = array(0,0,0); // default black
  15078.         }
  15079.         if (!isset($style['bgcolor'])) {
  15080.             $style['bgcolor'] = false// default transparent
  15081.         }
  15082.         if (!isset($style['border'])) {
  15083.             $style['border'] = false;
  15084.         }
  15085.         // padding
  15086.         if (!isset($style['padding'])) {
  15087.             $style['padding'] = 0;
  15088.         } elseif ($style['padding'] === 'auto') {
  15089.             $style['padding'] = 4;
  15090.         }
  15091.         if (!isset($style['hpadding'])) {
  15092.             $style['hpadding'] = $style['padding'];
  15093.         } elseif ($style['hpadding'] === 'auto') {
  15094.             $style['hpadding'] = 4;
  15095.         }
  15096.         if (!isset($style['vpadding'])) {
  15097.             $style['vpadding'] = $style['padding'];
  15098.         } elseif ($style['vpadding'] === 'auto') {
  15099.             $style['vpadding'] = 4;
  15100.         }
  15101.         $hpad = ($style['hpadding']);
  15102.         $vpad = ($style['vpadding']);
  15103.         // cell (module) dimension
  15104.         if (!isset($style['module_width'])) {
  15105.             $style['module_width'] = 1// width of a single module in points
  15106.         }
  15107.         if (!isset($style['module_height'])) {
  15108.             $style['module_height'] = 1// height of a single module in points
  15109.         }
  15110.         if (TCPDF_STATIC::empty_string($x)) {
  15111.             $x $this->x;
  15112.         }
  15113.         if (TCPDF_STATIC::empty_string($y)) {
  15114.             $y $this->y;
  15115.         }
  15116.         // check page for no-write regions and adapt page margins if necessary
  15117.         list($x$y) = $this->checkPageRegions($h$x$y);
  15118.         // number of barcode columns and rows
  15119.         $rows $arrcode['num_rows'];
  15120.         $cols $arrcode['num_cols'];
  15121.         if (($rows <= 0) || ($cols <= 0)){
  15122.             $this->Error('Error in 2D barcode string');
  15123.         }
  15124.         // module width and height
  15125.         $mw $style['module_width'];
  15126.         $mh $style['module_height'];
  15127.         if (($mw <= 0) OR ($mh <= 0)) {
  15128.             $this->Error('Error in 2D barcode string');
  15129.         }
  15130.         // get max dimensions
  15131.         if ($this->rtl) {
  15132.             $maxw $x $this->lMargin;
  15133.         } else {
  15134.             $maxw $this->$this->rMargin $x;
  15135.         }
  15136.         $maxh = ($this->$this->tMargin $this->bMargin);
  15137.         $ratioHW = ((($rows $mh) + $hpad) / (($cols $mw) + $vpad));
  15138.         $ratioWH = ((($cols $mw) + $vpad) / (($rows $mh) + $hpad));
  15139.         if (!$distort) {
  15140.             if (($maxw $ratioHW) > $maxh) {
  15141.                 $maxw $maxh $ratioWH;
  15142.             }
  15143.             if (($maxh $ratioWH) > $maxw) {
  15144.                 $maxh $maxw $ratioHW;
  15145.             }
  15146.         }
  15147.         // set maximum dimensions
  15148.         if ($w $maxw) {
  15149.             $w $maxw;
  15150.         }
  15151.         if ($h $maxh) {
  15152.             $h $maxh;
  15153.         }
  15154.         // set dimensions
  15155.         if ((TCPDF_STATIC::empty_string($w) OR ($w <= 0)) AND (TCPDF_STATIC::empty_string($h) OR ($h <= 0))) {
  15156.             $w = ($cols $hpad) * ($mw $this->k);
  15157.             $h = ($rows $vpad) * ($mh $this->k);
  15158.         } elseif (($w === '') OR ($w <= 0)) {
  15159.             $w $h $ratioWH;
  15160.         } elseif (($h === '') OR ($h <= 0)) {
  15161.             $h $w $ratioHW;
  15162.         }
  15163.         // barcode size (excluding padding)
  15164.         $bw = ($w $cols) / ($cols $hpad);
  15165.         $bh = ($h $rows) / ($rows $vpad);
  15166.         // dimension of single barcode cell unit
  15167.         $cw $bw $cols;
  15168.         $ch $bh $rows;
  15169.         if (!$distort) {
  15170.             if (($cw $ch) > ($mw $mh)) {
  15171.                 // correct horizontal distortion
  15172.                 $cw $ch $mw $mh;
  15173.                 $bw $cw $cols;
  15174.                 $style['hpadding'] = ($w $bw) / ($cw);
  15175.             } else {
  15176.                 // correct vertical distortion
  15177.                 $ch $cw $mh $mw;
  15178.                 $bh $ch $rows;
  15179.                 $style['vpadding'] = ($h $bh) / ($ch);
  15180.             }
  15181.         }
  15182.         // fit the barcode on available space
  15183.         list($w$h$x$y) = $this->fitBlock($w$h$x$yfalse);
  15184.         // set alignment
  15185.         $this->img_rb_y $y $h;
  15186.         // set alignment
  15187.         if ($this->rtl) {
  15188.             if ($style['position'] == 'L') {
  15189.                 $xpos $this->lMargin;
  15190.             } elseif ($style['position'] == 'C') {
  15191.                 $xpos = ($this->$this->lMargin $this->rMargin $w) / 2;
  15192.             } elseif ($style['position'] == 'R') {
  15193.                 $xpos $this->$this->rMargin $w;
  15194.             } else {
  15195.                 $xpos $x $w;
  15196.             }
  15197.             $this->img_rb_x $xpos;
  15198.         } else {
  15199.             if ($style['position'] == 'L') {
  15200.                 $xpos $this->lMargin;
  15201.             } elseif ($style['position'] == 'C') {
  15202.                 $xpos = ($this->$this->lMargin $this->rMargin $w) / 2;
  15203.             } elseif ($style['position'] == 'R') {
  15204.                 $xpos $this->$this->rMargin $w;
  15205.             } else {
  15206.                 $xpos $x;
  15207.             }
  15208.             $this->img_rb_x $xpos $w;
  15209.         }
  15210.         $xstart $xpos + ($style['hpadding'] * $cw);
  15211.         $ystart $y + ($style['vpadding'] * $ch);
  15212.         // barcode is always printed in LTR direction
  15213.         $tempRTL $this->rtl;
  15214.         $this->rtl false;
  15215.         // print background color
  15216.         if ($style['bgcolor']) {
  15217.             $this->Rect($xpos$y$w$h$style['border'] ? 'DF' 'F'''$style['bgcolor']);
  15218.         } elseif ($style['border']) {
  15219.             $this->Rect($xpos$y$w$h'D');
  15220.         }
  15221.         // set foreground color
  15222.         $this->setDrawColorArray($style['fgcolor']);
  15223.         // print barcode cells
  15224.         // for each row
  15225.         for ($r 0$r $rows; ++$r) {
  15226.             $xr $xstart;
  15227.             // for each column
  15228.             for ($c 0$c $cols; ++$c) {
  15229.                 if ($arrcode['bcode'][$r][$c] == 1) {
  15230.                     // draw a single barcode cell
  15231.                     $this->Rect($xr$ystart$cw$ch'F', array(), $style['fgcolor']);
  15232.                 }
  15233.                 $xr += $cw;
  15234.             }
  15235.             $ystart += $ch;
  15236.         }
  15237.         // restore original direction
  15238.         $this->rtl $tempRTL;
  15239.         // restore previous settings
  15240.         $this->setGraphicVars($gvars);
  15241.         // set pointer to align the next text/objects
  15242.         switch($align) {
  15243.             case 'T':{
  15244.                 $this->$y;
  15245.                 $this->$this->img_rb_x;
  15246.                 break;
  15247.             }
  15248.             case 'M':{
  15249.                 $this->$y round($h/2);
  15250.                 $this->$this->img_rb_x;
  15251.                 break;
  15252.             }
  15253.             case 'B':{
  15254.                 $this->$this->img_rb_y;
  15255.                 $this->$this->img_rb_x;
  15256.                 break;
  15257.             }
  15258.             case 'N':{
  15259.                 $this->setY($this->img_rb_y);
  15260.                 break;
  15261.             }
  15262.             default:{
  15263.                 break;
  15264.             }
  15265.         }
  15266.         $this->endlinex $this->img_rb_x;
  15267.     }
  15268.     /**
  15269.      * Returns an array containing current margins:
  15270.      * <ul>
  15271.             <li>$ret['left'] = left margin</li>
  15272.             <li>$ret['right'] = right margin</li>
  15273.             <li>$ret['top'] = top margin</li>
  15274.             <li>$ret['bottom'] = bottom margin</li>
  15275.             <li>$ret['header'] = header margin</li>
  15276.             <li>$ret['footer'] = footer margin</li>
  15277.             <li>$ret['cell'] = cell padding array</li>
  15278.             <li>$ret['padding_left'] = cell left padding</li>
  15279.             <li>$ret['padding_top'] = cell top padding</li>
  15280.             <li>$ret['padding_right'] = cell right padding</li>
  15281.             <li>$ret['padding_bottom'] = cell bottom padding</li>
  15282.      * </ul>
  15283.      * @return array containing all margins measures
  15284.      * @public
  15285.      * @since 3.2.000 (2008-06-23)
  15286.      */
  15287.     public function getMargins() {
  15288.         $ret = array(
  15289.             'left' => $this->lMargin,
  15290.             'right' => $this->rMargin,
  15291.             'top' => $this->tMargin,
  15292.             'bottom' => $this->bMargin,
  15293.             'header' => $this->header_margin,
  15294.             'footer' => $this->footer_margin,
  15295.             'cell' => $this->cell_padding,
  15296.             'padding_left' => $this->cell_padding['L'],
  15297.             'padding_top' => $this->cell_padding['T'],
  15298.             'padding_right' => $this->cell_padding['R'],
  15299.             'padding_bottom' => $this->cell_padding['B']
  15300.         );
  15301.         return $ret;
  15302.     }
  15303.     /**
  15304.      * Returns an array containing original margins:
  15305.      * <ul>
  15306.             <li>$ret['left'] = left margin</li>
  15307.             <li>$ret['right'] = right margin</li>
  15308.      * </ul>
  15309.      * @return array containing all margins measures
  15310.      * @public
  15311.      * @since 4.0.012 (2008-07-24)
  15312.      */
  15313.     public function getOriginalMargins() {
  15314.         $ret = array(
  15315.             'left' => $this->original_lMargin,
  15316.             'right' => $this->original_rMargin
  15317.         );
  15318.         return $ret;
  15319.     }
  15320.     /**
  15321.      * Returns the current font size.
  15322.      * @return float current font size
  15323.      * @public
  15324.      * @since 3.2.000 (2008-06-23)
  15325.      */
  15326.     public function getFontSize() {
  15327.         return $this->FontSize;
  15328.     }
  15329.     /**
  15330.      * Returns the current font size in points unit.
  15331.      * @return int current font size in points unit
  15332.      * @public
  15333.      * @since 3.2.000 (2008-06-23)
  15334.      */
  15335.     public function getFontSizePt() {
  15336.         return $this->FontSizePt;
  15337.     }
  15338.     /**
  15339.      * Returns the current font family name.
  15340.      * @return string current font family name
  15341.      * @public
  15342.      * @since 4.3.008 (2008-12-05)
  15343.      */
  15344.     public function getFontFamily() {
  15345.         return $this->FontFamily;
  15346.     }
  15347.     /**
  15348.      * Returns the current font style.
  15349.      * @return string current font style
  15350.      * @public
  15351.      * @since 4.3.008 (2008-12-05)
  15352.      */
  15353.     public function getFontStyle() {
  15354.         return $this->FontStyle;
  15355.     }
  15356.     /**
  15357.      * Cleanup HTML code (requires HTML Tidy library).
  15358.      * @param string $html htmlcode to fix
  15359.      * @param string $default_css CSS commands to add
  15360.      * @param array|null $tagvs parameters for setHtmlVSpace method
  15361.      * @param array|null $tidy_options options for tidy_parse_string function
  15362.      * @return string XHTML code cleaned up
  15363.      * @author Nicola Asuni
  15364.      * @public
  15365.      * @since 5.9.017 (2010-11-16)
  15366.      * @see setHtmlVSpace()
  15367.      */
  15368.     public function fixHTMLCode($html$default_css=''$tagvs=null$tidy_options=null) {
  15369.         return TCPDF_STATIC::fixHTMLCode($html$default_css$tagvs$tidy_options$this->tagvspaces);
  15370.     }
  15371.     /**
  15372.      * Returns the border width from CSS property
  15373.      * @param string $width border width
  15374.      * @return int with in user units
  15375.      * @protected
  15376.      * @since 5.7.000 (2010-08-02)
  15377.      */
  15378.     protected function getCSSBorderWidth($width) {
  15379.         if ($width == 'thin') {
  15380.             $width = ($this->k);
  15381.         } elseif ($width == 'medium') {
  15382.             $width = ($this->k);
  15383.         } elseif ($width == 'thick') {
  15384.             $width = ($this->k);
  15385.         } else {
  15386.             $width $this->getHTMLUnitToUnits($width1'px'false);
  15387.         }
  15388.         return $width;
  15389.     }
  15390.     /**
  15391.      * Returns the border dash style from CSS property
  15392.      * @param string $style border style to convert
  15393.      * @return int sash style (return -1 in case of none or hidden border)
  15394.      * @protected
  15395.      * @since 5.7.000 (2010-08-02)
  15396.      */
  15397.     protected function getCSSBorderDashStyle($style) {
  15398.         switch (strtolower($style)) {
  15399.             case 'none':
  15400.             case 'hidden': {
  15401.                 $dash = -1;
  15402.                 break;
  15403.             }
  15404.             case 'dotted': {
  15405.                 $dash 1;
  15406.                 break;
  15407.             }
  15408.             case 'dashed': {
  15409.                 $dash 3;
  15410.                 break;
  15411.             }
  15412.             case 'double':
  15413.             case 'groove':
  15414.             case 'ridge':
  15415.             case 'inset':
  15416.             case 'outset':
  15417.             case 'solid':
  15418.             default: {
  15419.                 $dash 0;
  15420.                 break;
  15421.             }
  15422.         }
  15423.         return $dash;
  15424.     }
  15425.     /**
  15426.      * Returns the border style array from CSS border properties
  15427.      * @param string $cssborder border properties
  15428.      * @return array containing border properties
  15429.      * @protected
  15430.      * @since 5.7.000 (2010-08-02)
  15431.      */
  15432.     protected function getCSSBorderStyle($cssborder) {
  15433.         $bprop preg_split('/[\s]+/'trim($cssborder));
  15434.         $count count($bprop);
  15435.         if ($count && $bprop[$count 1] === '!important') {
  15436.             unset($bprop[$count 1]);
  15437.             --$count;
  15438.         }
  15439.         $border = array(); // value to be returned
  15440.         switch ($count) {
  15441.             case 2: {
  15442.                 $width 'medium';
  15443.                 $style $bprop[0];
  15444.                 $color $bprop[1];
  15445.                 break;
  15446.             }
  15447.             case 1: {
  15448.                 $width 'medium';
  15449.                 $style $bprop[0];
  15450.                 $color 'black';
  15451.                 break;
  15452.             }
  15453.             case 0: {
  15454.                 $width 'medium';
  15455.                 $style 'solid';
  15456.                 $color 'black';
  15457.                 break;
  15458.             }
  15459.             default: {
  15460.                 $width $bprop[0];
  15461.                 $style $bprop[1];
  15462.                 $color $bprop[2];
  15463.                 break;
  15464.             }
  15465.         }
  15466.         if ($style == 'none') {
  15467.             return array();
  15468.         }
  15469.         $border['cap'] = 'square';
  15470.         $border['join'] = 'miter';
  15471.         $border['dash'] = $this->getCSSBorderDashStyle($style);
  15472.         if ($border['dash'] < 0) {
  15473.             return array();
  15474.         }
  15475.         $border['width'] = $this->getCSSBorderWidth($width);
  15476.         $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color$this->spot_colors);
  15477.         return $border;
  15478.     }
  15479.     /**
  15480.      * Get the internal Cell padding from CSS attribute.
  15481.      * @param string $csspadding padding properties
  15482.      * @param float $width width of the containing element
  15483.      * @return array of cell paddings
  15484.      * @public
  15485.      * @since 5.9.000 (2010-10-04)
  15486.      */
  15487.     public function getCSSPadding($csspadding$width=0) {
  15488.         $padding preg_split('/[\s]+/'trim($csspadding));
  15489.         $cell_padding = array(); // value to be returned
  15490.         switch (count($padding)) {
  15491.             case 4: {
  15492.                 $cell_padding['T'] = $padding[0];
  15493.                 $cell_padding['R'] = $padding[1];
  15494.                 $cell_padding['B'] = $padding[2];
  15495.                 $cell_padding['L'] = $padding[3];
  15496.                 break;
  15497.             }
  15498.             case 3: {
  15499.                 $cell_padding['T'] = $padding[0];
  15500.                 $cell_padding['R'] = $padding[1];
  15501.                 $cell_padding['B'] = $padding[2];
  15502.                 $cell_padding['L'] = $padding[1];
  15503.                 break;
  15504.             }
  15505.             case 2: {
  15506.                 $cell_padding['T'] = $padding[0];
  15507.                 $cell_padding['R'] = $padding[1];
  15508.                 $cell_padding['B'] = $padding[0];
  15509.                 $cell_padding['L'] = $padding[1];
  15510.                 break;
  15511.             }
  15512.             case 1: {
  15513.                 $cell_padding['T'] = $padding[0];
  15514.                 $cell_padding['R'] = $padding[0];
  15515.                 $cell_padding['B'] = $padding[0];
  15516.                 $cell_padding['L'] = $padding[0];
  15517.                 break;
  15518.             }
  15519.             default: {
  15520.                 return $this->cell_padding;
  15521.             }
  15522.         }
  15523.         if ($width == 0) {
  15524.             $width $this->$this->lMargin $this->rMargin;
  15525.         }
  15526.         $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width'px'false);
  15527.         $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width'px'false);
  15528.         $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width'px'false);
  15529.         $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width'px'false);
  15530.         return $cell_padding;
  15531.     }
  15532.     /**
  15533.      * Get the internal Cell margin from CSS attribute.
  15534.      * @param string $cssmargin margin properties
  15535.      * @param float $width width of the containing element
  15536.      * @return array of cell margins
  15537.      * @public
  15538.      * @since 5.9.000 (2010-10-04)
  15539.      */
  15540.     public function getCSSMargin($cssmargin$width=0) {
  15541.         $margin preg_split('/[\s]+/'trim($cssmargin));
  15542.         $cell_margin = array(); // value to be returned
  15543.         switch (count($margin)) {
  15544.             case 4: {
  15545.                 $cell_margin['T'] = $margin[0];
  15546.                 $cell_margin['R'] = $margin[1];
  15547.                 $cell_margin['B'] = $margin[2];
  15548.                 $cell_margin['L'] = $margin[3];
  15549.                 break;
  15550.             }
  15551.             case 3: {
  15552.                 $cell_margin['T'] = $margin[0];
  15553.                 $cell_margin['R'] = $margin[1];
  15554.                 $cell_margin['B'] = $margin[2];
  15555.                 $cell_margin['L'] = $margin[1];
  15556.                 break;
  15557.             }
  15558.             case 2: {
  15559.                 $cell_margin['T'] = $margin[0];
  15560.                 $cell_margin['R'] = $margin[1];
  15561.                 $cell_margin['B'] = $margin[0];
  15562.                 $cell_margin['L'] = $margin[1];
  15563.                 break;
  15564.             }
  15565.             case 1: {
  15566.                 $cell_margin['T'] = $margin[0];
  15567.                 $cell_margin['R'] = $margin[0];
  15568.                 $cell_margin['B'] = $margin[0];
  15569.                 $cell_margin['L'] = $margin[0];
  15570.                 break;
  15571.             }
  15572.             default: {
  15573.                 return $this->cell_margin;
  15574.             }
  15575.         }
  15576.         if ($width == 0) {
  15577.             $width $this->$this->lMargin $this->rMargin;
  15578.         }
  15579.         $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto''0'$cell_margin['T']), $width'px'false);
  15580.         $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto''0'$cell_margin['R']), $width'px'false);
  15581.         $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto''0'$cell_margin['B']), $width'px'false);
  15582.         $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto''0'$cell_margin['L']), $width'px'false);
  15583.         return $cell_margin;
  15584.     }
  15585.     /**
  15586.      * Get the border-spacing from CSS attribute.
  15587.      * @param string $cssbspace border-spacing CSS properties
  15588.      * @param float $width width of the containing element
  15589.      * @return array of border spacings
  15590.      * @public
  15591.      * @since 5.9.010 (2010-10-27)
  15592.      */
  15593.     public function getCSSBorderMargin($cssbspace$width=0) {
  15594.         $space preg_split('/[\s]+/'trim($cssbspace));
  15595.         $border_spacing = array(); // value to be returned
  15596.         switch (count($space)) {
  15597.             case 2: {
  15598.                 $border_spacing['H'] = $space[0];
  15599.                 $border_spacing['V'] = $space[1];
  15600.                 break;
  15601.             }
  15602.             case 1: {
  15603.                 $border_spacing['H'] = $space[0];
  15604.                 $border_spacing['V'] = $space[0];
  15605.                 break;
  15606.             }
  15607.             default: {
  15608.                 return array('H' => 0'V' => 0);
  15609.             }
  15610.         }
  15611.         if ($width == 0) {
  15612.             $width $this->$this->lMargin $this->rMargin;
  15613.         }
  15614.         $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width'px'false);
  15615.         $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width'px'false);
  15616.         return $border_spacing;
  15617.     }
  15618.     /**
  15619.      * Returns the letter-spacing value from CSS value
  15620.      * @param string $spacing letter-spacing value
  15621.      * @param float $parent font spacing (tracking) value of the parent element
  15622.      * @return float quantity to increases or decreases the space between characters in a text.
  15623.      * @protected
  15624.      * @since 5.9.000 (2010-10-02)
  15625.      */
  15626.     protected function getCSSFontSpacing($spacing$parent=0) {
  15627.         $val 0// value to be returned
  15628.         $spacing trim($spacing);
  15629.         switch ($spacing) {
  15630.             case 'normal': {
  15631.                 $val 0;
  15632.                 break;
  15633.             }
  15634.             case 'inherit': {
  15635.                 if ($parent == 'normal') {
  15636.                     $val 0;
  15637.                 } else {
  15638.                     $val $parent;
  15639.                 }
  15640.                 break;
  15641.             }
  15642.             default: {
  15643.                 $val $this->getHTMLUnitToUnits($spacing0'px'false);
  15644.             }
  15645.         }
  15646.         return $val;
  15647.     }
  15648.     /**
  15649.      * Returns the percentage of font stretching from CSS value
  15650.      * @param string $stretch stretch mode
  15651.      * @param float $parent stretch value of the parent element
  15652.      * @return float font stretching percentage
  15653.      * @protected
  15654.      * @since 5.9.000 (2010-10-02)
  15655.      */
  15656.     protected function getCSSFontStretching($stretch$parent=100) {
  15657.         $val 100// value to be returned
  15658.         $stretch trim($stretch);
  15659.         switch ($stretch) {
  15660.             case 'ultra-condensed': {
  15661.                 $val 40;
  15662.                 break;
  15663.             }
  15664.             case 'extra-condensed': {
  15665.                 $val 55;
  15666.                 break;
  15667.             }
  15668.             case 'condensed': {
  15669.                 $val 70;
  15670.                 break;
  15671.             }
  15672.             case 'semi-condensed': {
  15673.                 $val 85;
  15674.                 break;
  15675.             }
  15676.             case 'normal': {
  15677.                 $val 100;
  15678.                 break;
  15679.             }
  15680.             case 'semi-expanded': {
  15681.                 $val 115;
  15682.                 break;
  15683.             }
  15684.             case 'expanded': {
  15685.                 $val 130;
  15686.                 break;
  15687.             }
  15688.             case 'extra-expanded': {
  15689.                 $val 145;
  15690.                 break;
  15691.             }
  15692.             case 'ultra-expanded': {
  15693.                 $val 160;
  15694.                 break;
  15695.             }
  15696.             case 'wider': {
  15697.                 $val = ($parent 10);
  15698.                 break;
  15699.             }
  15700.             case 'narrower': {
  15701.                 $val = ($parent 10);
  15702.                 break;
  15703.             }
  15704.             case 'inherit': {
  15705.                 if ($parent == 'normal') {
  15706.                     $val 100;
  15707.                 } else {
  15708.                     $val $parent;
  15709.                 }
  15710.                 break;
  15711.             }
  15712.             default: {
  15713.                 $val $this->getHTMLUnitToUnits($stretch100'%'false);
  15714.             }
  15715.         }
  15716.         return $val;
  15717.     }
  15718.     /**
  15719.      * Convert HTML string containing font size value to points
  15720.      * @param string $val String containing font size value and unit.
  15721.      * @param float $refsize Reference font size in points.
  15722.      * @param float $parent_size Parent font size in points.
  15723.      * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15724.      * @return float value in points
  15725.      * @public
  15726.      */
  15727.     public function getHTMLFontUnits($val$refsize=12$parent_size=12$defaultunit='pt') {
  15728.         $refsize TCPDF_FONTS::getFontRefSize($refsize);
  15729.         $parent_size TCPDF_FONTS::getFontRefSize($parent_size$refsize);
  15730.         switch ($val) {
  15731.             case 'xx-small': {
  15732.                 $size = ($refsize 4);
  15733.                 break;
  15734.             }
  15735.             case 'x-small': {
  15736.                 $size = ($refsize 3);
  15737.                 break;
  15738.             }
  15739.             case 'small': {
  15740.                 $size = ($refsize 2);
  15741.                 break;
  15742.             }
  15743.             case 'medium': {
  15744.                 $size $refsize;
  15745.                 break;
  15746.             }
  15747.             case 'large': {
  15748.                 $size = ($refsize 2);
  15749.                 break;
  15750.             }
  15751.             case 'x-large': {
  15752.                 $size = ($refsize 4);
  15753.                 break;
  15754.             }
  15755.             case 'xx-large': {
  15756.                 $size = ($refsize 6);
  15757.                 break;
  15758.             }
  15759.             case 'smaller': {
  15760.                 $size = ($parent_size 3);
  15761.                 break;
  15762.             }
  15763.             case 'larger': {
  15764.                 $size = ($parent_size 3);
  15765.                 break;
  15766.             }
  15767.             default: {
  15768.                 $parentSize $this->getHTMLUnitToUnits($parent_size$refsize$defaultunittrue);
  15769.                 $size $this->getHTMLUnitToUnits($val$parent_size$defaultunittrue);
  15770.             }
  15771.         }
  15772.         return $size;
  15773.     }
  15774.     /**
  15775.      * Returns the HTML DOM array.
  15776.      * @param string $html html code
  15777.      * @return array
  15778.      * @protected
  15779.      * @since 3.2.000 (2008-06-20)
  15780.      */
  15781.     protected function getHtmlDomArray($html) {
  15782.         // array of CSS styles ( selector => properties).
  15783.         $css = array();
  15784.         // get CSS array defined at previous call
  15785.         $matches = array();
  15786.         if (preg_match_all('/<cssarray>([^\<]*?)<\/cssarray>/is'$html$matches) > 0) {
  15787.             if (isset($matches[1][0])) {
  15788.                 $css array_merge($cssjson_decode($this->unhtmlentities($matches[1][0]), true));
  15789.             }
  15790.             $html preg_replace('/<cssarray>(.*?)<\/cssarray>/is'''$html);
  15791.         }
  15792.         // extract external CSS files
  15793.         $matches = array();
  15794.         if (preg_match_all('/<link([^\>]*?)>/is'$html$matches) > 0) {
  15795.             foreach ($matches[1] as $key => $link) {
  15796.                 $type = array();
  15797.                 if (preg_match('/type[\s]*=[\s]*"text\/css"/'$link$type)) {
  15798.                     $type = array();
  15799.                     preg_match('/media[\s]*=[\s]*"([^"]*)"/'$link$type);
  15800.                     // get 'all' and 'print' media, other media types are discarded
  15801.                     // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15802.                     if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15803.                         $type = array();
  15804.                         if (preg_match('/href[\s]*=[\s]*"([^"]*)"/'$link$type) > 0) {
  15805.                             // read CSS data file
  15806.                             $cssdata $this->getCachedFileContents(trim($type[1]));
  15807.                             if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
  15808.                                 $css array_merge($cssTCPDF_STATIC::extractCSSproperties($cssdata));
  15809.                             }
  15810.                         }
  15811.                     }
  15812.                 }
  15813.             }
  15814.         }
  15815.         // extract style tags
  15816.         $matches = array();
  15817.         if (preg_match_all('/<style([^\>]*?)>([^\<]*?)<\/style>/is'$html$matches) > 0) {
  15818.             foreach ($matches[1] as $key => $media) {
  15819.                 $type = array();
  15820.                 preg_match('/media[\s]*=[\s]*"([^"]*)"/'$media$type);
  15821.                 // get 'all' and 'print' media, other media types are discarded
  15822.                 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15823.                 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15824.                     $cssdata $matches[2][$key];
  15825.                     $css array_merge($cssTCPDF_STATIC::extractCSSproperties($cssdata));
  15826.                 }
  15827.             }
  15828.         }
  15829.         // create a special tag to contain the CSS array (used for table content)
  15830.         $csstagarray '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
  15831.         // remove head and style blocks
  15832.         $html preg_replace('/<head([^\>]*?)>(.*?)<\/head>/is'''$html);
  15833.         $html preg_replace('/<style([^\>]*?)>([^\<]*?)<\/style>/is'''$html);
  15834.         // define block tags
  15835.         $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  15836.         // define self-closing tags
  15837.         $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  15838.         // remove all unsupported tags (the line below lists all supported tags)
  15839.         $html strip_tags($html'<marker/><a><b><blockquote><body><br><br/><dd><del><div><dl><dt><em><font><form><h1><h2><h3><h4><h5><h6><hr><hr/><i><img><input><label><li><ol><option><p><pre><s><select><small><span><strike><strong><sub><sup><table><tablehead><tcpdf><td><textarea><th><thead><tr><tt><u><ul>');
  15840.         //replace some blank characters
  15841.         $html preg_replace('/<pre/''<xre'$html); // preserve pre tag
  15842.         $html preg_replace('/<(table|tr|td|th|tcpdf|blockquote|dd|div|dl|dt|form|h1|h2|h3|h4|h5|h6|br|hr|li|ol|ul|p)([^\>]*)>[\n\r\t]+/''<\\1\\2>'$html);
  15843.         $html preg_replace('@(\r\n|\r)@'"\n"$html);
  15844.         $repTable = array("\t" => ' '"\0" => ' '"\x0B" => ' '"\\" => "\\\\");
  15845.         $html strtr($html$repTable);
  15846.         $offset 0;
  15847.         while (($offset strlen($html)) AND ($pos strpos($html'</pre>'$offset)) !== false) {
  15848.             $html_a substr($html0$offset);
  15849.             $html_b substr($html$offset, ($pos $offset 6));
  15850.             while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si"$html_b)) {
  15851.                 // preserve newlines on <pre> tag
  15852.                 $html_b preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si""<xre\\1>\\2<br />\\3</pre>"$html_b);
  15853.             }
  15854.             while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  15855.                 // preserve spaces on <pre> tag
  15856.                 $html_b preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>"$html_b);
  15857.             }
  15858.             $html $html_a.$html_b.substr($html$pos 6);
  15859.             $offset strlen($html_a.$html_b);
  15860.         }
  15861.         $offset 0;
  15862.         while (($offset strlen($html)) AND ($pos strpos($html'</textarea>'$offset)) !== false) {
  15863.             $html_a substr($html0$offset);
  15864.             $html_b substr($html$offset, ($pos $offset 11));
  15865.             while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si"$html_b)) {
  15866.                 // preserve newlines on <textarea> tag
  15867.                 $html_b preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si""<textarea\\1>\\2<TBR>\\3</textarea>"$html_b);
  15868.                 $html_b preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si""<textarea\\1>\\2''\\3</textarea>"$html_b);
  15869.             }
  15870.             $html $html_a.$html_b.substr($html$pos 11);
  15871.             $offset strlen($html_a.$html_b);
  15872.         }
  15873.         $html preg_replace('/([\s]*)<option/si''<option'$html);
  15874.         $html preg_replace('/<\/option>([\s]*)/si''</option>'$html);
  15875.         $offset 0;
  15876.         while (($offset strlen($html)) AND ($pos strpos($html'</option>'$offset)) !== false) {
  15877.             $html_a substr($html0$offset);
  15878.             $html_b substr($html$offset, ($pos $offset 9));
  15879.             while (preg_match("'<option([^\>]*)>(.*?)</option>'si"$html_b)) {
  15880.                 $html_b preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si""\\2#!TaB!#\\4#!NwL!#"$html_b);
  15881.                 $html_b preg_replace("'<option([^\>]*)>(.*?)</option>'si""\\2#!NwL!#"$html_b);
  15882.             }
  15883.             $html $html_a.$html_b.substr($html$pos 9);
  15884.             $offset strlen($html_a.$html_b);
  15885.         }
  15886.         if (preg_match("'</select'si"$html)) {
  15887.             $html preg_replace("'<select([^\>]*)>'si""<select\\1 opt=\""$html);
  15888.             $html preg_replace("'#!NwL!#</select>'si""\" />"$html);
  15889.         }
  15890.         $html str_replace("\n"' '$html);
  15891.         // restore textarea newlines
  15892.         $html str_replace('<TBR>'"\n"$html);
  15893.         // remove extra spaces from code
  15894.         $html preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/''</\\1>'$html);
  15895.         $html preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>'$html);
  15896.         $html preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/''<\\1'$html);
  15897.         $html preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1'$html);
  15898.         $html preg_replace('/<\/(table|tr|td|th|blockquote|dd|dt|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|ul|p)>[\s]+</''</\\1><'$html);
  15899.         $html preg_replace('/<\/(td|th)>/''<marker style="font-size:0"/></\\1>'$html);
  15900.         $html preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/''</table>'$html);
  15901.         $html preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img'$html);
  15902.         $html preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi''<img\\1>&nbsp;\\2'$html);
  15903.         $html preg_replace('/<img([^\>]*)>/xi''<img\\1><span><marker style="font-size:0"/></span>'$html);
  15904.         $html preg_replace('/<xre/''<pre'$html); // restore pre tag
  15905.         $html preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi''<textarea\\1 value="\\2" />'$html);
  15906.         $html preg_replace('/<li([^\>]*)><\/li>/''<li\\1>&nbsp;</li>'$html);
  15907.         $html preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img'$html);
  15908.         $html preg_replace('/<([^\>\/]*)>[\s]/''<\\1>&nbsp;'$html); // preserve some spaces
  15909.         $html preg_replace('/[\s]<\/([^\>]*)>/''&nbsp;</\\1>'$html); // preserve some spaces
  15910.         $html preg_replace('/<su([bp])/''<zws/><su\\1'$html); // fix sub/sup alignment
  15911.         $html preg_replace('/<\/su([bp])>/''</su\\1><zws/>'$html); // fix sub/sup alignment
  15912.         $html preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  15913.         // trim string
  15914.         $html $this->stringTrim($html);
  15915.         // fix br tag after li
  15916.         $html preg_replace('/<li><br([^\>]*)>/''<li> <br\\1>'$html);
  15917.         // fix first image tag alignment
  15918.         $html preg_replace('/^<img/''<span style="font-size:0"><br /></span> <img'$html1);
  15919.         // pattern for generic tag
  15920.         $tagpattern '/(<[^>]+>)/';
  15921.         // explodes the string
  15922.         $a preg_split($tagpattern$html, -1PREG_SPLIT_DELIM_CAPTURE PREG_SPLIT_NO_EMPTY);
  15923.         // count elements
  15924.         $maxel count($a);
  15925.         $elkey 0;
  15926.         $key 0;
  15927.         // create an array of elements
  15928.         $dom = array();
  15929.         $dom[$key] = array();
  15930.         // set inheritable properties fot the first void element
  15931.         // possible inheritable properties are: azimuth, border-collapse, border-spacing, caption-side, color, cursor, direction, empty-cells, font, font-family, font-stretch, font-size, font-size-adjust, font-style, font-variant, font-weight, letter-spacing, line-height, list-style, list-style-image, list-style-position, list-style-type, orphans, page, page-break-inside, quotes, speak, speak-header, text-align, text-indent, text-transform, volume, white-space, widows, word-spacing
  15932.         $dom[$key]['tag'] = false;
  15933.         $dom[$key]['block'] = false;
  15934.         $dom[$key]['value'] = '';
  15935.         $dom[$key]['parent'] = 0;
  15936.         $dom[$key]['hide'] = false;
  15937.         $dom[$key]['fontname'] = $this->FontFamily;
  15938.         $dom[$key]['fontstyle'] = $this->FontStyle;
  15939.         $dom[$key]['fontsize'] = $this->FontSizePt;
  15940.         $dom[$key]['font-stretch'] = $this->font_stretching;
  15941.         $dom[$key]['letter-spacing'] = $this->font_spacing;
  15942.         $dom[$key]['stroke'] = $this->textstrokewidth;
  15943.         $dom[$key]['fill'] = (($this->textrendermode 2) == 0);
  15944.         $dom[$key]['clip'] = ($this->textrendermode 3);
  15945.         $dom[$key]['line-height'] = $this->cell_height_ratio;
  15946.         $dom[$key]['bgcolor'] = false;
  15947.         $dom[$key]['fgcolor'] = $this->fgcolor// color
  15948.         $dom[$key]['strokecolor'] = $this->strokecolor;
  15949.         $dom[$key]['align'] = '';
  15950.         $dom[$key]['listtype'] = '';
  15951.         $dom[$key]['text-indent'] = 0;
  15952.         $dom[$key]['text-transform'] = '';
  15953.         $dom[$key]['border'] = array();
  15954.         $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  15955.         $thead false// true when we are inside the THEAD tag
  15956.         ++$key;
  15957.         $level = array();
  15958.         array_push($level0); // root
  15959.         while ($elkey $maxel) {
  15960.             $dom[$key] = array();
  15961.             $element $a[$elkey];
  15962.             $dom[$key]['elkey'] = $elkey;
  15963.             if (preg_match($tagpattern$element)) {
  15964.                 // html tag
  15965.                 $element substr($element1, -1);
  15966.                 // get tag name
  15967.                 preg_match('/[\/]?([a-zA-Z0-9]*)/'$element$tag);
  15968.                 $tagname strtolower($tag[1]);
  15969.                 // check if we are inside a table header
  15970.                 if ($tagname == 'thead') {
  15971.                     if ($element[0] == '/') {
  15972.                         $thead false;
  15973.                     } else {
  15974.                         $thead true;
  15975.                     }
  15976.                     ++$elkey;
  15977.                     continue;
  15978.                 }
  15979.                 $dom[$key]['tag'] = true;
  15980.                 $dom[$key]['value'] = $tagname;
  15981.                 if (in_array($dom[$key]['value'], $blocktags)) {
  15982.                     $dom[$key]['block'] = true;
  15983.                 } else {
  15984.                     $dom[$key]['block'] = false;
  15985.                 }
  15986.                 if ($element[0] == '/') {
  15987.                     // *** closing html tag
  15988.                     $dom[$key]['opening'] = false;
  15989.                     $dom[$key]['parent'] = end($level);
  15990.                     array_pop($level);
  15991.                     $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  15992.                     $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  15993.                     $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  15994.                     $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  15995.                     $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  15996.                     $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  15997.                     $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  15998.                     $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  15999.                     $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  16000.                     $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  16001.                     $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  16002.                     $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  16003.                     $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  16004.                     $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  16005.                     $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
  16006.                     $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  16007.                     if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  16008.                         $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  16009.                     }
  16010.                     // set the number of columns in table tag
  16011.                     if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  16012.                         $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  16013.                     }
  16014.                     if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  16015.                         $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  16016.                         for ($i = ($dom[$key]['parent'] + 1); $i $key; ++$i) {
  16017.                             $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
  16018.                         }
  16019.                         $key $i;
  16020.                         // mark nested tables
  16021.                         $dom[($dom[$key]['parent'])]['content'] = str_replace('<table''<table nested="true"'$dom[($dom[$key]['parent'])]['content']);
  16022.                         // remove thead sections from nested tables
  16023.                         $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>'''$dom[($dom[$key]['parent'])]['content']);
  16024.                         $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>'''$dom[($dom[$key]['parent'])]['content']);
  16025.                     }
  16026.                     // store header rows on a new table
  16027.                     if (
  16028.                         ($dom[$key]['value'] === 'tr')
  16029.                         && !empty($dom[($dom[$key]['parent'])]['thead'])
  16030.                         && ($dom[($dom[$key]['parent'])]['thead'] === true)
  16031.                     ) {
  16032.                         if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  16033.                             $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  16034.                         }
  16035.                         for ($i $dom[$key]['parent']; $i <= $key; ++$i) {
  16036.                             $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  16037.                         }
  16038.                         if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  16039.                             $dom[($dom[$key]['parent'])]['attribute'] = array();
  16040.                         }
  16041.                         // header elements must be always contained in a single page
  16042.                         $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  16043.                     }
  16044.                     if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  16045.                         // remove the nobr attributes from the table header
  16046.                         $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"'''$dom[($dom[$key]['parent'])]['thead']);
  16047.                         $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  16048.                     }
  16049.                 } else {
  16050.                     // *** opening or self-closing html tag
  16051.                     $dom[$key]['opening'] = true;
  16052.                     $dom[$key]['parent'] = end($level);
  16053.                     if ((substr($element, -11) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  16054.                         // self-closing tag
  16055.                         $dom[$key]['self'] = true;
  16056.                     } else {
  16057.                         // opening tag
  16058.                         array_push($level$key);
  16059.                         $dom[$key]['self'] = false;
  16060.                     }
  16061.                     // copy some values from parent
  16062.                     $parentkey 0;
  16063.                     if ($key 0) {
  16064.                         $parentkey $dom[$key]['parent'];
  16065.                         $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  16066.                         $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  16067.                         $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  16068.                         $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  16069.                         $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  16070.                         $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  16071.                         $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  16072.                         $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  16073.                         $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  16074.                         $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16075.                         $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  16076.                         $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  16077.                         $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  16078.                         $dom[$key]['align'] = $dom[$parentkey]['align'];
  16079.                         $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16080.                         $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16081.                         $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
  16082.                         $dom[$key]['border'] = array();
  16083.                         $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  16084.                     }
  16085.                     // get attributes
  16086.                     preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/'$element$attr_arrayPREG_PATTERN_ORDER);
  16087.                     $dom[$key]['attribute'] = array(); // reset attribute array
  16088.                     foreach($attr_array[1] as $id => $name) {
  16089.                         $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  16090.                     }
  16091.                     if (!empty($css)) {
  16092.                         // merge CSS style to current style
  16093.                         list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom$key$css);
  16094.                         $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  16095.                     }
  16096.                     // split style attributes
  16097.                     if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  16098.                         // get style attributes
  16099.                         preg_match_all('/([^;:\s]*):([^;]*)/'$dom[$key]['attribute']['style'], $style_arrayPREG_PATTERN_ORDER);
  16100.                         $dom[$key]['style'] = array(); // reset style attribute array
  16101.                         foreach($style_array[1] as $id => $name) {
  16102.                             // in case of duplicate attribute the last replace the previous
  16103.                             $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  16104.                         }
  16105.                         // --- get some style attributes ---
  16106.                         // text direction
  16107.                         if (isset($dom[$key]['style']['direction'])) {
  16108.                             $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  16109.                         }
  16110.                         // display
  16111.                         if (isset($dom[$key]['style']['display'])) {
  16112.                             $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  16113.                         }
  16114.                         // font family
  16115.                         if (isset($dom[$key]['style']['font-family'])) {
  16116.                             $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  16117.                         }
  16118.                         // list-style-type
  16119.                         if (isset($dom[$key]['style']['list-style-type'])) {
  16120.                             $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  16121.                             if ($dom[$key]['listtype'] == 'inherit') {
  16122.                                 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  16123.                             }
  16124.                         }
  16125.                         // text-indent
  16126.                         if (isset($dom[$key]['style']['text-indent'])) {
  16127.                             $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  16128.                             if ($dom[$key]['text-indent'] == 'inherit') {
  16129.                                 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  16130.                             }
  16131.                         }
  16132.                         // text-transform
  16133.                         if (isset($dom[$key]['style']['text-transform'])) {
  16134.                             $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
  16135.                         }
  16136.                         // font size
  16137.                         if (isset($dom[$key]['style']['font-size'])) {
  16138.                             $fsize trim($dom[$key]['style']['font-size']);
  16139.                             $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize$dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  16140.                         }
  16141.                         // font-stretch
  16142.                         if (isset($dom[$key]['style']['font-stretch'])) {
  16143.                             $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  16144.                         }
  16145.                         // letter-spacing
  16146.                         if (isset($dom[$key]['style']['letter-spacing'])) {
  16147.                             $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  16148.                         }
  16149.                         // line-height (internally is the cell height ratio)
  16150.                         if (isset($dom[$key]['style']['line-height'])) {
  16151.                             $lineheight trim($dom[$key]['style']['line-height']);
  16152.                             switch ($lineheight) {
  16153.                                 // A normal line height. This is default
  16154.                                 case 'normal': {
  16155.                                     $dom[$key]['line-height'] = $dom[0]['line-height'];
  16156.                                     break;
  16157.                                 }
  16158.                                 case 'inherit': {
  16159.                                     $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  16160.                                 }
  16161.                                 default: {
  16162.                                     if (is_numeric($lineheight)) {
  16163.                                         // convert to percentage of font height
  16164.                                         $lineheight = ($lineheight 100).'%';
  16165.                                     }
  16166.                                     $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight1'%'true);
  16167.                                     if (substr($lineheight, -1) !== '%') {
  16168.                                         if ($dom[$key]['fontsize'] <= 0) {
  16169.                                             $dom[$key]['line-height'] = 1;
  16170.                                         } else {
  16171.                                             $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
  16172.                                         }
  16173.                                     }
  16174.                                 }
  16175.                             }
  16176.                         }
  16177.                         // font style
  16178.                         if (isset($dom[$key]['style']['font-weight'])) {
  16179.                             if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
  16180.                                 if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  16181.                                     $dom[$key]['fontstyle'] = str_replace('B'''$dom[$key]['fontstyle']);
  16182.                                 }
  16183.                             } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
  16184.                                 $dom[$key]['fontstyle'] .= 'B';
  16185.                             }
  16186.                         }
  16187.                         if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
  16188.                             $dom[$key]['fontstyle'] .= 'I';
  16189.                         }
  16190.                         // font color
  16191.                         if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  16192.                             $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  16193.                         } elseif ($dom[$key]['value'] == 'a') {
  16194.                             $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16195.                         }
  16196.                         // background color
  16197.                         if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  16198.                             $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  16199.                         }
  16200.                         // text-decoration
  16201.                         if (isset($dom[$key]['style']['text-decoration'])) {
  16202.                             $decors explode(' 'strtolower($dom[$key]['style']['text-decoration']));
  16203.                             foreach ($decors as $dec) {
  16204.                                 $dec trim($dec);
  16205.                                 if (!TCPDF_STATIC::empty_string($dec)) {
  16206.                                     if ($dec[0] == 'u') {
  16207.                                         // underline
  16208.                                         $dom[$key]['fontstyle'] .= 'U';
  16209.                                     } elseif ($dec[0] == 'l') {
  16210.                                         // line-through
  16211.                                         $dom[$key]['fontstyle'] .= 'D';
  16212.                                     } elseif ($dec[0] == 'o') {
  16213.                                         // overline
  16214.                                         $dom[$key]['fontstyle'] .= 'O';
  16215.                                     }
  16216.                                 }
  16217.                             }
  16218.                         } elseif ($dom[$key]['value'] == 'a') {
  16219.                             $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16220.                         }
  16221.                         // check for width attribute
  16222.                         if (isset($dom[$key]['style']['width'])) {
  16223.                             $dom[$key]['width'] = $dom[$key]['style']['width'];
  16224.                         }
  16225.                         // check for height attribute
  16226.                         if (isset($dom[$key]['style']['height'])) {
  16227.                             $dom[$key]['height'] = $dom[$key]['style']['height'];
  16228.                         }
  16229.                         // check for text alignment
  16230.                         if (isset($dom[$key]['style']['text-align'])) {
  16231.                             $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
  16232.                         }
  16233.                         // check for CSS border properties
  16234.                         if (isset($dom[$key]['style']['border'])) {
  16235.                             $borderstyle $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16236.                             if (!empty($borderstyle)) {
  16237.                                 $dom[$key]['border']['LTRB'] = $borderstyle;
  16238.                             }
  16239.                         }
  16240.                         if (isset($dom[$key]['style']['border-color'])) {
  16241.                             $brd_colors preg_split('/[\s]+/'trim($dom[$key]['style']['border-color']));
  16242.                             if (isset($brd_colors[3])) {
  16243.                                 $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16244.                             }
  16245.                             if (isset($brd_colors[1])) {
  16246.                                 $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16247.                             }
  16248.                             if (isset($brd_colors[0])) {
  16249.                                 $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16250.                             }
  16251.                             if (isset($brd_colors[2])) {
  16252.                                 $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16253.                             }
  16254.                         }
  16255.                         if (isset($dom[$key]['style']['border-width'])) {
  16256.                             $brd_widths preg_split('/[\s]+/'trim($dom[$key]['style']['border-width']));
  16257.                             if (isset($brd_widths[3])) {
  16258.                                 $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16259.                             }
  16260.                             if (isset($brd_widths[1])) {
  16261.                                 $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16262.                             }
  16263.                             if (isset($brd_widths[0])) {
  16264.                                 $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16265.                             }
  16266.                             if (isset($brd_widths[2])) {
  16267.                                 $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16268.                             }
  16269.                         }
  16270.                         if (isset($dom[$key]['style']['border-style'])) {
  16271.                             $brd_styles preg_split('/[\s]+/'trim($dom[$key]['style']['border-style']));
  16272.                             if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16273.                                 $dom[$key]['border']['L']['cap'] = 'square';
  16274.                                 $dom[$key]['border']['L']['join'] = 'miter';
  16275.                                 $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16276.                                 if ($dom[$key]['border']['L']['dash'] < 0) {
  16277.                                     $dom[$key]['border']['L'] = array();
  16278.                                 }
  16279.                             }
  16280.                             if (isset($brd_styles[1])) {
  16281.                                 $dom[$key]['border']['R']['cap'] = 'square';
  16282.                                 $dom[$key]['border']['R']['join'] = 'miter';
  16283.                                 $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16284.                                 if ($dom[$key]['border']['R']['dash'] < 0) {
  16285.                                     $dom[$key]['border']['R'] = array();
  16286.                                 }
  16287.                             }
  16288.                             if (isset($brd_styles[0])) {
  16289.                                 $dom[$key]['border']['T']['cap'] = 'square';
  16290.                                 $dom[$key]['border']['T']['join'] = 'miter';
  16291.                                 $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16292.                                 if ($dom[$key]['border']['T']['dash'] < 0) {
  16293.                                     $dom[$key]['border']['T'] = array();
  16294.                                 }
  16295.                             }
  16296.                             if (isset($brd_styles[2])) {
  16297.                                 $dom[$key]['border']['B']['cap'] = 'square';
  16298.                                 $dom[$key]['border']['B']['join'] = 'miter';
  16299.                                 $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16300.                                 if ($dom[$key]['border']['B']['dash'] < 0) {
  16301.                                     $dom[$key]['border']['B'] = array();
  16302.                                 }
  16303.                             }
  16304.                         }
  16305.                         $cellside = array('L' => 'left''R' => 'right''T' => 'top''B' => 'bottom');
  16306.                         foreach ($cellside as $bsk => $bsv) {
  16307.                             if (isset($dom[$key]['style']['border-'.$bsv])) {
  16308.                                 $borderstyle $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16309.                                 if (!empty($borderstyle)) {
  16310.                                     $dom[$key]['border'][$bsk] = $borderstyle;
  16311.                                 }
  16312.                             }
  16313.                             if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16314.                                 $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16315.                             }
  16316.                             if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16317.                                 $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16318.                             }
  16319.                             if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16320.                                 $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16321.                                 if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16322.                                     $dom[$key]['border'][$bsk] = array();
  16323.                                 }
  16324.                             }
  16325.                         }
  16326.                         // check for CSS padding properties
  16327.                         if (isset($dom[$key]['style']['padding'])) {
  16328.                             $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16329.                         } else {
  16330.                             $dom[$key]['padding'] = $this->cell_padding;
  16331.                         }
  16332.                         foreach ($cellside as $psk => $psv) {
  16333.                             if (isset($dom[$key]['style']['padding-'.$psv])) {
  16334.                                 $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0'px'false);
  16335.                             }
  16336.                         }
  16337.                         // check for CSS margin properties
  16338.                         if (isset($dom[$key]['style']['margin'])) {
  16339.                             $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16340.                         } else {
  16341.                             $dom[$key]['margin'] = $this->cell_margin;
  16342.                         }
  16343.                         foreach ($cellside as $psk => $psv) {
  16344.                             if (isset($dom[$key]['style']['margin-'.$psv])) {
  16345.                                 $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto''0'$dom[$key]['style']['margin-'.$psv]), 0'px'false);
  16346.                             }
  16347.                         }
  16348.                         // check for CSS border-spacing properties
  16349.                         if (isset($dom[$key]['style']['border-spacing'])) {
  16350.                             $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16351.                         }
  16352.                         // page-break-inside
  16353.                         if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16354.                             $dom[$key]['attribute']['nobr'] = 'true';
  16355.                         }
  16356.                         // page-break-before
  16357.                         if (isset($dom[$key]['style']['page-break-before'])) {
  16358.                             if ($dom[$key]['style']['page-break-before'] == 'always') {
  16359.                                 $dom[$key]['attribute']['pagebreak'] = 'true';
  16360.                             } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16361.                                 $dom[$key]['attribute']['pagebreak'] = 'left';
  16362.                             } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16363.                                 $dom[$key]['attribute']['pagebreak'] = 'right';
  16364.                             }
  16365.                         }
  16366.                         // page-break-after
  16367.                         if (isset($dom[$key]['style']['page-break-after'])) {
  16368.                             if ($dom[$key]['style']['page-break-after'] == 'always') {
  16369.                                 $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16370.                             } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16371.                                 $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16372.                             } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16373.                                 $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16374.                             }
  16375.                         }
  16376.                     }
  16377.                     if (isset($dom[$key]['attribute']['display'])) {
  16378.                         $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16379.                     }
  16380.                     if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16381.                         $borderstyle $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16382.                         if (!empty($borderstyle)) {
  16383.                             $dom[$key]['border']['LTRB'] = $borderstyle;
  16384.                         }
  16385.                     }
  16386.                     // check for font tag
  16387.                     if ($dom[$key]['value'] == 'font') {
  16388.                         // font family
  16389.                         if (isset($dom[$key]['attribute']['face'])) {
  16390.                             $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16391.                         }
  16392.                         // font size
  16393.                         if (isset($dom[$key]['attribute']['size'])) {
  16394.                             if ($key 0) {
  16395.                                 if ($dom[$key]['attribute']['size'][0] == '+') {
  16396.                                     $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16397.                                 } elseif ($dom[$key]['attribute']['size'][0] == '-') {
  16398.                                     $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16399.                                 } else {
  16400.                                     $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16401.                                 }
  16402.                             } else {
  16403.                                 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16404.                             }
  16405.                         }
  16406.                     }
  16407.                     // force natural alignment for lists
  16408.                     if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16409.                         AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16410.                         if ($this->rtl) {
  16411.                             $dom[$key]['align'] = 'R';
  16412.                         } else {
  16413.                             $dom[$key]['align'] = 'L';
  16414.                         }
  16415.                     }
  16416.                     if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16417.                         if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16418.                             $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16419.                         }
  16420.                     }
  16421.                     if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16422.                         $dom[$key]['fontstyle'] .= 'B';
  16423.                     }
  16424.                     if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16425.                         $dom[$key]['fontstyle'] .= 'I';
  16426.                     }
  16427.                     if ($dom[$key]['value'] == 'u') {
  16428.                         $dom[$key]['fontstyle'] .= 'U';
  16429.                     }
  16430.                     if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16431.                         $dom[$key]['fontstyle'] .= 'D';
  16432.                     }
  16433.                     if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16434.                         $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16435.                     }
  16436.                     if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16437.                         $dom[$key]['fontname'] = $this->default_monospaced_font;
  16438.                     }
  16439.                     if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value'][1]) > 0) AND (intval($dom[$key]['value'][1]) < 7)) {
  16440.                         // headings h1, h2, h3, h4, h5, h6
  16441.                         if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16442.                             $headsize = (intval($dom[$key]['value'][1])) * 2;
  16443.                             $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16444.                         }
  16445.                         if (!isset($dom[$key]['style']['font-weight'])) {
  16446.                             $dom[$key]['fontstyle'] .= 'B';
  16447.                         }
  16448.                     }
  16449.                     if (($dom[$key]['value'] == 'table')) {
  16450.                         $dom[$key]['rows'] = 0// number of rows
  16451.                         $dom[$key]['trids'] = array(); // IDs of TR elements
  16452.                         $dom[$key]['thead'] = ''// table header rows
  16453.                     }
  16454.                     if (($dom[$key]['value'] == 'tr')) {
  16455.                         $dom[$key]['cols'] = 0;
  16456.                         if ($thead) {
  16457.                             $dom[$key]['thead'] = true;
  16458.                             // rows on thead block are printed as a separate table
  16459.                         } else {
  16460.                             $dom[$key]['thead'] = false;
  16461.                             $parent $dom[$key]['parent'];
  16462.                             if (!isset($dom[$parent]['rows'])) {
  16463.                                 $dom[$parent]['rows'] = 0;
  16464.                             }
  16465.                             // store the number of rows on table element
  16466.                             ++$dom[$parent]['rows'];
  16467.                             if (!isset($dom[$parent]['trids'])) {
  16468.                                 $dom[$parent]['trids'] = array();
  16469.                             }
  16470.                             // store the TR elements IDs on table element
  16471.                             array_push($dom[$parent]['trids'], $key);
  16472.                         }
  16473.                     }
  16474.                     if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16475.                         if (isset($dom[$key]['attribute']['colspan'])) {
  16476.                             $colspan intval($dom[$key]['attribute']['colspan']);
  16477.                         } else {
  16478.                             $colspan 1;
  16479.                         }
  16480.                         $dom[$key]['attribute']['colspan'] = $colspan;
  16481.                         $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16482.                     }
  16483.                     // text direction
  16484.                     if (isset($dom[$key]['attribute']['dir'])) {
  16485.                         $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16486.                     }
  16487.                     // set foreground color attribute
  16488.                     if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16489.                         $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16490.                     } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16491.                         $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16492.                     }
  16493.                     // set background color attribute
  16494.                     if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16495.                         $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16496.                     }
  16497.                     // set stroke color attribute
  16498.                     if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16499.                         $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16500.                     }
  16501.                     // check for width attribute
  16502.                     if (isset($dom[$key]['attribute']['width'])) {
  16503.                         $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16504.                     }
  16505.                     // check for height attribute
  16506.                     if (isset($dom[$key]['attribute']['height'])) {
  16507.                         $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16508.                     }
  16509.                     // check for text alignment
  16510.                     if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16511.                         $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
  16512.                     }
  16513.                     // check for text rendering mode (the following attributes do not exist in HTML)
  16514.                     if (isset($dom[$key]['attribute']['stroke'])) {
  16515.                         // font stroke width
  16516.                         $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt'true);
  16517.                     }
  16518.                     if (isset($dom[$key]['attribute']['fill'])) {
  16519.                         // font fill
  16520.                         if ($dom[$key]['attribute']['fill'] == 'true') {
  16521.                             $dom[$key]['fill'] = true;
  16522.                         } else {
  16523.                             $dom[$key]['fill'] = false;
  16524.                         }
  16525.                     }
  16526.                     if (isset($dom[$key]['attribute']['clip'])) {
  16527.                         // clipping mode
  16528.                         if ($dom[$key]['attribute']['clip'] == 'true') {
  16529.                             $dom[$key]['clip'] = true;
  16530.                         } else {
  16531.                             $dom[$key]['clip'] = false;
  16532.                         }
  16533.                     }
  16534.                 } // end opening tag
  16535.             } else {
  16536.                 // text
  16537.                 $dom[$key]['tag'] = false;
  16538.                 $dom[$key]['block'] = false;
  16539.                 $dom[$key]['parent'] = end($level);
  16540.                 $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16541.                 if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
  16542.                     // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
  16543.                     if (function_exists('mb_convert_case')) {
  16544.                         $ttm = array('capitalize' => MB_CASE_TITLE'uppercase' => MB_CASE_UPPER'lowercase' => MB_CASE_LOWER);
  16545.                         if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
  16546.                             $element mb_convert_case($element$ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding);
  16547.                         }
  16548.                     } elseif (!$this->isunicode) {
  16549.                         switch ($dom[$dom[$key]['parent']]['text-transform']) {
  16550.                             case 'capitalize': {
  16551.                                 $element ucwords(strtolower($element));
  16552.                                 break;
  16553.                             }
  16554.                             case 'uppercase': {
  16555.                                 $element strtoupper($element);
  16556.                                 break;
  16557.                             }
  16558.                             case 'lowercase': {
  16559.                                 $element strtolower($element);
  16560.                                 break;
  16561.                             }
  16562.                         }
  16563.                     }
  16564.                     $element preg_replace("/&NBSP;/i""&nbsp;"$element);
  16565.                 }
  16566.                 $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16567.             }
  16568.             ++$elkey;
  16569.             ++$key;
  16570.         }
  16571.         return $dom;
  16572.     }
  16573.     /**
  16574.      * Returns the string used to find spaces
  16575.      * @return string
  16576.      * @protected
  16577.      * @author Nicola Asuni
  16578.      * @since 4.8.024 (2010-01-15)
  16579.      */
  16580.     protected function getSpaceString() {
  16581.         $spacestr chr(32);
  16582.         if ($this->isUnicodeFont()) {
  16583.             $spacestr chr(0).chr(32);
  16584.         }
  16585.         return $spacestr;
  16586.     }
  16587.     /**
  16588.      * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance.
  16589.      * @param string $data serialized data
  16590.      * @return string
  16591.      * @public static
  16592.      */
  16593.     protected function getHashForTCPDFtagParams($data) {
  16594.         return md5(strlen($data).$this->file_id.$data);
  16595.     }
  16596.     /**
  16597.      * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  16598.      * @param array $data parameters array
  16599.      * @return string containing serialized data
  16600.      * @public static
  16601.      */
  16602.     public function serializeTCPDFtagParameters($data) {
  16603.         $encoded urlencode(json_encode($data));
  16604.         return $this->getHashForTCPDFtagParams($encoded).$encoded;
  16605.     }
  16606.     /**
  16607.      * Unserialize parameters to be used with TCPDF tag in HTML code.
  16608.      * @param string $data serialized data
  16609.      * @return array containing unserialized data
  16610.      * @protected static
  16611.      */
  16612.     protected function unserializeTCPDFtagParameters($data) {
  16613.         $hash substr($data032);
  16614.         $encoded substr($data32);
  16615.         if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
  16616.             $this->Error('Invalid parameters');
  16617.         }
  16618.         return json_decode(urldecode($encoded), true);
  16619.     }
  16620.     /**
  16621.      * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16622.      * 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 />
  16623.      * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16624.      * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16625.      * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul
  16626.      * NOTE: all the HTML attributes must be enclosed in double-quote.
  16627.      * @param float $w Cell width. If 0, the cell extends up to the right margin.
  16628.      * @param float $h Cell minimum height. The cell extends automatically if needed.
  16629.      * @param float|null $x upper-left corner X coordinate
  16630.      * @param float|null $y upper-left corner Y coordinate
  16631.      * @param string $html html text to print. Default value: empty string.
  16632.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  16633.      * @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>
  16634. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16635.      * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  16636.      * @param boolean $reseth if true reset the last cell height (default true).
  16637.      * @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>
  16638.      * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  16639.      * @see Multicell(), writeHTML()
  16640.      * @public
  16641.      */
  16642.     public function writeHTMLCell($w$h$x$y$html=''$border=0$ln=0$fill=false$reseth=true$align=''$autopadding=true) {
  16643.         return $this->MultiCell($w$h$html$border$align$fill$ln$x$y$reseth0true$autopadding0'T'false);
  16644.     }
  16645.     /**
  16646.      * Allows to preserve some HTML formatting (limited support).<br />
  16647.      * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16648.      * Supported tags are: a, b, blockquote, br, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, ol, p, pre, small, span, strong, sub, sup, table, tcpdf, td, th, thead, tr, tt, u, ul
  16649.      * NOTE: all the HTML attributes must be enclosed in double-quote.
  16650.      * @param string $html text to display
  16651.      * @param boolean $ln if true add a new line after text (default = true)
  16652.      * @param boolean $fill Indicates if the background must be painted (true) or transparent (false).
  16653.      * @param boolean $reseth if true reset the last cell height (default false).
  16654.      * @param boolean $cell if true add the current left (or right for RTL) padding to each Write (default false).
  16655.      * @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>
  16656.      * @public
  16657.      */
  16658.     public function writeHTML($html$ln=true$fill=false$reseth=false$cell=false$align='') {
  16659.         $gvars $this->getGraphicVars();
  16660.         // store current values
  16661.         $prev_cell_margin $this->cell_margin;
  16662.         $prev_cell_padding $this->cell_padding;
  16663.         $prevPage $this->page;
  16664.         $prevlMargin $this->lMargin;
  16665.         $prevrMargin $this->rMargin;
  16666.         $curfontname $this->FontFamily;
  16667.         $curfontstyle $this->FontStyle;
  16668.         $curfontsize $this->FontSizePt;
  16669.         $curfontascent $this->getFontAscent($curfontname$curfontstyle$curfontsize);
  16670.         $curfontdescent $this->getFontDescent($curfontname$curfontstyle$curfontsize);
  16671.         $curfontstretcing $this->font_stretching;
  16672.         $curfonttracking $this->font_spacing;
  16673.         $this->newline true;
  16674.         $newline true;
  16675.         $startlinepage $this->page;
  16676.         $minstartliney $this->y;
  16677.         $maxbottomliney 0;
  16678.         $startlinex $this->x;
  16679.         $startliney $this->y;
  16680.         $yshift 0;
  16681.         $loop 0;
  16682.         $curpos 0;
  16683.         $this_method_vars = array();
  16684.         $undo false;
  16685.         $fontaligned false;
  16686.         $reverse_dir false// true when the text direction is reversed
  16687.         $this->premode false;
  16688.         if ($this->inxobj) {
  16689.             // we are inside an XObject template
  16690.             $pask count($this->xobjects[$this->xobjid]['annotations']);
  16691.         } elseif (isset($this->PageAnnots[$this->page])) {
  16692.             $pask count($this->PageAnnots[$this->page]);
  16693.         } else {
  16694.             $pask 0;
  16695.         }
  16696.         if ($this->inxobj) {
  16697.             // we are inside an XObject template
  16698.             $startlinepos strlen($this->xobjects[$this->xobjid]['outdata']);
  16699.         } elseif (!$this->InFooter) {
  16700.             if (isset($this->footerlen[$this->page])) {
  16701.                 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16702.             } else {
  16703.                 $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16704.             }
  16705.             $startlinepos $this->footerpos[$this->page];
  16706.         } else {
  16707.             // we are inside the footer
  16708.             $startlinepos $this->pagelen[$this->page];
  16709.         }
  16710.         $lalign $align;
  16711.         $plalign $align;
  16712.         if ($this->rtl) {
  16713.             $w $this->$this->lMargin;
  16714.         } else {
  16715.             $w $this->$this->rMargin $this->x;
  16716.         }
  16717.         $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16718.         if ($cell) {
  16719.             if ($this->rtl) {
  16720.                 $this->-= $this->cell_padding['R'];
  16721.                 $this->lMargin += $this->cell_padding['L'];
  16722.             } else {
  16723.                 $this->+= $this->cell_padding['L'];
  16724.                 $this->rMargin += $this->cell_padding['R'];
  16725.             }
  16726.         }
  16727.         if ($this->customlistindent >= 0) {
  16728.             $this->listindent $this->customlistindent;
  16729.         } else {
  16730.             $this->listindent $this->GetStringWidth('000000');
  16731.         }
  16732.         $this->listindentlevel 0;
  16733.         // save previous states
  16734.         $prev_cell_height_ratio $this->cell_height_ratio;
  16735.         $prev_listnum $this->listnum;
  16736.         $prev_listordered $this->listordered;
  16737.         $prev_listcount $this->listcount;
  16738.         $prev_lispacer $this->lispacer;
  16739.         $this->listnum 0;
  16740.         $this->listordered = array();
  16741.         $this->listcount = array();
  16742.         $this->lispacer '';
  16743.         if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  16744.             // reset row height
  16745.             $this->resetLastH();
  16746.         }
  16747.         $dom $this->getHtmlDomArray($html);
  16748.         $maxel count($dom);
  16749.         $key 0;
  16750.         while ($key $maxel) {
  16751.             if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  16752.                 // store the node key
  16753.                 $hidden_node_key $key;
  16754.                 if ($dom[$key]['self']) {
  16755.                     // skip just this self-closing tag
  16756.                     ++$key;
  16757.                 } else {
  16758.                     // skip this and all children tags
  16759.                     while (($key $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  16760.                         // skip hidden objects
  16761.                         ++$key;
  16762.                     }
  16763.                     ++$key;
  16764.                 }
  16765.             }
  16766.             if ($key == $maxel) break;
  16767.             if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  16768.                 // check for pagebreak
  16769.                 if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  16770.                     // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16771.                     $this->checkPageBreak($this->PageBreakTrigger 1);
  16772.                     $this->htmlvspace = ($this->PageBreakTrigger 1);
  16773.                 }
  16774.                 if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page 2) == 0)) OR (($this->rtl) AND (($this->page 2) != 0))))
  16775.                     OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page 2) != 0)) OR (($this->rtl) AND (($this->page 2) == 0))))) {
  16776.                     // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16777.                     $this->checkPageBreak($this->PageBreakTrigger 1);
  16778.                     $this->htmlvspace = ($this->PageBreakTrigger 1);
  16779.                 }
  16780.             }
  16781.             if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  16782.                 if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  16783.                     $dom[$key]['attribute']['nobr'] = false;
  16784.                 } else {
  16785.                     // store current object
  16786.                     $this->startTransaction();
  16787.                     // save this method vars
  16788.                     $this_method_vars['html'] = $html;
  16789.                     $this_method_vars['ln'] = $ln;
  16790.                     $this_method_vars['fill'] = $fill;
  16791.                     $this_method_vars['reseth'] = $reseth;
  16792.                     $this_method_vars['cell'] = $cell;
  16793.                     $this_method_vars['align'] = $align;
  16794.                     $this_method_vars['gvars'] = $gvars;
  16795.                     $this_method_vars['prevPage'] = $prevPage;
  16796.                     $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  16797.                     $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  16798.                     $this_method_vars['prevlMargin'] = $prevlMargin;
  16799.                     $this_method_vars['prevrMargin'] = $prevrMargin;
  16800.                     $this_method_vars['curfontname'] = $curfontname;
  16801.                     $this_method_vars['curfontstyle'] = $curfontstyle;
  16802.                     $this_method_vars['curfontsize'] = $curfontsize;
  16803.                     $this_method_vars['curfontascent'] = $curfontascent;
  16804.                     $this_method_vars['curfontdescent'] = $curfontdescent;
  16805.                     $this_method_vars['curfontstretcing'] = $curfontstretcing;
  16806.                     $this_method_vars['curfonttracking'] = $curfonttracking;
  16807.                     $this_method_vars['minstartliney'] = $minstartliney;
  16808.                     $this_method_vars['maxbottomliney'] = $maxbottomliney;
  16809.                     $this_method_vars['yshift'] = $yshift;
  16810.                     $this_method_vars['startlinepage'] = $startlinepage;
  16811.                     $this_method_vars['startlinepos'] = $startlinepos;
  16812.                     $this_method_vars['startlinex'] = $startlinex;
  16813.                     $this_method_vars['startliney'] = $startliney;
  16814.                     $this_method_vars['newline'] = $newline;
  16815.                     $this_method_vars['loop'] = $loop;
  16816.                     $this_method_vars['curpos'] = $curpos;
  16817.                     $this_method_vars['pask'] = $pask;
  16818.                     $this_method_vars['lalign'] = $lalign;
  16819.                     $this_method_vars['plalign'] = $plalign;
  16820.                     $this_method_vars['w'] = $w;
  16821.                     $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  16822.                     $this_method_vars['prev_listnum'] = $prev_listnum;
  16823.                     $this_method_vars['prev_listordered'] = $prev_listordered;
  16824.                     $this_method_vars['prev_listcount'] = $prev_listcount;
  16825.                     $this_method_vars['prev_lispacer'] = $prev_lispacer;
  16826.                     $this_method_vars['fontaligned'] = $fontaligned;
  16827.                     $this_method_vars['key'] = $key;
  16828.                     $this_method_vars['dom'] = $dom;
  16829.                 }
  16830.             }
  16831.             // print THEAD block
  16832.             if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  16833.                 if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  16834.                     $this->inthead true;
  16835.                     // print table header (thead)
  16836.                     $this->writeHTML($this->theadfalsefalsefalsefalse'');
  16837.                     // check if we are on a new page or on a new column
  16838.                     if (($this->$this->start_transaction_y) OR ($this->checkPageBreak($this->lasth''false))) {
  16839.                         // we are on a new page or on a new column and the total object height is less than the available vertical space.
  16840.                         // restore previous object
  16841.                         $this->rollbackTransaction(true);
  16842.                         // restore previous values
  16843.                         foreach ($this_method_vars as $vkey => $vval) {
  16844.                             $$vkey $vval;
  16845.                         }
  16846.                         // disable table header
  16847.                         $tmp_thead $this->thead;
  16848.                         $this->thead '';
  16849.                         // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16850.                         $pre_y $this->y;
  16851.                         if ((!$this->checkPageBreak($this->PageBreakTrigger 1)) AND ($this->$pre_y)) {
  16852.                             // fix for multicolumn mode
  16853.                             $startliney $this->y;
  16854.                         }
  16855.                         $this->start_transaction_page $this->page;
  16856.                         $this->start_transaction_y $this->y;
  16857.                         // restore table header
  16858.                         $this->thead $tmp_thead;
  16859.                         // fix table border properties
  16860.                         if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  16861.                             $tmp_cellspacing $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1'px');
  16862.                         } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  16863.                             $tmp_cellspacing $dom[$dom[$key]['parent']]['border-spacing']['V'];
  16864.                         } else {
  16865.                             $tmp_cellspacing 0;
  16866.                         }
  16867.                         $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  16868.                         $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  16869.                         $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->$tmp_cellspacing;
  16870.                         $xoffset = ($this->$dom[$dom[$key]['parent']]['borderposition']['x']);
  16871.                         $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  16872.                         $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  16873.                         // print table header (thead)
  16874.                         $this->writeHTML($this->theadfalsefalsefalsefalse'');
  16875.                     }
  16876.                 }
  16877.                 // move $key index forward to skip THEAD block
  16878.                 while ( ($key $maxel) AND (!(
  16879.                     ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  16880.                     OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  16881.                     ++$key;
  16882.                 }
  16883.             }
  16884.             if ($dom[$key]['tag'] OR ($key == 0)) {
  16885.                 if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  16886.                     $dom[$key]['align'] = ($this->rtl) ? 'R' 'L';
  16887.                 }
  16888.                 // vertically align image in line
  16889.                 if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  16890.                     // get image height
  16891.                     $imgh $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px');
  16892.                     $autolinebreak false;
  16893.                     if (!empty($dom[$key]['width'])) {
  16894.                         $imgw $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px'false);
  16895.                         if (($imgw <= ($this->$this->lMargin $this->rMargin $this->cell_padding['L'] - $this->cell_padding['R']))
  16896.                             AND ((($this->rtl) AND (($this->$imgw) < ($this->lMargin $this->cell_padding['L'])))
  16897.                             OR ((!$this->rtl) AND (($this->$imgw) > ($this->$this->rMargin $this->cell_padding['R']))))) {
  16898.                             // add automatic line break
  16899.                             $autolinebreak true;
  16900.                             $this->Ln(''$cell);
  16901.                             if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  16902.                                 // go back to evaluate this line break
  16903.                                 --$key;
  16904.                             }
  16905.                         }
  16906.                     }
  16907.                     if (!$autolinebreak) {
  16908.                         if ($this->inPageBody()) {
  16909.                             $pre_y $this->y;
  16910.                             // check for page break
  16911.                             if ((!$this->checkPageBreak($imgh)) AND ($this->$pre_y)) {
  16912.                                 // fix for multicolumn mode
  16913.                                 $startliney $this->y;
  16914.                             }
  16915.                         }
  16916.                         if ($this->page $startlinepage) {
  16917.                             // fix line splitted over two pages
  16918.                             if (isset($this->footerlen[$startlinepage])) {
  16919.                                 $curpos $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16920.                             }
  16921.                             // line to be moved one page forward
  16922.                             $pagebuff $this->getPageBuffer($startlinepage);
  16923.                             $linebeg substr($pagebuff$startlinepos, ($curpos $startlinepos));
  16924.                             $tstart substr($pagebuff0$startlinepos);
  16925.                             $tend substr($this->getPageBuffer($startlinepage), $curpos);
  16926.                             // remove line from previous page
  16927.                             $this->setPageBuffer($startlinepage$tstart.''.$tend);
  16928.                             $pagebuff $this->getPageBuffer($this->page);
  16929.                             $tstart substr($pagebuff0$this->cntmrk[$this->page]);
  16930.                             $tend substr($pagebuff$this->cntmrk[$this->page]);
  16931.                             // add line start to current page
  16932.                             $yshift = ($minstartliney $this->y);
  16933.                             if ($fontaligned) {
  16934.                                 $yshift += ($curfontsize $this->k);
  16935.                             }
  16936.                             $try sprintf('1 0 0 1 0 %F cm', ($yshift $this->k));
  16937.                             $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16938.                             // shift the annotations and links
  16939.                             if (isset($this->PageAnnots[$this->page])) {
  16940.                                 $next_pask count($this->PageAnnots[$this->page]);
  16941.                             } else {
  16942.                                 $next_pask 0;
  16943.                             }
  16944.                             if (isset($this->PageAnnots[$startlinepage])) {
  16945.                                 foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16946.                                     if ($pak >= $pask) {
  16947.                                         $this->PageAnnots[$this->page][] = $pac;
  16948.                                         unset($this->PageAnnots[$startlinepage][$pak]);
  16949.                                         $npak count($this->PageAnnots[$this->page]) - 1;
  16950.                                         $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16951.                                     }
  16952.                                 }
  16953.                             }
  16954.                             $pask $next_pask;
  16955.                             $startlinepos $this->cntmrk[$this->page];
  16956.                             $startlinepage $this->page;
  16957.                             $startliney $this->y;
  16958.                             $this->newline false;
  16959.                         }
  16960.                         $this->+= ($this->getCellHeight($curfontsize $this->k) - ($curfontdescent $this->cell_height_ratio) - $imgh);
  16961.                         $minstartliney min($this->y$minstartliney);
  16962.                         $maxbottomliney = ($startliney $this->getCellHeight($curfontsize $this->k));
  16963.                     }
  16964.                 } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  16965.                     // account for different font size
  16966.                     $pfontname $curfontname;
  16967.                     $pfontstyle $curfontstyle;
  16968.                     $pfontsize $curfontsize;
  16969.                     $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  16970.                     $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  16971.                     $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  16972.                     $fontascent $this->getFontAscent($fontname$fontstyle$fontsize);
  16973.                     $fontdescent $this->getFontDescent($fontname$fontstyle$fontsize);
  16974.                     if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  16975.                         OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16976.                         OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  16977.                         if (($key < ($maxel 1)) AND (
  16978.                                 ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  16979.                                 OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16980.                                 OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
  16981.                                 AND ($fontsize >= 0) AND ($curfontsize >= 0)
  16982.                                 AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
  16983.                             )) {
  16984.                             if ($this->page $startlinepage) {
  16985.                                 // fix lines splitted over two pages
  16986.                                 if (isset($this->footerlen[$startlinepage])) {
  16987.                                     $curpos $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16988.                                 }
  16989.                                 // line to be moved one page forward
  16990.                                 $pagebuff $this->getPageBuffer($startlinepage);
  16991.                                 $linebeg substr($pagebuff$startlinepos, ($curpos $startlinepos));
  16992.                                 $tstart substr($pagebuff0$startlinepos);
  16993.                                 $tend substr($this->getPageBuffer($startlinepage), $curpos);
  16994.                                 // remove line start from previous page
  16995.                                 $this->setPageBuffer($startlinepage$tstart.''.$tend);
  16996.                                 $pagebuff $this->getPageBuffer($this->page);
  16997.                                 $tstart substr($pagebuff0$this->cntmrk[$this->page]);
  16998.                                 $tend substr($pagebuff$this->cntmrk[$this->page]);
  16999.                                 // add line start to current page
  17000.                                 $yshift = ($minstartliney $this->y);
  17001.                                 $try sprintf('1 0 0 1 0 %F cm', ($yshift $this->k));
  17002.                                 $this->setPageBuffer($this->page$tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  17003.                                 // shift the annotations and links
  17004.                                 if (isset($this->PageAnnots[$this->page])) {
  17005.                                     $next_pask count($this->PageAnnots[$this->page]);
  17006.                                 } else {
  17007.                                     $next_pask 0;
  17008.                                 }
  17009.                                 if (isset($this->PageAnnots[$startlinepage])) {
  17010.                                     foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  17011.                                         if ($pak >= $pask) {
  17012.                                             $this->PageAnnots[$this->page][] = $pac;
  17013.                                             unset($this->PageAnnots[$startlinepage][$pak]);
  17014.                                             $npak count($this->PageAnnots[$this->page]) - 1;
  17015.                                             $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  17016.                                         }
  17017.                                     }
  17018.                                 }
  17019.                                 $pask $next_pask;
  17020.                                 $startlinepos $this->cntmrk[$this->page];
  17021.                                 $startlinepage $this->page;
  17022.                                 $startliney $this->y;
  17023.                             }
  17024.                             if (!isset($dom[$key]['line-height'])) {
  17025.                                 $dom[$key]['line-height'] = $this->cell_height_ratio;
  17026.                             }
  17027.                             if (!$dom[$key]['block']) {
  17028.                                 if (!(isset($dom[($key 1)]) AND $dom[($key 1)]['tag'] AND (!$dom[($key 1)]['opening']) AND ($dom[($key 1)]['value'] != 'li') AND $dom[$key]['tag'] AND (!$dom[$key]['opening']))) {
  17029.                                     $this->+= (((($curfontsize $this->cell_height_ratio) - ($fontsize $dom[$key]['line-height'])) / $this->k) + $curfontascent $fontascent $curfontdescent $fontdescent) / 2;
  17030.                                 }
  17031.                                 if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  17032.                                     $current_line_align_data = array($key$minstartliney$maxbottomliney);
  17033.                                     if (isset($line_align_data) AND (($line_align_data[0] == ($key 1)) OR (($line_align_data[0] == ($key 2)) AND (isset($dom[($key 1)])) AND (preg_match('/^([\s]+)$/'$dom[($key 1)]['value']) > 0)))) {
  17034.                                         $minstartliney min($this->y$line_align_data[1]);
  17035.                                         $maxbottomliney max(($this->$this->getCellHeight($fontsize $this->k)), $line_align_data[2]);
  17036.                                     } else {
  17037.                                         $minstartliney min($this->y$minstartliney);
  17038.                                         $maxbottomliney max(($this->$this->getCellHeight($fontsize $this->k)), $maxbottomliney);
  17039.                                     }
  17040.                                     $line_align_data $current_line_align_data;
  17041.                                 }
  17042.                             }
  17043.                             $this->cell_height_ratio $dom[$key]['line-height'];
  17044.                             $fontaligned true;
  17045.                         }
  17046.                         $this->setFont($fontname$fontstyle$fontsize);
  17047.                         // reset row height
  17048.                         $this->resetLastH();
  17049.                         $curfontname $fontname;
  17050.                         $curfontstyle $fontstyle;
  17051.                         $curfontsize $fontsize;
  17052.                         $curfontascent $fontascent;
  17053.                         $curfontdescent $fontdescent;
  17054.                     }
  17055.                 }
  17056.                 // set text rendering mode
  17057.                 $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  17058.                 $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode 2) == 0);
  17059.                 $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode 3);
  17060.                 $this->setTextRenderingMode($textstroke$textfill$textclip);
  17061.                 if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  17062.                     $this->setFontStretching($dom[$key]['font-stretch']);
  17063.                 }
  17064.                 if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  17065.                     $this->setFontSpacing($dom[$key]['letter-spacing']);
  17066.                 }
  17067.                 if (($plalign == 'J') AND $dom[$key]['block']) {
  17068.                     $plalign '';
  17069.                 }
  17070.                 // get current position on page buffer
  17071.                 $curpos $this->pagelen[$startlinepage];
  17072.                 if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  17073.                     $this->setFillColorArray($dom[$key]['bgcolor']);
  17074.                     $wfill true;
  17075.                 } else {
  17076.                     $wfill $fill false;
  17077.                 }
  17078.                 if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  17079.                     $this->setTextColorArray($dom[$key]['fgcolor']);
  17080.                 }
  17081.                 if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  17082.                     $this->setDrawColorArray($dom[$key]['strokecolor']);
  17083.                 }
  17084.                 if (isset($dom[$key]['align'])) {
  17085.                     $lalign $dom[$key]['align'];
  17086.                 }
  17087.                 if (TCPDF_STATIC::empty_string($lalign)) {
  17088.                     $lalign $align;
  17089.                 }
  17090.             }
  17091.             // align lines
  17092.             if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  17093.                 $newline true;
  17094.                 $fontaligned false;
  17095.                 // we are at the beginning of a new line
  17096.                 if (isset($startlinex)) {
  17097.                     $yshift = ($minstartliney $startliney);
  17098.                     if (($yshift 0) OR ($this->page $startlinepage)) {
  17099.                         $yshift 0;
  17100.                     }
  17101.                     $t_x 0;
  17102.                     // the last line must be shifted to be aligned as requested
  17103.                     $linew abs($this->endlinex $startlinex);
  17104.                     if ($this->inxobj) {
  17105.                         // we are inside an XObject template
  17106.                         $pstart substr($this->xobjects[$this->xobjid]['outdata'], 0$startlinepos);
  17107.                         if (isset($opentagpos)) {
  17108.                             $midpos $opentagpos;
  17109.                         } else {
  17110.                             $midpos 0;
  17111.                         }
  17112.                         if ($midpos 0) {
  17113.                             $pmid substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos $startlinepos));
  17114.                             $pend substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17115.                         } else {
  17116.                             $pmid substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17117.                             $pend '';
  17118.                         }
  17119.                     } else {
  17120.                         $pstart substr($this->getPageBuffer($startlinepage), 0$startlinepos);
  17121.                         if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17122.                             $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17123.                             $midpos min($opentagpos$this->footerpos[$startlinepage]);
  17124.                         } elseif (isset($opentagpos)) {
  17125.                             $midpos $opentagpos;
  17126.                         } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17127.                             $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17128.                             $midpos $this->footerpos[$startlinepage];
  17129.                         } else {
  17130.                             $midpos 0;
  17131.                         }
  17132.                         if ($midpos 0) {
  17133.                             $pmid substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos $startlinepos));
  17134.                             $pend substr($this->getPageBuffer($startlinepage), $midpos);
  17135.                         } else {
  17136.                             $pmid substr($this->getPageBuffer($startlinepage), $startlinepos);
  17137.                             $pend '';
  17138.                         }
  17139.                     }
  17140.                     if ((((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17141.                         // calculate shifting amount
  17142.                         $tw $w;
  17143.                         if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns 1)) {
  17144.                             $tw += $this->cell_padding['R'];
  17145.                         }
  17146.                         if ($this->lMargin != $prevlMargin) {
  17147.                             $tw += ($prevlMargin $this->lMargin);
  17148.                         }
  17149.                         if ($this->rMargin != $prevrMargin) {
  17150.                             $tw += ($prevrMargin $this->rMargin);
  17151.                         }
  17152.                         $one_space_width $this->GetStringWidth(chr(32));
  17153.                         $no 0// number of spaces on a line contained on a single block
  17154.                         if ($this->isRTLTextDir()) { // RTL
  17155.                             // remove left space if exist
  17156.                             $pos1 TCPDF_STATIC::revstrpos($pmid'[(');
  17157.                             if ($pos1 0) {
  17158.                                 $pos1 intval($pos1);
  17159.                                 if ($this->isUnicodeFont()) {
  17160.                                     $pos2 intval(TCPDF_STATIC::revstrpos($pmid'[('.chr(0).chr(32)));
  17161.                                     $spacelen 2;
  17162.                                 } else {
  17163.                                     $pos2 intval(TCPDF_STATIC::revstrpos($pmid'[('.chr(32)));
  17164.                                     $spacelen 1;
  17165.                                 }
  17166.                                 if ($pos1 == $pos2) {
  17167.                                     $pmid substr($pmid0, ($pos1 2)).substr($pmid, ($pos1 $spacelen));
  17168.                                     if (substr($pmid$pos14) == '[()]') {
  17169.                                         $linew -= $one_space_width;
  17170.                                     } elseif ($pos1 == strpos($pmid'[(')) {
  17171.                                         $no 1;
  17172.                                     }
  17173.                                 }
  17174.                             }
  17175.                         } else { // LTR
  17176.                             // remove right space if exist
  17177.                             $pos1 TCPDF_STATIC::revstrpos($pmid')]');
  17178.                             if ($pos1 0) {
  17179.                                 $pos1 intval($pos1);
  17180.                                 if ($this->isUnicodeFont()) {
  17181.                                     $pos2 intval(TCPDF_STATIC::revstrpos($pmidchr(0).chr(32).')]')) + 2;
  17182.                                     $spacelen 2;
  17183.                                 } else {
  17184.                                     $pos2 intval(TCPDF_STATIC::revstrpos($pmidchr(32).')]')) + 1;
  17185.                                     $spacelen 1;
  17186.                                 }
  17187.                                 if ($pos1 == $pos2) {
  17188.                                     $pmid substr($pmid0, ($pos1 $spacelen)).substr($pmid$pos1);
  17189.                                     $linew -= $one_space_width;
  17190.                                 }
  17191.                             }
  17192.                         }
  17193.                         $mdiff = ($tw $linew);
  17194.                         if ($plalign == 'C') {
  17195.                             if ($this->rtl) {
  17196.                                 $t_x = -($mdiff 2);
  17197.                             } else {
  17198.                                 $t_x = ($mdiff 2);
  17199.                             }
  17200.                         } elseif ($plalign == 'R') {
  17201.                             // right alignment on LTR document
  17202.                             $t_x $mdiff;
  17203.                         } elseif ($plalign == 'L') {
  17204.                             // left alignment on RTL document
  17205.                             $t_x = -$mdiff;
  17206.                         } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  17207.                             // Justification
  17208.                             if ($this->isRTLTextDir()) {
  17209.                                 // align text on the left
  17210.                                 $t_x = -$mdiff;
  17211.                             }
  17212.                             $ns 0// number of spaces
  17213.                             $pmidtemp $pmid;
  17214.                             // escape special characters
  17215.                             $pmidtemp preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmidtemp);
  17216.                             $pmidtemp preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmidtemp);
  17217.                             // search spaces
  17218.                             if (preg_match_all('/\[\(([^\)]*)\)\]/x'$pmidtemp$lnstringPREG_PATTERN_ORDER)) {
  17219.                                 $spacestr $this->getSpaceString();
  17220.                                 $maxkk count($lnstring[1]) - 1;
  17221.                                 for ($kk=0$kk <= $maxkk; ++$kk) {
  17222.                                     // restore special characters
  17223.                                     $lnstring[1][$kk] = str_replace('#!#OP#!#''('$lnstring[1][$kk]);
  17224.                                     $lnstring[1][$kk] = str_replace('#!#CP#!#'')'$lnstring[1][$kk]);
  17225.                                     // store number of spaces on the strings
  17226.                                     $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  17227.                                     // count total spaces on line
  17228.                                     $ns += $lnstring[2][$kk];
  17229.                                     $lnstring[3][$kk] = $ns;
  17230.                                 }
  17231.                                 if ($ns == 0) {
  17232.                                     $ns 1;
  17233.                                 }
  17234.                                 // calculate additional space to add to each existing space
  17235.                                 $spacewidth = ($mdiff / ($ns $no)) * $this->k;
  17236.                                 if ($this->FontSize <= 0) {
  17237.                                     $this->FontSize 1;
  17238.                                 }
  17239.                                 $spacewidthu = -1000 * ($mdiff + (($ns $no) * $one_space_width)) / $ns $this->FontSize;
  17240.                                 if ($this->font_spacing != 0) {
  17241.                                     // fixed spacing mode
  17242.                                     $osw = -1000 $this->font_spacing $this->FontSize;
  17243.                                     $spacewidthu += $osw;
  17244.                                 }
  17245.                                 $nsmax $ns;
  17246.                                 $ns 0;
  17247.                                 reset($lnstring);
  17248.                                 $offset 0;
  17249.                                 $strcount 0;
  17250.                                 $prev_epsposbeg 0;
  17251.                                 $textpos 0;
  17252.                                 if ($this->isRTLTextDir()) {
  17253.                                     $textpos $this->wPt;
  17254.                                 }
  17255.                                 while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x'$pmid$strpiecePREG_OFFSET_CAPTURE$offset) == 1) {
  17256.                                     // check if we are inside a string section '[( ... )]'
  17257.                                     $stroffset strpos($pmid'[('$offset);
  17258.                                     if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  17259.                                         // set offset to the end of string section
  17260.                                         $offset strpos($pmid')]'$stroffset);
  17261.                                         while (($offset !== false) AND ($pmid[($offset 1)] == '\\')) {
  17262.                                             $offset strpos($pmid')]', ($offset 1));
  17263.                                         }
  17264.                                         if ($offset === false) {
  17265.                                             $this->Error('HTML Justification: malformed PDF code.');
  17266.                                         }
  17267.                                         continue;
  17268.                                     }
  17269.                                     if ($this->isRTLTextDir()) {
  17270.                                         $spacew = ($spacewidth * ($nsmax $ns));
  17271.                                     } else {
  17272.                                         $spacew = ($spacewidth $ns);
  17273.                                     }
  17274.                                     $offset $strpiece[2][1] + strlen($strpiece[2][0]);
  17275.                                     $epsposend strpos($pmid$this->epsmarker.'Q'$offset);
  17276.                                     if ($epsposend !== null) {
  17277.                                         $epsposend += strlen($this->epsmarker.'Q');
  17278.                                         $epsposbeg strpos($pmid'q'.$this->epsmarker$offset);
  17279.                                         if ($epsposbeg === null) {
  17280.                                             $epsposbeg strpos($pmid'q'.$this->epsmarker, ($prev_epsposbeg 6));
  17281.                                             $prev_epsposbeg $epsposbeg;
  17282.                                         }
  17283.                                         if (($epsposbeg 0) AND ($epsposend 0) AND ($offset $epsposbeg) AND ($offset $epsposend)) {
  17284.                                             // shift EPS images
  17285.                                             $trx sprintf('1 0 0 1 %F 0 cm'$spacew);
  17286.                                             $pmid_b substr($pmid0$epsposbeg);
  17287.                                             $pmid_m substr($pmid$epsposbeg, ($epsposend $epsposbeg));
  17288.                                             $pmid_e substr($pmid$epsposend);
  17289.                                             $pmid $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17290.                                             $offset $epsposend;
  17291.                                             continue;
  17292.                                         }
  17293.                                     }
  17294.                                     $currentxpos 0;
  17295.                                     // shift blocks of code
  17296.                                     switch ($strpiece[2][0]) {
  17297.                                         case 'Td':
  17298.                                         case 'cm':
  17299.                                         case 'm':
  17300.                                         case 'l': {
  17301.                                             // get current X position
  17302.                                             preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$xmatches);
  17303.                                             if (!isset($xmatches[1])) {
  17304.                                                 break;
  17305.                                             }
  17306.                                             $currentxpos $xmatches[1];
  17307.                                             $textpos $currentxpos;
  17308.                                             if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17309.                                                 $ns $lnstring[3][$strcount];
  17310.                                                 if ($this->isRTLTextDir()) {
  17311.                                                     $spacew = ($spacewidth * ($nsmax $ns));
  17312.                                                 }
  17313.                                                 ++$strcount;
  17314.                                             }
  17315.                                             // justify block
  17316.                                             if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x'$pmid$pmatch) == 1) {
  17317.                                                 $newpmid sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
  17318.                                                 $pmid str_replace($pmatch[0], $newpmid$pmid);
  17319.                                                 unset($pmatch$newpmid);
  17320.                                             }
  17321.                                             break;
  17322.                                         }
  17323.                                         case 're': {
  17324.                                             // justify block
  17325.                                             if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17326.                                                 $this->lispacer '';
  17327.                                                 break;
  17328.                                             }
  17329.                                             preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x'$pmid$xmatches);
  17330.                                             if (!isset($xmatches[1])) {
  17331.                                                 break;
  17332.                                             }
  17333.                                             $currentxpos $xmatches[1];
  17334.                                             $x_diff 0;
  17335.                                             $w_diff 0;
  17336.                                             if ($this->isRTLTextDir()) { // RTL
  17337.                                                 if ($currentxpos $textpos) {
  17338.                                                     $x_diff = ($spacewidth * ($nsmax $lnstring[3][$strcount]));
  17339.                                                     $w_diff = ($spacewidth $lnstring[2][$strcount]);
  17340.                                                 } else {
  17341.                                                     if ($strcount 0) {
  17342.                                                         $x_diff = ($spacewidth * ($nsmax $lnstring[3][($strcount 1)]));
  17343.                                                         $w_diff = ($spacewidth $lnstring[2][($strcount 1)]);
  17344.                                                     }
  17345.                                                 }
  17346.                                             } else { // LTR
  17347.                                                 if ($currentxpos $textpos) {
  17348.                                                     if ($strcount 0) {
  17349.                                                         $x_diff = ($spacewidth $lnstring[3][($strcount 1)]);
  17350.                                                     }
  17351.                                                     $w_diff = ($spacewidth $lnstring[2][$strcount]);
  17352.                                                 } else {
  17353.                                                     if ($strcount 1) {
  17354.                                                         $x_diff = ($spacewidth $lnstring[3][($strcount 2)]);
  17355.                                                     }
  17356.                                                     if ($strcount 0) {
  17357.                                                         $w_diff = ($spacewidth $lnstring[2][($strcount 1)]);
  17358.                                                     }
  17359.                                                 }
  17360.                                             }
  17361.                                             if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x'$pmid$pmatch) == 1) {
  17362.                                                 $newx sprintf('%F',(floatval($pmatch[1]) + $x_diff));
  17363.                                                 $neww sprintf('%F',(floatval($pmatch[3]) + $w_diff));
  17364.                                                 $newpmid $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
  17365.                                                 $pmid str_replace($pmatch[0], $newpmid$pmid);
  17366.                                                 unset($pmatch$newpmid$newx$neww);
  17367.                                             }
  17368.                                             break;
  17369.                                         }
  17370.                                         case 'c': {
  17371.                                             // get current X position
  17372.                                             preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x'$pmid$xmatches);
  17373.                                             if (!isset($xmatches[1])) {
  17374.                                                 break;
  17375.                                             }
  17376.                                             $currentxpos $xmatches[1];
  17377.                                             // justify block
  17378.                                             if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x'$pmid$pmatch) == 1) {
  17379.                                                 $newx1 sprintf('%F',(floatval($pmatch[1]) + $spacew));
  17380.                                                 $newx2 sprintf('%F',(floatval($pmatch[3]) + $spacew));
  17381.                                                 $newx3 sprintf('%F',(floatval($pmatch[5]) + $spacew));
  17382.                                                 $newpmid $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
  17383.                                                 $pmid str_replace($pmatch[0], $newpmid$pmid);
  17384.                                                 unset($pmatch$newpmid$newx1$newx2$newx3);
  17385.                                             }
  17386.                                             break;
  17387.                                         }
  17388.                                     }
  17389.                                     // shift the annotations and links
  17390.                                     $cxpos = ($currentxpos $this->k);
  17391.                                     $lmpos = ($this->lMargin $this->cell_padding['L'] + $this->feps);
  17392.                                     if ($this->inxobj) {
  17393.                                         // we are inside an XObject template
  17394.                                         foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17395.                                             if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos $this->feps))) {
  17396.                                                 if ($cxpos $lmpos) {
  17397.                                                     $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew $this->k);
  17398.                                                     $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth $pac['numspaces']) / $this->k);
  17399.                                                 } else {
  17400.                                                     $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth $pac['numspaces']) / $this->k);
  17401.                                                 }
  17402.                                                 break;
  17403.                                             }
  17404.                                         }
  17405.                                     } elseif (isset($this->PageAnnots[$this->page])) {
  17406.                                         foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17407.                                             if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos $this->feps))) {
  17408.                                                 if ($cxpos $lmpos) {
  17409.                                                     $this->PageAnnots[$this->page][$pak]['x'] += ($spacew $this->k);
  17410.                                                     $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth $pac['numspaces']) / $this->k);
  17411.                                                 } else {
  17412.                                                     $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth $pac['numspaces']) / $this->k);
  17413.                                                 }
  17414.                                                 break;
  17415.                                             }
  17416.                                         }
  17417.                                     }
  17418.                                 } // end of while
  17419.                                 // remove markers
  17420.                                 $pmid str_replace('x*#!#*x'''$pmid);
  17421.                                 if ($this->isUnicodeFont()) {
  17422.                                     // multibyte characters
  17423.                                     $spacew $spacewidthu;
  17424.                                     if ($this->font_stretching != 100) {
  17425.                                         // word spacing is affected by stretching
  17426.                                         $spacew /= ($this->font_stretching 100);
  17427.                                     }
  17428.                                     // escape special characters
  17429.                                     $pos 0;
  17430.                                     $pmid preg_replace('/[\\\][\(]/x''\\#!#OP#!#'$pmid);
  17431.                                     $pmid preg_replace('/[\\\][\)]/x''\\#!#CP#!#'$pmid);
  17432.                                     if (preg_match_all('/\[\(([^\)]*)\)\]/x'$pmid$pamatch) > 0) {
  17433.                                         foreach($pamatch[0] as $pk => $pmatch) {
  17434.                                             $replace $pamatch[1][$pk];
  17435.                                             $replace str_replace('#!#OP#!#''('$replace);
  17436.                                             $replace str_replace('#!#CP#!#'')'$replace);
  17437.                                             $newpmid '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F'$spacew).' ('$replace).')]';
  17438.                                             $pos strpos($pmid$pmatch$pos);
  17439.                                             if ($pos !== FALSE) {
  17440.                                                 $pmid substr_replace($pmid$newpmid$posstrlen($pmatch));
  17441.                                             }
  17442.                                             ++$pos;
  17443.                                         }
  17444.                                         unset($pamatch);
  17445.                                     }
  17446.                                     if ($this->inxobj) {
  17447.                                         // we are inside an XObject template
  17448.                                         $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17449.                                     } else {
  17450.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\n".$pend);
  17451.                                     }
  17452.                                     $endlinepos strlen($pstart."\n".$pmid."\n");
  17453.                                 } else {
  17454.                                     // non-unicode (single-byte characters)
  17455.                                     if ($this->font_stretching != 100) {
  17456.                                         // word spacing (Tw) is affected by stretching
  17457.                                         $spacewidth /= ($this->font_stretching 100);
  17458.                                     }
  17459.                                     $rs sprintf('%F Tw'$spacewidth);
  17460.                                     $pmid preg_replace("/\[\(/x"$rs.' [('$pmid);
  17461.                                     if ($this->inxobj) {
  17462.                                         // we are inside an XObject template
  17463.                                         $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17464.                                     } else {
  17465.                                         $this->setPageBuffer($startlinepage$pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17466.                                     }
  17467.                                     $endlinepos strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17468.                                 }
  17469.                             }
  17470.                         } // end of J
  17471.                     // end if $startlinex
  17472.                     if (($t_x != 0) OR ($yshift 0)) {
  17473.                         // shift the line
  17474.                         $trx sprintf('1 0 0 1 %F %F cm', ($t_x $this->k), ($yshift $this->k));
  17475.                         $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17476.                         $endlinepos strlen($pstart);
  17477.                         if ($this->inxobj) {
  17478.                             // we are inside an XObject template
  17479.                             $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17480.                             foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17481.                                 if ($pak >= $pask) {
  17482.                                     $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17483.                                     $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17484.                                 }
  17485.                             }
  17486.                         } else {
  17487.                             $this->setPageBuffer($startlinepage$pstart.$pend);
  17488.                             // shift the annotations and links
  17489.                             if (isset($this->PageAnnots[$this->page])) {
  17490.                                 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17491.                                     if ($pak >= $pask) {
  17492.                                         $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17493.                                         $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17494.                                     }
  17495.                                 }
  17496.                             }
  17497.                         }
  17498.                         $this->-= $yshift;
  17499.                     }
  17500.                 }
  17501.                 $pbrk $this->checkPageBreak($this->lasth);
  17502.                 $this->newline false;
  17503.                 $startlinex $this->x;
  17504.                 $startliney $this->y;
  17505.                 if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17506.                     $startliney -= ((0.3 $this->FontSizePt) / $this->k);
  17507.                 } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17508.                     $startliney -= (($this->FontSizePt 0.7) / $this->k);
  17509.                 } else {
  17510.                     $minstartliney $startliney;
  17511.                     $maxbottomliney = ($this->$this->getCellHeight($fontsize $this->k));
  17512.                 }
  17513.                 $startlinepage $this->page;
  17514.                 if (isset($endlinepos) AND (!$pbrk)) {
  17515.                     $startlinepos $endlinepos;
  17516.                 } else {
  17517.                     if ($this->inxobj) {
  17518.                         // we are inside an XObject template
  17519.                         $startlinepos strlen($this->xobjects[$this->xobjid]['outdata']);
  17520.                     } elseif (!$this->InFooter) {
  17521.                         if (isset($this->footerlen[$this->page])) {
  17522.                             $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17523.                         } else {
  17524.                             $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17525.                         }
  17526.                         $startlinepos $this->footerpos[$this->page];
  17527.                     } else {
  17528.                         $startlinepos $this->pagelen[$this->page];
  17529.                     }
  17530.                 }
  17531.                 unset($endlinepos);
  17532.                 $plalign $lalign;
  17533.                 if (isset($this->PageAnnots[$this->page])) {
  17534.                     $pask count($this->PageAnnots[$this->page]);
  17535.                 } else {
  17536.                     $pask 0;
  17537.                 }
  17538.                 if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17539.                     AND (isset($this->emptypagemrk[$this->page]))
  17540.                     AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17541.                     $this->setFont($fontname$fontstyle$fontsize);
  17542.                     if ($wfill) {
  17543.                         $this->setFillColorArray($this->bgcolor);
  17544.                     }
  17545.                 }
  17546.             } // end newline
  17547.             if (isset($opentagpos)) {
  17548.                 unset($opentagpos);
  17549.             }
  17550.             if ($dom[$key]['tag']) {
  17551.                 if ($dom[$key]['opening']) {
  17552.                     // get text indentation (if any)
  17553.                     if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17554.                         $this->textindent $dom[$key]['text-indent'];
  17555.                         $this->newline true;
  17556.                     }
  17557.                     // table
  17558.                     if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17559.                         // available page width
  17560.                         if ($this->rtl) {
  17561.                             $wtmp $this->$this->lMargin;
  17562.                         } else {
  17563.                             $wtmp $this->$this->rMargin $this->x;
  17564.                         }
  17565.                         // get cell spacing
  17566.                         if (isset($dom[$key]['attribute']['cellspacing'])) {
  17567.                             $clsp $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1'px');
  17568.                             $cellspacing = array('H' => $clsp'V' => $clsp);
  17569.                         } elseif (isset($dom[$key]['border-spacing'])) {
  17570.                             $cellspacing $dom[$key]['border-spacing'];
  17571.                         } else {
  17572.                             $cellspacing = array('H' => 0'V' => 0);
  17573.                         }
  17574.                         // table width
  17575.                         if (isset($dom[$key]['width'])) {
  17576.                             $table_width $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp'px');
  17577.                         } else {
  17578.                             $table_width $wtmp;
  17579.                         }
  17580.                         $table_width -= ($cellspacing['H']);
  17581.                         if (!$this->inthead) {
  17582.                             $this->+= $cellspacing['V'];
  17583.                         }
  17584.                         if ($this->rtl) {
  17585.                             $cellspacingx = -$cellspacing['H'];
  17586.                         } else {
  17587.                             $cellspacingx $cellspacing['H'];
  17588.                         }
  17589.                         // total table width without cellspaces
  17590.                         $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17591.                         // minimum column width
  17592.                         $table_min_column_width = ($table_columns_width $dom[$key]['cols']);
  17593.                         // array of custom column widths
  17594.                         $table_colwidths array_fill(0$dom[$key]['cols'], $table_min_column_width);
  17595.                     }
  17596.                     // table row
  17597.                     if ($dom[$key]['value'] == 'tr') {
  17598.                         // reset column counter
  17599.                         $colid 0;
  17600.                     }
  17601.                     // table cell
  17602.                     if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17603.                         $trid $dom[$key]['parent'];
  17604.                         $table_el $dom[$trid]['parent'];
  17605.                         if (!isset($dom[$table_el]['cols'])) {
  17606.                             $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17607.                         }
  17608.                         // store border info
  17609.                         $tdborder 0;
  17610.                         if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17611.                             $tdborder $dom[$key]['border'];
  17612.                         }
  17613.                         $colspan intval($dom[$key]['attribute']['colspan']);
  17614.                         if ($colspan <= 0) {
  17615.                             $colspan 1;
  17616.                         }
  17617.                         $old_cell_padding $this->cell_padding;
  17618.                         if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17619.                             $crclpd $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1'px');
  17620.                             $current_cell_padding = array('L' => $crclpd'T' => $crclpd'R' => $crclpd'B' => $crclpd);
  17621.                         } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17622.                             $current_cell_padding $dom[($dom[$trid]['parent'])]['padding'];
  17623.                         } else {
  17624.                             $current_cell_padding = array('L' => 0'T' => 0'R' => 0'B' => 0);
  17625.                         }
  17626.                         $this->cell_padding $current_cell_padding;
  17627.                         if (isset($dom[$key]['height'])) {
  17628.                             // minimum cell height
  17629.                             $cellh $this->getHTMLUnitToUnits($dom[$key]['height'], 0'px');
  17630.                         } else {
  17631.                             $cellh 0;
  17632.                         }
  17633.                         if (isset($dom[$key]['content'])) {
  17634.                             $cell_content $dom[$key]['content'];
  17635.                         } else {
  17636.                             $cell_content '&nbsp;';
  17637.                         }
  17638.                         $tagtype $dom[$key]['value'];
  17639.                         $parentid $key;
  17640.                         while (($key $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17641.                             // move $key index forward
  17642.                             ++$key;
  17643.                         }
  17644.                         if (!isset($dom[$trid]['startpage'])) {
  17645.                             $dom[$trid]['startpage'] = $this->page;
  17646.                         } else {
  17647.                             $this->setPage($dom[$trid]['startpage']);
  17648.                         }
  17649.                         if (!isset($dom[$trid]['startcolumn'])) {
  17650.                             $dom[$trid]['startcolumn'] = $this->current_column;
  17651.                         } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17652.                             $tmpx $this->x;
  17653.                             $this->selectColumn($dom[$trid]['startcolumn']);
  17654.                             $this->$tmpx;
  17655.                         }
  17656.                         if (!isset($dom[$trid]['starty'])) {
  17657.                             $dom[$trid]['starty'] = $this->y;
  17658.                         } else {
  17659.                             $this->$dom[$trid]['starty'];
  17660.                         }
  17661.                         if (!isset($dom[$trid]['startx'])) {
  17662.                             $dom[$trid]['startx'] = $this->x;
  17663.                             $this->+= $cellspacingx;
  17664.                         } else {
  17665.                             $this->+= ($cellspacingx 2);
  17666.                         }
  17667.                         if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17668.                             $rowspan intval($dom[$parentid]['attribute']['rowspan']);
  17669.                         } else {
  17670.                             $rowspan 1;
  17671.                         }
  17672.                         // skip row-spanned cells started on the previous rows
  17673.                         if (isset($dom[$table_el]['rowspans'])) {
  17674.                             $rsk 0;
  17675.                             $rskmax count($dom[$table_el]['rowspans']);
  17676.                             while ($rsk $rskmax) {
  17677.                                 $trwsp $dom[$table_el]['rowspans'][$rsk];
  17678.                                 $rsstartx $trwsp['startx'];
  17679.                                 $rsendx $trwsp['endx'];
  17680.                                 // account for margin changes
  17681.                                 if ($trwsp['startpage'] < $this->page) {
  17682.                                     if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17683.                                         $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17684.                                         $rsstartx -= $dl;
  17685.                                         $rsendx -= $dl;
  17686.                                     } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17687.                                         $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17688.                                         $rsstartx += $dl;
  17689.                                         $rsendx += $dl;
  17690.                                     }
  17691.                                 }
  17692.                                 if (($trwsp['rowspan'] > 0)
  17693.                                     AND ($rsstartx > ($this->$cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17694.                                     AND ($rsstartx < ($this->$cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17695.                                     AND (($trwsp['starty'] < ($this->$this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17696.                                     // set the starting X position of the current cell
  17697.                                     $this->$rsendx $cellspacingx;
  17698.                                     // increment column indicator
  17699.                                     $colid += $trwsp['colspan'];
  17700.                                     if (($trwsp['rowspan'] == 1)
  17701.                                         AND (isset($dom[$trid]['endy']))
  17702.                                         AND (isset($dom[$trid]['endpage']))
  17703.                                         AND (isset($dom[$trid]['endcolumn']))
  17704.                                         AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17705.                                         AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17706.                                         // set ending Y position for row
  17707.                                         $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17708.                                         $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17709.                                     }
  17710.                                     $rsk 0;
  17711.                                 } else {
  17712.                                     ++$rsk;
  17713.                                 }
  17714.                             }
  17715.                         }
  17716.                         if (isset($dom[$parentid]['width'])) {
  17717.                             // user specified width
  17718.                             $cellw $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width'px');
  17719.                             $tmpcw = ($cellw $colspan);
  17720.                             for ($i 0$i $colspan; ++$i) {
  17721.                                 $table_colwidths[($colid $i)] = $tmpcw;
  17722.                             }
  17723.                         } else {
  17724.                             // inherit column width
  17725.                             $cellw 0;
  17726.                             for ($i 0$i $colspan; ++$i) {
  17727.                                 $cellw += (isset($table_colwidths[($colid $i)]) ? $table_colwidths[($colid $i)] : 0);
  17728.                             }
  17729.                         }
  17730.                         $cellw += (($colspan 1) * $cellspacing['H']);
  17731.                         // increment column indicator
  17732.                         $colid += $colspan;
  17733.                         // add rowspan information to table element
  17734.                         if ($rowspan 1) {
  17735.                             $trsid array_push($dom[$table_el]['rowspans'], array('trid' => $trid'rowspan' => $rowspan'mrowspan' => $rowspan'colspan' => $colspan'startpage' => $this->page'startcolumn' => $this->current_column'startx' => $this->x'starty' => $this->y));
  17736.                         }
  17737.                         $cellid array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17738.                         if ($rowspan 1) {
  17739.                             $dom[$trid]['cellpos'][($cellid 1)]['rowspanid'] = ($trsid 1);
  17740.                         }
  17741.                         // push background colors
  17742.                         if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  17743.                             $dom[$trid]['cellpos'][($cellid 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  17744.                         }
  17745.                         // store border info
  17746.                         if (!empty($tdborder)) {
  17747.                             $dom[$trid]['cellpos'][($cellid 1)]['border'] = $tdborder;
  17748.                         }
  17749.                         $prevLastH $this->lasth;
  17750.                         // store some info for multicolumn mode
  17751.                         if ($this->rtl) {
  17752.                             $this->colxshift['x'] = $this->$this->$this->rMargin;
  17753.                         } else {
  17754.                             $this->colxshift['x'] = $this->$this->lMargin;
  17755.                         }
  17756.                         $this->colxshift['s'] = $cellspacing;
  17757.                         $this->colxshift['p'] = $current_cell_padding;
  17758.                         // ****** write the cell content ******
  17759.                         $this->MultiCell($cellw$cellh$cell_contentfalse$lalignfalse2''''true0truetrue0'T'false);
  17760.                         // restore some values
  17761.                         $this->colxshift = array('x' => 0's' => array('H' => 0'V' => 0), 'p' => array('L' => 0'T' => 0'R' => 0'B' => 0));
  17762.                         $this->lasth $prevLastH;
  17763.                         $this->cell_padding $old_cell_padding;
  17764.                         $dom[$trid]['cellpos'][($cellid 1)]['endx'] = $this->x;
  17765.                         // update the end of row position
  17766.                         if ($rowspan <= 1) {
  17767.                             if (isset($dom[$trid]['endy'])) {
  17768.                                 if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  17769.                                     $dom[$trid]['endy'] = max($this->y$dom[$trid]['endy']);
  17770.                                 } elseif (($this->page $dom[$trid]['endpage']) OR ($this->current_column $dom[$trid]['endcolumn'])) {
  17771.                                     $dom[$trid]['endy'] = $this->y;
  17772.                                 }
  17773.                             } else {
  17774.                                 $dom[$trid]['endy'] = $this->y;
  17775.                             }
  17776.                             if (isset($dom[$trid]['endpage'])) {
  17777.                                 $dom[$trid]['endpage'] = max($this->page$dom[$trid]['endpage']);
  17778.                             } else {
  17779.                                 $dom[$trid]['endpage'] = $this->page;
  17780.                             }
  17781.                             if (isset($dom[$trid]['endcolumn'])) {
  17782.                                 $dom[$trid]['endcolumn'] = max($this->current_column$dom[$trid]['endcolumn']);
  17783.                             } else {
  17784.                                 $dom[$trid]['endcolumn'] = $this->current_column;
  17785.                             }
  17786.                         } else {
  17787.                             // account for row-spanned cells
  17788.                             $dom[$table_el]['rowspans'][($trsid 1)]['endx'] = $this->x;
  17789.                             $dom[$table_el]['rowspans'][($trsid 1)]['endy'] = $this->y;
  17790.                             $dom[$table_el]['rowspans'][($trsid 1)]['endpage'] = $this->page;
  17791.                             $dom[$table_el]['rowspans'][($trsid 1)]['endcolumn'] = $this->current_column;
  17792.                         }
  17793.                         if (isset($dom[$table_el]['rowspans'])) {
  17794.                             // update endy and endpage on rowspanned cells
  17795.                             foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  17796.                                 if ($trwsp['rowspan'] > 0) {
  17797.                                     if (isset($dom[$trid]['endpage'])) {
  17798.                                         if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17799.                                             $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17800.                                         } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  17801.                                             $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  17802.                                             $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  17803.                                             $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  17804.                                         } else {
  17805.                                             $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  17806.                                         }
  17807.                                     }
  17808.                                 }
  17809.                             }
  17810.                         }
  17811.                         $this->+= ($cellspacingx 2);
  17812.                     } else {
  17813.                         // opening tag (or self-closing tag)
  17814.                         if (!isset($opentagpos)) {
  17815.                             if ($this->inxobj) {
  17816.                                 // we are inside an XObject template
  17817.                                 $opentagpos strlen($this->xobjects[$this->xobjid]['outdata']);
  17818.                             } elseif (!$this->InFooter) {
  17819.                                 if (isset($this->footerlen[$this->page])) {
  17820.                                     $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17821.                                 } else {
  17822.                                     $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17823.                                 }
  17824.                                 $opentagpos $this->footerpos[$this->page];
  17825.                             }
  17826.                         }
  17827.                         $dom $this->openHTMLTagHandler($dom$key$cell);
  17828.                     }
  17829.                 } else { // closing tag
  17830.                     $prev_numpages $this->numpages;
  17831.                     $old_bordermrk $this->bordermrk[$this->page];
  17832.                     $dom $this->closeHTMLTagHandler($dom$key$cell$maxbottomliney);
  17833.                     if ($this->bordermrk[$this->page] > $old_bordermrk) {
  17834.                         $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  17835.                     }
  17836.                     if ($prev_numpages $this->numpages) {
  17837.                         $startlinepage $this->page;
  17838.                     }
  17839.                 }
  17840.             } elseif (strlen($dom[$key]['value']) > 0) {
  17841.                 // print list-item
  17842.                 if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  17843.                     $this->setFont($pfontname$pfontstyle$pfontsize);
  17844.                     $this->resetLastH();
  17845.                     $minstartliney $this->y;
  17846.                     $maxbottomliney = ($startliney $this->getCellHeight($this->FontSize));
  17847.                     if (is_numeric($pfontsize) AND ($pfontsize 0)) {
  17848.                         $this->putHtmlListBullet($this->listnum$this->lispacer$pfontsize);
  17849.                     }
  17850.                     $this->setFont($curfontname$curfontstyle$curfontsize);
  17851.                     $this->resetLastH();
  17852.                     if (is_numeric($pfontsize) AND ($pfontsize 0) AND is_numeric($curfontsize) AND ($curfontsize 0) AND ($pfontsize != $curfontsize)) {
  17853.                         $pfontascent $this->getFontAscent($pfontname$pfontstyle$pfontsize);
  17854.                         $pfontdescent $this->getFontDescent($pfontname$pfontstyle$pfontsize);
  17855.                         $this->+= ($this->getCellHeight(($pfontsize $curfontsize) / $this->k) + $pfontascent $curfontascent $pfontdescent $curfontdescent) / 2;
  17856.                         $minstartliney min($this->y$minstartliney);
  17857.                         $maxbottomliney max(($this->$this->getCellHeight($pfontsize $this->k)), $maxbottomliney);
  17858.                     }
  17859.                 }
  17860.                 // text
  17861.                 $this->htmlvspace 0;
  17862.                 $isRTLString preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL$dom[$key]['value']) || preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC$dom[$key]['value']);
  17863.                 if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) {
  17864.                     // reverse spaces order
  17865.                     $lsp ''// left spaces
  17866.                     $rsp ''// right spaces
  17867.                     if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17868.                         $lsp $matches[1];
  17869.                     }
  17870.                     if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17871.                         $rsp $matches[1];
  17872.                     }
  17873.                     $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  17874.                 }
  17875.                 if ($newline) {
  17876.                     if (!$this->premode) {
  17877.                         $prelen strlen($dom[$key]['value']);
  17878.                         if ($this->isRTLTextDir() AND !$isRTLString) {
  17879.                             // right trim except non-breaking space
  17880.                             $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  17881.                         } else {
  17882.                             // left trim except non-breaking space
  17883.                             $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  17884.                         }
  17885.                         $postlen strlen($dom[$key]['value']);
  17886.                         if (($postlen == 0) AND ($prelen 0)) {
  17887.                             $dom[$key]['trimmed_space'] = true;
  17888.                         }
  17889.                     }
  17890.                     $newline false;
  17891.                     $firstblock true;
  17892.                 } else {
  17893.                     $firstblock false;
  17894.                     // replace empty multiple spaces string with a single space
  17895.                     $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  17896.                 }
  17897.                 $strrest '';
  17898.                 if ($this->rtl) {
  17899.                     $this->-= $this->textindent;
  17900.                 } else {
  17901.                     $this->+= $this->textindent;
  17902.                 }
  17903.                 if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  17904.                     $strlinelen $this->GetStringWidth($dom[$key]['value']);
  17905.                     if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  17906.                         // HTML <a> Link
  17907.                         $hrefcolor '';
  17908.                         if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  17909.                             $hrefcolor $dom[($dom[$key]['parent'])]['fgcolor'];
  17910.                         }
  17911.                         $hrefstyle = -1;
  17912.                         if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  17913.                             $hrefstyle $dom[($dom[$key]['parent'])]['fontstyle'];
  17914.                         }
  17915.                         $strrest $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfilltrue$hrefcolor$hrefstyletrue);
  17916.                     } else {
  17917.                         $wadj 0// space to leave for block continuity
  17918.                         if ($this->rtl) {
  17919.                             $cwa = ($this->$this->lMargin);
  17920.                         } else {
  17921.                             $cwa = ($this->$this->rMargin $this->x);
  17922.                         }
  17923.                         if (($strlinelen $cwa) AND (isset($dom[($key 1)])) AND ($dom[($key 1)]['tag']) AND (!$dom[($key 1)]['block'])) {
  17924.                             // check the next text blocks for continuity
  17925.                             $nkey = ($key 1);
  17926.                             $write_block true;
  17927.                             $same_textdir true;
  17928.                             $tmp_fontname $this->FontFamily;
  17929.                             $tmp_fontstyle $this->FontStyle;
  17930.                             $tmp_fontsize $this->FontSizePt;
  17931.                             while ($write_block AND isset($dom[$nkey])) {
  17932.                                 if ($dom[$nkey]['tag']) {
  17933.                                     if ($dom[$nkey]['block']) {
  17934.                                         // end of block
  17935.                                         $write_block false;
  17936.                                     }
  17937.                                     $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  17938.                                     $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  17939.                                     $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  17940.                                     $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  17941.                                 } else {
  17942.                                     $nextstr TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/'$this->re_space['m'], $dom[$nkey]['value']);
  17943.                                     if (isset($nextstr[0]) AND $same_textdir) {
  17944.                                         $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname$tmp_fontstyle$tmp_fontsize);
  17945.                                         if (isset($nextstr[1])) {
  17946.                                             $write_block false;
  17947.                                         }
  17948.                                     }
  17949.                                 }
  17950.                                 ++$nkey;
  17951.                             }
  17952.                         }
  17953.                         if (($wadj 0) AND (($strlinelen $wadj) >= $cwa)) {
  17954.                             $wadj 0;
  17955.                             $nextstr TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/'$this->re_space['m'], $dom[$key]['value']);
  17956.                             $numblks count($nextstr);
  17957.                             if ($numblks 1) {
  17958.                                 // try to split on blank spaces
  17959.                                 $wadj = ($cwa $strlinelen $this->GetStringWidth($nextstr[($numblks 1)]));
  17960.                             } else {
  17961.                                 // set the entire block on new line
  17962.                                 $wadj $this->GetStringWidth($nextstr[0]);
  17963.                             }
  17964.                         }
  17965.                         // check for reversed text direction
  17966.                         if (($wadj 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  17967.                             // LTR text on RTL direction or RTL text on LTR direction
  17968.                             $reverse_dir true;
  17969.                             $this->rtl = !$this->rtl;
  17970.                             $revshift = ($strlinelen $wadj 0.000001); // add little quantity for rounding problems
  17971.                             if ($this->rtl) {
  17972.                                 $this->+= $revshift;
  17973.                             } else {
  17974.                                 $this->-= $revshift;
  17975.                             }
  17976.                             $xws $this->x;
  17977.                         }
  17978.                         // ****** write only until the end of the line and get the rest ******
  17979.                         $strrest $this->Write($this->lasth$dom[$key]['value'], ''$wfill''false0true$firstblock0$wadj);
  17980.                         // restore default direction
  17981.                         if ($reverse_dir AND ($wadj == 0)) {
  17982.                             $this->$xws// @phpstan-ignore-line
  17983.                             $this->rtl = !$this->rtl;
  17984.                             $reverse_dir false;
  17985.                         }
  17986.                     }
  17987.                 }
  17988.                 $this->textindent 0;
  17989.                 if (strlen($strrest) > 0) {
  17990.                     // store the remaining string on the previous $key position
  17991.                     $this->newline true;
  17992.                     if ($strrest == $dom[$key]['value']) {
  17993.                         // used to avoid infinite loop
  17994.                         ++$loop;
  17995.                     } else {
  17996.                         $loop 0;
  17997.                     }
  17998.                     $dom[$key]['value'] = $strrest;
  17999.                     if ($cell) {
  18000.                         if ($this->rtl) {
  18001.                             $this->-= $this->cell_padding['R'];
  18002.                         } else {
  18003.                             $this->+= $this->cell_padding['L'];
  18004.                         }
  18005.                     }
  18006.                     if ($loop 3) {
  18007.                         --$key;
  18008.                     }
  18009.                 } else {
  18010.                     $loop 0;
  18011.                     // add the positive font spacing of the last character (if any)
  18012.                      if ($this->font_spacing 0) {
  18013.                          if ($this->rtl) {
  18014.                             $this->-= $this->font_spacing;
  18015.                         } else {
  18016.                             $this->+= $this->font_spacing;
  18017.                         }
  18018.                     }
  18019.                 }
  18020.             }
  18021.             ++$key;
  18022.             if (isset($dom[$key]['tag']) AND $dom[$key]['tag'] AND (!isset($dom[$key]['opening']) OR !$dom[$key]['opening']) AND isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  18023.                 // check if we are on a new page or on a new column
  18024.                 if ((!$undo) AND (($this->$this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  18025.                     // we are on a new page or on a new column and the total object height is less than the available vertical space.
  18026.                     // restore previous object
  18027.                     $this->rollbackTransaction(true);
  18028.                     // restore previous values
  18029.                     foreach ($this_method_vars as $vkey => $vval) {
  18030.                         $$vkey $vval;
  18031.                     }
  18032.                     if (!empty($dom[$key]['thead'])) {
  18033.                         $this->inthead true;
  18034.                     }
  18035.                     // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18036.                     $pre_y $this->y;
  18037.                     if ((!$this->checkPageBreak($this->PageBreakTrigger 1)) AND ($this->$pre_y)) {
  18038.                         $startliney $this->y;
  18039.                     }
  18040.                     $undo true// avoid infinite loop
  18041.                 } else {
  18042.                     $undo false;
  18043.                 }
  18044.             }
  18045.         } // end for each $key
  18046.         // align the last line
  18047.         if (isset($startlinex)) {
  18048.             $yshift = ($minstartliney $startliney);
  18049.             if (($yshift 0) OR ($this->page $startlinepage)) {
  18050.                 $yshift 0;
  18051.             }
  18052.             $t_x 0;
  18053.             // the last line must be shifted to be aligned as requested
  18054.             $linew abs($this->endlinex $startlinex);
  18055.             if ($this->inxobj) {
  18056.                 // we are inside an XObject template
  18057.                 $pstart substr($this->xobjects[$this->xobjid]['outdata'], 0$startlinepos);
  18058.                 if (isset($opentagpos)) {
  18059.                     $midpos $opentagpos;
  18060.                 } else {
  18061.                     $midpos 0;
  18062.                 }
  18063.                 if ($midpos 0) {
  18064.                     $pmid substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos $startlinepos));
  18065.                     $pend substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  18066.                 } else {
  18067.                     $pmid substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  18068.                     $pend '';
  18069.                 }
  18070.             } else {
  18071.                 $pstart substr($this->getPageBuffer($startlinepage), 0$startlinepos);
  18072.                 if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18073.                     $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18074.                     $midpos min($opentagpos$this->footerpos[$startlinepage]);
  18075.                 } elseif (isset($opentagpos)) {
  18076.                     $midpos $opentagpos;
  18077.                 } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  18078.                     $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  18079.                     $midpos $this->footerpos[$startlinepage];
  18080.                 } else {
  18081.                     $midpos 0;
  18082.                 }
  18083.                 if ($midpos 0) {
  18084.                     $pmid substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos $startlinepos));
  18085.                     $pend substr($this->getPageBuffer($startlinepage), $midpos);
  18086.                 } else {
  18087.                     $pmid substr($this->getPageBuffer($startlinepage), $startlinepos);
  18088.                     $pend '';
  18089.                 }
  18090.             }
  18091.             if ((((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  18092.                 // calculate shifting amount
  18093.                 $tw $w;
  18094.                 if ($this->lMargin != $prevlMargin) {
  18095.                     $tw += ($prevlMargin $this->lMargin);
  18096.                 }
  18097.                 if ($this->rMargin != $prevrMargin) {
  18098.                     $tw += ($prevrMargin $this->rMargin);
  18099.                 }
  18100.                 $one_space_width $this->GetStringWidth(chr(32));
  18101.                 $no 0// number of spaces on a line contained on a single block
  18102.                 if ($this->isRTLTextDir()) { // RTL
  18103.                     // remove left space if exist
  18104.                     $pos1 TCPDF_STATIC::revstrpos($pmid'[(');
  18105.                     if ($pos1 0) {
  18106.                         $pos1 intval($pos1);
  18107.                         if ($this->isUnicodeFont()) {
  18108.                             $pos2 intval(TCPDF_STATIC::revstrpos($pmid'[('.chr(0).chr(32)));
  18109.                             $spacelen 2;
  18110.                         } else {
  18111.                             $pos2 intval(TCPDF_STATIC::revstrpos($pmid'[('.chr(32)));
  18112.                             $spacelen 1;
  18113.                         }
  18114.                         if ($pos1 == $pos2) {
  18115.                             $pmid substr($pmid0, ($pos1 2)).substr($pmid, ($pos1 $spacelen));
  18116.                             if (substr($pmid$pos14) == '[()]') {
  18117.                                 $linew -= $one_space_width;
  18118.                             } elseif ($pos1 == strpos($pmid'[(')) {
  18119.                                 $no 1;
  18120.                             }
  18121.                         }
  18122.                     }
  18123.                 } else { // LTR
  18124.                     // remove right space if exist
  18125.                     $pos1 TCPDF_STATIC::revstrpos($pmid')]');
  18126.                     if ($pos1 0) {
  18127.                         $pos1 intval($pos1);
  18128.                         if ($this->isUnicodeFont()) {
  18129.                             $pos2 intval(TCPDF_STATIC::revstrpos($pmidchr(0).chr(32).')]')) + 2;
  18130.                             $spacelen 2;
  18131.                         } else {
  18132.                             $pos2 intval(TCPDF_STATIC::revstrpos($pmidchr(32).')]')) + 1;
  18133.                             $spacelen 1;
  18134.                         }
  18135.                         if ($pos1 == $pos2) {
  18136.                             $pmid substr($pmid0, ($pos1 $spacelen)).substr($pmid$pos1);
  18137.                             $linew -= $one_space_width;
  18138.                         }
  18139.                     }
  18140.                 }
  18141.                 $mdiff = ($tw $linew);
  18142.                 if ($plalign == 'C') {
  18143.                     if ($this->rtl) {
  18144.                         $t_x = -($mdiff 2);
  18145.                     } else {
  18146.                         $t_x = ($mdiff 2);
  18147.                     }
  18148.                 } elseif ($plalign == 'R') {
  18149.                     // right alignment on LTR document
  18150.                     $t_x $mdiff;
  18151.                 } elseif ($plalign == 'L') {
  18152.                     // left alignment on RTL document
  18153.                     $t_x = -$mdiff;
  18154.                 }
  18155.             } // end if startlinex
  18156.             if (($t_x != 0) OR ($yshift 0)) {
  18157.                 // shift the line
  18158.                 $trx sprintf('1 0 0 1 %F %F cm', ($t_x $this->k), ($yshift $this->k));
  18159.                 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  18160.                 $endlinepos strlen($pstart);
  18161.                 if ($this->inxobj) {
  18162.                     // we are inside an XObject template
  18163.                     $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  18164.                     foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  18165.                         if ($pak >= $pask) {
  18166.                             $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  18167.                             $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  18168.                         }
  18169.                     }
  18170.                 } else {
  18171.                     $this->setPageBuffer($startlinepage$pstart.$pend);
  18172.                     // shift the annotations and links
  18173.                     if (isset($this->PageAnnots[$this->page])) {
  18174.                         foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  18175.                             if ($pak >= $pask) {
  18176.                                 $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  18177.                                 $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  18178.                             }
  18179.                         }
  18180.                     }
  18181.                 }
  18182.                 $this->-= $yshift;
  18183.                 $yshift 0;
  18184.             }
  18185.         }
  18186.         // restore previous values
  18187.         $this->setGraphicVars($gvars);
  18188.         if ($this->num_columns 1) {
  18189.             $this->selectColumn();
  18190.         } elseif ($this->page $prevPage) {
  18191.             $this->lMargin $this->pagedim[$this->page]['olm'];
  18192.             $this->rMargin $this->pagedim[$this->page]['orm'];
  18193.         }
  18194.         // restore previous list state
  18195.         $this->cell_height_ratio $prev_cell_height_ratio;
  18196.         $this->listnum $prev_listnum;
  18197.         $this->listordered $prev_listordered;
  18198.         $this->listcount $prev_listcount;
  18199.         $this->lispacer $prev_lispacer;
  18200.         if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  18201.             $this->Ln($this->lasth);
  18202.             if (($this->$maxbottomliney) AND ($startlinepage == $this->page)) {
  18203.                 $this->$maxbottomliney;
  18204.             }
  18205.         }
  18206.         unset($dom);
  18207.     }
  18208.     /**
  18209.      * Process opening tags.
  18210.      * @param array $dom html dom array
  18211.      * @param int $key current element id
  18212.      * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  18213.      * @return array $dom
  18214.      * @protected
  18215.      */
  18216.     protected function openHTMLTagHandler($dom$key$cell) {
  18217.         $tag $dom[$key];
  18218.         $parent $dom[($dom[$key]['parent'])];
  18219.         $firsttag = ($key == 1);
  18220.         // check for text direction attribute
  18221.         if (isset($tag['dir'])) {
  18222.             $this->setTempRTL($tag['dir']);
  18223.         } else {
  18224.             $this->tmprtl false;
  18225.         }
  18226.         if ($tag['block']) {
  18227.             $hbz 0// distance from y to line bottom
  18228.             $hb 0// vertical space between block tags
  18229.             // calculate vertical space for block tags
  18230.             if (isset($this->tagvspaces[$tag['value']][0]['h']) && !empty($this->tagvspaces[$tag['value']][0]['h']) && ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  18231.                 $cur_h $this->tagvspaces[$tag['value']][0]['h'];
  18232.             } elseif (isset($tag['fontsize'])) {
  18233.                 $cur_h $this->getCellHeight($tag['fontsize'] / $this->k);
  18234.             } else {
  18235.                 $cur_h $this->getCellHeight($this->FontSize);
  18236.             }
  18237.             if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  18238.                 $on $this->tagvspaces[$tag['value']][0]['n'];
  18239.             } elseif (preg_match('/[h][0-9]/'$tag['value']) > 0) {
  18240.                 $on 0.6;
  18241.             } else {
  18242.                 $on 1;
  18243.             }
  18244.             if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div''dt''dd''li''br''hr')))) {
  18245.                 $hb 0;
  18246.             } else {
  18247.                 $hb = ($on $cur_h);
  18248.             }
  18249.             if (($this->htmlvspace <= 0) AND ($on 0)) {
  18250.                 if (isset($parent['fontsize'])) {
  18251.                     $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  18252.                 } else {
  18253.                     $hbz $this->getCellHeight($this->FontSize);
  18254.                 }
  18255.             }
  18256.             if (isset($dom[($key 1)]) AND ($dom[($key 1)]['value'] == 'table')) {
  18257.                 // fix vertical space after table
  18258.                 $hbz 0;
  18259.             }
  18260.             // closing vertical space
  18261.             $hbc 0;
  18262.             if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18263.                 $pre_h $this->tagvspaces[$tag['value']][1]['h'];
  18264.             } elseif (isset($parent['fontsize'])) {
  18265.                 $pre_h $this->getCellHeight($parent['fontsize'] / $this->k);
  18266.             } else {
  18267.                 $pre_h $this->getCellHeight($this->FontSize);
  18268.             }
  18269.             if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18270.                 $cn $this->tagvspaces[$tag['value']][1]['n'];
  18271.             } elseif (preg_match('/[h][0-9]/'$tag['value']) > 0) {
  18272.                 $cn 0.6;
  18273.             } else {
  18274.                 $cn 1;
  18275.             }
  18276.             if (isset($this->tagvspaces[$tag['value']][1])) {
  18277.                 $hbc = ($cn $pre_h);
  18278.             }
  18279.         }
  18280.         // Opening tag
  18281.         switch($tag['value']) {
  18282.             case 'table': {
  18283.                 $cp 0;
  18284.                 $cs 0;
  18285.                 $dom[$key]['rowspans'] = array();
  18286.                 if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  18287.                     $this->htmlvspace 0;
  18288.                     // set table header
  18289.                     if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  18290.                         // set table header
  18291.                         $this->thead $dom[$key]['thead'];
  18292.                         if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  18293.                             $this->theadMargins = array();
  18294.                             $this->theadMargins['cell_padding'] = $this->cell_padding;
  18295.                             $this->theadMargins['lmargin'] = $this->lMargin;
  18296.                             $this->theadMargins['rmargin'] = $this->rMargin;
  18297.                             $this->theadMargins['page'] = $this->page;
  18298.                             $this->theadMargins['cell'] = $cell;
  18299.                             $this->theadMargins['gvars'] = $this->getGraphicVars();
  18300.                         }
  18301.                     }
  18302.                 }
  18303.                 // store current margins and page
  18304.                 $dom[$key]['old_cell_padding'] = $this->cell_padding;
  18305.                 if (isset($tag['attribute']['cellpadding'])) {
  18306.                     $pad $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1'px');
  18307.                     $this->setCellPadding($pad);
  18308.                 } elseif (isset($tag['padding'])) {
  18309.                     $this->cell_padding $tag['padding'];
  18310.                 }
  18311.                 if (isset($tag['attribute']['cellspacing'])) {
  18312.                     $cs $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1'px');
  18313.                 } elseif (isset($tag['border-spacing'])) {
  18314.                     $cs $tag['border-spacing']['V'];
  18315.                 }
  18316.                 $prev_y $this->y;
  18317.                 if ($this->checkPageBreak((($cp) + ($cs) + $this->lasth), ''false) OR ($this->$prev_y)) {
  18318.                     $this->inthead true;
  18319.                     // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18320.                     $this->checkPageBreak($this->PageBreakTrigger 1);
  18321.                 }
  18322.                 break;
  18323.             }
  18324.             case 'tr': {
  18325.                 // array of columns positions
  18326.                 $dom[$key]['cellpos'] = array();
  18327.                 break;
  18328.             }
  18329.             case 'hr': {
  18330.                 if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18331.                     $hrHeight $this->getHTMLUnitToUnits($tag['height'], 1'px');
  18332.                 } else {
  18333.                     $hrHeight $this->GetLineWidth();
  18334.                 }
  18335.                 $this->addHTMLVertSpace($hbzmax($hb, ($hrHeight 2)), $cell$firsttag);
  18336.                 $x $this->GetX();
  18337.                 $y $this->GetY();
  18338.                 $wtmp $this->$this->lMargin $this->rMargin;
  18339.                 if ($cell) {
  18340.                     $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18341.                 }
  18342.                 if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18343.                     $hrWidth $this->getHTMLUnitToUnits($tag['width'], $wtmp'px');
  18344.                 } else {
  18345.                     $hrWidth $wtmp;
  18346.                 }
  18347.                 $prevlinewidth $this->GetLineWidth();
  18348.                 $this->setLineWidth($hrHeight);
  18349.                 $lineStyle = array();
  18350.                             if (isset($tag['fgcolor'])) {
  18351.                                 $lineStyle['color'] = $tag['fgcolor'];
  18352.                             }
  18353.                             if (isset($tag['fgcolor'])) {
  18354.                                 $lineStyle['color'] = $tag['fgcolor'];
  18355.                             }
  18356.                             if (isset($tag['style']['cap'])) {
  18357.                                 $lineStyle['cap'] = $tag['style']['cap'];
  18358.                             }
  18359.                             if (isset($tag['style']['join'])) {
  18360.                                 $lineStyle['join'] = $tag['style']['join'];
  18361.                             }
  18362.                             if (isset($tag['style']['dash'])) {
  18363.                                 $lineStyle['dash'] = $tag['style']['dash'];
  18364.                             }
  18365.                             if (isset($tag['style']['phase'])) {
  18366.                                 $lineStyle['phase'] = $tag['style']['phase'];
  18367.                             }
  18368.                 $lineStyle array_filter($lineStyle);
  18369.                 $this->Line($x$y$x $hrWidth$y$lineStyle);
  18370.                 $this->setLineWidth($prevlinewidth);
  18371.                 $this->addHTMLVertSpace(max($hbc, ($hrHeight 2)), 0$cell, !isset($dom[($key 1)]));
  18372.                 break;
  18373.             }
  18374.             case 'a': {
  18375.                 if (array_key_exists('href'$tag['attribute'])) {
  18376.                     $this->HREF['url'] = $tag['attribute']['href'];
  18377.                 }
  18378.                 break;
  18379.             }
  18380.             case 'img': {
  18381.                 if (empty($tag['attribute']['src'])) {
  18382.                     break;
  18383.                 }
  18384.                 $imgsrc $tag['attribute']['src'];
  18385.                 if ($imgsrc[0] === '@') {
  18386.                     // data stream
  18387.                     $imgsrc '@'.base64_decode(substr($imgsrc1));
  18388.                     $type '';
  18389.                 } else if (preg_match('@^data:image/([^;]*);base64,(.*)@'$imgsrc$reg)) {
  18390.                     $imgsrc '@'.base64_decode($reg[2]);
  18391.                     $type $reg[1];
  18392.                 } elseif ( $this->allowLocalFiles && substr($imgsrc07) === 'file://') {
  18393.                     // get image type from a local file path
  18394.                     $imgsrc substr($imgsrc7);
  18395.                     $type TCPDF_IMAGES::getImageFileType($imgsrc);
  18396.                 } else {
  18397.                     if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  18398.                         // fix image path
  18399.                         $findroot strpos($imgsrc$_SERVER['DOCUMENT_ROOT']);
  18400.                         if (($findroot === false) OR ($findroot 1)) {
  18401.                             if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  18402.                                 $imgsrc substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
  18403.                             } else {
  18404.                                 $imgsrc $_SERVER['DOCUMENT_ROOT'].$imgsrc;
  18405.                             }
  18406.                         }
  18407.                         $imgsrc urldecode($imgsrc);
  18408.                         $testscrtype = @parse_url($imgsrc);
  18409.                         if (empty($testscrtype['query'])) {
  18410.                             // convert URL to server path
  18411.                             $imgsrc str_replace(K_PATH_URLK_PATH_MAIN$imgsrc);
  18412.                         } elseif (preg_match('|^https?://|'$imgsrc) !== 1) {
  18413.                             // convert URL to server path
  18414.                             $imgsrc str_replace(K_PATH_MAINK_PATH_URL$imgsrc);
  18415.                         }
  18416.                     }
  18417.                     // get image type
  18418.                     $type TCPDF_IMAGES::getImageFileType($imgsrc);
  18419.                 }
  18420.                 if (!isset($tag['width'])) {
  18421.                     $tag['width'] = 0;
  18422.                 }
  18423.                 if (!isset($tag['height'])) {
  18424.                     $tag['height'] = 0;
  18425.                 }
  18426.                 //if (!isset($tag['attribute']['align'])) {
  18427.                     // the only alignment supported is "bottom"
  18428.                     // further development is required for other modes.
  18429.                     $tag['attribute']['align'] = 'bottom';
  18430.                 //}
  18431.                 switch($tag['attribute']['align']) {
  18432.                     case 'top': {
  18433.                         $align 'T';
  18434.                         break;
  18435.                     }
  18436.                     case 'middle': {
  18437.                         $align 'M';
  18438.                         break;
  18439.                     }
  18440.                     case 'bottom': {
  18441.                         $align 'B';
  18442.                         break;
  18443.                     }
  18444.                     default: {
  18445.                         $align 'B';
  18446.                         break;
  18447.                     }
  18448.                 }
  18449.                 $prevy $this->y;
  18450.                 $xpos $this->x;
  18451.                 $imglink '';
  18452.                 if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18453.                     $imglink $this->HREF['url'];
  18454.                     if ($imglink[0] == '#') {
  18455.                         // convert url to internal link
  18456.                         $lnkdata explode(','$imglink);
  18457.                         if (isset($lnkdata[0])) {
  18458.                             $page intval(substr($lnkdata[0], 1));
  18459.                             if (empty($page) OR ($page <= 0)) {
  18460.                                 $page $this->page;
  18461.                             }
  18462.                             if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18463.                                 $lnky floatval($lnkdata[1]);
  18464.                             } else {
  18465.                                 $lnky 0;
  18466.                             }
  18467.                             $imglink $this->AddLink();
  18468.                             $this->setLink($imglink$lnky$page);
  18469.                         }
  18470.                     }
  18471.                 }
  18472.                 $border 0;
  18473.                 if (isset($tag['border']) AND !empty($tag['border'])) {
  18474.                     // currently only support 1 (frame) or a combination of 'LTRB'
  18475.                     $border $tag['border'];
  18476.                 }
  18477.                 $iw '';
  18478.                 if (isset($tag['width'])) {
  18479.                     $iw $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px'false);
  18480.                 }
  18481.                 $ih '';
  18482.                 if (isset($tag['height'])) {
  18483.                     $ih $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px'false);
  18484.                 }
  18485.                 if (($type == 'eps') OR ($type == 'ai')) {
  18486.                     $this->ImageEps($imgsrc$xpos$this->y$iw$ih$imglinktrue$align''$bordertrue);
  18487.                 } elseif ($type == 'svg') {
  18488.                     $this->ImageSVG($imgsrc$xpos$this->y$iw$ih$imglink$align''$bordertrue);
  18489.                 } else {
  18490.                     $this->Image($imgsrc$xpos$this->y$iw$ih''$imglink$alignfalse300''falsefalse$borderfalsefalsetrue);
  18491.                 }
  18492.                 switch($align) {
  18493.                     case 'T': {
  18494.                         $this->$prevy;
  18495.                         break;
  18496.                     }
  18497.                     case 'M': {
  18498.                         $this->= (($this->img_rb_y $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2);
  18499.                         break;
  18500.                     }
  18501.                     case 'B': {
  18502.                         $this->$this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio));
  18503.                         break;
  18504.                     }
  18505.                 }
  18506.                 break;
  18507.             }
  18508.             case 'dl': {
  18509.                 ++$this->listnum;
  18510.                 if ($this->listnum == 1) {
  18511.                     $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18512.                 } else {
  18513.                     $this->addHTMLVertSpace(00$cell$firsttag);
  18514.                 }
  18515.                 break;
  18516.             }
  18517.             case 'dt': {
  18518.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18519.                 break;
  18520.             }
  18521.             case 'dd': {
  18522.                 if ($this->rtl) {
  18523.                     $this->rMargin += $this->listindent;
  18524.                 } else {
  18525.                     $this->lMargin += $this->listindent;
  18526.                 }
  18527.                 ++$this->listindentlevel;
  18528.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18529.                 break;
  18530.             }
  18531.             case 'ul':
  18532.             case 'ol': {
  18533.                 ++$this->listnum;
  18534.                 if ($tag['value'] == 'ol') {
  18535.                     $this->listordered[$this->listnum] = true;
  18536.                 } else {
  18537.                     $this->listordered[$this->listnum] = false;
  18538.                 }
  18539.                 if (isset($tag['attribute']['start'])) {
  18540.                     $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18541.                 } else {
  18542.                     $this->listcount[$this->listnum] = 0;
  18543.                 }
  18544.                 if ($this->rtl) {
  18545.                     $this->rMargin += $this->listindent;
  18546.                     $this->-= $this->listindent;
  18547.                 } else {
  18548.                     $this->lMargin += $this->listindent;
  18549.                     $this->+= $this->listindent;
  18550.                 }
  18551.                 ++$this->listindentlevel;
  18552.                 if ($this->listnum == 1) {
  18553.                     if ($key 1) {
  18554.                         $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18555.                     }
  18556.                 } else {
  18557.                     $this->addHTMLVertSpace(00$cell$firsttag);
  18558.                 }
  18559.                 break;
  18560.             }
  18561.             case 'li': {
  18562.                 if ($key 2) {
  18563.                     $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18564.                 }
  18565.                 if ($this->listordered[$this->listnum]) {
  18566.                     // ordered item
  18567.                     if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18568.                         $this->lispacer $parent['attribute']['type'];
  18569.                     } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18570.                         $this->lispacer $parent['listtype'];
  18571.                     } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18572.                         $this->lispacer $this->lisymbol;
  18573.                     } else {
  18574.                         $this->lispacer '#';
  18575.                     }
  18576.                     ++$this->listcount[$this->listnum];
  18577.                     if (isset($tag['attribute']['value'])) {
  18578.                         $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18579.                     }
  18580.                 } else {
  18581.                     // unordered item
  18582.                     if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18583.                         $this->lispacer $parent['attribute']['type'];
  18584.                     } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18585.                         $this->lispacer $parent['listtype'];
  18586.                     } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18587.                         $this->lispacer $this->lisymbol;
  18588.                     } else {
  18589.                         $this->lispacer '!';
  18590.                     }
  18591.                 }
  18592.                 break;
  18593.             }
  18594.             case 'blockquote': {
  18595.                 if ($this->rtl) {
  18596.                     $this->rMargin += $this->listindent;
  18597.                 } else {
  18598.                     $this->lMargin += $this->listindent;
  18599.                 }
  18600.                 ++$this->listindentlevel;
  18601.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18602.                 break;
  18603.             }
  18604.             case 'br': {
  18605.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18606.                 break;
  18607.             }
  18608.             case 'div': {
  18609.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18610.                 break;
  18611.             }
  18612.             case 'p': {
  18613.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18614.                 break;
  18615.             }
  18616.             case 'pre': {
  18617.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18618.                 $this->premode true;
  18619.                 break;
  18620.             }
  18621.             case 'sup': {
  18622.                 $this->setXY($this->GetX(), $this->GetY() - ((0.7 $this->FontSizePt) / $this->k));
  18623.                 break;
  18624.             }
  18625.             case 'sub': {
  18626.                 $this->setXY($this->GetX(), $this->GetY() + ((0.3 $this->FontSizePt) / $this->k));
  18627.                 break;
  18628.             }
  18629.             case 'h1':
  18630.             case 'h2':
  18631.             case 'h3':
  18632.             case 'h4':
  18633.             case 'h5':
  18634.             case 'h6': {
  18635.                 $this->addHTMLVertSpace($hbz$hb$cell$firsttag);
  18636.                 break;
  18637.             }
  18638.             // Form fields (since 4.8.000 - 2009-09-07)
  18639.             case 'form': {
  18640.                 if (isset($tag['attribute']['action'])) {
  18641.                     $this->form_action $tag['attribute']['action'];
  18642.                 } else {
  18643.                     $this->Error('Please explicitly set action attribute path!');
  18644.                 }
  18645.                 if (isset($tag['attribute']['enctype'])) {
  18646.                     $this->form_enctype $tag['attribute']['enctype'];
  18647.                 } else {
  18648.                     $this->form_enctype 'application/x-www-form-urlencoded';
  18649.                 }
  18650.                 if (isset($tag['attribute']['method'])) {
  18651.                     $this->form_mode $tag['attribute']['method'];
  18652.                 } else {
  18653.                     $this->form_mode 'post';
  18654.                 }
  18655.                 break;
  18656.             }
  18657.             case 'input': {
  18658.                 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18659.                     $name $tag['attribute']['name'];
  18660.                 } else {
  18661.                     break;
  18662.                 }
  18663.                 $prop = array();
  18664.                 $opt = array();
  18665.                 if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18666.                     $prop['readonly'] = true;
  18667.                 }
  18668.                 if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18669.                     $value $tag['attribute']['value'];
  18670.                 }
  18671.                 if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18672.                     $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18673.                 }
  18674.                 $h $this->getCellHeight($this->FontSize);
  18675.                 if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18676.                     $w intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18677.                 } else {
  18678.                     $w $h;
  18679.                 }
  18680.                 if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18681.                     $checked true;
  18682.                 } else {
  18683.                     $checked false;
  18684.                 }
  18685.                 if (isset($tag['align'])) {
  18686.                     switch ($tag['align']) {
  18687.                         case 'C': {
  18688.                             $opt['q'] = 1;
  18689.                             break;
  18690.                         }
  18691.                         case 'R': {
  18692.                             $opt['q'] = 2;
  18693.                             break;
  18694.                         }
  18695.                         case 'L':
  18696.                         default: {
  18697.                             break;
  18698.                         }
  18699.                     }
  18700.                 }
  18701.                 switch ($tag['attribute']['type']) {
  18702.                     case 'text': {
  18703.                         if (isset($value)) {
  18704.                             $opt['v'] = $value;
  18705.                         }
  18706.                         $this->TextField($name$w$h$prop$opt''''false);
  18707.                         break;
  18708.                     }
  18709.                     case 'password': {
  18710.                         if (isset($value)) {
  18711.                             $opt['v'] = $value;
  18712.                         }
  18713.                         $prop['password'] = 'true';
  18714.                         $this->TextField($name$w$h$prop$opt''''false);
  18715.                         break;
  18716.                     }
  18717.                     case 'checkbox': {
  18718.                         if (!isset($value)) {
  18719.                             break;
  18720.                         }
  18721.                         $this->CheckBox($name$w$checked$prop$opt$value''''false);
  18722.                         break;
  18723.                     }
  18724.                     case 'radio': {
  18725.                         if (!isset($value)) {
  18726.                             break;
  18727.                         }
  18728.                         $this->RadioButton($name$w$prop$opt$value$checked''''false);
  18729.                         break;
  18730.                     }
  18731.                     case 'submit': {
  18732.                         if (!isset($value)) {
  18733.                             $value 'submit';
  18734.                         }
  18735.                         $w $this->GetStringWidth($value) * 1.5;
  18736.                         $h *= 1.6;
  18737.                         $prop = array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196), 'strokeColor'=>array(255255255));
  18738.                         $action = array();
  18739.                         $action['S'] = 'SubmitForm';
  18740.                         $action['F'] = $this->form_action;
  18741.                         if ($this->form_enctype != 'FDF') {
  18742.                             $action['Flags'] = array('ExportFormat');
  18743.                         }
  18744.                         if ($this->form_mode == 'get') {
  18745.                             $action['Flags'] = array('GetMethod');
  18746.                         }
  18747.                         $this->Button($name$w$h$value$action$prop$opt''''false);
  18748.                         break;
  18749.                     }
  18750.                     case 'reset': {
  18751.                         if (!isset($value)) {
  18752.                             $value 'reset';
  18753.                         }
  18754.                         $w $this->GetStringWidth($value) * 1.5;
  18755.                         $h *= 1.6;
  18756.                         $prop = array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196), 'strokeColor'=>array(255255255));
  18757.                         $this->Button($name$w$h$value, array('S'=>'ResetForm'), $prop$opt''''false);
  18758.                         break;
  18759.                     }
  18760.                     case 'file': {
  18761.                         $prop['fileSelect'] = 'true';
  18762.                         $this->TextField($name$w$h$prop$opt''''false);
  18763.                         if (!isset($value)) {
  18764.                             $value '*';
  18765.                         }
  18766.                         $w $this->GetStringWidth($value) * 2;
  18767.                         $h *= 1.2;
  18768.                         $prop = array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196), 'strokeColor'=>array(255255255));
  18769.                         $jsaction 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  18770.                         $this->Button('FB_'.$name$w$h$value$jsaction$prop$opt''''false);
  18771.                         break;
  18772.                     }
  18773.                     case 'hidden': {
  18774.                         if (isset($value)) {
  18775.                             $opt['v'] = $value;
  18776.                         }
  18777.                         $opt['f'] = array('invisible''hidden');
  18778.                         $this->TextField($name00$prop$opt''''false);
  18779.                         break;
  18780.                     }
  18781.                     case 'image': {
  18782.                         // THIS TYPE MUST BE FIXED
  18783.                         if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  18784.                             $img $tag['attribute']['src'];
  18785.                         } else {
  18786.                             break;
  18787.                         }
  18788.                         $value 'img';
  18789.                         //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  18790.                         if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18791.                             $jsaction $tag['attribute']['onclick'];
  18792.                         } else {
  18793.                             $jsaction '';
  18794.                         }
  18795.                         $this->Button($name$w$h$value$jsaction$prop$opt''''false);
  18796.                         break;
  18797.                     }
  18798.                     case 'button': {
  18799.                         if (!isset($value)) {
  18800.                             $value ' ';
  18801.                         }
  18802.                         $w $this->GetStringWidth($value) * 1.5;
  18803.                         $h *= 1.6;
  18804.                         $prop = array('lineWidth'=>1'borderStyle'=>'beveled''fillColor'=>array(196196196), 'strokeColor'=>array(255255255));
  18805.                         if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18806.                             $jsaction $tag['attribute']['onclick'];
  18807.                         } else {
  18808.                             $jsaction '';
  18809.                         }
  18810.                         $this->Button($name$w$h$value$jsaction$prop$opt''''false);
  18811.                         break;
  18812.                     }
  18813.                 }
  18814.                 break;
  18815.             }
  18816.             case 'textarea': {
  18817.                 $prop = array();
  18818.                 $opt = array();
  18819.                 if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18820.                     $prop['readonly'] = true;
  18821.                 }
  18822.                 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18823.                     $name $tag['attribute']['name'];
  18824.                 } else {
  18825.                     break;
  18826.                 }
  18827.                 if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18828.                     $opt['v'] = $tag['attribute']['value'];
  18829.                 }
  18830.                 if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  18831.                     $w intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  18832.                 } else {
  18833.                     $w 40;
  18834.                 }
  18835.                 if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  18836.                     $h intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
  18837.                 } else {
  18838.                     $h 10;
  18839.                 }
  18840.                 $prop['multiline'] = 'true';
  18841.                 $this->TextField($name$w$h$prop$opt''''false);
  18842.                 break;
  18843.             }
  18844.             case 'select': {
  18845.                 $h $this->getCellHeight($this->FontSize);
  18846.                 if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18847.                     $h *= ($tag['attribute']['size'] + 1);
  18848.                 }
  18849.                 $prop = array();
  18850.                 $opt = array();
  18851.                 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18852.                     $name $tag['attribute']['name'];
  18853.                 } else {
  18854.                     break;
  18855.                 }
  18856.                 $w 0;
  18857.                 if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  18858.                     $options explode('#!NwL!#'$tag['attribute']['opt']);
  18859.                     $values = array();
  18860.                     foreach ($options as $val) {
  18861.                         if (strpos($val'#!TaB!#') !== false) {
  18862.                             $opts explode('#!TaB!#'$val);
  18863.                             $values[] = $opts;
  18864.                             $w max($w$this->GetStringWidth($opts[1]));
  18865.                         } else {
  18866.                             $values[] = $val;
  18867.                             $w max($w$this->GetStringWidth($val));
  18868.                         }
  18869.                     }
  18870.                 } else {
  18871.                     break;
  18872.                 }
  18873.                 $w *= 2;
  18874.                 if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  18875.                     $prop['multipleSelection'] = 'true';
  18876.                     $this->ListBox($name$w$h$values$prop$opt''''false);
  18877.                 } else {
  18878.                     $this->ComboBox($name$w$h$values$prop$opt''''false);
  18879.                 }
  18880.                 break;
  18881.             }
  18882.             case 'tcpdf': {
  18883.                 if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  18884.                     // Special tag used to call TCPDF methods
  18885.                     if (isset($tag['attribute']['method'])) {
  18886.                         $tcpdf_method $tag['attribute']['method'];
  18887.                         if (method_exists($this$tcpdf_method)) {
  18888.                             if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  18889.                                 $params $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
  18890.                                 call_user_func_array(array($this$tcpdf_method), $params);
  18891.                             } else {
  18892.                                 $this->$tcpdf_method();
  18893.                             }
  18894.                             $this->newline true;
  18895.                         }
  18896.                     }
  18897.                 }
  18898.                 break;
  18899.             }
  18900.             default: {
  18901.                 break;
  18902.             }
  18903.         }
  18904.         // define tags that support borders and background colors
  18905.         $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  18906.         if (in_array($tag['value'], $bordertags)) {
  18907.             // set border
  18908.             $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  18909.         }
  18910.         if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  18911.             $pba $dom[$key]['attribute']['pagebreakafter'];
  18912.             // check for pagebreak
  18913.             if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  18914.                 // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18915.                 $this->checkPageBreak($this->PageBreakTrigger 1);
  18916.             }
  18917.             if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page 2) == 0)) OR (($this->rtl) AND (($this->page 2) != 0))))
  18918.                 OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page 2) != 0)) OR (($this->rtl) AND (($this->page 2) == 0))))) {
  18919.                 // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18920.                 $this->checkPageBreak($this->PageBreakTrigger 1);
  18921.             }
  18922.         }
  18923.         return $dom;
  18924.     }
  18925.     /**
  18926.      * Process closing tags.
  18927.      * @param array $dom html dom array
  18928.      * @param int $key current element id
  18929.      * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  18930.      * @param int $maxbottomliney maximum y value of current line
  18931.      * @return array $dom
  18932.      * @protected
  18933.      */
  18934.     protected function closeHTMLTagHandler($dom$key$cell$maxbottomliney=0) {
  18935.         $tag $dom[$key];
  18936.         $parent $dom[($dom[$key]['parent'])];
  18937.         $lasttag = ((!isset($dom[($key 1)])) OR ((!isset($dom[($key 2)])) AND ($dom[($key 1)]['value'] == 'marker')));
  18938.         $in_table_head false;
  18939.         // maximum x position (used to draw borders)
  18940.         if ($this->rtl) {
  18941.             $xmax $this->w;
  18942.         } else {
  18943.             $xmax 0;
  18944.         }
  18945.         if ($tag['block']) {
  18946.             $hbz 0// distance from y to line bottom
  18947.             $hb 0// vertical space between block tags
  18948.             // calculate vertical space for block tags
  18949.             if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18950.                 $pre_h $this->tagvspaces[$tag['value']][1]['h'];
  18951.             } elseif (isset($parent['fontsize'])) {
  18952.                 $pre_h $this->getCellHeight($parent['fontsize'] / $this->k);
  18953.             } else {
  18954.                 $pre_h $this->getCellHeight($this->FontSize);
  18955.             }
  18956.             if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18957.                 $cn $this->tagvspaces[$tag['value']][1]['n'];
  18958.             } elseif (preg_match('/[h][0-9]/'$tag['value']) > 0) {
  18959.                 $cn 0.6;
  18960.             } else {
  18961.                 $cn 1;
  18962.             }
  18963.             if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  18964.                 $hb 0;
  18965.             } else {
  18966.                 $hb = ($cn $pre_h);
  18967.             }
  18968.             if ($maxbottomliney $this->PageBreakTrigger) {
  18969.                 $hbz $this->getCellHeight($this->FontSize);
  18970.             } elseif ($this->$maxbottomliney) {
  18971.                 $hbz = ($maxbottomliney $this->y);
  18972.             }
  18973.         }
  18974.         // Closing tag
  18975.         switch($tag['value']) {
  18976.             case 'tr': {
  18977.                 $table_el $dom[($dom[$key]['parent'])]['parent'];
  18978.                 if (!isset($parent['endy'])) {
  18979.                     $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  18980.                     $parent['endy'] = $this->y;
  18981.                 }
  18982.                 if (!isset($parent['endpage'])) {
  18983.                     $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  18984.                     $parent['endpage'] = $this->page;
  18985.                 }
  18986.                 if (!isset($parent['endcolumn'])) {
  18987.                     $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  18988.                     $parent['endcolumn'] = $this->current_column;
  18989.                 }
  18990.                 // update row-spanned cells
  18991.                 if (isset($dom[$table_el]['rowspans'])) {
  18992.                     foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18993.                         $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  18994.                         if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18995.                             if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  18996.                                 $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  18997.                             } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  18998.                                 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18999.                                 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  19000.                                 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  19001.                             }
  19002.                         }
  19003.                     }
  19004.                     // report new endy and endpage to the rowspanned cells
  19005.                     foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19006.                         if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19007.                             $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  19008.                             $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  19009.                             $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  19010.                             $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  19011.                             $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  19012.                             $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  19013.                         }
  19014.                     }
  19015.                     // update remaining rowspanned cells
  19016.                     foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  19017.                         if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  19018.                             $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  19019.                             $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  19020.                             $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  19021.                         }
  19022.                     }
  19023.                 }
  19024.                 $prev_page $this->page;
  19025.                 $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  19026.                 if ($this->num_columns 1) {
  19027.                     if (($prev_page $this->page)
  19028.                         AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns 1)))
  19029.                             OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) {
  19030.                         // page jump
  19031.                         $this->selectColumn(0);
  19032.                         $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
  19033.                         $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  19034.                     } else {
  19035.                         $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  19036.                         $this->$dom[($dom[$key]['parent'])]['endy'];
  19037.                     }
  19038.                 } else {
  19039.                     $this->$dom[($dom[$key]['parent'])]['endy'];
  19040.                 }
  19041.                 if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  19042.                     $this->+= $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1'px');
  19043.                 } elseif (isset($dom[$table_el]['border-spacing'])) {
  19044.                     $this->+= $dom[$table_el]['border-spacing']['V'];
  19045.                 }
  19046.                 $this->Ln(0$cell);
  19047.                 if ($this->current_column == $parent['startcolumn']) {
  19048.                     $this->$parent['startx'];
  19049.                 }
  19050.                 // account for booklet mode
  19051.                 if ($this->page $parent['startpage']) {
  19052.                     if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  19053.                         $this->-= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  19054.                     } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  19055.                         $this->+= ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  19056.                     }
  19057.                 }
  19058.                 break;
  19059.             }
  19060.             case 'tablehead':
  19061.                 // closing tag used for the thead part
  19062.                 $in_table_head true;
  19063.                 $this->inthead false;
  19064.             case 'table': {
  19065.                 $table_el $parent;
  19066.                 // set default border
  19067.                 if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  19068.                     // set default border
  19069.                     $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square''join'=>'miter''dash'=> 0'color'=>array(0,0,0)));
  19070.                 } else {
  19071.                     $border 0;
  19072.                 }
  19073.                 $default_border $border;
  19074.                 // fix bottom line alignment of last line before page break
  19075.                 foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  19076.                     // update row-spanned cells
  19077.                     if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19078.                         foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19079.                             if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  19080.                                 $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  19081.                             }
  19082.                             if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  19083.                                 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  19084.                             }
  19085.                         }
  19086.                     }
  19087.                     if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  19088.                         $pgendy $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  19089.                         $dom[$prevtrkey]['endy'] = $pgendy;
  19090.                         // update row-spanned cells
  19091.                         if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  19092.                             foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  19093.                                 if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  19094.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  19095.                                     $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  19096.                                 }
  19097.                             }
  19098.                         }
  19099.                     }
  19100.                     $prevtrkey $trkey;
  19101.                     $table_el $dom[($dom[$key]['parent'])];
  19102.                 }
  19103.                 // for each row
  19104.                 if (!empty($table_el['trids'])) {
  19105.                     unset($xmax);
  19106.                 }
  19107.                 foreach ($table_el['trids'] as $j => $trkey) {
  19108.                     $parent $dom[$trkey];
  19109.                     if (!isset($xmax)) {
  19110.                         $xmax $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  19111.                     }
  19112.                     // for each cell on the row
  19113.                     foreach ($parent['cellpos'] as $k => $cellpos) {
  19114.                         if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  19115.                             $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  19116.                             $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  19117.                             $endy $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  19118.                             $startpage $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  19119.                             $endpage $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  19120.                             $startcolumn $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  19121.                             $endcolumn $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  19122.                         } else {
  19123.                             $endy $parent['endy'];
  19124.                             $startpage $parent['startpage'];
  19125.                             $endpage $parent['endpage'];
  19126.                             $startcolumn $parent['startcolumn'];
  19127.                             $endcolumn $parent['endcolumn'];
  19128.                         }
  19129.                         if ($this->num_columns == 0) {
  19130.                             $this->num_columns 1;
  19131.                         }
  19132.                         if (isset($cellpos['border'])) {
  19133.                             $border $cellpos['border'];
  19134.                         }
  19135.                         if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  19136.                             $this->setFillColorArray($cellpos['bgcolor']);
  19137.                             $fill true;
  19138.                         } else {
  19139.                             $fill false;
  19140.                         }
  19141.                         $x $cellpos['startx'];
  19142.                         $y $parent['starty'];
  19143.                         $starty $y;
  19144.                         $w abs($cellpos['endx'] - $cellpos['startx']);
  19145.                         // get border modes
  19146.                         $border_start TCPDF_STATIC::getBorderMode($border$position='start'$this->opencell);
  19147.                         $border_end TCPDF_STATIC::getBorderMode($border$position='end'$this->opencell);
  19148.                         $border_middle TCPDF_STATIC::getBorderMode($border$position='middle'$this->opencell);
  19149.                         // design borders around HTML cells.
  19150.                         for ($page $startpage$page <= $endpage; ++$page) { // for each page
  19151.                             $ccode '';
  19152.                             $this->setPage($page);
  19153.                             if ($this->num_columns 2) {
  19154.                                 // single-column mode
  19155.                                 $this->$x;
  19156.                                 $this->$this->tMargin;
  19157.                             }
  19158.                             // account for margin changes
  19159.                             if ($page $startpage) {
  19160.                                 if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19161.                                     $this->-= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19162.                                 } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19163.                                     $this->+= ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19164.                                 }
  19165.                             }
  19166.                             if ($startpage == $endpage) { // single page
  19167.                                 $deltacol 0;
  19168.                                 $deltath 0;
  19169.                                 for ($column $startcolumn$column <= $endcolumn; ++$column) { // for each column
  19170.                                     $this->selectColumn($column);
  19171.                                     if ($startcolumn == $endcolumn) { // single column
  19172.                                         $cborder $border;
  19173.                                         $h $endy $parent['starty'];
  19174.                                         $this->$y;
  19175.                                         $this->$x;
  19176.                                     } elseif ($column == $startcolumn) { // first column
  19177.                                         $cborder $border_start;
  19178.                                         $this->$starty;
  19179.                                         $this->$x;
  19180.                                         $h $this->$this->$this->bMargin;
  19181.                                         if ($this->rtl) {
  19182.                                             $deltacol $this->$this->rMargin $this->w;
  19183.                                         } else {
  19184.                                             $deltacol $this->$this->lMargin;
  19185.                                         }
  19186.                                     } elseif ($column == $endcolumn) { // end column
  19187.                                         $cborder $border_end;
  19188.                                         if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19189.                                             $this->$this->columns[$column]['th']['\''.$page.'\''];
  19190.                                         }
  19191.                                         $this->+= $deltacol;
  19192.                                         $h $endy $this->y;
  19193.                                     } else { // middle column
  19194.                                         $cborder $border_middle;
  19195.                                         if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19196.                                             $this->$this->columns[$column]['th']['\''.$page.'\''];
  19197.                                         }
  19198.                                         $this->+= $deltacol;
  19199.                                         $h $this->$this->$this->bMargin;
  19200.                                     }
  19201.                                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19202.                                 } // end for each column
  19203.                             } elseif ($page == $startpage) { // first page
  19204.                                 $deltacol 0;
  19205.                                 $deltath 0;
  19206.                                 for ($column $startcolumn$column $this->num_columns; ++$column) { // for each column
  19207.                                     $this->selectColumn($column);
  19208.                                     if ($column == $startcolumn) { // first column
  19209.                                         $cborder $border_start;
  19210.                                         $this->$starty;
  19211.                                         $this->$x;
  19212.                                         $h $this->$this->$this->bMargin;
  19213.                                         if ($this->rtl) {
  19214.                                             $deltacol $this->$this->rMargin $this->w;
  19215.                                         } else {
  19216.                                             $deltacol $this->$this->lMargin;
  19217.                                         }
  19218.                                     } else { // middle column
  19219.                                         $cborder $border_middle;
  19220.                                         if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19221.                                             $this->$this->columns[$column]['th']['\''.$page.'\''];
  19222.                                         }
  19223.                                         $this->+= $deltacol;
  19224.                                         $h $this->$this->$this->bMargin;
  19225.                                     }
  19226.                                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19227.                                 } // end for each column
  19228.                             } elseif ($page == $endpage) { // last page
  19229.                                 $deltacol 0;
  19230.                                 $deltath 0;
  19231.                                 for ($column 0$column <= $endcolumn; ++$column) { // for each column
  19232.                                     $this->selectColumn($column);
  19233.                                     if ($column == $endcolumn) { // end column
  19234.                                         $cborder $border_end;
  19235.                                         if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19236.                                             $this->$this->columns[$column]['th']['\''.$page.'\''];
  19237.                                         }
  19238.                                         $this->+= $deltacol;
  19239.                                         $h $endy $this->y;
  19240.                                     } else { // middle column
  19241.                                         $cborder $border_middle;
  19242.                                         if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19243.                                             $this->$this->columns[$column]['th']['\''.$page.'\''];
  19244.                                         }
  19245.                                         $this->+= $deltacol;
  19246.                                         $h $this->$this->$this->bMargin;
  19247.                                     }
  19248.                                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19249.                                 } // end for each column
  19250.                             } else { // middle page
  19251.                                 $deltacol 0;
  19252.                                 $deltath 0;
  19253.                                 for ($column 0$column $this->num_columns; ++$column) { // for each column
  19254.                                     $this->selectColumn($column);
  19255.                                     $cborder $border_middle;
  19256.                                     if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  19257.                                         $this->$this->columns[$column]['th']['\''.$page.'\''];
  19258.                                     }
  19259.                                     $this->+= $deltacol;
  19260.                                     $h $this->$this->$this->bMargin;
  19261.                                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19262.                                 } // end for each column
  19263.                             }
  19264.                             if (!empty($cborder) OR !empty($fill)) {
  19265.                                 $offsetlen strlen($ccode);
  19266.                                 // draw border and fill
  19267.                                 if ($this->inxobj) {
  19268.                                     // we are inside an XObject template
  19269.                                     if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19270.                                         $pagemarkkey key($this->xobjects[$this->xobjid]['transfmrk']);
  19271.                                         $pagemark $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19272.                                         $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19273.                                     } else {
  19274.                                         $pagemark $this->xobjects[$this->xobjid]['intmrk'];
  19275.                                         $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19276.                                     }
  19277.                                     $pagebuff $this->xobjects[$this->xobjid]['outdata'];
  19278.                                     $pstart substr($pagebuff0$pagemark);
  19279.                                     $pend substr($pagebuff$pagemark);
  19280.                                     $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19281.                                 } else {
  19282.                                     // draw border and fill
  19283.                                     if (end($this->transfmrk[$this->page]) !== false) {
  19284.                                         $pagemarkkey key($this->transfmrk[$this->page]);
  19285.                                         $pagemark $this->transfmrk[$this->page][$pagemarkkey];
  19286.                                     } elseif ($this->InFooter) {
  19287.                                         $pagemark $this->footerpos[$this->page];
  19288.                                     } else {
  19289.                                         $pagemark $this->intmrk[$this->page];
  19290.                                     }
  19291.                                     $pagebuff $this->getPageBuffer($this->page);
  19292.                                     $pstart substr($pagebuff0$pagemark);
  19293.                                     $pend substr($pagebuff$pagemark);
  19294.                                     $this->setPageBuffer($this->page$pstart.$ccode.$pend);
  19295.                                 }
  19296.                             }
  19297.                         } // end for each page
  19298.                         // restore default border
  19299.                         $border $default_border;
  19300.                     } // end for each cell on the row
  19301.                     if (isset($table_el['attribute']['cellspacing'])) {
  19302.                         $this->+= $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1'px');
  19303.                     } elseif (isset($table_el['border-spacing'])) {
  19304.                         $this->+= $table_el['border-spacing']['V'];
  19305.                     }
  19306.                     $this->Ln(0$cell);
  19307.                     $this->$parent['startx'];
  19308.                     if ($endpage $startpage) {
  19309.                         if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19310.                             $this->+= ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  19311.                         } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19312.                             $this->+= ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  19313.                         }
  19314.                     }
  19315.                 }
  19316.                 if (!$in_table_head) { // we are not inside a thead section
  19317.                     $this->cell_padding = isset($table_el['old_cell_padding']) ? $table_el['old_cell_padding'] : null;
  19318.                     // reset row height
  19319.                     $this->resetLastH();
  19320.                     if (($this->page == ($this->numpages 1)) AND ($this->pageopen[$this->numpages])) {
  19321.                         $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  19322.                         if (($plendiff 0) AND ($plendiff 60)) {
  19323.                             $pagediff substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  19324.                             if (substr($pagediff05) == 'BT /F') {
  19325.                                 // the difference is only a font setting
  19326.                                 $plendiff 0;
  19327.                             }
  19328.                         }
  19329.                         if ($plendiff == 0) {
  19330.                             // remove last blank page
  19331.                             $this->deletePage($this->numpages);
  19332.                         }
  19333.                     }
  19334.                     if (isset($this->theadMargins['top'])) {
  19335.                         // restore top margin
  19336.                         $this->tMargin $this->theadMargins['top'];
  19337.                     }
  19338.                     if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  19339.                         // reset main table header
  19340.                         $this->thead '';
  19341.                         $this->theadMargins = array();
  19342.                         $this->pagedim[$this->page]['tm'] = $this->tMargin;
  19343.                     }
  19344.                 }
  19345.                 $parent $table_el;
  19346.                 break;
  19347.             }
  19348.             case 'a': {
  19349.                 $this->HREF = array();
  19350.                 break;
  19351.             }
  19352.             case 'sup': {
  19353.                 $this->setXY($this->GetX(), $this->GetY() + ((0.7 $parent['fontsize']) / $this->k));
  19354.                 break;
  19355.             }
  19356.             case 'sub': {
  19357.                 $this->setXY($this->GetX(), $this->GetY() - ((0.3 $parent['fontsize']) / $this->k));
  19358.                 break;
  19359.             }
  19360.             case 'div': {
  19361.                 $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19362.                 break;
  19363.             }
  19364.             case 'blockquote': {
  19365.                 if ($this->rtl) {
  19366.                     $this->rMargin -= $this->listindent;
  19367.                 } else {
  19368.                     $this->lMargin -= $this->listindent;
  19369.                 }
  19370.                 --$this->listindentlevel;
  19371.                 $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19372.                 break;
  19373.             }
  19374.             case 'p': {
  19375.                 $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19376.                 break;
  19377.             }
  19378.             case 'pre': {
  19379.                 $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19380.                 $this->premode false;
  19381.                 break;
  19382.             }
  19383.             case 'dl': {
  19384.                 --$this->listnum;
  19385.                 if ($this->listnum <= 0) {
  19386.                     $this->listnum 0;
  19387.                     $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19388.                 } else {
  19389.                     $this->addHTMLVertSpace(00$cellfalse$lasttag);
  19390.                 }
  19391.                 $this->resetLastH();
  19392.                 break;
  19393.             }
  19394.             case 'dt': {
  19395.                 $this->lispacer '';
  19396.                 $this->addHTMLVertSpace(00$cellfalse$lasttag);
  19397.                 break;
  19398.             }
  19399.             case 'dd': {
  19400.                 $this->lispacer '';
  19401.                 if ($this->rtl) {
  19402.                     $this->rMargin -= $this->listindent;
  19403.                 } else {
  19404.                     $this->lMargin -= $this->listindent;
  19405.                 }
  19406.                 --$this->listindentlevel;
  19407.                 $this->addHTMLVertSpace(00$cellfalse$lasttag);
  19408.                 break;
  19409.             }
  19410.             case 'ul':
  19411.             case 'ol': {
  19412.                 --$this->listnum;
  19413.                 $this->lispacer '';
  19414.                 if ($this->rtl) {
  19415.                     $this->rMargin -= $this->listindent;
  19416.                 } else {
  19417.                     $this->lMargin -= $this->listindent;
  19418.                 }
  19419.                 --$this->listindentlevel;
  19420.                 if ($this->listnum <= 0) {
  19421.                     $this->listnum 0;
  19422.                     $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19423.                 } else {
  19424.                     $this->addHTMLVertSpace(00$cellfalse$lasttag);
  19425.                 }
  19426.                 $this->resetLastH();
  19427.                 break;
  19428.             }
  19429.             case 'li': {
  19430.                 $this->lispacer '';
  19431.                 $this->addHTMLVertSpace(00$cellfalse$lasttag);
  19432.                 break;
  19433.             }
  19434.             case 'h1':
  19435.             case 'h2':
  19436.             case 'h3':
  19437.             case 'h4':
  19438.             case 'h5':
  19439.             case 'h6': {
  19440.                 $this->addHTMLVertSpace($hbz$hb$cellfalse$lasttag);
  19441.                 break;
  19442.             }
  19443.             // Form fields (since 4.8.000 - 2009-09-07)
  19444.             case 'form': {
  19445.                 $this->form_action '';
  19446.                 $this->form_enctype 'application/x-www-form-urlencoded';
  19447.                 break;
  19448.             }
  19449.             default : {
  19450.                 break;
  19451.             }
  19452.         }
  19453.         // draw border and background (if any)
  19454.         $this->drawHTMLTagBorder($parent$xmax);
  19455.         if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19456.             $pba $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19457.             // check for pagebreak
  19458.             if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19459.                 // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19460.                 $this->checkPageBreak($this->PageBreakTrigger 1);
  19461.             }
  19462.             if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page 2) == 0)) OR (($this->rtl) AND (($this->page 2) != 0))))
  19463.                 OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page 2) != 0)) OR (($this->rtl) AND (($this->page 2) == 0))))) {
  19464.                 // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19465.                 $this->checkPageBreak($this->PageBreakTrigger 1);
  19466.             }
  19467.         }
  19468.         $this->tmprtl false;
  19469.         return $dom;
  19470.     }
  19471.     /**
  19472.      * Add vertical spaces if needed.
  19473.      * @param string $hbz Distance between current y and line bottom.
  19474.      * @param string $hb The height of the break.
  19475.      * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  19476.      * @param boolean $firsttag set to true when the tag is the first.
  19477.      * @param boolean $lasttag set to true when the tag is the last.
  19478.      * @protected
  19479.      */
  19480.     protected function addHTMLVertSpace($hbz=0$hb=0$cell=false$firsttag=false$lasttag=false) {
  19481.         if ($firsttag) {
  19482.             $this->Ln(0$cell);
  19483.             $this->htmlvspace 0;
  19484.             return;
  19485.         }
  19486.         if ($lasttag) {
  19487.             $this->Ln($hbz$cell);
  19488.             $this->htmlvspace 0;
  19489.             return;
  19490.         }
  19491.         if ($hb $this->htmlvspace) {
  19492.             $hd 0;
  19493.         } else {
  19494.             $hd $hb $this->htmlvspace;
  19495.             $this->htmlvspace $hb;
  19496.         }
  19497.         $this->Ln(($hbz $hd), $cell);
  19498.     }
  19499.     /**
  19500.      * Return the starting coordinates to draw an html border
  19501.      * @return array containing top-left border coordinates
  19502.      * @protected
  19503.      * @since 5.7.000 (2010-08-03)
  19504.      */
  19505.     protected function getBorderStartPosition() {
  19506.         if ($this->rtl) {
  19507.             $xmax $this->lMargin;
  19508.         } else {
  19509.             $xmax $this->$this->rMargin;
  19510.         }
  19511.         return array('page' => $this->page'column' => $this->current_column'x' => $this->x'y' => $this->y'xmax' => $xmax);
  19512.     }
  19513.     /**
  19514.      * Draw an HTML block border and fill
  19515.      * @param array $tag array of tag properties.
  19516.      * @param int $xmax end X coordinate for border.
  19517.      * @protected
  19518.      * @since 5.7.000 (2010-08-03)
  19519.      */
  19520.     protected function drawHTMLTagBorder($tag$xmax) {
  19521.         if (!isset($tag['borderposition'])) {
  19522.             // nothing to draw
  19523.             return;
  19524.         }
  19525.         $prev_x $this->x;
  19526.         $prev_y $this->y;
  19527.         $prev_lasth $this->lasth;
  19528.         $border 0;
  19529.         $fill false;
  19530.         $this->lasth 0;
  19531.         if (isset($tag['border']) AND !empty($tag['border'])) {
  19532.             // get border style
  19533.             $border $tag['border'];
  19534.             if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19535.                 // border for table header
  19536.                 $border TCPDF_STATIC::getBorderMode($border$position='middle'$this->opencell);
  19537.             }
  19538.         }
  19539.         if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19540.             // get background color
  19541.             $old_bgcolor $this->bgcolor;
  19542.             $this->setFillColorArray($tag['bgcolor']);
  19543.             $fill true;
  19544.         }
  19545.         if (!$border AND !$fill) {
  19546.             // nothing to draw
  19547.             return;
  19548.         }
  19549.         if (isset($tag['attribute']['cellspacing'])) {
  19550.             $clsp $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1'px');
  19551.             $cellspacing = array('H' => $clsp'V' => $clsp);
  19552.         } elseif (isset($tag['border-spacing'])) {
  19553.             $cellspacing $tag['border-spacing'];
  19554.         } else {
  19555.             $cellspacing = array('H' => 0'V' => 0);
  19556.         }
  19557.         if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19558.             // draw the border externally respect the sqare edge.
  19559.             $border['mode'] = 'ext';
  19560.         }
  19561.         if ($this->rtl) {
  19562.             if ($xmax >= $tag['borderposition']['x']) {
  19563.                 $xmax $tag['borderposition']['xmax'];
  19564.             }
  19565.             $w = ($tag['borderposition']['x'] - $xmax);
  19566.         } else {
  19567.             if ($xmax <= $tag['borderposition']['x']) {
  19568.                 $xmax $tag['borderposition']['xmax'];
  19569.             }
  19570.             $w = ($xmax $tag['borderposition']['x']);
  19571.         }
  19572.         if ($w <= 0) {
  19573.             return;
  19574.         }
  19575.         $w += $cellspacing['H'];
  19576.         $startpage $tag['borderposition']['page'];
  19577.         $startcolumn $tag['borderposition']['column'];
  19578.         $x $tag['borderposition']['x'];
  19579.         $y $tag['borderposition']['y'];
  19580.         $endpage $this->page;
  19581.         $starty $tag['borderposition']['y'] - $cellspacing['V'];
  19582.         $currentY $this->y;
  19583.         $this->$x;
  19584.         // get latest column
  19585.         $endcolumn $this->current_column;
  19586.         if ($this->num_columns == 0) {
  19587.             $this->num_columns 1;
  19588.         }
  19589.         // get border modes
  19590.         $border_start TCPDF_STATIC::getBorderMode($border$position='start'$this->opencell);
  19591.         $border_end TCPDF_STATIC::getBorderMode($border$position='end'$this->opencell);
  19592.         $border_middle TCPDF_STATIC::getBorderMode($border$position='middle'$this->opencell);
  19593.         // temporary disable page regions
  19594.         $temp_page_regions $this->page_regions;
  19595.         $this->page_regions = array();
  19596.         // design borders around HTML cells.
  19597.         for ($page $startpage$page <= $endpage; ++$page) { // for each page
  19598.             $ccode '';
  19599.             $this->setPage($page);
  19600.             if ($this->num_columns 2) {
  19601.                 // single-column mode
  19602.                 $this->$x;
  19603.                 $this->$this->tMargin;
  19604.             }
  19605.             // account for margin changes
  19606.             if ($page $startpage) {
  19607.                 if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19608.                     $this->-= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19609.                 } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19610.                     $this->+= ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19611.                 }
  19612.             }
  19613.             if ($startpage == $endpage) {
  19614.                 // single page
  19615.                 for ($column $startcolumn$column <= $endcolumn; ++$column) { // for each column
  19616.                     $this->selectColumn($column);
  19617.                     if ($startcolumn == $endcolumn) { // single column
  19618.                         $cborder $border;
  19619.                         $h = ($currentY $y) + $cellspacing['V'];
  19620.                         $this->$starty;
  19621.                     } elseif ($column == $startcolumn) { // first column
  19622.                         $cborder $border_start;
  19623.                         $this->$starty;
  19624.                         $h $this->$this->$this->bMargin;
  19625.                     } elseif ($column == $endcolumn) { // end column
  19626.                         $cborder $border_end;
  19627.                         $h $currentY $this->y;
  19628.                     } else { // middle column
  19629.                         $cborder $border_middle;
  19630.                         $h $this->$this->$this->bMargin;
  19631.                     }
  19632.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19633.                 } // end for each column
  19634.             } elseif ($page == $startpage) { // first page
  19635.                 for ($column $startcolumn$column $this->num_columns; ++$column) { // for each column
  19636.                     $this->selectColumn($column);
  19637.                     if ($column == $startcolumn) { // first column
  19638.                         $cborder $border_start;
  19639.                         $this->$starty;
  19640.                         $h $this->$this->$this->bMargin;
  19641.                     } else { // middle column
  19642.                         $cborder $border_middle;
  19643.                         $h $this->$this->$this->bMargin;
  19644.                     }
  19645.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19646.                 } // end for each column
  19647.             } elseif ($page == $endpage) { // last page
  19648.                 for ($column 0$column <= $endcolumn; ++$column) { // for each column
  19649.                     $this->selectColumn($column);
  19650.                     if ($column == $endcolumn) {
  19651.                         // end column
  19652.                         $cborder $border_end;
  19653.                         $h $currentY $this->y;
  19654.                     } else {
  19655.                         // middle column
  19656.                         $cborder $border_middle;
  19657.                         $h $this->$this->$this->bMargin;
  19658.                     }
  19659.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19660.                 } // end for each column
  19661.             } else { // middle page
  19662.                 for ($column 0$column $this->num_columns; ++$column) { // for each column
  19663.                     $this->selectColumn($column);
  19664.                     $cborder $border_middle;
  19665.                     $h $this->$this->$this->bMargin;
  19666.                     $ccode .= $this->getCellCode($w$h''$cborder1''$fill''0true)."\n";
  19667.                 } // end for each column
  19668.             }
  19669.             if ($cborder OR $fill) {
  19670.                 $offsetlen strlen($ccode);
  19671.                 // draw border and fill
  19672.                 if ($this->inxobj) {
  19673.                     // we are inside an XObject template
  19674.                     if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19675.                         $pagemarkkey key($this->xobjects[$this->xobjid]['transfmrk']);
  19676.                         $pagemark $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19677.                         $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19678.                     } else {
  19679.                         $pagemark $this->xobjects[$this->xobjid]['intmrk'];
  19680.                         $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19681.                     }
  19682.                     $pagebuff $this->xobjects[$this->xobjid]['outdata'];
  19683.                     $pstart substr($pagebuff0$pagemark);
  19684.                     $pend substr($pagebuff$pagemark);
  19685.                     $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19686.                 } else {
  19687.                     if (end($this->transfmrk[$this->page]) !== false) {
  19688.                         $pagemarkkey key($this->transfmrk[$this->page]);
  19689.                         $pagemark $this->transfmrk[$this->page][$pagemarkkey];
  19690.                     } elseif ($this->InFooter) {
  19691.                         $pagemark $this->footerpos[$this->page];
  19692.                     } else {
  19693.                         $pagemark $this->intmrk[$this->page];
  19694.                     }
  19695.                     $pagebuff $this->getPageBuffer($this->page);
  19696.                     $pstart substr($pagebuff0$pagemark);
  19697.                     $pend substr($pagebuff$pagemark);
  19698.                     $this->setPageBuffer($this->page$pstart.$ccode.$pend);
  19699.                     $this->bordermrk[$this->page] += $offsetlen;
  19700.                     $this->cntmrk[$this->page] += $offsetlen;
  19701.                 }
  19702.             }
  19703.         } // end for each page
  19704.         // restore page regions
  19705.         $this->page_regions $temp_page_regions;
  19706.         if (isset($old_bgcolor)) {
  19707.             // restore background color
  19708.             $this->setFillColorArray($old_bgcolor);
  19709.         }
  19710.         // restore pointer position
  19711.         $this->$prev_x;
  19712.         $this->$prev_y;
  19713.         $this->lasth $prev_lasth;
  19714.     }
  19715.     /**
  19716.      * Set the default bullet to be used as LI bullet symbol
  19717.      * @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', 'img|type|width|height|image.ext')
  19718.      * @public
  19719.      * @since 4.0.028 (2008-09-26)
  19720.      */
  19721.     public function setLIsymbol($symbol='!') {
  19722.         // check for custom image symbol
  19723.         if (substr($symbol04) == 'img|') {
  19724.             $this->lisymbol $symbol;
  19725.             return;
  19726.         }
  19727.         $symbol strtolower($symbol);
  19728.         $valid_symbols = array('!''#''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');
  19729.         if (in_array($symbol$valid_symbols)) {
  19730.             $this->lisymbol $symbol;
  19731.         } else {
  19732.             $this->lisymbol '';
  19733.         }
  19734.     }
  19735.     /**
  19736.      * Set the booklet mode for double-sided pages.
  19737.      * @param boolean $booklet true set the booklet mode on, false otherwise.
  19738.      * @param float $inner Inner page margin.
  19739.      * @param float $outer Outer page margin.
  19740.      * @public
  19741.      * @since 4.2.000 (2008-10-29)
  19742.      */
  19743.     public function setBooklet($booklet=true$inner=-1$outer=-1) {
  19744.         $this->booklet $booklet;
  19745.         if ($inner >= 0) {
  19746.             $this->lMargin $inner;
  19747.         }
  19748.         if ($outer >= 0) {
  19749.             $this->rMargin $outer;
  19750.         }
  19751.     }
  19752.     /**
  19753.      * Swap the left and right margins.
  19754.      * @param boolean $reverse if true swap left and right margins.
  19755.      * @protected
  19756.      * @since 4.2.000 (2008-10-29)
  19757.      */
  19758.     protected function swapMargins($reverse=true) {
  19759.         if ($reverse) {
  19760.             // swap left and right margins
  19761.             $mtemp $this->original_lMargin;
  19762.             $this->original_lMargin $this->original_rMargin;
  19763.             $this->original_rMargin $mtemp;
  19764.             $deltam $this->original_lMargin $this->original_rMargin;
  19765.             $this->lMargin += $deltam;
  19766.             $this->rMargin -= $deltam;
  19767.         }
  19768.     }
  19769.     /**
  19770.      * Set the vertical spaces for HTML tags.
  19771.      * The array must have the following structure (example):
  19772.      * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  19773.      * The first array level contains the tag names,
  19774.      * the second level contains 0 for opening tags or 1 for closing tags,
  19775.      * the third level contains the vertical space unit (h) and the number spaces to add (n).
  19776.      * If the h parameter is not specified, default values are used.
  19777.      * @param array $tagvs array of tags and relative vertical spaces.
  19778.      * @public
  19779.      * @since 4.2.001 (2008-10-30)
  19780.      */
  19781.     public function setHtmlVSpace($tagvs) {
  19782.         $this->tagvspaces $tagvs;
  19783.     }
  19784.     /**
  19785.      * Set custom width for list indentation.
  19786.      * @param float $width width of the indentation. Use negative value to disable it.
  19787.      * @public
  19788.      * @since 4.2.007 (2008-11-12)
  19789.      */
  19790.     public function setListIndentWidth($width) {
  19791.         return $this->customlistindent floatval($width);
  19792.     }
  19793.     /**
  19794.      * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  19795.      * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  19796.      * @public
  19797.      * @since 4.2.010 (2008-11-14)
  19798.      */
  19799.     public function setOpenCell($isopen) {
  19800.         $this->opencell $isopen;
  19801.     }
  19802.     /**
  19803.      * Set the color and font style for HTML links.
  19804.      * @param array $color RGB array of colors
  19805.      * @param string $fontstyle additional font styles to add
  19806.      * @public
  19807.      * @since 4.4.003 (2008-12-09)
  19808.      */
  19809.     public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  19810.         $this->htmlLinkColorArray $color;
  19811.         $this->htmlLinkFontStyle $fontstyle;
  19812.     }
  19813.     /**
  19814.      * Convert HTML string containing value and unit of measure to user's units or points.
  19815.      * @param string $htmlval String containing values and unit.
  19816.      * @param string $refsize Reference value in points.
  19817.      * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  19818.      * @param boolean $points If true returns points, otherwise returns value in user's units.
  19819.      * @return float value in user's unit or point if $points=true
  19820.      * @public
  19821.      * @since 4.4.004 (2008-12-10)
  19822.      */
  19823.     public function getHTMLUnitToUnits($htmlval$refsize=1$defaultunit='px'$points=false) {
  19824.         $supportedunits = array('%''em''ex''px''in''cm''mm''pc''pt');
  19825.         $retval 0;
  19826.         $value 0;
  19827.         $unit 'px';
  19828.         if ($points) {
  19829.             $k 1;
  19830.         } else {
  19831.             $k $this->k;
  19832.         }
  19833.         if (in_array($defaultunit$supportedunits)) {
  19834.             $unit $defaultunit;
  19835.         }
  19836.         if (is_numeric($htmlval)) {
  19837.             $value floatval($htmlval);
  19838.         } elseif (preg_match('/([0-9\.\-\+]+)/'$htmlval$mnum)) {
  19839.             $value floatval($mnum[1]);
  19840.             if (preg_match('/([a-z%]+)/'$htmlval$munit)) {
  19841.                 if (in_array($munit[1], $supportedunits)) {
  19842.                     $unit $munit[1];
  19843.                 }
  19844.             }
  19845.         }
  19846.         switch ($unit) {
  19847.             // percentage
  19848.             case '%': {
  19849.                 $retval = (($value $refsize) / 100);
  19850.                 break;
  19851.             }
  19852.             // relative-size
  19853.             case 'em': {
  19854.                 $retval = ($value $refsize);
  19855.                 break;
  19856.             }
  19857.             // height of lower case 'x' (about half the font-size)
  19858.             case 'ex': {
  19859.                 $retval = ($value * ($refsize 2));
  19860.                 break;
  19861.             }
  19862.             // absolute-size
  19863.             case 'in': {
  19864.                 $retval = (($value $this->dpi) / $k);
  19865.                 break;
  19866.             }
  19867.             // centimeters
  19868.             case 'cm': {
  19869.                 $retval = (($value 2.54 $this->dpi) / $k);
  19870.                 break;
  19871.             }
  19872.             // millimeters
  19873.             case 'mm': {
  19874.                 $retval = (($value 25.4 $this->dpi) / $k);
  19875.                 break;
  19876.             }
  19877.             // one pica is 12 points
  19878.             case 'pc': {
  19879.                 $retval = (($value 12) / $k);
  19880.                 break;
  19881.             }
  19882.             // points
  19883.             case 'pt': {
  19884.                 $retval = ($value $k);
  19885.                 break;
  19886.             }
  19887.             // pixels
  19888.             case 'px': {
  19889.                 $retval $this->pixelsToUnits($value);
  19890.                 if ($points) {
  19891.                     $retval *= $this->k;
  19892.                 }
  19893.                 break;
  19894.             }
  19895.         }
  19896.         return $retval;
  19897.     }
  19898.     /**
  19899.      * Output an HTML list bullet or ordered item symbol
  19900.      * @param int $listdepth list nesting level
  19901.      * @param string $listtype type of list
  19902.      * @param float $size current font size
  19903.      * @protected
  19904.      * @since 4.4.004 (2008-12-10)
  19905.      */
  19906.     protected function putHtmlListBullet($listdepth$listtype=''$size=10) {
  19907.         if ($this->state != 2) {
  19908.             return;
  19909.         }
  19910.         $size /= $this->k;
  19911.         $fill '';
  19912.         $bgcolor $this->bgcolor;
  19913.         $color $this->fgcolor;
  19914.         $strokecolor $this->strokecolor;
  19915.         $width 0;
  19916.         $textitem '';
  19917.         $tmpx $this->x;
  19918.         $lspace $this->GetStringWidth('  ');
  19919.         if ($listtype == '^') {
  19920.             // special symbol used for avoid justification of rect bullet
  19921.             $this->lispacer '';
  19922.             return;
  19923.         } elseif ($listtype == '!') {
  19924.             // set default list type for unordered list
  19925.             $deftypes = array('disc''circle''square');
  19926.             $listtype $deftypes[($listdepth 1) % 3];
  19927.         } elseif ($listtype == '#') {
  19928.             // set default list type for ordered list
  19929.             $listtype 'decimal';
  19930.         } elseif (substr($listtype04) == 'img|') {
  19931.             // custom image type ('img|type|width|height|image.ext')
  19932.             $img explode('|'$listtype);
  19933.             $listtype 'img';
  19934.         }
  19935.         switch ($listtype) {
  19936.             // unordered types
  19937.             case 'none': {
  19938.                 break;
  19939.             }
  19940.             case 'disc': {
  19941.                 $r $size 6;
  19942.                 $lspace += ($r);
  19943.                 if ($this->rtl) {
  19944.                     $this->+= $lspace;
  19945.                 } else {
  19946.                     $this->-= $lspace;
  19947.                 }
  19948.                 $this->Circle(($this->$r), ($this->+ ($this->lasth 2)), $r0360'F', array(), $color8);
  19949.                 break;
  19950.             }
  19951.             case 'circle': {
  19952.                 $r $size 6;
  19953.                 $lspace += ($r);
  19954.                 if ($this->rtl) {
  19955.                     $this->+= $lspace;
  19956.                 } else {
  19957.                     $this->-= $lspace;
  19958.                 }
  19959.                 $prev_line_style $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  19960.                 $new_line_style = array('width' => ($r 3), 'cap' => 'butt''join' => 'miter''dash' => 0'phase' => 0'color'=>$color);
  19961.                 $this->Circle(($this->$r), ($this->+ ($this->lasth 2)), ($r * (- (1/6))), 0360'D'$new_line_style, array(), 8);
  19962.                 $this->_out($prev_line_style); // restore line settings
  19963.                 break;
  19964.             }
  19965.             case 'square': {
  19966.                 $l $size 3;
  19967.                 $lspace += $l;
  19968.                 if ($this->rtl) {;
  19969.                     $this->+= $lspace;
  19970.                 } else {
  19971.                     $this->-= $lspace;
  19972.                 }
  19973.                 $this->Rect($this->x, ($this->+ (($this->lasth $l) / 2)), $l$l'F', array(), $color);
  19974.                 break;
  19975.             }
  19976.             case 'img': {
  19977.                 // 1=>type, 2=>width, 3=>height, 4=>image.ext
  19978.                 $lspace += $img[2];
  19979.                 if ($this->rtl) {;
  19980.                     $this->+= $lspace;
  19981.                 } else {
  19982.                     $this->-= $lspace;
  19983.                 }
  19984.                 $imgtype strtolower($img[1]);
  19985.                 $prev_y $this->y;
  19986.                 switch ($imgtype) {
  19987.                     case 'svg': {
  19988.                         $this->ImageSVG($img[4], $this->x, ($this->+ (($this->lasth $img[3]) / 2)), $img[2], $img[3], '''T'''0false);
  19989.                         break;
  19990.                     }
  19991.                     case 'ai':
  19992.                     case 'eps': {
  19993.                         $this->ImageEps($img[4], $this->x, ($this->+ (($this->lasth $img[3]) / 2)), $img[2], $img[3], ''true'T'''0false);
  19994.                         break;
  19995.                     }
  19996.                     default: {
  19997.                         $this->Image($img[4], $this->x, ($this->+ (($this->lasth $img[3]) / 2)), $img[2], $img[3], $img[1], '''T'false300''falsefalse0falsefalsefalse);
  19998.                         break;
  19999.                     }
  20000.                 }
  20001.                 $this->$prev_y;
  20002.                 break;
  20003.             }
  20004.             // ordered types
  20005.             // $this->listcount[$this->listnum];
  20006.             // $textitem
  20007.             case '1':
  20008.             case 'decimal': {
  20009.                 $textitem $this->listcount[$this->listnum];
  20010.                 break;
  20011.             }
  20012.             case 'decimal-leading-zero': {
  20013.                 $textitem sprintf('%02d'$this->listcount[$this->listnum]);
  20014.                 break;
  20015.             }
  20016.             case 'i':
  20017.             case 'lower-roman': {
  20018.                 $textitem strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  20019.                 break;
  20020.             }
  20021.             case 'I':
  20022.             case 'upper-roman': {
  20023.                 $textitem TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  20024.                 break;
  20025.             }
  20026.             case 'a':
  20027.             case 'lower-alpha':
  20028.             case 'lower-latin': {
  20029.                 $textitem chr(97 $this->listcount[$this->listnum] - 1);
  20030.                 break;
  20031.             }
  20032.             case 'A':
  20033.             case 'upper-alpha':
  20034.             case 'upper-latin': {
  20035.                 $textitem chr(65 $this->listcount[$this->listnum] - 1);
  20036.                 break;
  20037.             }
  20038.             case 'lower-greek': {
  20039.                 $textitem TCPDF_FONTS::unichr((945 $this->listcount[$this->listnum] - 1), $this->isunicode);
  20040.                 break;
  20041.             }
  20042.             /*
  20043.             // Types to be implemented (special handling)
  20044.             case 'hebrew': {
  20045.                 break;
  20046.             }
  20047.             case 'armenian': {
  20048.                 break;
  20049.             }
  20050.             case 'georgian': {
  20051.                 break;
  20052.             }
  20053.             case 'cjk-ideographic': {
  20054.                 break;
  20055.             }
  20056.             case 'hiragana': {
  20057.                 break;
  20058.             }
  20059.             case 'katakana': {
  20060.                 break;
  20061.             }
  20062.             case 'hiragana-iroha': {
  20063.                 break;
  20064.             }
  20065.             case 'katakana-iroha': {
  20066.                 break;
  20067.             }
  20068.             */
  20069.             default: {
  20070.                 $textitem $this->listcount[$this->listnum];
  20071.             }
  20072.         }
  20073.         if (!TCPDF_STATIC::empty_string($textitem)) {
  20074.             // Check whether we need a new page or new column
  20075.             $prev_y $this->y;
  20076.             $h $this->getCellHeight($this->FontSize);
  20077.             if ($this->checkPageBreak($h) OR ($this->$prev_y)) {
  20078.                 $tmpx $this->x;
  20079.             }
  20080.             // print ordered item
  20081.             if ($this->rtl) {
  20082.                 $textitem '.'.$textitem;
  20083.             } else {
  20084.                 $textitem $textitem.'.';
  20085.             }
  20086.             $lspace += $this->GetStringWidth($textitem);
  20087.             if ($this->rtl) {
  20088.                 $this->+= $lspace;
  20089.             } else {
  20090.                 $this->-= $lspace;
  20091.             }
  20092.             $this->Write($this->lasth$textitem''false''false0false);
  20093.         }
  20094.         $this->$tmpx;
  20095.         $this->lispacer '^';
  20096.         // restore colors
  20097.         $this->setFillColorArray($bgcolor);
  20098.         $this->setDrawColorArray($strokecolor);
  20099.         $this->settextColorArray($color);
  20100.     }
  20101.     /**
  20102.      * Returns current graphic variables as array.
  20103.      * @return array of graphic variables
  20104.      * @protected
  20105.      * @since 4.2.010 (2008-11-14)
  20106.      */
  20107.     protected function getGraphicVars() {
  20108.         $grapvars = array(
  20109.             'FontFamily' => $this->FontFamily,
  20110.             'FontStyle' => $this->FontStyle,
  20111.             'FontSizePt' => $this->FontSizePt,
  20112.             'rMargin' => $this->rMargin,
  20113.             'lMargin' => $this->lMargin,
  20114.             'cell_padding' => $this->cell_padding,
  20115.             'cell_margin' => $this->cell_margin,
  20116.             'LineWidth' => $this->LineWidth,
  20117.             'linestyleWidth' => $this->linestyleWidth,
  20118.             'linestyleCap' => $this->linestyleCap,
  20119.             'linestyleJoin' => $this->linestyleJoin,
  20120.             'linestyleDash' => $this->linestyleDash,
  20121.             'textrendermode' => $this->textrendermode,
  20122.             'textstrokewidth' => $this->textstrokewidth,
  20123.             'DrawColor' => $this->DrawColor,
  20124.             'FillColor' => $this->FillColor,
  20125.             'TextColor' => $this->TextColor,
  20126.             'ColorFlag' => $this->ColorFlag,
  20127.             'bgcolor' => $this->bgcolor,
  20128.             'fgcolor' => $this->fgcolor,
  20129.             'htmlvspace' => $this->htmlvspace,
  20130.             'listindent' => $this->listindent,
  20131.             'listindentlevel' => $this->listindentlevel,
  20132.             'listnum' => $this->listnum,
  20133.             'listordered' => $this->listordered,
  20134.             'listcount' => $this->listcount,
  20135.             'lispacer' => $this->lispacer,
  20136.             'cell_height_ratio' => $this->cell_height_ratio,
  20137.             'font_stretching' => $this->font_stretching,
  20138.             'font_spacing' => $this->font_spacing,
  20139.             'alpha' => $this->alpha,
  20140.             // extended
  20141.             'lasth' => $this->lasth,
  20142.             'tMargin' => $this->tMargin,
  20143.             'bMargin' => $this->bMargin,
  20144.             'AutoPageBreak' => $this->AutoPageBreak,
  20145.             'PageBreakTrigger' => $this->PageBreakTrigger,
  20146.             'x' => $this->x,
  20147.             'y' => $this->y,
  20148.             'w' => $this->w,
  20149.             'h' => $this->h,
  20150.             'wPt' => $this->wPt,
  20151.             'hPt' => $this->hPt,
  20152.             'fwPt' => $this->fwPt,
  20153.             'fhPt' => $this->fhPt,
  20154.             'page' => $this->page,
  20155.             'current_column' => $this->current_column,
  20156.             'num_columns' => $this->num_columns
  20157.             );
  20158.         return $grapvars;
  20159.     }
  20160.     /**
  20161.      * Set graphic variables.
  20162.      * @param array $gvars array of graphic variablesto restore
  20163.      * @param boolean $extended if true restore extended graphic variables
  20164.      * @protected
  20165.      * @since 4.2.010 (2008-11-14)
  20166.      */
  20167.     protected function setGraphicVars($gvars$extended=false) {
  20168.         if ($this->state != 2) {
  20169.              return;
  20170.         }
  20171.         $this->FontFamily $gvars['FontFamily'];
  20172.         $this->FontStyle $gvars['FontStyle'];
  20173.         $this->FontSizePt $gvars['FontSizePt'];
  20174.         $this->rMargin $gvars['rMargin'];
  20175.         $this->lMargin $gvars['lMargin'];
  20176.         $this->cell_padding $gvars['cell_padding'];
  20177.         $this->cell_margin $gvars['cell_margin'];
  20178.         $this->LineWidth $gvars['LineWidth'];
  20179.         $this->linestyleWidth $gvars['linestyleWidth'];
  20180.         $this->linestyleCap $gvars['linestyleCap'];
  20181.         $this->linestyleJoin $gvars['linestyleJoin'];
  20182.         $this->linestyleDash $gvars['linestyleDash'];
  20183.         $this->textrendermode $gvars['textrendermode'];
  20184.         $this->textstrokewidth $gvars['textstrokewidth'];
  20185.         $this->DrawColor $gvars['DrawColor'];
  20186.         $this->FillColor $gvars['FillColor'];
  20187.         $this->TextColor $gvars['TextColor'];
  20188.         $this->ColorFlag $gvars['ColorFlag'];
  20189.         $this->bgcolor $gvars['bgcolor'];
  20190.         $this->fgcolor $gvars['fgcolor'];
  20191.         $this->htmlvspace $gvars['htmlvspace'];
  20192.         $this->listindent $gvars['listindent'];
  20193.         $this->listindentlevel $gvars['listindentlevel'];
  20194.         $this->listnum $gvars['listnum'];
  20195.         $this->listordered $gvars['listordered'];
  20196.         $this->listcount $gvars['listcount'];
  20197.         $this->lispacer $gvars['lispacer'];
  20198.         $this->cell_height_ratio $gvars['cell_height_ratio'];
  20199.         $this->font_stretching $gvars['font_stretching'];
  20200.         $this->font_spacing $gvars['font_spacing'];
  20201.         $this->alpha $gvars['alpha'];
  20202.         if ($extended) {
  20203.             // restore extended values
  20204.             $this->lasth $gvars['lasth'];
  20205.             $this->tMargin $gvars['tMargin'];
  20206.             $this->bMargin $gvars['bMargin'];
  20207.             $this->AutoPageBreak $gvars['AutoPageBreak'];
  20208.             $this->PageBreakTrigger $gvars['PageBreakTrigger'];
  20209.             $this->$gvars['x'];
  20210.             $this->$gvars['y'];
  20211.             $this->$gvars['w'];
  20212.             $this->$gvars['h'];
  20213.             $this->wPt $gvars['wPt'];
  20214.             $this->hPt $gvars['hPt'];
  20215.             $this->fwPt $gvars['fwPt'];
  20216.             $this->fhPt $gvars['fhPt'];
  20217.             $this->page $gvars['page'];
  20218.             $this->current_column $gvars['current_column'];
  20219.             $this->num_columns $gvars['num_columns'];
  20220.         }
  20221.         $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  20222.         if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  20223.             $this->setFont($this->FontFamily$this->FontStyle$this->FontSizePt);
  20224.         }
  20225.     }
  20226.     /**
  20227.      * Outputs the "save graphics state" operator 'q'
  20228.      * @protected
  20229.      */
  20230.     protected function _outSaveGraphicsState() {
  20231.         $this->_out('q');
  20232.     }
  20233.     /**
  20234.      * Outputs the "restore graphics state" operator 'Q'
  20235.      * @protected
  20236.      */
  20237.     protected function _outRestoreGraphicsState() {
  20238.         $this->_out('Q');
  20239.     }
  20240.     /**
  20241.      * Set buffer content (always append data).
  20242.      * @param string $data data
  20243.      * @protected
  20244.      * @since 4.5.000 (2009-01-02)
  20245.      */
  20246.     protected function setBuffer($data) {
  20247.         $this->bufferlen += strlen($data);
  20248.         $this->buffer .= $data;
  20249.     }
  20250.     /**
  20251.      * Replace the buffer content
  20252.      * @param string $data data
  20253.      * @protected
  20254.      * @since 5.5.000 (2010-06-22)
  20255.      */
  20256.     protected function replaceBuffer($data) {
  20257.         $this->bufferlen strlen($data);
  20258.         $this->buffer $data;
  20259.     }
  20260.     /**
  20261.      * Get buffer content.
  20262.      * @return string buffer content
  20263.      * @protected
  20264.      * @since 4.5.000 (2009-01-02)
  20265.      */
  20266.     protected function getBuffer() {
  20267.         return $this->buffer;
  20268.     }
  20269.     /**
  20270.      * Set page buffer content.
  20271.      * @param int $page page number
  20272.      * @param string $data page data
  20273.      * @param boolean $append if true append data, false replace.
  20274.      * @protected
  20275.      * @since 4.5.000 (2008-12-31)
  20276.      */
  20277.     protected function setPageBuffer($page$data$append=false) {
  20278.         if ($append) {
  20279.             $this->pages[$page] .= $data;
  20280.         } else {
  20281.             $this->pages[$page] = $data;
  20282.         }
  20283.         if ($append AND isset($this->pagelen[$page])) {
  20284.             $this->pagelen[$page] += strlen($data);
  20285.         } else {
  20286.             $this->pagelen[$page] = strlen($data);
  20287.         }
  20288.     }
  20289.     /**
  20290.      * Get page buffer content.
  20291.      * @param int $page page number
  20292.      * @return string page buffer content or false in case of error
  20293.      * @protected
  20294.      * @since 4.5.000 (2008-12-31)
  20295.      */
  20296.     protected function getPageBuffer($page) {
  20297.         if (isset($this->pages[$page])) {
  20298.             return $this->pages[$page];
  20299.         }
  20300.         return false;
  20301.     }
  20302.     /**
  20303.      * Set image buffer content.
  20304.      * @param string $image image key
  20305.      * @param array $data image data
  20306.      * @return int image index number
  20307.      * @protected
  20308.      * @since 4.5.000 (2008-12-31)
  20309.      */
  20310.     protected function setImageBuffer($image$data) {
  20311.         if (($data['i'] = array_search($image$this->imagekeys)) === FALSE) {
  20312.             $this->imagekeys[$this->numimages] = $image;
  20313.             $data['i'] = $this->numimages;
  20314.             ++$this->numimages;
  20315.         }
  20316.         $this->images[$image] = $data;
  20317.         return $data['i'];
  20318.     }
  20319.     /**
  20320.      * Set image buffer content for a specified sub-key.
  20321.      * @param string $image image key
  20322.      * @param string $key image sub-key
  20323.      * @param array $data image data
  20324.      * @protected
  20325.      * @since 4.5.000 (2008-12-31)
  20326.      */
  20327.     protected function setImageSubBuffer($image$key$data) {
  20328.         if (!isset($this->images[$image])) {
  20329.             $this->setImageBuffer($image, array());
  20330.         }
  20331.         $this->images[$image][$key] = $data;
  20332.     }
  20333.     /**
  20334.      * Get image buffer content.
  20335.      * @param string $image image key
  20336.      * @return string|false image buffer content or false in case of error
  20337.      * @protected
  20338.      * @since 4.5.000 (2008-12-31)
  20339.      */
  20340.     protected function getImageBuffer($image) {
  20341.         if (isset($this->images[$image])) {
  20342.             return $this->images[$image];
  20343.         }
  20344.         return false;
  20345.     }
  20346.     /**
  20347.      * Set font buffer content.
  20348.      * @param string $font font key
  20349.      * @param array $data font data
  20350.      * @protected
  20351.      * @since 4.5.000 (2009-01-02)
  20352.      */
  20353.     protected function setFontBuffer($font$data) {
  20354.         $this->fonts[$font] = $data;
  20355.         if (!in_array($font$this->fontkeys)) {
  20356.             $this->fontkeys[] = $font;
  20357.             // store object ID for current font
  20358.             ++$this->n;
  20359.             $this->font_obj_ids[$font] = $this->n;
  20360.             $this->setFontSubBuffer($font'n'$this->n);
  20361.         }
  20362.     }
  20363.     /**
  20364.      * Set font buffer content.
  20365.      * @param string $font font key
  20366.      * @param string $key font sub-key
  20367.      * @param mixed $data font data
  20368.      * @protected
  20369.      * @since 4.5.000 (2009-01-02)
  20370.      */
  20371.     protected function setFontSubBuffer($font$key$data) {
  20372.         if (!isset($this->fonts[$font])) {
  20373.             $this->setFontBuffer($font, array());
  20374.         }
  20375.         $this->fonts[$font][$key] = $data;
  20376.     }
  20377.     /**
  20378.      * Get font buffer content.
  20379.      * @param string $font font key
  20380.      * @return string|false font buffer content or false in case of error
  20381.      * @protected
  20382.      * @since 4.5.000 (2009-01-02)
  20383.      */
  20384.     protected function getFontBuffer($font) {
  20385.         if (isset($this->fonts[$font])) {
  20386.             return $this->fonts[$font];
  20387.         }
  20388.         return false;
  20389.     }
  20390.     /**
  20391.      * Move a page to a previous position.
  20392.      * @param int $frompage number of the source page
  20393.      * @param int $topage number of the destination page (must be less than $frompage)
  20394.      * @return bool true in case of success, false in case of error.
  20395.      * @public
  20396.      * @since 4.5.000 (2009-01-02)
  20397.      */
  20398.     public function movePage($frompage$topage) {
  20399.         if (($frompage $this->numpages) OR ($frompage <= $topage)) {
  20400.             return false;
  20401.         }
  20402.         if ($frompage == $this->page) {
  20403.             // close the page before moving it
  20404.             $this->endPage();
  20405.         }
  20406.         // move all page-related states
  20407.         $tmppage $this->getPageBuffer($frompage);
  20408.         $tmppagedim $this->pagedim[$frompage];
  20409.         $tmppagelen $this->pagelen[$frompage];
  20410.         $tmpintmrk $this->intmrk[$frompage];
  20411.         $tmpbordermrk $this->bordermrk[$frompage];
  20412.         $tmpcntmrk $this->cntmrk[$frompage];
  20413.         $tmppageobjects $this->pageobjects[$frompage];
  20414.         if (isset($this->footerpos[$frompage])) {
  20415.             $tmpfooterpos $this->footerpos[$frompage];
  20416.         }
  20417.         if (isset($this->footerlen[$frompage])) {
  20418.             $tmpfooterlen $this->footerlen[$frompage];
  20419.         }
  20420.         if (isset($this->transfmrk[$frompage])) {
  20421.             $tmptransfmrk $this->transfmrk[$frompage];
  20422.         }
  20423.         if (isset($this->PageAnnots[$frompage])) {
  20424.             $tmpannots $this->PageAnnots[$frompage];
  20425.         }
  20426.         if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20427.             for ($i $frompage$i $topage; --$i) {
  20428.                 if (isset($this->newpagegroup[$i]) AND (($i $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20429.                     --$this->pagegroups[$this->newpagegroup[$i]];
  20430.                     break;
  20431.                 }
  20432.             }
  20433.             for ($i $topage$i 0; --$i) {
  20434.                 if (isset($this->newpagegroup[$i]) AND (($i $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20435.                     ++$this->pagegroups[$this->newpagegroup[$i]];
  20436.                     break;
  20437.                 }
  20438.             }
  20439.         }
  20440.         for ($i $frompage$i $topage; --$i) {
  20441.             $j $i 1;
  20442.             // shift pages down
  20443.             $this->setPageBuffer($i$this->getPageBuffer($j));
  20444.             $this->pagedim[$i] = $this->pagedim[$j];
  20445.             $this->pagelen[$i] = $this->pagelen[$j];
  20446.             $this->intmrk[$i] = $this->intmrk[$j];
  20447.             $this->bordermrk[$i] = $this->bordermrk[$j];
  20448.             $this->cntmrk[$i] = $this->cntmrk[$j];
  20449.             $this->pageobjects[$i] = $this->pageobjects[$j];
  20450.             if (isset($this->footerpos[$j])) {
  20451.                 $this->footerpos[$i] = $this->footerpos[$j];
  20452.             } elseif (isset($this->footerpos[$i])) {
  20453.                 unset($this->footerpos[$i]);
  20454.             }
  20455.             if (isset($this->footerlen[$j])) {
  20456.                 $this->footerlen[$i] = $this->footerlen[$j];
  20457.             } elseif (isset($this->footerlen[$i])) {
  20458.                 unset($this->footerlen[$i]);
  20459.             }
  20460.             if (isset($this->transfmrk[$j])) {
  20461.                 $this->transfmrk[$i] = $this->transfmrk[$j];
  20462.             } elseif (isset($this->transfmrk[$i])) {
  20463.                 unset($this->transfmrk[$i]);
  20464.             }
  20465.             if (isset($this->PageAnnots[$j])) {
  20466.                 $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20467.             } elseif (isset($this->PageAnnots[$i])) {
  20468.                 unset($this->PageAnnots[$i]);
  20469.             }
  20470.             if (isset($this->newpagegroup[$j])) {
  20471.                 $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20472.                 unset($this->newpagegroup[$j]);
  20473.             }
  20474.             if ($this->currpagegroup == $j) {
  20475.                 $this->currpagegroup $i;
  20476.             }
  20477.         }
  20478.         $this->setPageBuffer($topage$tmppage);
  20479.         $this->pagedim[$topage] = $tmppagedim;
  20480.         $this->pagelen[$topage] = $tmppagelen;
  20481.         $this->intmrk[$topage] = $tmpintmrk;
  20482.         $this->bordermrk[$topage] = $tmpbordermrk;
  20483.         $this->cntmrk[$topage] = $tmpcntmrk;
  20484.         $this->pageobjects[$topage] = $tmppageobjects;
  20485.         if (isset($tmpfooterpos)) {
  20486.             $this->footerpos[$topage] = $tmpfooterpos;
  20487.         } elseif (isset($this->footerpos[$topage])) {
  20488.             unset($this->footerpos[$topage]);
  20489.         }
  20490.         if (isset($tmpfooterlen)) {
  20491.             $this->footerlen[$topage] = $tmpfooterlen;
  20492.         } elseif (isset($this->footerlen[$topage])) {
  20493.             unset($this->footerlen[$topage]);
  20494.         }
  20495.         if (isset($tmptransfmrk)) {
  20496.             $this->transfmrk[$topage] = $tmptransfmrk;
  20497.         } elseif (isset($this->transfmrk[$topage])) {
  20498.             unset($this->transfmrk[$topage]);
  20499.         }
  20500.         if (isset($tmpannots)) {
  20501.             $this->PageAnnots[$topage] = $tmpannots;
  20502.         } elseif (isset($this->PageAnnots[$topage])) {
  20503.             unset($this->PageAnnots[$topage]);
  20504.         }
  20505.         // adjust outlines
  20506.         $tmpoutlines $this->outlines;
  20507.         foreach ($tmpoutlines as $key => $outline) {
  20508.             if (!$outline['f']) {
  20509.                 if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20510.                     $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20511.                 } elseif ($outline['p'] == $frompage) {
  20512.                     $this->outlines[$key]['p'] = $topage;
  20513.                 }
  20514.             }
  20515.         }
  20516.         // adjust dests
  20517.         $tmpdests $this->dests;
  20518.         foreach ($tmpdests as $key => $dest) {
  20519.             if (!$dest['f']) {
  20520.                 if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20521.                     $this->dests[$key]['p'] = ($dest['p'] + 1);
  20522.                 } elseif ($dest['p'] == $frompage) {
  20523.                     $this->dests[$key]['p'] = $topage;
  20524.                 }
  20525.             }
  20526.         }
  20527.         // adjust links
  20528.         $tmplinks $this->links;
  20529.         foreach ($tmplinks as $key => $link) {
  20530.             if (!$link['f']) {
  20531.                 if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
  20532.                     $this->links[$key]['p'] = ($link['p'] + 1);
  20533.                 } elseif ($link['p'] == $frompage) {
  20534.                     $this->links[$key]['p'] = $topage;
  20535.                 }
  20536.             }
  20537.         }
  20538.         // adjust javascript
  20539.         $jfrompage $frompage;
  20540.         $jtopage $topage;
  20541.         if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/'$this->javascript$pamatch) > 0) {
  20542.             foreach($pamatch[0] as $pk => $pmatch) {
  20543.                 $pagenum intval($pamatch[3][$pk]) + 1;
  20544.                 if (($pagenum >= $jtopage) AND ($pagenum $jfrompage)) {
  20545.                     $newpage = ($pagenum 1);
  20546.                 } elseif ($pagenum == $jfrompage) {
  20547.                     $newpage $jtopage;
  20548.                 } else {
  20549.                     $newpage $pagenum;
  20550.                 }
  20551.                 --$newpage;
  20552.                 $newjs "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20553.                 $this->javascript str_replace($pmatch$newjs$this->javascript);
  20554.             }
  20555.             unset($pamatch);
  20556.         }
  20557.         // return to last page
  20558.         $this->lastPage(true);
  20559.         return true;
  20560.     }
  20561.     /**
  20562.      * Remove the specified page.
  20563.      * @param int $page page to remove
  20564.      * @return bool true in case of success, false in case of error.
  20565.      * @public
  20566.      * @since 4.6.004 (2009-04-23)
  20567.      */
  20568.     public function deletePage($page) {
  20569.         if (($page 1) OR ($page $this->numpages)) {
  20570.             return false;
  20571.         }
  20572.         // delete current page
  20573.         unset($this->pages[$page]);
  20574.         unset($this->pagedim[$page]);
  20575.         unset($this->pagelen[$page]);
  20576.         unset($this->intmrk[$page]);
  20577.         unset($this->bordermrk[$page]);
  20578.         unset($this->cntmrk[$page]);
  20579.         foreach ($this->pageobjects[$page] as $oid) {
  20580.             if (isset($this->offsets[$oid])){
  20581.                 unset($this->offsets[$oid]);
  20582.             }
  20583.         }
  20584.         unset($this->pageobjects[$page]);
  20585.         if (isset($this->footerpos[$page])) {
  20586.             unset($this->footerpos[$page]);
  20587.         }
  20588.         if (isset($this->footerlen[$page])) {
  20589.             unset($this->footerlen[$page]);
  20590.         }
  20591.         if (isset($this->transfmrk[$page])) {
  20592.             unset($this->transfmrk[$page]);
  20593.         }
  20594.         if (isset($this->PageAnnots[$page])) {
  20595.             unset($this->PageAnnots[$page]);
  20596.         }
  20597.         if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20598.             for ($i $page$i 0; --$i) {
  20599.                 if (isset($this->newpagegroup[$i]) AND (($i $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20600.                     --$this->pagegroups[$this->newpagegroup[$i]];
  20601.                     break;
  20602.                 }
  20603.             }
  20604.         }
  20605.         if (isset($this->pageopen[$page])) {
  20606.             unset($this->pageopen[$page]);
  20607.         }
  20608.         if ($page $this->numpages) {
  20609.             // update remaining pages
  20610.             for ($i $page$i $this->numpages; ++$i) {
  20611.                 $j $i 1;
  20612.                 // shift pages
  20613.                 $this->setPageBuffer($i$this->getPageBuffer($j));
  20614.                 $this->pagedim[$i] = $this->pagedim[$j];
  20615.                 $this->pagelen[$i] = $this->pagelen[$j];
  20616.                 $this->intmrk[$i] = $this->intmrk[$j];
  20617.                 $this->bordermrk[$i] = $this->bordermrk[$j];
  20618.                 $this->cntmrk[$i] = $this->cntmrk[$j];
  20619.                 $this->pageobjects[$i] = $this->pageobjects[$j];
  20620.                 if (isset($this->footerpos[$j])) {
  20621.                     $this->footerpos[$i] = $this->footerpos[$j];
  20622.                 } elseif (isset($this->footerpos[$i])) {
  20623.                     unset($this->footerpos[$i]);
  20624.                 }
  20625.                 if (isset($this->footerlen[$j])) {
  20626.                     $this->footerlen[$i] = $this->footerlen[$j];
  20627.                 } elseif (isset($this->footerlen[$i])) {
  20628.                     unset($this->footerlen[$i]);
  20629.                 }
  20630.                 if (isset($this->transfmrk[$j])) {
  20631.                     $this->transfmrk[$i] = $this->transfmrk[$j];
  20632.                 } elseif (isset($this->transfmrk[$i])) {
  20633.                     unset($this->transfmrk[$i]);
  20634.                 }
  20635.                 if (isset($this->PageAnnots[$j])) {
  20636.                     $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20637.                 } elseif (isset($this->PageAnnots[$i])) {
  20638.                     unset($this->PageAnnots[$i]);
  20639.                 }
  20640.                 if (isset($this->newpagegroup[$j])) {
  20641.                     $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20642.                     unset($this->newpagegroup[$j]);
  20643.                 }
  20644.                 if ($this->currpagegroup == $j) {
  20645.                     $this->currpagegroup $i;
  20646.                 }
  20647.                 if (isset($this->pageopen[$j])) {
  20648.                     $this->pageopen[$i] = $this->pageopen[$j];
  20649.                 } elseif (isset($this->pageopen[$i])) {
  20650.                     unset($this->pageopen[$i]);
  20651.                 }
  20652.             }
  20653.             // remove last page
  20654.             unset($this->pages[$this->numpages]);
  20655.             unset($this->pagedim[$this->numpages]);
  20656.             unset($this->pagelen[$this->numpages]);
  20657.             unset($this->intmrk[$this->numpages]);
  20658.             unset($this->bordermrk[$this->numpages]);
  20659.             unset($this->cntmrk[$this->numpages]);
  20660.             foreach ($this->pageobjects[$this->numpages] as $oid) {
  20661.                 if (isset($this->offsets[$oid])){
  20662.                     unset($this->offsets[$oid]);
  20663.                 }
  20664.             }
  20665.             unset($this->pageobjects[$this->numpages]);
  20666.             if (isset($this->footerpos[$this->numpages])) {
  20667.                 unset($this->footerpos[$this->numpages]);
  20668.             }
  20669.             if (isset($this->footerlen[$this->numpages])) {
  20670.                 unset($this->footerlen[$this->numpages]);
  20671.             }
  20672.             if (isset($this->transfmrk[$this->numpages])) {
  20673.                 unset($this->transfmrk[$this->numpages]);
  20674.             }
  20675.             if (isset($this->PageAnnots[$this->numpages])) {
  20676.                 unset($this->PageAnnots[$this->numpages]);
  20677.             }
  20678.             if (isset($this->newpagegroup[$this->numpages])) {
  20679.                 unset($this->newpagegroup[$this->numpages]);
  20680.             }
  20681.             if ($this->currpagegroup == $this->numpages) {
  20682.                 $this->currpagegroup = ($this->numpages 1);
  20683.             }
  20684.             if (isset($this->pagegroups[$this->numpages])) {
  20685.                 unset($this->pagegroups[$this->numpages]);
  20686.             }
  20687.             if (isset($this->pageopen[$this->numpages])) {
  20688.                 unset($this->pageopen[$this->numpages]);
  20689.             }
  20690.         }
  20691.         --$this->numpages;
  20692.         $this->page $this->numpages;
  20693.         // adjust outlines
  20694.         $tmpoutlines $this->outlines;
  20695.         foreach ($tmpoutlines as $key => $outline) {
  20696.             if (!$outline['f']) {
  20697.                 if ($outline['p'] > $page) {
  20698.                     $this->outlines[$key]['p'] = $outline['p'] - 1;
  20699.                 } elseif ($outline['p'] == $page) {
  20700.                     unset($this->outlines[$key]);
  20701.                 }
  20702.             }
  20703.         }
  20704.         // adjust dests
  20705.         $tmpdests $this->dests;
  20706.         foreach ($tmpdests as $key => $dest) {
  20707.             if (!$dest['f']) {
  20708.                 if ($dest['p'] > $page) {
  20709.                     $this->dests[$key]['p'] = $dest['p'] - 1;
  20710.                 } elseif ($dest['p'] == $page) {
  20711.                     unset($this->dests[$key]);
  20712.                 }
  20713.             }
  20714.         }
  20715.         // adjust links
  20716.         $tmplinks $this->links;
  20717.         foreach ($tmplinks as $key => $link) {
  20718.             if (!$link['f']) {
  20719.                 if ($link['p'] > $page) {
  20720.                     $this->links[$key]['p'] = $link['p'] - 1;
  20721.                 } elseif ($link['p'] == $page) {
  20722.                     unset($this->links[$key]);
  20723.                 }
  20724.             }
  20725.         }
  20726.         // adjust javascript
  20727.         $jpage $page;
  20728.         if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/'$this->javascript$pamatch) > 0) {
  20729.             foreach($pamatch[0] as $pk => $pmatch) {
  20730.                 $pagenum intval($pamatch[3][$pk]) + 1;
  20731.                 if ($pagenum >= $jpage) {
  20732.                     $newpage = ($pagenum 1);
  20733.                 } elseif ($pagenum == $jpage) {
  20734.                     $newpage 1;
  20735.                 } else {
  20736.                     $newpage $pagenum;
  20737.                 }
  20738.                 --$newpage;
  20739.                 $newjs "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
  20740.                 $this->javascript str_replace($pmatch$newjs$this->javascript);
  20741.             }
  20742.             unset($pamatch);
  20743.         }
  20744.         // return to last page
  20745.         if ($this->numpages 0) {
  20746.             $this->lastPage(true);
  20747.         }
  20748.         return true;
  20749.     }
  20750.     /**
  20751.      * Clone the specified page to a new page.
  20752.      * @param int $page number of page to copy (0 = current page)
  20753.      * @return bool true in case of success, false in case of error.
  20754.      * @public
  20755.      * @since 4.9.015 (2010-04-20)
  20756.      */
  20757.     public function copyPage($page=0) {
  20758.         if ($page == 0) {
  20759.             // default value
  20760.             $page $this->page;
  20761.         }
  20762.         if (($page 1) OR ($page $this->numpages)) {
  20763.             return false;
  20764.         }
  20765.         // close the last page
  20766.         $this->endPage();
  20767.         // copy all page-related states
  20768.         ++$this->numpages;
  20769.         $this->page $this->numpages;
  20770.         $this->setPageBuffer($this->page$this->getPageBuffer($page));
  20771.         $this->pagedim[$this->page] = $this->pagedim[$page];
  20772.         $this->pagelen[$this->page] = $this->pagelen[$page];
  20773.         $this->intmrk[$this->page] = $this->intmrk[$page];
  20774.         $this->bordermrk[$this->page] = $this->bordermrk[$page];
  20775.         $this->cntmrk[$this->page] = $this->cntmrk[$page];
  20776.         $this->pageobjects[$this->page] = $this->pageobjects[$page];
  20777.         $this->pageopen[$this->page] = false;
  20778.         if (isset($this->footerpos[$page])) {
  20779.             $this->footerpos[$this->page] = $this->footerpos[$page];
  20780.         }
  20781.         if (isset($this->footerlen[$page])) {
  20782.             $this->footerlen[$this->page] = $this->footerlen[$page];
  20783.         }
  20784.         if (isset($this->transfmrk[$page])) {
  20785.             $this->transfmrk[$this->page] = $this->transfmrk[$page];
  20786.         }
  20787.         if (isset($this->PageAnnots[$page])) {
  20788.             $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  20789.         }
  20790.         if (isset($this->newpagegroup[$page])) {
  20791.             // start a new group
  20792.             $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  20793.             $this->currpagegroup $this->newpagegroup[$this->page];
  20794.             $this->pagegroups[$this->currpagegroup] = 1;
  20795.         } elseif (isset($this->currpagegroup) AND ($this->currpagegroup 0)) {
  20796.             ++$this->pagegroups[$this->currpagegroup];
  20797.         }
  20798.         // copy outlines
  20799.         $tmpoutlines $this->outlines;
  20800.         foreach ($tmpoutlines as $key => $outline) {
  20801.             if ($outline['p'] == $page) {
  20802.                 $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page'f' => $outline['f'], 's' => $outline['s'], 'c' => $outline['c']);
  20803.             }
  20804.         }
  20805.         // copy links
  20806.         $tmplinks $this->links;
  20807.         foreach ($tmplinks as $key => $link) {
  20808.             if ($link['p'] == $page) {
  20809.                 $this->links[] = array('p' => $this->page'y' => $link['y'], 'f' => $link['f']);
  20810.             }
  20811.         }
  20812.         // return to last page
  20813.         $this->lastPage(true);
  20814.         return true;
  20815.     }
  20816.     /**
  20817.      * Output a Table of Content Index (TOC).
  20818.      * This method must be called after all Bookmarks were set.
  20819.      * Before calling this method you have to open the page using the addTOCPage() method.
  20820.      * After calling this method you have to call endTOCPage() to close the TOC page.
  20821.      * You can override this method to achieve different styles.
  20822.      * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
  20823.      * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  20824.      * @param string $filler string used to fill the space between text and page number.
  20825.      * @param string $toc_name name to use for TOC bookmark.
  20826.      * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20827.      * @param array $color RGB color array for bookmark title (values from 0 to 255).
  20828.      * @public
  20829.      * @author Nicola Asuni
  20830.      * @since 4.5.000 (2009-01-02)
  20831.      * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  20832.      */
  20833.     public function addTOC($page=null$numbersfont=''$filler='.'$toc_name='TOC'$style=''$color=array(0,0,0)) {
  20834.         $fontsize $this->FontSizePt;
  20835.         $fontfamily $this->FontFamily;
  20836.         $fontstyle $this->FontStyle;
  20837.         $w $this->$this->lMargin $this->rMargin;
  20838.         $spacer $this->GetStringWidth(chr(32)) * 4;
  20839.         $lmargin $this->lMargin;
  20840.         $rmargin $this->rMargin;
  20841.         $x_start $this->GetX();
  20842.         $page_first $this->page;
  20843.         $current_page $this->page;
  20844.         $page_fill_start false;
  20845.         $page_fill_end false;
  20846.         $current_column $this->current_column;
  20847.         if (TCPDF_STATIC::empty_string($numbersfont)) {
  20848.             $numbersfont $this->default_monospaced_font;
  20849.         }
  20850.         if (TCPDF_STATIC::empty_string($filler)) {
  20851.             $filler ' ';
  20852.         }
  20853.         if (TCPDF_STATIC::empty_string($page)) {
  20854.             $gap ' ';
  20855.         } else {
  20856.             $gap '';
  20857.             if ($page 1) {
  20858.                 $page 1;
  20859.             }
  20860.         }
  20861.         $this->setFont($numbersfont$fontstyle$fontsize);
  20862.         $numwidth $this->GetStringWidth('00000');
  20863.         $maxpage 0//used for pages on attached documents
  20864.         foreach ($this->outlines as $key => $outline) {
  20865.             // check for extra pages (used for attachments)
  20866.             if (($this->page $page_first) AND ($outline['p'] >= $this->numpages)) {
  20867.                 $outline['p'] += ($this->page $page_first);
  20868.             }
  20869.             if ($this->rtl) {
  20870.                 $aligntext 'R';
  20871.                 $alignnum 'L';
  20872.             } else {
  20873.                 $aligntext 'L';
  20874.                 $alignnum 'R';
  20875.             }
  20876.             if ($outline['l'] == 0) {
  20877.                 $this->setFont($fontfamily$outline['s'].'B'$fontsize);
  20878.             } else {
  20879.                 $this->setFont($fontfamily$outline['s'], $fontsize $outline['l']);
  20880.             }
  20881.             $this->setTextColorArray($outline['c']);
  20882.             // check for page break
  20883.             $this->checkPageBreak($this->getCellHeight($this->FontSize));
  20884.             // set margins and X position
  20885.             if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  20886.                 $this->lMargin $lmargin;
  20887.                 $this->rMargin $rmargin;
  20888.             } else {
  20889.                 if ($this->current_column != $current_column) {
  20890.                     if ($this->rtl) {
  20891.                         $x_start $this->$this->columns[$this->current_column]['x'];
  20892.                     } else {
  20893.                         $x_start $this->columns[$this->current_column]['x'];
  20894.                     }
  20895.                 }
  20896.                 $lmargin $this->lMargin;
  20897.                 $rmargin $this->rMargin;
  20898.                 $current_page $this->page;
  20899.                 $current_column $this->current_column;
  20900.             }
  20901.             $this->setX($x_start);
  20902.             $indent = ($spacer $outline['l']);
  20903.             if ($this->rtl) {
  20904.                 $this->-= $indent;
  20905.                 $this->rMargin $this->$this->x;
  20906.             } else {
  20907.                 $this->+= $indent;
  20908.                 $this->lMargin $this->x;
  20909.             }
  20910.             $link $this->AddLink();
  20911.             $this->setLink($link$outline['y'], $outline['p']);
  20912.             // write the text
  20913.             if ($this->rtl) {
  20914.                 $txt ' '.$outline['t'];
  20915.             } else {
  20916.                 $txt $outline['t'].' ';
  20917.             }
  20918.             $this->Write(0$txt$linkfalse$aligntextfalse0falsefalse0$numwidth'');
  20919.             if ($this->rtl) {
  20920.                 $tw $this->$this->lMargin;
  20921.             } else {
  20922.                 $tw $this->$this->rMargin $this->x;
  20923.             }
  20924.             $this->setFont($numbersfont$fontstyle$fontsize);
  20925.             if (TCPDF_STATIC::empty_string($page)) {
  20926.                 $pagenum $outline['p'];
  20927.             } else {
  20928.                 // placemark to be replaced with the correct number
  20929.                 $pagenum '{#'.($outline['p']).'}';
  20930.                 if ($this->isUnicodeFont()) {
  20931.                     $pagenum '{'.$pagenum.'}';
  20932.                 }
  20933.                 $maxpage max($maxpage$outline['p']);
  20934.             }
  20935.             $fw = ($tw $this->GetStringWidth($pagenum.$filler));
  20936.             $wfiller $this->GetStringWidth($filler);
  20937.             if ($wfiller 0) {
  20938.                 $numfills floor($fw $wfiller);
  20939.             } else {
  20940.                 $numfills 0;
  20941.             }
  20942.             if ($numfills 0) {
  20943.                 $rowfill str_repeat($filler$numfills);
  20944.             } else {
  20945.                 $rowfill '';
  20946.             }
  20947.             if ($this->rtl) {
  20948.                 $pagenum $pagenum.$gap.$rowfill;
  20949.             } else {
  20950.                 $pagenum $rowfill.$gap.$pagenum;
  20951.             }
  20952.             // write the number
  20953.             $this->Cell($tw0$pagenum01$alignnum0$link0);
  20954.         }
  20955.         $page_last $this->getPage();
  20956.         $numpages = ($page_last $page_first 1);
  20957.         // account for booklet mode
  20958.         if ($this->booklet) {
  20959.             // check if a blank page is required before TOC
  20960.             $page_fill_start = ((($page_first 2) == 0) XOR (($page 2) == 0));
  20961.             $page_fill_end = (!((($numpages 2) == 0) XOR ($page_fill_start)));
  20962.             if ($page_fill_start) {
  20963.                 // add a page at the end (to be moved before TOC)
  20964.                 $this->addPage();
  20965.                 ++$page_last;
  20966.                 ++$numpages;
  20967.             }
  20968.             if ($page_fill_end) {
  20969.                 // add a page at the end
  20970.                 $this->addPage();
  20971.                 ++$page_last;
  20972.                 ++$numpages;
  20973.             }
  20974.         }
  20975.         $maxpage max($maxpage$page_last);
  20976.         if (!TCPDF_STATIC::empty_string($page)) {
  20977.             for ($p $page_first$p <= $page_last; ++$p) {
  20978.                 // get page data
  20979.                 $temppage $this->getPageBuffer($p);
  20980.                 for ($n 1$n <= $maxpage; ++$n) {
  20981.                     // update page numbers
  20982.                     $a '{#'.$n.'}';
  20983.                     // get page number aliases
  20984.                     $pnalias $this->getInternalPageNumberAliases($a);
  20985.                     // calculate replacement number
  20986.                     if (($n >= $page) AND ($n <= $this->numpages)) {
  20987.                         $np $n $numpages;
  20988.                     } else {
  20989.                         $np $n;
  20990.                     }
  20991.                     $na TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number $np 1));
  20992.                     $nu TCPDF_FONTS::UTF8ToUTF16BE($nafalse$this->isunicode$this->CurrentFont);
  20993.                     // replace aliases with numbers
  20994.                     foreach ($pnalias['u'] as $u) {
  20995.                         $sfill str_repeat($fillermax(0, (strlen($u) - strlen($nu.' '))));
  20996.                         if ($this->rtl) {
  20997.                             $nr $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfillfalse$this->isunicode$this->CurrentFont);
  20998.                         } else {
  20999.                             $nr TCPDF_FONTS::UTF8ToUTF16BE($sfill.' 'false$this->isunicode$this->CurrentFont).$nu;
  21000.                         }
  21001.                         $temppage str_replace($u$nr$temppage);
  21002.                     }
  21003.                     foreach ($pnalias['a'] as $a) {
  21004.                         $sfill str_repeat($fillermax(0, (strlen($a) - strlen($na.' '))));
  21005.                         if ($this->rtl) {
  21006.                             $nr $na.' '.$sfill;
  21007.                         } else {
  21008.                             $nr $sfill.' '.$na;
  21009.                         }
  21010.                         $temppage str_replace($a$nr$temppage);
  21011.                     }
  21012.                 }
  21013.                 // save changes
  21014.                 $this->setPageBuffer($p$temppage);
  21015.             }
  21016.             // move pages
  21017.             $this->Bookmark($toc_name00$page_first$style$color);
  21018.             if ($page_fill_start) {
  21019.                 $this->movePage($page_last$page_first);
  21020.             }
  21021.             for ($i 0$i $numpages; ++$i) {
  21022.                 $this->movePage($page_last$page);
  21023.             }
  21024.         }
  21025.     }
  21026.     /**
  21027.      * Output a Table Of Content Index (TOC) using HTML templates.
  21028.      * This method must be called after all Bookmarks were set.
  21029.      * Before calling this method you have to open the page using the addTOCPage() method.
  21030.      * After calling this method you have to call endTOCPage() to close the TOC page.
  21031.      * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
  21032.      * @param string $toc_name name to use for TOC bookmark.
  21033.      * @param array $templates array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  21034.      * @param boolean $correct_align if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
  21035.      * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  21036.      * @param array $color RGB color array for title (values from 0 to 255).
  21037.      * @public
  21038.      * @author Nicola Asuni
  21039.      * @since 5.0.001 (2010-05-06)
  21040.      * @see addTOCPage(), endTOCPage(), addTOC()
  21041.      */
  21042.     public function addHTMLTOC($page=null$toc_name='TOC'$templates=array(), $correct_align=true$style=''$color=array(0,0,0)) {
  21043.         $filler ' ';
  21044.         $prev_htmlLinkColorArray $this->htmlLinkColorArray;
  21045.         $prev_htmlLinkFontStyle $this->htmlLinkFontStyle;
  21046.         // set new style for link
  21047.         $this->htmlLinkColorArray = array();
  21048.         $this->htmlLinkFontStyle '';
  21049.         $page_first $this->getPage();
  21050.         $page_fill_start false;
  21051.         $page_fill_end false;
  21052.         // get the font type used for numbers in each template
  21053.         $current_font $this->FontFamily;
  21054.         foreach ($templates as $level => $html) {
  21055.             $dom $this->getHtmlDomArray($html);
  21056.             foreach ($dom as $key => $value) {
  21057.                 if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  21058.                     $this->setFont($dom[($key 1)]['fontname']);
  21059.                     $templates['F'.$level] = $this->isUnicodeFont();
  21060.                 }
  21061.             }
  21062.         }
  21063.         $this->setFont($current_font);
  21064.         $maxpage 0//used for pages on attached documents
  21065.         foreach ($this->outlines as $key => $outline) {
  21066.             // get HTML template
  21067.             $row $templates[$outline['l']];
  21068.             if (TCPDF_STATIC::empty_string($page)) {
  21069.                 $pagenum $outline['p'];
  21070.             } else {
  21071.                 // placemark to be replaced with the correct number
  21072.                 $pagenum '{#'.($outline['p']).'}';
  21073.                 if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
  21074.                     $pagenum '{'.$pagenum.'}';
  21075.                 }
  21076.                 $maxpage max($maxpage$outline['p']);
  21077.             }
  21078.             // replace templates with current values
  21079.             $row str_replace('#TOC_DESCRIPTION#'$outline['t'], $row);
  21080.             $row str_replace('#TOC_PAGE_NUMBER#'$pagenum$row);
  21081.             // add link to page
  21082.             $row '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  21083.             // write bookmark entry
  21084.             $this->writeHTML($rowfalsefalsetruefalse'');
  21085.         }
  21086.         // restore link styles
  21087.         $this->htmlLinkColorArray $prev_htmlLinkColorArray;
  21088.         $this->htmlLinkFontStyle $prev_htmlLinkFontStyle;
  21089.         // move TOC page and replace numbers
  21090.         $page_last $this->getPage();
  21091.         $numpages = ($page_last $page_first 1);
  21092.         // account for booklet mode
  21093.         if ($this->booklet) {
  21094.             // check if a blank page is required before TOC
  21095.             $page_fill_start = ((($page_first 2) == 0) XOR (($page 2) == 0));
  21096.             $page_fill_end = (!((($numpages 2) == 0) XOR ($page_fill_start)));
  21097.             if ($page_fill_start) {
  21098.                 // add a page at the end (to be moved before TOC)
  21099.                 $this->addPage();
  21100.                 ++$page_last;
  21101.                 ++$numpages;
  21102.             }
  21103.             if ($page_fill_end) {
  21104.                 // add a page at the end
  21105.                 $this->addPage();
  21106.                 ++$page_last;
  21107.                 ++$numpages;
  21108.             }
  21109.         }
  21110.         $maxpage max($maxpage$page_last);
  21111.         if (!TCPDF_STATIC::empty_string($page)) {
  21112.             for ($p $page_first$p <= $page_last; ++$p) {
  21113.                 // get page data
  21114.                 $temppage $this->getPageBuffer($p);
  21115.                 for ($n 1$n <= $maxpage; ++$n) {
  21116.                     // update page numbers
  21117.                     $a '{#'.$n.'}';
  21118.                     // get page number aliases
  21119.                     $pnalias $this->getInternalPageNumberAliases($a);
  21120.                     // calculate replacement number
  21121.                     if ($n >= $page) {
  21122.                         $np $n $numpages;
  21123.                     } else {
  21124.                         $np $n;
  21125.                     }
  21126.                     $na TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number $np 1));
  21127.                     $nu TCPDF_FONTS::UTF8ToUTF16BE($nafalse$this->isunicode$this->CurrentFont);
  21128.                     // replace aliases with numbers
  21129.                     foreach ($pnalias['u'] as $u) {
  21130.                         if ($correct_align) {
  21131.                             $sfill str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  21132.                             if ($this->rtl) {
  21133.                                 $nr $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfillfalse$this->isunicode$this->CurrentFont);
  21134.                             } else {
  21135.                                 $nr TCPDF_FONTS::UTF8ToUTF16BE($sfill.' 'false$this->isunicode$this->CurrentFont).$nu;
  21136.                             }
  21137.                         } else {
  21138.                             $nr $nu;
  21139.                         }
  21140.                         $temppage str_replace($u$nr$temppage);
  21141.                     }
  21142.                     foreach ($pnalias['a'] as $a) {
  21143.                         if ($correct_align) {
  21144.                             $sfill str_repeat($filler, (strlen($a) - strlen($na.' ')));
  21145.                             if ($this->rtl) {
  21146.                                 $nr $na.' '.$sfill;
  21147.                             } else {
  21148.                                 $nr $sfill.' '.$na;
  21149.                             }
  21150.                         } else {
  21151.                             $nr $na;
  21152.                         }
  21153.                         $temppage str_replace($a$nr$temppage);
  21154.                     }
  21155.                 }
  21156.                 // save changes
  21157.                 $this->setPageBuffer($p$temppage);
  21158.             }
  21159.             // move pages
  21160.             $this->Bookmark($toc_name00$page_first$style$color);
  21161.             if ($page_fill_start) {
  21162.                 $this->movePage($page_last$page_first);
  21163.             }
  21164.             for ($i 0$i $numpages; ++$i) {
  21165.                 $this->movePage($page_last$page);
  21166.             }
  21167.         }
  21168.     }
  21169.     /**
  21170.      * Stores a copy of the current TCPDF object used for undo operation.
  21171.      * @public
  21172.      * @since 4.5.029 (2009-03-19)
  21173.      */
  21174.     public function startTransaction() {
  21175.         if (isset($this->objcopy)) {
  21176.             // remove previous copy
  21177.             $this->commitTransaction();
  21178.         }
  21179.         // record current page number and Y position
  21180.         $this->start_transaction_page $this->page;
  21181.         $this->start_transaction_y $this->y;
  21182.         // clone current object
  21183.         $this->objcopy TCPDF_STATIC::objclone($this);
  21184.     }
  21185.     /**
  21186.      * Delete the copy of the current TCPDF object used for undo operation.
  21187.      * @public
  21188.      * @since 4.5.029 (2009-03-19)
  21189.      */
  21190.     public function commitTransaction() {
  21191.         if (isset($this->objcopy)) {
  21192.             $this->objcopy->_destroy(truetrue);
  21193.             /* The unique file_id should not be used during cleanup again */
  21194.             $this->objcopy->file_id NULL;
  21195.             unset($this->objcopy);
  21196.         }
  21197.     }
  21198.     /**
  21199.      * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  21200.      * @param boolean $self if true restores current class object to previous state without the need of reassignment via the returned value.
  21201.      * @return TCPDF object.
  21202.      * @public
  21203.      * @since 4.5.029 (2009-03-19)
  21204.      */
  21205.     public function rollbackTransaction($self=false) {
  21206.         if (isset($this->objcopy)) {
  21207.             $objcopy $this->objcopy;
  21208.             $this->_destroy(truetrue);
  21209.             if ($self) {
  21210.                 $objvars get_object_vars($objcopy);
  21211.                 foreach ($objvars as $key => $value) {
  21212.                     $this->$key $value;
  21213.                 }
  21214.                 $objcopy->_destroy(truetrue);
  21215.                 /* The unique file_id should not be used during cleanup again */
  21216.                 $objcopy->file_id NULL;
  21217.                 unset($objcopy);
  21218.                 return $this;
  21219.             }
  21220.             /* The unique file_id should not be used during cleanup again */
  21221.             $this->file_id NULL;
  21222.             return $objcopy;
  21223.         }
  21224.         return $this;
  21225.     }
  21226.     // --- MULTI COLUMNS METHODS -----------------------
  21227.     /**
  21228.      * Set multiple columns of the same size
  21229.      * @param int $numcols number of columns (set to zero to disable columns mode)
  21230.      * @param int $width column width
  21231.      * @param int|null $y column starting Y position (leave empty for current Y position)
  21232.      * @public
  21233.      * @since 4.9.001 (2010-03-28)
  21234.      */
  21235.     public function setEqualColumns($numcols=0$width=0$y=null) {
  21236.         $this->columns = array();
  21237.         if ($numcols 2) {
  21238.             $numcols 0;
  21239.             $this->columns = array();
  21240.         } else {
  21241.             // maximum column width
  21242.             $maxwidth = ($this->$this->original_lMargin $this->original_rMargin) / $numcols;
  21243.             if (($width == 0) OR ($width $maxwidth)) {
  21244.                 $width $maxwidth;
  21245.             }
  21246.             if (TCPDF_STATIC::empty_string($y)) {
  21247.                 $y $this->y;
  21248.             }
  21249.             // space between columns
  21250.             $space = (($this->$this->original_lMargin $this->original_rMargin - ($numcols $width)) / ($numcols 1));
  21251.             // fill the columns array (with, space, starting Y position)
  21252.             for ($i 0$i $numcols; ++$i) {
  21253.                 $this->columns[$i] = array('w' => $width's' => $space'y' => $y);
  21254.             }
  21255.         }
  21256.         $this->num_columns $numcols;
  21257.         $this->current_column 0;
  21258.         $this->column_start_page $this->page;
  21259.         $this->selectColumn(0);
  21260.     }
  21261.     /**
  21262.      * Remove columns and reset page margins.
  21263.      * @public
  21264.      * @since 5.9.072 (2011-04-26)
  21265.      */
  21266.     public function resetColumns() {
  21267.         $this->lMargin $this->original_lMargin;
  21268.         $this->rMargin $this->original_rMargin;
  21269.         $this->setEqualColumns();
  21270.     }
  21271.     /**
  21272.      * Set columns array.
  21273.      * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  21274.      * @param array $columns
  21275.      * @public
  21276.      * @since 4.9.001 (2010-03-28)
  21277.      */
  21278.     public function setColumnsArray($columns) {
  21279.         $this->columns $columns;
  21280.         $this->num_columns count($columns);
  21281.         $this->current_column 0;
  21282.         $this->column_start_page $this->page;
  21283.         $this->selectColumn(0);
  21284.     }
  21285.     /**
  21286.      * Set position at a given column
  21287.      * @param int|null $col column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  21288.      * @public
  21289.      * @since 4.9.001 (2010-03-28)
  21290.      */
  21291.     public function selectColumn($col=null) {
  21292.         if (TCPDF_STATIC::empty_string($col)) {
  21293.             $col $this->current_column;
  21294.         } elseif ($col >= $this->num_columns) {
  21295.             $col 0;
  21296.         }
  21297.         $xshift = array('x' => 0's' => array('H' => 0'V' => 0), 'p' => array('L' => 0'T' => 0'R' => 0'B' => 0));
  21298.         $enable_thead false;
  21299.         if ($this->num_columns 1) {
  21300.             if ($col != $this->current_column) {
  21301.                 // move Y pointer at the top of the column
  21302.                 if ($this->column_start_page == $this->page) {
  21303.                     $this->$this->columns[$col]['y'];
  21304.                 } else {
  21305.                     $this->$this->tMargin;
  21306.                 }
  21307.                 // Avoid to write table headers more than once
  21308.                 if (($this->page $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col $this->maxselcol['column']))) {
  21309.                     $enable_thead true;
  21310.                     $this->maxselcol['page'] = $this->page;
  21311.                     $this->maxselcol['column'] = $col;
  21312.                 }
  21313.             }
  21314.             $xshift $this->colxshift;
  21315.             // set X position of the current column by case
  21316.             $listindent = ($this->listindentlevel $this->listindent);
  21317.             // calculate column X position
  21318.             $colpos 0;
  21319.             for ($i 0$i $col; ++$i) {
  21320.                 $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21321.             }
  21322.             if ($this->rtl) {
  21323.                 $x $this->$this->original_rMargin $colpos;
  21324.                 $this->rMargin = ($this->$x $listindent);
  21325.                 $this->lMargin = ($x $this->columns[$col]['w']);
  21326.                 $this->$x $listindent;
  21327.             } else {
  21328.                 $x $this->original_lMargin $colpos;
  21329.                 $this->lMargin = ($x $listindent);
  21330.                 $this->rMargin = ($this->$x $this->columns[$col]['w']);
  21331.                 $this->$x $listindent;
  21332.             }
  21333.             $this->columns[$col]['x'] = $x;
  21334.         }
  21335.         $this->current_column $col;
  21336.         // fix for HTML mode
  21337.         $this->newline true;
  21338.         // print HTML table header (if any)
  21339.         if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21340.             if ($enable_thead) {
  21341.                 // print table header
  21342.                 $this->writeHTML($this->theadfalsefalsefalsefalse'');
  21343.                 $this->+= $xshift['s']['V'];
  21344.                 // store end of header position
  21345.                 if (!isset($this->columns[$col]['th'])) {
  21346.                     $this->columns[$col]['th'] = array();
  21347.                 }
  21348.                 $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21349.                 $this->lasth 0;
  21350.             } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21351.                 $this->$this->columns[$col]['th']['\''.$this->page.'\''];
  21352.             }
  21353.         }
  21354.         // account for an html table cell over multiple columns
  21355.         if ($this->rtl) {
  21356.             $this->rMargin += $xshift['x'];
  21357.             $this->-= ($xshift['x'] + $xshift['p']['R']);
  21358.         } else {
  21359.             $this->lMargin += $xshift['x'];
  21360.             $this->+= $xshift['x'] + $xshift['p']['L'];
  21361.         }
  21362.     }
  21363.     /**
  21364.      * Return the current column number
  21365.      * @return int current column number
  21366.      * @public
  21367.      * @since 5.5.011 (2010-07-08)
  21368.      */
  21369.     public function getColumn() {
  21370.         return $this->current_column;
  21371.     }
  21372.     /**
  21373.      * Return the current number of columns.
  21374.      * @return int number of columns
  21375.      * @public
  21376.      * @since 5.8.018 (2010-08-25)
  21377.      */
  21378.     public function getNumberOfColumns() {
  21379.         return $this->num_columns;
  21380.     }
  21381.     /**
  21382.      * Set Text rendering mode.
  21383.      * @param int $stroke outline size in user units (0 = disable).
  21384.      * @param boolean $fill if true fills the text (default).
  21385.      * @param boolean $clip if true activate clipping mode
  21386.      * @public
  21387.      * @since 4.9.008 (2009-04-02)
  21388.      */
  21389.     public function setTextRenderingMode($stroke=0$fill=true$clip=false) {
  21390.         // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21391.         // convert text rendering parameters
  21392.         if ($stroke || !is_numeric($stroke)) {
  21393.             $stroke 0;
  21394.         }
  21395.         if ($fill === true) {
  21396.             if ($stroke 0) {
  21397.                 if ($clip === true) {
  21398.                     // Fill, then stroke text and add to path for clipping
  21399.                     $textrendermode 6;
  21400.                 } else {
  21401.                     // Fill, then stroke text
  21402.                     $textrendermode 2;
  21403.                 }
  21404.                 $textstrokewidth $stroke;
  21405.             } else {
  21406.                 if ($clip === true) {
  21407.                     // Fill text and add to path for clipping
  21408.                     $textrendermode 4;
  21409.                 } else {
  21410.                     // Fill text
  21411.                     $textrendermode 0;
  21412.                 }
  21413.             }
  21414.         } else {
  21415.             if ($stroke 0) {
  21416.                 if ($clip === true) {
  21417.                     // Stroke text and add to path for clipping
  21418.                     $textrendermode 5;
  21419.                 } else {
  21420.                     // Stroke text
  21421.                     $textrendermode 1;
  21422.                 }
  21423.                 $textstrokewidth $stroke;
  21424.             } else {
  21425.                 if ($clip === true) {
  21426.                     // Add text to path for clipping
  21427.                     $textrendermode 7;
  21428.                 } else {
  21429.                     // Neither fill nor stroke text (invisible)
  21430.                     $textrendermode 3;
  21431.                 }
  21432.             }
  21433.         }
  21434.         $this->textrendermode $textrendermode;
  21435.         $this->textstrokewidth $stroke;
  21436.     }
  21437.     /**
  21438.      * Set parameters for drop shadow effect for text.
  21439.      * @param array $params Array of parameters: enabled (boolean) set to true to enable shadow; depth_w (float) shadow width in user units; depth_h (float) shadow height in user units; color (array) shadow color or false to use the stroke color; opacity (float) Alpha value: real value from 0 (transparent) to 1 (opaque); blend_mode (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity.
  21440.      * @since 5.9.174 (2012-07-25)
  21441.      * @public
  21442.     */
  21443.     public function setTextShadow($params=array('enabled'=>false'depth_w'=>0'depth_h'=>0'color'=>false'opacity'=>1'blend_mode'=>'Normal')) {
  21444.         if (isset($params['enabled'])) {
  21445.             $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21446.         } else {
  21447.             $this->txtshadow['enabled'] = false;
  21448.         }
  21449.         if (isset($params['depth_w'])) {
  21450.             $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21451.         } else {
  21452.             $this->txtshadow['depth_w'] = 0;
  21453.         }
  21454.         if (isset($params['depth_h'])) {
  21455.             $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21456.         } else {
  21457.             $this->txtshadow['depth_h'] = 0;
  21458.         }
  21459.         if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21460.             $this->txtshadow['color'] = $params['color'];
  21461.         } else {
  21462.             $this->txtshadow['color'] = $this->strokecolor;
  21463.         }
  21464.         if (isset($params['opacity'])) {
  21465.             $this->txtshadow['opacity'] = min(1max(0floatval($params['opacity'])));
  21466.         } else {
  21467.             $this->txtshadow['opacity'] = 1;
  21468.         }
  21469.         if (isset($params['blend_mode']) AND in_array($params['blend_mode'], array('Normal''Multiply''Screen''Overlay''Darken''Lighten''ColorDodge''ColorBurn''HardLight''SoftLight''Difference''Exclusion''Hue''Saturation''Color''Luminosity'))) {
  21470.             $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21471.         } else {
  21472.             $this->txtshadow['blend_mode'] = 'Normal';
  21473.         }
  21474.         if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21475.             $this->txtshadow['enabled'] = false;
  21476.         }
  21477.     }
  21478.     /**
  21479.      * Return the text shadow parameters array.
  21480.      * @return array array of parameters.
  21481.      * @since 5.9.174 (2012-07-25)
  21482.      * @public
  21483.      */
  21484.     public function getTextShadow() {
  21485.         return $this->txtshadow;
  21486.     }
  21487.     /**
  21488.      * Returns an array of chars containing soft hyphens.
  21489.      * @param array $word array of chars
  21490.      * @param array $patterns Array of hypenation patterns.
  21491.      * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
  21492.      * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  21493.      * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  21494.      * @param int $charmin Minimum word length to apply the hyphenation algorithm.
  21495.      * @param int $charmax Maximum length of broken piece of word.
  21496.      * @return array text with soft hyphens
  21497.      * @author Nicola Asuni
  21498.      * @since 4.9.012 (2010-04-12)
  21499.      * @protected
  21500.      */
  21501.     protected function hyphenateWord($word$patterns$dictionary=array(), $leftmin=1$rightmin=2$charmin=1$charmax=8) {
  21502.         $hyphenword = array(); // hyphens positions
  21503.         $numchars count($word);
  21504.         if ($numchars <= $charmin) {
  21505.             return $word;
  21506.         }
  21507.         $word_string TCPDF_FONTS::UTF8ArrSubString($word''''$this->isunicode);
  21508.         // some words will be returned as-is
  21509.         $pattern '/^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
  21510.         if (preg_match($pattern$word_string) > 0) {
  21511.             // email
  21512.             return $word;
  21513.         }
  21514.         $pattern '/(([a-zA-Z0-9\-]+\.)?)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
  21515.         if (preg_match($pattern$word_string) > 0) {
  21516.             // URL
  21517.             return $word;
  21518.         }
  21519.         if (isset($dictionary[$word_string])) {
  21520.             return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode$this->CurrentFont);
  21521.         }
  21522.         // surround word with '_' characters
  21523.         $tmpword array_merge(array(46), $word, array(46));
  21524.         $tmpnumchars $numchars 2;
  21525.         $maxpos $tmpnumchars 1;
  21526.         for ($pos 0$pos $maxpos; ++$pos) {
  21527.             $imax min(($tmpnumchars $pos), $charmax);
  21528.             for ($i 1$i <= $imax; ++$i) {
  21529.                 $subword strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword$pos, ($pos $i), $this->isunicode));
  21530.                 if (isset($patterns[$subword])) {
  21531.                     $pattern TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode$this->CurrentFont);
  21532.                     $pattern_length count($pattern);
  21533.                     $digits 1;
  21534.                     for ($j 0$j $pattern_length; ++$j) {
  21535.                         // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
  21536.                         if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21537.                             if ($j == 0) {
  21538.                                 $zero $pos 1;
  21539.                             } else {
  21540.                                 $zero $pos $j $digits;
  21541.                             }
  21542.                             // get hyphenation level
  21543.                             $level = ($pattern[$j] - 48);
  21544.                             // if two levels from two different patterns match at the same point, the higher one is selected.
  21545.                             if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
  21546.                                 $hyphenword[$zero] = $level;
  21547.                             }
  21548.                             ++$digits;
  21549.                         }
  21550.                     }
  21551.                 }
  21552.             }
  21553.         }
  21554.         $inserted 0;
  21555.         $maxpos $numchars $rightmin;
  21556.         for ($i $leftmin$i <= $maxpos; ++$i) {
  21557.             // only odd levels indicate allowed hyphenation points
  21558.             if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21559.                 // 173 = soft hyphen character
  21560.                 array_splice($word$i $inserted0173);
  21561.                 ++$inserted;
  21562.             }
  21563.         }
  21564.         return $word;
  21565.     }
  21566.     /**
  21567.      * Returns text with soft hyphens.
  21568.      * @param string $text text to process
  21569.      * @param mixed $patterns Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  21570.      * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
  21571.      * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  21572.      * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  21573.      * @param int $charmin Minimum word length to apply the hyphenation algorithm.
  21574.      * @param int $charmax Maximum length of broken piece of word.
  21575.      * @return string text with soft hyphens
  21576.      * @author Nicola Asuni
  21577.      * @since 4.9.012 (2010-04-12)
  21578.      * @public
  21579.      */
  21580.     public function hyphenateText($text$patterns$dictionary=array(), $leftmin=1$rightmin=2$charmin=1$charmax=8) {
  21581.         $text $this->unhtmlentities($text);
  21582.         $word = array(); // last word
  21583.         $txtarr = array(); // text to be returned
  21584.         $intag false// true if we are inside an HTML tag
  21585.         $skip false// true to skip hyphenation
  21586.         if (!is_array($patterns)) {
  21587.             $patterns TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21588.         }
  21589.         // get array of characters
  21590.         $unichars TCPDF_FONTS::UTF8StringToArray($text$this->isunicode$this->CurrentFont);
  21591.         // for each char
  21592.         foreach ($unichars as $char) {
  21593.             if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21594.                 // letter character
  21595.                 $word[] = $char;
  21596.             } else {
  21597.                 // other type of character
  21598.                 if (!TCPDF_STATIC::empty_string($word)) {
  21599.                     // hypenate the word
  21600.                     $txtarr array_merge($txtarr$this->hyphenateWord($word$patterns$dictionary$leftmin$rightmin$charmin$charmax));
  21601.                     $word = array();
  21602.                 }
  21603.                 $txtarr[] = $char;
  21604.                 if (chr($char) == '<') {
  21605.                     // we are inside an HTML tag
  21606.                     $intag true;
  21607.                 } elseif ($intag AND (chr($char) == '>')) {
  21608.                     // end of HTML tag
  21609.                     $intag false;
  21610.                     // check for style tag
  21611.                     $expected = array(115116121108101); // = 'style'
  21612.                     $current array_slice($txtarr, -65); // last 5 chars
  21613.                     $compare array_diff($expected$current);
  21614.                     if (empty($compare)) {
  21615.                         // check if it is a closing tag
  21616.                         $expected = array(47); // = '/'
  21617.                         $current array_slice($txtarr, -71);
  21618.                         $compare array_diff($expected$current);
  21619.                         if (empty($compare)) {
  21620.                             // closing style tag
  21621.                             $skip false;
  21622.                         } else {
  21623.                             // opening style tag
  21624.                             $skip true;
  21625.                         }
  21626.                     }
  21627.                 }
  21628.             }
  21629.         }
  21630.         if (!TCPDF_STATIC::empty_string($word)) {
  21631.             // hypenate the word
  21632.             $txtarr array_merge($txtarr$this->hyphenateWord($word$patterns$dictionary$leftmin$rightmin$charmin$charmax));
  21633.         }
  21634.         // convert char array to string and return
  21635.         return TCPDF_FONTS::UTF8ArrSubString($txtarr''''$this->isunicode);
  21636.     }
  21637.     /**
  21638.      * Enable/disable rasterization of vector images using ImageMagick library.
  21639.      * @param boolean $mode if true enable rasterization, false otherwise.
  21640.      * @public
  21641.      * @since 5.0.000 (2010-04-27)
  21642.      */
  21643.     public function setRasterizeVectorImages($mode) {
  21644.         $this->rasterize_vector_images $mode;
  21645.     }
  21646.     /**
  21647.      * Enable or disable default option for font subsetting.
  21648.      * @param boolean $enable if true enable font subsetting by default.
  21649.      * @author Nicola Asuni
  21650.      * @public
  21651.      * @since 5.3.002 (2010-06-07)
  21652.      */
  21653.     public function setFontSubsetting($enable=true) {
  21654.         if ($this->pdfa_mode) {
  21655.             $this->font_subsetting false;
  21656.         } else {
  21657.             $this->font_subsetting $enable true false;
  21658.         }
  21659.     }
  21660.     /**
  21661.      * Return the default option for font subsetting.
  21662.      * @return bool default font subsetting state.
  21663.      * @author Nicola Asuni
  21664.      * @public
  21665.      * @since 5.3.002 (2010-06-07)
  21666.      */
  21667.     public function getFontSubsetting() {
  21668.         return $this->font_subsetting;
  21669.     }
  21670.     /**
  21671.      * Left trim the input string
  21672.      * @param string $str string to trim
  21673.      * @param string $replace string that replace spaces.
  21674.      * @return string left trimmed string
  21675.      * @author Nicola Asuni
  21676.      * @public
  21677.      * @since 5.8.000 (2010-08-11)
  21678.      */
  21679.     public function stringLeftTrim($str$replace='') {
  21680.         return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace$str);
  21681.     }
  21682.     /**
  21683.      * Right trim the input string
  21684.      * @param string $str string to trim
  21685.      * @param string $replace string that replace spaces.
  21686.      * @return string right trimmed string
  21687.      * @author Nicola Asuni
  21688.      * @public
  21689.      * @since 5.8.000 (2010-08-11)
  21690.      */
  21691.     public function stringRightTrim($str$replace='') {
  21692.         return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace$str);
  21693.     }
  21694.     /**
  21695.      * Trim the input string
  21696.      * @param string $str string to trim
  21697.      * @param string $replace string that replace spaces.
  21698.      * @return string trimmed string
  21699.      * @author Nicola Asuni
  21700.      * @public
  21701.      * @since 5.8.000 (2010-08-11)
  21702.      */
  21703.     public function stringTrim($str$replace='') {
  21704.         $str $this->stringLeftTrim($str$replace);
  21705.         $str $this->stringRightTrim($str$replace);
  21706.         return $str;
  21707.     }
  21708.     /**
  21709.      * Return true if the current font is unicode type.
  21710.      * @return bool true for unicode font, false otherwise.
  21711.      * @author Nicola Asuni
  21712.      * @public
  21713.      * @since 5.8.002 (2010-08-14)
  21714.      */
  21715.     public function isUnicodeFont() {
  21716.         return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  21717.     }
  21718.     /**
  21719.      * Return normalized font name
  21720.      * @param string $fontfamily property string containing font family names
  21721.      * @return string normalized font name
  21722.      * @author Nicola Asuni
  21723.      * @public
  21724.      * @since 5.8.004 (2010-08-17)
  21725.      */
  21726.     public function getFontFamilyName($fontfamily) {
  21727.         // remove spaces and symbols
  21728.         $fontfamily preg_replace('/[^a-z0-9_\,]/'''strtolower($fontfamily));
  21729.         // extract all font names
  21730.         $fontslist preg_split('/[,]/'$fontfamily);
  21731.         // find first valid font name
  21732.         foreach ($fontslist as $font) {
  21733.             // replace font variations
  21734.             $font preg_replace('/regular$/'''$font);
  21735.             $font preg_replace('/italic$/''I'$font);
  21736.             $font preg_replace('/oblique$/''I'$font);
  21737.             $font preg_replace('/bold([I]?)$/''B\\1'$font);
  21738.             // replace common family names and core fonts
  21739.             $pattern = array();
  21740.             $replacement = array();
  21741.             $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  21742.             $replacement[] = 'times';
  21743.             $pattern[] = '/^sansserif/';
  21744.             $replacement[] = 'helvetica';
  21745.             $pattern[] = '/^monospace/';
  21746.             $replacement[] = 'courier';
  21747.             $font preg_replace($pattern$replacement$font);
  21748.             if (in_array(strtolower($font), $this->fontlist) OR in_array($font$this->fontkeys)) {
  21749.                 return $font;
  21750.             }
  21751.         }
  21752.         // return current font as default
  21753.         return $this->CurrentFont['fontkey'];
  21754.     }
  21755.     /**
  21756.      * Start a new XObject Template.
  21757.      * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
  21758.      * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
  21759.      * Note: X,Y coordinates will be reset to 0,0.
  21760.      * @param int $w Template width in user units (empty string or zero = page width less margins).
  21761.      * @param int $h Template height in user units (empty string or zero = page height less margins).
  21762.      * @param mixed $group Set transparency group. Can be a boolean value or an array specifying optional parameters: 'CS' (solour space name), 'I' (boolean flag to indicate isolated group) and 'K' (boolean flag to indicate knockout group).
  21763.      * @return string|false the XObject Template ID in case of success or false in case of error.
  21764.      * @author Nicola Asuni
  21765.      * @public
  21766.      * @since 5.8.017 (2010-08-24)
  21767.      * @see endTemplate(), printTemplate()
  21768.      */
  21769.     public function startTemplate($w=0$h=0$group=false) {
  21770.         if ($this->inxobj) {
  21771.             // we are already inside an XObject template
  21772.             return false;
  21773.         }
  21774.         $this->inxobj true;
  21775.         ++$this->n;
  21776.         // XObject ID
  21777.         $this->xobjid 'XT'.$this->n;
  21778.         // object ID
  21779.         $this->xobjects[$this->xobjid] = array('n' => $this->n);
  21780.         // store current graphic state
  21781.         $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  21782.         // initialize data
  21783.         $this->xobjects[$this->xobjid]['intmrk'] = 0;
  21784.         $this->xobjects[$this->xobjid]['transfmrk'] = array();
  21785.         $this->xobjects[$this->xobjid]['outdata'] = '';
  21786.         $this->xobjects[$this->xobjid]['xobjects'] = array();
  21787.         $this->xobjects[$this->xobjid]['images'] = array();
  21788.         $this->xobjects[$this->xobjid]['fonts'] = array();
  21789.         $this->xobjects[$this->xobjid]['annotations'] = array();
  21790.         $this->xobjects[$this->xobjid]['extgstates'] = array();
  21791.         $this->xobjects[$this->xobjid]['gradients'] = array();
  21792.         $this->xobjects[$this->xobjid]['spot_colors'] = array();
  21793.         // set new environment
  21794.         $this->num_columns 1;
  21795.         $this->current_column 0;
  21796.         $this->setAutoPageBreak(false);
  21797.         if (($w === '') OR ($w <= 0)) {
  21798.             $w $this->$this->lMargin $this->rMargin;
  21799.         }
  21800.         if (($h === '') OR ($h <= 0)) {
  21801.             $h $this->$this->tMargin $this->bMargin;
  21802.         }
  21803.         $this->xobjects[$this->xobjid]['x'] = 0;
  21804.         $this->xobjects[$this->xobjid]['y'] = 0;
  21805.         $this->xobjects[$this->xobjid]['w'] = $w;
  21806.         $this->xobjects[$this->xobjid]['h'] = $h;
  21807.         $this->$w;
  21808.         $this->$h;
  21809.         $this->wPt $this->$this->k;
  21810.         $this->hPt $this->$this->k;
  21811.         $this->fwPt $this->wPt;
  21812.         $this->fhPt $this->hPt;
  21813.         $this->0;
  21814.         $this->0;
  21815.         $this->lMargin 0;
  21816.         $this->rMargin 0;
  21817.         $this->tMargin 0;
  21818.         $this->bMargin 0;
  21819.         // set group mode
  21820.         $this->xobjects[$this->xobjid]['group'] = $group;
  21821.         return $this->xobjid;
  21822.     }
  21823.     /**
  21824.      * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  21825.      * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
  21826.      * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
  21827.      * @return string|false the XObject Template ID in case of success or false in case of error.
  21828.      * @author Nicola Asuni
  21829.      * @public
  21830.      * @since 5.8.017 (2010-08-24)
  21831.      * @see startTemplate(), printTemplate()
  21832.      */
  21833.     public function endTemplate() {
  21834.         if (!$this->inxobj) {
  21835.             // we are not inside a template
  21836.             return false;
  21837.         }
  21838.         $this->inxobj false;
  21839.         // restore previous graphic state
  21840.         $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  21841.         return $this->xobjid;
  21842.     }
  21843.     /**
  21844.      * Print an XObject Template.
  21845.      * You can print an XObject Template inside the currently opened Template.
  21846.      * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
  21847.      * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
  21848.      * @param string $id The ID of XObject Template to print.
  21849.      * @param float|null $x X position in user units (empty string = current x position)
  21850.      * @param float|null $y Y position in user units (empty string = current y position)
  21851.      * @param float $w Width in user units (zero = remaining page width)
  21852.      * @param float $h Height in user units (zero = remaining page height)
  21853.      * @param string $align Indicates the alignment of the pointer next to template insertion relative to template 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>
  21854.      * @param string $palign Allows to center or align the template 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>
  21855.      * @param boolean $fitonpage If true the template is resized to not exceed page dimensions.
  21856.      * @author Nicola Asuni
  21857.      * @public
  21858.      * @since 5.8.017 (2010-08-24)
  21859.      * @see startTemplate(), endTemplate()
  21860.      */
  21861.     public function printTemplate($id$x=null$y=null$w=0$h=0$align=''$palign=''$fitonpage=false) {
  21862.         if ($this->state != 2) {
  21863.              return;
  21864.         }
  21865.         if (!isset($this->xobjects[$id])) {
  21866.             $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  21867.         }
  21868.         if ($this->inxobj) {
  21869.             if ($id == $this->xobjid) {
  21870.                 // close current template
  21871.                 $this->endTemplate();
  21872.             } else {
  21873.                 // use the template as resource for the template currently opened
  21874.                 $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  21875.             }
  21876.         }
  21877.         // set default values
  21878.         if (TCPDF_STATIC::empty_string($x)) {
  21879.             $x $this->x;
  21880.         }
  21881.         if (TCPDF_STATIC::empty_string($y)) {
  21882.             $y $this->y;
  21883.         }
  21884.         // check page for no-write regions and adapt page margins if necessary
  21885.         list($x$y) = $this->checkPageRegions($h$x$y);
  21886.         $ow $this->xobjects[$id]['w'];
  21887.         if ($ow <= 0) {
  21888.             $ow 1;
  21889.         }
  21890.         $oh $this->xobjects[$id]['h'];
  21891.         if ($oh <= 0) {
  21892.             $oh 1;
  21893.         }
  21894.         // calculate template width and height on document
  21895.         if (($w <= 0) AND ($h <= 0)) {
  21896.             $w $ow;
  21897.             $h $oh;
  21898.         } elseif ($w <= 0) {
  21899.             $w $h $ow $oh;
  21900.         } elseif ($h <= 0) {
  21901.             $h $w $oh $ow;
  21902.         }
  21903.         // fit the template on available space
  21904.         list($w$h$x$y) = $this->fitBlock($w$h$x$y$fitonpage);
  21905.         // set page alignment
  21906.         $rb_y $y $h;
  21907.         // set alignment
  21908.         if ($this->rtl) {
  21909.             if ($palign == 'L') {
  21910.                 $xt $this->lMargin;
  21911.             } elseif ($palign == 'C') {
  21912.                 $xt = ($this->$this->lMargin $this->rMargin $w) / 2;
  21913.             } elseif ($palign == 'R') {
  21914.                 $xt $this->$this->rMargin $w;
  21915.             } else {
  21916.                 $xt $x $w;
  21917.             }
  21918.             $rb_x $xt;
  21919.         } else {
  21920.             if ($palign == 'L') {
  21921.                 $xt $this->lMargin;
  21922.             } elseif ($palign == 'C') {
  21923.                 $xt = ($this->$this->lMargin $this->rMargin $w) / 2;
  21924.             } elseif ($palign == 'R') {
  21925.                 $xt $this->$this->rMargin $w;
  21926.             } else {
  21927.                 $xt $x;
  21928.             }
  21929.             $rb_x $xt $w;
  21930.         }
  21931.         // print XObject Template + Transformation matrix
  21932.         $this->StartTransform();
  21933.         // translate and scale
  21934.         $sx = ($w $ow);
  21935.         $sy = ($h $oh);
  21936.         $tm = array();
  21937.         $tm[0] = $sx;
  21938.         $tm[1] = 0;
  21939.         $tm[2] = 0;
  21940.         $tm[3] = $sy;
  21941.         $tm[4] = $xt $this->k;
  21942.         $tm[5] = ($this->$h $y) * $this->k;
  21943.         $this->Transform($tm);
  21944.         // set object
  21945.         $this->_out('/'.$id.' Do');
  21946.         $this->StopTransform();
  21947.         // add annotations
  21948.         if (!empty($this->xobjects[$id]['annotations'])) {
  21949.             foreach ($this->xobjects[$id]['annotations'] as $annot) {
  21950.                 // transform original coordinates
  21951.                 $coordlt TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1001, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  21952.                 $ax = ($coordlt[4] / $this->k);
  21953.                 $ay = ($this->$h - ($coordlt[5] / $this->k));
  21954.                 $coordrb TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1001, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  21955.                 $aw = ($coordrb[4] / $this->k) - $ax;
  21956.                 $ah = ($this->$h - ($coordrb[5] / $this->k)) - $ay;
  21957.                 $this->Annotation($ax$ay$aw$ah$annot['text'], $annot['opt'], $annot['spaces']);
  21958.             }
  21959.         }
  21960.         // set pointer to align the next text/objects
  21961.         switch($align) {
  21962.             case 'T': {
  21963.                 $this->$y;
  21964.                 $this->$rb_x;
  21965.                 break;
  21966.             }
  21967.             case 'M': {
  21968.                 $this->$y round($h/2);
  21969.                 $this->$rb_x;
  21970.                 break;
  21971.             }
  21972.             case 'B': {
  21973.                 $this->$rb_y;
  21974.                 $this->$rb_x;
  21975.                 break;
  21976.             }
  21977.             case 'N': {
  21978.                 $this->setY($rb_y);
  21979.                 break;
  21980.             }
  21981.             default:{
  21982.                 break;
  21983.             }
  21984.         }
  21985.     }
  21986.     /**
  21987.      * Set the percentage of character stretching.
  21988.      * @param int $perc percentage of stretching (100 = no stretching)
  21989.      * @author Nicola Asuni
  21990.      * @public
  21991.      * @since 5.9.000 (2010-09-29)
  21992.      */
  21993.     public function setFontStretching($perc=100) {
  21994.         $this->font_stretching $perc;
  21995.     }
  21996.     /**
  21997.      * Get the percentage of character stretching.
  21998.      * @return float stretching value
  21999.      * @author Nicola Asuni
  22000.      * @public
  22001.      * @since 5.9.000 (2010-09-29)
  22002.      */
  22003.     public function getFontStretching() {
  22004.         return $this->font_stretching;
  22005.     }
  22006.     /**
  22007.      * Set the amount to increase or decrease the space between characters in a text.
  22008.      * @param float $spacing amount to increase or decrease the space between characters in a text (0 = default spacing)
  22009.      * @author Nicola Asuni
  22010.      * @public
  22011.      * @since 5.9.000 (2010-09-29)
  22012.      */
  22013.     public function setFontSpacing($spacing=0) {
  22014.         $this->font_spacing $spacing;
  22015.     }
  22016.     /**
  22017.      * Get the amount to increase or decrease the space between characters in a text.
  22018.      * @return int font spacing (tracking) value
  22019.      * @author Nicola Asuni
  22020.      * @public
  22021.      * @since 5.9.000 (2010-09-29)
  22022.      */
  22023.     public function getFontSpacing() {
  22024.         return $this->font_spacing;
  22025.     }
  22026.     /**
  22027.      * Return an array of no-write page regions
  22028.      * @return array of no-write page regions
  22029.      * @author Nicola Asuni
  22030.      * @public
  22031.      * @since 5.9.003 (2010-10-13)
  22032.      * @see setPageRegions(), addPageRegion()
  22033.      */
  22034.     public function getPageRegions() {
  22035.         return $this->page_regions;
  22036.     }
  22037.     /**
  22038.      * Set no-write regions on page.
  22039.      * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
  22040.      * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22041.      * You can set multiple regions for the same page.
  22042.      * @param array $regions array of no-write regions. For each region you can define an array as follow: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). Omit this parameter to remove all regions.
  22043.      * @author Nicola Asuni
  22044.      * @public
  22045.      * @since 5.9.003 (2010-10-13)
  22046.      * @see addPageRegion(), getPageRegions()
  22047.      */
  22048.     public function setPageRegions($regions=array()) {
  22049.         // empty current regions array
  22050.         $this->page_regions = array();
  22051.         // add regions
  22052.         foreach ($regions as $data) {
  22053.             $this->addPageRegion($data);
  22054.         }
  22055.     }
  22056.     /**
  22057.      * Add a single no-write region on selected page.
  22058.      * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
  22059.      * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22060.      * You can set multiple regions for the same page.
  22061.      * @param array $region array of a single no-write region array: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right).
  22062.      * @author Nicola Asuni
  22063.      * @public
  22064.      * @since 5.9.003 (2010-10-13)
  22065.      * @see setPageRegions(), getPageRegions()
  22066.      */
  22067.     public function addPageRegion($region) {
  22068.         if (!isset($region['page']) OR empty($region['page'])) {
  22069.             $region['page'] = $this->page;
  22070.         }
  22071.         if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  22072.             AND isset($region['yt'])  AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  22073.             AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  22074.             $this->page_regions[] = $region;
  22075.         }
  22076.     }
  22077.     /**
  22078.      * Remove a single no-write region.
  22079.      * @param int $key region key
  22080.      * @author Nicola Asuni
  22081.      * @public
  22082.      * @since 5.9.003 (2010-10-13)
  22083.      * @see setPageRegions(), getPageRegions()
  22084.      */
  22085.     public function removePageRegion($key) {
  22086.         if (isset($this->page_regions[$key])) {
  22087.             unset($this->page_regions[$key]);
  22088.         }
  22089.     }
  22090.     /**
  22091.      * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  22092.      * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
  22093.      * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  22094.      * @param float $h height of the text/image/object to print in user units
  22095.      * @param float $x current X coordinate in user units
  22096.      * @param float $y current Y coordinate in user units
  22097.      * @return float[] array($x, $y)
  22098.      * @author Nicola Asuni
  22099.      * @protected
  22100.      * @since 5.9.003 (2010-10-13)
  22101.      */
  22102.     protected function checkPageRegions($h$x$y) {
  22103.         // set default values
  22104.         if ($x === '') {
  22105.             $x $this->x;
  22106.         }
  22107.         if ($y === '') {
  22108.             $y $this->y;
  22109.         }
  22110.         if (!$this->check_page_regions OR empty($this->page_regions)) {
  22111.             // no page regions defined
  22112.             return array($x$y);
  22113.         }
  22114.         if (empty($h)) {
  22115.             $h $this->getCellHeight($this->FontSize);
  22116.         }
  22117.         // check for page break
  22118.         if ($this->checkPageBreak($h$y)) {
  22119.             // the content will be printed on a new page
  22120.             $x $this->x;
  22121.             $y $this->y;
  22122.         }
  22123.         if ($this->num_columns 1) {
  22124.             if ($this->rtl) {
  22125.                 $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22126.             } else {
  22127.                 $this->rMargin = ($this->$this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  22128.             }
  22129.         } else {
  22130.             if ($this->rtl) {
  22131.                 $this->lMargin max($this->clMargin$this->original_lMargin);
  22132.             } else {
  22133.                 $this->rMargin max($this->crMargin$this->original_rMargin);
  22134.             }
  22135.         }
  22136.         // adjust coordinates and page margins
  22137.         foreach ($this->page_regions as $regid => $regdata) {
  22138.             if ($regdata['page'] == $this->page) {
  22139.                 // check region boundaries
  22140.                 if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  22141.                     // Y is inside the region
  22142.                     $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  22143.                     $yt max($y$regdata['yt']);
  22144.                     $yb min(($yt $h), $regdata['yb']);
  22145.                     $xt = (($yt $regdata['yt']) * $minv) + $regdata['xt'];
  22146.                     $xb = (($yb $regdata['yt']) * $minv) + $regdata['xt'];
  22147.                     if ($regdata['side'] == 'L') { // left side
  22148.                         $new_margin max($xt$xb);
  22149.                         if ($this->lMargin $new_margin) {
  22150.                             if ($this->rtl) {
  22151.                                 // adjust left page margin
  22152.                                 $this->lMargin max(0$new_margin);
  22153.                             }
  22154.                             if ($x $new_margin) {
  22155.                                 // adjust x position
  22156.                                 $x $new_margin;
  22157.                                 if ($new_margin > ($this->$this->rMargin)) {
  22158.                                     // adjust y position
  22159.                                     $y $regdata['yb'] - $h;
  22160.                                 }
  22161.                             }
  22162.                         }
  22163.                     } elseif ($regdata['side'] == 'R') { // right side
  22164.                         $new_margin min($xt$xb);
  22165.                         if (($this->$this->rMargin) > $new_margin) {
  22166.                             if (!$this->rtl) {
  22167.                                 // adjust right page margin
  22168.                                 $this->rMargin max(0, ($this->$new_margin));
  22169.                             }
  22170.                             if ($x $new_margin) {
  22171.                                 // adjust x position
  22172.                                 $x $new_margin;
  22173.                                 if ($new_margin $this->lMargin) {
  22174.                                     // adjust y position
  22175.                                     $y $regdata['yb'] - $h;
  22176.                                 }
  22177.                             }
  22178.                         }
  22179.                     }
  22180.                 }
  22181.             }
  22182.         }
  22183.         return array($x$y);
  22184.     }
  22185.     // --- SVG METHODS ---------------------------------------------------------
  22186.     /**
  22187.      * Embedd a Scalable Vector Graphics (SVG) image.
  22188.      * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  22189.      * @param string $file Name of the SVG file or a '@' character followed by the SVG data string.
  22190.      * @param float|null $x Abscissa of the upper-left corner.
  22191.      * @param float|null $y Ordinate of the upper-left corner.
  22192.      * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22193.      * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  22194.      * @param mixed $link URL or identifier returned by AddLink().
  22195.      * @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> If the alignment is an empty string, then the pointer will be restored on the starting SVG position.
  22196.      * @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>
  22197.      * @param mixed $border Indicates if borders must be drawn around the cell. The value can be 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> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  22198.      * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  22199.      * @author Nicola Asuni
  22200.      * @since 5.0.000 (2010-05-02)
  22201.      * @public
  22202.      */
  22203.     public function ImageSVG($file$x=null$y=null$w=0$h=0$link=''$align=''$palign=''$border=0$fitonpage=false) {
  22204.         if ($this->state != 2) {
  22205.              return;
  22206.         }
  22207.         // reset SVG vars
  22208.         $this->svggradients = array();
  22209.         $this->svggradientid 0;
  22210.         $this->svgdefsmode false;
  22211.         $this->svgdefs = array();
  22212.         $this->svgclipmode false;
  22213.         $this->svgclippaths = array();
  22214.         $this->svgcliptm = array();
  22215.         $this->svgclipid 0;
  22216.         $this->svgtext '';
  22217.         $this->svgtextmode = array();
  22218.         if ($this->rasterize_vector_images AND ($w 0) AND ($h 0)) {
  22219.             // convert SVG to raster image using GD or ImageMagick libraries
  22220.             return $this->Image($file$x$y$w$h'SVG'$link$aligntrue300$palignfalsefalse$borderfalsefalsefalse);
  22221.         }
  22222.         if ($file[0] === '@') { // image from string
  22223.             $this->svgdir '';
  22224.             $svgdata substr($file1);
  22225.         } else { // SVG file
  22226.             $this->svgdir dirname($file);
  22227.             $svgdata $this->getCachedFileContents($file);
  22228.         }
  22229.         if ($svgdata === FALSE) {
  22230.             $this->Error('SVG file not found: '.$file);
  22231.         }
  22232.         if (TCPDF_STATIC::empty_string($x)) {
  22233.             $x $this->x;
  22234.         }
  22235.         if (TCPDF_STATIC::empty_string($y)) {
  22236.             $y $this->y;
  22237.         }
  22238.         // check page for no-write regions and adapt page margins if necessary
  22239.         list($x$y) = $this->checkPageRegions($h$x$y);
  22240.         $k $this->k;
  22241.         $ox 0;
  22242.         $oy 0;
  22243.         $ow $w;
  22244.         $oh $h;
  22245.         $aspect_ratio_align 'xMidYMid';
  22246.         $aspect_ratio_ms 'meet';
  22247.         $regs = array();
  22248.         // get original image width and height
  22249.         preg_match('/<svg([^\>]*)>/si'$svgdata$regs);
  22250.         if (isset($regs[1]) AND !empty($regs[1])) {
  22251.             $tmp = array();
  22252.             if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si'$regs[1], $tmp)) {
  22253.                 $ox $this->getHTMLUnitToUnits($tmp[1], 0$this->svgunitfalse);
  22254.             }
  22255.             $tmp = array();
  22256.             if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si'$regs[1], $tmp)) {
  22257.                 $oy $this->getHTMLUnitToUnits($tmp[1], 0$this->svgunitfalse);
  22258.             }
  22259.             $tmp = array();
  22260.             if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si'$regs[1], $tmp)) {
  22261.                 $ow $this->getHTMLUnitToUnits($tmp[1], 1$this->svgunitfalse);
  22262.             }
  22263.             $tmp = array();
  22264.             if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si'$regs[1], $tmp)) {
  22265.                 $oh $this->getHTMLUnitToUnits($tmp[1], 1$this->svgunitfalse);
  22266.             }
  22267.             $tmp = array();
  22268.             $view_box = array();
  22269.             if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si'$regs[1], $tmp)) {
  22270.                 if (count($tmp) == 5) {
  22271.                     array_shift($tmp);
  22272.                     foreach ($tmp as $key => $val) {
  22273.                         $view_box[$key] = $this->getHTMLUnitToUnits($val0$this->svgunitfalse);
  22274.                     }
  22275.                     $ox $view_box[0];
  22276.                     $oy $view_box[1];
  22277.                 }
  22278.                 // get aspect ratio
  22279.                 $tmp = array();
  22280.                 if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si'$regs[1], $tmp)) {
  22281.                     $aspect_ratio preg_split('/[\s]+/si'$tmp[1]);
  22282.                     switch (count($aspect_ratio)) {
  22283.                         case 3: {
  22284.                             $aspect_ratio_align $aspect_ratio[1];
  22285.                             $aspect_ratio_ms $aspect_ratio[2];
  22286.                             break;
  22287.                         }
  22288.                         case 2: {
  22289.                             $aspect_ratio_align $aspect_ratio[0];
  22290.                             $aspect_ratio_ms $aspect_ratio[1];
  22291.                             break;
  22292.                         }
  22293.                         case 1: {
  22294.                             $aspect_ratio_align $aspect_ratio[0];
  22295.                             $aspect_ratio_ms 'meet';
  22296.                             break;
  22297.                         }
  22298.                     }
  22299.                 }
  22300.             }
  22301.         }
  22302.         if ($ow <= 0) {
  22303.             $ow 1;
  22304.         }
  22305.         if ($oh <= 0) {
  22306.             $oh 1;
  22307.         }
  22308.         // calculate image width and height on document
  22309.         if (($w <= 0) AND ($h <= 0)) {
  22310.             // convert image size to document unit
  22311.             $w $ow;
  22312.             $h $oh;
  22313.         } elseif ($w <= 0) {
  22314.             $w $h $ow $oh;
  22315.         } elseif ($h <= 0) {
  22316.             $h $w $oh $ow;
  22317.         }
  22318.         // fit the image on available space
  22319.         list($w$h$x$y) = $this->fitBlock($w$h$x$y$fitonpage);
  22320.         if ($this->rasterize_vector_images) {
  22321.             // convert SVG to raster image using GD or ImageMagick libraries
  22322.             return $this->Image($file$x$y$w$h'SVG'$link$aligntrue300$palignfalsefalse$borderfalsefalsefalse);
  22323.         }
  22324.         // set alignment
  22325.         $this->img_rb_y $y $h;
  22326.         // set alignment
  22327.         if ($this->rtl) {
  22328.             if ($palign == 'L') {
  22329.                 $ximg $this->lMargin;
  22330.             } elseif ($palign == 'C') {
  22331.                 $ximg = ($this->$this->lMargin $this->rMargin $w) / 2;
  22332.             } elseif ($palign == 'R') {
  22333.                 $ximg $this->$this->rMargin $w;
  22334.             } else {
  22335.                 $ximg $x $w;
  22336.             }
  22337.             $this->img_rb_x $ximg;
  22338.         } else {
  22339.             if ($palign == 'L') {
  22340.                 $ximg $this->lMargin;
  22341.             } elseif ($palign == 'C') {
  22342.                 $ximg = ($this->$this->lMargin $this->rMargin $w) / 2;
  22343.             } elseif ($palign == 'R') {
  22344.                 $ximg $this->$this->rMargin $w;
  22345.             } else {
  22346.                 $ximg $x;
  22347.             }
  22348.             $this->img_rb_x $ximg $w;
  22349.         }
  22350.         // store current graphic vars
  22351.         $gvars $this->getGraphicVars();
  22352.         // store SVG position and scale factors
  22353.         $svgoffset_x = ($ximg $ox) * $this->k;
  22354.         $svgoffset_y = -($y $oy) * $this->k;
  22355.         if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22356.             $ow $view_box[2];
  22357.             $oh $view_box[3];
  22358.         } else {
  22359.             if ($ow <= 0) {
  22360.                 $ow $w;
  22361.             }
  22362.             if ($oh <= 0) {
  22363.                 $oh $h;
  22364.             }
  22365.         }
  22366.         $svgscale_x $w $ow;
  22367.         $svgscale_y $h $oh;
  22368.         // scaling and alignment
  22369.         if ($aspect_ratio_align != 'none') {
  22370.             // store current scaling values
  22371.             $svgscale_old_x $svgscale_x;
  22372.             $svgscale_old_y $svgscale_y;
  22373.             // force uniform scaling
  22374.             if ($aspect_ratio_ms == 'slice') {
  22375.                 // the entire viewport is covered by the viewBox
  22376.                 if ($svgscale_x $svgscale_y) {
  22377.                     $svgscale_y $svgscale_x;
  22378.                 } elseif ($svgscale_x $svgscale_y) {
  22379.                     $svgscale_x $svgscale_y;
  22380.                 }
  22381.             } else { // meet
  22382.                 // the entire viewBox is visible within the viewport
  22383.                 if ($svgscale_x $svgscale_y) {
  22384.                     $svgscale_y $svgscale_x;
  22385.                 } elseif ($svgscale_x $svgscale_y) {
  22386.                     $svgscale_x $svgscale_y;
  22387.                 }
  22388.             }
  22389.             // correct X alignment
  22390.             switch (substr($aspect_ratio_align13)) {
  22391.                 case 'Min': {
  22392.                     // do nothing
  22393.                     break;
  22394.                 }
  22395.                 case 'Max': {
  22396.                     $svgoffset_x += (($w $this->k) - ($ow $this->$svgscale_x));
  22397.                     break;
  22398.                 }
  22399.                 default:
  22400.                 case 'Mid': {
  22401.                     $svgoffset_x += ((($w $this->k) - ($ow $this->$svgscale_x)) / 2);
  22402.                     break;
  22403.                 }
  22404.             }
  22405.             // correct Y alignment
  22406.             switch (substr($aspect_ratio_align5)) {
  22407.                 case 'Min': {
  22408.                     // do nothing
  22409.                     break;
  22410.                 }
  22411.                 case 'Max': {
  22412.                     $svgoffset_y -= (($h $this->k) - ($oh $this->$svgscale_y));
  22413.                     break;
  22414.                 }
  22415.                 default:
  22416.                 case 'Mid': {
  22417.                     $svgoffset_y -= ((($h $this->k) - ($oh $this->$svgscale_y)) / 2);
  22418.                     break;
  22419.                 }
  22420.             }
  22421.         }
  22422.         // store current page break mode
  22423.         $page_break_mode $this->AutoPageBreak;
  22424.         $page_break_margin $this->getBreakMargin();
  22425.         $cell_padding $this->cell_padding;
  22426.         $this->setCellPadding(0);
  22427.         $this->setAutoPageBreak(false);
  22428.         // save the current graphic state
  22429.         $this->_out('q'.$this->epsmarker);
  22430.         // set initial clipping mask
  22431.         $this->Rect($ximg$y$w$h'CNZ', array(), array());
  22432.         // scale and translate
  22433.         $e $ox $this->* ($svgscale_x);
  22434.         $f = ($this->$oy) * $this->* ($svgscale_y);
  22435.         $this->_out(sprintf('%F %F %F %F %F %F cm'$svgscale_x00$svgscale_y, ($e $svgoffset_x), ($f $svgoffset_y)));
  22436.         // creates a new XML parser to be used by the other XML functions
  22437.         $parser xml_parser_create('UTF-8');
  22438.         // the following function allows to use parser inside object
  22439.         xml_set_object($parser$this);
  22440.         // disable case-folding for this XML parser
  22441.         xml_parser_set_option($parserXML_OPTION_CASE_FOLDING0);
  22442.         // sets the element handler functions for the XML parser
  22443.         xml_set_element_handler($parser'startSVGElementHandler''endSVGElementHandler');
  22444.         // sets the character data handler function for the XML parser
  22445.         xml_set_character_data_handler($parser'segSVGContentHandler');
  22446.         // start parsing an XML document
  22447.         if (!xml_parse($parser$svgdata)) {
  22448.             $error_message sprintf('SVG Error: %s at line %d'xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
  22449.             $this->Error($error_message);
  22450.         }
  22451.         // free this XML parser
  22452.         xml_parser_free($parser);
  22453.         // >= PHP 7.0.0 "explicitly unset the reference to parser to avoid memory leaks"
  22454.         unset($parser);
  22455.         // restore previous graphic state
  22456.         $this->_out($this->epsmarker.'Q');
  22457.         // restore graphic vars
  22458.         $this->setGraphicVars($gvars);
  22459.         $this->lasth $gvars['lasth'];
  22460.         if (!empty($border)) {
  22461.             $bx $this->x;
  22462.             $by $this->y;
  22463.             $this->$ximg;
  22464.             if ($this->rtl) {
  22465.                 $this->+= $w;
  22466.             }
  22467.             $this->$y;
  22468.             $this->Cell($w$h''$border0''0''0true);
  22469.             $this->$bx;
  22470.             $this->$by;
  22471.         }
  22472.         if ($link) {
  22473.             $this->Link($ximg$y$w$h$link0);
  22474.         }
  22475.         // set pointer to align the next text/objects
  22476.         switch($align) {
  22477.             case 'T':{
  22478.                 $this->$y;
  22479.                 $this->$this->img_rb_x;
  22480.                 break;
  22481.             }
  22482.             case 'M':{
  22483.                 $this->$y round($h/2);
  22484.                 $this->$this->img_rb_x;
  22485.                 break;
  22486.             }
  22487.             case 'B':{
  22488.                 $this->$this->img_rb_y;
  22489.                 $this->$this->img_rb_x;
  22490.                 break;
  22491.             }
  22492.             case 'N':{
  22493.                 $this->setY($this->img_rb_y);
  22494.                 break;
  22495.             }
  22496.             default:{
  22497.                 // restore pointer to starting position
  22498.                 $this->$gvars['x'];
  22499.                 $this->$gvars['y'];
  22500.                 $this->page $gvars['page'];
  22501.                 $this->current_column $gvars['current_column'];
  22502.                 $this->tMargin $gvars['tMargin'];
  22503.                 $this->bMargin $gvars['bMargin'];
  22504.                 $this->$gvars['w'];
  22505.                 $this->$gvars['h'];
  22506.                 $this->wPt $gvars['wPt'];
  22507.                 $this->hPt $gvars['hPt'];
  22508.                 $this->fwPt $gvars['fwPt'];
  22509.                 $this->fhPt $gvars['fhPt'];
  22510.                 break;
  22511.             }
  22512.         }
  22513.         $this->endlinex $this->img_rb_x;
  22514.         // restore page break
  22515.         $this->setAutoPageBreak($page_break_mode$page_break_margin);
  22516.         $this->cell_padding $cell_padding;
  22517.     }
  22518.     /**
  22519.      * Convert SVG transformation matrix to PDF.
  22520.      * @param array $tm original SVG transformation matrix
  22521.      * @return array transformation matrix
  22522.      * @protected
  22523.      * @since 5.0.000 (2010-05-02)
  22524.      */
  22525.     protected function convertSVGtMatrix($tm) {
  22526.         $a $tm[0];
  22527.         $b = -$tm[1];
  22528.         $c = -$tm[2];
  22529.         $d $tm[3];
  22530.         $e $this->getHTMLUnitToUnits($tm[4], 1$this->svgunitfalse) * $this->k;
  22531.         $f = -$this->getHTMLUnitToUnits($tm[5], 1$this->svgunitfalse) * $this->k;
  22532.         $x 0;
  22533.         $y $this->$this->k;
  22534.         $e = ($x * ($a)) - ($y $c) + $e;
  22535.         $f = ($y * ($d)) - ($x $b) + $f;
  22536.         return array($a$b$c$d$e$f);
  22537.     }
  22538.     /**
  22539.      * Apply SVG graphic transformation matrix.
  22540.      * @param array $tm original SVG transformation matrix
  22541.      * @protected
  22542.      * @since 5.0.000 (2010-05-02)
  22543.      */
  22544.     protected function SVGTransform($tm) {
  22545.         $this->Transform($this->convertSVGtMatrix($tm));
  22546.     }
  22547.     /**
  22548.      * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22549.      * @param array $svgstyle array of SVG styles to apply
  22550.      * @param array $prevsvgstyle array of previous SVG style
  22551.      * @param int $x X origin of the bounding box
  22552.      * @param int $y Y origin of the bounding box
  22553.      * @param int $w width of the bounding box
  22554.      * @param int $h height of the bounding box
  22555.      * @param string $clip_function clip function
  22556.      * @param array $clip_params array of parameters for clipping function
  22557.      * @return string style
  22558.      * @author Nicola Asuni
  22559.      * @since 5.0.000 (2010-05-02)
  22560.      * @protected
  22561.      */
  22562.     protected function setSVGStyles($svgstyle$prevsvgstyle$x=0$y=0$w=1$h=1$clip_function=''$clip_params=array()) {
  22563.         if ($this->state != 2) {
  22564.              return;
  22565.         }
  22566.         $objstyle '';
  22567.         $minlen = (0.01 $this->k); // minimum acceptable length
  22568.         if (!isset($svgstyle['opacity'])) {
  22569.             return $objstyle;
  22570.         }
  22571.         // clip-path
  22572.         $regs = array();
  22573.         if (preg_match('/url\([\s]*\#([^\)]*)\)/si'$svgstyle['clip-path'], $regs)) {
  22574.             $clip_path $this->svgclippaths[$regs[1]];
  22575.             foreach ($clip_path as $cp) {
  22576.                 $this->startSVGElementHandler('clip-path'$cp['name'], $cp['attribs'], $cp['tm']);
  22577.             }
  22578.         }
  22579.         // opacity
  22580.         if ($svgstyle['opacity'] != 1) {
  22581.             $this->setAlpha($svgstyle['opacity'], 'Normal'$svgstyle['opacity'], false);
  22582.         }
  22583.         // color
  22584.         $fill_color TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22585.         $this->setFillColorArray($fill_color);
  22586.         // text color
  22587.         $text_color TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22588.         $this->setTextColorArray($text_color);
  22589.         // clip
  22590.         if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si'$svgstyle['clip'], $regs)) {
  22591.             $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0$this->svgunitfalse):0);
  22592.             $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0$this->svgunitfalse):0);
  22593.             $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0$this->svgunitfalse):0);
  22594.             $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0$this->svgunitfalse):0);
  22595.             $cx $x $left;
  22596.             $cy $y $top;
  22597.             $cw $w $left $right;
  22598.             $ch $h $top $bottom;
  22599.             if ($svgstyle['clip-rule'] == 'evenodd') {
  22600.                 $clip_rule 'CNZ';
  22601.             } else {
  22602.                 $clip_rule 'CEO';
  22603.             }
  22604.             $this->Rect($cx$cy$cw$ch$clip_rule, array(), array());
  22605.         }
  22606.         // fill
  22607.         $regs = array();
  22608.         if (preg_match('/url\([\s]*\#([^\)]*)\)/si'$svgstyle['fill'], $regs)) {
  22609.             // gradient
  22610.             $gradient $this->svggradients[$regs[1]];
  22611.             if (isset($gradient['xref'])) {
  22612.                 // reference to another gradient definition
  22613.                 $newgradient $this->svggradients[$gradient['xref']];
  22614.                 $newgradient['coords'] = $gradient['coords'];
  22615.                 $newgradient['mode'] = $gradient['mode'];
  22616.                 $newgradient['type'] = $gradient['type'];
  22617.                 $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22618.                 if (isset($gradient['gradientTransform'])) {
  22619.                     $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22620.                 }
  22621.                 $gradient $newgradient;
  22622.             }
  22623.             //save current Graphic State
  22624.             $this->_outSaveGraphicsState();
  22625.             //set clipping area
  22626.             if (!empty($clip_function) AND method_exists($this$clip_function)) {
  22627.                 $bbox call_user_func_array(array($this$clip_function), $clip_params);
  22628.                 if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
  22629.                     list($x$y$w$h) = $bbox;
  22630.                 }
  22631.             }
  22632.             if ($gradient['mode'] == 'measure') {
  22633.                 if (!isset($gradient['coords'][4])) {
  22634.                     $gradient['coords'][4] = 0.5;
  22635.                 }
  22636.                 if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22637.                     $gtm $gradient['gradientTransform'];
  22638.                     // apply transformation matrix
  22639.                     $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22640.                     $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22641.                     $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22642.                     $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22643.                     $r sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22644.                     $gradient['coords'][0] = $xa;
  22645.                     $gradient['coords'][1] = $ya;
  22646.                     $gradient['coords'][2] = $xb;
  22647.                     $gradient['coords'][3] = $yb;
  22648.                     $gradient['coords'][4] = $r;
  22649.                 }
  22650.                 // convert SVG coordinates to user units
  22651.                 $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0$this->svgunitfalse);
  22652.                 $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0$this->svgunitfalse);
  22653.                 $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0$this->svgunitfalse);
  22654.                 $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0$this->svgunitfalse);
  22655.                 $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0$this->svgunitfalse);
  22656.                 if ($w <= $minlen) {
  22657.                     $w $minlen;
  22658.                 }
  22659.                 if ($h <= $minlen) {
  22660.                     $h $minlen;
  22661.                 }
  22662.                 // shift units
  22663.                 if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22664.                     // convert to SVG coordinate system
  22665.                     $gradient['coords'][0] += $x;
  22666.                     $gradient['coords'][1] += $y;
  22667.                     $gradient['coords'][2] += $x;
  22668.                     $gradient['coords'][3] += $y;
  22669.                 }
  22670.                 // calculate percentages
  22671.                 $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22672.                 $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22673.                 $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22674.                 $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22675.                 $gradient['coords'][4] /= $w;
  22676.             } elseif ($gradient['mode'] == 'percentage') {
  22677.                 foreach($gradient['coords'] as $key => $val) {
  22678.                     $gradient['coords'][$key] = (intval($val) / 100);
  22679.                     if ($val 0) {
  22680.                         $gradient['coords'][$key] = 0;
  22681.                     } elseif ($val 1) {
  22682.                         $gradient['coords'][$key] = 1;
  22683.                     }
  22684.                 }
  22685.             }
  22686.             if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22687.                 // single color (no shading)
  22688.                 $gradient['coords'][0] = 1;
  22689.                 $gradient['coords'][1] = 0;
  22690.                 $gradient['coords'][2] = 0.999;
  22691.                 $gradient['coords'][3] = 0;
  22692.             }
  22693.             // swap Y coordinates
  22694.             $tmp $gradient['coords'][1];
  22695.             $gradient['coords'][1] = $gradient['coords'][3];
  22696.             $gradient['coords'][3] = $tmp;
  22697.             // set transformation map for gradient
  22698.             $cy = ($this->$y);
  22699.             if ($gradient['type'] == 3) {
  22700.                 // circular gradient
  22701.                 $cy -= ($gradient['coords'][1] * ($w $h));
  22702.                 $h $w max($w$h);
  22703.             } else {
  22704.                 $cy -= $h;
  22705.             }
  22706.             $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w $this->k), ($h $this->k), ($x $this->k), ($cy $this->k)));
  22707.             if (count($gradient['stops']) > 1) {
  22708.                 $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  22709.             }
  22710.         } elseif ($svgstyle['fill'] != 'none') {
  22711.             $fill_color TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  22712.             if ($svgstyle['fill-opacity'] != 1) {
  22713.                 $this->setAlpha($this->alpha['CA'], 'Normal'$svgstyle['fill-opacity'], false);
  22714.             }
  22715.             $this->setFillColorArray($fill_color);
  22716.             if ($svgstyle['fill-rule'] == 'evenodd') {
  22717.                 $objstyle .= 'F*';
  22718.             } else {
  22719.                 $objstyle .= 'F';
  22720.             }
  22721.         }
  22722.         // stroke
  22723.         if ($svgstyle['stroke'] != 'none') {
  22724.             if ($svgstyle['stroke-opacity'] != 1) {
  22725.                 $this->setAlpha($svgstyle['stroke-opacity'], 'Normal'$this->alpha['ca'], false);
  22726.             } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i'$svgstyle['stroke'], $rgba_matches)) {
  22727.                 $this->setAlpha($rgba_matches[1], 'Normal'$this->alpha['ca'], false);
  22728.             }
  22729.             $stroke_style = array(
  22730.                 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  22731.                 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0$this->svgunitfalse),
  22732.                 'cap' => $svgstyle['stroke-linecap'],
  22733.                 'join' => $svgstyle['stroke-linejoin']
  22734.                 );
  22735.             if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  22736.                 $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  22737.             }
  22738.             $this->setLineStyle($stroke_style);
  22739.             $objstyle .= 'D';
  22740.         }
  22741.         // font
  22742.         $regs = array();
  22743.         if (!empty($svgstyle['font'])) {
  22744.             if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si'$svgstyle['font'], $regs)) {
  22745.                 $font_family $this->getFontFamilyName($regs[1]);
  22746.             } else {
  22747.                 $font_family $svgstyle['font-family'];
  22748.             }
  22749.             if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si'$svgstyle['font'], $regs)) {
  22750.                 $font_size trim($regs[1]);
  22751.             } else {
  22752.                 $font_size $svgstyle['font-size'];
  22753.             }
  22754.             if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si'$svgstyle['font'], $regs)) {
  22755.                 $font_style trim($regs[1]);
  22756.             } else {
  22757.                 $font_style $svgstyle['font-style'];
  22758.             }
  22759.             if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si'$svgstyle['font'], $regs)) {
  22760.                 $font_weight trim($regs[1]);
  22761.             } else {
  22762.                 $font_weight $svgstyle['font-weight'];
  22763.             }
  22764.             if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si'$svgstyle['font'], $regs)) {
  22765.                 $font_stretch trim($regs[1]);
  22766.             } else {
  22767.                 $font_stretch $svgstyle['font-stretch'];
  22768.             }
  22769.             if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si'$svgstyle['font'], $regs)) {
  22770.                 $font_spacing trim($regs[1]);
  22771.             } else {
  22772.                 $font_spacing $svgstyle['letter-spacing'];
  22773.             }
  22774.         } else {
  22775.             $font_family $this->getFontFamilyName($svgstyle['font-family']);
  22776.             $font_size $svgstyle['font-size'];
  22777.             $font_style $svgstyle['font-style'];
  22778.             $font_weight $svgstyle['font-weight'];
  22779.             $font_stretch $svgstyle['font-stretch'];
  22780.             $font_spacing $svgstyle['letter-spacing'];
  22781.         }
  22782.         $font_size $this->getHTMLFontUnits($font_size$this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  22783.         $font_stretch $this->getCSSFontStretching($font_stretch$svgstyle['font-stretch']);
  22784.         $font_spacing $this->getCSSFontSpacing($font_spacing$svgstyle['letter-spacing']);
  22785.         switch ($font_style) {
  22786.             case 'italic': {
  22787.                 $font_style 'I';
  22788.                 break;
  22789.             }
  22790.             case 'oblique': {
  22791.                 $font_style 'I';
  22792.                 break;
  22793.             }
  22794.             default:
  22795.             case 'normal': {
  22796.                 $font_style '';
  22797.                 break;
  22798.             }
  22799.         }
  22800.         switch ($font_weight) {
  22801.             case 'bold':
  22802.             case 'bolder': {
  22803.                 $font_style .= 'B';
  22804.                 break;
  22805.             }
  22806.             case 'normal': {
  22807.                 if ((substr($font_family, -1) == 'I') AND (substr($font_family, -21) == 'B')) {
  22808.                     $font_family substr($font_family0, -2).'I';
  22809.                 } elseif (substr($font_family, -1) == 'B') {
  22810.                     $font_family substr($font_family0, -1);
  22811.                 }
  22812.                 break;
  22813.             }
  22814.         }
  22815.         switch ($svgstyle['text-decoration']) {
  22816.             case 'underline': {
  22817.                 $font_style .= 'U';
  22818.                 break;
  22819.             }
  22820.             case 'overline': {
  22821.                 $font_style .= 'O';
  22822.                 break;
  22823.             }
  22824.             case 'line-through': {
  22825.                 $font_style .= 'D';
  22826.                 break;
  22827.             }
  22828.             default:
  22829.             case 'none': {
  22830.                 break;
  22831.             }
  22832.         }
  22833.         $this->setFont($font_family$font_style$font_size);
  22834.         $this->setFontStretching($font_stretch);
  22835.         $this->setFontSpacing($font_spacing);
  22836.         return $objstyle;
  22837.     }
  22838.     /**
  22839.      * Draws an SVG path
  22840.      * @param string $d attribute d of the path SVG element
  22841.      * @param string $style Style of rendering. Possible values are:
  22842.      * <ul>
  22843.      *     <li>D or empty string: Draw (default).</li>
  22844.      *     <li>F: Fill.</li>
  22845.      *     <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22846.      *     <li>DF or FD: Draw and fill.</li>
  22847.      *     <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22848.      *     <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  22849.      *     <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  22850.      * </ul>
  22851.      * @return array of container box measures (x, y, w, h)
  22852.      * @author Nicola Asuni
  22853.      * @since 5.0.000 (2010-05-02)
  22854.      * @protected
  22855.      */
  22856.     protected function SVGPath($d$style='') {
  22857.         if ($this->state != 2) {
  22858.             return;
  22859.         }
  22860.         // set fill/stroke style
  22861.         $op TCPDF_STATIC::getPathPaintOperator($style'');
  22862.         if (empty($op)) {
  22863.             return;
  22864.         }
  22865.         $paths = array();
  22866.         $d preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si''\\1 \\2'$d);
  22867.         $d preg_replace('/(\.[0-9]+)(\.)/s''\\1 \\2'$d);
  22868.         preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si'$d$pathsPREG_SET_ORDER);
  22869.         $x 0;
  22870.         $y 0;
  22871.         $x1 0;
  22872.         $y1 0;
  22873.         $x2 0;
  22874.         $y2 0;
  22875.         $xmin 2147483647;
  22876.         $xmax 0;
  22877.         $ymin 2147483647;
  22878.         $ymax 0;
  22879.         $xinitial 0;
  22880.         $yinitial 0;
  22881.         $relcoord false;
  22882.         $minlen = (0.01 $this->k); // minimum acceptable length (3 point)
  22883.         $firstcmd true// used to print first point
  22884.         // draw curve pieces
  22885.         foreach ($paths as $key => $val) {
  22886.             // get curve type
  22887.             $cmd trim($val[1]);
  22888.             if (strtolower($cmd) == $cmd) {
  22889.                 // use relative coordinated instead of absolute
  22890.                 $relcoord true;
  22891.                 $xoffset $x;
  22892.                 $yoffset $y;
  22893.             } else {
  22894.                 $relcoord false;
  22895.                 $xoffset 0;
  22896.                 $yoffset 0;
  22897.             }
  22898.             $params = array();
  22899.             if (isset($val[2])) {
  22900.                 // get curve parameters
  22901.                 $rawparams preg_split('/([\,\s]+)/si'trim($val[2]));
  22902.                 $params = array();
  22903.                 foreach ($rawparams as $ck => $cp) {
  22904.                     $params[$ck] = $this->getHTMLUnitToUnits($cp0$this->svgunitfalse);
  22905.                     if (abs($params[$ck]) < $minlen) {
  22906.                         // approximate little values to zero
  22907.                         $params[$ck] = 0;
  22908.                     }
  22909.                 }
  22910.             }
  22911.             // store current origin point
  22912.             $x0 $x;
  22913.             $y0 $y;
  22914.             switch (strtoupper($cmd)) {
  22915.                 case 'M': { // moveto
  22916.                     foreach ($params as $ck => $cp) {
  22917.                         if (($ck 2) == 0) {
  22918.                             $x $cp $xoffset;
  22919.                         } else {
  22920.                             $y $cp $yoffset;
  22921.                             if ($firstcmd OR (abs($x0 $x) >= $minlen) OR (abs($y0 $y) >= $minlen)) {
  22922.                                 if ($ck == 1) {
  22923.                                     $this->_outPoint($x$y);
  22924.                                     $firstcmd false;
  22925.                                     $xinitial $x;
  22926.                                     $yinitial $y;
  22927.                                 } else {
  22928.                                     $this->_outLine($x$y);
  22929.                                 }
  22930.                                 $x0 $x;
  22931.                                 $y0 $y;
  22932.                             }
  22933.                             $xmin min($xmin$x);
  22934.                             $ymin min($ymin$y);
  22935.                             $xmax max($xmax$x);
  22936.                             $ymax max($ymax$y);
  22937.                             if ($relcoord) {
  22938.                                 $xoffset $x;
  22939.                                 $yoffset $y;
  22940.                             }
  22941.                         }
  22942.                     }
  22943.                     break;
  22944.                 }
  22945.                 case 'L': { // lineto
  22946.                     foreach ($params as $ck => $cp) {
  22947.                         if (($ck 2) == 0) {
  22948.                             $x $cp $xoffset;
  22949.                         } else {
  22950.                             $y $cp $yoffset;
  22951.                             if ((abs($x0 $x) >= $minlen) OR (abs($y0 $y) >= $minlen)) {
  22952.                                 $this->_outLine($x$y);
  22953.                                 $x0 $x;
  22954.                                 $y0 $y;
  22955.                             }
  22956.                             $xmin min($xmin$x);
  22957.                             $ymin min($ymin$y);
  22958.                             $xmax max($xmax$x);
  22959.                             $ymax max($ymax$y);
  22960.                             if ($relcoord) {
  22961.                                 $xoffset $x;
  22962.                                 $yoffset $y;
  22963.                             }
  22964.                         }
  22965.                     }
  22966.                     break;
  22967.                 }
  22968.                 case 'H': { // horizontal lineto
  22969.                     foreach ($params as $ck => $cp) {
  22970.                         $x $cp $xoffset;
  22971.                         if ((abs($x0 $x) >= $minlen) OR (abs($y0 $y) >= $minlen)) {
  22972.                             $this->_outLine($x$y);
  22973.                             $x0 $x;
  22974.                             $y0 $y;
  22975.                         }
  22976.                         $xmin min($xmin$x);
  22977.                         $xmax max($xmax$x);
  22978.                         if ($relcoord) {
  22979.                             $xoffset $x;
  22980.                         }
  22981.                     }
  22982.                     break;
  22983.                 }
  22984.                 case 'V': { // vertical lineto
  22985.                     foreach ($params as $ck => $cp) {
  22986.                         $y $cp $yoffset;
  22987.                         if ((abs($x0 $x) >= $minlen) OR (abs($y0 $y) >= $minlen)) {
  22988.                             $this->_outLine($x$y);
  22989.                             $x0 $x;
  22990.                             $y0 $y;
  22991.                         }
  22992.                         $ymin min($ymin$y);
  22993.                         $ymax max($ymax$y);
  22994.                         if ($relcoord) {
  22995.                             $yoffset $y;
  22996.                         }
  22997.                     }
  22998.                     break;
  22999.                 }
  23000.                 case 'C': { // curveto
  23001.                     foreach ($params as $ck => $cp) {
  23002.                         $params[$ck] = $cp;
  23003.                         if ((($ck 1) % 6) == 0) {
  23004.                             $x1 $params[($ck 5)] + $xoffset;
  23005.                             $y1 $params[($ck 4)] + $yoffset;
  23006.                             $x2 $params[($ck 3)] + $xoffset;
  23007.                             $y2 $params[($ck 2)] + $yoffset;
  23008.                             $x $params[($ck 1)] + $xoffset;
  23009.                             $y $params[($ck)] + $yoffset;
  23010.                             $this->_outCurve($x1$y1$x2$y2$x$y);
  23011.                             $xmin min($xmin$x$x1$x2);
  23012.                             $ymin min($ymin$y$y1$y2);
  23013.                             $xmax max($xmax$x$x1$x2);
  23014.                             $ymax max($ymax$y$y1$y2);
  23015.                             if ($relcoord) {
  23016.                                 $xoffset $x;
  23017.                                 $yoffset $y;
  23018.                             }
  23019.                         }
  23020.                     }
  23021.                     break;
  23022.                 }
  23023.                 case 'S': { // shorthand/smooth curveto
  23024.                     foreach ($params as $ck => $cp) {
  23025.                         $params[$ck] = $cp;
  23026.                         if ((($ck 1) % 4) == 0) {
  23027.                             if (($key 0) AND ((strtoupper($paths[($key 1)][1]) == 'C') OR (strtoupper($paths[($key 1)][1]) == 'S'))) {
  23028.                                 $x1 = ($x) - $x2;
  23029.                                 $y1 = ($y) - $y2;
  23030.                             } else {
  23031.                                 $x1 $x;
  23032.                                 $y1 $y;
  23033.                             }
  23034.                             $x2 $params[($ck 3)] + $xoffset;
  23035.                             $y2 $params[($ck 2)] + $yoffset;
  23036.                             $x $params[($ck 1)] + $xoffset;
  23037.                             $y $params[($ck)] + $yoffset;
  23038.                             $this->_outCurve($x1$y1$x2$y2$x$y);
  23039.                             $xmin min($xmin$x$x1$x2);
  23040.                             $ymin min($ymin$y$y1$y2);
  23041.                             $xmax max($xmax$x$x1$x2);
  23042.                             $ymax max($ymax$y$y1$y2);
  23043.                             if ($relcoord) {
  23044.                                 $xoffset $x;
  23045.                                 $yoffset $y;
  23046.                             }
  23047.                         }
  23048.                     }
  23049.                     break;
  23050.                 }
  23051.                 case 'Q': { // quadratic Bezier curveto
  23052.                     foreach ($params as $ck => $cp) {
  23053.                         $params[$ck] = $cp;
  23054.                         if ((($ck 1) % 4) == 0) {
  23055.                             // convert quadratic points to cubic points
  23056.                             $x1 $params[($ck 3)] + $xoffset;
  23057.                             $y1 $params[($ck 2)] + $yoffset;
  23058.                             $xa = ($x + ($x1)) / 3;
  23059.                             $ya = ($y + ($y1)) / 3;
  23060.                             $x $params[($ck 1)] + $xoffset;
  23061.                             $y $params[($ck)] + $yoffset;
  23062.                             $xb = ($x + ($x1)) / 3;
  23063.                             $yb = ($y + ($y1)) / 3;
  23064.                             $this->_outCurve($xa$ya$xb$yb$x$y);
  23065.                             $xmin min($xmin$x$xa$xb);
  23066.                             $ymin min($ymin$y$ya$yb);
  23067.                             $xmax max($xmax$x$xa$xb);
  23068.                             $ymax max($ymax$y$ya$yb);
  23069.                             if ($relcoord) {
  23070.                                 $xoffset $x;
  23071.                                 $yoffset $y;
  23072.                             }
  23073.                         }
  23074.                     }
  23075.                     break;
  23076.                 }
  23077.                 case 'T': { // shorthand/smooth quadratic Bezier curveto
  23078.                     foreach ($params as $ck => $cp) {
  23079.                         $params[$ck] = $cp;
  23080.                         if (($ck 2) != 0) {
  23081.                             if (($key 0) AND ((strtoupper($paths[($key 1)][1]) == 'Q') OR (strtoupper($paths[($key 1)][1]) == 'T'))) {
  23082.                                 $x1 = ($x) - $x1;
  23083.                                 $y1 = ($y) - $y1;
  23084.                             } else {
  23085.                                 $x1 $x;
  23086.                                 $y1 $y;
  23087.                             }
  23088.                             // convert quadratic points to cubic points
  23089.                             $xa = ($x + ($x1)) / 3;
  23090.                             $ya = ($y + ($y1)) / 3;
  23091.                             $x $params[($ck 1)] + $xoffset;
  23092.                             $y $params[($ck)] + $yoffset;
  23093.                             $xb = ($x + ($x1)) / 3;
  23094.                             $yb = ($y + ($y1)) / 3;
  23095.                             $this->_outCurve($xa$ya$xb$yb$x$y);
  23096.                             $xmin min($xmin$x$xa$xb);
  23097.                             $ymin min($ymin$y$ya$yb);
  23098.                             $xmax max($xmax$x$xa$xb);
  23099.                             $ymax max($ymax$y$ya$yb);
  23100.                             if ($relcoord) {
  23101.                                 $xoffset $x;
  23102.                                 $yoffset $y;
  23103.                             }
  23104.                         }
  23105.                     }
  23106.                     break;
  23107.                 }
  23108.                 case 'A': { // elliptical arc
  23109.                     foreach ($params as $ck => $cp) {
  23110.                         $params[$ck] = $cp;
  23111.                         if ((($ck 1) % 7) == 0) {
  23112.                             $x0 $x;
  23113.                             $y0 $y;
  23114.                             $rx max(abs($params[($ck 6)]), .000000001);
  23115.                             $ry max(abs($params[($ck 5)]), .000000001);
  23116.                             $ang = -$rawparams[($ck 4)];
  23117.                             $angle deg2rad($ang);
  23118.                             $fa $rawparams[($ck 3)]; // large-arc-flag
  23119.                             $fs $rawparams[($ck 2)]; // sweep-flag
  23120.                             $x $params[($ck 1)] + $xoffset;
  23121.                             $y $params[$ck] + $yoffset;
  23122.                             if ((abs($x0 $x) < $minlen) AND (abs($y0 $y) < $minlen)) {
  23123.                                 // endpoints are almost identical
  23124.                                 $xmin min($xmin$x);
  23125.                                 $ymin min($ymin$y);
  23126.                                 $xmax max($xmax$x);
  23127.                                 $ymax max($ymax$y);
  23128.                             } else {
  23129.                                 $cos_ang cos($angle);
  23130.                                 $sin_ang sin($angle);
  23131.                                 $a = (($x0 $x) / 2);
  23132.                                 $b = (($y0 $y) / 2);
  23133.                                 $xa = ($a $cos_ang) - ($b $sin_ang);
  23134.                                 $ya = ($a $sin_ang) + ($b $cos_ang);
  23135.                                 $rx2 $rx $rx;
  23136.                                 $ry2 $ry $ry;
  23137.                                 $xa2 $xa $xa;
  23138.                                 $ya2 $ya $ya;
  23139.                                 $delta = ($xa2 $rx2) + ($ya2 $ry2);
  23140.                                 if ($delta 1) {
  23141.                                     $rx *= sqrt($delta);
  23142.                                     $ry *= sqrt($delta);
  23143.                                     $rx2 $rx $rx;
  23144.                                     $ry2 $ry $ry;
  23145.                                 }
  23146.                                 $numerator = (($rx2 $ry2) - ($rx2 $ya2) - ($ry2 $xa2));
  23147.                                 if ($numerator 0) {
  23148.                                     $root 0;
  23149.                                 } else {
  23150.                                     $root sqrt($numerator / (($rx2 $ya2) + ($ry2 $xa2)));
  23151.                                 }
  23152.                                 if ($fa == $fs){
  23153.                                     $root *= -1;
  23154.                                 }
  23155.                                 $cax $root * (($rx $ya) / $ry);
  23156.                                 $cay = -$root * (($ry $xa) / $rx);
  23157.                                 // coordinates of ellipse center
  23158.                                 $cx = ($cax $cos_ang) - ($cay $sin_ang) + (($x0 $x) / 2);
  23159.                                 $cy = ($cax $sin_ang) + ($cay $cos_ang) + (($y0 $y) / 2);
  23160.                                 // get angles
  23161.                                 $angs TCPDF_STATIC::getVectorsAngle(10, (($xa $cax) / $rx), (($cay $ya) / $ry));
  23162.                                 $dang TCPDF_STATIC::getVectorsAngle((($xa $cax) / $rx), (($ya $cay) / $ry), ((-$xa $cax) / $rx), ((-$ya $cay) / $ry));
  23163.                                 if (($fs == 0) AND ($dang 0)) {
  23164.                                     $dang -= (M_PI);
  23165.                                 } elseif (($fs == 1) AND ($dang 0)) {
  23166.                                     $dang += (M_PI);
  23167.                                 }
  23168.                                 $angf $angs $dang;
  23169.                                 if ((($fs == 0) AND ($angs $angf)) OR (($fs == 1) AND ($angs $angf))) {
  23170.                                     // reverse angles
  23171.                                     $tmp $angs;
  23172.                                     $angs $angf;
  23173.                                     $angf $tmp;
  23174.                                 }
  23175.                                 $angs round(rad2deg($angs), 6);
  23176.                                 $angf round(rad2deg($angf), 6);
  23177.                                 // covent angles to positive values
  23178.                                 if (($angs 0) AND ($angf 0)) {
  23179.                                     $angs += 360;
  23180.                                     $angf += 360;
  23181.                                 }
  23182.                                 $pie false;
  23183.                                 if (($key == 0) AND (isset($paths[($key 1)][1])) AND (trim($paths[($key 1)][1]) == 'z')) {
  23184.                                     $pie true;
  23185.                                 }
  23186.                                 list($axmin$aymin$axmax$aymax) = $this->_outellipticalarc($cx$cy$rx$ry$ang$angs$angf$pie2false, ($fs == 0), true);
  23187.                                 $xmin min($xmin$x$axmin);
  23188.                                 $ymin min($ymin$y$aymin);
  23189.                                 $xmax max($xmax$x$axmax);
  23190.                                 $ymax max($ymax$y$aymax);
  23191.                             }
  23192.                             if ($relcoord) {
  23193.                                 $xoffset $x;
  23194.                                 $yoffset $y;
  23195.                             }
  23196.                         }
  23197.                     }
  23198.                     break;
  23199.                 }
  23200.                 case 'Z': {
  23201.                     $this->_out('h');
  23202.                     $x $x0 $xinitial;
  23203.                     $y $y0 $yinitial;
  23204.                     break;
  23205.                 }
  23206.             }
  23207.             $firstcmd false;
  23208.         } // end foreach
  23209.         $this->_out($op);
  23210.         return array($xmin$ymin, ($xmax $xmin), ($ymax $ymin));
  23211.     }
  23212.     /**
  23213.      * Return the tag name without the namespace
  23214.      * @param string $name Tag name
  23215.      * @protected
  23216.      */
  23217.     protected function removeTagNamespace($name) {
  23218.         if(strpos($name':') !== false) {
  23219.             $parts explode(':'$name);
  23220.             return $parts[(sizeof($parts) - 1)];
  23221.         }
  23222.         return $name;
  23223.     }
  23224.     /**
  23225.      * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  23226.      * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23227.      * @param string $name The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  23228.      * @param array $attribs The third parameter, attribs, contains an associative array with the element's attributes (if any). The keys of this array are the attribute names, the values are the attribute values. Attribute names are case-folded on the same criteria as element names. Attribute values are not case-folded. The original order of the attributes can be retrieved by walking through attribs the normal way, using each(). The first key in the array was the first attribute, and so on.
  23229.      * @param array $ctm tranformation matrix for clipping mode (starting transformation matrix).
  23230.      * @author Nicola Asuni
  23231.      * @since 5.0.000 (2010-05-02)
  23232.      * @protected
  23233.      */
  23234.     protected function startSVGElementHandler($parser$name$attribs$ctm=array()) {
  23235.         $name $this->removeTagNamespace($name);
  23236.         // check if we are in clip mode
  23237.         if ($this->svgclipmode) {
  23238.             $this->svgclippaths[$this->svgclipid][] = array('name' => $name'attribs' => $attribs'tm' => $this->svgcliptm[$this->svgclipid]);
  23239.             return;
  23240.         }
  23241.         if ($this->svgdefsmode AND !in_array($name, array('clipPath''linearGradient''radialGradient''stop'))) {
  23242.             if (isset($attribs['id'])) {
  23243.                 $attribs['child_elements'] = array();
  23244.                 $this->svgdefs[$attribs['id']] = array('name' => $name'attribs' => $attribs);
  23245.                 return;
  23246.             }
  23247.             if (end($this->svgdefs) !== FALSE) {
  23248.                 $last_svgdefs_id key($this->svgdefs);
  23249.                 if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23250.                     $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1);
  23251.                     $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name'attribs' => $attribs);
  23252.                     return;
  23253.                 }
  23254.             }
  23255.             return;
  23256.         }
  23257.         $clipping false;
  23258.         if ($parser == 'clip-path') {
  23259.             // set clipping mode
  23260.             $clipping true;
  23261.         }
  23262.         // get styling properties
  23263.         $prev_svgstyle $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style
  23264.         $svgstyle $this->svgstyles[0]; // set default style
  23265.         if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si'$attribs['style'], $attrval)))) {
  23266.             // default fill attribute for clipping
  23267.             $attribs['fill'] = 'none';
  23268.         }
  23269.         if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
  23270.             // fix style for regular expression
  23271.             $attribs['style'] = ';'.$attribs['style'];
  23272.         }
  23273.         foreach ($prev_svgstyle as $key => $val) {
  23274.             if (in_array($keyTCPDF_IMAGES::$svginheritprop)) {
  23275.                 // inherit previous value
  23276.                 $svgstyle[$key] = $val;
  23277.             }
  23278.             if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  23279.                 // specific attribute settings
  23280.                 if ($attribs[$key] == 'inherit') {
  23281.                     $svgstyle[$key] = $val;
  23282.                 } else {
  23283.                     $svgstyle[$key] = $attribs[$key];
  23284.                 }
  23285.             } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  23286.                 // CSS style syntax
  23287.                 $attrval = array();
  23288.                 if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si'$attribs['style'], $attrval) AND isset($attrval[1])) {
  23289.                     if ($attrval[1] == 'inherit') {
  23290.                         $svgstyle[$key] = $val;
  23291.                     } else {
  23292.                         $svgstyle[$key] = $attrval[1];
  23293.                     }
  23294.                 }
  23295.             }
  23296.         }
  23297.         // transformation matrix
  23298.         if (!empty($ctm)) {
  23299.             $tm $ctm;
  23300.         } else {
  23301.             $tm = array(1,0,0,1,0,0);
  23302.         }
  23303.         if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  23304.             $tm TCPDF_STATIC::getTransformationMatrixProduct($tmTCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  23305.         }
  23306.         $svgstyle['transfmatrix'] = $tm;
  23307.         $invisible false;
  23308.         if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  23309.             // the current graphics element is invisible (nothing is painted)
  23310.             $invisible true;
  23311.         }
  23312.         // process tag
  23313.         switch($name) {
  23314.             case 'defs': {
  23315.                 $this->svgdefsmode true;
  23316.                 break;
  23317.             }
  23318.             // clipPath
  23319.             case 'clipPath': {
  23320.                 if ($invisible) {
  23321.                     break;
  23322.                 }
  23323.                 $this->svgclipmode true;
  23324.                 if (!isset($attribs['id'])) {
  23325.                     $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  23326.                 }
  23327.                 $this->svgclipid $attribs['id'];
  23328.                 $this->svgclippaths[$this->svgclipid] = array();
  23329.                 $this->svgcliptm[$this->svgclipid] = $tm;
  23330.                 break;
  23331.             }
  23332.             case 'svg': {
  23333.                 // start of SVG object
  23334.                 if(++$this->svg_tag_depth <= 1) {
  23335.                     break;
  23336.                 }
  23337.                 // inner SVG
  23338.                 array_push($this->svgstyles$svgstyle);
  23339.                 $this->StartTransform();
  23340.                 $svgX = (isset($attribs['x'])?$attribs['x']:0);
  23341.                 $svgY = (isset($attribs['y'])?$attribs['y']:0);
  23342.                 $svgW = (isset($attribs['width'])?$attribs['width']:0);
  23343.                 $svgH = (isset($attribs['height'])?$attribs['height']:0);
  23344.                 // set x, y position using transform matrix
  23345.                 $tm TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1001$svgX$svgY));
  23346.                 $this->SVGTransform($tm);
  23347.                 // set clipping for width and height
  23348.                 $x 0;
  23349.                 $y 0;
  23350.                 $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0$this->svgunitfalse):$this->w);
  23351.                 $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0$this->svgunitfalse):$this->h);
  23352.                 // draw clipping rect
  23353.                 $this->Rect($x$y$w$h'CNZ', array(), array());
  23354.                 // parse viewbox, calculate extra transformation matrix
  23355.                 if (isset($attribs['viewBox'])) {
  23356.                     $tmp = array();
  23357.                     preg_match_all("/[0-9]+/"$attribs['viewBox'], $tmp);
  23358.                     $tmp $tmp[0];
  23359.                     if (sizeof($tmp) == 4) {
  23360.                         $vx $tmp[0];
  23361.                         $vy $tmp[1];
  23362.                         $vw $tmp[2];
  23363.                         $vh $tmp[3];
  23364.                         // get aspect ratio
  23365.                         $tmp = array();
  23366.                         $aspectX 'xMid';
  23367.                         $aspectY 'YMid';
  23368.                         $fit 'meet';
  23369.                         if (isset($attribs['preserveAspectRatio'])) {
  23370.                             if($attribs['preserveAspectRatio'] == 'none') {
  23371.                                 $fit 'none';
  23372.                             } else {
  23373.                                 preg_match_all('/[a-zA-Z]+/'$attribs['preserveAspectRatio'], $tmp);
  23374.                                 $tmp $tmp[0];
  23375.                                 if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet''slice''none')))) {
  23376.                                     $aspectX substr($tmp[0], 04);
  23377.                                     $aspectY substr($tmp[0], 44);
  23378.                                     $fit $tmp[1];
  23379.                                 }
  23380.                             }
  23381.                         }
  23382.                         $wr = ($svgW $vw);
  23383.                         $hr = ($svgH $vh);
  23384.                         $ax $ay 0;
  23385.                         if ((($fit == 'meet') AND ($hr $wr)) OR (($fit == 'slice') AND ($hr $wr))) {
  23386.                             if ($aspectX == 'xMax') {
  23387.                                 $ax = (($vw * ($wr $hr)) - $vw);
  23388.                             }
  23389.                             if ($aspectX == 'xMid') {
  23390.                                 $ax = ((($vw * ($wr $hr)) - $vw) / 2);
  23391.                             }
  23392.                             $wr $hr;
  23393.                         } elseif ((($fit == 'meet') AND ($hr $wr)) OR (($fit == 'slice') AND ($hr $wr))) {
  23394.                             if ($aspectY == 'YMax') {
  23395.                                 $ay = (($vh * ($hr $wr)) - $vh);
  23396.                             }
  23397.                             if ($aspectY == 'YMid') {
  23398.                                 $ay = ((($vh * ($hr $wr)) - $vh) / 2);
  23399.                             }
  23400.                             $hr $wr;
  23401.                         }
  23402.                         $newtm = array($wr00$hr, (($wr * ($ax $vx)) - $svgX), (($hr * ($ay $vy)) - $svgY));
  23403.                         $tm TCPDF_STATIC::getTransformationMatrixProduct($tm$newtm);
  23404.                         $this->SVGTransform($tm);
  23405.                     }
  23406.                 }
  23407.                 $this->setSVGStyles($svgstyle$prev_svgstyle);
  23408.                 break;
  23409.             }
  23410.             case 'g': {
  23411.                 // group together related graphics elements
  23412.                 array_push($this->svgstyles$svgstyle);
  23413.                 $this->StartTransform();
  23414.                 $x = (isset($attribs['x'])?$attribs['x']:0);
  23415.                 $y = (isset($attribs['y'])?$attribs['y']:0);
  23416.                 $w 1;//(isset($attribs['width'])?$attribs['width']:1);
  23417.                 $h 1;//(isset($attribs['height'])?$attribs['height']:1);
  23418.                 $tm TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w00$h$x$y));
  23419.                 $this->SVGTransform($tm);
  23420.                 $this->setSVGStyles($svgstyle$prev_svgstyle);
  23421.                 break;
  23422.             }
  23423.             case 'linearGradient': {
  23424.                 if ($this->pdfa_mode && $this->pdfa_version 2) {
  23425.                     break;
  23426.                 }
  23427.                 if (!isset($attribs['id'])) {
  23428.                     $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23429.                 }
  23430.                 $this->svggradientid $attribs['id'];
  23431.                 $this->svggradients[$this->svggradientid] = array();
  23432.                 $this->svggradients[$this->svggradientid]['type'] = 2;
  23433.                 $this->svggradients[$this->svggradientid]['stops'] = array();
  23434.                 if (isset($attribs['gradientUnits'])) {
  23435.                     $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23436.                 } else {
  23437.                     $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23438.                 }
  23439.                 //$attribs['spreadMethod']
  23440.                 if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  23441.                     OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  23442.                         OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  23443.                         OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  23444.                         OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  23445.                     $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23446.                 } else {
  23447.                     $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23448.                 }
  23449.                 $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  23450.                 $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  23451.                 $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  23452.                 $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  23453.                 if (isset($attribs['gradientTransform'])) {
  23454.                     $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23455.                 }
  23456.                 $this->svggradients[$this->svggradientid]['coords'] = array($x1$y1$x2$y2);
  23457.                 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23458.                     // gradient is defined on another place
  23459.                     $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23460.                 }
  23461.                 break;
  23462.             }
  23463.             case 'radialGradient': {
  23464.                 if ($this->pdfa_mode && $this->pdfa_version 2) {
  23465.                     break;
  23466.                 }
  23467.                 if (!isset($attribs['id'])) {
  23468.                     $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  23469.                 }
  23470.                 $this->svggradientid $attribs['id'];
  23471.                 $this->svggradients[$this->svggradientid] = array();
  23472.                 $this->svggradients[$this->svggradientid]['type'] = 3;
  23473.                 $this->svggradients[$this->svggradientid]['stops'] = array();
  23474.                 if (isset($attribs['gradientUnits'])) {
  23475.                     $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23476.                 } else {
  23477.                     $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23478.                 }
  23479.                 //$attribs['spreadMethod']
  23480.                 if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23481.                     OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23482.                     OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
  23483.                     $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23484.                 } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
  23485.                     $this->svggradients[$this->svggradientid]['mode'] = 'ratio';
  23486.                 } else {
  23487.                     $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23488.                 }
  23489.                 $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23490.                 $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23491.                 $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23492.                 $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23493.                 $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23494.                 if (isset($attribs['gradientTransform'])) {
  23495.                     $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23496.                 }
  23497.                 $this->svggradients[$this->svggradientid]['coords'] = array($cx$cy$fx$fy$r);
  23498.                 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23499.                     // gradient is defined on another place
  23500.                     $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23501.                 }
  23502.                 break;
  23503.             }
  23504.             case 'stop': {
  23505.                 // gradient stops
  23506.                 if (substr($attribs['offset'], -1) == '%') {
  23507.                     $offset floatval(substr($attribs['offset'], 0, -1)) / 100;
  23508.                 } else {
  23509.                     $offset floatval($attribs['offset']);
  23510.                     if ($offset 1) {
  23511.                         $offset /= 100;
  23512.                     }
  23513.                 }
  23514.                 $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23515.                 $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23516.                 $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset'color' => $stop_color'opacity' => $opacity);
  23517.                 break;
  23518.             }
  23519.             // paths
  23520.             case 'path': {
  23521.                 if ($invisible) {
  23522.                     break;
  23523.                 }
  23524.                 if (isset($attribs['d'])) {
  23525.                     $d trim($attribs['d']);
  23526.                     if (!empty($d)) {
  23527.                         $x = (isset($attribs['x'])?$attribs['x']:0);
  23528.                         $y = (isset($attribs['y'])?$attribs['y']:0);
  23529.                         $w = (isset($attribs['width'])?$attribs['width']:1);
  23530.                         $h = (isset($attribs['height'])?$attribs['height']:1);
  23531.                         $tm TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w00$h$x$y));
  23532.                         if ($clipping) {
  23533.                             $this->SVGTransform($tm);
  23534.                             $this->SVGPath($d'CNZ');
  23535.                         } else {
  23536.                             $this->StartTransform();
  23537.                             $this->SVGTransform($tm);
  23538.                             $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'SVGPath', array($d'CNZ'));
  23539.                             if (!empty($obstyle)) {
  23540.                                 $this->SVGPath($d$obstyle);
  23541.                             }
  23542.                             $this->StopTransform();
  23543.                         }
  23544.                     }
  23545.                 }
  23546.                 break;
  23547.             }
  23548.             // shapes
  23549.             case 'rect': {
  23550.                 if ($invisible) {
  23551.                     break;
  23552.                 }
  23553.                 $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0$this->svgunitfalse):0);
  23554.                 $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0$this->svgunitfalse):0);
  23555.                 $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0$this->svgunitfalse):0);
  23556.                 $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0$this->svgunitfalse):0);
  23557.                 $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0$this->svgunitfalse):0);
  23558.                 $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0$this->svgunitfalse):$rx);
  23559.                 if ($clipping) {
  23560.                     $this->SVGTransform($tm);
  23561.                     $this->RoundedRectXY($x$y$w$h$rx$ry'1111''CNZ', array(), array());
  23562.                 } else {
  23563.                     $this->StartTransform();
  23564.                     $this->SVGTransform($tm);
  23565.                     $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'RoundedRectXY', array($x$y$w$h$rx$ry'1111''CNZ'));
  23566.                     if (!empty($obstyle)) {
  23567.                         $this->RoundedRectXY($x$y$w$h$rx$ry'1111'$obstyle, array(), array());
  23568.                     }
  23569.                     $this->StopTransform();
  23570.                 }
  23571.                 break;
  23572.             }
  23573.             case 'circle': {
  23574.                 if ($invisible) {
  23575.                     break;
  23576.                 }
  23577.                 $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0$this->svgunitfalse) : 0);
  23578.                 $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0$this->svgunitfalse) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0$this->svgunitfalse) : 0));
  23579.                 $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0$this->svgunitfalse) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0$this->svgunitfalse) : 0));
  23580.                 $x = ($cx $r);
  23581.                 $y = ($cy $r);
  23582.                 $w = ($r);
  23583.                 $h $w;
  23584.                 if ($clipping) {
  23585.                     $this->SVGTransform($tm);
  23586.                     $this->Circle($cx$cy$r0360'CNZ', array(), array(), 8);
  23587.                 } else {
  23588.                     $this->StartTransform();
  23589.                     $this->SVGTransform($tm);
  23590.                     $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'Circle', array($cx$cy$r0360'CNZ'));
  23591.                     if (!empty($obstyle)) {
  23592.                         $this->Circle($cx$cy$r0360$obstyle, array(), array(), 8);
  23593.                     }
  23594.                     $this->StopTransform();
  23595.                 }
  23596.                 break;
  23597.             }
  23598.             case 'ellipse': {
  23599.                 if ($invisible) {
  23600.                     break;
  23601.                 }
  23602.                 $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0$this->svgunitfalse) : 0);
  23603.                 $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0$this->svgunitfalse) : 0);
  23604.                 $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0$this->svgunitfalse) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0$this->svgunitfalse) : 0));
  23605.                 $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0$this->svgunitfalse) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0$this->svgunitfalse) : 0));
  23606.                 $x = ($cx $rx);
  23607.                 $y = ($cy $ry);
  23608.                 $w = ($rx);
  23609.                 $h = ($ry);
  23610.                 if ($clipping) {
  23611.                     $this->SVGTransform($tm);
  23612.                     $this->Ellipse($cx$cy$rx$ry00360'CNZ', array(), array(), 8);
  23613.                 } else {
  23614.                     $this->StartTransform();
  23615.                     $this->SVGTransform($tm);
  23616.                     $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'Ellipse', array($cx$cy$rx$ry00360'CNZ'));
  23617.                     if (!empty($obstyle)) {
  23618.                         $this->Ellipse($cx$cy$rx$ry00360$obstyle, array(), array(), 8);
  23619.                     }
  23620.                     $this->StopTransform();
  23621.                 }
  23622.                 break;
  23623.             }
  23624.             case 'line': {
  23625.                 if ($invisible) {
  23626.                     break;
  23627.                 }
  23628.                 $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0$this->svgunitfalse):0);
  23629.                 $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0$this->svgunitfalse):0);
  23630.                 $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0$this->svgunitfalse):0);
  23631.                 $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0$this->svgunitfalse):0);
  23632.                 $x $x1;
  23633.                 $y $y1;
  23634.                 $w abs($x2 $x1);
  23635.                 $h abs($y2 $y1);
  23636.                 if (!$clipping) {
  23637.                     $this->StartTransform();
  23638.                     $this->SVGTransform($tm);
  23639.                     $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'Line', array($x1$y1$x2$y2));
  23640.                     $this->Line($x1$y1$x2$y2);
  23641.                     $this->StopTransform();
  23642.                 }
  23643.                 break;
  23644.             }
  23645.             case 'polyline':
  23646.             case 'polygon': {
  23647.                 if ($invisible) {
  23648.                     break;
  23649.                 }
  23650.                 $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23651.                 $points trim($points);
  23652.                 // note that point may use a complex syntax not covered here
  23653.                 $points preg_split('/[\,\s]+/si'$points);
  23654.                 if (count($points) < 4) {
  23655.                     break;
  23656.                 }
  23657.                 $p = array();
  23658.                 $xmin 2147483647;
  23659.                 $xmax 0;
  23660.                 $ymin 2147483647;
  23661.                 $ymax 0;
  23662.                 foreach ($points as $key => $val) {
  23663.                     $p[$key] = $this->getHTMLUnitToUnits($val0$this->svgunitfalse);
  23664.                     if (($key 2) == 0) {
  23665.                         // X coordinate
  23666.                         $xmin min($xmin$p[$key]);
  23667.                         $xmax max($xmax$p[$key]);
  23668.                     } else {
  23669.                         // Y coordinate
  23670.                         $ymin min($ymin$p[$key]);
  23671.                         $ymax max($ymax$p[$key]);
  23672.                     }
  23673.                 }
  23674.                 $x $xmin;
  23675.                 $y $ymin;
  23676.                 $w = ($xmax $xmin);
  23677.                 $h = ($ymax $ymin);
  23678.                 if ($name == 'polyline') {
  23679.                     $this->StartTransform();
  23680.                     $this->SVGTransform($tm);
  23681.                     $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'PolyLine', array($p'CNZ'));
  23682.                     if (!empty($obstyle)) {
  23683.                         $this->PolyLine($p$obstyle, array(), array());
  23684.                     }
  23685.                     $this->StopTransform();
  23686.                 } else { // polygon
  23687.                     if ($clipping) {
  23688.                         $this->SVGTransform($tm);
  23689.                         $this->Polygon($p'CNZ', array(), array(), true);
  23690.                     } else {
  23691.                         $this->StartTransform();
  23692.                         $this->SVGTransform($tm);
  23693.                         $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h'Polygon', array($p'CNZ'));
  23694.                         if (!empty($obstyle)) {
  23695.                             $this->Polygon($p$obstyle, array(), array(), true);
  23696.                         }
  23697.                         $this->StopTransform();
  23698.                     }
  23699.                 }
  23700.                 break;
  23701.             }
  23702.             // image
  23703.             case 'image': {
  23704.                 if ($invisible) {
  23705.                     break;
  23706.                 }
  23707.                 if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  23708.                     break;
  23709.                 }
  23710.                 $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0$this->svgunitfalse):0);
  23711.                 $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0$this->svgunitfalse):0);
  23712.                 $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0$this->svgunitfalse):0);
  23713.                 $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0$this->svgunitfalse):0);
  23714.                 $img $attribs['xlink:href'];
  23715.                 if (!$clipping) {
  23716.                     $this->StartTransform();
  23717.                     $this->SVGTransform($tm);
  23718.                     $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y$w$h);
  23719.                     if (preg_match('/^data:image\/[^;]+;base64,/'$img$m) > 0) {
  23720.                         // embedded image encoded as base64
  23721.                         $img '@'.base64_decode(substr($imgstrlen($m[0])));
  23722.                     } else {
  23723.                         // fix image path
  23724.                         if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
  23725.                             // replace relative path with full server path
  23726.                             $img $this->svgdir.'/'.$img;
  23727.                         }
  23728.                         if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23729.                             $findroot strpos($img$_SERVER['DOCUMENT_ROOT']);
  23730.                             if (($findroot === false) OR ($findroot 1)) {
  23731.                                 if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23732.                                     $img substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  23733.                                 } else {
  23734.                                     $img $_SERVER['DOCUMENT_ROOT'].$img;
  23735.                                 }
  23736.                             }
  23737.                         }
  23738.                         $img urldecode($img);
  23739.                         $testscrtype = @parse_url($img);
  23740.                         if (empty($testscrtype['query'])) {
  23741.                             // convert URL to server path
  23742.                             $img str_replace(K_PATH_URLK_PATH_MAIN$img);
  23743.                         } elseif (preg_match('|^https?://|'$img) !== 1) {
  23744.                             // convert server path to URL
  23745.                             $img str_replace(K_PATH_MAINK_PATH_URL$img);
  23746.                         }
  23747.                     }
  23748.                     // get image type
  23749.                     $imgtype TCPDF_IMAGES::getImageFileType($img);
  23750.                     if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  23751.                         $this->ImageEps($img$x$y$w$h);
  23752.                     } elseif ($imgtype == 'svg') {
  23753.                         // store SVG vars
  23754.                         $svggradients $this->svggradients;
  23755.                         $svggradientid $this->svggradientid;
  23756.                         $svgdefsmode $this->svgdefsmode;
  23757.                         $svgdefs $this->svgdefs;
  23758.                         $svgclipmode $this->svgclipmode;
  23759.                         $svgclippaths $this->svgclippaths;
  23760.                         $svgcliptm $this->svgcliptm;
  23761.                         $svgclipid $this->svgclipid;
  23762.                         $svgtext $this->svgtext;
  23763.                         $svgtextmode $this->svgtextmode;
  23764.                         $this->ImageSVG($img$x$y$w$h);
  23765.                         // restore SVG vars
  23766.                         $this->svggradients $svggradients;
  23767.                         $this->svggradientid $svggradientid;
  23768.                         $this->svgdefsmode $svgdefsmode;
  23769.                         $this->svgdefs $svgdefs;
  23770.                         $this->svgclipmode $svgclipmode;
  23771.                         $this->svgclippaths $svgclippaths;
  23772.                         $this->svgcliptm $svgcliptm;
  23773.                         $this->svgclipid $svgclipid;
  23774.                         $this->svgtext $svgtext;
  23775.                         $this->svgtextmode $svgtextmode;
  23776.                     } else {
  23777.                         $this->Image($img$x$y$w$h);
  23778.                     }
  23779.                     $this->StopTransform();
  23780.                 }
  23781.                 break;
  23782.             }
  23783.             // text
  23784.             case 'text':
  23785.             case 'tspan': {
  23786.                 if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) {
  23787.                     // @TODO: unsupported feature
  23788.                 }
  23789.                 // only basic support - advanced features must be implemented
  23790.                 $this->svgtextmode['invisible'] = $invisible;
  23791.                 if ($invisible) {
  23792.                     break;
  23793.                 }
  23794.                 array_push($this->svgstyles$svgstyle);
  23795.                 if (isset($attribs['x'])) {
  23796.                     $x $this->getHTMLUnitToUnits($attribs['x'], 0$this->svgunitfalse);
  23797.                 } elseif ($name == 'tspan') {
  23798.                     $x $this->x;
  23799.                 } else {
  23800.                     $x 0;
  23801.                 }
  23802.                 if (isset($attribs['dx'])) {
  23803.                     $x += $this->getHTMLUnitToUnits($attribs['dx'], 0$this->svgunitfalse);
  23804.                 }
  23805.                 if (isset($attribs['y'])) {
  23806.                     $y $this->getHTMLUnitToUnits($attribs['y'], 0$this->svgunitfalse);
  23807.                 } elseif ($name == 'tspan') {
  23808.                     $y $this->y;
  23809.                 } else {
  23810.                     $y 0;
  23811.                 }
  23812.                 if (isset($attribs['dy'])) {
  23813.                     $y += $this->getHTMLUnitToUnits($attribs['dy'], 0$this->svgunitfalse);
  23814.                 }
  23815.                 $svgstyle['text-color'] = $svgstyle['fill'];
  23816.                 $this->svgtext '';
  23817.                 if (isset($svgstyle['text-anchor'])) {
  23818.                     $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  23819.                 } else {
  23820.                     $this->svgtextmode['text-anchor'] = 'start';
  23821.                 }
  23822.                 if (isset($svgstyle['direction'])) {
  23823.                     if ($svgstyle['direction'] == 'rtl') {
  23824.                         $this->svgtextmode['rtl'] = true;
  23825.                     } else {
  23826.                         $this->svgtextmode['rtl'] = false;
  23827.                     }
  23828.                 } else {
  23829.                     $this->svgtextmode['rtl'] = false;
  23830.                 }
  23831.                 if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  23832.                     $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0$this->svgunitfalse);
  23833.                 } else {
  23834.                     $this->svgtextmode['stroke'] = false;
  23835.                 }
  23836.                 $this->StartTransform();
  23837.                 $this->SVGTransform($tm);
  23838.                 $obstyle $this->setSVGStyles($svgstyle$prev_svgstyle$x$y11);
  23839.                 $this->$x;
  23840.                 $this->$y;
  23841.                 break;
  23842.             }
  23843.             // use
  23844.             case 'use': {
  23845.                 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23846.                     $svgdefid substr($attribs['xlink:href'], 1);
  23847.                     if (isset($this->svgdefs[$svgdefid])) {
  23848.                         $use $this->svgdefs[$svgdefid];
  23849.                         if (isset($attribs['xlink:href'])) {
  23850.                             unset($attribs['xlink:href']);
  23851.                         }
  23852.                         if (isset($attribs['id'])) {
  23853.                             unset($attribs['id']);
  23854.                         }
  23855.                         if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  23856.                             $attribs['x'] += $use['attribs']['x'];
  23857.                         }
  23858.                         if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  23859.                             $attribs['y'] += $use['attribs']['y'];
  23860.                         }
  23861.                         if (empty($attribs['style'])) {
  23862.                             $attribs['style'] = '';
  23863.                         }
  23864.                         if (!empty($use['attribs']['style'])) {
  23865.                             // merge styles
  23866.                             $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']);
  23867.                         }
  23868.                         $attribs array_merge($use['attribs'], $attribs);
  23869.                         $this->startSVGElementHandler($parser$use['name'], $attribs);
  23870.                         return;
  23871.                     }
  23872.                 }
  23873.                 break;
  23874.             }
  23875.             default: {
  23876.                 break;
  23877.             }
  23878.         } // end of switch
  23879.         // process child elements
  23880.         if (!empty($attribs['child_elements'])) {
  23881.             $child_elements $attribs['child_elements'];
  23882.             unset($attribs['child_elements']);
  23883.             foreach($child_elements as $child_element) {
  23884.                 if (empty($child_element['attribs']['closing_tag'])) {
  23885.                     $this->startSVGElementHandler('child-tag'$child_element['name'], $child_element['attribs']);
  23886.                 } else {
  23887.                     if (isset($child_element['attribs']['content'])) {
  23888.                         $this->svgtext $child_element['attribs']['content'];
  23889.                     }
  23890.                     $this->endSVGElementHandler('child-tag'$child_element['name']);
  23891.                 }
  23892.             }
  23893.         }
  23894.     }
  23895.     /**
  23896.      * Sets the closing SVG element handler function for the XML parser.
  23897.      * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  23898.      * @param string $name The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  23899.      * @author Nicola Asuni
  23900.      * @since 5.0.000 (2010-05-02)
  23901.      * @protected
  23902.      */
  23903.     protected function endSVGElementHandler($parser$name) {
  23904.         $name $this->removeTagNamespace($name);
  23905.         if ($this->svgdefsmode AND !in_array($name, array('defs''clipPath''linearGradient''radialGradient''stop'))) {;
  23906.             if (end($this->svgdefs) !== FALSE) {
  23907.                 $last_svgdefs_id key($this->svgdefs);
  23908.                 if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
  23909.                     foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
  23910.                         if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
  23911.                             $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name'attribs' => array('closing_tag' => TRUE'content' => $this->svgtext));
  23912.                             return;
  23913.                         }
  23914.                     }
  23915.                     if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
  23916.                         $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name'attribs' => array('closing_tag' => TRUE'content' => $this->svgtext));
  23917.                         return;
  23918.                     }
  23919.                 }
  23920.             }
  23921.             return;
  23922.         }
  23923.         switch($name) {
  23924.             case 'defs': {
  23925.                 $this->svgdefsmode false;
  23926.                 break;
  23927.             }
  23928.             // clipPath
  23929.             case 'clipPath': {
  23930.                 $this->svgclipmode false;
  23931.                 break;
  23932.             }
  23933.             case 'svg': {
  23934.                 if (--$this->svg_tag_depth <= 0) {
  23935.                     break;
  23936.                 }
  23937.             }
  23938.             case 'g': {
  23939.                 // ungroup: remove last style from array
  23940.                 array_pop($this->svgstyles);
  23941.                 $this->StopTransform();
  23942.                 break;
  23943.             }
  23944.             case 'text':
  23945.             case 'tspan': {
  23946.                 if ($this->svgtextmode['invisible']) {
  23947.                     // This implementation must be fixed to following the rule:
  23948.                     // If the 'visibility' property is set to hidden on a 'tspan', 'tref' or 'altGlyph' element, then the text is invisible but still takes up space in text layout calculations.
  23949.                     break;
  23950.                 }
  23951.                 // print text
  23952.                 $text $this->svgtext;
  23953.                 //$text = $this->stringTrim($text);
  23954.                 $textlen $this->GetStringWidth($text);
  23955.                 if ($this->svgtextmode['text-anchor'] != 'start') {
  23956.                     // check if string is RTL text
  23957.                     if ($this->svgtextmode['text-anchor'] == 'end') {
  23958.                         if ($this->svgtextmode['rtl']) {
  23959.                             $this->+= $textlen;
  23960.                         } else {
  23961.                             $this->-= $textlen;
  23962.                         }
  23963.                     } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  23964.                         if ($this->svgtextmode['rtl']) {
  23965.                             $this->+= ($textlen 2);
  23966.                         } else {
  23967.                             $this->-= ($textlen 2);
  23968.                         }
  23969.                     }
  23970.                 }
  23971.                 $textrendermode $this->textrendermode;
  23972.                 $textstrokewidth $this->textstrokewidth;
  23973.                 $this->setTextRenderingMode($this->svgtextmode['stroke'], truefalse);
  23974.                 if ($name == 'text') {
  23975.                     // store current coordinates
  23976.                     $tmpx $this->x;
  23977.                     $tmpy $this->y;
  23978.                 }
  23979.                 // print the text
  23980.                 $this->Cell($textlen0$text00''false''0false'L''T');
  23981.                 if ($name == 'text') {
  23982.                     // restore coordinates
  23983.                     $this->$tmpx;
  23984.                     $this->$tmpy;
  23985.                 }
  23986.                 // restore previous rendering mode
  23987.                 $this->textrendermode $textrendermode;
  23988.                 $this->textstrokewidth $textstrokewidth;
  23989.                 $this->svgtext '';
  23990.                 $this->StopTransform();
  23991.                 if (!$this->svgdefsmode) {
  23992.                     array_pop($this->svgstyles);
  23993.                 }
  23994.                 break;
  23995.             }
  23996.             default: {
  23997.                 break;
  23998.             }
  23999.         }
  24000.     }
  24001.     /**
  24002.      * Sets the character data handler function for the XML parser.
  24003.      * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  24004.      * @param string $data The second parameter, data, contains the character data as a string.
  24005.      * @author Nicola Asuni
  24006.      * @since 5.0.000 (2010-05-02)
  24007.      * @protected
  24008.      */
  24009.     protected function segSVGContentHandler($parser$data) {
  24010.         $this->svgtext .= $data;
  24011.     }
  24012.     // --- END SVG METHODS -----------------------------------------------------
  24013.     /**
  24014.      * Keeps files in memory, so it doesn't need to downloaded everytime in a loop
  24015.      * @param string $file
  24016.      * @return string
  24017.      */
  24018.     protected function getCachedFileContents($file)
  24019.     {
  24020.         if (!isset($this->fileContentCache[$file])) {
  24021.             $this->fileContentCache[$file] = TCPDF_STATIC::fileGetContents($file);
  24022.         }
  24023.         return $this->fileContentCache[$file];
  24024.     }
  24025.     /**
  24026.      * Avoid multiple calls to an external server to see if a file exists
  24027.      * @param string $file
  24028.      * @return bool
  24029.      */
  24030.     protected function fileExists($file)
  24031.     {
  24032.         if (isset($this->fileContentCache[$file]) || false !== $this->getImageBuffer($file)) {
  24033.             return true;
  24034.         }
  24035.         return TCPDF_STATIC::file_exists($file);
  24036.     }
  24037. // END OF TCPDF CLASS
  24038. //============================================================+
  24039. // END OF FILE
  24040. //============================================================+