Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  //============================================================+
   3  // File name   : tcpdf.php
   4  // Version     : 6.4.4
   5  // Begin       : 2002-08-03
   6  // Last Update : 2022-08-12
   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-2022 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  /**
  71   * @file
  72   * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  73   * 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>
  74   * <h3>TCPDF main features are:</h3>
  75   * <ul>
  76   * <li>no external libraries are required for the basic functions;</li>
  77   * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  78   * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  79   * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  80   * <li>font subsetting;</li>
  81   * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  82   * <li>images, graphic (geometric figures) and transformation methods;
  83   * <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>
  84   * <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>
  85   * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  86   * <li>automatic page header and footer management;</li>
  87   * <li>document encryption up to 256 bit and digital signature certifications;</li>
  88   * <li>transactions to UNDO commands;</li>
  89   * <li>PDF annotations, including links, text and file attachments;</li>
  90   * <li>text rendering modes (fill, stroke and clipping);</li>
  91   * <li>multiple columns mode;</li>
  92   * <li>no-write page regions;</li>
  93   * <li>bookmarks, named destinations and table of content;</li>
  94   * <li>text hyphenation;</li>
  95   * <li>text stretching and spacing (tracking);</li>
  96   * <li>automatic page break, line break and text alignments including justification;</li>
  97   * <li>automatic page numbering and page groups;</li>
  98   * <li>move and delete pages;</li>
  99   * <li>page compression (requires php-zlib extension);</li>
 100   * <li>XOBject Templates;</li>
 101   * <li>Layers and object visibility;</li>
 102   * <li>PDF/A-1b support.</li>
 103   * </ul>
 104   * Tools to encode your unicode fonts are on fonts/utils directory.</p>
 105   * @package com.tecnick.tcpdf
 106   * @author Nicola Asuni
 107   * @version 6.5.0
 108   */
 109  
 110  // TCPDF configuration
 111  require_once(dirname(__FILE__).'/tcpdf_autoconfig.php');
 112  // TCPDF static font methods and data
 113  require_once(dirname(__FILE__).'/include/tcpdf_font_data.php');
 114  // TCPDF static font methods and data
 115  require_once(dirname(__FILE__).'/include/tcpdf_fonts.php');
 116  // TCPDF static color methods and data
 117  require_once(dirname(__FILE__).'/include/tcpdf_colors.php');
 118  // TCPDF static image methods and data
 119  require_once(dirname(__FILE__).'/include/tcpdf_images.php');
 120  // TCPDF static methods and data
 121  require_once(dirname(__FILE__).'/include/tcpdf_static.php');
 122  
 123  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 124  
 125  /**
 126   * @class TCPDF
 127   * PHP class for generating PDF documents without requiring external extensions.
 128   * 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>
 129   * @package com.tecnick.tcpdf
 130   * @brief PHP class for generating PDF documents without requiring external extensions.
 131   * @version 6.3.2
 132   * @author Nicola Asuni - info@tecnick.com
 133   * @IgnoreAnnotation("protected")
 134   * @IgnoreAnnotation("public")
 135   * @IgnoreAnnotation("pre")
 136   */
 137  class TCPDF {
 138  
 139  	 // Protected properties
 140  
 141  	 /**
 142  	  * Current page number.
 143  	  * @protected
 144  	  */
 145  	 protected $page;
 146  
 147  	 /**
 148  	  * Current object number.
 149  	  * @protected
 150  	  */
 151  	 protected $n;
 152  
 153  	 /**
 154  	  * Array of object offsets.
 155  	  * @protected
 156  	  */
 157  	 protected $offsets = array();
 158  
 159  	 /**
 160  	  * Array of object IDs for each page.
 161  	  * @protected
 162  	  */
 163  	 protected $pageobjects = array();
 164  
 165  	 /**
 166  	  * Buffer holding in-memory PDF.
 167  	  * @protected
 168  	  */
 169  	 protected $buffer;
 170  
 171  	 /**
 172  	  * Array containing pages.
 173  	  * @protected
 174  	  */
 175  	 protected $pages = array();
 176  
 177  	 /**
 178  	  * Current document state.
 179  	  * @protected
 180  	  */
 181  	 protected $state;
 182  
 183  	 /**
 184  	  * Compression flag.
 185  	  * @protected
 186  	  */
 187  	 protected $compress;
 188  
 189  	 /**
 190  	  * Current page orientation (P = Portrait, L = Landscape).
 191  	  * @protected
 192  	  */
 193  	 protected $CurOrientation;
 194  
 195  	 /**
 196  	  * Page dimensions.
 197  	  * @protected
 198  	  */
 199  	 protected $pagedim = array();
 200  
 201  	 /**
 202  	  * Scale factor (number of points in user unit).
 203  	  * @protected
 204  	  */
 205  	 protected $k;
 206  
 207  	 /**
 208  	  * Width of page format in points.
 209  	  * @protected
 210  	  */
 211  	 protected $fwPt;
 212  
 213  	 /**
 214  	  * Height of page format in points.
 215  	  * @protected
 216  	  */
 217  	 protected $fhPt;
 218  
 219  	 /**
 220  	  * Current width of page in points.
 221  	  * @protected
 222  	  */
 223  	 protected $wPt;
 224  
 225  	 /**
 226  	  * Current height of page in points.
 227  	  * @protected
 228  	  */
 229  	 protected $hPt;
 230  
 231  	 /**
 232  	  * Current width of page in user unit.
 233  	  * @protected
 234  	  */
 235  	 protected $w;
 236  
 237  	 /**
 238  	  * Current height of page in user unit.
 239  	  * @protected
 240  	  */
 241  	 protected $h;
 242  
 243  	 /**
 244  	  * Left margin.
 245  	  * @protected
 246  	  */
 247  	 protected $lMargin;
 248  
 249  	 /**
 250  	  * Right margin.
 251  	  * @protected
 252  	  */
 253  	 protected $rMargin;
 254  
 255  	 /**
 256  	  * Cell left margin (used by regions).
 257  	  * @protected
 258  	  */
 259  	 protected $clMargin;
 260  
 261  	 /**
 262  	  * Cell right margin (used by regions).
 263  	  * @protected
 264  	  */
 265  	 protected $crMargin;
 266  
 267  	 /**
 268  	  * Top margin.
 269  	  * @protected
 270  	  */
 271  	 protected $tMargin;
 272  
 273  	 /**
 274  	  * Page break margin.
 275  	  * @protected
 276  	  */
 277  	 protected $bMargin;
 278  
 279  	 /**
 280  	  * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
 281  	  * @since 5.9.000 (2010-10-03)
 282  	  * @protected
 283  	  */
 284  	 protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
 285  
 286  	 /**
 287  	  * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
 288  	  * @since 5.9.000 (2010-10-04)
 289  	  * @protected
 290  	  */
 291  	 protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
 292  
 293  	 /**
 294  	  * Current horizontal position in user unit for cell positioning.
 295  	  * @protected
 296  	  */
 297  	 protected $x;
 298  
 299  	 /**
 300  	  * Current vertical position in user unit for cell positioning.
 301  	  * @protected
 302  	  */
 303  	 protected $y;
 304  
 305  	 /**
 306  	  * Height of last cell printed.
 307  	  * @protected
 308  	  */
 309  	 protected $lasth;
 310  
 311  	 /**
 312  	  * Line width in user unit.
 313  	  * @protected
 314  	  */
 315  	 protected $LineWidth;
 316  
 317  	 /**
 318  	  * Array of standard font names.
 319  	  * @protected
 320  	  */
 321  	 protected $CoreFonts;
 322  
 323  	 /**
 324  	  * Array of used fonts.
 325  	  * @protected
 326  	  */
 327  	 protected $fonts = array();
 328  
 329  	 /**
 330  	  * Array of font files.
 331  	  * @protected
 332  	  */
 333  	 protected $FontFiles = array();
 334  
 335  	 /**
 336  	  * Array of encoding differences.
 337  	  * @protected
 338  	  */
 339  	 protected $diffs = array();
 340  
 341  	 /**
 342  	  * Array of used images.
 343  	  * @protected
 344  	  */
 345  	 protected $images = array();
 346  
 347  	 /**
 348  	  * Depth of the svg tag, to keep track if the svg tag is a subtag or the root tag.
 349  	  * @protected
 350  	  */
 351  	 protected $svg_tag_depth = 0;
 352  
 353  	 /**
 354  	  * Array of Annotations in pages.
 355  	  * @protected
 356  	  */
 357  	 protected $PageAnnots = array();
 358  
 359  	 /**
 360  	  * Array of internal links.
 361  	  * @protected
 362  	  */
 363  	 protected $links = array();
 364  
 365  	 /**
 366  	  * Current font family.
 367  	  * @protected
 368  	  */
 369  	 protected $FontFamily;
 370  
 371  	 /**
 372  	  * Current font style.
 373  	  * @protected
 374  	  */
 375  	 protected $FontStyle;
 376  
 377  	 /**
 378  	  * Current font ascent (distance between font top and baseline).
 379  	  * @protected
 380  	  * @since 2.8.000 (2007-03-29)
 381  	  */
 382  	 protected $FontAscent;
 383  
 384  	 /**
 385  	  * Current font descent (distance between font bottom and baseline).
 386  	  * @protected
 387  	  * @since 2.8.000 (2007-03-29)
 388  	  */
 389  	 protected $FontDescent;
 390  
 391  	 /**
 392  	  * Underlining flag.
 393  	  * @protected
 394  	  */
 395  	 protected $underline;
 396  
 397  	 /**
 398  	  * Overlining flag.
 399  	  * @protected
 400  	  */
 401  	 protected $overline;
 402  
 403  	 /**
 404  	  * Current font info.
 405  	  * @protected
 406  	  */
 407  	 protected $CurrentFont;
 408  
 409  	 /**
 410  	  * Current font size in points.
 411  	  * @protected
 412  	  */
 413  	 protected $FontSizePt;
 414  
 415  	 /**
 416  	  * Current font size in user unit.
 417  	  * @protected
 418  	  */
 419  	 protected $FontSize;
 420  
 421  	 /**
 422  	  * Commands for drawing color.
 423  	  * @protected
 424  	  */
 425  	 protected $DrawColor;
 426  
 427  	 /**
 428  	  * Commands for filling color.
 429  	  * @protected
 430  	  */
 431  	 protected $FillColor;
 432  
 433  	 /**
 434  	  * Commands for text color.
 435  	  * @protected
 436  	  */
 437  	 protected $TextColor;
 438  
 439  	 /**
 440  	  * Indicates whether fill and text colors are different.
 441  	  * @protected
 442  	  */
 443  	 protected $ColorFlag;
 444  
 445  	 /**
 446  	  * Automatic page breaking.
 447  	  * @protected
 448  	  */
 449  	 protected $AutoPageBreak;
 450  
 451  	 /**
 452  	  * Threshold used to trigger page breaks.
 453  	  * @protected
 454  	  */
 455  	 protected $PageBreakTrigger;
 456  
 457  	 /**
 458  	  * Flag set when processing page header.
 459  	  * @protected
 460  	  */
 461  	 protected $InHeader = false;
 462  
 463  	 /**
 464  	  * Flag set when processing page footer.
 465  	  * @protected
 466  	  */
 467  	 protected $InFooter = false;
 468  
 469  	 /**
 470  	  * Zoom display mode.
 471  	  * @protected
 472  	  */
 473  	 protected $ZoomMode;
 474  
 475  	 /**
 476  	  * Layout display mode.
 477  	  * @protected
 478  	  */
 479  	 protected $LayoutMode;
 480  
 481  	 /**
 482  	  * If true set the document information dictionary in Unicode.
 483  	  * @protected
 484  	  */
 485  	 protected $docinfounicode = true;
 486  
 487  	 /**
 488  	  * Document title.
 489  	  * @protected
 490  	  */
 491  	 protected $title = '';
 492  
 493  	 /**
 494  	  * Document subject.
 495  	  * @protected
 496  	  */
 497  	 protected $subject = '';
 498  
 499  	 /**
 500  	  * Document author.
 501  	  * @protected
 502  	  */
 503  	 protected $author = '';
 504  
 505  	 /**
 506  	  * Document keywords.
 507  	  * @protected
 508  	  */
 509  	 protected $keywords = '';
 510  
 511  	 /**
 512  	  * Document creator.
 513  	  * @protected
 514  	  */
 515  	 protected $creator = '';
 516  
 517  	 /**
 518  	  * Starting page number.
 519  	  * @protected
 520  	  */
 521  	 protected $starting_page_number = 1;
 522  
 523  	 /**
 524  	  * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
 525  	  * @since 2002-07-31
 526  	  * @author Nicola Asuni
 527  	  * @protected
 528  	  */
 529  	 protected $img_rb_x;
 530  
 531  	 /**
 532  	  * The right-bottom corner Y coordinate of last inserted image.
 533  	  * @since 2002-07-31
 534  	  * @author Nicola Asuni
 535  	  * @protected
 536  	  */
 537  	 protected $img_rb_y;
 538  
 539  	 /**
 540  	  * Adjusting factor to convert pixels to user units.
 541  	  * @since 2004-06-14
 542  	  * @author Nicola Asuni
 543  	  * @protected
 544  	  */
 545  	 protected $imgscale = 1;
 546  
 547  	 /**
 548  	  * Boolean flag set to true when the input text is unicode (require unicode fonts).
 549  	  * @since 2005-01-02
 550  	  * @author Nicola Asuni
 551  	  * @protected
 552  	  */
 553  	 protected $isunicode = false;
 554  
 555  	 /**
 556  	  * PDF version.
 557  	  * @since 1.5.3
 558  	  * @protected
 559  	  */
 560  	 protected $PDFVersion = '1.7';
 561  
 562  	 /**
 563  	  * ID of the stored default header template (-1 = not set).
 564  	  * @protected
 565  	  */
 566  	 protected $header_xobjid = false;
 567  
 568  	 /**
 569  	  * If true reset the Header Xobject template at each page
 570  	  * @protected
 571  	  */
 572  	 protected $header_xobj_autoreset = false;
 573  
 574  	 /**
 575  	  * Minimum distance between header and top page margin.
 576  	  * @protected
 577  	  */
 578  	 protected $header_margin;
 579  
 580  	 /**
 581  	  * Minimum distance between footer and bottom page margin.
 582  	  * @protected
 583  	  */
 584  	 protected $footer_margin;
 585  
 586  	 /**
 587  	  * Original left margin value.
 588  	  * @protected
 589  	  * @since 1.53.0.TC013
 590  	  */
 591  	 protected $original_lMargin;
 592  
 593  	 /**
 594  	  * Original right margin value.
 595  	  * @protected
 596  	  * @since 1.53.0.TC013
 597  	  */
 598  	 protected $original_rMargin;
 599  
 600  	 /**
 601  	  * Default font used on page header.
 602  	  * @protected
 603  	  * @var array<int,string|float|null>
 604  	  * @phpstan-var array{0: string, 1: string, 2: float|null}
 605  	  */
 606  	 protected $header_font;
 607  
 608  	 /**
 609  	  * Default font used on page footer.
 610  	  * @protected
 611  	  * @var array<int,string|float|null>
 612  	  * @phpstan-var array{0: string, 1: string, 2: float|null}
 613  	  */
 614  	 protected $footer_font;
 615  
 616  	 /**
 617  	  * Language templates.
 618  	  * @protected
 619  	  */
 620  	 protected $l;
 621  
 622  	 /**
 623  	  * Barcode to print on page footer (only if set).
 624  	  * @protected
 625  	  */
 626  	 protected $barcode = false;
 627  
 628  	 /**
 629  	  * Boolean flag to print/hide page header.
 630  	  * @protected
 631  	  */
 632  	 protected $print_header = true;
 633  
 634  	 /**
 635  	  * Boolean flag to print/hide page footer.
 636  	  * @protected
 637  	  */
 638  	 protected $print_footer = true;
 639  
 640  	 /**
 641  	  * Header image logo.
 642  	  * @protected
 643  	  */
 644  	 protected $header_logo = '';
 645  
 646  	 /**
 647  	  * Width of header image logo in user units.
 648  	  * @protected
 649  	  */
 650  	 protected $header_logo_width = 30;
 651  
 652  	 /**
 653  	  * Title to be printed on default page header.
 654  	  * @protected
 655  	  */
 656  	 protected $header_title = '';
 657  
 658  	 /**
 659  	  * String to print on page header after title.
 660  	  * @protected
 661  	  */
 662  	 protected $header_string = '';
 663  
 664  	 /**
 665  	  * Color for header text (RGB array).
 666  	  * @since 5.9.174 (2012-07-25)
 667  	  * @protected
 668  	  * @var int[]
 669  	  * @phpstan-var array{0: int, 1: int, 2: int}
 670  	  */
 671  	 protected $header_text_color = array(0,0,0);
 672  
 673  	 /**
 674  	  * Color for header line (RGB array).
 675  	  * @since 5.9.174 (2012-07-25)
 676  	  * @protected
 677  	  * @var int[]
 678  	  * @phpstan-var array{0: int, 1: int, 2: int}
 679  	  */
 680  	 protected $header_line_color = array(0,0,0);
 681  
 682  	 /**
 683  	  * Color for footer text (RGB array).
 684  	  * @since 5.9.174 (2012-07-25)
 685  	  * @protected
 686  	  * @var int[]
 687  	  * @phpstan-var array{0: int, 1: int, 2: int}
 688  	  */
 689  	 protected $footer_text_color = array(0,0,0);
 690  
 691  	 /**
 692  	  * Color for footer line (RGB array).
 693  	  * @since 5.9.174 (2012-07-25)
 694  	  * @protected
 695  	  * @var int[]
 696  	  * @phpstan-var array{0: int, 1: int, 2: int}
 697  	  */
 698  	 protected $footer_line_color = array(0,0,0);
 699  
 700  	 /**
 701  	  * Text shadow data array.
 702  	  * @since 5.9.174 (2012-07-25)
 703  	  * @protected
 704  	  */
 705  	 protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
 706  
 707  	 /**
 708  	  * Default number of columns for html table.
 709  	  * @protected
 710  	  */
 711  	 protected $default_table_columns = 4;
 712  
 713  	 // variables for html parser
 714  
 715  	 /**
 716  	  * HTML PARSER: array to store current link and rendering styles.
 717  	  * @protected
 718  	  */
 719  	 protected $HREF = array();
 720  
 721  	 /**
 722  	  * List of available fonts on filesystem.
 723  	  * @protected
 724  	  */
 725  	 protected $fontlist = array();
 726  
 727  	 /**
 728  	  * Current foreground color.
 729  	  * @protected
 730  	  */
 731  	 protected $fgcolor;
 732  
 733  	 /**
 734  	  * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
 735  	  * @protected
 736  	  */
 737  	 protected $listordered = array();
 738  
 739  	 /**
 740  	  * HTML PARSER: array count list items on nested lists.
 741  	  * @protected
 742  	  */
 743  	 protected $listcount = array();
 744  
 745  	 /**
 746  	  * HTML PARSER: current list nesting level.
 747  	  * @protected
 748  	  */
 749  	 protected $listnum = 0;
 750  
 751  	 /**
 752  	  * HTML PARSER: indent amount for lists.
 753  	  * @protected
 754  	  */
 755  	 protected $listindent = 0;
 756  
 757  	 /**
 758  	  * HTML PARSER: current list indententation level.
 759  	  * @protected
 760  	  */
 761  	 protected $listindentlevel = 0;
 762  
 763  	 /**
 764  	  * Current background color.
 765  	  * @protected
 766  	  */
 767  	 protected $bgcolor;
 768  
 769  	 /**
 770  	  * Temporary font size in points.
 771  	  * @protected
 772  	  */
 773  	 protected $tempfontsize = 10;
 774  
 775  	 /**
 776  	  * Spacer string for LI tags.
 777  	  * @protected
 778  	  */
 779  	 protected $lispacer = '';
 780  
 781  	 /**
 782  	  * Default encoding.
 783  	  * @protected
 784  	  * @since 1.53.0.TC010
 785  	  */
 786  	 protected $encoding = 'UTF-8';
 787  
 788  	 /**
 789  	  * Boolean flag to indicate if the document language is Right-To-Left.
 790  	  * @protected
 791  	  * @since 2.0.000
 792  	  */
 793  	 protected $rtl = false;
 794  
 795  	 /**
 796  	  * Boolean flag used to force RTL or LTR string direction.
 797  	  * @protected
 798  	  * @since 2.0.000
 799  	  */
 800  	 protected $tmprtl = false;
 801  
 802  	 // --- Variables used for document encryption:
 803  
 804  	 /**
 805  	  * IBoolean flag indicating whether document is protected.
 806  	  * @protected
 807  	  * @since 2.0.000 (2008-01-02)
 808  	  */
 809  	 protected $encrypted;
 810  
 811  	 /**
 812  	  * Array containing encryption settings.
 813  	  * @protected
 814  	  * @since 5.0.005 (2010-05-11)
 815  	  */
 816  	 protected $encryptdata = array();
 817  
 818  	 /**
 819  	  * Last RC4 key encrypted (cached for optimisation).
 820  	  * @protected
 821  	  * @since 2.0.000 (2008-01-02)
 822  	  */
 823  	 protected $last_enc_key;
 824  
 825  	 /**
 826  	  * Last RC4 computed key.
 827  	  * @protected
 828  	  * @since 2.0.000 (2008-01-02)
 829  	  */
 830  	 protected $last_enc_key_c;
 831  
 832  	 /**
 833  	  * File ID (used on document trailer).
 834  	  * @protected
 835  	  * @since 5.0.005 (2010-05-12)
 836  	  */
 837  	 protected $file_id;
 838  
 839  	 // --- bookmark ---
 840  
 841  	 /**
 842  	  * Outlines for bookmark.
 843  	  * @protected
 844  	  * @since 2.1.002 (2008-02-12)
 845  	  */
 846  	 protected $outlines = array();
 847  
 848  	 /**
 849  	  * Outline root for bookmark.
 850  	  * @protected
 851  	  * @since 2.1.002 (2008-02-12)
 852  	  */
 853  	 protected $OutlineRoot;
 854  
 855  	 // --- javascript and form ---
 856  
 857  	 /**
 858  	  * Javascript code.
 859  	  * @protected
 860  	  * @since 2.1.002 (2008-02-12)
 861  	  */
 862  	 protected $javascript = '';
 863  
 864  	 /**
 865  	  * Javascript counter.
 866  	  * @protected
 867  	  * @since 2.1.002 (2008-02-12)
 868  	  */
 869  	 protected $n_js;
 870  
 871  	 /**
 872  	  * line through state
 873  	  * @protected
 874  	  * @since 2.8.000 (2008-03-19)
 875  	  */
 876  	 protected $linethrough;
 877  
 878  	 /**
 879  	  * Array with additional document-wide usage rights for the document.
 880  	  * @protected
 881  	  * @since 5.8.014 (2010-08-23)
 882  	  */
 883  	 protected $ur = array();
 884  
 885  	 /**
 886  	  * DPI (Dot Per Inch) Document Resolution (do not change).
 887  	  * @protected
 888  	  * @since 3.0.000 (2008-03-27)
 889  	  */
 890  	 protected $dpi = 72;
 891  
 892  	 /**
 893  	  * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
 894  	  * @protected
 895  	  * @since 3.0.000 (2008-03-27)
 896  	  */
 897  	 protected $newpagegroup = array();
 898  
 899  	 /**
 900  	  * Array that contains the number of pages in each page group.
 901  	  * @protected
 902  	  * @since 3.0.000 (2008-03-27)
 903  	  */
 904  	 protected $pagegroups = array();
 905  
 906  	 /**
 907  	  * Current page group number.
 908  	  * @protected
 909  	  * @since 3.0.000 (2008-03-27)
 910  	  */
 911  	 protected $currpagegroup = 0;
 912  
 913  	 /**
 914  	  * Array of transparency objects and parameters.
 915  	  * @protected
 916  	  * @since 3.0.000 (2008-03-27)
 917  	  */
 918  	 protected $extgstates;
 919  
 920  	 /**
 921  	  * Set the default JPEG compression quality (1-100).
 922  	  * @protected
 923  	  * @since 3.0.000 (2008-03-27)
 924  	  */
 925  	 protected $jpeg_quality;
 926  
 927  	 /**
 928  	  * Default cell height ratio.
 929  	  * @protected
 930  	  * @since 3.0.014 (2008-05-23)
 931  	  * @var float
 932  	  */
 933  	 protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
 934  
 935  	 /**
 936  	  * PDF viewer preferences.
 937  	  * @protected
 938  	  * @since 3.1.000 (2008-06-09)
 939  	  */
 940  	 protected $viewer_preferences;
 941  
 942  	 /**
 943  	  * A name object specifying how the document should be displayed when opened.
 944  	  * @protected
 945  	  * @since 3.1.000 (2008-06-09)
 946  	  */
 947  	 protected $PageMode;
 948  
 949  	 /**
 950  	  * Array for storing gradient information.
 951  	  * @protected
 952  	  * @since 3.1.000 (2008-06-09)
 953  	  */
 954  	 protected $gradients = array();
 955  
 956  	 /**
 957  	  * Array used to store positions inside the pages buffer (keys are the page numbers).
 958  	  * @protected
 959  	  * @since 3.2.000 (2008-06-26)
 960  	  */
 961  	 protected $intmrk = array();
 962  
 963  	 /**
 964  	  * Array used to store positions inside the pages buffer (keys are the page numbers).
 965  	  * @protected
 966  	  * @since 5.7.000 (2010-08-03)
 967  	  */
 968  	 protected $bordermrk = array();
 969  
 970  	 /**
 971  	  * Array used to store page positions to track empty pages (keys are the page numbers).
 972  	  * @protected
 973  	  * @since 5.8.007 (2010-08-18)
 974  	  */
 975  	 protected $emptypagemrk = array();
 976  
 977  	 /**
 978  	  * Array used to store content positions inside the pages buffer (keys are the page numbers).
 979  	  * @protected
 980  	  * @since 4.6.021 (2009-07-20)
 981  	  */
 982  	 protected $cntmrk = array();
 983  
 984  	 /**
 985  	  * Array used to store footer positions of each page.
 986  	  * @protected
 987  	  * @since 3.2.000 (2008-07-01)
 988  	  */
 989  	 protected $footerpos = array();
 990  
 991  	 /**
 992  	  * Array used to store footer length of each page.
 993  	  * @protected
 994  	  * @since 4.0.014 (2008-07-29)
 995  	  */
 996  	 protected $footerlen = array();
 997  
 998  	 /**
 999  	  * Boolean flag to indicate if a new line is created.
1000  	  * @protected
1001  	  * @since 3.2.000 (2008-07-01)
1002  	  */
1003  	 protected $newline = true;
1004  
1005  	 /**
1006  	  * End position of the latest inserted line.
1007  	  * @protected
1008  	  * @since 3.2.000 (2008-07-01)
1009  	  */
1010  	 protected $endlinex = 0;
1011  
1012  	 /**
1013  	  * PDF string for width value of the last line.
1014  	  * @protected
1015  	  * @since 4.0.006 (2008-07-16)
1016  	  */
1017  	 protected $linestyleWidth = '';
1018  
1019  	 /**
1020  	  * PDF string for CAP value of the last line.
1021  	  * @protected
1022  	  * @since 4.0.006 (2008-07-16)
1023  	  */
1024  	 protected $linestyleCap = '0 J';
1025  
1026  	 /**
1027  	  * PDF string for join value of the last line.
1028  	  * @protected
1029  	  * @since 4.0.006 (2008-07-16)
1030  	  */
1031  	 protected $linestyleJoin = '0 j';
1032  
1033  	 /**
1034  	  * PDF string for dash value of the last line.
1035  	  * @protected
1036  	  * @since 4.0.006 (2008-07-16)
1037  	  */
1038  	 protected $linestyleDash = '[] 0 d';
1039  
1040  	 /**
1041  	  * Boolean flag to indicate if marked-content sequence is open.
1042  	  * @protected
1043  	  * @since 4.0.013 (2008-07-28)
1044  	  */
1045  	 protected $openMarkedContent = false;
1046  
1047  	 /**
1048  	  * Count the latest inserted vertical spaces on HTML.
1049  	  * @protected
1050  	  * @since 4.0.021 (2008-08-24)
1051  	  */
1052  	 protected $htmlvspace = 0;
1053  
1054  	 /**
1055  	  * Array of Spot colors.
1056  	  * @protected
1057  	  * @since 4.0.024 (2008-09-12)
1058  	  */
1059  	 protected $spot_colors = array();
1060  
1061  	 /**
1062  	  * Symbol used for HTML unordered list items.
1063  	  * @protected
1064  	  * @since 4.0.028 (2008-09-26)
1065  	  */
1066  	 protected $lisymbol = '';
1067  
1068  	 /**
1069  	  * String used to mark the beginning and end of EPS image blocks.
1070  	  * @protected
1071  	  * @since 4.1.000 (2008-10-18)
1072  	  */
1073  	 protected $epsmarker = 'x#!#EPS#!#x';
1074  
1075  	 /**
1076  	  * Array of transformation matrix.
1077  	  * @protected
1078  	  * @since 4.2.000 (2008-10-29)
1079  	  */
1080  	 protected $transfmatrix = array();
1081  
1082  	 /**
1083  	  * Current key for transformation matrix.
1084  	  * @protected
1085  	  * @since 4.8.005 (2009-09-17)
1086  	  */
1087  	 protected $transfmatrix_key = 0;
1088  
1089  	 /**
1090  	  * Booklet mode for double-sided pages.
1091  	  * @protected
1092  	  * @since 4.2.000 (2008-10-29)
1093  	  */
1094  	 protected $booklet = false;
1095  
1096  	 /**
1097  	  * Epsilon value used for float calculations.
1098  	  * @protected
1099  	  * @since 4.2.000 (2008-10-29)
1100  	  */
1101  	 protected $feps = 0.005;
1102  
1103  	 /**
1104  	  * Array used for custom vertical spaces for HTML tags.
1105  	  * @protected
1106  	  * @since 4.2.001 (2008-10-30)
1107  	  */
1108  	 protected $tagvspaces = array();
1109  
1110  	 /**
1111  	  * HTML PARSER: custom indent amount for lists. Negative value means disabled.
1112  	  * @protected
1113  	  * @since 4.2.007 (2008-11-12)
1114  	  */
1115  	 protected $customlistindent = -1;
1116  
1117  	 /**
1118  	  * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
1119  	  * @protected
1120  	  * @since 4.2.010 (2008-11-14)
1121  	  */
1122  	 protected $opencell = true;
1123  
1124  	 /**
1125  	  * Array of files to embedd.
1126  	  * @protected
1127  	  * @since 4.4.000 (2008-12-07)
1128  	  */
1129  	 protected $embeddedfiles = array();
1130  
1131  	 /**
1132  	  * Boolean flag to indicate if we are inside a PRE tag.
1133  	  * @protected
1134  	  * @since 4.4.001 (2008-12-08)
1135  	  */
1136  	 protected $premode = false;
1137  
1138  	 /**
1139  	  * Array used to store positions of graphics transformation blocks inside the page buffer.
1140  	  * keys are the page numbers
1141  	  * @protected
1142  	  * @since 4.4.002 (2008-12-09)
1143  	  */
1144  	 protected $transfmrk = array();
1145  
1146  	 /**
1147  	  * Default color for html links.
1148  	  * @protected
1149  	  * @since 4.4.003 (2008-12-09)
1150  	  */
1151  	 protected $htmlLinkColorArray = array(0, 0, 255);
1152  
1153  	 /**
1154  	  * Default font style to add to html links.
1155  	  * @protected
1156  	  * @since 4.4.003 (2008-12-09)
1157  	  */
1158  	 protected $htmlLinkFontStyle = 'U';
1159  
1160  	 /**
1161  	  * Counts the number of pages.
1162  	  * @protected
1163  	  * @since 4.5.000 (2008-12-31)
1164  	  */
1165  	 protected $numpages = 0;
1166  
1167  	 /**
1168  	  * Array containing page lengths in bytes.
1169  	  * @protected
1170  	  * @since 4.5.000 (2008-12-31)
1171  	  */
1172  	 protected $pagelen = array();
1173  
1174  	 /**
1175  	  * Counts the number of pages.
1176  	  * @protected
1177  	  * @since 4.5.000 (2008-12-31)
1178  	  */
1179  	 protected $numimages = 0;
1180  
1181  	 /**
1182  	  * Store the image keys.
1183  	  * @protected
1184  	  * @since 4.5.000 (2008-12-31)
1185  	  */
1186  	 protected $imagekeys = array();
1187  
1188  	 /**
1189  	  * Length of the buffer in bytes.
1190  	  * @protected
1191  	  * @since 4.5.000 (2008-12-31)
1192  	  */
1193  	 protected $bufferlen = 0;
1194  
1195  	 /**
1196  	  * Counts the number of fonts.
1197  	  * @protected
1198  	  * @since 4.5.000 (2009-01-02)
1199  	  */
1200  	 protected $numfonts = 0;
1201  
1202  	 /**
1203  	  * Store the font keys.
1204  	  * @protected
1205  	  * @since 4.5.000 (2009-01-02)
1206  	  */
1207  	 protected $fontkeys = array();
1208  
1209  	 /**
1210  	  * Store the font object IDs.
1211  	  * @protected
1212  	  * @since 4.8.001 (2009-09-09)
1213  	  */
1214  	 protected $font_obj_ids = array();
1215  
1216  	 /**
1217  	  * Store the fage status (true when opened, false when closed).
1218  	  * @protected
1219  	  * @since 4.5.000 (2009-01-02)
1220  	  */
1221  	 protected $pageopen = array();
1222  
1223  	 /**
1224  	  * Default monospace font.
1225  	  * @protected
1226  	  * @since 4.5.025 (2009-03-10)
1227  	  */
1228  	 protected $default_monospaced_font = 'courier';
1229  
1230  	 /**
1231  	  * Cloned copy of the current class object.
1232  	  * @protected
1233  	  * @since 4.5.029 (2009-03-19)
1234  	  */
1235  	 protected $objcopy;
1236  
1237  	 /**
1238  	  * Array used to store the lengths of cache files.
1239  	  * @protected
1240  	  * @since 4.5.029 (2009-03-19)
1241  	  */
1242  	 protected $cache_file_length = array();
1243  
1244  	 /**
1245  	  * Table header content to be repeated on each new page.
1246  	  * @protected
1247  	  * @since 4.5.030 (2009-03-20)
1248  	  */
1249  	 protected $thead = '';
1250  
1251  	 /**
1252  	  * Margins used for table header.
1253  	  * @protected
1254  	  * @since 4.5.030 (2009-03-20)
1255  	  */
1256  	 protected $theadMargins = array();
1257  
1258  	 /**
1259  	  * Boolean flag to enable document digital signature.
1260  	  * @protected
1261  	  * @since 4.6.005 (2009-04-24)
1262  	  */
1263  	 protected $sign = false;
1264  
1265  	 /**
1266  	  * Digital signature data.
1267  	  * @protected
1268  	  * @since 4.6.005 (2009-04-24)
1269  	  */
1270  	 protected $signature_data = array();
1271  
1272  	 /**
1273  	  * Digital signature max length.
1274  	  * @protected
1275  	  * @since 4.6.005 (2009-04-24)
1276  	  */
1277  	 protected $signature_max_length = 11742;
1278  
1279  	 /**
1280  	  * Data for digital signature appearance.
1281  	  * @protected
1282  	  * @since 5.3.011 (2010-06-16)
1283  	  */
1284  	 protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
1285  
1286  	 /**
1287  	  * Array of empty digital signature appearances.
1288  	  * @protected
1289  	  * @since 5.9.101 (2011-07-06)
1290  	  */
1291  	 protected $empty_signature_appearance = array();
1292  
1293  	 /**
1294  	  * Boolean flag to enable document timestamping with TSA.
1295  	  * @protected
1296  	  * @since 6.0.085 (2014-06-19)
1297  	  */
1298  	 protected $tsa_timestamp = false;
1299  
1300  	 /**
1301  	  * Timestamping data.
1302  	  * @protected
1303  	  * @since 6.0.085 (2014-06-19)
1304  	  */
1305  	 protected $tsa_data = array();
1306  
1307  	 /**
1308  	  * Regular expression used to find blank characters (required for word-wrapping).
1309  	  * @protected
1310  	  * @since 4.6.006 (2009-04-28)
1311  	  */
1312  	 protected $re_spaces = '/[^\S\xa0]/';
1313  
1314  	 /**
1315  	  * Array of $re_spaces parts.
1316  	  * @protected
1317  	  * @since 5.5.011 (2010-07-09)
1318  	  */
1319  	 protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
1320  
1321  	 /**
1322  	  * Digital signature object ID.
1323  	  * @protected
1324  	  * @since 4.6.022 (2009-06-23)
1325  	  */
1326  	 protected $sig_obj_id = 0;
1327  
1328  	 /**
1329  	  * ID of page objects.
1330  	  * @protected
1331  	  * @since 4.7.000 (2009-08-29)
1332  	  */
1333  	 protected $page_obj_id = array();
1334  
1335  	 /**
1336  	  * List of form annotations IDs.
1337  	  * @protected
1338  	  * @since 4.8.000 (2009-09-07)
1339  	  */
1340  	 protected $form_obj_id = array();
1341  
1342  	 /**
1343  	  * 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.
1344  	  * @protected
1345  	  * @since 4.8.000 (2009-09-07)
1346  	  */
1347  	 protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
1348  
1349  	 /**
1350  	  * Javascript objects array.
1351  	  * @protected
1352  	  * @since 4.8.000 (2009-09-07)
1353  	  */
1354  	 protected $js_objects = array();
1355  
1356  	 /**
1357  	  * Current form action (used during XHTML rendering).
1358  	  * @protected
1359  	  * @since 4.8.000 (2009-09-07)
1360  	  */
1361  	 protected $form_action = '';
1362  
1363  	 /**
1364  	  * Current form encryption type (used during XHTML rendering).
1365  	  * @protected
1366  	  * @since 4.8.000 (2009-09-07)
1367  	  */
1368  	 protected $form_enctype = 'application/x-www-form-urlencoded';
1369  
1370  	 /**
1371  	  * Current method to submit forms.
1372  	  * @protected
1373  	  * @since 4.8.000 (2009-09-07)
1374  	  */
1375  	 protected $form_mode = 'post';
1376  
1377  	 /**
1378  	  * List of fonts used on form fields (fontname => fontkey).
1379  	  * @protected
1380  	  * @since 4.8.001 (2009-09-09)
1381  	  */
1382  	 protected $annotation_fonts = array();
1383  
1384  	 /**
1385  	  * List of radio buttons parent objects.
1386  	  * @protected
1387  	  * @since 4.8.001 (2009-09-09)
1388  	  */
1389  	 protected $radiobutton_groups = array();
1390  
1391  	 /**
1392  	  * List of radio group objects IDs.
1393  	  * @protected
1394  	  * @since 4.8.001 (2009-09-09)
1395  	  */
1396  	 protected $radio_groups = array();
1397  
1398  	 /**
1399  	  * Text indentation value (used for text-indent CSS attribute).
1400  	  * @protected
1401  	  * @since 4.8.006 (2009-09-23)
1402  	  */
1403  	 protected $textindent = 0;
1404  
1405  	 /**
1406  	  * Store page number when startTransaction() is called.
1407  	  * @protected
1408  	  * @since 4.8.006 (2009-09-23)
1409  	  */
1410  	 protected $start_transaction_page = 0;
1411  
1412  	 /**
1413  	  * Store Y position when startTransaction() is called.
1414  	  * @protected
1415  	  * @since 4.9.001 (2010-03-28)
1416  	  */
1417  	 protected $start_transaction_y = 0;
1418  
1419  	 /**
1420  	  * True when we are printing the thead section on a new page.
1421  	  * @protected
1422  	  * @since 4.8.027 (2010-01-25)
1423  	  */
1424  	 protected $inthead = false;
1425  
1426  	 /**
1427  	  * Array of column measures (width, space, starting Y position).
1428  	  * @protected
1429  	  * @since 4.9.001 (2010-03-28)
1430  	  */
1431  	 protected $columns = array();
1432  
1433  	 /**
1434  	  * Number of colums.
1435  	  * @protected
1436  	  * @since 4.9.001 (2010-03-28)
1437  	  */
1438  	 protected $num_columns = 1;
1439  
1440  	 /**
1441  	  * Current column number.
1442  	  * @protected
1443  	  * @since 4.9.001 (2010-03-28)
1444  	  */
1445  	 protected $current_column = 0;
1446  
1447  	 /**
1448  	  * Starting page for columns.
1449  	  * @protected
1450  	  * @since 4.9.001 (2010-03-28)
1451  	  */
1452  	 protected $column_start_page = 0;
1453  
1454  	 /**
1455  	  * Maximum page and column selected.
1456  	  * @protected
1457  	  * @since 5.8.000 (2010-08-11)
1458  	  */
1459  	 protected $maxselcol = array('page' => 0, 'column' => 0);
1460  
1461  	 /**
1462  	  * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
1463  	  * @protected
1464  	  * @since 5.8.000 (2010-08-11)
1465  	  */
1466  	 protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
1467  
1468  	 /**
1469  	  * 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.
1470  	  * @protected
1471  	  * @since 4.9.008 (2010-04-03)
1472  	  */
1473  	 protected $textrendermode = 0;
1474  
1475  	 /**
1476  	  * Text stroke width in doc units.
1477  	  * @protected
1478  	  * @since 4.9.008 (2010-04-03)
1479  	  */
1480  	 protected $textstrokewidth = 0;
1481  
1482  	 /**
1483  	  * Current stroke color.
1484  	  * @protected
1485  	  * @since 4.9.008 (2010-04-03)
1486  	  */
1487  	 protected $strokecolor;
1488  
1489  	 /**
1490  	  * Default unit of measure for document.
1491  	  * @protected
1492  	  * @since 5.0.000 (2010-04-22)
1493  	  */
1494  	 protected $pdfunit = 'mm';
1495  
1496  	 /**
1497  	  * Boolean flag true when we are on TOC (Table Of Content) page.
1498  	  * @protected
1499  	  */
1500  	 protected $tocpage = false;
1501  
1502  	 /**
1503  	  * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
1504  	  * @protected
1505  	  * @since 5.0.000 (2010-04-26)
1506  	  */
1507  	 protected $rasterize_vector_images = false;
1508  
1509  	 /**
1510  	  * Boolean flag: if true enables font subsetting by default.
1511  	  * @protected
1512  	  * @since 5.3.002 (2010-06-07)
1513  	  */
1514  	 protected $font_subsetting = true;
1515  
1516  	 /**
1517  	  * Array of default graphic settings.
1518  	  * @protected
1519  	  * @since 5.5.008 (2010-07-02)
1520  	  */
1521  	 protected $default_graphic_vars = array();
1522  
1523  	 /**
1524  	  * Array of XObjects.
1525  	  * @protected
1526  	  * @since 5.8.014 (2010-08-23)
1527  	  */
1528  	 protected $xobjects = array();
1529  
1530  	 /**
1531  	  * Boolean value true when we are inside an XObject.
1532  	  * @protected
1533  	  * @since 5.8.017 (2010-08-24)
1534  	  */
1535  	 protected $inxobj = false;
1536  
1537  	 /**
1538  	  * Current XObject ID.
1539  	  * @protected
1540  	  * @since 5.8.017 (2010-08-24)
1541  	  */
1542  	 protected $xobjid = '';
1543  
1544  	 /**
1545  	  * Percentage of character stretching.
1546  	  * @protected
1547  	  * @since 5.9.000 (2010-09-29)
1548  	  */
1549  	 protected $font_stretching = 100;
1550  
1551  	 /**
1552  	  * Increases or decreases the space between characters in a text by the specified amount (tracking).
1553  	  * @protected
1554  	  * @since 5.9.000 (2010-09-29)
1555  	  */
1556  	 protected $font_spacing = 0;
1557  
1558  	 /**
1559  	  * Array of no-write regions.
1560  	  * ('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)
1561  	  * @protected
1562  	  * @since 5.9.003 (2010-10-14)
1563  	  */
1564  	 protected $page_regions = array();
1565  
1566  	 /**
1567  	  * Boolean value true when page region check is active.
1568  	  * @protected
1569  	  */
1570  	 protected $check_page_regions = true;
1571  
1572  	 /**
1573  	  * Array of PDF layers data.
1574  	  * @protected
1575  	  * @since 5.9.102 (2011-07-13)
1576  	  */
1577  	 protected $pdflayers = array();
1578  
1579  	 /**
1580  	  * A dictionary of names and corresponding destinations (Dests key on document Catalog).
1581  	  * @protected
1582  	  * @since 5.9.097 (2011-06-23)
1583  	  */
1584  	 protected $dests = array();
1585  
1586  	 /**
1587  	  * Object ID for Named Destinations
1588  	  * @protected
1589  	  * @since 5.9.097 (2011-06-23)
1590  	  */
1591  	 protected $n_dests;
1592  
1593  	 /**
1594  	  * Embedded Files Names
1595  	  * @protected
1596  	  * @since 5.9.204 (2013-01-23)
1597  	  */
1598  	 protected $efnames = array();
1599  
1600  	 /**
1601  	  * Directory used for the last SVG image.
1602  	  * @protected
1603  	  * @since 5.0.000 (2010-05-05)
1604  	  */
1605  	 protected $svgdir = '';
1606  
1607  	 /**
1608  	  *  Deafult unit of measure for SVG.
1609  	  * @protected
1610  	  * @since 5.0.000 (2010-05-02)
1611  	  */
1612  	 protected $svgunit = 'px';
1613  
1614  	 /**
1615  	  * Array of SVG gradients.
1616  	  * @protected
1617  	  * @since 5.0.000 (2010-05-02)
1618  	  */
1619  	 protected $svggradients = array();
1620  
1621  	 /**
1622  	  * ID of last SVG gradient.
1623  	  * @protected
1624  	  * @since 5.0.000 (2010-05-02)
1625  	  */
1626  	 protected $svggradientid = 0;
1627  
1628  	 /**
1629  	  * Boolean value true when in SVG defs group.
1630  	  * @protected
1631  	  * @since 5.0.000 (2010-05-02)
1632  	  */
1633  	 protected $svgdefsmode = false;
1634  
1635  	 /**
1636  	  * Array of SVG defs.
1637  	  * @protected
1638  	  * @since 5.0.000 (2010-05-02)
1639  	  */
1640  	 protected $svgdefs = array();
1641  
1642  	 /**
1643  	  * Boolean value true when in SVG clipPath tag.
1644  	  * @protected
1645  	  * @since 5.0.000 (2010-04-26)
1646  	  */
1647  	 protected $svgclipmode = false;
1648  
1649  	 /**
1650  	  * Array of SVG clipPath commands.
1651  	  * @protected
1652  	  * @since 5.0.000 (2010-05-02)
1653  	  */
1654  	 protected $svgclippaths = array();
1655  
1656  	 /**
1657  	  * Array of SVG clipPath tranformation matrix.
1658  	  * @protected
1659  	  * @since 5.8.022 (2010-08-31)
1660  	  */
1661  	 protected $svgcliptm = array();
1662  
1663  	 /**
1664  	  * ID of last SVG clipPath.
1665  	  * @protected
1666  	  * @since 5.0.000 (2010-05-02)
1667  	  */
1668  	 protected $svgclipid = 0;
1669  
1670  	 /**
1671  	  * SVG text.
1672  	  * @protected
1673  	  * @since 5.0.000 (2010-05-02)
1674  	  */
1675  	 protected $svgtext = '';
1676  
1677  	 /**
1678  	  * SVG text properties.
1679  	  * @protected
1680  	  * @since 5.8.013 (2010-08-23)
1681  	  */
1682  	 protected $svgtextmode = array();
1683  
1684  	 /**
1685  	  * Array of SVG properties.
1686  	  * @protected
1687  	  * @since 5.0.000 (2010-05-02)
1688  	  */
1689  	 protected $svgstyles = array(array(
1690  	 	 'alignment-baseline' => 'auto',
1691  	 	 'baseline-shift' => 'baseline',
1692  	 	 'clip' => 'auto',
1693  	 	 'clip-path' => 'none',
1694  	 	 'clip-rule' => 'nonzero',
1695  	 	 'color' => 'black',
1696  	 	 'color-interpolation' => 'sRGB',
1697  	 	 'color-interpolation-filters' => 'linearRGB',
1698  	 	 'color-profile' => 'auto',
1699  	 	 'color-rendering' => 'auto',
1700  	 	 'cursor' => 'auto',
1701  	 	 'direction' => 'ltr',
1702  	 	 'display' => 'inline',
1703  	 	 'dominant-baseline' => 'auto',
1704  	 	 'enable-background' => 'accumulate',
1705  	 	 'fill' => 'black',
1706  	 	 'fill-opacity' => 1,
1707  	 	 'fill-rule' => 'nonzero',
1708  	 	 'filter' => 'none',
1709  	 	 'flood-color' => 'black',
1710  	 	 'flood-opacity' => 1,
1711  	 	 'font' => '',
1712  	 	 'font-family' => 'helvetica',
1713  	 	 'font-size' => 'medium',
1714  	 	 'font-size-adjust' => 'none',
1715  	 	 'font-stretch' => 'normal',
1716  	 	 'font-style' => 'normal',
1717  	 	 'font-variant' => 'normal',
1718  	 	 'font-weight' => 'normal',
1719  	 	 'glyph-orientation-horizontal' => '0deg',
1720  	 	 'glyph-orientation-vertical' => 'auto',
1721  	 	 'image-rendering' => 'auto',
1722  	 	 'kerning' => 'auto',
1723  	 	 'letter-spacing' => 'normal',
1724  	 	 'lighting-color' => 'white',
1725  	 	 'marker' => '',
1726  	 	 'marker-end' => 'none',
1727  	 	 'marker-mid' => 'none',
1728  	 	 'marker-start' => 'none',
1729  	 	 'mask' => 'none',
1730  	 	 'opacity' => 1,
1731  	 	 'overflow' => 'auto',
1732  	 	 'pointer-events' => 'visiblePainted',
1733  	 	 'shape-rendering' => 'auto',
1734  	 	 'stop-color' => 'black',
1735  	 	 'stop-opacity' => 1,
1736  	 	 'stroke' => 'none',
1737  	 	 'stroke-dasharray' => 'none',
1738  	 	 'stroke-dashoffset' => 0,
1739  	 	 'stroke-linecap' => 'butt',
1740  	 	 'stroke-linejoin' => 'miter',
1741  	 	 'stroke-miterlimit' => 4,
1742  	 	 'stroke-opacity' => 1,
1743  	 	 'stroke-width' => 1,
1744  	 	 'text-anchor' => 'start',
1745  	 	 'text-decoration' => 'none',
1746  	 	 'text-rendering' => 'auto',
1747  	 	 'unicode-bidi' => 'normal',
1748  	 	 'visibility' => 'visible',
1749  	 	 'word-spacing' => 'normal',
1750  	 	 'writing-mode' => 'lr-tb',
1751  	 	 'text-color' => 'black',
1752  	 	 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
1753  	 	 ));
1754  
1755  	 /**
1756  	  * If true force sRGB color profile for all document.
1757  	  * @protected
1758  	  * @since 5.9.121 (2011-09-28)
1759  	  */
1760  	 protected $force_srgb = false;
1761  
1762  	 /**
1763  	  * If true set the document to PDF/A mode.
1764  	  * @protected
1765  	  * @since 5.9.121 (2011-09-27)
1766  	  */
1767  	 protected $pdfa_mode = false;
1768  
1769  	 /**
1770  	  * version of PDF/A mode (1 - 3).
1771  	  * @protected
1772  	  * @since 6.2.26 (2019-03-12)
1773  	  */
1774  	 protected $pdfa_version = 1;
1775  
1776  	 /**
1777  	  * Document creation date-time
1778  	  * @protected
1779  	  * @since 5.9.152 (2012-03-22)
1780  	  */
1781  	 protected $doc_creation_timestamp;
1782  
1783  	 /**
1784  	  * Document modification date-time
1785  	  * @protected
1786  	  * @since 5.9.152 (2012-03-22)
1787  	  */
1788  	 protected $doc_modification_timestamp;
1789  
1790  	 /**
1791  	  * Custom XMP data.
1792  	  * @protected
1793  	  * @since 5.9.128 (2011-10-06)
1794  	  */
1795  	 protected $custom_xmp = '';
1796  
1797  	 /**
1798  	  * Custom XMP RDF data.
1799  	  * @protected
1800  	  * @since 6.3.0 (2019-09-19)
1801  	  */
1802  	 protected $custom_xmp_rdf = '';
1803  
1804  	 /**
1805  	  * Overprint mode array.
1806  	  * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
1807  	  * @protected
1808  	  * @since 5.9.152 (2012-03-23)
1809  	  * @var array<string,bool|int>
1810  	  */
1811  	 protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
1812  
1813  	 /**
1814  	  * Alpha mode array.
1815  	  * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
1816  	  * @protected
1817  	  * @since 5.9.152 (2012-03-23)
1818  	  */
1819  	 protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
1820  
1821  	 /**
1822  	  * Define the page boundaries boxes to be set on document.
1823  	  * @protected
1824  	  * @since 5.9.152 (2012-03-23)
1825  	  */
1826  	 protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
1827  
1828  	 /**
1829  	  * If true print TCPDF meta link.
1830  	  * @protected
1831  	  * @since 5.9.152 (2012-03-23)
1832  	  */
1833  	 protected $tcpdflink = true;
1834  
1835  	 /**
1836  	  * Cache array for computed GD gamma values.
1837  	  * @protected
1838  	  * @since 5.9.1632 (2012-06-05)
1839  	  */
1840  	 protected $gdgammacache = array();
1841  
1842      /**
1843       * Cache array for file content
1844       * @protected
1845       * @var array
1846       * @since 6.3.5 (2020-09-28)
1847       */
1848  	 protected $fileContentCache = array();
1849  
1850  	 /**
1851  	  * Whether to allow local file path in image html tags, when prefixed with file://
1852  	  *
1853  	  * @var bool
1854  	  * @protected
1855  	  * @since 6.4 (2020-07-23)
1856  	  */
1857  	 protected $allowLocalFiles = false;
1858  
1859  	 //------------------------------------------------------------
1860  	 // METHODS
1861  	 //------------------------------------------------------------
1862  
1863  	 /**
1864  	  * This is the class constructor.
1865  	  * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
1866  	  *
1867  	  * @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>
1868  	  * @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.
1869  	  * @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().
1870  	  * @param boolean $unicode TRUE means that the input text is unicode (default = true)
1871  	  * @param string $encoding Charset encoding (used only when converting back html entities); default is UTF-8.
1872  	  * @param boolean $diskcache DEPRECATED FEATURE
1873  	  * @param false|integer $pdfa If not false, set the document to PDF/A mode and the good version (1 or 3).
1874  	  * @public
1875  	  * @see getPageSizeFromFormat(), setPageFormat()
1876  	  */
1877  	public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
1878  	 	 // set file ID for trailer
1879  	 	 $serformat = (is_array($format) ? json_encode($format) : $format);
1880  	 	 $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
1881  	 	 $this->font_obj_ids = array();
1882  	 	 $this->page_obj_id = array();
1883  	 	 $this->form_obj_id = array();
1884  
1885  	 	 // set pdf/a mode
1886  	 	 if ($pdfa != false) {
1887  	 	 	 $this->pdfa_mode = true;
1888  	 	 	 $this->pdfa_version = $pdfa;  // 1 or 3
1889  	 	 } else
1890  	 	 	 $this->pdfa_mode = false;
1891  
1892  	 	 $this->force_srgb = false;
1893  	 	 // set language direction
1894  	 	 $this->rtl = false;
1895  	 	 $this->tmprtl = false;
1896  	 	 // some checks
1897  	 	 $this->_dochecks();
1898  	 	 // initialization of properties
1899  	 	 $this->isunicode = $unicode;
1900  	 	 $this->page = 0;
1901  	 	 $this->transfmrk[0] = array();
1902  	 	 $this->pagedim = array();
1903  	 	 $this->n = 2;
1904  	 	 $this->buffer = '';
1905  	 	 $this->pages = array();
1906  	 	 $this->state = 0;
1907  	 	 $this->fonts = array();
1908  	 	 $this->FontFiles = array();
1909  	 	 $this->diffs = array();
1910  	 	 $this->images = array();
1911  	 	 $this->links = array();
1912  	 	 $this->gradients = array();
1913  	 	 $this->InFooter = false;
1914  	 	 $this->lasth = 0;
1915  	 	 $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
1916  	 	 $this->FontStyle = '';
1917  	 	 $this->FontSizePt = 12;
1918  	 	 $this->underline = false;
1919  	 	 $this->overline = false;
1920  	 	 $this->linethrough = false;
1921  	 	 $this->DrawColor = '0 G';
1922  	 	 $this->FillColor = '0 g';
1923  	 	 $this->TextColor = '0 g';
1924  	 	 $this->ColorFlag = false;
1925  	 	 $this->pdflayers = array();
1926  	 	 // encryption values
1927  	 	 $this->encrypted = false;
1928  	 	 $this->last_enc_key = '';
1929  	 	 // standard Unicode fonts
1930  	 	 $this->CoreFonts = array(
1931  	 	 	 'courier'=>'Courier',
1932  	 	 	 'courierB'=>'Courier-Bold',
1933  	 	 	 'courierI'=>'Courier-Oblique',
1934  	 	 	 'courierBI'=>'Courier-BoldOblique',
1935  	 	 	 'helvetica'=>'Helvetica',
1936  	 	 	 'helveticaB'=>'Helvetica-Bold',
1937  	 	 	 'helveticaI'=>'Helvetica-Oblique',
1938  	 	 	 'helveticaBI'=>'Helvetica-BoldOblique',
1939  	 	 	 'times'=>'Times-Roman',
1940  	 	 	 'timesB'=>'Times-Bold',
1941  	 	 	 'timesI'=>'Times-Italic',
1942  	 	 	 'timesBI'=>'Times-BoldItalic',
1943  	 	 	 'symbol'=>'Symbol',
1944  	 	 	 'zapfdingbats'=>'ZapfDingbats'
1945  	 	 );
1946  	 	 // set scale factor
1947  	 	 $this->setPageUnit($unit);
1948  	 	 // set page format and orientation
1949  	 	 $this->setPageFormat($format, $orientation);
1950  	 	 // page margins (1 cm)
1951  	 	 $margin = 28.35 / $this->k;
1952  	 	 $this->setMargins($margin, $margin);
1953  	 	 $this->clMargin = $this->lMargin;
1954  	 	 $this->crMargin = $this->rMargin;
1955  	 	 // internal cell padding
1956  	 	 $cpadding = $margin / 10;
1957  	 	 $this->setCellPaddings($cpadding, 0, $cpadding, 0);
1958  	 	 // cell margins
1959  	 	 $this->setCellMargins(0, 0, 0, 0);
1960  	 	 // line width (0.2 mm)
1961  	 	 $this->LineWidth = 0.57 / $this->k;
1962  	 	 $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
1963  	 	 $this->linestyleCap = '0 J';
1964  	 	 $this->linestyleJoin = '0 j';
1965  	 	 $this->linestyleDash = '[] 0 d';
1966  	 	 // automatic page break
1967  	 	 $this->setAutoPageBreak(true, (2 * $margin));
1968  	 	 // full width display mode
1969  	 	 $this->setDisplayMode('fullwidth');
1970  	 	 // compression
1971  	 	 $this->setCompression();
1972  	 	 // set default PDF version number
1973  	 	 $this->setPDFVersion();
1974  	 	 $this->tcpdflink = true;
1975  	 	 $this->encoding = $encoding;
1976  	 	 $this->HREF = array();
1977  	 	 $this->getFontsList();
1978  	 	 $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
1979  	 	 $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
1980  	 	 $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
1981  	 	 $this->extgstates = array();
1982  	 	 $this->setTextShadow();
1983  	 	 // signature
1984  	 	 $this->sign = false;
1985  	 	 $this->tsa_timestamp = false;
1986  	 	 $this->tsa_data = array();
1987  	 	 $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
1988  	 	 $this->empty_signature_appearance = array();
1989  	 	 // user's rights
1990  	 	 $this->ur['enabled'] = false;
1991  	 	 $this->ur['document'] = '/FullSave';
1992  	 	 $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
1993  	 	 $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
1994  	 	 $this->ur['signature'] = '/Modify';
1995  	 	 $this->ur['ef'] = '/Create/Delete/Modify/Import';
1996  	 	 $this->ur['formex'] = '';
1997  	 	 // set default JPEG quality
1998  	 	 $this->jpeg_quality = 75;
1999  	 	 // initialize some settings
2000  	 	 TCPDF_FONTS::utf8Bidi(array(), '', false, $this->isunicode, $this->CurrentFont);
2001  	 	 // set default font
2002  	 	 $this->setFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
2003  	 	 $this->setHeaderFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
2004  	 	 $this->setFooterFont(array($this->FontFamily, $this->FontStyle, $this->FontSizePt));
2005  	 	 // check if PCRE Unicode support is enabled
2006  	 	 if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
2007  	 	 	 // PCRE unicode support is turned ON
2008  	 	 	 // \s     : any whitespace character
2009  	 	 	 // \p{Z}  : any separator
2010  	 	 	 // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
2011  	 	 	 // \xa0   : Unicode Character 'NO-BREAK SPACE' (U+00A0)
2012  	 	 	 //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
2013  	 	 	 $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
2014  	 	 } else {
2015  	 	 	 // PCRE unicode support is turned OFF
2016  	 	 	 $this->setSpacesRE('/[^\S\xa0]/');
2017  	 	 }
2018  	 	 $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
2019  	 	 // set document creation and modification timestamp
2020  	 	 $this->doc_creation_timestamp = time();
2021  	 	 $this->doc_modification_timestamp = $this->doc_creation_timestamp;
2022  	 	 // get default graphic vars
2023  	 	 $this->default_graphic_vars = $this->getGraphicVars();
2024  	 	 $this->header_xobj_autoreset = false;
2025  	 	 $this->custom_xmp = '';
2026  	 	 $this->custom_xmp_rdf = '';
2027  	 	 // Call cleanup method after script execution finishes or exit() is called.
2028  	 	 // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal.
2029  	 	 register_shutdown_function(array($this, '_destroy'), true);
2030  	 }
2031  
2032  	 /**
2033  	  * Default destructor.
2034  	  * @public
2035  	  * @since 1.53.0.TC016
2036  	  */
2037  	public function __destruct() {
2038  	 	 // cleanup
2039  	 	 $this->_destroy(true);
2040  	 }
2041  
2042  	 /**
2043  	  * Set the units of measure for the document.
2044  	  * @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.
2045  	  * @public
2046  	  * @since 3.0.015 (2008-06-06)
2047  	  */
2048  	public function setPageUnit($unit) {
2049  	 	 $unit = strtolower($unit);
2050  	 	 //Set scale factor
2051  	 	 switch ($unit) {
2052  	 	 	 // points
2053  	 	 	 case 'px':
2054  	 	 	 case 'pt': {
2055  	 	 	 	 $this->k = 1;
2056  	 	 	 	 break;
2057  	 	 	 }
2058  	 	 	 // millimeters
2059  	 	 	 case 'mm': {
2060  	 	 	 	 $this->k = $this->dpi / 25.4;
2061  	 	 	 	 break;
2062  	 	 	 }
2063  	 	 	 // centimeters
2064  	 	 	 case 'cm': {
2065  	 	 	 	 $this->k = $this->dpi / 2.54;
2066  	 	 	 	 break;
2067  	 	 	 }
2068  	 	 	 // inches
2069  	 	 	 case 'in': {
2070  	 	 	 	 $this->k = $this->dpi;
2071  	 	 	 	 break;
2072  	 	 	 }
2073  	 	 	 // unsupported unit
2074  	 	 	 default : {
2075  	 	 	 	 $this->Error('Incorrect unit: '.$unit);
2076  	 	 	 	 break;
2077  	 	 	 }
2078  	 	 }
2079  	 	 $this->pdfunit = $unit;
2080  	 	 if (isset($this->CurOrientation)) {
2081  	 	 	 $this->setPageOrientation($this->CurOrientation);
2082  	 	 }
2083  	 }
2084  
2085  	 /**
2086  	  * Change the format of the current page
2087  	  * @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>
2088  	  * <li>['format'] = page format name (one of the above);</li>
2089  	  * <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>
2090  	  * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
2091  	  * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
2092  	  * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
2093  	  * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
2094  	  * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
2095  	  * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
2096  	  * <li>['CropBox'] : the visible region of default user space:</li>
2097  	  * <li>['CropBox']['llx'] : lower-left x coordinate</li>
2098  	  * <li>['CropBox']['lly'] : lower-left y coordinate</li>
2099  	  * <li>['CropBox']['urx'] : upper-right x coordinate</li>
2100  	  * <li>['CropBox']['ury'] : upper-right y coordinate</li>
2101  	  * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
2102  	  * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
2103  	  * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
2104  	  * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
2105  	  * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
2106  	  * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
2107  	  * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
2108  	  * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
2109  	  * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
2110  	  * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
2111  	  * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
2112  	  * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
2113  	  * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
2114  	  * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
2115  	  * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
2116  	  * <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>
2117  	  * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
2118  	  * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
2119  	  * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
2120  	  * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
2121  	  * <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>
2122  	  * <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>
2123  	  * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
2124  	  * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
2125  	  * <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>
2126  	  * <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>
2127  	  * <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>
2128  	  * <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>
2129  	  * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
2130  	  * </ul>
2131  	  * @param string $orientation page orientation. Possible values are (case insensitive):<ul>
2132  	  * <li>P or Portrait (default)</li>
2133  	  * <li>L or Landscape</li>
2134  	  * <li>'' (empty string) for automatic orientation</li>
2135  	  * </ul>
2136  	  * @protected
2137  	  * @since 3.0.015 (2008-06-06)
2138  	  * @see getPageSizeFromFormat()
2139  	  */
2140  	protected function setPageFormat($format, $orientation='P') {
2141  	 	 if (!empty($format) AND isset($this->pagedim[$this->page])) {
2142  	 	 	 // remove inherited values
2143  	 	 	 unset($this->pagedim[$this->page]);
2144  	 	 }
2145  	 	 if (is_string($format)) {
2146  	 	 	 // get page measures from format name
2147  	 	 	 $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
2148  	 	 	 $this->fwPt = $pf[0];
2149  	 	 	 $this->fhPt = $pf[1];
2150  	 	 } else {
2151  	 	 	 // the boundaries of the physical medium on which the page shall be displayed or printed
2152  	 	 	 if (isset($format['MediaBox'])) {
2153  	 	 	 	 $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);
2154  	 	 	 	 $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
2155  	 	 	 	 $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
2156  	 	 	 } else {
2157  	 	 	 	 if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
2158  	 	 	 	 	 $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
2159  	 	 	 	 } else {
2160  	 	 	 	 	 if (!isset($format['format'])) {
2161  	 	 	 	 	 	 // default value
2162  	 	 	 	 	 	 $format['format'] = 'A4';
2163  	 	 	 	 	 }
2164  	 	 	 	 	 $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
2165  	 	 	 	 }
2166  	 	 	 	 $this->fwPt = $pf[0];
2167  	 	 	 	 $this->fhPt = $pf[1];
2168  	 	 	 	 $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
2169  	 	 	 }
2170  	 	 	 // the visible region of default user space
2171  	 	 	 if (isset($format['CropBox'])) {
2172  	 	 	 	 $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);
2173  	 	 	 }
2174  	 	 	 // the region to which the contents of the page shall be clipped when output in a production environment
2175  	 	 	 if (isset($format['BleedBox'])) {
2176  	 	 	 	 $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);
2177  	 	 	 }
2178  	 	 	 // the intended dimensions of the finished page after trimming
2179  	 	 	 if (isset($format['TrimBox'])) {
2180  	 	 	 	 $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);
2181  	 	 	 }
2182  	 	 	 // the page's meaningful content (including potential white space)
2183  	 	 	 if (isset($format['ArtBox'])) {
2184  	 	 	 	 $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);
2185  	 	 	 }
2186  	 	 	 // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
2187  	 	 	 if (isset($format['BoxColorInfo'])) {
2188  	 	 	 	 $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
2189  	 	 	 }
2190  	 	 	 if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
2191  	 	 	 	 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
2192  	 	 	 	 $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
2193  	 	 	 }
2194  	 	 	 if (isset($format['PZ'])) {
2195  	 	 	 	 // The page's preferred zoom (magnification) factor
2196  	 	 	 	 $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
2197  	 	 	 }
2198  	 	 	 if (isset($format['trans'])) {
2199  	 	 	 	 // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
2200  	 	 	 	 if (isset($format['trans']['Dur'])) {
2201  	 	 	 	 	 // The page's display duration
2202  	 	 	 	 	 $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
2203  	 	 	 	 }
2204  	 	 	 	 $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
2205  	 	 	 	 if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
2206  	 	 	 	 	 // The transition style that shall be used when moving to this page from another during a presentation
2207  	 	 	 	 	 $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
2208  	 	 	 	 	 $valid_effect = array('Split', 'Blinds');
2209  	 	 	 	 	 $valid_vals = array('H', 'V');
2210  	 	 	 	 	 if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
2211  	 	 	 	 	 	 $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
2212  	 	 	 	 	 }
2213  	 	 	 	 	 $valid_effect = array('Split', 'Box', 'Fly');
2214  	 	 	 	 	 $valid_vals = array('I', 'O');
2215  	 	 	 	 	 if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
2216  	 	 	 	 	 	 $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
2217  	 	 	 	 	 }
2218  	 	 	 	 	 $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
2219  	 	 	 	 	 if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
2220  	 	 	 	 	 	 if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
2221  	 	 	 	 	 	 	 OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
2222  	 	 	 	 	 	 	 OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
2223  	 	 	 	 	 	 	 $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
2224  	 	 	 	 	 	 }
2225  	 	 	 	 	 }
2226  	 	 	 	 	 if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
2227  	 	 	 	 	 	 $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
2228  	 	 	 	 	 }
2229  	 	 	 	 	 if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
2230  	 	 	 	 	 	 $this->pagedim[$this->page]['trans']['B'] = 'true';
2231  	 	 	 	 	 }
2232  	 	 	 	 } else {
2233  	 	 	 	 	 $this->pagedim[$this->page]['trans']['S'] = 'R';
2234  	 	 	 	 }
2235  	 	 	 	 if (isset($format['trans']['D'])) {
2236  	 	 	 	 	 // The duration of the transition effect, in seconds
2237  	 	 	 	 	 $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
2238  	 	 	 	 } else {
2239  	 	 	 	 	 $this->pagedim[$this->page]['trans']['D'] = 1;
2240  	 	 	 	 }
2241  	 	 	 }
2242  	 	 }
2243  	 	 $this->setPageOrientation($orientation);
2244  	 }
2245  
2246  	 /**
2247  	  * Set page orientation.
2248  	  * @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>
2249  	  * @param boolean|null $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
2250  	  * @param float|null $bottommargin bottom margin of the page.
2251  	  * @public
2252  	  * @since 3.0.015 (2008-06-06)
2253  	  */
2254  	public function setPageOrientation($orientation, $autopagebreak=null, $bottommargin=null) {
2255  	 	 if (!isset($this->pagedim[$this->page]['MediaBox'])) {
2256  	 	 	 // the boundaries of the physical medium on which the page shall be displayed or printed
2257  	 	 	 $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
2258  	 	 }
2259  	 	 if (!isset($this->pagedim[$this->page]['CropBox'])) {
2260  	 	 	 // the visible region of default user space
2261  	 	 	 $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);
2262  	 	 }
2263  	 	 if (!isset($this->pagedim[$this->page]['BleedBox'])) {
2264  	 	 	 // the region to which the contents of the page shall be clipped when output in a production environment
2265  	 	 	 $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);
2266  	 	 }
2267  	 	 if (!isset($this->pagedim[$this->page]['TrimBox'])) {
2268  	 	 	 // the intended dimensions of the finished page after trimming
2269  	 	 	 $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);
2270  	 	 }
2271  	 	 if (!isset($this->pagedim[$this->page]['ArtBox'])) {
2272  	 	 	 // the page's meaningful content (including potential white space)
2273  	 	 	 $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);
2274  	 	 }
2275  	 	 if (!isset($this->pagedim[$this->page]['Rotate'])) {
2276  	 	 	 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
2277  	 	 	 $this->pagedim[$this->page]['Rotate'] = 0;
2278  	 	 }
2279  	 	 if (!isset($this->pagedim[$this->page]['PZ'])) {
2280  	 	 	 // The page's preferred zoom (magnification) factor
2281  	 	 	 $this->pagedim[$this->page]['PZ'] = 1;
2282  	 	 }
2283  	 	 if ($this->fwPt > $this->fhPt) {
2284  	 	 	 // landscape
2285  	 	 	 $default_orientation = 'L';
2286  	 	 } else {
2287  	 	 	 // portrait
2288  	 	 	 $default_orientation = 'P';
2289  	 	 }
2290  	 	 $valid_orientations = array('P', 'L');
2291  	 	 if (empty($orientation)) {
2292  	 	 	 $orientation = $default_orientation;
2293  	 	 } else {
2294  	 	 	 $orientation = strtoupper($orientation[0]);
2295  	 	 }
2296  	 	 if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
2297  	 	 	 $this->CurOrientation = $orientation;
2298  	 	 	 $this->wPt = $this->fhPt;
2299  	 	 	 $this->hPt = $this->fwPt;
2300  	 	 } else {
2301  	 	 	 $this->CurOrientation = $default_orientation;
2302  	 	 	 $this->wPt = $this->fwPt;
2303  	 	 	 $this->hPt = $this->fhPt;
2304  	 	 }
2305  	 	 if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
2306  	 	 	 // swap X and Y coordinates (change page orientation)
2307  	 	 	 $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
2308  	 	 }
2309  	 	 $this->w = ($this->wPt / $this->k);
2310  	 	 $this->h = ($this->hPt / $this->k);
2311  	 	 if (TCPDF_STATIC::empty_string($autopagebreak)) {
2312  	 	 	 if (isset($this->AutoPageBreak)) {
2313  	 	 	 	 $autopagebreak = $this->AutoPageBreak;
2314  	 	 	 } else {
2315  	 	 	 	 $autopagebreak = true;
2316  	 	 	 }
2317  	 	 }
2318  	 	 if (TCPDF_STATIC::empty_string($bottommargin)) {
2319  	 	 	 if (isset($this->bMargin)) {
2320  	 	 	 	 $bottommargin = $this->bMargin;
2321  	 	 	 } else {
2322  	 	 	 	 // default value = 2 cm
2323  	 	 	 	 $bottommargin = 2 * 28.35 / $this->k;
2324  	 	 	 }
2325  	 	 }
2326  	 	 $this->setAutoPageBreak($autopagebreak, $bottommargin);
2327  	 	 // store page dimensions
2328  	 	 $this->pagedim[$this->page]['w'] = $this->wPt;
2329  	 	 $this->pagedim[$this->page]['h'] = $this->hPt;
2330  	 	 $this->pagedim[$this->page]['wk'] = $this->w;
2331  	 	 $this->pagedim[$this->page]['hk'] = $this->h;
2332  	 	 $this->pagedim[$this->page]['tm'] = $this->tMargin;
2333  	 	 $this->pagedim[$this->page]['bm'] = $bottommargin;
2334  	 	 $this->pagedim[$this->page]['lm'] = $this->lMargin;
2335  	 	 $this->pagedim[$this->page]['rm'] = $this->rMargin;
2336  	 	 $this->pagedim[$this->page]['pb'] = $autopagebreak;
2337  	 	 $this->pagedim[$this->page]['or'] = $this->CurOrientation;
2338  	 	 $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
2339  	 	 $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
2340  	 }
2341  
2342  	 /**
2343  	  * Set regular expression to detect withespaces or word separators.
2344  	  * The pattern delimiter must be the forward-slash character "/".
2345  	  * Some example patterns are:
2346  	  * <pre>
2347  	  * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
2348  	  * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
2349  	  * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
2350  	  * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
2351  	  *      \s     : any whitespace character
2352  	  *      \p{Z}  : any separator
2353  	  *      \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
2354  	  *      \xa0   : Unicode Character 'NO-BREAK SPACE' (U+00A0)
2355  	  * </pre>
2356  	  * @param string $re regular expression (leave empty for default).
2357  	  * @public
2358  	  * @since 4.6.016 (2009-06-15)
2359  	  */
2360  	public function setSpacesRE($re='/[^\S\xa0]/') {
2361  	 	 $this->re_spaces = $re;
2362  	 	 $re_parts = explode('/', $re);
2363  	 	 // get pattern parts
2364  	 	 $this->re_space = array();
2365  	 	 if (isset($re_parts[1]) AND !empty($re_parts[1])) {
2366  	 	 	 $this->re_space['p'] = $re_parts[1];
2367  	 	 } else {
2368  	 	 	 $this->re_space['p'] = '[\s]';
2369  	 	 }
2370  	 	 // set pattern modifiers
2371  	 	 if (isset($re_parts[2]) AND !empty($re_parts[2])) {
2372  	 	 	 $this->re_space['m'] = $re_parts[2];
2373  	 	 } else {
2374  	 	 	 $this->re_space['m'] = '';
2375  	 	 }
2376  	 }
2377  
2378  	 /**
2379  	  * Enable or disable Right-To-Left language mode
2380  	  * @param boolean $enable if true enable Right-To-Left language mode.
2381  	  * @param boolean $resetx if true reset the X position on direction change.
2382  	  * @public
2383  	  * @since 2.0.000 (2008-01-03)
2384  	  */
2385  	public function setRTL($enable, $resetx=true) {
2386  	 	 $enable = $enable ? true : false;
2387  	 	 $resetx = ($resetx AND ($enable != $this->rtl));
2388  	 	 $this->rtl = $enable;
2389  	 	 $this->tmprtl = false;
2390  	 	 if ($resetx) {
2391  	 	 	 $this->Ln(0);
2392  	 	 }
2393  	 }
2394  
2395  	 /**
2396  	  * Return the RTL status
2397  	  * @return bool
2398  	  * @public
2399  	  * @since 4.0.012 (2008-07-24)
2400  	  */
2401  	public function getRTL() {
2402  	 	 return $this->rtl;
2403  	 }
2404  
2405  	 /**
2406  	  * Force temporary RTL language direction
2407  	  * @param false|string $mode can be false, 'L' for LTR or 'R' for RTL
2408  	  * @public
2409  	  * @since 2.1.000 (2008-01-09)
2410  	  */
2411  	public function setTempRTL($mode) {
2412  	 	 $newmode = false;
2413  	 	 switch (strtoupper($mode)) {
2414  	 	 	 case 'LTR':
2415  	 	 	 case 'L': {
2416  	 	 	 	 if ($this->rtl) {
2417  	 	 	 	 	 $newmode = 'L';
2418  	 	 	 	 }
2419  	 	 	 	 break;
2420  	 	 	 }
2421  	 	 	 case 'RTL':
2422  	 	 	 case 'R': {
2423  	 	 	 	 if (!$this->rtl) {
2424  	 	 	 	 	 $newmode = 'R';
2425  	 	 	 	 }
2426  	 	 	 	 break;
2427  	 	 	 }
2428  	 	 	 case false:
2429  	 	 	 default: {
2430  	 	 	 	 $newmode = false;
2431  	 	 	 	 break;
2432  	 	 	 }
2433  	 	 }
2434  	 	 $this->tmprtl = $newmode;
2435  	 }
2436  
2437  	 /**
2438  	  * Return the current temporary RTL status
2439  	  * @return bool
2440  	  * @public
2441  	  * @since 4.8.014 (2009-11-04)
2442  	  */
2443  	public function isRTLTextDir() {
2444  	 	 return ($this->rtl OR ($this->tmprtl == 'R'));
2445  	 }
2446  
2447  	 /**
2448  	  * Set the last cell height.
2449  	  * @param float $h cell height.
2450  	  * @author Nicola Asuni
2451  	  * @public
2452  	  * @since 1.53.0.TC034
2453  	  */
2454  	public function setLastH($h) {
2455  	 	 $this->lasth = $h;
2456  	 }
2457  
2458  	 /**
2459  	  * Return the cell height
2460  	  * @param int $fontsize Font size in internal units
2461  	  * @param boolean $padding If true add cell padding
2462  	  * @public
2463  	  * @return float
2464  	  */
2465  	public function getCellHeight($fontsize, $padding=TRUE) {
2466  	 	 $height = ($fontsize * $this->cell_height_ratio);
2467  	 	 if ($padding) {
2468  	 	 	 $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
2469  	 	 }
2470  	 	 return round($height, 6);
2471  	 }
2472  
2473  	 /**
2474  	  * Reset the last cell height.
2475  	  * @public
2476  	  * @since 5.9.000 (2010-10-03)
2477  	  */
2478  	public function resetLastH() {
2479  	 	 $this->lasth = $this->getCellHeight($this->FontSize);
2480  	 }
2481  
2482  	 /**
2483  	  * Get the last cell height.
2484  	  * @return float last cell height
2485  	  * @public
2486  	  * @since 4.0.017 (2008-08-05)
2487  	  */
2488  	public function getLastH() {
2489  	 	 return $this->lasth;
2490  	 }
2491  
2492  	 /**
2493  	  * Set the adjusting factor to convert pixels to user units.
2494  	  * @param float $scale adjusting factor to convert pixels to user units.
2495  	  * @author Nicola Asuni
2496  	  * @public
2497  	  * @since 1.5.2
2498  	  */
2499  	public function setImageScale($scale) {
2500  	 	 $this->imgscale = $scale;
2501  	 }
2502  
2503  	 /**
2504  	  * Returns the adjusting factor to convert pixels to user units.
2505  	  * @return float adjusting factor to convert pixels to user units.
2506  	  * @author Nicola Asuni
2507  	  * @public
2508  	  * @since 1.5.2
2509  	  */
2510  	public function getImageScale() {
2511  	 	 return $this->imgscale;
2512  	 }
2513  
2514  	 /**
2515  	  * Returns an array of page dimensions:
2516  	  * <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>
2517  	  * @param int|null $pagenum page number (empty = current page)
2518  	  * @return array of page dimensions.
2519  	  * @author Nicola Asuni
2520  	  * @public
2521  	  * @since 4.5.027 (2009-03-16)
2522  	  */
2523  	public function getPageDimensions($pagenum=null) {
2524  	 	 if (empty($pagenum)) {
2525  	 	 	 $pagenum = $this->page;
2526  	 	 }
2527  	 	 return $this->pagedim[$pagenum];
2528  	 }
2529  
2530  	 /**
2531  	  * Returns the page width in units.
2532  	  * @param int|null $pagenum page number (empty = current page)
2533  	  * @return int|float page width.
2534  	  * @author Nicola Asuni
2535  	  * @public
2536  	  * @since 1.5.2
2537  	  * @see getPageDimensions()
2538  	  */
2539  	public function getPageWidth($pagenum=null) {
2540  	 	 if (empty($pagenum)) {
2541  	 	 	 return $this->w;
2542  	 	 }
2543  	 	 return $this->pagedim[$pagenum]['w'];
2544  	 }
2545  
2546  	 /**
2547  	  * Returns the page height in units.
2548  	  * @param int|null $pagenum page number (empty = current page)
2549  	  * @return int|float page height.
2550  	  * @author Nicola Asuni
2551  	  * @public
2552  	  * @since 1.5.2
2553  	  * @see getPageDimensions()
2554  	  */
2555  	public function getPageHeight($pagenum=null) {
2556  	 	 if (empty($pagenum)) {
2557  	 	 	 return $this->h;
2558  	 	 }
2559  	 	 return $this->pagedim[$pagenum]['h'];
2560  	 }
2561  
2562  	 /**
2563  	  * Returns the page break margin.
2564  	  * @param int|null $pagenum page number (empty = current page)
2565  	  * @return int|float page break margin.
2566  	  * @author Nicola Asuni
2567  	  * @public
2568  	  * @since 1.5.2
2569  	  * @see getPageDimensions()
2570  	  */
2571  	public function getBreakMargin($pagenum=null) {
2572  	 	 if (empty($pagenum)) {
2573  	 	 	 return $this->bMargin;
2574  	 	 }
2575  	 	 return $this->pagedim[$pagenum]['bm'];
2576  	 }
2577  
2578  	 /**
2579  	  * Returns the scale factor (number of points in user unit).
2580  	  * @return int scale factor.
2581  	  * @author Nicola Asuni
2582  	  * @public
2583  	  * @since 1.5.2
2584  	  */
2585  	public function getScaleFactor() {
2586  	 	 return $this->k;
2587  	 }
2588  
2589  	 /**
2590  	  * Defines the left, top and right margins.
2591  	  * @param int|float $left Left margin.
2592  	  * @param int|float $top Top margin.
2593  	  * @param int|float|null $right Right margin. Default value is the left one.
2594  	  * @param boolean $keepmargins if true overwrites the default page margins
2595  	  * @public
2596  	  * @since 1.0
2597  	  * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
2598  	  */
2599  	public function setMargins($left, $top, $right=null, $keepmargins=false) {
2600  	 	 //Set left, top and right margins
2601  	 	 $this->lMargin = $left;
2602  	 	 $this->tMargin = $top;
2603  	 	 if ($right == -1 OR $right === null) {
2604  	 	 	 $right = $left;
2605  	 	 }
2606  	 	 $this->rMargin = $right;
2607  	 	 if ($keepmargins) {
2608  	 	 	 // overwrite original values
2609  	 	 	 $this->original_lMargin = $this->lMargin;
2610  	 	 	 $this->original_rMargin = $this->rMargin;
2611  	 	 }
2612  	 }
2613  
2614  	 /**
2615  	  * 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.
2616  	  * @param int|float $margin The margin.
2617  	  * @public
2618  	  * @since 1.4
2619  	  * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
2620  	  */
2621  	public function setLeftMargin($margin) {
2622  	 	 //Set left margin
2623  	 	 $this->lMargin = $margin;
2624  	 	 if (($this->page > 0) AND ($this->x < $margin)) {
2625  	 	 	 $this->x = $margin;
2626  	 	 }
2627  	 }
2628  
2629  	 /**
2630  	  * Defines the top margin. The method can be called before creating the first page.
2631  	  * @param int|float $margin The margin.
2632  	  * @public
2633  	  * @since 1.5
2634  	  * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
2635  	  */
2636  	public function setTopMargin($margin) {
2637  	 	 //Set top margin
2638  	 	 $this->tMargin = $margin;
2639  	 	 if (($this->page > 0) AND ($this->y < $margin)) {
2640  	 	 	 $this->y = $margin;
2641  	 	 }
2642  	 }
2643  
2644  	 /**
2645  	  * Defines the right margin. The method can be called before creating the first page.
2646  	  * @param int|float $margin The margin.
2647  	  * @public
2648  	  * @since 1.5
2649  	  * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
2650  	  */
2651  	public function setRightMargin($margin) {
2652  	 	 $this->rMargin = $margin;
2653  	 	 if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
2654  	 	 	 $this->x = $this->w - $margin;
2655  	 	 }
2656  	 }
2657  
2658  	 /**
2659  	  * Set the same internal Cell padding for top, right, bottom, left-
2660  	  * @param int|float $pad internal padding.
2661  	  * @public
2662  	  * @since 2.1.000 (2008-01-09)
2663  	  * @see getCellPaddings(), setCellPaddings()
2664  	  */
2665  	public function setCellPadding($pad) {
2666  	 	 if ($pad >= 0) {
2667  	 	 	 $this->cell_padding['L'] = $pad;
2668  	 	 	 $this->cell_padding['T'] = $pad;
2669  	 	 	 $this->cell_padding['R'] = $pad;
2670  	 	 	 $this->cell_padding['B'] = $pad;
2671  	 	 }
2672  	 }
2673  
2674  	 /**
2675  	  * Set the internal Cell paddings.
2676  	  * @param int|float|null $left left padding
2677  	  * @param int|float|null $top top padding
2678  	  * @param int|float|null $right right padding
2679  	  * @param int|float|null $bottom bottom padding
2680  	  * @public
2681  	  * @since 5.9.000 (2010-10-03)
2682  	  * @see getCellPaddings(), SetCellPadding()
2683  	  */
2684  	public function setCellPaddings($left=null, $top=null, $right=null, $bottom=null) {
2685  	 	 if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
2686  	 	 	 $this->cell_padding['L'] = $left;
2687  	 	 }
2688  	 	 if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
2689  	 	 	 $this->cell_padding['T'] = $top;
2690  	 	 }
2691  	 	 if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
2692  	 	 	 $this->cell_padding['R'] = $right;
2693  	 	 }
2694  	 	 if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
2695  	 	 	 $this->cell_padding['B'] = $bottom;
2696  	 	 }
2697  	 }
2698  
2699  	 /**
2700  	  * Get the internal Cell padding array.
2701  	  * @return array of padding values
2702  	  * @public
2703  	  * @since 5.9.000 (2010-10-03)
2704  	  * @see setCellPaddings(), SetCellPadding()
2705  	  */
2706  	public function getCellPaddings() {
2707  	 	 return $this->cell_padding;
2708  	 }
2709  
2710  	 /**
2711  	  * Set the internal Cell margins.
2712  	  * @param int|float|null $left left margin
2713  	  * @param int|float|null $top top margin
2714  	  * @param int|float|null $right right margin
2715  	  * @param int|float|null $bottom bottom margin
2716  	  * @public
2717  	  * @since 5.9.000 (2010-10-03)
2718  	  * @see getCellMargins()
2719  	  */
2720  	public function setCellMargins($left=null, $top=null, $right=null, $bottom=null) {
2721  	 	 if (!TCPDF_STATIC::empty_string($left) AND ($left >= 0)) {
2722  	 	 	 $this->cell_margin['L'] = $left;
2723  	 	 }
2724  	 	 if (!TCPDF_STATIC::empty_string($top) AND ($top >= 0)) {
2725  	 	 	 $this->cell_margin['T'] = $top;
2726  	 	 }
2727  	 	 if (!TCPDF_STATIC::empty_string($right) AND ($right >= 0)) {
2728  	 	 	 $this->cell_margin['R'] = $right;
2729  	 	 }
2730  	 	 if (!TCPDF_STATIC::empty_string($bottom) AND ($bottom >= 0)) {
2731  	 	 	 $this->cell_margin['B'] = $bottom;
2732  	 	 }
2733  	 }
2734  
2735  	 /**
2736  	  * Get the internal Cell margin array.
2737  	  * @return array of margin values
2738  	  * @public
2739  	  * @since 5.9.000 (2010-10-03)
2740  	  * @see setCellMargins()
2741  	  */
2742  	public function getCellMargins() {
2743  	 	 return $this->cell_margin;
2744  	 }
2745  
2746  	 /**
2747  	  * Adjust the internal Cell padding array to take account of the line width.
2748  	  * @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)))
2749  	  * @return void|array array of adjustments
2750  	  * @public
2751  	  * @since 5.9.000 (2010-10-03)
2752  	  */
2753  	protected function adjustCellPadding($brd=0) {
2754  	 	 if (empty($brd)) {
2755  	 	 	 return;
2756  	 	 }
2757  	 	 if (is_string($brd)) {
2758  	 	 	 // convert string to array
2759  	 	 	 $slen = strlen($brd);
2760  	 	 	 $newbrd = array();
2761  	 	 	 for ($i = 0; $i < $slen; ++$i) {
2762  	 	 	 	 $newbrd[$brd[$i]] = true;
2763  	 	 	 }
2764  	 	 	 $brd = $newbrd;
2765  	 	 } elseif (
2766  	 	 	 ($brd === 1)
2767  	 	 	 || ($brd === true)
2768  	 	 	 || (is_numeric($brd) && ((int)$brd > 0))
2769  	 	 ) {
2770  	 	 	 $brd = array('LRTB' => true);
2771  	 	 }
2772  	 	 if (!is_array($brd)) {
2773  	 	 	 return;
2774  	 	 }
2775  	 	 // store current cell padding
2776  	 	 $cp = $this->cell_padding;
2777  	 	 // select border mode
2778  	 	 if (isset($brd['mode'])) {
2779  	 	 	 $mode = $brd['mode'];
2780  	 	 	 unset($brd['mode']);
2781  	 	 } else {
2782  	 	 	 $mode = 'normal';
2783  	 	 }
2784  	 	 // process borders
2785  	 	 foreach ($brd as $border => $style) {
2786  	 	 	 $line_width = $this->LineWidth;
2787  	 	 	 if (is_array($style) && isset($style['width'])) {
2788  	 	 	 	 // get border width
2789  	 	 	 	 $line_width = $style['width'];
2790  	 	 	 }
2791  	 	 	 $adj = 0; // line width inside the cell
2792  	 	 	 switch ($mode) {
2793  	 	 	 	 case 'ext': {
2794  	 	 	 	 	 $adj = 0;
2795  	 	 	 	 	 break;
2796  	 	 	 	 }
2797  	 	 	 	 case 'int': {
2798  	 	 	 	 	 $adj = $line_width;
2799  	 	 	 	 	 break;
2800  	 	 	 	 }
2801  	 	 	 	 case 'normal':
2802  	 	 	 	 default: {
2803  	 	 	 	 	 $adj = ($line_width / 2);
2804  	 	 	 	 	 break;
2805  	 	 	 	 }
2806  	 	 	 }
2807  	 	 	 // correct internal cell padding if required to avoid overlap between text and lines
2808  	 	 	 if (
2809  	 	 	 	 is_numeric($this->cell_padding['T'])
2810  	 	 	 	 && ($this->cell_padding['T'] < $adj)
2811  	 	 	 	 && (strpos($border, 'T') !== false)
2812  	 	 	 ) {
2813  	 	 	 	 $this->cell_padding['T'] = $adj;
2814  	 	 	 }
2815  	 	 	 if (
2816  	 	 	 	 is_numeric($this->cell_padding['R'])
2817  	 	 	 	 && ($this->cell_padding['R'] < $adj)
2818  	 	 	 	 && (strpos($border, 'R') !== false)
2819  	 	 	 ) {
2820  	 	 	 	 $this->cell_padding['R'] = $adj;
2821  	 	 	 }
2822  	 	 	 if (
2823  	 	 	 	 is_numeric($this->cell_padding['B'])
2824  	 	 	 	 && ($this->cell_padding['B'] < $adj)
2825  	 	 	 	 && (strpos($border, 'B') !== false)
2826  	 	 	 ) {
2827  	 	 	 	 $this->cell_padding['B'] = $adj;
2828  	 	 	 }
2829  	 	 	 if (
2830  	 	 	 	 is_numeric($this->cell_padding['L'])
2831  	 	 	 	 && ($this->cell_padding['L'] < $adj)
2832  	 	 	 	 && (strpos($border, 'L') !== false)
2833  	 	 	 ) {
2834  	 	 	 	 $this->cell_padding['L'] = $adj;
2835  	 	 	 }
2836  
2837  	 	 }
2838  
2839  	 	 return array(
2840  	 	 	 'T' => ($this->cell_padding['T'] - $cp['T']),
2841  	 	 	 'R' => ($this->cell_padding['R'] - $cp['R']),
2842  	 	 	 'B' => ($this->cell_padding['B'] - $cp['B']),
2843  	 	 	 'L' => ($this->cell_padding['L'] - $cp['L']),
2844  	 	 );
2845  	 }
2846  
2847  	 /**
2848  	  * 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.
2849  	  * @param boolean $auto Boolean indicating if mode should be on or off.
2850  	  * @param float $margin Distance from the bottom of the page.
2851  	  * @public
2852  	  * @since 1.0
2853  	  * @see Cell(), MultiCell(), AcceptPageBreak()
2854  	  */
2855  	public function setAutoPageBreak($auto, $margin=0) {
2856  	 	 $this->AutoPageBreak = $auto ? true : false;
2857  	 	 $this->bMargin = $margin;
2858  	 	 $this->PageBreakTrigger = $this->h - $margin;
2859  	 }
2860  
2861  	 /**
2862  	  * Return the auto-page-break mode (true or false).
2863  	  * @return bool auto-page-break mode
2864  	  * @public
2865  	  * @since 5.9.088
2866  	  */
2867  	public function getAutoPageBreak() {
2868  	 	 return $this->AutoPageBreak;
2869  	 }
2870  
2871  	 /**
2872  	  * Defines the way the document is to be displayed by the viewer.
2873  	  * @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>
2874  	  * @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>
2875  	  * @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>
2876  	  * @public
2877  	  * @since 1.2
2878  	  */
2879  	public function setDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
2880  	 	 if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
2881  	 	 	 $this->ZoomMode = $zoom;
2882  	 	 } else {
2883  	 	 	 $this->Error('Incorrect zoom display mode: '.$zoom);
2884  	 	 }
2885  	 	 $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
2886  	 	 $this->PageMode = TCPDF_STATIC::getPageMode($mode);
2887  	 }
2888  
2889  	 /**
2890  	  * 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.
2891  	  * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
2892  	  * @param boolean $compress Boolean indicating if compression must be enabled.
2893  	  * @public
2894  	  * @since 1.4
2895  	  */
2896  	public function setCompression($compress=true) {
2897  	 	 $this->compress = false;
2898  	 	 if (function_exists('gzcompress')) {
2899  	 	 	 if ($compress) {
2900  	 	 	 	 if ( !$this->pdfa_mode) {
2901  	 	 	 	 	 $this->compress = true;
2902  	 	 	 	 }
2903  	 	 	 }
2904  	 	 }
2905  	 }
2906  
2907  	 /**
2908  	  * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
2909  	  * @param boolean $mode If true force sRGB output intent.
2910  	  * @public
2911  	  * @since 5.9.121 (2011-09-28)
2912  	  */
2913  	public function setSRGBmode($mode=false) {
2914  	 	 $this->force_srgb = $mode ? true : false;
2915  	 }
2916  
2917  	 /**
2918  	  * Turn on/off Unicode mode for document information dictionary (meta tags).
2919  	  * This has effect only when unicode mode is set to false.
2920  	  * @param boolean $unicode if true set the meta information in Unicode
2921  	  * @since 5.9.027 (2010-12-01)
2922  	  * @public
2923  	  */
2924  	public function setDocInfoUnicode($unicode=true) {
2925  	 	 $this->docinfounicode = $unicode ? true : false;
2926  	 }
2927  
2928  	 /**
2929  	  * Defines the title of the document.
2930  	  * @param string $title The title.
2931  	  * @public
2932  	  * @since 1.2
2933  	  * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
2934  	  */
2935  	public function setTitle($title) {
2936  	 	 $this->title = $title;
2937  	 }
2938  
2939  	 /**
2940  	  * Defines the subject of the document.
2941  	  * @param string $subject The subject.
2942  	  * @public
2943  	  * @since 1.2
2944  	  * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
2945  	  */
2946  	public function setSubject($subject) {
2947  	 	 $this->subject = $subject;
2948  	 }
2949  
2950  	 /**
2951  	  * Defines the author of the document.
2952  	  * @param string $author The name of the author.
2953  	  * @public
2954  	  * @since 1.2
2955  	  * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
2956  	  */
2957  	public function setAuthor($author) {
2958  	 	 $this->author = $author;
2959  	 }
2960  
2961  	 /**
2962  	  * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
2963  	  * @param string $keywords The list of keywords.
2964  	  * @public
2965  	  * @since 1.2
2966  	  * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
2967  	  */
2968  	public function setKeywords($keywords) {
2969  	 	 $this->keywords = $keywords;
2970  	 }
2971  
2972  	 /**
2973  	  * Defines the creator of the document. This is typically the name of the application that generates the PDF.
2974  	  * @param string $creator The name of the creator.
2975  	  * @public
2976  	  * @since 1.2
2977  	  * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
2978  	  */
2979  	public function setCreator($creator) {
2980  	 	 $this->creator = $creator;
2981  	 }
2982  
2983  	 /**
2984  	  * Whether to allow local file path in image html tags, when prefixed with file://
2985  	  *
2986  	  * @param bool $allowLocalFiles true, when local files should be allowed. Otherwise false.
2987  	  * @public
2988  	  * @since 6.4
2989  	  */
2990  	public function setAllowLocalFiles($allowLocalFiles) {
2991  	 	 $this->allowLocalFiles = (bool) $allowLocalFiles;
2992  	 }
2993  
2994  
2995  	 /**
2996  	  * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
2997  	  * @param string $msg The error message
2998  	  * @public
2999  	  * @since 1.0
3000  	  */
3001  	public function Error($msg) {
3002  	 	 // unset all class variables
3003  	 	 $this->_destroy(true);
3004  	 	 if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
3005  	 	 	 die('<strong>TCPDF ERROR: </strong>'.$msg);
3006  	 	 } else {
3007  	 	 	 throw new Exception('TCPDF ERROR: '.$msg);
3008  	 	 }
3009  	 }
3010  
3011  	 /**
3012  	  * This method begins the generation of the PDF document.
3013  	  * It is not necessary to call it explicitly because AddPage() does it automatically.
3014  	  * Note: no page is created by this method
3015  	  * @public
3016  	  * @since 1.0
3017  	  * @see AddPage(), Close()
3018  	  */
3019  	public function Open() {
3020  	 	 $this->state = 1;
3021  	 }
3022  
3023  	 /**
3024  	  * Terminates the PDF document.
3025  	  * It is not necessary to call this method explicitly because Output() does it automatically.
3026  	  * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
3027  	  * @public
3028  	  * @since 1.0
3029  	  * @see Open(), Output()
3030  	  */
3031  	public function Close() {
3032  	 	 if ($this->state == 3) {
3033  	 	 	 return;
3034  	 	 }
3035  	 	 if ($this->page == 0) {
3036  	 	 	 $this->AddPage();
3037  	 	 }
3038  	 	 $this->endLayer();
3039  	 	 if ($this->tcpdflink) {
3040  	 	 	 // save current graphic settings
3041  	 	 	 $gvars = $this->getGraphicVars();
3042  	 	 	 $this->setEqualColumns();
3043  	 	 	 $this->lastpage(true);
3044  	 	 	 $this->setAutoPageBreak(false);
3045  	 	 	 $this->x = 0;
3046  	 	 	 $this->y = $this->h - (1 / $this->k);
3047  	 	 	 $this->lMargin = 0;
3048  	 	 	 $this->_outSaveGraphicsState();
3049  	 	 	 $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
3050  	 	 	 $this->setFont($font, '', 1);
3051  	 	 	 $this->setTextRenderingMode(0, false, false);
3052  	 	 	 $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";
3053  	 	 	 $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
3054  	 	 	 $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
3055  	 	 	 $this->_outRestoreGraphicsState();
3056  	 	 	 // restore graphic settings
3057  	 	 	 $this->setGraphicVars($gvars);
3058  	 	 }
3059  	 	 // close page
3060  	 	 $this->endPage();
3061  	 	 // close document
3062  	 	 $this->_enddoc();
3063  	 	 // unset all class variables (except critical ones)
3064  	 	 $this->_destroy(false);
3065  	 }
3066  
3067  	 /**
3068  	  * Move pointer at the specified document page and update page dimensions.
3069  	  * @param int $pnum page number (1 ... numpages)
3070  	  * @param boolean $resetmargins if true reset left, right, top margins and Y position.
3071  	  * @public
3072  	  * @since 2.1.000 (2008-01-07)
3073  	  * @see getPage(), lastpage(), getNumPages()
3074  	  */
3075  	public function setPage($pnum, $resetmargins=false) {
3076  	 	 if (($pnum == $this->page) AND ($this->state == 2)) {
3077  	 	 	 return;
3078  	 	 }
3079  	 	 if (($pnum > 0) AND ($pnum <= $this->numpages)) {
3080  	 	 	 $this->state = 2;
3081  	 	 	 // save current graphic settings
3082  	 	 	 //$gvars = $this->getGraphicVars();
3083  	 	 	 $oldpage = $this->page;
3084  	 	 	 $this->page = $pnum;
3085  	 	 	 $this->wPt = $this->pagedim[$this->page]['w'];
3086  	 	 	 $this->hPt = $this->pagedim[$this->page]['h'];
3087  	 	 	 $this->w = $this->pagedim[$this->page]['wk'];
3088  	 	 	 $this->h = $this->pagedim[$this->page]['hk'];
3089  	 	 	 $this->tMargin = $this->pagedim[$this->page]['tm'];
3090  	 	 	 $this->bMargin = $this->pagedim[$this->page]['bm'];
3091  	 	 	 $this->original_lMargin = $this->pagedim[$this->page]['olm'];
3092  	 	 	 $this->original_rMargin = $this->pagedim[$this->page]['orm'];
3093  	 	 	 $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
3094  	 	 	 $this->CurOrientation = $this->pagedim[$this->page]['or'];
3095  	 	 	 $this->setAutoPageBreak($this->AutoPageBreak, $this->bMargin);
3096  	 	 	 // restore graphic settings
3097  	 	 	 //$this->setGraphicVars($gvars);
3098  	 	 	 if ($resetmargins) {
3099  	 	 	 	 $this->lMargin = $this->pagedim[$this->page]['olm'];
3100  	 	 	 	 $this->rMargin = $this->pagedim[$this->page]['orm'];
3101  	 	 	 	 $this->setY($this->tMargin);
3102  	 	 	 } else {
3103  	 	 	 	 // account for booklet mode
3104  	 	 	 	 if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
3105  	 	 	 	 	 $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
3106  	 	 	 	 	 $this->lMargin += $deltam;
3107  	 	 	 	 	 $this->rMargin -= $deltam;
3108  	 	 	 	 }
3109  	 	 	 }
3110  	 	 } else {
3111  	 	 	 $this->Error('Wrong page number on setPage() function: '.$pnum);
3112  	 	 }
3113  	 }
3114  
3115  	 /**
3116  	  * Reset pointer to the last document page.
3117  	  * @param boolean $resetmargins if true reset left, right, top margins and Y position.
3118  	  * @public
3119  	  * @since 2.0.000 (2008-01-04)
3120  	  * @see setPage(), getPage(), getNumPages()
3121  	  */
3122  	public function lastPage($resetmargins=false) {
3123  	 	 $this->setPage($this->getNumPages(), $resetmargins);
3124  	 }
3125  
3126  	 /**
3127  	  * Get current document page number.
3128  	  * @return int page number
3129  	  * @public
3130  	  * @since 2.1.000 (2008-01-07)
3131  	  * @see setPage(), lastpage(), getNumPages()
3132  	  */
3133  	public function getPage() {
3134  	 	 return $this->page;
3135  	 }
3136  
3137  	 /**
3138  	  * Get the total number of insered pages.
3139  	  * @return int number of pages
3140  	  * @public
3141  	  * @since 2.1.000 (2008-01-07)
3142  	  * @see setPage(), getPage(), lastpage()
3143  	  */
3144  	public function getNumPages() {
3145  	 	 return $this->numpages;
3146  	 }
3147  
3148  	 /**
3149  	  * Adds a new TOC (Table Of Content) page to the document.
3150  	  * @param string $orientation page orientation.
3151  	  * @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().
3152  	  * @param boolean $keepmargins if true overwrites the default page margins with the current margins
3153  	  * @public
3154  	  * @since 5.0.001 (2010-05-06)
3155  	  * @see AddPage(), startPage(), endPage(), endTOCPage()
3156  	  */
3157  	public function addTOCPage($orientation='', $format='', $keepmargins=false) {
3158  	 	 $this->AddPage($orientation, $format, $keepmargins, true);
3159  	 }
3160  
3161  	 /**
3162  	  * Terminate the current TOC (Table Of Content) page
3163  	  * @public
3164  	  * @since 5.0.001 (2010-05-06)
3165  	  * @see AddPage(), startPage(), endPage(), addTOCPage()
3166  	  */
3167  	public function endTOCPage() {
3168  	 	 $this->endPage(true);
3169  	 }
3170  
3171  	 /**
3172  	  * 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).
3173  	  * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
3174  	  * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
3175  	  * @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().
3176  	  * @param boolean $keepmargins if true overwrites the default page margins with the current margins
3177  	  * @param boolean $tocpage if true set the tocpage state to true (the added page will be used to display Table Of Content).
3178  	  * @public
3179  	  * @since 1.0
3180  	  * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
3181  	  */
3182  	public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
3183  	 	 if ($this->inxobj) {
3184  	 	 	 // we are inside an XObject template
3185  	 	 	 return;
3186  	 	 }
3187  	 	 if (!isset($this->original_lMargin) OR $keepmargins) {
3188  	 	 	 $this->original_lMargin = $this->lMargin;
3189  	 	 }
3190  	 	 if (!isset($this->original_rMargin) OR $keepmargins) {
3191  	 	 	 $this->original_rMargin = $this->rMargin;
3192  	 	 }
3193  	 	 // terminate previous page
3194  	 	 $this->endPage();
3195  	 	 // start new page
3196  	 	 $this->startPage($orientation, $format, $tocpage);
3197  	 }
3198  
3199  	 /**
3200  	  * Terminate the current page
3201  	  * @param boolean $tocpage if true set the tocpage state to false (end the page used to display Table Of Content).
3202  	  * @public
3203  	  * @since 4.2.010 (2008-11-14)
3204  	  * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
3205  	  */
3206  	public function endPage($tocpage=false) {
3207  	 	 // check if page is already closed
3208  	 	 if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
3209  	 	 	 return;
3210  	 	 }
3211  	 	 // print page footer
3212  	 	 $this->setFooter();
3213  	 	 // close page
3214  	 	 $this->_endpage();
3215  	 	 // mark page as closed
3216  	 	 $this->pageopen[$this->page] = false;
3217  	 	 if ($tocpage) {
3218  	 	 	 $this->tocpage = false;
3219  	 	 }
3220  	 }
3221  
3222  	 /**
3223  	  * Starts a new page to the document. The page must be closed using the endPage() function.
3224  	  * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
3225  	  * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
3226  	  * @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().
3227  	  * @param boolean $tocpage if true the page is designated to contain the Table-Of-Content.
3228  	  * @since 4.2.010 (2008-11-14)
3229  	  * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
3230  	  * @public
3231  	  */
3232  	public function startPage($orientation='', $format='', $tocpage=false) {
3233  	 	 if ($tocpage) {
3234  	 	 	 $this->tocpage = true;
3235  	 	 }
3236  	 	 // move page numbers of documents to be attached
3237  	 	 if ($this->tocpage) {
3238  	 	 	 // move reference to unexistent pages (used for page attachments)
3239  	 	 	 // adjust outlines
3240  	 	 	 $tmpoutlines = $this->outlines;
3241  	 	 	 foreach ($tmpoutlines as $key => $outline) {
3242  	 	 	 	 if (!$outline['f'] AND ($outline['p'] > $this->numpages)) {
3243  	 	 	 	 	 $this->outlines[$key]['p'] = ($outline['p'] + 1);
3244  	 	 	 	 }
3245  	 	 	 }
3246  	 	 	 // adjust dests
3247  	 	 	 $tmpdests = $this->dests;
3248  	 	 	 foreach ($tmpdests as $key => $dest) {
3249  	 	 	 	 if (!$dest['f'] AND ($dest['p'] > $this->numpages)) {
3250  	 	 	 	 	 $this->dests[$key]['p'] = ($dest['p'] + 1);
3251  	 	 	 	 }
3252  	 	 	 }
3253  	 	 	 // adjust links
3254  	 	 	 $tmplinks = $this->links;
3255  	 	 	 foreach ($tmplinks as $key => $link) {
3256  	 	 	 	 if (!$link['f'] AND ($link['p'] > $this->numpages)) {
3257  	 	 	 	 	 $this->links[$key]['p'] = ($link['p'] + 1);
3258  	 	 	 	 }
3259  	 	 	 }
3260  	 	 }
3261  	 	 if ($this->numpages > $this->page) {
3262  	 	 	 // this page has been already added
3263  	 	 	 $this->setPage($this->page + 1);
3264  	 	 	 $this->setY($this->tMargin);
3265  	 	 	 return;
3266  	 	 }
3267  	 	 // start a new page
3268  	 	 if ($this->state == 0) {
3269  	 	 	 $this->Open();
3270  	 	 }
3271  	 	 ++$this->numpages;
3272  	 	 $this->swapMargins($this->booklet);
3273  	 	 // save current graphic settings
3274  	 	 $gvars = $this->getGraphicVars();
3275  	 	 // start new page
3276  	 	 $this->_beginpage($orientation, $format);
3277  	 	 // mark page as open
3278  	 	 $this->pageopen[$this->page] = true;
3279  	 	 // restore graphic settings
3280  	 	 $this->setGraphicVars($gvars);
3281  	 	 // mark this point
3282  	 	 $this->setPageMark();
3283  	 	 // print page header
3284  	 	 $this->setHeader();
3285  	 	 // restore graphic settings
3286  	 	 $this->setGraphicVars($gvars);
3287  	 	 // mark this point
3288  	 	 $this->setPageMark();
3289  	 	 // print table header (if any)
3290  	 	 $this->setTableHeader();
3291  	 	 // set mark for empty page check
3292  	 	 $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
3293  	 }
3294  
3295  	 /**
3296  	  * Set start-writing mark on current page stream used to put borders and fills.
3297  	  * Borders and fills are always created after content and inserted on the position marked by this method.
3298  	  * This function must be called after calling Image() function for a background image.
3299  	  * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
3300  	  * @public
3301  	  * @since 4.0.016 (2008-07-30)
3302  	  */
3303  	public function setPageMark() {
3304  	 	 $this->intmrk[$this->page] = $this->pagelen[$this->page];
3305  	 	 $this->bordermrk[$this->page] = $this->intmrk[$this->page];
3306  	 	 $this->setContentMark();
3307  	 }
3308  
3309  	 /**
3310  	  * Set start-writing mark on selected page.
3311  	  * Borders and fills are always created after content and inserted on the position marked by this method.
3312  	  * @param int $page page number (default is the current page)
3313  	  * @protected
3314  	  * @since 4.6.021 (2009-07-20)
3315  	  */
3316  	protected function setContentMark($page=0) {
3317  	 	 if ($page <= 0) {
3318  	 	 	 $page = $this->page;
3319  	 	 }
3320  	 	 if (isset($this->footerlen[$page])) {
3321  	 	 	 $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
3322  	 	 } else {
3323  	 	 	 $this->cntmrk[$page] = $this->pagelen[$page];
3324  	 	 }
3325  	 }
3326  
3327  	 /**
3328  	  * Set header data.
3329  	  * @param string $ln header image logo
3330  	  * @param int $lw header image logo width in mm
3331  	  * @param string $ht string to print as title on document header
3332  	  * @param string $hs string to print on document header
3333  	  * @param int[] $tc RGB array color for text.
3334  	  * @param int[] $lc RGB array color for line.
3335  	  * @public
3336  	  */
3337  	public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
3338  	 	 $this->header_logo = $ln;
3339  	 	 $this->header_logo_width = $lw;
3340  	 	 $this->header_title = $ht;
3341  	 	 $this->header_string = $hs;
3342  	 	 $this->header_text_color = $tc;
3343  	 	 $this->header_line_color = $lc;
3344  	 }
3345  
3346  	 /**
3347  	  * Set footer data.
3348  	  * @param int[] $tc RGB array color for text.
3349  	  * @param int[] $lc RGB array color for line.
3350  	  * @public
3351  	  */
3352  	public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
3353  	 	 $this->footer_text_color = $tc;
3354  	 	 $this->footer_line_color = $lc;
3355  	 }
3356  
3357  	 /**
3358  	  * Returns header data:
3359  	  * <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>
3360  	  * @return array<string,mixed>
3361  	  * @public
3362  	  * @since 4.0.012 (2008-07-24)
3363  	  */
3364  	public function getHeaderData() {
3365  	 	 $ret = array();
3366  	 	 $ret['logo'] = $this->header_logo;
3367  	 	 $ret['logo_width'] = $this->header_logo_width;
3368  	 	 $ret['title'] = $this->header_title;
3369  	 	 $ret['string'] = $this->header_string;
3370  	 	 $ret['text_color'] = $this->header_text_color;
3371  	 	 $ret['line_color'] = $this->header_line_color;
3372  	 	 return $ret;
3373  	 }
3374  
3375  	 /**
3376  	  * Set header margin.
3377  	  * (minimum distance between header and top page margin)
3378  	  * @param int $hm distance in user units
3379  	  * @public
3380  	  */
3381  	public function setHeaderMargin($hm=10) {
3382  	 	 $this->header_margin = $hm;
3383  	 }
3384  
3385  	 /**
3386  	  * Returns header margin in user units.
3387  	  * @return float
3388  	  * @since 4.0.012 (2008-07-24)
3389  	  * @public
3390  	  */
3391  	public function getHeaderMargin() {
3392  	 	 return $this->header_margin;
3393  	 }
3394  
3395  	 /**
3396  	  * Set footer margin.
3397  	  * (minimum distance between footer and bottom page margin)
3398  	  * @param int $fm distance in user units
3399  	  * @public
3400  	  */
3401  	public function setFooterMargin($fm=10) {
3402  	 	 $this->footer_margin = $fm;
3403  	 }
3404  
3405  	 /**
3406  	  * Returns footer margin in user units.
3407  	  * @return float
3408  	  * @since 4.0.012 (2008-07-24)
3409  	  * @public
3410  	  */
3411  	public function getFooterMargin() {
3412  	 	 return $this->footer_margin;
3413  	 }
3414  	 /**
3415  	  * Set a flag to print page header.
3416  	  * @param boolean $val set to true to print the page header (default), false otherwise.
3417  	  * @public
3418  	  */
3419  	public function setPrintHeader($val=true) {
3420  	 	 $this->print_header = $val ? true : false;
3421  	 }
3422  
3423  	 /**
3424  	  * Set a flag to print page footer.
3425  	  * @param boolean $val set to true to print the page footer (default), false otherwise.
3426  	  * @public
3427  	  */
3428  	public function setPrintFooter($val=true) {
3429  	 	 $this->print_footer = $val ? true : false;
3430  	 }
3431  
3432  	 /**
3433  	  * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
3434  	  * @return float
3435  	  * @public
3436  	  */
3437  	public function getImageRBX() {
3438  	 	 return $this->img_rb_x;
3439  	 }
3440  
3441  	 /**
3442  	  * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
3443  	  * @return float
3444  	  * @public
3445  	  */
3446  	public function getImageRBY() {
3447  	 	 return $this->img_rb_y;
3448  	 }
3449  
3450  	 /**
3451  	  * Reset the xobject template used by Header() method.
3452  	  * @public
3453  	  */
3454  	public function resetHeaderTemplate() {
3455  	 	 $this->header_xobjid = false;
3456  	 }
3457  
3458  	 /**
3459  	  * Set a flag to automatically reset the xobject template used by Header() method at each page.
3460  	  * @param boolean $val set to true to reset Header xobject template at each page, false otherwise.
3461  	  * @public
3462  	  */
3463  	public function setHeaderTemplateAutoreset($val=true) {
3464  	 	 $this->header_xobj_autoreset = $val ? true : false;
3465  	 }
3466  
3467  	 /**
3468  	  * This method is used to render the page header.
3469  	  * It is automatically called by AddPage() and could be overwritten in your own inherited class.
3470  	  * @public
3471  	  */
3472  	public function Header() {
3473  	 	 if ($this->header_xobjid === false) {
3474  	 	 	 // start a new XObject Template
3475  	 	 	 $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
3476  	 	 	 $headerfont = $this->getHeaderFont();
3477  	 	 	 $headerdata = $this->getHeaderData();
3478  	 	 	 $this->y = $this->header_margin;
3479  	 	 	 if ($this->rtl) {
3480  	 	 	 	 $this->x = $this->w - $this->original_rMargin;
3481  	 	 	 } else {
3482  	 	 	 	 $this->x = $this->original_lMargin;
3483  	 	 	 }
3484  	 	 	 if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
3485  	 	 	 	 $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
3486  	 	 	 	 if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
3487  	 	 	 	 	 $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
3488  	 	 	 	 } elseif ($imgtype == 'svg') {
3489  	 	 	 	 	 $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
3490  	 	 	 	 } else {
3491  	 	 	 	 	 $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
3492  	 	 	 	 }
3493  	 	 	 	 $imgy = $this->getImageRBY();
3494  	 	 	 } else {
3495  	 	 	 	 $imgy = $this->y;
3496  	 	 	 }
3497  	 	 	 $cell_height = $this->getCellHeight($headerfont[2] / $this->k);
3498  	 	 	 // set starting margin for text data cell
3499  	 	 	 if ($this->getRTL()) {
3500  	 	 	 	 $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
3501  	 	 	 } else {
3502  	 	 	 	 $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
3503  	 	 	 }
3504  	 	 	 $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
3505  	 	 	 $this->setTextColorArray($this->header_text_color);
3506  	 	 	 // header title
3507  	 	 	 $this->setFont($headerfont[0], 'B', $headerfont[2] + 1);
3508  	 	 	 $this->setX($header_x);
3509  	 	 	 $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
3510  	 	 	 // header string
3511  	 	 	 $this->setFont($headerfont[0], $headerfont[1], $headerfont[2]);
3512  	 	 	 $this->setX($header_x);
3513  	 	 	 $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
3514  	 	 	 // print an ending header line
3515  	 	 	 $this->setLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
3516  	 	 	 $this->setY((2.835 / $this->k) + max($imgy, $this->y));
3517  	 	 	 if ($this->rtl) {
3518  	 	 	 	 $this->setX($this->original_rMargin);
3519  	 	 	 } else {
3520  	 	 	 	 $this->setX($this->original_lMargin);
3521  	 	 	 }
3522  	 	 	 $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
3523  	 	 	 $this->endTemplate();
3524  	 	 }
3525  	 	 // print header template
3526  	 	 $x = 0;
3527  	 	 $dx = 0;
3528  	 	 if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
3529  	 	 	 // adjust margins for booklet mode
3530  	 	 	 $dx = ($this->original_lMargin - $this->original_rMargin);
3531  	 	 }
3532  	 	 if ($this->rtl) {
3533  	 	 	 $x = $this->w + $dx;
3534  	 	 } else {
3535  	 	 	 $x = 0 + $dx;
3536  	 	 }
3537  	 	 $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
3538  	 	 if ($this->header_xobj_autoreset) {
3539  	 	 	 // reset header xobject template at each page
3540  	 	 	 $this->header_xobjid = false;
3541  	 	 }
3542  	 }
3543  
3544  	 /**
3545  	  * This method is used to render the page footer.
3546  	  * It is automatically called by AddPage() and could be overwritten in your own inherited class.
3547  	  * @public
3548  	  */
3549  	public function Footer() {
3550  	 	 $cur_y = $this->y;
3551  	 	 $this->setTextColorArray($this->footer_text_color);
3552  	 	 //set style for cell border
3553  	 	 $line_width = (0.85 / $this->k);
3554  	 	 $this->setLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
3555  	 	 //print document barcode
3556  	 	 $barcode = $this->getBarcode();
3557  	 	 if (!empty($barcode)) {
3558  	 	 	 $this->Ln($line_width);
3559  	 	 	 $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
3560  	 	 	 $style = array(
3561  	 	 	 	 'position' => $this->rtl?'R':'L',
3562  	 	 	 	 'align' => $this->rtl?'R':'L',
3563  	 	 	 	 'stretch' => false,
3564  	 	 	 	 'fitwidth' => true,
3565  	 	 	 	 'cellfitalign' => '',
3566  	 	 	 	 'border' => false,
3567  	 	 	 	 'padding' => 0,
3568  	 	 	 	 'fgcolor' => array(0,0,0),
3569  	 	 	 	 'bgcolor' => false,
3570  	 	 	 	 'text' => false
3571  	 	 	 );
3572  	 	 	 $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
3573  	 	 }
3574  	 	 $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
3575  	 	 if (empty($this->pagegroups)) {
3576  	 	 	 $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
3577  	 	 } else {
3578  	 	 	 $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
3579  	 	 }
3580  	 	 $this->setY($cur_y);
3581  	 	 //Print page number
3582  	 	 if ($this->getRTL()) {
3583  	 	 	 $this->setX($this->original_rMargin);
3584  	 	 	 $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
3585  	 	 } else {
3586  	 	 	 $this->setX($this->original_lMargin);
3587  	 	 	 $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
3588  	 	 }
3589  	 }
3590  
3591  	 /**
3592  	  * This method is used to render the page header.
3593  	  * @protected
3594  	  * @since 4.0.012 (2008-07-24)
3595  	  */
3596  	protected function setHeader() {
3597  	 	 if (!$this->print_header OR ($this->state != 2)) {
3598  	 	 	 return;
3599  	 	 }
3600  	 	 $this->InHeader = true;
3601  	 	 $this->setGraphicVars($this->default_graphic_vars);
3602  	 	 $temp_thead = $this->thead;
3603  	 	 $temp_theadMargins = $this->theadMargins;
3604  	 	 $lasth = $this->lasth;
3605  	 	 $newline = $this->newline;
3606  	 	 $this->_outSaveGraphicsState();
3607  	 	 $this->rMargin = $this->original_rMargin;
3608  	 	 $this->lMargin = $this->original_lMargin;
3609  	 	 $this->setCellPadding(0);
3610  	 	 //set current position
3611  	 	 if ($this->rtl) {
3612  	 	 	 $this->setXY($this->original_rMargin, $this->header_margin);
3613  	 	 } else {
3614  	 	 	 $this->setXY($this->original_lMargin, $this->header_margin);
3615  	 	 }
3616  	 	 $this->setFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
3617  	 	 $this->Header();
3618  	 	 //restore position
3619  	 	 if ($this->rtl) {
3620  	 	 	 $this->setXY($this->original_rMargin, $this->tMargin);
3621  	 	 } else {
3622  	 	 	 $this->setXY($this->original_lMargin, $this->tMargin);
3623  	 	 }
3624  	 	 $this->_outRestoreGraphicsState();
3625  	 	 $this->lasth = $lasth;
3626  	 	 $this->thead = $temp_thead;
3627  	 	 $this->theadMargins = $temp_theadMargins;
3628  	 	 $this->newline = $newline;
3629  	 	 $this->InHeader = false;
3630  	 }
3631  
3632  	 /**
3633  	  * This method is used to render the page footer.
3634  	  * @protected
3635  	  * @since 4.0.012 (2008-07-24)
3636  	  */
3637  	protected function setFooter() {
3638  	 	 if ($this->state != 2) {
3639  	 	 	 return;
3640  	 	 }
3641  	 	 $this->InFooter = true;
3642  	 	 // save current graphic settings
3643  	 	 $gvars = $this->getGraphicVars();
3644  	 	 // mark this point
3645  	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page];
3646  	 	 $this->_out("\n");
3647  	 	 if ($this->print_footer) {
3648  	 	 	 $this->setGraphicVars($this->default_graphic_vars);
3649  	 	 	 $this->current_column = 0;
3650  	 	 	 $this->num_columns = 1;
3651  	 	 	 $temp_thead = $this->thead;
3652  	 	 	 $temp_theadMargins = $this->theadMargins;
3653  	 	 	 $lasth = $this->lasth;
3654  	 	 	 $this->_outSaveGraphicsState();
3655  	 	 	 $this->rMargin = $this->original_rMargin;
3656  	 	 	 $this->lMargin = $this->original_lMargin;
3657  	 	 	 $this->setCellPadding(0);
3658  	 	 	 //set current position
3659  	 	 	 $footer_y = $this->h - $this->footer_margin;
3660  	 	 	 if ($this->rtl) {
3661  	 	 	 	 $this->setXY($this->original_rMargin, $footer_y);
3662  	 	 	 } else {
3663  	 	 	 	 $this->setXY($this->original_lMargin, $footer_y);
3664  	 	 	 }
3665  	 	 	 $this->setFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
3666  	 	 	 $this->Footer();
3667  	 	 	 //restore position
3668  	 	 	 if ($this->rtl) {
3669  	 	 	 	 $this->setXY($this->original_rMargin, $this->tMargin);
3670  	 	 	 } else {
3671  	 	 	 	 $this->setXY($this->original_lMargin, $this->tMargin);
3672  	 	 	 }
3673  	 	 	 $this->_outRestoreGraphicsState();
3674  	 	 	 $this->lasth = $lasth;
3675  	 	 	 $this->thead = $temp_thead;
3676  	 	 	 $this->theadMargins = $temp_theadMargins;
3677  	 	 }
3678  	 	 // restore graphic settings
3679  	 	 $this->setGraphicVars($gvars);
3680  	 	 $this->current_column = $gvars['current_column'];
3681  	 	 $this->num_columns = $gvars['num_columns'];
3682  	 	 // calculate footer length
3683  	 	 $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
3684  	 	 $this->InFooter = false;
3685  	 }
3686  
3687  	 /**
3688  	  * Check if we are on the page body (excluding page header and footer).
3689  	  * @return bool true if we are not in page header nor in page footer, false otherwise.
3690  	  * @protected
3691  	  * @since 5.9.091 (2011-06-15)
3692  	  */
3693  	protected function inPageBody() {
3694  	 	 return (($this->InHeader === false) AND ($this->InFooter === false));
3695  	 }
3696  
3697  	 /**
3698  	  * This method is used to render the table header on new page (if any).
3699  	  * @protected
3700  	  * @since 4.5.030 (2009-03-25)
3701  	  */
3702  	protected function setTableHeader() {
3703  	 	 if ($this->num_columns > 1) {
3704  	 	 	 // multi column mode
3705  	 	 	 return;
3706  	 	 }
3707  	 	 if (isset($this->theadMargins['top'])) {
3708  	 	 	 // restore the original top-margin
3709  	 	 	 $this->tMargin = $this->theadMargins['top'];
3710  	 	 	 $this->pagedim[$this->page]['tm'] = $this->tMargin;
3711  	 	 	 $this->y = $this->tMargin;
3712  	 	 }
3713  	 	 if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
3714  	 	 	 // set margins
3715  	 	 	 $prev_lMargin = $this->lMargin;
3716  	 	 	 $prev_rMargin = $this->rMargin;
3717  	 	 	 $prev_cell_padding = $this->cell_padding;
3718  	 	 	 $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
3719  	 	 	 $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
3720  	 	 	 $this->cell_padding = $this->theadMargins['cell_padding'];
3721  	 	 	 if ($this->rtl) {
3722  	 	 	 	 $this->x = $this->w - $this->rMargin;
3723  	 	 	 } else {
3724  	 	 	 	 $this->x = $this->lMargin;
3725  	 	 	 }
3726  	 	 	 // account for special "cell" mode
3727  	 	 	 if ($this->theadMargins['cell']) {
3728  	 	 	 	 if ($this->rtl) {
3729  	 	 	 	 	 $this->x -= $this->cell_padding['R'];
3730  	 	 	 	 } else {
3731  	 	 	 	 	 $this->x += $this->cell_padding['L'];
3732  	 	 	 	 }
3733  	 	 	 }
3734  	 	 	 $gvars = $this->getGraphicVars();
3735  	 	 	 if (!empty($this->theadMargins['gvars'])) {
3736  	 	 	 	 // set the correct graphic style
3737  	 	 	 	 $this->setGraphicVars($this->theadMargins['gvars']);
3738  	 	 	 	 $this->rMargin = $gvars['rMargin'];
3739  	 	 	 	 $this->lMargin = $gvars['lMargin'];
3740  	 	 	 }
3741  	 	 	 // print table header
3742  	 	 	 $this->writeHTML($this->thead, false, false, false, false, '');
3743  	 	 	 $this->setGraphicVars($gvars);
3744  	 	 	 // set new top margin to skip the table headers
3745  	 	 	 if (!isset($this->theadMargins['top'])) {
3746  	 	 	 	 $this->theadMargins['top'] = $this->tMargin;
3747  	 	 	 }
3748  	 	 	 // store end of header position
3749  	 	 	 if (!isset($this->columns[0]['th'])) {
3750  	 	 	 	 $this->columns[0]['th'] = array();
3751  	 	 	 }
3752  	 	 	 $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
3753  	 	 	 $this->tMargin = $this->y;
3754  	 	 	 $this->pagedim[$this->page]['tm'] = $this->tMargin;
3755  	 	 	 $this->lasth = 0;
3756  	 	 	 $this->lMargin = $prev_lMargin;
3757  	 	 	 $this->rMargin = $prev_rMargin;
3758  	 	 	 $this->cell_padding = $prev_cell_padding;
3759  	 	 }
3760  	 }
3761  
3762  	 /**
3763  	  * Returns the current page number.
3764  	  * @return int page number
3765  	  * @public
3766  	  * @since 1.0
3767  	  * @see getAliasNbPages()
3768  	  */
3769  	public function PageNo() {
3770  	 	 return $this->page;
3771  	 }
3772  
3773  	 /**
3774  	  * Returns the array of spot colors.
3775  	  * @return array Spot colors array.
3776  	  * @public
3777  	  * @since 6.0.038 (2013-09-30)
3778  	  */
3779  	public function getAllSpotColors() {
3780  	 	 return $this->spot_colors;
3781  	 }
3782  
3783  	 /**
3784  	  * Defines a new spot color.
3785  	  * It can be expressed in RGB components or gray scale.
3786  	  * The method can be called before the first page is created and the value is retained from page to page.
3787  	  * @param string $name Full name of the spot color.
3788  	  * @param float $c Cyan color for CMYK. Value between 0 and 100.
3789  	  * @param float $m Magenta color for CMYK. Value between 0 and 100.
3790  	  * @param float $y Yellow color for CMYK. Value between 0 and 100.
3791  	  * @param float $k Key (Black) color for CMYK. Value between 0 and 100.
3792  	  * @public
3793  	  * @since 4.0.024 (2008-09-12)
3794  	  * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
3795  	  */
3796  	public function AddSpotColor($name, $c, $m, $y, $k) {
3797  	 	 if (!isset($this->spot_colors[$name])) {
3798  	 	 	 $i = (1 + count($this->spot_colors));
3799  	 	 	 $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
3800  	 	 }
3801  	 }
3802  
3803  	 /**
3804  	  * Set the spot color for the specified type ('draw', 'fill', 'text').
3805  	  * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
3806  	  * @param string $name Name of the spot color.
3807  	  * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3808  	  * @return string PDF color command.
3809  	  * @public
3810  	  * @since 5.9.125 (2011-10-03)
3811  	  */
3812  	public function setSpotColor($type, $name, $tint=100) {
3813  	 	 $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
3814  	 	 if ($spotcolor === false) {
3815  	 	 	 $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
3816  	 	 }
3817  	 	 $tint = (max(0, min(100, $tint)) / 100);
3818  	 	 $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
3819  	 	 switch ($type) {
3820  	 	 	 case 'draw': {
3821  	 	 	 	 $pdfcolor .= sprintf('CS %F SCN', $tint);
3822  	 	 	 	 $this->DrawColor = $pdfcolor;
3823  	 	 	 	 $this->strokecolor = $spotcolor;
3824  	 	 	 	 break;
3825  	 	 	 }
3826  	 	 	 case 'fill': {
3827  	 	 	 	 $pdfcolor .= sprintf('cs %F scn', $tint);
3828  	 	 	 	 $this->FillColor = $pdfcolor;
3829  	 	 	 	 $this->bgcolor = $spotcolor;
3830  	 	 	 	 break;
3831  	 	 	 }
3832  	 	 	 case 'text': {
3833  	 	 	 	 $pdfcolor .= sprintf('cs %F scn', $tint);
3834  	 	 	 	 $this->TextColor = $pdfcolor;
3835  	 	 	 	 $this->fgcolor = $spotcolor;
3836  	 	 	 	 break;
3837  	 	 	 }
3838  	 	 }
3839  	 	 $this->ColorFlag = ($this->FillColor != $this->TextColor);
3840  	 	 if ($this->state == 2) {
3841  	 	 	 $this->_out($pdfcolor);
3842  	 	 }
3843  	 	 if ($this->inxobj) {
3844  	 	 	 // we are inside an XObject template
3845  	 	 	 $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
3846  	 	 }
3847  	 	 return $pdfcolor;
3848  	 }
3849  
3850  	 /**
3851  	  * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
3852  	  * @param string $name Name of the spot color.
3853  	  * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3854  	  * @public
3855  	  * @since 4.0.024 (2008-09-12)
3856  	  * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
3857  	  */
3858  	public function setDrawSpotColor($name, $tint=100) {
3859  	 	 $this->setSpotColor('draw', $name, $tint);
3860  	 }
3861  
3862  	 /**
3863  	  * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
3864  	  * @param string $name Name of the spot color.
3865  	  * @param float $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3866  	  * @public
3867  	  * @since 4.0.024 (2008-09-12)
3868  	  * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
3869  	  */
3870  	public function setFillSpotColor($name, $tint=100) {
3871  	 	 $this->setSpotColor('fill', $name, $tint);
3872  	 }
3873  
3874  	 /**
3875  	  * Defines the spot color used for text.
3876  	  * @param string $name Name of the spot color.
3877  	  * @param int $tint Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3878  	  * @public
3879  	  * @since 4.0.024 (2008-09-12)
3880  	  * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
3881  	  */
3882  	public function setTextSpotColor($name, $tint=100) {
3883  	 	 $this->setSpotColor('text', $name, $tint);
3884  	 }
3885  
3886  	 /**
3887  	  * Set the color array for the specified type ('draw', 'fill', 'text').
3888  	  * It can be expressed in RGB, CMYK or GRAY SCALE components.
3889  	  * The method can be called before the first page is created and the value is retained from page to page.
3890  	  * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
3891  	  * @param array $color Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
3892  	  * @param boolean $ret If true do not send the PDF command.
3893  	  * @return string The PDF command or empty string.
3894  	  * @public
3895  	  * @since 3.1.000 (2008-06-11)
3896  	  */
3897  	public function setColorArray($type, $color, $ret=false) {
3898  	 	 if (is_array($color)) {
3899  	 	 	 $color = array_values($color);
3900  	 	 	 // component: grey, RGB red or CMYK cyan
3901  	 	 	 $c = isset($color[0]) ? $color[0] : -1;
3902  	 	 	 // component: RGB green or CMYK magenta
3903  	 	 	 $m = isset($color[1]) ? $color[1] : -1;
3904  	 	 	 // component: RGB blue or CMYK yellow
3905  	 	 	 $y = isset($color[2]) ? $color[2] : -1;
3906  	 	 	 // component: CMYK black
3907  	 	 	 $k = isset($color[3]) ? $color[3] : -1;
3908  	 	 	 // color name
3909  	 	 	 $name = isset($color[4]) ? $color[4] : '';
3910  	 	 	 if ($c >= 0) {
3911  	 	 	 	 return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
3912  	 	 	 }
3913  	 	 }
3914  	 	 return '';
3915  	 }
3916  
3917  	 /**
3918  	  * Defines the color used for all drawing operations (lines, rectangles and cell borders).
3919  	  * It can be expressed in RGB, CMYK or GRAY SCALE components.
3920  	  * The method can be called before the first page is created and the value is retained from page to page.
3921  	  * @param array $color Array of colors (1, 3 or 4 values).
3922  	  * @param boolean $ret If true do not send the PDF command.
3923  	  * @return string the PDF command
3924  	  * @public
3925  	  * @since 3.1.000 (2008-06-11)
3926  	  * @see SetDrawColor()
3927  	  */
3928  	public function setDrawColorArray($color, $ret=false) {
3929  	 	 return $this->setColorArray('draw', $color, $ret);
3930  	 }
3931  
3932  	 /**
3933  	  * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
3934  	  * It can be expressed in RGB, CMYK or GRAY SCALE components.
3935  	  * The method can be called before the first page is created and the value is retained from page to page.
3936  	  * @param array $color Array of colors (1, 3 or 4 values).
3937  	  * @param boolean $ret If true do not send the PDF command.
3938  	  * @public
3939  	  * @since 3.1.000 (2008-6-11)
3940  	  * @see SetFillColor()
3941  	  */
3942  	public function setFillColorArray($color, $ret=false) {
3943  	 	 return $this->setColorArray('fill', $color, $ret);
3944  	 }
3945  
3946  	 /**
3947  	  * Defines the color used for text. It can be expressed in RGB components or gray scale.
3948  	  * The method can be called before the first page is created and the value is retained from page to page.
3949  	  * @param array $color Array of colors (1, 3 or 4 values).
3950  	  * @param boolean $ret If true do not send the PDF command.
3951  	  * @public
3952  	  * @since 3.1.000 (2008-6-11)
3953  	  * @see SetFillColor()
3954  	  */
3955  	public function setTextColorArray($color, $ret=false) {
3956  	 	 return $this->setColorArray('text', $color, $ret);
3957  	 }
3958  
3959  	 /**
3960  	  * Defines the color used by the specified type ('draw', 'fill', 'text').
3961  	  * @param string $type Type of object affected by this color: ('draw', 'fill', 'text').
3962  	  * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
3963  	  * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
3964  	  * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
3965  	  * @param float $col4 KEY (BLACK) color for CMYK (0-100).
3966  	  * @param boolean $ret If true do not send the command.
3967  	  * @param string $name spot color name (if any)
3968  	  * @return string The PDF command or empty string.
3969  	  * @public
3970  	  * @since 5.9.125 (2011-10-03)
3971  	  */
3972  	public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
3973  	 	 // set default values
3974  	 	 if (!is_numeric($col1)) {
3975  	 	 	 $col1 = 0;
3976  	 	 }
3977  	 	 if (!is_numeric($col2)) {
3978  	 	 	 $col2 = -1;
3979  	 	 }
3980  	 	 if (!is_numeric($col3)) {
3981  	 	 	 $col3 = -1;
3982  	 	 }
3983  	 	 if (!is_numeric($col4)) {
3984  	 	 	 $col4 = -1;
3985  	 	 }
3986  	 	 // set color by case
3987  	 	 $suffix = '';
3988  	 	 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
3989  	 	 	 // Grey scale
3990  	 	 	 $col1 = max(0, min(255, $col1));
3991  	 	 	 $intcolor = array('G' => $col1);
3992  	 	 	 $pdfcolor = sprintf('%F ', ($col1 / 255));
3993  	 	 	 $suffix = 'g';
3994  	 	 } elseif ($col4 == -1) {
3995  	 	 	 // RGB
3996  	 	 	 $col1 = max(0, min(255, $col1));
3997  	 	 	 $col2 = max(0, min(255, $col2));
3998  	 	 	 $col3 = max(0, min(255, $col3));
3999  	 	 	 $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
4000  	 	 	 $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
4001  	 	 	 $suffix = 'rg';
4002  	 	 } else {
4003  	 	 	 $col1 = max(0, min(100, $col1));
4004  	 	 	 $col2 = max(0, min(100, $col2));
4005  	 	 	 $col3 = max(0, min(100, $col3));
4006  	 	 	 $col4 = max(0, min(100, $col4));
4007  	 	 	 if (empty($name)) {
4008  	 	 	 	 // CMYK
4009  	 	 	 	 $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
4010  	 	 	 	 $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
4011  	 	 	 	 $suffix = 'k';
4012  	 	 	 } else {
4013  	 	 	 	 // SPOT COLOR
4014  	 	 	 	 $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
4015  	 	 	 	 $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
4016  	 	 	 	 $pdfcolor = $this->setSpotColor($type, $name, 100);
4017  	 	 	 }
4018  	 	 }
4019  	 	 switch ($type) {
4020  	 	 	 case 'draw': {
4021  	 	 	 	 $pdfcolor .= strtoupper($suffix);
4022  	 	 	 	 $this->DrawColor = $pdfcolor;
4023  	 	 	 	 $this->strokecolor = $intcolor;
4024  	 	 	 	 break;
4025  	 	 	 }
4026  	 	 	 case 'fill': {
4027  	 	 	 	 $pdfcolor .= $suffix;
4028  	 	 	 	 $this->FillColor = $pdfcolor;
4029  	 	 	 	 $this->bgcolor = $intcolor;
4030  	 	 	 	 break;
4031  	 	 	 }
4032  	 	 	 case 'text': {
4033  	 	 	 	 $pdfcolor .= $suffix;
4034  	 	 	 	 $this->TextColor = $pdfcolor;
4035  	 	 	 	 $this->fgcolor = $intcolor;
4036  	 	 	 	 break;
4037  	 	 	 }
4038  	 	 }
4039  	 	 $this->ColorFlag = ($this->FillColor != $this->TextColor);
4040  	 	 if (($type != 'text') AND ($this->state == 2) AND $type !== 0) {
4041  	 	 	 if (!$ret) {
4042  	 	 	 	 $this->_out($pdfcolor);
4043  	 	 	 }
4044  	 	 	 return $pdfcolor;
4045  	 	 }
4046  	 	 return '';
4047  	 }
4048  
4049  	 /**
4050  	  * 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.
4051  	  * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4052  	  * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4053  	  * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4054  	  * @param float $col4 KEY (BLACK) color for CMYK (0-100).
4055  	  * @param boolean $ret If true do not send the command.
4056  	  * @param string $name spot color name (if any)
4057  	  * @return string the PDF command
4058  	  * @public
4059  	  * @since 1.3
4060  	  * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
4061  	  */
4062  	public function setDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4063  	 	 return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
4064  	 }
4065  
4066  	 /**
4067  	  * 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.
4068  	  * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4069  	  * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4070  	  * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4071  	  * @param float $col4 KEY (BLACK) color for CMYK (0-100).
4072  	  * @param boolean $ret If true do not send the command.
4073  	  * @param string $name Spot color name (if any).
4074  	  * @return string The PDF command.
4075  	  * @public
4076  	  * @since 1.3
4077  	  * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
4078  	  */
4079  	public function setFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4080  	 	 return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
4081  	 }
4082  
4083  	 /**
4084  	  * 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.
4085  	  * @param float $col1 GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4086  	  * @param float $col2 GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4087  	  * @param float $col3 BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4088  	  * @param float $col4 KEY (BLACK) color for CMYK (0-100).
4089  	  * @param boolean $ret If true do not send the command.
4090  	  * @param string $name Spot color name (if any).
4091  	  * @return string Empty string.
4092  	  * @public
4093  	  * @since 1.3
4094  	  * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
4095  	  */
4096  	public function setTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4097  	 	 return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
4098  	 }
4099  
4100  	 /**
4101  	  * Returns the length of a string in user unit. A font must be selected.<br>
4102  	  * @param string $s The string whose length is to be computed
4103  	  * @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.
4104  	  * @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.
4105  	  * @param float $fontsize Font size in points. The default value is the current size.
4106  	  * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
4107  	  * @return float[]|float total string length or array of characted widths
4108  	  * @author Nicola Asuni
4109  	  * @public
4110  	  * @since 1.2
4111  	  */
4112  	public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
4113  	 	 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);
4114  	 }
4115  
4116  	 /**
4117  	  * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
4118  	  * @param array $sa The array of chars whose total length is to be computed
4119  	  * @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.
4120  	  * @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.
4121  	  * @param float $fontsize Font size in points. The default value is the current size.
4122  	  * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
4123  	  * @return float[]|float total string length or array of characted widths
4124  	  * @author Nicola Asuni
4125  	  * @public
4126  	  * @since 2.4.000 (2008-03-06)
4127  	  */
4128  	public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
4129  	 	 // store current values
4130  	 	 if (!TCPDF_STATIC::empty_string($fontname)) {
4131  	 	 	 $prev_FontFamily = $this->FontFamily;
4132  	 	 	 $prev_FontStyle = $this->FontStyle;
4133  	 	 	 $prev_FontSizePt = $this->FontSizePt;
4134  	 	 	 $this->setFont($fontname, $fontstyle, $fontsize, '', 'default', false);
4135  	 	 }
4136  	 	 // convert UTF-8 array to Latin1 if required
4137  	 	 if ($this->isunicode AND (!$this->isUnicodeFont())) {
4138  	 	 	 $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
4139  	 	 }
4140  	 	 $w = 0; // total width
4141  	 	 $wa = array(); // array of characters widths
4142  	 	 foreach ($sa as $ck => $char) {
4143  	 	 	 // character width
4144  	 	 	 $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
4145  	 	 	 $wa[] = $cw;
4146  	 	 	 $w += $cw;
4147  	 	 }
4148  	 	 // restore previous values
4149  	 	 if (!TCPDF_STATIC::empty_string($fontname)) {
4150  	 	 	 $this->setFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
4151  	 	 }
4152  	 	 if ($getarray) {
4153  	 	 	 return $wa;
4154  	 	 }
4155  	 	 return $w;
4156  	 }
4157  
4158  	 /**
4159  	  * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
4160  	  * @param int $char The char code whose length is to be returned
4161  	  * @param boolean $notlast If false ignore the font-spacing.
4162  	  * @return float char width
4163  	  * @author Nicola Asuni
4164  	  * @public
4165  	  * @since 2.4.000 (2008-03-06)
4166  	  */
4167  	public function GetCharWidth($char, $notlast=true) {
4168  	 	 // get raw width
4169  	 	 $chw = $this->getRawCharWidth($char);
4170  	 	 if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
4171  	 	 	 // increase/decrease font spacing
4172  	 	 	 $chw += $this->font_spacing;
4173  	 	 }
4174  	 	 if ($this->font_stretching != 100) {
4175  	 	 	 // fixed stretching mode
4176  	 	 	 $chw *= ($this->font_stretching / 100);
4177  	 	 }
4178  	 	 return $chw;
4179  	 }
4180  
4181  	 /**
4182  	  * Returns the length of the char in user unit for the current font.
4183  	  * @param int $char The char code whose length is to be returned
4184  	  * @return float char width
4185  	  * @author Nicola Asuni
4186  	  * @public
4187  	  * @since 5.9.000 (2010-09-28)
4188  	  */
4189  	public function getRawCharWidth($char) {
4190  	 	 if ($char == 173) {
4191  	 	 	 // SHY character will not be printed
4192  	 	 	 return (0);
4193  	 	 }
4194  	 	 if (isset($this->CurrentFont['cw'][intval($char)])) {
4195  	 	 	 $w = $this->CurrentFont['cw'][intval($char)];
4196  	 	 } elseif (isset($this->CurrentFont['dw'])) {
4197  	 	 	 // default width
4198  	 	 	 $w = $this->CurrentFont['dw'];
4199  	 	 } elseif (isset($this->CurrentFont['cw'][32])) {
4200  	 	 	 // default width
4201  	 	 	 $w = $this->CurrentFont['cw'][32];
4202  	 	 } else {
4203  	 	 	 $w = 600;
4204  	 	 }
4205  	 	 return $this->getAbsFontMeasure($w);
4206  	 }
4207  
4208  	 /**
4209  	  * Returns the numbero of characters in a string.
4210  	  * @param string $s The input string.
4211  	  * @return int number of characters
4212  	  * @public
4213  	  * @since 2.0.0001 (2008-01-07)
4214  	  */
4215  	public function GetNumChars($s) {
4216  	 	 if ($this->isUnicodeFont()) {
4217  	 	 	 return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
4218  	 	 }
4219  	 	 return strlen($s);
4220  	 }
4221  
4222  	 /**
4223  	  * Fill the list of available fonts ($this->fontlist).
4224  	  * @protected
4225  	  * @since 4.0.013 (2008-07-28)
4226  	  */
4227  	protected function getFontsList() {
4228  	 	 if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
4229  	 	 	 while (($file = readdir($fontsdir)) !== false) {
4230  	 	 	 	 if (substr($file, -4) == '.php') {
4231  	 	 	 	 	 array_push($this->fontlist, strtolower(basename($file, '.php')));
4232  	 	 	 	 }
4233  	 	 	 }
4234  	 	 	 closedir($fontsdir);
4235  	 	 }
4236  	 }
4237  
4238  	 /**
4239  	  * Imports a TrueType, Type1, core, or CID0 font and makes it available.
4240  	  * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
4241  	  * 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.
4242  	  * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
4243  	  * @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>
4244  	  * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
4245  	  * @return array|false array containing the font data, or false in case of error.
4246  	  * @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.
4247  	  * @public
4248  	  * @since 1.5
4249  	  * @see SetFont(), setFontSubsetting()
4250  	  */
4251  	public function AddFont($family, $style='', $fontfile='', $subset='default') {
4252  	 	 if ($subset === 'default') {
4253  	 	 	 $subset = $this->font_subsetting;
4254  	 	 }
4255  	 	 if ($this->pdfa_mode) {
4256  	 	 	 $subset = false;
4257  	 	 }
4258  	 	 if (TCPDF_STATIC::empty_string($family)) {
4259  	 	 	 if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
4260  	 	 	 	 $family = $this->FontFamily;
4261  	 	 	 } else {
4262  	 	 	 	 $this->Error('Empty font family');
4263  	 	 	 }
4264  	 	 }
4265  	 	 // move embedded styles on $style
4266  	 	 if (substr($family, -1) == 'I') {
4267  	 	 	 $style .= 'I';
4268  	 	 	 $family = substr($family, 0, -1);
4269  	 	 }
4270  	 	 if (substr($family, -1) == 'B') {
4271  	 	 	 $style .= 'B';
4272  	 	 	 $family = substr($family, 0, -1);
4273  	 	 }
4274  	 	 // normalize family name
4275  	 	 $family = strtolower($family);
4276  	 	 if ((!$this->isunicode) AND ($family == 'arial')) {
4277  	 	 	 $family = 'helvetica';
4278  	 	 }
4279  	 	 if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
4280  	 	 	 $style = '';
4281  	 	 }
4282  	 	 if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
4283  	 	 	 // all fonts must be embedded
4284  	 	 	 $family = 'pdfa'.$family;
4285  	 	 }
4286  	 	 $tempstyle = strtoupper($style);
4287  	 	 $style = '';
4288  	 	 // underline
4289  	 	 if (strpos($tempstyle, 'U') !== false) {
4290  	 	 	 $this->underline = true;
4291  	 	 } else {
4292  	 	 	 $this->underline = false;
4293  	 	 }
4294  	 	 // line-through (deleted)
4295  	 	 if (strpos($tempstyle, 'D') !== false) {
4296  	 	 	 $this->linethrough = true;
4297  	 	 } else {
4298  	 	 	 $this->linethrough = false;
4299  	 	 }
4300  	 	 // overline
4301  	 	 if (strpos($tempstyle, 'O') !== false) {
4302  	 	 	 $this->overline = true;
4303  	 	 } else {
4304  	 	 	 $this->overline = false;
4305  	 	 }
4306  	 	 // bold
4307  	 	 if (strpos($tempstyle, 'B') !== false) {
4308  	 	 	 $style .= 'B';
4309  	 	 }
4310  	 	 // oblique
4311  	 	 if (strpos($tempstyle, 'I') !== false) {
4312  	 	 	 $style .= 'I';
4313  	 	 }
4314  	 	 $bistyle = $style;
4315  	 	 $fontkey = $family.$style;
4316  	 	 $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
4317  	 	 $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
4318  	 	 // check if the font has been already added
4319  	 	 $fb = $this->getFontBuffer($fontkey);
4320  	 	 if ($fb !== false) {
4321  	 	 	 if ($this->inxobj) {
4322  	 	 	 	 // we are inside an XObject template
4323  	 	 	 	 $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
4324  	 	 	 }
4325  	 	 	 return $fontdata;
4326  	 	 }
4327  	 	 // get specified font directory (if any)
4328  	 	 $fontdir = false;
4329  	 	 if (!TCPDF_STATIC::empty_string($fontfile)) {
4330  	 	 	 $fontdir = dirname($fontfile);
4331  	 	 	 if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
4332  	 	 	 	 $fontdir = '';
4333  	 	 	 } else {
4334  	 	 	 	 $fontdir .= '/';
4335  	 	 	 }
4336  	 	 }
4337  	 	 // true when the font style variation is missing
4338  	 	 $missing_style = false;
4339  	 	 // search and include font file
4340  	 	 if (TCPDF_STATIC::empty_string($fontfile) OR (!@TCPDF_STATIC::file_exists($fontfile))) {
4341  	 	 	 // build a standard filenames for specified font
4342  	 	 	 $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
4343  	 	 	 $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
4344  	 	 	 if (TCPDF_STATIC::empty_string($fontfile)) {
4345  	 	 	 	 $missing_style = true;
4346  	 	 	 	 // try to remove the style part
4347  	 	 	 	 $tmp_fontfile = str_replace(' ', '', $family).'.php';
4348  	 	 	 	 $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
4349  	 	 	 }
4350  	 	 }
4351  	 	 // include font file
4352  	 	 if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
4353  	 	 	 include($fontfile);
4354  	 	 } else {
4355  	 	 	 $this->Error('Could not include font definition file: '.$family.'');
4356  	 	 }
4357  	 	 // check font parameters
4358  	 	 if ((!isset($type)) OR (!isset($cw))) {
4359  	 	 	 $this->Error('The font definition file has a bad format: '.$fontfile.'');
4360  	 	 }
4361  	 	 // SET default parameters
4362  	 	 if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
4363  	 	 	 $file = '';
4364  	 	 }
4365  	 	 if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
4366  	 	 	 $enc = '';
4367  	 	 }
4368  	 	 if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
4369  	 	 	 $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
4370  	 	 	 $cidinfo['uni2cid'] = array();
4371  	 	 }
4372  	 	 if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
4373  	 	 	 $ctg = '';
4374  	 	 }
4375  	 	 if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
4376  	 	 	 $desc = array();
4377  	 	 }
4378  	 	 if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
4379  	 	 	 $up = -100;
4380  	 	 }
4381  	 	 if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
4382  	 	 	 $ut = 50;
4383  	 	 }
4384  	 	 if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
4385  	 	 	 $cw = array();
4386  	 	 }
4387  	 	 if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
4388  	 	 	 // set default width
4389  	 	 	 if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
4390  	 	 	 	 $dw = $desc['MissingWidth'];
4391  	 	 	 } elseif (isset($cw[32])) {
4392  	 	 	 	 $dw = $cw[32];
4393  	 	 	 } else {
4394  	 	 	 	 $dw = 600;
4395  	 	 	 }
4396  	 	 }
4397  	 	 ++$this->numfonts;
4398  	 	 if ($type == 'core') {
4399  	 	 	 $name = $this->CoreFonts[$fontkey];
4400  	 	 	 $subset = false;
4401  	 	 } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
4402  	 	 	 $subset = false;
4403  	 	 } elseif ($type == 'TrueTypeUnicode') {
4404  	 	 	 $enc = 'Identity-H';
4405  	 	 } elseif ($type == 'cidfont0') {
4406  	 	 	 if ($this->pdfa_mode) {
4407  	 	 	 	 $this->Error('All fonts must be embedded in PDF/A mode!');
4408  	 	 	 }
4409  	 	 } else {
4410  	 	 	 $this->Error('Unknow font type: '.$type.'');
4411  	 	 }
4412  	 	 // set name if unset
4413  	 	 if (!isset($name) OR empty($name)) {
4414  	 	 	 $name = $fontkey;
4415  	 	 }
4416  	 	 // create artificial font style variations if missing (only works with non-embedded fonts)
4417  	 	 if (($type != 'core') AND $missing_style) {
4418  	 	 	 // style variations
4419  	 	 	 $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
4420  	 	 	 $name .= $styles[$bistyle];
4421  	 	 	 // artificial bold
4422  	 	 	 if (strpos($bistyle, 'B') !== false) {
4423  	 	 	 	 if (isset($desc['StemV'])) {
4424  	 	 	 	 	 // from normal to bold
4425  	 	 	 	 	 $desc['StemV'] = round($desc['StemV'] * 1.75);
4426  	 	 	 	 } else {
4427  	 	 	 	 	 // bold
4428  	 	 	 	 	 $desc['StemV'] = 123;
4429  	 	 	 	 }
4430  	 	 	 }
4431  	 	 	 // artificial italic
4432  	 	 	 if (strpos($bistyle, 'I') !== false) {
4433  	 	 	 	 if (isset($desc['ItalicAngle'])) {
4434  	 	 	 	 	 $desc['ItalicAngle'] -= 11;
4435  	 	 	 	 } else {
4436  	 	 	 	 	 $desc['ItalicAngle'] = -11;
4437  	 	 	 	 }
4438  	 	 	 	 if (isset($desc['Flags'])) {
4439  	 	 	 	 	 $desc['Flags'] |= 64; //bit 7
4440  	 	 	 	 } else {
4441  	 	 	 	 	 $desc['Flags'] = 64;
4442  	 	 	 	 }
4443  	 	 	 }
4444  	 	 }
4445  	 	 // check if the array of characters bounding boxes is defined
4446  	 	 if (!isset($cbbox)) {
4447  	 	 	 $cbbox = array();
4448  	 	 }
4449  	 	 // initialize subsetchars
4450  	 	 $subsetchars = array_fill(0, 255, true);
4451  	 	 $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));
4452  	 	 if ($this->inxobj) {
4453  	 	 	 // we are inside an XObject template
4454  	 	 	 $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
4455  	 	 }
4456  	 	 if (isset($diff) AND (!empty($diff))) {
4457  	 	 	 //Search existing encodings
4458  	 	 	 $d = 0;
4459  	 	 	 $nb = count($this->diffs);
4460  	 	 	 for ($i=1; $i <= $nb; ++$i) {
4461  	 	 	 	 if ($this->diffs[$i] == $diff) {
4462  	 	 	 	 	 $d = $i;
4463  	 	 	 	 	 break;
4464  	 	 	 	 }
4465  	 	 	 }
4466  	 	 	 if ($d == 0) {
4467  	 	 	 	 $d = $nb + 1;
4468  	 	 	 	 $this->diffs[$d] = $diff;
4469  	 	 	 }
4470  	 	 	 $this->setFontSubBuffer($fontkey, 'diff', $d);
4471  	 	 }
4472  	 	 if (!TCPDF_STATIC::empty_string($file)) {
4473  	 	 	 if (!isset($this->FontFiles[$file])) {
4474  	 	 	 	 if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
4475  	 	 	 	 	 $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
4476  	 	 	 	 } elseif ($type != 'core') {
4477  	 	 	 	 	 $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
4478  	 	 	 	 }
4479  	 	 	 } else {
4480  	 	 	 	 // update fontkeys that are sharing this font file
4481  	 	 	 	 $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
4482  	 	 	 	 if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
4483  	 	 	 	 	 $this->FontFiles[$file]['fontkeys'][] = $fontkey;
4484  	 	 	 	 }
4485  	 	 	 }
4486  	 	 }
4487  	 	 return $fontdata;
4488  	 }
4489  
4490  	 /**
4491  	  * Sets the font used to print character strings.
4492  	  * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
4493  	  * The method can be called before the first page is created and the font is retained from page to page.
4494  	  * If you just wish to change the current font size, it is simpler to call SetFontSize().
4495  	  * 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 />
4496  	  * @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.
4497  	  * @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.
4498  	  * @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
4499  	  * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
4500  	  * @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.
4501  	  * @param boolean $out if true output the font size command, otherwise only set the font properties.
4502  	  * @author Nicola Asuni
4503  	  * @public
4504  	  * @since 1.0
4505  	  * @see AddFont(), SetFontSize()
4506  	  */
4507  	public function setFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
4508  	 	 //Select a font; size given in points
4509  	 	 if ($size === null) {
4510  	 	 	 $size = $this->FontSizePt;
4511  	 	 }
4512  	 	 if ($size < 0) {
4513  	 	 	 $size = 0;
4514  	 	 }
4515  	 	 // try to add font (if not already added)
4516  	 	 $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
4517  	 	 $this->FontFamily = $fontdata['family'];
4518  	 	 $this->FontStyle = $fontdata['style'];
4519  	 	 if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
4520  	 	 	 // save subset chars of the previous font
4521  	 	 	 $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
4522  	 	 }
4523  	 	 $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
4524  	 	 $this->setFontSize($size, $out);
4525  	 }
4526  
4527  	 /**
4528  	  * Defines the size of the current font.
4529  	  * @param float $size The font size in points.
4530  	  * @param boolean $out if true output the font size command, otherwise only set the font properties.
4531  	  * @public
4532  	  * @since 1.0
4533  	  * @see SetFont()
4534  	  */
4535  	public function setFontSize($size, $out=true) {
4536  	 	 $size = (float)$size;
4537  	 	 // font size in points
4538  	 	 $this->FontSizePt = $size;
4539  	 	 // font size in user units
4540  	 	 $this->FontSize = $size / $this->k;
4541  	 	 // calculate some font metrics
4542  	 	 if (isset($this->CurrentFont['desc']['FontBBox'])) {
4543  	 	 	 $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
4544  	 	 	 $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
4545  	 	 } else {
4546  	 	 	 $font_height = $size * 1.219;
4547  	 	 }
4548  	 	 if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
4549  	 	 	 $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
4550  	 	 }
4551  	 	 if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
4552  	 	 	 $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
4553  	 	 }
4554  	 	 if (!isset($font_ascent) AND !isset($font_descent)) {
4555  	 	 	 // core font
4556  	 	 	 $font_ascent = 0.76 * $font_height;
4557  	 	 	 $font_descent = $font_height - $font_ascent;
4558  	 	 } elseif (!isset($font_descent)) {
4559  	 	 	 $font_descent = $font_height - $font_ascent;
4560  	 	 } elseif (!isset($font_ascent)) {
4561  	 	 	 $font_ascent = $font_height - $font_descent;
4562  	 	 }
4563  	 	 $this->FontAscent = ($font_ascent / $this->k);
4564  	 	 $this->FontDescent = ($font_descent / $this->k);
4565  	 	 if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
4566  	 	 	 $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
4567  	 	 }
4568  	 }
4569  
4570  	 /**
4571  	  * Returns the bounding box of the current font in user units.
4572  	  * @return array
4573  	  * @public
4574  	  * @since 5.9.152 (2012-03-23)
4575  	  */
4576  	public function getFontBBox() {
4577  	 	 $fbbox = array();
4578  	 	 if (isset($this->CurrentFont['desc']['FontBBox'])) {
4579  	 	 	 $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
4580  	 	 	 $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
4581  	 	 } else {
4582  	 	 	 // Find max width
4583  	 	 	 if (isset($this->CurrentFont['desc']['MaxWidth'])) {
4584  	 	 	 	 $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
4585  	 	 	 } else {
4586  	 	 	 	 $maxw = 0;
4587  	 	 	 	 if (isset($this->CurrentFont['desc']['MissingWidth'])) {
4588  	 	 	 	 	 $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
4589  	 	 	 	 }
4590  	 	 	 	 if (isset($this->CurrentFont['desc']['AvgWidth'])) {
4591  	 	 	 	 	 $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
4592  	 	 	 	 }
4593  	 	 	 	 if (isset($this->CurrentFont['dw'])) {
4594  	 	 	 	 	 $maxw = max($maxw, $this->CurrentFont['dw']);
4595  	 	 	 	 }
4596  	 	 	 	 foreach ($this->CurrentFont['cw'] as $char => $w) {
4597  	 	 	 	 	 $maxw = max($maxw, $w);
4598  	 	 	 	 }
4599  	 	 	 	 if ($maxw == 0) {
4600  	 	 	 	 	 $maxw = 600;
4601  	 	 	 	 }
4602  	 	 	 	 $maxw = $this->getAbsFontMeasure($maxw);
4603  	 	 	 }
4604  	 	 	 $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
4605  	 	 }
4606  	 	 return $fbbox;
4607  	 }
4608  
4609  	 /**
4610  	  * Convert a relative font measure into absolute value.
4611  	  * @param int $s Font measure.
4612  	  * @return float Absolute measure.
4613  	  * @since 5.9.186 (2012-09-13)
4614  	  */
4615  	public function getAbsFontMeasure($s) {
4616  	 	 return ($s * $this->FontSize / 1000);
4617  	 }
4618  
4619  	 /**
4620  	  * Returns the glyph bounding box of the specified character in the current font in user units.
4621  	  * @param int $char Input character code.
4622  	  * @return false|array array(xMin, yMin, xMax, yMax) or FALSE if not defined.
4623  	  * @since 5.9.186 (2012-09-13)
4624  	  */
4625  	public function getCharBBox($char) {
4626  	 	 $c = intval($char);
4627  	 	 if (isset($this->CurrentFont['cw'][$c])) {
4628  	 	 	 // glyph is defined ... use zero width & height for glyphs without outlines
4629  	 	 	 $result = array(0,0,0,0);
4630  	 	 	 if (isset($this->CurrentFont['cbbox'][$c])) {
4631  	 	 	 	 $result = $this->CurrentFont['cbbox'][$c];
4632  	 	 	 }
4633  	 	 	 return array_map(array($this,'getAbsFontMeasure'), $result);
4634  	 	 }
4635  	 	 return false;
4636  	 }
4637  
4638  	 /**
4639  	  * Return the font descent value
4640  	  * @param string $font font name
4641  	  * @param string $style font style
4642  	  * @param float $size The size (in points)
4643  	  * @return int font descent
4644  	  * @public
4645  	  * @author Nicola Asuni
4646  	  * @since 4.9.003 (2010-03-30)
4647  	  */
4648  	public function getFontDescent($font, $style='', $size=0) {
4649  	 	 $fontdata = $this->AddFont($font, $style);
4650  	 	 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4651  	 	 if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
4652  	 	 	 $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
4653  	 	 } else {
4654  	 	 	 $descent = (1.219 * 0.24 * $size);
4655  	 	 }
4656  	 	 return ($descent / $this->k);
4657  	 }
4658  
4659  	 /**
4660  	  * Return the font ascent value.
4661  	  * @param string $font font name
4662  	  * @param string $style font style
4663  	  * @param float $size The size (in points)
4664  	  * @return int font ascent
4665  	  * @public
4666  	  * @author Nicola Asuni
4667  	  * @since 4.9.003 (2010-03-30)
4668  	  */
4669  	public function getFontAscent($font, $style='', $size=0) {
4670  	 	 $fontdata = $this->AddFont($font, $style);
4671  	 	 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4672  	 	 if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
4673  	 	 	 $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
4674  	 	 } else {
4675  	 	 	 $ascent = 1.219 * 0.76 * $size;
4676  	 	 }
4677  	 	 return ($ascent / $this->k);
4678  	 }
4679  
4680  	 /**
4681  	  * Return true in the character is present in the specified font.
4682  	  * @param mixed $char Character to check (integer value or string)
4683  	  * @param string $font Font name (family name).
4684  	  * @param string $style Font style.
4685  	  * @return bool true if the char is defined, false otherwise.
4686  	  * @public
4687  	  * @since 5.9.153 (2012-03-28)
4688  	  */
4689  	public function isCharDefined($char, $font='', $style='') {
4690  	 	 if (is_string($char)) {
4691  	 	 	 // get character code
4692  	 	 	 $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
4693  	 	 	 $char = $char[0];
4694  	 	 }
4695  	 	 if (TCPDF_STATIC::empty_string($font)) {
4696  	 	 	 if (TCPDF_STATIC::empty_string($style)) {
4697  	 	 	 	 return (isset($this->CurrentFont['cw'][intval($char)]));
4698  	 	 	 }
4699  	 	 	 $font = $this->FontFamily;
4700  	 	 }
4701  	 	 $fontdata = $this->AddFont($font, $style);
4702  	 	 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4703  	 	 return (isset($fontinfo['cw'][intval($char)]));
4704  	 }
4705  
4706  	 /**
4707  	  * Replace missing font characters on selected font with specified substitutions.
4708  	  * @param string $text Text to process.
4709  	  * @param string $font Font name (family name).
4710  	  * @param string $style Font style.
4711  	  * @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.
4712  	  * @return string Processed text.
4713  	  * @public
4714  	  * @since 5.9.153 (2012-03-28)
4715  	  */
4716  	public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
4717  	 	 if (empty($subs)) {
4718  	 	 	 return $text;
4719  	 	 }
4720  	 	 if (TCPDF_STATIC::empty_string($font)) {
4721  	 	 	 $font = $this->FontFamily;
4722  	 	 }
4723  	 	 $fontdata = $this->AddFont($font, $style);
4724  	 	 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4725  	 	 $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
4726  	 	 foreach ($uniarr as $k => $chr) {
4727  	 	 	 if (!isset($fontinfo['cw'][$chr])) {
4728  	 	 	 	 // this character is missing on the selected font
4729  	 	 	 	 if (isset($subs[$chr])) {
4730  	 	 	 	 	 // we have available substitutions
4731  	 	 	 	 	 if (is_array($subs[$chr])) {
4732  	 	 	 	 	 	 foreach($subs[$chr] as $s) {
4733  	 	 	 	 	 	 	 if (isset($fontinfo['cw'][$s])) {
4734  	 	 	 	 	 	 	 	 $uniarr[$k] = $s;
4735  	 	 	 	 	 	 	 	 break;
4736  	 	 	 	 	 	 	 }
4737  	 	 	 	 	 	 }
4738  	 	 	 	 	 } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
4739  	 	 	 	 	 	 $uniarr[$k] = $subs[$chr];
4740  	 	 	 	 	 }
4741  	 	 	 	 }
4742  	 	 	 }
4743  	 	 }
4744  	 	 return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
4745  	 }
4746  
4747  	 /**
4748  	  * Defines the default monospaced font.
4749  	  * @param string $font Font name.
4750  	  * @public
4751  	  * @since 4.5.025
4752  	  */
4753  	public function setDefaultMonospacedFont($font) {
4754  	 	 $this->default_monospaced_font = $font;
4755  	 }
4756  
4757  	 /**
4758  	  * 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 />
4759  	  * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
4760  	  * @public
4761  	  * @since 1.5
4762  	  * @see Cell(), Write(), Image(), Link(), SetLink()
4763  	  */
4764  	public function AddLink() {
4765  	 	 // create a new internal link
4766  	 	 $n = count($this->links) + 1;
4767  	 	 $this->links[$n] = array('p' => 0, 'y' => 0, 'f' => false);
4768  	 	 return $n;
4769  	 }
4770  
4771  	 /**
4772  	  * Defines the page and position a link points to.
4773  	  * @param int $link The link identifier returned by AddLink()
4774  	  * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
4775  	  * @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.
4776  	  * @public
4777  	  * @since 1.5
4778  	  * @see AddLink()
4779  	  */
4780  	public function setLink($link, $y=0, $page=-1) {
4781  	 	 $fixed = false;
4782  	 	 if (!empty($page) AND (substr($page, 0, 1) == '*')) {
4783  	 	 	 $page = intval(substr($page, 1));
4784  	 	 	 // this page number will not be changed when moving/add/deleting pages
4785  	 	 	 $fixed = true;
4786  	 	 }
4787  	 	 if ($page < 0) {
4788  	 	 	 $page = $this->page;
4789  	 	 }
4790  	 	 if ($y == -1) {
4791  	 	 	 $y = $this->y;
4792  	 	 }
4793  	 	 $this->links[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed);
4794  	 }
4795  
4796  	 /**
4797  	  * Puts a link on a rectangular area of the page.
4798  	  * 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.
4799  	  * @param float $x Abscissa of the upper-left corner of the rectangle
4800  	  * @param float $y Ordinate of the upper-left corner of the rectangle
4801  	  * @param float $w Width of the rectangle
4802  	  * @param float $h Height of the rectangle
4803  	  * @param mixed $link URL or identifier returned by AddLink()
4804  	  * @param int $spaces number of spaces on the text to link
4805  	  * @public
4806  	  * @since 1.5
4807  	  * @see AddLink(), Annotation(), Cell(), Write(), Image()
4808  	  */
4809  	public function Link($x, $y, $w, $h, $link, $spaces=0) {
4810  	 	 $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
4811  	 }
4812  
4813  	 /**
4814  	  * Puts a markup annotation on a rectangular area of the page.
4815  	  * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
4816  	  * @param float $x Abscissa of the upper-left corner of the rectangle
4817  	  * @param float $y Ordinate of the upper-left corner of the rectangle
4818  	  * @param float $w Width of the rectangle
4819  	  * @param float $h Height of the rectangle
4820  	  * @param string $text annotation text or alternate content
4821  	  * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
4822  	  * @param int $spaces number of spaces on the text to link
4823  	  * @public
4824  	  * @since 4.0.018 (2008-08-06)
4825  	  */
4826  	public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
4827  	 	 if ($this->inxobj) {
4828  	 	 	 // store parameters for later use on template
4829  	 	 	 $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
4830  	 	 	 return;
4831  	 	 }
4832  	 	 if ($x === '') {
4833  	 	 	 $x = $this->x;
4834  	 	 }
4835  	 	 if ($y === '') {
4836  	 	 	 $y = $this->y;
4837  	 	 }
4838  	 	 // check page for no-write regions and adapt page margins if necessary
4839  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
4840  	 	 // recalculate coordinates to account for graphic transformations
4841  	 	 if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
4842  	 	 	 for ($i=$this->transfmatrix_key; $i > 0; --$i) {
4843  	 	 	 	 $maxid = count($this->transfmatrix[$i]) - 1;
4844  	 	 	 	 for ($j=$maxid; $j >= 0; --$j) {
4845  	 	 	 	 	 $ctm = $this->transfmatrix[$i][$j];
4846  	 	 	 	 	 if (isset($ctm['a'])) {
4847  	 	 	 	 	 	 $x = $x * $this->k;
4848  	 	 	 	 	 	 $y = ($this->h - $y) * $this->k;
4849  	 	 	 	 	 	 $w = $w * $this->k;
4850  	 	 	 	 	 	 $h = $h * $this->k;
4851  	 	 	 	 	 	 // top left
4852  	 	 	 	 	 	 $xt = $x;
4853  	 	 	 	 	 	 $yt = $y;
4854  	 	 	 	 	 	 $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
4855  	 	 	 	 	 	 $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
4856  	 	 	 	 	 	 // top right
4857  	 	 	 	 	 	 $xt = $x + $w;
4858  	 	 	 	 	 	 $yt = $y;
4859  	 	 	 	 	 	 $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
4860  	 	 	 	 	 	 $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
4861  	 	 	 	 	 	 // bottom left
4862  	 	 	 	 	 	 $xt = $x;
4863  	 	 	 	 	 	 $yt = $y - $h;
4864  	 	 	 	 	 	 $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
4865  	 	 	 	 	 	 $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
4866  	 	 	 	 	 	 // bottom right
4867  	 	 	 	 	 	 $xt = $x + $w;
4868  	 	 	 	 	 	 $yt = $y - $h;
4869  	 	 	 	 	 	 $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
4870  	 	 	 	 	 	 $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
4871  	 	 	 	 	 	 // new coordinates (rectangle area)
4872  	 	 	 	 	 	 $x = min($x1, $x2, $x3, $x4);
4873  	 	 	 	 	 	 $y = max($y1, $y2, $y3, $y4);
4874  	 	 	 	 	 	 $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
4875  	 	 	 	 	 	 $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
4876  	 	 	 	 	 	 $x = $x / $this->k;
4877  	 	 	 	 	 	 $y = $this->h - ($y / $this->k);
4878  	 	 	 	 	 }
4879  	 	 	 	 }
4880  	 	 	 }
4881  	 	 }
4882  	 	 if ($this->page <= 0) {
4883  	 	 	 $page = 1;
4884  	 	 } else {
4885  	 	 	 $page = $this->page;
4886  	 	 }
4887  	 	 if (!isset($this->PageAnnots[$page])) {
4888  	 	 	 $this->PageAnnots[$page] = array();
4889  	 	 }
4890  	 	 $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
4891  	 	 if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) {
4892  	 	 	 if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
4893  	 	 	 	 AND (@TCPDF_STATIC::file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
4894  	 	 	 	 AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
4895  	 	 	 	 $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
4896  	 	 	 }
4897  	 	 }
4898  	 	 // Add widgets annotation's icons
4899  	 	 if (isset($opt['mk']['i']) AND @TCPDF_STATIC::file_exists($opt['mk']['i'])) {
4900  	 	 	 $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
4901  	 	 }
4902  	 	 if (isset($opt['mk']['ri']) AND @TCPDF_STATIC::file_exists($opt['mk']['ri'])) {
4903  	 	 	 $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
4904  	 	 }
4905  	 	 if (isset($opt['mk']['ix']) AND @TCPDF_STATIC::file_exists($opt['mk']['ix'])) {
4906  	 	 	 $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
4907  	 	 }
4908  	 }
4909  
4910  	 /**
4911  	  * Embedd the attached files.
4912  	  * @since 4.4.000 (2008-12-07)
4913  	  * @protected
4914  	  * @see Annotation()
4915  	  */
4916  	protected function _putEmbeddedFiles() {
4917  	 	 if ($this->pdfa_mode && $this->pdfa_version != 3)  {
4918  	 	 	 // embedded files are not allowed in PDF/A mode version 1 and 2
4919  	 	 	 return;
4920  	 	 }
4921  	 	 reset($this->embeddedfiles);
4922  	 	 foreach ($this->embeddedfiles as $filename => $filedata) {
4923  	 	     $data = $this->getCachedFileContents($filedata['file']);
4924  	 	 	 if ($data !== FALSE) {
4925  	 	 	 	 $rawsize = strlen($data);
4926  	 	 	 	 if ($rawsize > 0) {
4927  	 	 	 	 	 // update name tree
4928  	 	 	 	 	 $this->efnames[$filename] = $filedata['f'].' 0 R';
4929  	 	 	 	 	 // embedded file specification object
4930  	 	 	 	 	 $out = $this->_getobj($filedata['f'])."\n";
4931  	 	 	 	 	 $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']);
4932  	 	 	 	 	 $out .= ' /UF '.$this->_datastring($filename, $filedata['f']);
4933  	 	 	 	 	 $out .= ' /AFRelationship /Source';
4934  	 	 	 	 	 $out .= ' /EF <</F '.$filedata['n'].' 0 R>> >>';
4935  	 	 	 	 	 $out .= "\n".'endobj';
4936  	 	 	 	 	 $this->_out($out);
4937  	 	 	 	 	 // embedded file object
4938  	 	 	 	 	 $filter = '';
4939  	 	 	 	 	 if ($this->compress) {
4940  	 	 	 	 	 	 $data = gzcompress($data);
4941  	 	 	 	 	 	 $filter = ' /Filter /FlateDecode';
4942  	 	 	 	 	 }
4943  
4944  	 	 	 	 	 if ($this->pdfa_version == 3) {
4945  	 	 	 	 	 	 $filter = ' /Subtype /text#2Fxml';
4946  	 	 	 	 	 }
4947  
4948  	 	 	 	 	 $stream = $this->_getrawstream($data, $filedata['n']);
4949  	 	 	 	 	 $out = $this->_getobj($filedata['n'])."\n";
4950  	 	 	 	 	 $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
4951  	 	 	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
4952  	 	 	 	 	 $out .= "\n".'endobj';
4953  	 	 	 	 	 $this->_out($out);
4954  	 	 	 	 }
4955  	 	 	 }
4956  	 	 }
4957  	 }
4958  
4959  	 /**
4960  	  * Prints a text cell at the specified position.
4961  	  * This method allows to place a string precisely on the page.
4962  	  * @param float $x Abscissa of the cell origin
4963  	  * @param float $y Ordinate of the cell origin
4964  	  * @param string $txt String to print
4965  	  * @param int $fstroke outline size in user units (0 = disable)
4966  	  * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
4967  	  * @param boolean $ffill if true fills the text
4968  	  * @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)))
4969  	  * @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.
4970  	  * @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>
4971  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
4972  	  * @param mixed $link URL or identifier returned by AddLink().
4973  	  * @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.
4974  	  * @param boolean $ignore_min_height if true ignore automatic minimum height value.
4975  	  * @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>
4976  	  * @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>
4977  	  * @param boolean $rtloff if true uses the page top-left corner as origin of axis for $x and $y initial position.
4978  	  * @public
4979  	  * @since 1.0
4980  	  * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
4981  	  */
4982  	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) {
4983  	 	 $textrendermode = $this->textrendermode;
4984  	 	 $textstrokewidth = $this->textstrokewidth;
4985  	 	 $this->setTextRenderingMode($fstroke, $ffill, $fclip);
4986  	 	 $this->setXY($x, $y, $rtloff);
4987  	 	 $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
4988  	 	 // restore previous rendering mode
4989  	 	 $this->textrendermode = $textrendermode;
4990  	 	 $this->textstrokewidth = $textstrokewidth;
4991  	 }
4992  
4993  	 /**
4994  	  * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
4995  	  * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
4996  	  * This method is called automatically and should not be called directly by the application.
4997  	  * @return bool
4998  	  * @public
4999  	  * @since 1.4
5000  	  * @see SetAutoPageBreak()
5001  	  */
5002  	public function AcceptPageBreak() {
5003  	 	 if ($this->num_columns > 1) {
5004  	 	 	 // multi column mode
5005  	 	 	 if ($this->current_column < ($this->num_columns - 1)) {
5006  	 	 	 	 // go to next column
5007  	 	 	 	 $this->selectColumn($this->current_column + 1);
5008  	 	 	 } elseif ($this->AutoPageBreak) {
5009  	 	 	 	 // add a new page
5010  	 	 	 	 $this->AddPage();
5011  	 	 	 	 // set first column
5012  	 	 	 	 $this->selectColumn(0);
5013  	 	 	 }
5014  	 	 	 // avoid page breaking from checkPageBreak()
5015  	 	 	 return false;
5016  	 	 }
5017  	 	 return $this->AutoPageBreak;
5018  	 }
5019  
5020  	 /**
5021  	  * Add page if needed.
5022  	  * @param float $h Cell height. Default value: 0.
5023  	  * @param float|null $y starting y position, leave empty for current position.
5024  	  * @param bool  $addpage if true add a page, otherwise only return the true/false state
5025  	  * @return bool true in case of page break, false otherwise.
5026  	  * @since 3.2.000 (2008-07-01)
5027  	  * @protected
5028  	  */
5029  	protected function checkPageBreak($h=0, $y=null, $addpage=true) {
5030  	 	 if (TCPDF_STATIC::empty_string($y)) {
5031  	 	 	 $y = $this->y;
5032  	 	 }
5033  	 	 $current_page = $this->page;
5034  	 	 if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
5035  	 	 	 if ($addpage) {
5036  	 	 	 	 //Automatic page break
5037  	 	 	 	 $x = $this->x;
5038  	 	 	 	 $this->AddPage($this->CurOrientation);
5039  	 	 	 	 $this->y = $this->tMargin;
5040  	 	 	 	 $oldpage = $this->page - 1;
5041  	 	 	 	 if ($this->rtl) {
5042  	 	 	 	 	 if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
5043  	 	 	 	 	 	 $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
5044  	 	 	 	 	 } else {
5045  	 	 	 	 	 	 $this->x = $x;
5046  	 	 	 	 	 }
5047  	 	 	 	 } else {
5048  	 	 	 	 	 if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
5049  	 	 	 	 	 	 $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
5050  	 	 	 	 	 } else {
5051  	 	 	 	 	 	 $this->x = $x;
5052  	 	 	 	 	 }
5053  	 	 	 	 }
5054  	 	 	 }
5055  	 	 	 return true;
5056  	 	 }
5057  	 	 if ($current_page != $this->page) {
5058  	 	 	 // account for columns mode
5059  	 	 	 return true;
5060  	 	 }
5061  	 	 return false;
5062  	 }
5063  
5064  	 /**
5065  	  * 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 />
5066  	  * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
5067  	  * @param float $w Cell width. If 0, the cell extends up to the right margin.
5068  	  * @param float $h Cell height. Default value: 0.
5069  	  * @param string $txt String to print. Default value: empty string.
5070  	  * @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)))
5071  	  * @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.
5072  	  * @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>
5073  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
5074  	  * @param mixed $link URL or identifier returned by AddLink().
5075  	  * @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.
5076  	  * @param boolean $ignore_min_height if true ignore automatic minimum height value.
5077  	  * @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>
5078  	  * @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>
5079  	  * @public
5080  	  * @since 1.0
5081  	  * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
5082  	  */
5083  	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') {
5084  	 	 $prev_cell_margin = $this->cell_margin;
5085  	 	 $prev_cell_padding = $this->cell_padding;
5086  	 	 $this->adjustCellPadding($border);
5087  	 	 if (!$ignore_min_height) {
5088  	 	 	 $min_cell_height = $this->getCellHeight($this->FontSize);
5089  	 	 	 if ($h < $min_cell_height) {
5090  	 	 	 	 $h = $min_cell_height;
5091  	 	 	 }
5092  	 	 }
5093  	 	 $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
5094  	 	 // apply text shadow if enabled
5095  	 	 if ($this->txtshadow['enabled']) {
5096  	 	 	 // save data
5097  	 	 	 $x = $this->x;
5098  	 	 	 $y = $this->y;
5099  	 	 	 $bc = $this->bgcolor;
5100  	 	 	 $fc = $this->fgcolor;
5101  	 	 	 $sc = $this->strokecolor;
5102  	 	 	 $alpha = $this->alpha;
5103  	 	 	 // print shadow
5104  	 	 	 $this->x += $this->txtshadow['depth_w'];
5105  	 	 	 $this->y += $this->txtshadow['depth_h'];
5106  	 	 	 $this->setFillColorArray($this->txtshadow['color']);
5107  	 	 	 $this->setTextColorArray($this->txtshadow['color']);
5108  	 	 	 $this->setDrawColorArray($this->txtshadow['color']);
5109  	 	 	 if ($this->txtshadow['opacity'] != $alpha['CA']) {
5110  	 	 	 	 $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
5111  	 	 	 }
5112  	 	 	 if ($this->state == 2) {
5113  	 	 	 	 $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
5114  	 	 	 }
5115  	 	 	 //restore data
5116  	 	 	 $this->x = $x;
5117  	 	 	 $this->y = $y;
5118  	 	 	 $this->setFillColorArray($bc);
5119  	 	 	 $this->setTextColorArray($fc);
5120  	 	 	 $this->setDrawColorArray($sc);
5121  	 	 	 if ($this->txtshadow['opacity'] != $alpha['CA']) {
5122  	 	 	 	 $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
5123  	 	 	 }
5124  	 	 }
5125  	 	 if ($this->state == 2) {
5126  	 	 	 $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
5127  	 	 }
5128  	 	 $this->cell_padding = $prev_cell_padding;
5129  	 	 $this->cell_margin = $prev_cell_margin;
5130  	 }
5131  
5132  	 /**
5133  	  * 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 />
5134  	  * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
5135  	  * @param float $w Cell width. If 0, the cell extends up to the right margin.
5136  	  * @param float $h Cell height. Default value: 0.
5137  	  * @param string $txt String to print. Default value: empty string.
5138  	  * @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)))
5139  	  * @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.
5140  	  * @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>
5141  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
5142  	  * @param mixed $link URL or identifier returned by AddLink().
5143  	  * @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.
5144  	  * @param boolean $ignore_min_height if true ignore automatic minimum height value.
5145  	  * @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>
5146  	  * @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>
5147  	  * @return string containing cell code
5148  	  * @protected
5149  	  * @since 1.0
5150  	  * @see Cell()
5151  	  */
5152  	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') {
5153  	 	 // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
5154  	 	 $txt = is_null($txt) ? '' : $txt;
5155  	 	 $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
5156  	 	 $prev_cell_margin = $this->cell_margin;
5157  	 	 $prev_cell_padding = $this->cell_padding;
5158  	 	 $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
5159  	 	 $rs = ''; //string to be returned
5160  	 	 $this->adjustCellPadding($border);
5161  	 	 if (!$ignore_min_height) {
5162  	 	 	 $min_cell_height = $this->getCellHeight($this->FontSize);
5163  	 	 	 if ($h < $min_cell_height) {
5164  	 	 	 	 $h = $min_cell_height;
5165  	 	 	 }
5166  	 	 }
5167  	 	 $k = $this->k;
5168  	 	 // check page for no-write regions and adapt page margins if necessary
5169  	 	 list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
5170  	 	 if ($this->rtl) {
5171  	 	 	 $x = $this->x - $this->cell_margin['R'];
5172  	 	 } else {
5173  	 	 	 $x = $this->x + $this->cell_margin['L'];
5174  	 	 }
5175  	 	 $y = $this->y + $this->cell_margin['T'];
5176  	 	 $prev_font_stretching = $this->font_stretching;
5177  	 	 $prev_font_spacing = $this->font_spacing;
5178  	 	 // cell vertical alignment
5179  	 	 switch ($calign) {
5180  	 	 	 case 'A': {
5181  	 	 	 	 // font top
5182  	 	 	 	 switch ($valign) {
5183  	 	 	 	 	 case 'T': {
5184  	 	 	 	 	 	 // top
5185  	 	 	 	 	 	 $y -= $this->cell_padding['T'];
5186  	 	 	 	 	 	 break;
5187  	 	 	 	 	 }
5188  	 	 	 	 	 case 'B': {
5189  	 	 	 	 	 	 // bottom
5190  	 	 	 	 	 	 $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
5191  	 	 	 	 	 	 break;
5192  	 	 	 	 	 }
5193  	 	 	 	 	 default:
5194  	 	 	 	 	 case 'C':
5195  	 	 	 	 	 case 'M': {
5196  	 	 	 	 	 	 // center
5197  	 	 	 	 	 	 $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
5198  	 	 	 	 	 	 break;
5199  	 	 	 	 	 }
5200  	 	 	 	 }
5201  	 	 	 	 break;
5202  	 	 	 }
5203  	 	 	 case 'L': {
5204  	 	 	 	 // font baseline
5205  	 	 	 	 switch ($valign) {
5206  	 	 	 	 	 case 'T': {
5207  	 	 	 	 	 	 // top
5208  	 	 	 	 	 	 $y -= ($this->cell_padding['T'] + $this->FontAscent);
5209  	 	 	 	 	 	 break;
5210  	 	 	 	 	 }
5211  	 	 	 	 	 case 'B': {
5212  	 	 	 	 	 	 // bottom
5213  	 	 	 	 	 	 $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
5214  	 	 	 	 	 	 break;
5215  	 	 	 	 	 }
5216  	 	 	 	 	 default:
5217  	 	 	 	 	 case 'C':
5218  	 	 	 	 	 case 'M': {
5219  	 	 	 	 	 	 // center
5220  	 	 	 	 	 	 $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
5221  	 	 	 	 	 	 break;
5222  	 	 	 	 	 }
5223  	 	 	 	 }
5224  	 	 	 	 break;
5225  	 	 	 }
5226  	 	 	 case 'D': {
5227  	 	 	 	 // font bottom
5228  	 	 	 	 switch ($valign) {
5229  	 	 	 	 	 case 'T': {
5230  	 	 	 	 	 	 // top
5231  	 	 	 	 	 	 $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
5232  	 	 	 	 	 	 break;
5233  	 	 	 	 	 }
5234  	 	 	 	 	 case 'B': {
5235  	 	 	 	 	 	 // bottom
5236  	 	 	 	 	 	 $y -= ($h - $this->cell_padding['B']);
5237  	 	 	 	 	 	 break;
5238  	 	 	 	 	 }
5239  	 	 	 	 	 default:
5240  	 	 	 	 	 case 'C':
5241  	 	 	 	 	 case 'M': {
5242  	 	 	 	 	 	 // center
5243  	 	 	 	 	 	 $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
5244  	 	 	 	 	 	 break;
5245  	 	 	 	 	 }
5246  	 	 	 	 }
5247  	 	 	 	 break;
5248  	 	 	 }
5249  	 	 	 case 'B': {
5250  	 	 	 	 // cell bottom
5251  	 	 	 	 $y -= $h;
5252  	 	 	 	 break;
5253  	 	 	 }
5254  	 	 	 case 'C':
5255  	 	 	 case 'M': {
5256  	 	 	 	 // cell center
5257  	 	 	 	 $y -= ($h / 2);
5258  	 	 	 	 break;
5259  	 	 	 }
5260  	 	 	 default:
5261  	 	 	 case 'T': {
5262  	 	 	 	 // cell top
5263  	 	 	 	 break;
5264  	 	 	 }
5265  	 	 }
5266  	 	 // text vertical alignment
5267  	 	 switch ($valign) {
5268  	 	 	 case 'T': {
5269  	 	 	 	 // top
5270  	 	 	 	 $yt = $y + $this->cell_padding['T'];
5271  	 	 	 	 break;
5272  	 	 	 }
5273  	 	 	 case 'B': {
5274  	 	 	 	 // bottom
5275  	 	 	 	 $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
5276  	 	 	 	 break;
5277  	 	 	 }
5278  	 	 	 default:
5279  	 	 	 case 'C':
5280  	 	 	 case 'M': {
5281  	 	 	 	 // center
5282  	 	 	 	 $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
5283  	 	 	 	 break;
5284  	 	 	 }
5285  	 	 }
5286  	 	 $basefonty = $yt + $this->FontAscent;
5287  	 	 if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
5288  	 	 	 if ($this->rtl) {
5289  	 	 	 	 $w = $x - $this->lMargin;
5290  	 	 	 } else {
5291  	 	 	 	 $w = $this->w - $this->rMargin - $x;
5292  	 	 	 }
5293  	 	 }
5294  	 	 $s = '';
5295  	 	 // fill and borders
5296  	 	 if (is_string($border) AND (strlen($border) == 4)) {
5297  	 	 	 // full border
5298  	 	 	 $border = 1;
5299  	 	 }
5300  	 	 if ($fill OR ($border == 1)) {
5301  	 	 	 if ($fill) {
5302  	 	 	 	 $op = ($border == 1) ? 'B' : 'f';
5303  	 	 	 } else {
5304  	 	 	 	 $op = 'S';
5305  	 	 	 }
5306  	 	 	 if ($this->rtl) {
5307  	 	 	 	 $xk = (($x - $w) * $k);
5308  	 	 	 } else {
5309  	 	 	 	 $xk = ($x * $k);
5310  	 	 	 }
5311  	 	 	 $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
5312  	 	 }
5313  	 	 // draw borders
5314  	 	 $s .= $this->getCellBorder($x, $y, $w, $h, $border);
5315  	 	 if ($txt != '') {
5316  	 	 	 $txt2 = $txt;
5317  	 	 	 if ($this->isunicode) {
5318  	 	 	 	 if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
5319  	 	 	 	 	 $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
5320  	 	 	 	 } else {
5321  	 	 	 	 	 $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
5322  	 	 	 	 	 $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
5323  	 	 	 	 	 // replace thai chars (if any)
5324  	 	 	 	 	 if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
5325  	 	 	 	 	 	 // number of chars
5326  	 	 	 	 	 	 $numchars = count($unicode);
5327  	 	 	 	 	 	 // po pla, for far, for fan
5328  	 	 	 	 	 	 $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
5329  	 	 	 	 	 	 // do chada, to patak
5330  	 	 	 	 	 	 $lowtail = array(0x0e0e, 0x0e0f);
5331  	 	 	 	 	 	 // mai hun arkad, sara i, sara ii, sara ue, sara uee
5332  	 	 	 	 	 	 $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
5333  	 	 	 	 	 	 // mai ek, mai tho, mai tri, mai chattawa, karan
5334  	 	 	 	 	 	 $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
5335  	 	 	 	 	 	 // sara u, sara uu, pinthu
5336  	 	 	 	 	 	 $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
5337  	 	 	 	 	 	 $output = array();
5338  	 	 	 	 	 	 for ($i = 0; $i < $numchars; $i++) {
5339  	 	 	 	 	 	 	 if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
5340  	 	 	 	 	 	 	 	 $ch0 = $unicode[$i];
5341  	 	 	 	 	 	 	 	 $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
5342  	 	 	 	 	 	 	 	 $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
5343  	 	 	 	 	 	 	 	 $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
5344  	 	 	 	 	 	 	 	 if (in_array($ch0, $tonemark)) {
5345  	 	 	 	 	 	 	 	 	 if ($chn == 0x0e33) {
5346  	 	 	 	 	 	 	 	 	 	 // sara um
5347  	 	 	 	 	 	 	 	 	 	 if (in_array($ch1, $longtail)) {
5348  	 	 	 	 	 	 	 	 	 	 	 // tonemark at upper left
5349  	 	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
5350  	 	 	 	 	 	 	 	 	 	 } else {
5351  	 	 	 	 	 	 	 	 	 	 	 // tonemark at upper right (normal position)
5352  	 	 	 	 	 	 	 	 	 	 	 $output[] = $ch0;
5353  	 	 	 	 	 	 	 	 	 	 }
5354  	 	 	 	 	 	 	 	 	 } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
5355  	 	 	 	 	 	 	 	 	 	 // tonemark at lower left
5356  	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
5357  	 	 	 	 	 	 	 	 	 } elseif (in_array($ch1, $upvowel)) {
5358  	 	 	 	 	 	 	 	 	 	 if (in_array($ch2, $longtail)) {
5359  	 	 	 	 	 	 	 	 	 	 	 // tonemark at upper left
5360  	 	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
5361  	 	 	 	 	 	 	 	 	 	 } else {
5362  	 	 	 	 	 	 	 	 	 	 	 // tonemark at upper right (normal position)
5363  	 	 	 	 	 	 	 	 	 	 	 $output[] = $ch0;
5364  	 	 	 	 	 	 	 	 	 	 }
5365  	 	 	 	 	 	 	 	 	 } else {
5366  	 	 	 	 	 	 	 	 	 	 // tonemark at lower right
5367  	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
5368  	 	 	 	 	 	 	 	 	 }
5369  	 	 	 	 	 	 	 	 } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
5370  	 	 	 	 	 	 	 	 	 // add lower left nikhahit and sara aa
5371  	 	 	 	 	 	 	 	 	 if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
5372  	 	 	 	 	 	 	 	 	 	 $output[] = 0xf711;
5373  	 	 	 	 	 	 	 	 	 	 $this->CurrentFont['subsetchars'][0xf711] = true;
5374  	 	 	 	 	 	 	 	 	 	 $output[] = 0x0e32;
5375  	 	 	 	 	 	 	 	 	 	 $this->CurrentFont['subsetchars'][0x0e32] = true;
5376  	 	 	 	 	 	 	 	 	 } else {
5377  	 	 	 	 	 	 	 	 	 	 $output[] = $ch0;
5378  	 	 	 	 	 	 	 	 	 }
5379  	 	 	 	 	 	 	 	 } elseif (in_array($ch1, $longtail)) {
5380  	 	 	 	 	 	 	 	 	 if ($ch0 == 0x0e31) {
5381  	 	 	 	 	 	 	 	 	 	 // lower left mai hun arkad
5382  	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, 0xf710);
5383  	 	 	 	 	 	 	 	 	 } elseif (in_array($ch0, $upvowel)) {
5384  	 	 	 	 	 	 	 	 	 	 // lower left
5385  	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
5386  	 	 	 	 	 	 	 	 	 } elseif ($ch0 == 0x0e47) {
5387  	 	 	 	 	 	 	 	 	 	 // lower left mai tai koo
5388  	 	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, 0xf712);
5389  	 	 	 	 	 	 	 	 	 } else {
5390  	 	 	 	 	 	 	 	 	 	 // normal character
5391  	 	 	 	 	 	 	 	 	 	 $output[] = $ch0;
5392  	 	 	 	 	 	 	 	 	 }
5393  	 	 	 	 	 	 	 	 } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
5394  	 	 	 	 	 	 	 	 	 // lower vowel
5395  	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
5396  	 	 	 	 	 	 	 	 } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
5397  	 	 	 	 	 	 	 	 	 // yo ying without lower part
5398  	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, 0xf70f);
5399  	 	 	 	 	 	 	 	 } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
5400  	 	 	 	 	 	 	 	 	 // tho santan without lower part
5401  	 	 	 	 	 	 	 	 	 $output[] = $this->replaceChar($ch0, 0xf700);
5402  	 	 	 	 	 	 	 	 } else {
5403  	 	 	 	 	 	 	 	 	 $output[] = $ch0;
5404  	 	 	 	 	 	 	 	 }
5405  	 	 	 	 	 	 	 } else {
5406  	 	 	 	 	 	 	 	 // non-thai character
5407  	 	 	 	 	 	 	 	 $output[] = $unicode[$i];
5408  	 	 	 	 	 	 	 }
5409  	 	 	 	 	 	 }
5410  	 	 	 	 	 	 $unicode = $output;
5411  	 	 	 	 	 	 // update font subsetchars
5412  	 	 	 	 	 	 $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
5413  	 	 	 	 	 } // end of K_THAI_TOPCHARS
5414  	 	 	 	 	 $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
5415  	 	 	 	 }
5416  	 	 	 }
5417  	 	 	 $txt2 = TCPDF_STATIC::_escape($txt2);
5418  	 	 	 // get current text width (considering general font stretching and spacing)
5419  	 	 	 $txwidth = $this->GetStringWidth($txt);
5420  	 	 	 $width = $txwidth;
5421  	 	 	 // check for stretch mode
5422  	 	 	 if ($stretch > 0) {
5423  	 	 	 	 // calculate ratio between cell width and text width
5424  	 	 	 	 if ($width <= 0) {
5425  	 	 	 	 	 $ratio = 1;
5426  	 	 	 	 } else {
5427  	 	 	 	 	 $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
5428  	 	 	 	 }
5429  	 	 	 	 // check if stretching is required
5430  	 	 	 	 if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
5431  	 	 	 	 	 // the text will be stretched to fit cell width
5432  	 	 	 	 	 if ($stretch > 2) {
5433  	 	 	 	 	 	 // set new character spacing
5434  	 	 	 	 	 	 $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
5435  	 	 	 	 	 } else {
5436  	 	 	 	 	 	 // set new horizontal stretching
5437  	 	 	 	 	 	 $this->font_stretching *= $ratio;
5438  	 	 	 	 	 }
5439  	 	 	 	 	 // recalculate text width (the text fills the entire cell)
5440  	 	 	 	 	 $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
5441  	 	 	 	 	 // reset alignment
5442  	 	 	 	 	 $align = '';
5443  	 	 	 	 }
5444  	 	 	 }
5445  	 	 	 if ($this->font_stretching != 100) {
5446  	 	 	 	 // apply font stretching
5447  	 	 	 	 $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
5448  	 	 	 }
5449  	 	 	 if ($this->font_spacing != 0) {
5450  	 	 	 	 // increase/decrease font spacing
5451  	 	 	 	 $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
5452  	 	 	 }
5453  	 	 	 if ($this->ColorFlag AND ($this->textrendermode < 4)) {
5454  	 	 	 	 $s .= 'q '.$this->TextColor.' ';
5455  	 	 	 }
5456  	 	 	 // rendering mode
5457  	 	 	 $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
5458  	 	 	 // count number of spaces
5459  	 	 	 $ns = substr_count($txt, chr(32));
5460  	 	 	 // Justification
5461  	 	 	 $spacewidth = 0;
5462  	 	 	 if (($align == 'J') AND ($ns > 0)) {
5463  	 	 	 	 if ($this->isUnicodeFont()) {
5464  	 	 	 	 	 // get string width without spaces
5465  	 	 	 	 	 $width = $this->GetStringWidth(str_replace(' ', '', $txt));
5466  	 	 	 	 	 // calculate average space width
5467  	 	 	 	 	 $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
5468  	 	 	 	 	 if ($this->font_stretching != 100) {
5469  	 	 	 	 	 	 // word spacing is affected by stretching
5470  	 	 	 	 	 	 $spacewidth /= ($this->font_stretching / 100);
5471  	 	 	 	 	 }
5472  	 	 	 	 	 // set word position to be used with TJ operator
5473  	 	 	 	 	 $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
5474  	 	 	 	 	 $unicode_justification = true;
5475  	 	 	 	 } else {
5476  	 	 	 	 	 // get string width
5477  	 	 	 	 	 $width = $txwidth;
5478  	 	 	 	 	 // new space width
5479  	 	 	 	 	 $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
5480  	 	 	 	 	 if ($this->font_stretching != 100) {
5481  	 	 	 	 	 	 // word spacing (Tw) is affected by stretching
5482  	 	 	 	 	 	 $spacewidth /= ($this->font_stretching / 100);
5483  	 	 	 	 	 }
5484  	 	 	 	 	 // set word spacing
5485  	 	 	 	 	 $rs .= sprintf('BT %F Tw ET ', $spacewidth);
5486  	 	 	 	 }
5487  	 	 	 	 $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
5488  	 	 	 }
5489  	 	 	 // replace carriage return characters
5490  	 	 	 $txt2 = str_replace("\r", ' ', $txt2);
5491  	 	 	 switch ($align) {
5492  	 	 	 	 case 'C': {
5493  	 	 	 	 	 $dx = ($w - $width) / 2;
5494  	 	 	 	 	 break;
5495  	 	 	 	 }
5496  	 	 	 	 case 'R': {
5497  	 	 	 	 	 if ($this->rtl) {
5498  	 	 	 	 	 	 $dx = $this->cell_padding['R'];
5499  	 	 	 	 	 } else {
5500  	 	 	 	 	 	 $dx = $w - $width - $this->cell_padding['R'];
5501  	 	 	 	 	 }
5502  	 	 	 	 	 break;
5503  	 	 	 	 }
5504  	 	 	 	 case 'L': {
5505  	 	 	 	 	 if ($this->rtl) {
5506  	 	 	 	 	 	 $dx = $w - $width - $this->cell_padding['L'];
5507  	 	 	 	 	 } else {
5508  	 	 	 	 	 	 $dx = $this->cell_padding['L'];
5509  	 	 	 	 	 }
5510  	 	 	 	 	 break;
5511  	 	 	 	 }
5512  	 	 	 	 case 'J':
5513  	 	 	 	 default: {
5514  	 	 	 	 	 if ($this->rtl) {
5515  	 	 	 	 	 	 $dx = $this->cell_padding['R'];
5516  	 	 	 	 	 } else {
5517  	 	 	 	 	 	 $dx = $this->cell_padding['L'];
5518  	 	 	 	 	 }
5519  	 	 	 	 	 break;
5520  	 	 	 	 }
5521  	 	 	 }
5522  	 	 	 if ($this->rtl) {
5523  	 	 	 	 $xdx = $x - $dx - $width;
5524  	 	 	 } else {
5525  	 	 	 	 $xdx = $x + $dx;
5526  	 	 	 }
5527  	 	 	 $xdk = $xdx * $k;
5528  	 	 	 // print text
5529  	 	 	 $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
5530  	 	 	 if (isset($uniblock)) {
5531  	 	 	 	 // print overlapping characters as separate string
5532  	 	 	 	 $xshift = 0; // horizontal shift
5533  	 	 	 	 $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
5534  	 	 	 	 $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
5535  	 	 	 	 foreach ($uniblock as $uk => $uniarr) {
5536  	 	 	 	 	 if (($uk % 2) == 0) {
5537  	 	 	 	 	 	 // x space to skip
5538  	 	 	 	 	 	 if ($spacewidth != 0) {
5539  	 	 	 	 	 	 	 // justification shift
5540  	 	 	 	 	 	 	 $xshift += (count(array_keys($uniarr, 32)) * $spw);
5541  	 	 	 	 	 	 }
5542  	 	 	 	 	 	 $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
5543  	 	 	 	 	 } else {
5544  	 	 	 	 	 	 // character to print
5545  	 	 	 	 	 	 $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
5546  	 	 	 	 	 	 $topchr = TCPDF_STATIC::_escape($topchr);
5547  	 	 	 	 	 	 $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
5548  	 	 	 	 	 }
5549  	 	 	 	 }
5550  	 	 	 }
5551  	 	 	 if ($this->underline) {
5552  	 	 	 	 $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
5553  	 	 	 }
5554  	 	 	 if ($this->linethrough) {
5555  	 	 	 	 $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
5556  	 	 	 }
5557  	 	 	 if ($this->overline) {
5558  	 	 	 	 $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
5559  	 	 	 }
5560  	 	 	 if ($this->ColorFlag AND ($this->textrendermode < 4)) {
5561  	 	 	 	 $s .= ' Q';
5562  	 	 	 }
5563  	 	 	 if ($link) {
5564  	 	 	 	 $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
5565  	 	 	 }
5566  	 	 }
5567  	 	 // output cell
5568  	 	 if ($s) {
5569  	 	 	 // output cell
5570  	 	 	 $rs .= $s;
5571  	 	 	 if ($this->font_spacing != 0) {
5572  	 	 	 	 // reset font spacing mode
5573  	 	 	 	 $rs .= ' BT 0 Tc ET';
5574  	 	 	 }
5575  	 	 	 if ($this->font_stretching != 100) {
5576  	 	 	 	 // reset font stretching mode
5577  	 	 	 	 $rs .= ' BT 100 Tz ET';
5578  	 	 	 }
5579  	 	 }
5580  	 	 // reset word spacing
5581  	 	 if (!$this->isUnicodeFont() AND ($align == 'J')) {
5582  	 	 	 $rs .= ' BT 0 Tw ET';
5583  	 	 }
5584  	 	 // reset stretching and spacing
5585  	 	 $this->font_stretching = $prev_font_stretching;
5586  	 	 $this->font_spacing = $prev_font_spacing;
5587  	 	 $this->lasth = $h;
5588  	 	 if ($ln > 0) {
5589  	 	 	 //Go to the beginning of the next line
5590  	 	 	 $this->y = $y + $h + $this->cell_margin['B'];
5591  	 	 	 if ($ln == 1) {
5592  	 	 	 	 if ($this->rtl) {
5593  	 	 	 	 	 $this->x = $this->w - $this->rMargin;
5594  	 	 	 	 } else {
5595  	 	 	 	 	 $this->x = $this->lMargin;
5596  	 	 	 	 }
5597  	 	 	 }
5598  	 	 } else {
5599  	 	 	 // go left or right by case
5600  	 	 	 if ($this->rtl) {
5601  	 	 	 	 $this->x = $x - $w - $this->cell_margin['L'];
5602  	 	 	 } else {
5603  	 	 	 	 $this->x = $x + $w + $this->cell_margin['R'];
5604  	 	 	 }
5605  	 	 }
5606  	 	 $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
5607  	 	 $rs = $gstyles.$rs;
5608  	 	 $this->cell_padding = $prev_cell_padding;
5609  	 	 $this->cell_margin = $prev_cell_margin;
5610  	 	 return $rs;
5611  	 }
5612  
5613  	 /**
5614  	  * Replace a char if is defined on the current font.
5615  	  * @param int $oldchar Integer code (unicode) of the character to replace.
5616  	  * @param int $newchar Integer code (unicode) of the new character.
5617  	  * @return int the replaced char or the old char in case the new char i not defined
5618  	  * @protected
5619  	  * @since 5.9.167 (2012-06-22)
5620  	  */
5621  	protected function replaceChar($oldchar, $newchar) {
5622  	 	 if ($this->isCharDefined($newchar)) {
5623  	 	 	 // add the new char on the subset list
5624  	 	 	 $this->CurrentFont['subsetchars'][$newchar] = true;
5625  	 	 	 // return the new character
5626  	 	 	 return $newchar;
5627  	 	 }
5628  	 	 // return the old char
5629  	 	 return $oldchar;
5630  	 }
5631  
5632  	 /**
5633  	  * Returns the code to draw the cell border
5634  	  * @param float $x X coordinate.
5635  	  * @param float $y Y coordinate.
5636  	  * @param float $w Cell width.
5637  	  * @param float $h Cell height.
5638  	  * @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)))
5639  	  * @return string containing cell border code
5640  	  * @protected
5641  	  * @see SetLineStyle()
5642  	  * @since 5.7.000 (2010-08-02)
5643  	  */
5644  	protected function getCellBorder($x, $y, $w, $h, $brd) {
5645  	 	 $s = ''; // string to be returned
5646  	 	 if (empty($brd)) {
5647  	 	 	 return $s;
5648  	 	 }
5649  	 	 if ($brd == 1) {
5650  	 	 	 $brd = array('LRTB' => true);
5651  	 	 }
5652  	 	 // calculate coordinates for border
5653  	 	 $k = $this->k;
5654  	 	 if ($this->rtl) {
5655  	 	 	 $xeL = ($x - $w) * $k;
5656  	 	 	 $xeR = $x * $k;
5657  	 	 } else {
5658  	 	 	 $xeL = $x * $k;
5659  	 	 	 $xeR = ($x + $w) * $k;
5660  	 	 }
5661  	 	 $yeL = (($this->h - ($y + $h)) * $k);
5662  	 	 $yeT = (($this->h - $y) * $k);
5663  	 	 $xeT = $xeL;
5664  	 	 $xeB = $xeR;
5665  	 	 $yeR = $yeT;
5666  	 	 $yeB = $yeL;
5667  	 	 if (is_string($brd)) {
5668  	 	 	 // convert string to array
5669  	 	 	 $slen = strlen($brd);
5670  	 	 	 $newbrd = array();
5671  	 	 	 for ($i = 0; $i < $slen; ++$i) {
5672  	 	 	 	 $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
5673  	 	 	 }
5674  	 	 	 $brd = $newbrd;
5675  	 	 }
5676  	 	 if (isset($brd['mode'])) {
5677  	 	 	 $mode = $brd['mode'];
5678  	 	 	 unset($brd['mode']);
5679  	 	 } else {
5680  	 	 	 $mode = 'normal';
5681  	 	 }
5682  	 	 foreach ($brd as $border => $style) {
5683  	 	 	 if (is_array($style) AND !empty($style)) {
5684  	 	 	 	 // apply border style
5685  	 	 	 	 $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
5686  	 	 	 	 $s .= $this->setLineStyle($style, true)."\n";
5687  	 	 	 }
5688  	 	 	 switch ($mode) {
5689  	 	 	 	 case 'ext': {
5690  	 	 	 	 	 $off = (($this->LineWidth / 2) * $k);
5691  	 	 	 	 	 $xL = $xeL - $off;
5692  	 	 	 	 	 $xR = $xeR + $off;
5693  	 	 	 	 	 $yT = $yeT + $off;
5694  	 	 	 	 	 $yL = $yeL - $off;
5695  	 	 	 	 	 $xT = $xL;
5696  	 	 	 	 	 $xB = $xR;
5697  	 	 	 	 	 $yR = $yT;
5698  	 	 	 	 	 $yB = $yL;
5699  	 	 	 	 	 $w += $this->LineWidth;
5700  	 	 	 	 	 $h += $this->LineWidth;
5701  	 	 	 	 	 break;
5702  	 	 	 	 }
5703  	 	 	 	 case 'int': {
5704  	 	 	 	 	 $off = ($this->LineWidth / 2) * $k;
5705  	 	 	 	 	 $xL = $xeL + $off;
5706  	 	 	 	 	 $xR = $xeR - $off;
5707  	 	 	 	 	 $yT = $yeT - $off;
5708  	 	 	 	 	 $yL = $yeL + $off;
5709  	 	 	 	 	 $xT = $xL;
5710  	 	 	 	 	 $xB = $xR;
5711  	 	 	 	 	 $yR = $yT;
5712  	 	 	 	 	 $yB = $yL;
5713  	 	 	 	 	 $w -= $this->LineWidth;
5714  	 	 	 	 	 $h -= $this->LineWidth;
5715  	 	 	 	 	 break;
5716  	 	 	 	 }
5717  	 	 	 	 case 'normal':
5718  	 	 	 	 default: {
5719  	 	 	 	 	 $xL = $xeL;
5720  	 	 	 	 	 $xT = $xeT;
5721  	 	 	 	 	 $xB = $xeB;
5722  	 	 	 	 	 $xR = $xeR;
5723  	 	 	 	 	 $yL = $yeL;
5724  	 	 	 	 	 $yT = $yeT;
5725  	 	 	 	 	 $yB = $yeB;
5726  	 	 	 	 	 $yR = $yeR;
5727  	 	 	 	 	 break;
5728  	 	 	 	 }
5729  	 	 	 }
5730  	 	 	 // draw borders by case
5731  	 	 	 if (strlen($border) == 4) {
5732  	 	 	 	 $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
5733  	 	 	 } elseif (strlen($border) == 3) {
5734  	 	 	 	 if (strpos($border,'B') === false) { // LTR
5735  	 	 	 	 	 $s .= sprintf('%F %F m ', $xL, $yL);
5736  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5737  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5738  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5739  	 	 	 	 	 $s .= 'S ';
5740  	 	 	 	 } elseif (strpos($border,'L') === false) { // TRB
5741  	 	 	 	 	 $s .= sprintf('%F %F m ', $xT, $yT);
5742  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5743  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5744  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5745  	 	 	 	 	 $s .= 'S ';
5746  	 	 	 	 } elseif (strpos($border,'T') === false) { // RBL
5747  	 	 	 	 	 $s .= sprintf('%F %F m ', $xR, $yR);
5748  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5749  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5750  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5751  	 	 	 	 	 $s .= 'S ';
5752  	 	 	 	 } elseif (strpos($border,'R') === false) { // BLT
5753  	 	 	 	 	 $s .= sprintf('%F %F m ', $xB, $yB);
5754  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5755  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5756  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5757  	 	 	 	 	 $s .= 'S ';
5758  	 	 	 	 }
5759  	 	 	 } elseif (strlen($border) == 2) {
5760  	 	 	 	 if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
5761  	 	 	 	 	 $s .= sprintf('%F %F m ', $xL, $yL);
5762  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5763  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5764  	 	 	 	 	 $s .= 'S ';
5765  	 	 	 	 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
5766  	 	 	 	 	 $s .= sprintf('%F %F m ', $xT, $yT);
5767  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5768  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5769  	 	 	 	 	 $s .= 'S ';
5770  	 	 	 	 } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
5771  	 	 	 	 	 $s .= sprintf('%F %F m ', $xR, $yR);
5772  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5773  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5774  	 	 	 	 	 $s .= 'S ';
5775  	 	 	 	 } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
5776  	 	 	 	 	 $s .= sprintf('%F %F m ', $xB, $yB);
5777  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5778  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5779  	 	 	 	 	 $s .= 'S ';
5780  	 	 	 	 } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
5781  	 	 	 	 	 $s .= sprintf('%F %F m ', $xL, $yL);
5782  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5783  	 	 	 	 	 $s .= 'S ';
5784  	 	 	 	 	 $s .= sprintf('%F %F m ', $xR, $yR);
5785  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5786  	 	 	 	 	 $s .= 'S ';
5787  	 	 	 	 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
5788  	 	 	 	 	 $s .= sprintf('%F %F m ', $xT, $yT);
5789  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5790  	 	 	 	 	 $s .= 'S ';
5791  	 	 	 	 	 $s .= sprintf('%F %F m ', $xB, $yB);
5792  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5793  	 	 	 	 	 $s .= 'S ';
5794  	 	 	 	 }
5795  	 	 	 } else { // strlen($border) == 1
5796  	 	 	 	 if (strpos($border,'L') !== false) { // L
5797  	 	 	 	 	 $s .= sprintf('%F %F m ', $xL, $yL);
5798  	 	 	 	 	 $s .= sprintf('%F %F l ', $xT, $yT);
5799  	 	 	 	 	 $s .= 'S ';
5800  	 	 	 	 } elseif (strpos($border,'T') !== false) { // T
5801  	 	 	 	 	 $s .= sprintf('%F %F m ', $xT, $yT);
5802  	 	 	 	 	 $s .= sprintf('%F %F l ', $xR, $yR);
5803  	 	 	 	 	 $s .= 'S ';
5804  	 	 	 	 } elseif (strpos($border,'R') !== false) { // R
5805  	 	 	 	 	 $s .= sprintf('%F %F m ', $xR, $yR);
5806  	 	 	 	 	 $s .= sprintf('%F %F l ', $xB, $yB);
5807  	 	 	 	 	 $s .= 'S ';
5808  	 	 	 	 } elseif (strpos($border,'B') !== false) { // B
5809  	 	 	 	 	 $s .= sprintf('%F %F m ', $xB, $yB);
5810  	 	 	 	 	 $s .= sprintf('%F %F l ', $xL, $yL);
5811  	 	 	 	 	 $s .= 'S ';
5812  	 	 	 	 }
5813  	 	 	 }
5814  	 	 	 if (is_array($style) AND !empty($style)) {
5815  	 	 	 	 // reset border style to previous value
5816  	 	 	 	 $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
5817  	 	 	 }
5818  	 	 }
5819  	 	 return $s;
5820  	 }
5821  
5822  	 /**
5823  	  * This method allows printing text with line breaks.
5824  	  * 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 />
5825  	  * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
5826  	  * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
5827  	  * @param float $h Cell minimum height. The cell extends automatically if needed.
5828  	  * @param string $txt String to print
5829  	  * @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)))
5830  	  * @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>
5831  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
5832  	  * @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>
5833  	  * @param float|null $x x position in user units
5834  	  * @param float|null $y y position in user units
5835  	  * @param boolean $reseth if true reset the last cell height (default true).
5836  	  * @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.
5837  	  * @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.
5838  	  * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
5839  	  * @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.
5840  	  * @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.
5841  	  * @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.
5842  	  * @return int Return the number of cells or 1 for html mode.
5843  	  * @public
5844  	  * @since 1.3
5845  	  * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
5846  	  */
5847  	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) {
5848  	 	 $prev_cell_margin = $this->cell_margin;
5849  	 	 $prev_cell_padding = $this->cell_padding;
5850  	 	 // adjust internal padding
5851  	 	 $this->adjustCellPadding($border);
5852  	 	 $mc_padding = $this->cell_padding;
5853  	 	 $mc_margin = $this->cell_margin;
5854  	 	 $this->cell_padding['T'] = 0;
5855  	 	 $this->cell_padding['B'] = 0;
5856  	 	 $this->setCellMargins(0, 0, 0, 0);
5857  	 	 if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
5858  	 	 	 // reset row height
5859  	 	 	 $this->resetLastH();
5860  	 	 }
5861  	 	 if (!TCPDF_STATIC::empty_string($y)) {
5862  	 	 	 $this->setY($y); // set y in order to convert negative y values to positive ones
5863  	 	 }
5864  	 	 $y = $this->GetY();
5865  	 	 $resth = 0;
5866  	 	 if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
5867  	 	 	 // spit cell in more pages/columns
5868  	 	 	 $newh = ($this->PageBreakTrigger - $y);
5869  	 	 	 $resth = ($h - $newh); // cell to be printed on the next page/column
5870  	 	 	 $h = $newh;
5871  	 	 }
5872  	 	 // get current page number
5873  	 	 $startpage = $this->page;
5874  	 	 // get current column
5875  	 	 $startcolumn = $this->current_column;
5876  	 	 if (!TCPDF_STATIC::empty_string($x)) {
5877  	 	 	 $this->setX($x);
5878  	 	 } else {
5879  	 	 	 $x = $this->GetX();
5880  	 	 }
5881  	 	 // check page for no-write regions and adapt page margins if necessary
5882  	 	 list($x, $y) = $this->checkPageRegions(0, $x, $y);
5883  	 	 // apply margins
5884  	 	 $oy = $y + $mc_margin['T'];
5885  	 	 if ($this->rtl) {
5886  	 	 	 $ox = ($this->w - $x - $mc_margin['R']);
5887  	 	 } else {
5888  	 	 	 $ox = ($x + $mc_margin['L']);
5889  	 	 }
5890  	 	 $this->x = $ox;
5891  	 	 $this->y = $oy;
5892  	 	 // set width
5893  	 	 if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
5894  	 	 	 if ($this->rtl) {
5895  	 	 	 	 $w = ($this->x - $this->lMargin - $mc_margin['L']);
5896  	 	 	 } else {
5897  	 	 	 	 $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
5898  	 	 	 }
5899  	 	 }
5900  	 	 // store original margin values
5901  	 	 $lMargin = $this->lMargin;
5902  	 	 $rMargin = $this->rMargin;
5903  	 	 if ($this->rtl) {
5904  	 	 	 $this->rMargin = ($this->w - $this->x);
5905  	 	 	 $this->lMargin = ($this->x - $w);
5906  	 	 } else {
5907  	 	 	 $this->lMargin = ($this->x);
5908  	 	 	 $this->rMargin = ($this->w - $this->x - $w);
5909  	 	 }
5910  	 	 $this->clMargin = $this->lMargin;
5911  	 	 $this->crMargin = $this->rMargin;
5912  	 	 if ($autopadding) {
5913  	 	 	 // add top padding
5914  	 	 	 $this->y += $mc_padding['T'];
5915  	 	 }
5916  	 	 if ($ishtml) { // ******* Write HTML text
5917  	 	 	 $this->writeHTML($txt, true, false, $reseth, true, $align);
5918  	 	 	 $nl = 1;
5919  	 	 } else { // ******* Write simple text
5920  	 	 	 $prev_FontSizePt = $this->FontSizePt;
5921  	 	 	 if ($fitcell) {
5922  	 	 	 	 // ajust height values
5923  	 	 	 	 $tobottom = ($this->h - $this->y - $this->bMargin - $this->cell_padding['T'] - $this->cell_padding['B']);
5924  	 	 	 	 $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom));
5925  	 	 	 }
5926  	 	 	 // vertical alignment
5927  	 	 	 if ($maxh > 0) {
5928  	 	 	 	 // get text height
5929  	 	 	 	 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
5930  	 	 	 	 if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt > 1)) {
5931  	 	 	 	 	 // try to reduce font size to fit text on cell (use a quick search algorithm)
5932  	 	 	 	 	 $fmin = 1;
5933  	 	 	 	 	 $fmax = $this->FontSizePt;
5934  	 	 	 	 	 $diff_epsilon = (1 / $this->k); // one point (min resolution)
5935  	 	 	 	 	 $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations
5936  	 	 	 	 	 while ($maxit >= 0) {
5937  	 	 	 	 	 	 $fmid = (($fmax + $fmin) / 2);
5938  	 	 	 	 	 	 $this->setFontSize($fmid, false);
5939  	 	 	 	 	 	 $this->resetLastH();
5940  	 	 	 	 	 	 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
5941  	 	 	 	 	 	 $diff = ($maxh - $text_height);
5942  	 	 	 	 	 	 if ($diff >= 0) {
5943  	 	 	 	 	 	 	 if ($diff <= $diff_epsilon) {
5944  	 	 	 	 	 	 	 	 break;
5945  	 	 	 	 	 	 	 }
5946  	 	 	 	 	 	 	 $fmin = $fmid;
5947  	 	 	 	 	 	 } else {
5948  	 	 	 	 	 	 	 $fmax = $fmid;
5949  	 	 	 	 	 	 }
5950  	 	 	 	 	 	 --$maxit;
5951  	 	 	 	 	 }
5952  	 	 	 	 	 if ($maxit < 0) {
5953  	 	 	 	 	 	 // premature exit, we get the minimum font value to fit the cell
5954  	 	 	 	 	 	 $this->setFontSize($fmin);
5955  	 	 	 	 	 	 $this->resetLastH();
5956  	 	 	 	 	 	 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
5957  	 	 	 	 	 } else {
5958  	 	 	 	 	 	 $this->setFontSize($fmid);
5959  	 	 	 	 	 	 $this->resetLastH();
5960  	 	 	 	 	 }
5961  	 	 	 	 }
5962  	 	 	 	 if ($text_height < $maxh) {
5963  	 	 	 	 	 if ($valign == 'M') {
5964  	 	 	 	 	 	 // text vertically centered
5965  	 	 	 	 	 	 $this->y += (($maxh - $text_height) / 2);
5966  	 	 	 	 	 } elseif ($valign == 'B') {
5967  	 	 	 	 	 	 // text vertically aligned on bottom
5968  	 	 	 	 	 	 $this->y += ($maxh - $text_height);
5969  	 	 	 	 	 }
5970  	 	 	 	 }
5971  	 	 	 }
5972  	 	 	 $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
5973  	 	 	 if ($fitcell) {
5974  	 	 	 	 // restore font size
5975  	 	 	 	 $this->setFontSize($prev_FontSizePt);
5976  	 	 	 }
5977  	 	 }
5978  	 	 if ($autopadding) {
5979  	 	 	 // add bottom padding
5980  	 	 	 $this->y += $mc_padding['B'];
5981  	 	 }
5982  	 	 // Get end-of-text Y position
5983  	 	 $currentY = $this->y;
5984  	 	 // get latest page number
5985  	 	 $endpage = $this->page;
5986  	 	 if ($resth > 0) {
5987  	 	 	 $skip = ($endpage - $startpage);
5988  	 	 	 $tmpresth = $resth;
5989  	 	 	 while ($tmpresth > 0) {
5990  	 	 	 	 if ($skip <= 0) {
5991  	 	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
5992  	 	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
5993  	 	 	 	 }
5994  	 	 	 	 if ($this->num_columns > 1) {
5995  	 	 	 	 	 $tmpresth -= ($this->h - $this->y - $this->bMargin);
5996  	 	 	 	 } else {
5997  	 	 	 	 	 $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
5998  	 	 	 	 }
5999  	 	 	 	 --$skip;
6000  	 	 	 }
6001  	 	 	 $currentY = $this->y;
6002  	 	 	 $endpage = $this->page;
6003  	 	 }
6004  	 	 // get latest column
6005  	 	 $endcolumn = $this->current_column;
6006  	 	 if ($this->num_columns == 0) {
6007  	 	 	 $this->num_columns = 1;
6008  	 	 }
6009  	 	 // disable page regions check
6010  	 	 $check_page_regions = $this->check_page_regions;
6011  	 	 $this->check_page_regions = false;
6012  	 	 // get border modes
6013  	 	 $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
6014  	 	 $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
6015  	 	 $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
6016  	 	 // design borders around HTML cells.
6017  	 	 for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
6018  	 	 	 $ccode = '';
6019  	 	 	 $this->setPage($page);
6020  	 	 	 if ($this->num_columns < 2) {
6021  	 	 	 	 // single-column mode
6022  	 	 	 	 $this->setX($x);
6023  	 	 	 	 $this->y = $this->tMargin;
6024  	 	 	 }
6025  	 	 	 // account for margin changes
6026  	 	 	 if ($page > $startpage) {
6027  	 	 	 	 if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
6028  	 	 	 	 	 $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
6029  	 	 	 	 } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
6030  	 	 	 	 	 $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
6031  	 	 	 	 }
6032  	 	 	 }
6033  	 	 	 if ($startpage == $endpage) {
6034  	 	 	 	 // single page
6035  	 	 	 	 for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
6036  	 	 	 	 	 if ($column != $this->current_column) {
6037  	 	 	 	 	 	 $this->selectColumn($column);
6038  	 	 	 	 	 }
6039  	 	 	 	 	 if ($this->rtl) {
6040  	 	 	 	 	 	 $this->x -= $mc_margin['R'];
6041  	 	 	 	 	 } else {
6042  	 	 	 	 	 	 $this->x += $mc_margin['L'];
6043  	 	 	 	 	 }
6044  	 	 	 	 	 if ($startcolumn == $endcolumn) { // single column
6045  	 	 	 	 	 	 $cborder = $border;
6046  	 	 	 	 	 	 $h = max($h, ($currentY - $oy));
6047  	 	 	 	 	 	 $this->y = $oy;
6048  	 	 	 	 	 } elseif ($column == $startcolumn) { // first column
6049  	 	 	 	 	 	 $cborder = $border_start;
6050  	 	 	 	 	 	 $this->y = $oy;
6051  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
6052  	 	 	 	 	 } elseif ($column == $endcolumn) { // end column
6053  	 	 	 	 	 	 $cborder = $border_end;
6054  	 	 	 	 	 	 $h = $currentY - $this->y;
6055  	 	 	 	 	 	 if ($resth > $h) {
6056  	 	 	 	 	 	 	 $h = $resth;
6057  	 	 	 	 	 	 }
6058  	 	 	 	 	 } else { // middle column
6059  	 	 	 	 	 	 $cborder = $border_middle;
6060  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
6061  	 	 	 	 	 	 $resth -= $h;
6062  	 	 	 	 	 }
6063  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6064  	 	 	 	 } // end for each column
6065  	 	 	 } elseif ($page == $startpage) { // first page
6066  	 	 	 	 for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
6067  	 	 	 	 	 if ($column != $this->current_column) {
6068  	 	 	 	 	 	 $this->selectColumn($column);
6069  	 	 	 	 	 }
6070  	 	 	 	 	 if ($this->rtl) {
6071  	 	 	 	 	 	 $this->x -= $mc_margin['R'];
6072  	 	 	 	 	 } else {
6073  	 	 	 	 	 	 $this->x += $mc_margin['L'];
6074  	 	 	 	 	 }
6075  	 	 	 	 	 if ($column == $startcolumn) { // first column
6076  	 	 	 	 	 	 $cborder = $border_start;
6077  	 	 	 	 	 	 $this->y = $oy;
6078  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
6079  	 	 	 	 	 } else { // middle column
6080  	 	 	 	 	 	 $cborder = $border_middle;
6081  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
6082  	 	 	 	 	 	 $resth -= $h;
6083  	 	 	 	 	 }
6084  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6085  	 	 	 	 } // end for each column
6086  	 	 	 } elseif ($page == $endpage) { // last page
6087  	 	 	 	 for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
6088  	 	 	 	 	 if ($column != $this->current_column) {
6089  	 	 	 	 	 	 $this->selectColumn($column);
6090  	 	 	 	 	 }
6091  	 	 	 	 	 if ($this->rtl) {
6092  	 	 	 	 	 	 $this->x -= $mc_margin['R'];
6093  	 	 	 	 	 } else {
6094  	 	 	 	 	 	 $this->x += $mc_margin['L'];
6095  	 	 	 	 	 }
6096  	 	 	 	 	 if ($column == $endcolumn) {
6097  	 	 	 	 	 	 // end column
6098  	 	 	 	 	 	 $cborder = $border_end;
6099  	 	 	 	 	 	 $h = $currentY - $this->y;
6100  	 	 	 	 	 	 if ($resth > $h) {
6101  	 	 	 	 	 	 	 $h = $resth;
6102  	 	 	 	 	 	 }
6103  	 	 	 	 	 } else {
6104  	 	 	 	 	 	 // middle column
6105  	 	 	 	 	 	 $cborder = $border_middle;
6106  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
6107  	 	 	 	 	 	 $resth -= $h;
6108  	 	 	 	 	 }
6109  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6110  	 	 	 	 } // end for each column
6111  	 	 	 } else { // middle page
6112  	 	 	 	 for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
6113  	 	 	 	 	 $this->selectColumn($column);
6114  	 	 	 	 	 if ($this->rtl) {
6115  	 	 	 	 	 	 $this->x -= $mc_margin['R'];
6116  	 	 	 	 	 } else {
6117  	 	 	 	 	 	 $this->x += $mc_margin['L'];
6118  	 	 	 	 	 }
6119  	 	 	 	 	 $cborder = $border_middle;
6120  	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
6121  	 	 	 	 	 $resth -= $h;
6122  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6123  	 	 	 	 } // end for each column
6124  	 	 	 }
6125  	 	 	 if ($cborder OR $fill) {
6126  	 	 	 	 $offsetlen = strlen($ccode);
6127  	 	 	 	 // draw border and fill
6128  	 	 	 	 if ($this->inxobj) {
6129  	 	 	 	 	 // we are inside an XObject template
6130  	 	 	 	 	 if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
6131  	 	 	 	 	 	 $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
6132  	 	 	 	 	 	 $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
6133  	 	 	 	 	 	 $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
6134  	 	 	 	 	 } else {
6135  	 	 	 	 	 	 $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
6136  	 	 	 	 	 	 $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
6137  	 	 	 	 	 }
6138  	 	 	 	 	 $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
6139  	 	 	 	 	 $pstart = substr($pagebuff, 0, $pagemark);
6140  	 	 	 	 	 $pend = substr($pagebuff, $pagemark);
6141  	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
6142  	 	 	 	 } else {
6143  	 	 	 	 	 if (end($this->transfmrk[$this->page]) !== false) {
6144  	 	 	 	 	 	 $pagemarkkey = key($this->transfmrk[$this->page]);
6145  	 	 	 	 	 	 $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
6146  	 	 	 	 	 	 $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
6147  	 	 	 	 	 } elseif ($this->InFooter) {
6148  	 	 	 	 	 	 $pagemark = $this->footerpos[$this->page];
6149  	 	 	 	 	 	 $this->footerpos[$this->page] += $offsetlen;
6150  	 	 	 	 	 } else {
6151  	 	 	 	 	 	 $pagemark = $this->intmrk[$this->page];
6152  	 	 	 	 	 	 $this->intmrk[$this->page] += $offsetlen;
6153  	 	 	 	 	 }
6154  	 	 	 	 	 $pagebuff = $this->getPageBuffer($this->page);
6155  	 	 	 	 	 $pstart = substr($pagebuff, 0, $pagemark);
6156  	 	 	 	 	 $pend = substr($pagebuff, $pagemark);
6157  	 	 	 	 	 $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
6158  	 	 	 	 }
6159  	 	 	 }
6160  	 	 } // end for each page
6161  	 	 // restore page regions check
6162  	 	 $this->check_page_regions = $check_page_regions;
6163  	 	 // Get end-of-cell Y position
6164  	 	 $currentY = $this->GetY();
6165  	 	 // restore previous values
6166  	 	 if ($this->num_columns > 1) {
6167  	 	 	 $this->selectColumn();
6168  	 	 } else {
6169  	 	 	 // restore original margins
6170  	 	 	 $this->lMargin = $lMargin;
6171  	 	 	 $this->rMargin = $rMargin;
6172  	 	 	 if ($this->page > $startpage) {
6173  	 	 	 	 // check for margin variations between pages (i.e. booklet mode)
6174  	 	 	 	 $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
6175  	 	 	 	 $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
6176  	 	 	 	 if (($dl != 0) OR ($dr != 0)) {
6177  	 	 	 	 	 $this->lMargin += $dl;
6178  	 	 	 	 	 $this->rMargin += $dr;
6179  	 	 	 	 }
6180  	 	 	 }
6181  	 	 }
6182  	 	 if ($ln > 0) {
6183  	 	 	 //Go to the beginning of the next line
6184  	 	 	 $this->setY($currentY + $mc_margin['B']);
6185  	 	 	 if ($ln == 2) {
6186  	 	 	 	 $this->setX($x + $w + $mc_margin['L'] + $mc_margin['R']);
6187  	 	 	 }
6188  	 	 } else {
6189  	 	 	 // go left or right by case
6190  	 	 	 $this->setPage($startpage);
6191  	 	 	 $this->y = $y;
6192  	 	 	 $this->setX($x + $w + $mc_margin['L'] + $mc_margin['R']);
6193  	 	 }
6194  	 	 $this->setContentMark();
6195  	 	 $this->cell_padding = $prev_cell_padding;
6196  	 	 $this->cell_margin = $prev_cell_margin;
6197  	 	 $this->clMargin = $this->lMargin;
6198  	 	 $this->crMargin = $this->rMargin;
6199  	 	 return $nl;
6200  	 }
6201  
6202  	 /**
6203  	  * This method return the estimated number of lines for print a simple text string using Multicell() method.
6204  	  * @param string $txt String for calculating his height
6205  	  * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
6206  	  * @param boolean $reseth if true reset the last cell height (default false).
6207  	  * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
6208  	  * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
6209  	  * @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)))
6210  	  * @return float Return the minimal height needed for multicell method for printing the $txt param.
6211  	  * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
6212  	  * @public
6213  	  * @since 4.5.011
6214  	  */
6215  	public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding=null, $border=0) {
6216  	 	 if ($txt === NULL) {
6217  	 	 	 return 0;
6218  	 	 }
6219  	 	 if ($txt === '') {
6220  	 	 	 // empty string
6221  	 	 	 return 1;
6222  	 	 }
6223  	 	 // adjust internal padding
6224  	 	 $prev_cell_padding = $this->cell_padding;
6225  	 	 $prev_lasth = $this->lasth;
6226  	 	 if (is_array($cellpadding)) {
6227  	 	 	 $this->cell_padding = $cellpadding;
6228  	 	 }
6229  	 	 $this->adjustCellPadding($border);
6230  	 	 if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
6231  	 	 	 if ($this->rtl) {
6232  	 	 	 	 $w = $this->x - $this->lMargin;
6233  	 	 	 } else {
6234  	 	 	 	 $w = $this->w - $this->rMargin - $this->x;
6235  	 	 	 }
6236  	 	 }
6237  	 	 $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
6238  	 	 if ($reseth) {
6239  	 	 	 // reset row height
6240  	 	 	 $this->resetLastH();
6241  	 	 }
6242  	 	 $lines = 1;
6243  	 	 $sum = 0;
6244  	 	 $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
6245  	 	 $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
6246  	 	 $length = count($chars);
6247  	 	 $lastSeparator = -1;
6248  	 	 for ($i = 0; $i < $length; ++$i) {
6249  	 	 	 $c = $chars[$i];
6250  	 	 	 $charWidth = $charsWidth[$i];
6251  	 	 	 if (($c != 160)
6252  	 	 	 	 	 AND (($c == 173)
6253  	 	 	 	 	 	 OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
6254  	 	 	 	 	 	 OR (($c == 45)
6255  	 	 	 	 	 	 	 AND ($i > 0) AND ($i < ($length - 1))
6256  	 	 	 	 	 	 	 AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i - 1)], $this->isunicode))
6257  	 	 	 	 	 	 	 AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
6258  	 	 	 	 	 	 )
6259  	 	 	 	 	 )
6260  	 	 	 	 ) {
6261  	 	 	 	 $lastSeparator = $i;
6262  	 	 	 }
6263  	 	 	 if ((($sum + $charWidth) > $wmax) OR ($c == 10)) {
6264  	 	 	 	 ++$lines;
6265  	 	 	 	 if ($c == 10) {
6266  	 	 	 	 	 $lastSeparator = -1;
6267  	 	 	 	 	 $sum = 0;
6268  	 	 	 	 } elseif ($lastSeparator != -1) {
6269  	 	 	 	 	 $i = $lastSeparator;
6270  	 	 	 	 	 $lastSeparator = -1;
6271  	 	 	 	 	 $sum = 0;
6272  	 	 	 	 } else {
6273  	 	 	 	 	 $sum = $charWidth;
6274  	 	 	 	 }
6275  	 	 	 } else {
6276  	 	 	 	 $sum += $charWidth;
6277  	 	 	 }
6278  	 	 }
6279  	 	 if ($chars[($length - 1)] == 10) {
6280  	 	 	 --$lines;
6281  	 	 }
6282  	 	 $this->cell_padding = $prev_cell_padding;
6283  	 	 $this->lasth = $prev_lasth;
6284  	 	 return $lines;
6285  	 }
6286  
6287  	 /**
6288  	  * This method return the estimated height needed for printing a simple text string using the Multicell() method.
6289  	  * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
6290  	  * @pre
6291  	  *  // store current object
6292  	  *  $pdf->startTransaction();
6293  	  *  // store starting values
6294  	  *  $start_y = $pdf->GetY();
6295  	  *  $start_page = $pdf->getPage();
6296  	  *  // call your printing functions with your parameters
6297  	  *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6298  	  *  $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);
6299  	  *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6300  	  *  // get the new Y
6301  	  *  $end_y = $pdf->GetY();
6302  	  *  $end_page = $pdf->getPage();
6303  	  *  // calculate height
6304  	  *  $height = 0;
6305  	  *  if ($end_page == $start_page) {
6306  	  *  	 $height = $end_y - $start_y;
6307  	  *  } else {
6308  	  *  	 for ($page=$start_page; $page <= $end_page; ++$page) {
6309  	  *  	 	 $this->setPage($page);
6310  	  *  	 	 if ($page == $start_page) {
6311  	  *  	 	 	 // first page
6312  	  *  	 	 	 $height += $this->h - $start_y - $this->bMargin;
6313  	  *  	 	 } elseif ($page == $end_page) {
6314  	  *  	 	 	 // last page
6315  	  *  	 	 	 $height += $end_y - $this->tMargin;
6316  	  *  	 	 } else {
6317  	  *  	 	 	 $height += $this->h - $this->tMargin - $this->bMargin;
6318  	  *  	 	 }
6319  	  *  	 }
6320  	  *  }
6321  	  *  // restore previous object
6322  	  *  $pdf = $pdf->rollbackTransaction();
6323  	  *
6324  	  * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
6325  	  * @param string $txt String for calculating his height
6326  	  * @param boolean $reseth if true reset the last cell height (default false).
6327  	  * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
6328  	  * @param array|null $cellpadding Internal cell padding, if empty uses default cell padding.
6329  	  * @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)))
6330  	  * @return float Return the minimal height needed for multicell method for printing the $txt param.
6331  	  * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
6332  	  * @public
6333  	  */
6334  	public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding=null, $border=0) {
6335  	 	 // adjust internal padding
6336  	 	 $prev_cell_padding = $this->cell_padding;
6337  	 	 $prev_lasth = $this->lasth;
6338  	 	 if (is_array($cellpadding)) {
6339  	 	 	 $this->cell_padding = $cellpadding;
6340  	 	 }
6341  	 	 $this->adjustCellPadding($border);
6342  	 	 $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
6343  	 	 $height = $this->getCellHeight(($lines * $this->FontSize), $autopadding);
6344  	 	 $this->cell_padding = $prev_cell_padding;
6345  	 	 $this->lasth = $prev_lasth;
6346  	 	 return $height;
6347  	 }
6348  
6349  	 /**
6350  	  * This method prints text from the current position.<br />
6351  	  * @param float $h Line height
6352  	  * @param string $txt String to print
6353  	  * @param mixed $link URL or identifier returned by AddLink()
6354  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
6355  	  * @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>
6356  	  * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
6357  	  * @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.
6358  	  * @param boolean $firstline if true prints only the first line and return the remaining string.
6359  	  * @param boolean $firstblock if true the string is the starting of a line.
6360  	  * @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.
6361  	  * @param float $wadj first line width will be reduced by this amount (used in HTML mode).
6362  	  * @param array|null $margin margin array of the parent container
6363  	  * @return mixed Return the number of cells or the remaining string if $firstline = true.
6364  	  * @public
6365  	  * @since 1.5
6366  	  */
6367  	public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin=null) {
6368  	 	 // check page for no-write regions and adapt page margins if necessary
6369  	 	 list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
6370  	 	 if (strlen($txt) == 0) {
6371  	 	 	 // fix empty text
6372  	 	 	 $txt = ' ';
6373  	 	 }
6374  	 	 if (!is_array($margin)) {
6375  	 	 	 // set default margins
6376  	 	 	 $margin = $this->cell_margin;
6377  	 	 }
6378  	 	 // remove carriage returns
6379  	 	 $s = str_replace("\r", '', $txt);
6380  	 	 // check if string contains arabic text
6381  	 	 if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
6382  	 	 	 $arabic = true;
6383  	 	 } else {
6384  	 	 	 $arabic = false;
6385  	 	 }
6386  	 	 // check if string contains RTL text
6387  	 	 if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
6388  	 	 	 $rtlmode = true;
6389  	 	 } else {
6390  	 	 	 $rtlmode = false;
6391  	 	 }
6392  	 	 // get a char width
6393  	 	 $chrwidth = $this->GetCharWidth(46); // dot character
6394  	 	 // get array of unicode values
6395  	 	 $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
6396  	 	 // calculate maximum width for a single character on string
6397  	 	 $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
6398  	 	 array_walk($chrw, array($this, 'getRawCharWidth'));
6399  	 	 $maxchwidth = max($chrw);
6400  	 	 // get array of chars
6401  	 	 $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
6402  	 	 // get the number of characters
6403  	 	 $nb = count($chars);
6404  	 	 // replacement for SHY character (minus symbol)
6405  	 	 $shy_replacement = 45;
6406  	 	 $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
6407  	 	 // widht for SHY replacement
6408  	 	 $shy_replacement_width = $this->GetCharWidth($shy_replacement);
6409  	 	 // page width
6410  	 	 $pw = $w = $this->w - $this->lMargin - $this->rMargin;
6411  	 	 // calculate remaining line width ($w)
6412  	 	 if ($this->rtl) {
6413  	 	 	 $w = $this->x - $this->lMargin;
6414  	 	 } else {
6415  	 	 	 $w = $this->w - $this->rMargin - $this->x;
6416  	 	 }
6417  	 	 // max column width
6418  	 	 $wmax = ($w - $wadj);
6419  	 	 if (!$firstline) {
6420  	 	 	 $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
6421  	 	 }
6422  	 	 if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
6423  	 	 	 // the maximum width character do not fit on column
6424  	 	 	 return '';
6425  	 	 }
6426  	 	 // minimum row height
6427  	 	 $row_height = max($h, $this->getCellHeight($this->FontSize));
6428  	 	 // max Y
6429  	 	 $maxy = $this->y + $maxh - max($row_height, $h);
6430  	 	 $start_page = $this->page;
6431  	 	 $i = 0; // character position
6432  	 	 $j = 0; // current starting position
6433  	 	 $sep = -1; // position of the last blank space
6434  	 	 $prevsep = $sep; // previous separator
6435  	 	 $shy = false; // true if the last blank is a soft hypen (SHY)
6436  	 	 $prevshy = $shy; // previous shy mode
6437  	 	 $l = 0; // current string length
6438  	 	 $nl = 0; //number of lines
6439  	 	 $linebreak = false;
6440  	 	 $pc = 0; // previous character
6441  	 	 // for each character
6442  	 	 while ($i < $nb) {
6443  	 	 	 if (($maxh > 0) AND ($this->y > $maxy) ) {
6444  	 	 	 	 break;
6445  	 	 	 }
6446  	 	 	 //Get the current character
6447  	 	 	 $c = $chars[$i];
6448  	 	 	 if ($c == 10) { // 10 = "\n" = new line
6449  	 	 	 	 //Explicit line break
6450  	 	 	 	 if ($align == 'J') {
6451  	 	 	 	 	 if ($this->rtl) {
6452  	 	 	 	 	 	 $talign = 'R';
6453  	 	 	 	 	 } else {
6454  	 	 	 	 	 	 $talign = 'L';
6455  	 	 	 	 	 }
6456  	 	 	 	 } else {
6457  	 	 	 	 	 $talign = $align;
6458  	 	 	 	 }
6459  	 	 	 	 $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
6460  	 	 	 	 if ($firstline) {
6461  	 	 	 	 	 $startx = $this->x;
6462  	 	 	 	 	 $tmparr = array_slice($chars, $j, ($i - $j));
6463  	 	 	 	 	 if ($rtlmode) {
6464  	 	 	 	 	 	 $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
6465  	 	 	 	 	 }
6466  	 	 	 	 	 $linew = $this->GetArrStringWidth($tmparr);
6467  	 	 	 	 	 unset($tmparr);
6468  	 	 	 	 	 if ($this->rtl) {
6469  	 	 	 	 	 	 $this->endlinex = $startx - $linew;
6470  	 	 	 	 	 } else {
6471  	 	 	 	 	 	 $this->endlinex = $startx + $linew;
6472  	 	 	 	 	 }
6473  	 	 	 	 	 $w = $linew;
6474  	 	 	 	 	 $tmpcellpadding = $this->cell_padding;
6475  	 	 	 	 	 if ($maxh == 0) {
6476  	 	 	 	 	 	 $this->setCellPadding(0);
6477  	 	 	 	 	 }
6478  	 	 	 	 }
6479  	 	 	 	 if ($firstblock AND $this->isRTLTextDir()) {
6480  	 	 	 	 	 $tmpstr = $this->stringRightTrim($tmpstr);
6481  	 	 	 	 }
6482  	 	 	 	 // Skip newlines at the beginning of a page or column
6483  	 	 	 	 if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
6484  	 	 	 	 	 $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
6485  	 	 	 	 }
6486  	 	 	 	 unset($tmpstr);
6487  	 	 	 	 if ($firstline) {
6488  	 	 	 	 	 $this->cell_padding = $tmpcellpadding;
6489  	 	 	 	 	 return (TCPDF_FONTS::UniArrSubString($uchars, $i));
6490  	 	 	 	 }
6491  	 	 	 	 ++$nl;
6492  	 	 	 	 $j = $i + 1;
6493  	 	 	 	 $l = 0;
6494  	 	 	 	 $sep = -1;
6495  	 	 	 	 $prevsep = $sep;
6496  	 	 	 	 $shy = false;
6497  	 	 	 	 // account for margin changes
6498  	 	 	 	 if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
6499  	 	 	 	 	 if ($this->AcceptPageBreak())
6500  	 	 	 	 	 {
6501  	 	 	 	 	 	 if ($this->rtl) {
6502  	 	 	 	 	 	 	 $this->x -= $margin['R'];
6503  	 	 	 	 	 	 } else {
6504  	 	 	 	 	 	 	 $this->x += $margin['L'];
6505  	 	 	 	 	 	 }
6506  	 	 	 	 	 	 $this->lMargin += $margin['L'];
6507  	 	 	 	 	 	 $this->rMargin += $margin['R'];
6508  	 	 	 	 	 }
6509  	 	 	 	 }
6510  	 	 	 	 $w = $this->getRemainingWidth();
6511  	 	 	 	 $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
6512  	 	 	 } else {
6513  	 	 	 	 // 160 is the non-breaking space.
6514  	 	 	 	 // 173 is SHY (Soft Hypen).
6515  	 	 	 	 // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
6516  	 	 	 	 // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
6517  	 	 	 	 // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
6518  	 	 	 	 if (($c != 160)
6519  	 	 	 	 	 AND (($c == 173)
6520  	 	 	 	 	 	 OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
6521  	 	 	 	 	 	 OR (($c == 45)
6522  	 	 	 	 	 	 	 AND ($i < ($nb - 1))
6523  	 	 	 	 	 	 	 AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
6524  	 	 	 	 	 	 	 AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
6525  	 	 	 	 	 	 )
6526  	 	 	 	 	 )
6527  	 	 	 	 ) {
6528  	 	 	 	 	 // update last blank space position
6529  	 	 	 	 	 $prevsep = $sep;
6530  	 	 	 	 	 $sep = $i;
6531  	 	 	 	 	 // check if is a SHY
6532  	 	 	 	 	 if (($c == 173) OR ($c == 45)) {
6533  	 	 	 	 	 	 $prevshy = $shy;
6534  	 	 	 	 	 	 $shy = true;
6535  	 	 	 	 	 	 if ($pc == 45) {
6536  	 	 	 	 	 	 	 $tmp_shy_replacement_width = 0;
6537  	 	 	 	 	 	 	 $tmp_shy_replacement_char = '';
6538  	 	 	 	 	 	 } else {
6539  	 	 	 	 	 	 	 $tmp_shy_replacement_width = $shy_replacement_width;
6540  	 	 	 	 	 	 	 $tmp_shy_replacement_char = $shy_replacement_char;
6541  	 	 	 	 	 	 }
6542  	 	 	 	 	 } else {
6543  	 	 	 	 	 	 $shy = false;
6544  	 	 	 	 	 }
6545  	 	 	 	 }
6546  	 	 	 	 // update string length
6547  	 	 	 	 if ($this->isUnicodeFont() AND ($arabic)) {
6548  	 	 	 	 	 // with bidirectional algorithm some chars may be changed affecting the line length
6549  	 	 	 	 	 // *** very slow ***
6550  	 	 	 	 	 $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
6551  	 	 	 	 } else {
6552  	 	 	 	 	 $l += $this->GetCharWidth($c, ($i+1 < $nb));
6553  	 	 	 	 }
6554  	 	 	 	 if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) >= $wmax))) {
6555  	 	 	 	 	 if (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) {
6556  	 	 	 	 	 	 $sep = $prevsep;
6557  	 	 	 	 	 	 $shy = $prevshy;
6558  	 	 	 	 	 }
6559  	 	 	 	 	 // we have reached the end of column
6560  	 	 	 	 	 if ($sep == -1) {
6561  	 	 	 	 	 	 // check if the line was already started
6562  	 	 	 	 	 	 if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
6563  	 	 	 	 	 	 	 OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
6564  	 	 	 	 	 	 	 // print a void cell and go to next line
6565  	 	 	 	 	 	 	 $this->Cell($w, $h, '', 0, 1);
6566  	 	 	 	 	 	 	 $linebreak = true;
6567  	 	 	 	 	 	 	 if ($firstline) {
6568  	 	 	 	 	 	 	 	 return (TCPDF_FONTS::UniArrSubString($uchars, $j));
6569  	 	 	 	 	 	 	 }
6570  	 	 	 	 	 	 } else {
6571  	 	 	 	 	 	 	 // truncate the word because do not fit on column
6572  	 	 	 	 	 	 	 $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
6573  	 	 	 	 	 	 	 if ($firstline) {
6574  	 	 	 	 	 	 	 	 $startx = $this->x;
6575  	 	 	 	 	 	 	 	 $tmparr = array_slice($chars, $j, ($i - $j));
6576  	 	 	 	 	 	 	 	 if ($rtlmode) {
6577  	 	 	 	 	 	 	 	 	 $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
6578  	 	 	 	 	 	 	 	 }
6579  	 	 	 	 	 	 	 	 $linew = $this->GetArrStringWidth($tmparr);
6580  	 	 	 	 	 	 	 	 unset($tmparr);
6581  	 	 	 	 	 	 	 	 if ($this->rtl) {
6582  	 	 	 	 	 	 	 	 	 $this->endlinex = $startx - $linew;
6583  	 	 	 	 	 	 	 	 } else {
6584  	 	 	 	 	 	 	 	 	 $this->endlinex = $startx + $linew;
6585  	 	 	 	 	 	 	 	 }
6586  	 	 	 	 	 	 	 	 $w = $linew;
6587  	 	 	 	 	 	 	 	 $tmpcellpadding = $this->cell_padding;
6588  	 	 	 	 	 	 	 	 if ($maxh == 0) {
6589  	 	 	 	 	 	 	 	 	 $this->setCellPadding(0);
6590  	 	 	 	 	 	 	 	 }
6591  	 	 	 	 	 	 	 }
6592  	 	 	 	 	 	 	 if ($firstblock AND $this->isRTLTextDir()) {
6593  	 	 	 	 	 	 	 	 $tmpstr = $this->stringRightTrim($tmpstr);
6594  	 	 	 	 	 	 	 }
6595  	 	 	 	 	 	 	 $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
6596  	 	 	 	 	 	 	 unset($tmpstr);
6597  	 	 	 	 	 	 	 if ($firstline) {
6598  	 	 	 	 	 	 	 	 $this->cell_padding = $tmpcellpadding;
6599  	 	 	 	 	 	 	 	 return (TCPDF_FONTS::UniArrSubString($uchars, $i));
6600  	 	 	 	 	 	 	 }
6601  	 	 	 	 	 	 	 $j = $i;
6602  	 	 	 	 	 	 	 --$i;
6603  	 	 	 	 	 	 }
6604  	 	 	 	 	 } else {
6605  	 	 	 	 	 	 // word wrapping
6606  	 	 	 	 	 	 if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
6607  	 	 	 	 	 	 	 $endspace = 1;
6608  	 	 	 	 	 	 } else {
6609  	 	 	 	 	 	 	 $endspace = 0;
6610  	 	 	 	 	 	 }
6611  	 	 	 	 	 	 // check the length of the next string
6612  	 	 	 	 	 	 $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
6613  	 	 	 	 	 	 $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
6614  	 	 	 	 	 	 if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
6615  	 	 	 	 	 	 	 // truncate the word because do not fit on a full page width
6616  	 	 	 	 	 	 	 $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
6617  	 	 	 	 	 	 	 if ($firstline) {
6618  	 	 	 	 	 	 	 	 $startx = $this->x;
6619  	 	 	 	 	 	 	 	 $tmparr = array_slice($chars, $j, ($i - $j));
6620  	 	 	 	 	 	 	 	 if ($rtlmode) {
6621  	 	 	 	 	 	 	 	 	 $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
6622  	 	 	 	 	 	 	 	 }
6623  	 	 	 	 	 	 	 	 $linew = $this->GetArrStringWidth($tmparr);
6624  	 	 	 	 	 	 	 	 unset($tmparr);
6625  	 	 	 	 	 	 	 	 if ($this->rtl) {
6626  	 	 	 	 	 	 	 	 	 $this->endlinex = ($startx - $linew);
6627  	 	 	 	 	 	 	 	 } else {
6628  	 	 	 	 	 	 	 	 	 $this->endlinex = ($startx + $linew);
6629  	 	 	 	 	 	 	 	 }
6630  	 	 	 	 	 	 	 	 $w = $linew;
6631  	 	 	 	 	 	 	 	 $tmpcellpadding = $this->cell_padding;
6632  	 	 	 	 	 	 	 	 if ($maxh == 0) {
6633  	 	 	 	 	 	 	 	 	 $this->setCellPadding(0);
6634  	 	 	 	 	 	 	 	 }
6635  	 	 	 	 	 	 	 }
6636  	 	 	 	 	 	 	 if ($firstblock AND $this->isRTLTextDir()) {
6637  	 	 	 	 	 	 	 	 $tmpstr = $this->stringRightTrim($tmpstr);
6638  	 	 	 	 	 	 	 }
6639  	 	 	 	 	 	 	 $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
6640  	 	 	 	 	 	 	 unset($tmpstr);
6641  	 	 	 	 	 	 	 if ($firstline) {
6642  	 	 	 	 	 	 	 	 $this->cell_padding = $tmpcellpadding;
6643  	 	 	 	 	 	 	 	 return (TCPDF_FONTS::UniArrSubString($uchars, $i));
6644  	 	 	 	 	 	 	 }
6645  	 	 	 	 	 	 	 $j = $i;
6646  	 	 	 	 	 	 	 --$i;
6647  	 	 	 	 	 	 } else {
6648  	 	 	 	 	 	 	 // word wrapping
6649  	 	 	 	 	 	 	 if ($shy) {
6650  	 	 	 	 	 	 	 	 // add hypen (minus symbol) at the end of the line
6651  	 	 	 	 	 	 	 	 $shy_width = $tmp_shy_replacement_width;
6652  	 	 	 	 	 	 	 	 if ($this->rtl) {
6653  	 	 	 	 	 	 	 	 	 $shy_char_left = $tmp_shy_replacement_char;
6654  	 	 	 	 	 	 	 	 	 $shy_char_right = '';
6655  	 	 	 	 	 	 	 	 } else {
6656  	 	 	 	 	 	 	 	 	 $shy_char_left = '';
6657  	 	 	 	 	 	 	 	 	 $shy_char_right = $tmp_shy_replacement_char;
6658  	 	 	 	 	 	 	 	 }
6659  	 	 	 	 	 	 	 } else {
6660  	 	 	 	 	 	 	 	 $shy_width = 0;
6661  	 	 	 	 	 	 	 	 $shy_char_left = '';
6662  	 	 	 	 	 	 	 	 $shy_char_right = '';
6663  	 	 	 	 	 	 	 }
6664  	 	 	 	 	 	 	 $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
6665  	 	 	 	 	 	 	 if ($firstline) {
6666  	 	 	 	 	 	 	 	 $startx = $this->x;
6667  	 	 	 	 	 	 	 	 $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
6668  	 	 	 	 	 	 	 	 if ($rtlmode) {
6669  	 	 	 	 	 	 	 	 	 $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
6670  	 	 	 	 	 	 	 	 }
6671  	 	 	 	 	 	 	 	 $linew = $this->GetArrStringWidth($tmparr);
6672  	 	 	 	 	 	 	 	 unset($tmparr);
6673  	 	 	 	 	 	 	 	 if ($this->rtl) {
6674  	 	 	 	 	 	 	 	 	 $this->endlinex = $startx - $linew - $shy_width;
6675  	 	 	 	 	 	 	 	 } else {
6676  	 	 	 	 	 	 	 	 	 $this->endlinex = $startx + $linew + $shy_width;
6677  	 	 	 	 	 	 	 	 }
6678  	 	 	 	 	 	 	 	 $w = $linew;
6679  	 	 	 	 	 	 	 	 $tmpcellpadding = $this->cell_padding;
6680  	 	 	 	 	 	 	 	 if ($maxh == 0) {
6681  	 	 	 	 	 	 	 	 	 $this->setCellPadding(0);
6682  	 	 	 	 	 	 	 	 }
6683  	 	 	 	 	 	 	 }
6684  	 	 	 	 	 	 	 // print the line
6685  	 	 	 	 	 	 	 if ($firstblock AND $this->isRTLTextDir()) {
6686  	 	 	 	 	 	 	 	 $tmpstr = $this->stringRightTrim($tmpstr);
6687  	 	 	 	 	 	 	 }
6688  	 	 	 	 	 	 	 $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
6689  	 	 	 	 	 	 	 unset($tmpstr);
6690  	 	 	 	 	 	 	 if ($firstline) {
6691  	 	 	 	 	 	 	 	 if ($chars[$sep] == 45) {
6692  	 	 	 	 	 	 	 	 	 $endspace += 1;
6693  	 	 	 	 	 	 	 	 }
6694  	 	 	 	 	 	 	 	 // return the remaining text
6695  	 	 	 	 	 	 	 	 $this->cell_padding = $tmpcellpadding;
6696  	 	 	 	 	 	 	 	 return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
6697  	 	 	 	 	 	 	 }
6698  	 	 	 	 	 	 	 $i = $sep;
6699  	 	 	 	 	 	 	 $sep = -1;
6700  	 	 	 	 	 	 	 $shy = false;
6701  	 	 	 	 	 	 	 $j = ($i + 1);
6702  	 	 	 	 	 	 }
6703  	 	 	 	 	 }
6704  	 	 	 	 	 // account for margin changes
6705  	 	 	 	 	 if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
6706  	 	 	 	 	 	 if ($this->AcceptPageBreak())
6707  	 	 	 	 	 	 {
6708  	 	 	 	 	 	 	 if ($this->rtl) {
6709  	 	 	 	 	 	 	 	 $this->x -= $margin['R'];
6710  	 	 	 	 	 	 	 } else {
6711  	 	 	 	 	 	 	 	 $this->x += $margin['L'];
6712  	 	 	 	 	 	 	 }
6713  	 	 	 	 	 	 	 $this->lMargin += $margin['L'];
6714  	 	 	 	 	 	 	 $this->rMargin += $margin['R'];
6715  	 	 	 	 	 	 }
6716  	 	 	 	 	 }
6717  	 	 	 	 	 $w = $this->getRemainingWidth();
6718  	 	 	 	 	 $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
6719  	 	 	 	 	 if ($linebreak) {
6720  	 	 	 	 	 	 $linebreak = false;
6721  	 	 	 	 	 } else {
6722  	 	 	 	 	 	 ++$nl;
6723  	 	 	 	 	 	 $l = 0;
6724  	 	 	 	 	 }
6725  	 	 	 	 }
6726  	 	 	 }
6727  	 	 	 // save last character
6728  	 	 	 $pc = $c;
6729  	 	 	 ++$i;
6730  	 	 } // end while i < nb
6731  	 	 // print last substring (if any)
6732  	 	 if ($l > 0) {
6733  	 	 	 switch ($align) {
6734  	 	 	 	 case 'J':
6735  	 	 	 	 case 'C': {
6736  	 	 	 	 	 break;
6737  	 	 	 	 }
6738  	 	 	 	 case 'L': {
6739  	 	 	 	 	 if (!$this->rtl) {
6740  	 	 	 	 	 	 $w = $l;
6741  	 	 	 	 	 }
6742  	 	 	 	 	 break;
6743  	 	 	 	 }
6744  	 	 	 	 case 'R': {
6745  	 	 	 	 	 if ($this->rtl) {
6746  	 	 	 	 	 	 $w = $l;
6747  	 	 	 	 	 }
6748  	 	 	 	 	 break;
6749  	 	 	 	 }
6750  	 	 	 	 default: {
6751  	 	 	 	 	 $w = $l;
6752  	 	 	 	 	 break;
6753  	 	 	 	 }
6754  	 	 	 }
6755  	 	 	 $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
6756  	 	 	 if ($firstline) {
6757  	 	 	 	 $startx = $this->x;
6758  	 	 	 	 $tmparr = array_slice($chars, $j, ($nb - $j));
6759  	 	 	 	 if ($rtlmode) {
6760  	 	 	 	 	 $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
6761  	 	 	 	 }
6762  	 	 	 	 $linew = $this->GetArrStringWidth($tmparr);
6763  	 	 	 	 unset($tmparr);
6764  	 	 	 	 if ($this->rtl) {
6765  	 	 	 	 	 $this->endlinex = $startx - $linew;
6766  	 	 	 	 } else {
6767  	 	 	 	 	 $this->endlinex = $startx + $linew;
6768  	 	 	 	 }
6769  	 	 	 	 $w = $linew;
6770  	 	 	 	 $tmpcellpadding = $this->cell_padding;
6771  	 	 	 	 if ($maxh == 0) {
6772  	 	 	 	 	 $this->setCellPadding(0);
6773  	 	 	 	 }
6774  	 	 	 }
6775  	 	 	 if ($firstblock AND $this->isRTLTextDir()) {
6776  	 	 	 	 $tmpstr = $this->stringRightTrim($tmpstr);
6777  	 	 	 }
6778  	 	 	 $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
6779  	 	 	 unset($tmpstr);
6780  	 	 	 if ($firstline) {
6781  	 	 	 	 $this->cell_padding = $tmpcellpadding;
6782  	 	 	 	 return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
6783  	 	 	 }
6784  	 	 	 ++$nl;
6785  	 	 }
6786  	 	 if ($firstline) {
6787  	 	 	 return '';
6788  	 	 }
6789  	 	 return $nl;
6790  	 }
6791  
6792  	 /**
6793  	  * Returns the remaining width between the current position and margins.
6794  	  * @return float Return the remaining width
6795  	  * @protected
6796  	  */
6797  	protected function getRemainingWidth() {
6798  	 	 list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
6799  	 	 if ($this->rtl) {
6800  	 	 	 return ($this->x - $this->lMargin);
6801  	 	 } else {
6802  	 	 	 return ($this->w - $this->rMargin - $this->x);
6803  	 	 }
6804  	 }
6805  
6806  	 /**
6807  	  * Set the block dimensions accounting for page breaks and page/column fitting
6808  	  * @param float $w width
6809  	  * @param float $h height
6810  	  * @param float $x X coordinate
6811  	  * @param float $y Y coodiante
6812  	  * @param boolean $fitonpage if true the block is resized to not exceed page dimensions.
6813  	  * @return array array($w, $h, $x, $y)
6814  	  * @protected
6815  	  * @since 5.5.009 (2010-07-05)
6816  	  */
6817  	protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
6818  	 	 if ($w <= 0) {
6819  	 	 	 // set maximum width
6820  	 	 	 $w = ($this->w - $this->lMargin - $this->rMargin);
6821  	 	 	 if ($w <= 0) {
6822  	 	 	 	 $w = 1;
6823  	 	 	 }
6824  	 	 }
6825  	 	 if ($h <= 0) {
6826  	 	 	 // set maximum height
6827  	 	 	 $h = ($this->PageBreakTrigger - $this->tMargin);
6828  	 	 	 if ($h <= 0) {
6829  	 	 	 	 $h = 1;
6830  	 	 	 }
6831  	 	 }
6832  	 	 // resize the block to be vertically contained on a single page or single column
6833  	 	 if ($fitonpage OR $this->AutoPageBreak) {
6834  	 	 	 $ratio_wh = ($w / $h);
6835  	 	 	 if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
6836  	 	 	 	 $h = $this->PageBreakTrigger - $this->tMargin;
6837  	 	 	 	 $w = ($h * $ratio_wh);
6838  	 	 	 }
6839  	 	 	 // resize the block to be horizontally contained on a single page or single column
6840  	 	 	 if ($fitonpage) {
6841  	 	 	 	 $maxw = ($this->w - $this->lMargin - $this->rMargin);
6842  	 	 	 	 if ($w > $maxw) {
6843  	 	 	 	 	 $w = $maxw;
6844  	 	 	 	 	 $h = ($w / $ratio_wh);
6845  	 	 	 	 }
6846  	 	 	 }
6847  	 	 }
6848  	 	 // Check whether we need a new page or new column first as this does not fit
6849  	 	 $prev_x = $this->x;
6850  	 	 $prev_y = $this->y;
6851  	 	 if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
6852  	 	 	 $y = $this->y;
6853  	 	 	 if ($this->rtl) {
6854  	 	 	 	 $x += ($prev_x - $this->x);
6855  	 	 	 } else {
6856  	 	 	 	 $x += ($this->x - $prev_x);
6857  	 	 	 }
6858  	 	 	 $this->newline = true;
6859  	 	 }
6860  	 	 // resize the block to be contained on the remaining available page or column space
6861  	 	 if ($fitonpage) {
6862  	 	 	 $ratio_wh = ($w / $h);
6863  	 	 	 if (($y + $h) > $this->PageBreakTrigger) {
6864  	 	 	 	 $h = $this->PageBreakTrigger - $y;
6865  	 	 	 	 $w = ($h * $ratio_wh);
6866  	 	 	 }
6867  	 	 	 if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
6868  	 	 	 	 $w = $this->w - $this->rMargin - $x;
6869  	 	 	 	 $h = ($w / $ratio_wh);
6870  	 	 	 } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
6871  	 	 	 	 $w = $x - $this->lMargin;
6872  	 	 	 	 $h = ($w / $ratio_wh);
6873  	 	 	 }
6874  	 	 }
6875  	 	 return array($w, $h, $x, $y);
6876  	 }
6877  
6878  	 /**
6879  	  * Puts an image in the page.
6880  	  * The upper-left corner must be given.
6881  	  * The dimensions can be specified in different ways:<ul>
6882  	  * <li>explicit width and height (expressed in user unit)</li>
6883  	  * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
6884  	  * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
6885  	  * 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;
6886  	  * The format can be specified explicitly or inferred from the file extension.<br />
6887  	  * It is possible to put a link on the image.<br />
6888  	  * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
6889  	  * @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').
6890  	  * @param float|null $x Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
6891  	  * @param float|null $y Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
6892  	  * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
6893  	  * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
6894  	  * @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.
6895  	  * @param mixed $link URL or identifier returned by AddLink().
6896  	  * @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>
6897  	  * @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).
6898  	  * @param int $dpi dot-per-inch resolution used on resize
6899  	  * @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>
6900  	  * @param boolean $ismask true if this image is a mask, false otherwise
6901  	  * @param mixed $imgmask image object returned by this function or false
6902  	  * @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)))
6903  	  * @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).
6904  	  * @param boolean $hidden If true do not display the image.
6905  	  * @param boolean $fitonpage If true the image is resized to not exceed page dimensions.
6906  	  * @param boolean $alt If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
6907  	  * @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.
6908  	  * @return mixed|false image information
6909  	  * @public
6910  	  * @since 1.1
6911  	  */
6912  	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()) {
6913  	 	 if ($this->state != 2) {
6914  	 	 	 return false;
6915  	 	 }
6916  	 	 if (TCPDF_STATIC::empty_string($x)) {
6917  	 	 	 $x = $this->x;
6918  	 	 }
6919  	 	 if (TCPDF_STATIC::empty_string($y)) {
6920  	 	 	 $y = $this->y;
6921  	 	 }
6922  	 	 // check page for no-write regions and adapt page margins if necessary
6923  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
6924  	 	 $exurl = ''; // external streams
6925  	 	 $imsize = FALSE;
6926  
6927          // Make sure the file variable is not empty or null because accessing $file[0] later
6928          // results in error when running PHP 7.4
6929          if (empty($file)) {
6930              return false;
6931          }
6932  	 	 // check if we are passing an image as file or string
6933  	 	 if ($file[0] === '@') {
6934  	 	 	 // image from string
6935  	 	 	 $imgdata = substr($file, 1);
6936  	 	 } else { // image file
6937  	 	 	 if ($file[0] === '*') {
6938  	 	 	 	 // image as external stream
6939  	 	 	 	 $file = substr($file, 1);
6940  	 	 	 	 $exurl = $file;
6941  	 	 	 }
6942  	 	 	 // check if file exist and it is valid
6943  	 	 	 if (!@$this->fileExists($file)) {
6944  	 	 	 	 return false;
6945  	 	 	 }
6946              if (false !== $info = $this->getImageBuffer($file)) {
6947                  $imsize = array($info['w'], $info['h']);
6948              } elseif (($imsize = @getimagesize($file)) === FALSE && strpos($file, '__tcpdf_'.$this->file_id.'_img') === FALSE){
6949                  $imgdata = $this->getCachedFileContents($file);
6950              }
6951  	 	 }
6952  	 	 if (!empty($imgdata)) {
6953  	 	 	 // copy image to cache
6954  	 	 	 $original_file = $file;
6955  	 	 	 $file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
6956  	 	 	 $fp = TCPDF_STATIC::fopenLocal($file, 'w');
6957  	 	 	 if (!$fp) {
6958  	 	 	 	 $this->Error('Unable to write file: '.$file);
6959  	 	 	 }
6960  	 	 	 fwrite($fp, $imgdata);
6961  	 	 	 fclose($fp);
6962  	 	 	 unset($imgdata);
6963  	 	 	 $imsize = @getimagesize($file);
6964  	 	 	 if ($imsize === FALSE) {
6965  	 	 	 	 unlink($file);
6966  	 	 	 	 $file = $original_file;
6967  	 	 	 }
6968  	 	 }
6969  	 	 if ($imsize === FALSE) {
6970  	 	 	 if (($w > 0) AND ($h > 0)) {
6971  	 	 	 	 // get measures from specified data
6972  	 	 	 	 $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
6973  	 	 	 	 $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
6974  	 	 	 	 $imsize = array($pw, $ph);
6975  	 	 	 } else {
6976  	 	 	 	 $this->Error('[Image] Unable to get the size of the image: '.$file);
6977  	 	 	 }
6978  	 	 }
6979  	 	 // file hash
6980  	 	 $filehash = md5($file);
6981  	 	 // get original image width and height in pixels
6982  	 	 list($pixw, $pixh) = $imsize;
6983  	 	 // calculate image width and height on document
6984  	 	 if (($w <= 0) AND ($h <= 0)) {
6985  	 	 	 // convert image size to document unit
6986  	 	 	 $w = $this->pixelsToUnits($pixw);
6987  	 	 	 $h = $this->pixelsToUnits($pixh);
6988  	 	 } elseif ($w <= 0) {
6989  	 	 	 $w = $h * $pixw / $pixh;
6990  	 	 } elseif ($h <= 0) {
6991  	 	 	 $h = $w * $pixh / $pixw;
6992  	 	 } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
6993  	 	 	 if (strlen($fitbox) !== 2) {
6994  	 	 	 	 // set default alignment
6995  	 	 	 	 $fitbox = '--';
6996  	 	 	 }
6997  	 	 	 // scale image dimensions proportionally to fit within the ($w, $h) box
6998  	 	 	 if ((($w * $pixh) / ($h * $pixw)) < 1) {
6999  	 	 	 	 // store current height
7000  	 	 	 	 $oldh = $h;
7001  	 	 	 	 // calculate new height
7002  	 	 	 	 $h = $w * $pixh / $pixw;
7003  	 	 	 	 // height difference
7004  	 	 	 	 $hdiff = ($oldh - $h);
7005  	 	 	 	 // vertical alignment
7006  	 	 	 	 switch (strtoupper($fitbox[1])) {
7007  	 	 	 	 	 case 'T': {
7008  	 	 	 	 	 	 break;
7009  	 	 	 	 	 }
7010  	 	 	 	 	 case 'M': {
7011  	 	 	 	 	 	 $y += ($hdiff / 2);
7012  	 	 	 	 	 	 break;
7013  	 	 	 	 	 }
7014  	 	 	 	 	 case 'B': {
7015  	 	 	 	 	 	 $y += $hdiff;
7016  	 	 	 	 	 	 break;
7017  	 	 	 	 	 }
7018  	 	 	 	 }
7019  	 	 	 } else {
7020  	 	 	 	 // store current width
7021  	 	 	 	 $oldw = $w;
7022  	 	 	 	 // calculate new width
7023  	 	 	 	 $w = $h * $pixw / $pixh;
7024  	 	 	 	 // width difference
7025  	 	 	 	 $wdiff = ($oldw - $w);
7026  	 	 	 	 // horizontal alignment
7027  	 	 	 	 switch (strtoupper($fitbox[0])) {
7028  	 	 	 	 	 case 'L': {
7029  	 	 	 	 	 	 if ($this->rtl) {
7030  	 	 	 	 	 	 	 $x -= $wdiff;
7031  	 	 	 	 	 	 }
7032  	 	 	 	 	 	 break;
7033  	 	 	 	 	 }
7034  	 	 	 	 	 case 'C': {
7035  	 	 	 	 	 	 if ($this->rtl) {
7036  	 	 	 	 	 	 	 $x -= ($wdiff / 2);
7037  	 	 	 	 	 	 } else {
7038  	 	 	 	 	 	 	 $x += ($wdiff / 2);
7039  	 	 	 	 	 	 }
7040  	 	 	 	 	 	 break;
7041  	 	 	 	 	 }
7042  	 	 	 	 	 case 'R': {
7043  	 	 	 	 	 	 if (!$this->rtl) {
7044  	 	 	 	 	 	 	 $x += $wdiff;
7045  	 	 	 	 	 	 }
7046  	 	 	 	 	 	 break;
7047  	 	 	 	 	 }
7048  	 	 	 	 }
7049  	 	 	 }
7050  	 	 }
7051  	 	 // fit the image on available space
7052  	 	 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
7053  	 	 // calculate new minimum dimensions in pixels
7054  	 	 $neww = round($w * $this->k * $dpi / $this->dpi);
7055  	 	 $newh = round($h * $this->k * $dpi / $this->dpi);
7056  	 	 // check if resize is necessary (resize is used only to reduce the image)
7057  	 	 $newsize = ($neww * $newh);
7058  	 	 $pixsize = ($pixw * $pixh);
7059  	 	 if (intval($resize) == 2) {
7060  	 	 	 $resize = true;
7061  	 	 } elseif ($newsize >= $pixsize) {
7062  	 	 	 $resize = false;
7063  	 	 }
7064  	 	 // check if image has been already added on document
7065  	 	 $newimage = true;
7066  	 	 if (in_array($file, $this->imagekeys)) {
7067  	 	 	 $newimage = false;
7068  	 	 	 // get existing image data
7069  	 	 	 $info = $this->getImageBuffer($file);
7070  	 	 	 if (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE) {
7071  	 	 	 	 // check if the newer image is larger
7072  	 	 	 	 $oldsize = ($info['w'] * $info['h']);
7073  	 	 	 	 if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
7074  	 	 	 	 	 $newimage = true;
7075  	 	 	 	 }
7076  	 	 	 }
7077  	 	 } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)) {
7078  	 	 	 // create temp image file (without alpha channel)
7079  	 	 	 $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
7080  	 	 	 // create temp alpha file
7081  	 	 	 $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
7082  	 	 	 // check for cached images
7083  	 	 	 if (in_array($tempfile_plain, $this->imagekeys)) {
7084  	 	 	 	 // get existing image data
7085  	 	 	 	 $info = $this->getImageBuffer($tempfile_plain);
7086  	 	 	 	 // check if the newer image is larger
7087  	 	 	 	 $oldsize = ($info['w'] * $info['h']);
7088  	 	 	 	 if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
7089  	 	 	 	 	 $newimage = true;
7090  	 	 	 	 } else {
7091  	 	 	 	 	 $newimage = false;
7092  	 	 	 	 	 // embed mask image
7093  	 	 	 	 	 $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
7094  	 	 	 	 	 // embed image, masked with previously embedded mask
7095  	 	 	 	 	 return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
7096  	 	 	 	 }
7097  	 	 	 }
7098  	 	 }
7099  	 	 if ($newimage) {
7100  	 	 	 //First use of image, get info
7101  	 	 	 $type = strtolower($type);
7102  	 	 	 if ($type == '') {
7103  	 	 	 	 $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
7104  	 	 	 } elseif ($type == 'jpg') {
7105  	 	 	 	 $type = 'jpeg';
7106  	 	 	 }
7107  	 	 	 $mqr = TCPDF_STATIC::get_mqr();
7108  	 	 	 TCPDF_STATIC::set_mqr(false);
7109  	 	 	 // Specific image handlers (defined on TCPDF_IMAGES CLASS)
7110  	 	 	 $mtd = '_parse'.$type;
7111  	 	 	 // GD image handler function
7112  	 	 	 $gdfunction = 'imagecreatefrom'.$type;
7113  	 	 	 $info = false;
7114  	 	 	 if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
7115  	 	 	 	 // TCPDF image functions
7116  	 	 	 	 $info = TCPDF_IMAGES::$mtd($file);
7117  	 	 	 	 if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id.'_imgmask_') === FALSE)
7118  	 	 	 	 	 AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
7119  	 	 	 	 	 return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
7120  	 	 	 	 }
7121  	 	 	 }
7122  	 	 	 if (($info === false) AND function_exists($gdfunction)) {
7123  	 	 	 	 try {
7124  	 	 	 	 	 // GD library
7125  	 	 	 	 	 $img = $gdfunction($file);
7126  	 	 	 	 	 if ($img !== false) {
7127  	 	 	 	 	 	 if ($resize) {
7128  	 	 	 	 	 	 	 $imgr = imagecreatetruecolor($neww, $newh);
7129  	 	 	 	 	 	 	 if (($type == 'gif') OR ($type == 'png')) {
7130  	 	 	 	 	 	 	 	 $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
7131  	 	 	 	 	 	 	 }
7132  	 	 	 	 	 	 	 imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
7133  	 	 	 	 	 	 	 $img = $imgr;
7134  	 	 	 	 	 	 }
7135  	 	 	 	 	 	 if (($type == 'gif') OR ($type == 'png')) {
7136  	 	 	 	 	 	 	 $info = TCPDF_IMAGES::_toPNG($img, TCPDF_STATIC::getObjFilename('img', $this->file_id));
7137  	 	 	 	 	 	 } else {
7138  	 	 	 	 	 	 	 $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality, TCPDF_STATIC::getObjFilename('img', $this->file_id));
7139  	 	 	 	 	 	 }
7140  	 	 	 	 	 }
7141  	 	 	 	 } catch(Exception $e) {
7142  	 	 	 	 	 $info = false;
7143  	 	 	 	 }
7144  	 	 	 }
7145  	 	 	 if (($info === false) AND extension_loaded('imagick')) {
7146  	 	 	 	 try {
7147  	 	 	 	 	 // ImageMagick library
7148  	 	 	 	 	 $img = new Imagick();
7149  	 	 	 	 	 if ($type == 'svg') {
7150  	 	 	 	 	 	 if ($file[0] === '@') {
7151  	 	 	 	 	 	 	 // image from string
7152  	 	 	 	 	 	 	 $svgimg = substr($file, 1);
7153  	 	 	 	 	 	 } else {
7154  	 	 	 	 	 	 	 // get SVG file content
7155                              $svgimg = $this->getCachedFileContents($file);
7156  	 	 	 	 	 	 }
7157  	 	 	 	 	 	 if ($svgimg !== FALSE) {
7158  	 	 	 	 	 	 	 // get width and height
7159  	 	 	 	 	 	 	 $regs = array();
7160  	 	 	 	 	 	 	 if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
7161  	 	 	 	 	 	 	 	 $svgtag = $regs[1];
7162  	 	 	 	 	 	 	 	 $tmp = array();
7163  	 	 	 	 	 	 	 	 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
7164  	 	 	 	 	 	 	 	 	 $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
7165  	 	 	 	 	 	 	 	 	 $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
7166  	 	 	 	 	 	 	 	 	 $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
7167  	 	 	 	 	 	 	 	 } else {
7168  	 	 	 	 	 	 	 	 	 $ow = $w;
7169  	 	 	 	 	 	 	 	 }
7170  	 	 	 	 	 	 	 	 $tmp = array();
7171  	 	 	 	 	 	 	 	 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
7172  	 	 	 	 	 	 	 	 	 $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
7173  	 	 	 	 	 	 	 	 	 $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
7174  	 	 	 	 	 	 	 	 	 $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
7175  	 	 	 	 	 	 	 	 } else {
7176  	 	 	 	 	 	 	 	 	 $oh = $h;
7177  	 	 	 	 	 	 	 	 }
7178  	 	 	 	 	 	 	 	 $tmp = array();
7179  	 	 	 	 	 	 	 	 if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
7180  	 	 	 	 	 	 	 	 	 $vbw = ($ow * $this->imgscale * $this->k);
7181  	 	 	 	 	 	 	 	 	 $vbh = ($oh * $this->imgscale * $this->k);
7182  	 	 	 	 	 	 	 	 	 $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
7183  	 	 	 	 	 	 	 	 	 $svgtag = $vbox.$svgtag;
7184  	 	 	 	 	 	 	 	 }
7185  	 	 	 	 	 	 	 	 $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
7186  	 	 	 	 	 	 	 }
7187  	 	 	 	 	 	 	 $img->readImageBlob($svgimg);
7188  	 	 	 	 	 	 }
7189  	 	 	 	 	 } else {
7190  	 	 	 	 	 	 $img->readImage($file);
7191  	 	 	 	 	 }
7192  	 	 	 	 	 if ($resize) {
7193  	 	 	 	 	 	 $img->resizeImage($neww, $newh, 10, 1, false);
7194  	 	 	 	 	 }
7195  	 	 	 	 	 $img->setCompressionQuality($this->jpeg_quality);
7196  	 	 	 	 	 $img->setImageFormat('jpeg');
7197  	 	 	 	 	 $tempname = TCPDF_STATIC::getObjFilename('img', $this->file_id);
7198  	 	 	 	 	 $img->writeImage($tempname);
7199  	 	 	 	 	 $info = TCPDF_IMAGES::_parsejpeg($tempname);
7200  	 	 	 	 	 unlink($tempname);
7201  	 	 	 	 	 $img->destroy();
7202  	 	 	 	 } catch(Exception $e) {
7203  	 	 	 	 	 $info = false;
7204  	 	 	 	 }
7205  	 	 	 }
7206  	 	 	 if ($info === false) {
7207  	 	 	 	 // unable to process image
7208  	 	 	 	 return false;
7209  	 	 	 }
7210  	 	 	 TCPDF_STATIC::set_mqr($mqr);
7211  	 	 	 if ($ismask) {
7212  	 	 	 	 // force grayscale
7213  	 	 	 	 $info['cs'] = 'DeviceGray';
7214  	 	 	 }
7215  	 	 	 if ($imgmask !== false) {
7216  	 	 	 	 $info['masked'] = $imgmask;
7217  	 	 	 }
7218  	 	 	 if (!empty($exurl)) {
7219  	 	 	 	 $info['exurl'] = $exurl;
7220  	 	 	 }
7221  	 	 	 // array of alternative images
7222  	 	 	 $info['altimgs'] = $altimgs;
7223  	 	 	 // add image to document
7224  	 	 	 $info['i'] = $this->setImageBuffer($file, $info);
7225  	 	 }
7226  	 	 // set alignment
7227  	 	 $this->img_rb_x = $x + $w;
7228  	 	 $this->img_rb_y = $y + $h;
7229  
7230  	 	 // set alignment
7231  	 	 if ($palign == 'L') {
7232  	 	 	 $ximg = $this->lMargin;
7233  	 	 } elseif ($palign == 'C') {
7234  	 	 	 $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
7235  	 	 } elseif ($palign == 'R') {
7236  	 	 	 $ximg = $this->w - $this->rMargin - $w;
7237  	 	 } else {
7238  	 	 	 $ximg = $x;
7239  	 	 }
7240  
7241  	 	 if ($ismask OR $hidden) {
7242  	 	 	 // image is not displayed
7243  	 	 	 return $info['i'];
7244  	 	 }
7245  	 	 $xkimg = $ximg * $this->k;
7246  	 	 if (!$alt) {
7247  	 	 	 // only non-alternative immages will be set
7248  	 	 	 $this->_out(sprintf('q %F 0 0 %F %F %F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
7249  	 	 }
7250  	 	 if (!empty($border)) {
7251  	 	 	 $bx = $this->x;
7252  	 	 	 $by = $this->y;
7253  	 	 	 $this->x = $ximg;
7254  	 	 	 if ($this->rtl) {
7255  	 	 	 	 $this->x += $w;
7256  	 	 	 }
7257  	 	 	 $this->y = $y;
7258  	 	 	 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
7259  	 	 	 $this->x = $bx;
7260  	 	 	 $this->y = $by;
7261  	 	 }
7262  	 	 if ($link) {
7263  	 	 	 $this->Link($ximg, $y, $w, $h, $link, 0);
7264  	 	 }
7265  	 	 // set pointer to align the next text/objects
7266  	 	 switch($align) {
7267  	 	 	 case 'T': {
7268  	 	 	 	 $this->y = $y;
7269  	 	 	 	 $this->x = $this->img_rb_x;
7270  	 	 	 	 break;
7271  	 	 	 }
7272  	 	 	 case 'M': {
7273  	 	 	 	 $this->y = $y + round($h/2);
7274  	 	 	 	 $this->x = $this->img_rb_x;
7275  	 	 	 	 break;
7276  	 	 	 }
7277  	 	 	 case 'B': {
7278  	 	 	 	 $this->y = $this->img_rb_y;
7279  	 	 	 	 $this->x = $this->img_rb_x;
7280  	 	 	 	 break;
7281  	 	 	 }
7282  	 	 	 case 'N': {
7283  	 	 	 	 $this->setY($this->img_rb_y);
7284  	 	 	 	 break;
7285  	 	 	 }
7286  	 	 	 default:{
7287  	 	 	 	 break;
7288  	 	 	 }
7289  	 	 }
7290  	 	 $this->endlinex = $this->img_rb_x;
7291  	 	 if ($this->inxobj) {
7292  	 	 	 // we are inside an XObject template
7293  	 	 	 $this->xobjects[$this->xobjid]['images'][] = $info['i'];
7294  	 	 }
7295  	 	 return $info['i'];
7296  	 }
7297  
7298  	 /**
7299  	  * Extract info from a PNG image with alpha channel using the Imagick or GD library.
7300  	  * @param string $file Name of the file containing the image.
7301  	  * @param float $x Abscissa of the upper-left corner.
7302  	  * @param float $y Ordinate of the upper-left corner.
7303  	  * @param float $wpx Original width of the image in pixels.
7304  	  * @param float $hpx original height of the image in pixels.
7305  	  * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
7306  	  * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
7307  	  * @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.
7308  	  * @param mixed $link URL or identifier returned by AddLink().
7309  	  * @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>
7310  	  * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
7311  	  * @param int $dpi dot-per-inch resolution used on resize
7312  	  * @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>
7313  	  * @param string $filehash File hash used to build unique file names.
7314  	  * @author Nicola Asuni
7315  	  * @protected
7316  	  * @since 4.3.007 (2008-12-04)
7317  	  * @see Image()
7318  	  */
7319  	protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
7320  	 	 // create temp images
7321  	 	 if (empty($filehash)) {
7322  	 	 	 $filehash = md5($file);
7323  	 	 }
7324  	 	 // create temp image file (without alpha channel)
7325  	 	 $tempfile_plain = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_plain_'.$filehash;
7326  	 	 // create temp alpha file
7327  	 	 $tempfile_alpha = K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_imgmask_alpha_'.$filehash;
7328  	 	 $parsed = false;
7329  	 	 $parse_error = '';
7330  	 	 // ImageMagick extension
7331  	 	 if (($parsed === false) AND extension_loaded('imagick')) {
7332  	 	 	 try {
7333  	 	 	 	 // ImageMagick library
7334  	 	 	 	 $img = new Imagick();
7335  	 	 	 	 $img->readImage($file);
7336  	 	 	 	 // clone image object
7337  	 	 	 	 $imga = TCPDF_STATIC::objclone($img);
7338  	 	 	 	 // extract alpha channel
7339  	 	 	 	 if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
7340  	 	 	 	 	 $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
7341  	 	 	 	 } else {
7342  	 	 	 	 	 $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
7343  	 	 	 	 	 $img->negateImage(true);
7344  	 	 	 	 }
7345  	 	 	 	 $img->setImageFormat('png');
7346  	 	 	 	 $img->writeImage($tempfile_alpha);
7347  	 	 	 	 // remove alpha channel
7348  	 	 	 	 if (method_exists($imga, 'setImageMatte')) {
7349  	 	 	 	 	 $imga->setImageMatte(false);
7350  	 	 	 	 } else {
7351  	 	 	 	 	 $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
7352  	 	 	 	 }
7353  	 	 	 	 $imga->setImageFormat('png');
7354  	 	 	 	 $imga->writeImage($tempfile_plain);
7355  	 	 	 	 $parsed = true;
7356  	 	 	 } catch (Exception $e) {
7357  	 	 	 	 // Imagemagick fails, try with GD
7358  	 	 	 	 $parse_error = 'Imagick library error: '.$e->getMessage();
7359  	 	 	 }
7360  	 	 }
7361  	 	 // GD extension
7362  	 	 if (($parsed === false) AND function_exists('imagecreatefrompng')) {
7363  	 	 	 try {
7364  	 	 	 	 // generate images
7365  	 	 	 	 $img = imagecreatefrompng($file);
7366  	 	 	 	 $imgalpha = imagecreate($wpx, $hpx);
7367  	 	 	 	 // generate gray scale palette (0 -> 255)
7368  	 	 	 	 for ($c = 0; $c < 256; ++$c) {
7369  	 	 	 	 	 ImageColorAllocate($imgalpha, $c, $c, $c);
7370  	 	 	 	 }
7371  	 	 	 	 // extract alpha channel
7372  	 	 	 	 for ($xpx = 0; $xpx < $wpx; ++$xpx) {
7373  	 	 	 	 	 for ($ypx = 0; $ypx < $hpx; ++$ypx) {
7374  	 	 	 	 	 	 $color = imagecolorat($img, $xpx, $ypx);
7375  	 	 	 	 	 	 // get and correct gamma color
7376  	 	 	 	 	 	 $alpha = $this->getGDgamma($img, $color);
7377  	 	 	 	 	 	 imagesetpixel($imgalpha, (int) $xpx, (int) $ypx, (int) $alpha);
7378  	 	 	 	 	 }
7379  	 	 	 	 }
7380  	 	 	 	 imagepng($imgalpha, $tempfile_alpha);
7381  	 	 	 	 imagedestroy($imgalpha);
7382  	 	 	 	 // extract image without alpha channel
7383  	 	 	 	 $imgplain = imagecreatetruecolor($wpx, $hpx);
7384  	 	 	 	 imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
7385  	 	 	 	 imagepng($imgplain, $tempfile_plain);
7386  	 	 	 	 imagedestroy($imgplain);
7387  	 	 	 	 $parsed = true;
7388  	 	 	 } catch (Exception $e) {
7389  	 	 	 	 // GD fails
7390  	 	 	 	 $parse_error = 'GD library error: '.$e->getMessage();
7391  	 	 	 }
7392  	 	 }
7393  	 	 if ($parsed === false) {
7394  	 	 	 if (empty($parse_error)) {
7395  	 	 	 	 $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
7396  	 	 	 } else {
7397  	 	 	 	 $this->Error($parse_error);
7398  	 	 	 }
7399  	 	 }
7400  	 	 // embed mask image
7401  	 	 $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
7402  	 	 // embed image, masked with previously embedded mask
7403  	 	 $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
7404  	 }
7405  
7406  	 /**
7407  	  * Get the GD-corrected PNG gamma value from alpha color
7408  	  * @param resource $img GD image Resource ID.
7409  	  * @param int $c alpha color
7410  	  * @protected
7411  	  * @since 4.3.007 (2008-12-04)
7412  	  */
7413  	protected function getGDgamma($img, $c) {
7414  	 	 if (!isset($this->gdgammacache['#'.$c])) {
7415  	 	 	 $colors = imagecolorsforindex($img, $c);
7416  	 	 	 // GD alpha is only 7 bit (0 -> 127)
7417  	 	 	 $this->gdgammacache['#'.$c] = (int) (((127 - $colors['alpha']) / 127) * 255);
7418  	 	 	 // correct gamma
7419  	 	 	 $this->gdgammacache['#'.$c] = (int) (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
7420  	 	 	 // store the latest values on cache to improve performances
7421  	 	 	 if (count($this->gdgammacache) > 8) {
7422  	 	 	 	 // remove one element from the cache array
7423  	 	 	 	 array_shift($this->gdgammacache);
7424  	 	 	 }
7425  	 	 }
7426  	 	 return $this->gdgammacache['#'.$c];
7427  	 }
7428  
7429  	 /**
7430  	  * Performs a line break.
7431  	  * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
7432  	  * @param float|null $h The height of the break. By default, the value equals the height of the last printed cell.
7433  	  * @param boolean $cell if true add the current left (or right o for RTL) padding to the X coordinate
7434  	  * @public
7435  	  * @since 1.0
7436  	  * @see Cell()
7437  	  */
7438  	 public function Ln($h=null, $cell=false) {
7439  	 	 if (($this->num_columns > 1) AND ($this->y == $this->columns[$this->current_column]['y']) AND isset($this->columns[$this->current_column]['x']) AND ($this->x == $this->columns[$this->current_column]['x'])) {
7440  	 	 	 // revove vertical space from the top of the column
7441  	 	 	 return;
7442  	 	 }
7443  	 	 if ($cell) {
7444  	 	 	 if ($this->rtl) {
7445  	 	 	 	 $cellpadding = $this->cell_padding['R'];
7446  	 	 	 } else {
7447  	 	 	 	 $cellpadding = $this->cell_padding['L'];
7448  	 	 	 }
7449  	 	 } else {
7450  	 	 	 $cellpadding = 0;
7451  	 	 }
7452  	 	 if ($this->rtl) {
7453  	 	 	 $this->x = $this->w - $this->rMargin - $cellpadding;
7454  	 	 } else {
7455  	 	 	 $this->x = $this->lMargin + $cellpadding;
7456  	 	 }
7457  	 	 if (TCPDF_STATIC::empty_string($h)) {
7458  	 	 	 $h = $this->lasth;
7459  	 	 }
7460  	 	 $this->y += $h;
7461  	 	 $this->newline = true;
7462  	 }
7463  
7464  	 /**
7465  	  * Returns the relative X value of current position.
7466  	  * The value is relative to the left border for LTR languages and to the right border for RTL languages.
7467  	  * @return float
7468  	  * @public
7469  	  * @since 1.2
7470  	  * @see SetX(), GetY(), SetY()
7471  	  */
7472  	public function GetX() {
7473  	 	 //Get x position
7474  	 	 if ($this->rtl) {
7475  	 	 	 return ($this->w - $this->x);
7476  	 	 } else {
7477  	 	 	 return $this->x;
7478  	 	 }
7479  	 }
7480  
7481  	 /**
7482  	  * Returns the absolute X value of current position.
7483  	  * @return float
7484  	  * @public
7485  	  * @since 1.2
7486  	  * @see SetX(), GetY(), SetY()
7487  	  */
7488  	public function GetAbsX() {
7489  	 	 return $this->x;
7490  	 }
7491  
7492  	 /**
7493  	  * Returns the ordinate of the current position.
7494  	  * @return float
7495  	  * @public
7496  	  * @since 1.0
7497  	  * @see SetY(), GetX(), SetX()
7498  	  */
7499  	public function GetY() {
7500  	 	 return $this->y;
7501  	 }
7502  
7503  	 /**
7504  	  * Defines the abscissa of the current position.
7505  	  * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
7506  	  * @param float $x The value of the abscissa in user units.
7507  	  * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
7508  	  * @public
7509  	  * @since 1.2
7510  	  * @see GetX(), GetY(), SetY(), SetXY()
7511  	  */
7512  	public function setX($x, $rtloff=false) {
7513  	 	 $x = floatval($x);
7514  	 	 if (!$rtloff AND $this->rtl) {
7515  	 	 	 if ($x >= 0) {
7516  	 	 	 	 $this->x = $this->w - $x;
7517  	 	 	 } else {
7518  	 	 	 	 $this->x = abs($x);
7519  	 	 	 }
7520  	 	 } else {
7521  	 	 	 if ($x >= 0) {
7522  	 	 	 	 $this->x = $x;
7523  	 	 	 } else {
7524  	 	 	 	 $this->x = $this->w + $x;
7525  	 	 	 }
7526  	 	 }
7527  	 	 if ($this->x < 0) {
7528  	 	 	 $this->x = 0;
7529  	 	 }
7530  	 	 if ($this->x > $this->w) {
7531  	 	 	 $this->x = $this->w;
7532  	 	 }
7533  	 }
7534  
7535  	 /**
7536  	  * Moves the current abscissa back to the left margin and sets the ordinate.
7537  	  * If the passed value is negative, it is relative to the bottom of the page.
7538  	  * @param float $y The value of the ordinate in user units.
7539  	  * @param bool $resetx if true (default) reset the X position.
7540  	  * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
7541  	  * @public
7542  	  * @since 1.0
7543  	  * @see GetX(), GetY(), SetY(), SetXY()
7544  	  */
7545  	public function setY($y, $resetx=true, $rtloff=false) {
7546  	 	 $y = floatval($y);
7547  	 	 if ($resetx) {
7548  	 	 	 //reset x
7549  	 	 	 if (!$rtloff AND $this->rtl) {
7550  	 	 	 	 $this->x = $this->w - $this->rMargin;
7551  	 	 	 } else {
7552  	 	 	 	 $this->x = $this->lMargin;
7553  	 	 	 }
7554  	 	 }
7555  	 	 if ($y >= 0) {
7556  	 	 	 $this->y = $y;
7557  	 	 } else {
7558  	 	 	 $this->y = $this->h + $y;
7559  	 	 }
7560  	 	 if ($this->y < 0) {
7561  	 	 	 $this->y = 0;
7562  	 	 }
7563  	 	 if ($this->y > $this->h) {
7564  	 	 	 $this->y = $this->h;
7565  	 	 }
7566  	 }
7567  
7568  	 /**
7569  	  * Defines the abscissa and ordinate of the current position.
7570  	  * If the passed values are negative, they are relative respectively to the right and bottom of the page.
7571  	  * @param float $x The value of the abscissa.
7572  	  * @param float $y The value of the ordinate.
7573  	  * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
7574  	  * @public
7575  	  * @since 1.2
7576  	  * @see SetX(), SetY()
7577  	  */
7578  	public function setXY($x, $y, $rtloff=false) {
7579  	 	 $this->setY($y, false, $rtloff);
7580  	 	 $this->setX($x, $rtloff);
7581  	 }
7582  
7583  	 /**
7584  	  * Set the absolute X coordinate of the current pointer.
7585  	  * @param float $x The value of the abscissa in user units.
7586  	  * @public
7587  	  * @since 5.9.186 (2012-09-13)
7588  	  * @see setAbsX(), setAbsY(), SetAbsXY()
7589  	  */
7590  	public function setAbsX($x) {
7591  	 	 $this->x = floatval($x);
7592  	 }
7593  
7594  	 /**
7595  	  * Set the absolute Y coordinate of the current pointer.
7596  	  * @param float $y (float) The value of the ordinate in user units.
7597  	  * @public
7598  	  * @since 5.9.186 (2012-09-13)
7599  	  * @see setAbsX(), setAbsY(), SetAbsXY()
7600  	  */
7601  	public function setAbsY($y) {
7602  	 	 $this->y = floatval($y);
7603  	 }
7604  
7605  	 /**
7606  	  * Set the absolute X and Y coordinates of the current pointer.
7607  	  * @param float $x The value of the abscissa in user units.
7608  	  * @param float $y (float) The value of the ordinate in user units.
7609  	  * @public
7610  	  * @since 5.9.186 (2012-09-13)
7611  	  * @see setAbsX(), setAbsY(), SetAbsXY()
7612  	  */
7613  	public function setAbsXY($x, $y) {
7614  	 	 $this->setAbsX($x);
7615  	 	 $this->setAbsY($y);
7616  	 }
7617  
7618  	 /**
7619  	  * Send the document to a given destination: string, local file or browser.
7620  	  * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
7621  	  * The method first calls Close() if necessary to terminate the document.
7622  	  * @param string $name The name of the file when saved
7623  	  * @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>
7624  	  * @return string
7625  	  * @public
7626  	  * @since 1.0
7627  	  * @see Close()
7628  	  */
7629  	public function Output($name='doc.pdf', $dest='I') {
7630  	 	 //Output PDF to some destination
7631  	 	 //Finish document if necessary
7632  	 	 if ($this->state < 3) {
7633  	 	 	 $this->Close();
7634  	 	 }
7635  	 	 //Normalize parameters
7636  	 	 if (is_bool($dest)) {
7637  	 	 	 $dest = $dest ? 'D' : 'F';
7638  	 	 }
7639  	 	 $dest = strtoupper($dest);
7640  
7641  	 	 if ($this->sign) {
7642  	 	 	 // *** apply digital signature to the document ***
7643  	 	 	 // get the document content
7644  	 	 	 $pdfdoc = $this->getBuffer();
7645  	 	 	 // remove last newline
7646  	 	 	 $pdfdoc = substr($pdfdoc, 0, -1);
7647  	 	 	 // remove filler space
7648  	 	 	 $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
7649  	 	 	 // define the ByteRange
7650  	 	 	 $byte_range = array();
7651  	 	 	 $byte_range[0] = 0;
7652  	 	 	 $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
7653  	 	 	 $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
7654  	 	 	 $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
7655  	 	 	 $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
7656  	 	 	 // replace the ByteRange
7657  	 	 	 $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
7658  	 	 	 $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
7659  	 	 	 $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
7660  	 	 	 // write the document to a temporary folder
7661  	 	 	 $tempdoc = TCPDF_STATIC::getObjFilename('doc', $this->file_id);
7662  	 	 	 $f = TCPDF_STATIC::fopenLocal($tempdoc, 'wb');
7663  	 	 	 if (!$f) {
7664  	 	 	 	 $this->Error('Unable to create temporary file: '.$tempdoc);
7665  	 	 	 }
7666  	 	 	 $pdfdoc_length = strlen($pdfdoc);
7667  	 	 	 fwrite($f, $pdfdoc, $pdfdoc_length);
7668  	 	 	 fclose($f);
7669  	 	 	 // get digital signature via openssl library
7670  	 	 	 $tempsign = TCPDF_STATIC::getObjFilename('sig', $this->file_id);
7671  	 	 	 if (empty($this->signature_data['extracerts'])) {
7672  	 	 	 	 openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
7673  	 	 	 } else {
7674  	 	 	 	 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']);
7675  	 	 	 }
7676  	 	 	 // read signature
7677  	 	 	 $signature = file_get_contents($tempsign);
7678  	 	 	 // extract signature
7679  	 	 	 $signature = substr($signature, $pdfdoc_length);
7680  	 	 	 $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
7681  	 	 	 $tmparr = explode("\n\n", $signature);
7682  	 	 	 $signature = $tmparr[1];
7683  	 	 	 // decode signature
7684  	 	 	 $signature = base64_decode(trim($signature));
7685  	 	 	 // add TSA timestamp to signature
7686  	 	 	 $signature = $this->applyTSA($signature);
7687  	 	 	 // convert signature to hex
7688  	 	 	 $signature = current(unpack('H*', $signature));
7689  	 	 	 $signature = str_pad($signature, $this->signature_max_length, '0');
7690  	 	 	 // Add signature to the document
7691  	 	 	 $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
7692  	 	 	 $this->bufferlen = strlen($this->buffer);
7693  	 	 }
7694  	 	 switch($dest) {
7695  	 	 	 case 'I': {
7696  	 	 	 	 // Send PDF to the standard output
7697  	 	 	 	 if (ob_get_contents()) {
7698  	 	 	 	 	 $this->Error('Some data has already been output, can\'t send PDF file');
7699  	 	 	 	 }
7700  	 	 	 	 if (php_sapi_name() != 'cli') {
7701  	 	 	 	 	 // send output to a browser
7702  	 	 	 	 	 header('Content-Type: application/pdf');
7703  	 	 	 	 	 if (headers_sent()) {
7704  	 	 	 	 	 	 $this->Error('Some data has already been output to browser, can\'t send PDF file');
7705  	 	 	 	 	 }
7706  	 	 	 	 	 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7707  	 	 	 	 	 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
7708  	 	 	 	 	 header('Pragma: public');
7709  	 	 	 	 	 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7710  	 	 	 	 	 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7711  	 	 	 	 	 header('Content-Disposition: inline; filename="' . rawurlencode(basename($name)) . '"; ' .
7712  	 	 	 	 	 	 'filename*=UTF-8\'\'' . rawurlencode(basename($name)));
7713  	 	 	 	 	 TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
7714  	 	 	 	 } else {
7715  	 	 	 	 	 echo $this->getBuffer();
7716  	 	 	 	 }
7717  	 	 	 	 break;
7718  	 	 	 }
7719  	 	 	 case 'D': {
7720  	 	 	 	 // download PDF as file
7721  	 	 	 	 if (ob_get_contents()) {
7722  	 	 	 	 	 $this->Error('Some data has already been output, can\'t send PDF file');
7723  	 	 	 	 }
7724  	 	 	 	 header('Content-Description: File Transfer');
7725  	 	 	 	 if (headers_sent()) {
7726  	 	 	 	 	 $this->Error('Some data has already been output to browser, can\'t send PDF file');
7727  	 	 	 	 }
7728  	 	 	 	 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7729  	 	 	 	 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
7730  	 	 	 	 header('Pragma: public');
7731  	 	 	 	 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7732  	 	 	 	 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7733  	 	 	 	 // force download dialog
7734  	 	 	 	 if (strpos(php_sapi_name(), 'cgi') === false) {
7735  	 	 	 	 	 header('Content-Type: application/force-download');
7736  	 	 	 	 	 header('Content-Type: application/octet-stream', false);
7737  	 	 	 	 	 header('Content-Type: application/download', false);
7738  	 	 	 	 	 header('Content-Type: application/pdf', false);
7739  	 	 	 	 } else {
7740  	 	 	 	 	 header('Content-Type: application/pdf');
7741  	 	 	 	 }
7742  	 	 	 	 // use the Content-Disposition header to supply a recommended filename
7743  	 	 	 	 header('Content-Disposition: attachment; filename="' . rawurlencode(basename($name)) . '"; ' .
7744  	 	 	 	 	 'filename*=UTF-8\'\'' . rawurlencode(basename($name)));
7745  	 	 	 	 header('Content-Transfer-Encoding: binary');
7746  	 	 	 	 TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
7747  	 	 	 	 break;
7748  	 	 	 }
7749  	 	 	 case 'F':
7750  	 	 	 case 'FI':
7751  	 	 	 case 'FD': {
7752  	 	 	 	 // save PDF to a local file
7753  	 	 	 	 $f = TCPDF_STATIC::fopenLocal($name, 'wb');
7754  	 	 	 	 if (!$f) {
7755  	 	 	 	 	 $this->Error('Unable to create output file: '.$name);
7756  	 	 	 	 }
7757  	 	 	 	 fwrite($f, $this->getBuffer(), $this->bufferlen);
7758  	 	 	 	 fclose($f);
7759  	 	 	 	 if ($dest == 'FI') {
7760  	 	 	 	 	 // send headers to browser
7761  	 	 	 	 	 header('Content-Type: application/pdf');
7762  	 	 	 	 	 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7763  	 	 	 	 	 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
7764  	 	 	 	 	 header('Pragma: public');
7765  	 	 	 	 	 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7766  	 	 	 	 	 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7767  	 	 	 	 	 header('Content-Disposition: inline; filename="'.basename($name).'"');
7768  	 	 	 	 	 TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
7769  	 	 	 	 } elseif ($dest == 'FD') {
7770  	 	 	 	 	 // send headers to browser
7771  	 	 	 	 	 if (ob_get_contents()) {
7772  	 	 	 	 	 	 $this->Error('Some data has already been output, can\'t send PDF file');
7773  	 	 	 	 	 }
7774  	 	 	 	 	 header('Content-Description: File Transfer');
7775  	 	 	 	 	 if (headers_sent()) {
7776  	 	 	 	 	 	 $this->Error('Some data has already been output to browser, can\'t send PDF file');
7777  	 	 	 	 	 }
7778  	 	 	 	 	 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7779  	 	 	 	 	 header('Pragma: public');
7780  	 	 	 	 	 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7781  	 	 	 	 	 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7782  	 	 	 	 	 // force download dialog
7783  	 	 	 	 	 if (strpos(php_sapi_name(), 'cgi') === false) {
7784  	 	 	 	 	 	 header('Content-Type: application/force-download');
7785  	 	 	 	 	 	 header('Content-Type: application/octet-stream', false);
7786  	 	 	 	 	 	 header('Content-Type: application/download', false);
7787  	 	 	 	 	 	 header('Content-Type: application/pdf', false);
7788  	 	 	 	 	 } else {
7789  	 	 	 	 	 	 header('Content-Type: application/pdf');
7790  	 	 	 	 	 }
7791  	 	 	 	 	 // use the Content-Disposition header to supply a recommended filename
7792  	 	 	 	 	 header('Content-Disposition: attachment; filename="'.basename($name).'"');
7793  	 	 	 	 	 header('Content-Transfer-Encoding: binary');
7794  	 	 	 	 	 TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
7795  	 	 	 	 }
7796  	 	 	 	 break;
7797  	 	 	 }
7798  	 	 	 case 'E': {
7799  	 	 	 	 // return PDF as base64 mime multi-part email attachment (RFC 2045)
7800  	 	 	 	 $retval = 'Content-Type: application/pdf;'."\r\n";
7801  	 	 	 	 $retval .= ' name="'.$name.'"'."\r\n";
7802  	 	 	 	 $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
7803  	 	 	 	 $retval .= 'Content-Disposition: attachment;'."\r\n";
7804  	 	 	 	 $retval .= ' filename="'.$name.'"'."\r\n\r\n";
7805  	 	 	 	 $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
7806  	 	 	 	 return $retval;
7807  	 	 	 }
7808  	 	 	 case 'S': {
7809  	 	 	 	 // returns PDF as a string
7810  	 	 	 	 return $this->getBuffer();
7811  	 	 	 }
7812  	 	 	 default: {
7813  	 	 	 	 $this->Error('Incorrect output destination: '.$dest);
7814  	 	 	 }
7815  	 	 }
7816  	 	 return '';
7817  	 }
7818  
7819  	 protected static $cleaned_ids = array();
7820  	 /**
7821  	  * Unset all class variables except the following critical variables.
7822  	  * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
7823  	  * @param boolean $preserve_objcopy if true preserves the objcopy variable
7824  	  * @public
7825  	  * @since 4.5.016 (2009-02-24)
7826  	  */
7827  	public function _destroy($destroyall=false, $preserve_objcopy=false) {
7828  	 	 if (isset(self::$cleaned_ids[$this->file_id])) {
7829  	 	 	 $destroyall = false;
7830  	 	 }
7831  	 	 if ($destroyall AND !$preserve_objcopy && isset($this->file_id)) {
7832  	 	 	 self::$cleaned_ids[$this->file_id] = true;
7833  	 	 	 // remove all temporary files
7834  	 	 	 if ($handle = @opendir(K_PATH_CACHE)) {
7835  	 	 	 	 while ( false !== ( $file_name = readdir( $handle ) ) ) {
7836  	 	 	 	 	 if (strpos($file_name, '__tcpdf_'.$this->file_id.'_') === 0) {
7837  	 	 	 	 	 	 unlink(K_PATH_CACHE.$file_name);
7838  	 	 	 	 	 }
7839  	 	 	 	 }
7840  	 	 	 	 closedir($handle);
7841  	 	 	 }
7842  	 	 	 if (isset($this->imagekeys)) {
7843  	 	 	 	 foreach($this->imagekeys as $file) {
7844  	 	 	 	 	 if (strpos($file, K_PATH_CACHE) === 0 && TCPDF_STATIC::file_exists($file)) {
7845  	 	 	 	 	 	 @unlink($file);
7846  	 	 	 	 	 }
7847  	 	 	 	 }
7848  	 	 	 }
7849  	 	 }
7850  	 	 $preserve = array(
7851  	 	 	 'file_id',
7852  	 	 	 'state',
7853  	 	 	 'bufferlen',
7854  	 	 	 'buffer',
7855  	 	 	 'cached_files',
7856  	 	 	 'imagekeys',
7857  	 	 	 'sign',
7858  	 	 	 'signature_data',
7859  	 	 	 'signature_max_length',
7860  	 	 	 'byterange_string',
7861  	 	 	 'tsa_timestamp',
7862  	 	 	 'tsa_data'
7863  	 	 );
7864  	 	 foreach (array_keys(get_object_vars($this)) as $val) {
7865  	 	 	 if ($destroyall OR !in_array($val, $preserve)) {
7866  	 	 	 	 if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
7867  	 	 	 	 	 unset($this->$val);
7868  	 	 	 	 }
7869  	 	 	 }
7870  	 	 }
7871  	 }
7872  
7873  	 /**
7874  	  * Check for locale-related bug
7875  	  * @protected
7876  	  */
7877  	protected function _dochecks() {
7878  	 	 //Check for locale-related bug
7879  	 	 if (1.1 == 1) {
7880  	 	 	 $this->Error('Don\'t alter the locale before including class file');
7881  	 	 }
7882  	 	 //Check for decimal separator
7883  	 	 if (sprintf('%.1F', 1.0) != '1.0') {
7884  	 	 	 setlocale(LC_NUMERIC, 'C');
7885  	 	 }
7886  	 }
7887  
7888  	 /**
7889  	  * Return an array containing variations for the basic page number alias.
7890  	  * @param string $a Base alias.
7891  	  * @return array of page number aliases
7892  	  * @protected
7893  	  */
7894  	protected function getInternalPageNumberAliases($a= '') {
7895  	 	 $alias = array();
7896  	 	 // build array of Unicode + ASCII variants (the order is important)
7897  	 	 $alias = array('u' => array(), 'a' => array());
7898  	 	 $u = '{'.$a.'}';
7899  	 	 $alias['u'][] = TCPDF_STATIC::_escape($u);
7900  	 	 if ($this->isunicode) {
7901  	 	 	 $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
7902  	 	 	 $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
7903  	 	 	 $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
7904  	 	 	 $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
7905  	 	 }
7906  	 	 $alias['a'][] = TCPDF_STATIC::_escape($a);
7907  	 	 return $alias;
7908  	 }
7909  
7910  	 /**
7911  	  * Return an array containing all internal page aliases.
7912  	  * @return array of page number aliases
7913  	  * @protected
7914  	  */
7915  	protected function getAllInternalPageNumberAliases() {
7916  	 	 $basic_alias = array(TCPDF_STATIC::$alias_tot_pages, TCPDF_STATIC::$alias_num_page, TCPDF_STATIC::$alias_group_tot_pages, TCPDF_STATIC::$alias_group_num_page, TCPDF_STATIC::$alias_right_shift);
7917  	 	 $pnalias = array();
7918  	 	 foreach($basic_alias as $k => $a) {
7919  	 	 	 $pnalias[$k] = $this->getInternalPageNumberAliases($a);
7920  	 	 }
7921  	 	 return $pnalias;
7922  	 }
7923  
7924  	 /**
7925  	  * Replace right shift page number aliases with spaces to correct right alignment.
7926  	  * This works perfectly only when using monospaced fonts.
7927  	  * @param string $page Page content.
7928  	  * @param array $aliases Array of page aliases.
7929  	  * @param int $diff initial difference to add.
7930  	  * @return string replaced page content.
7931  	  * @protected
7932  	  */
7933  	protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
7934  	 	 foreach ($aliases as $type => $alias) {
7935  	 	 	 foreach ($alias as $a) {
7936  	 	 	 	 // find position of compensation factor
7937  	 	 	 	 $startnum = (strpos($a, ':') + 1);
7938  	 	 	 	 $a = substr($a, 0, $startnum);
7939  	 	 	 	 if (($pos = strpos($page, $a)) !== false) {
7940  	 	 	 	 	 // end of alias
7941  	 	 	 	 	 $endnum = strpos($page, '}', $pos);
7942  	 	 	 	 	 // string to be replaced
7943  	 	 	 	 	 $aa = substr($page, $pos, ($endnum - $pos + 1));
7944  	 	 	 	 	 // get compensation factor
7945  	 	 	 	 	 $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
7946  	 	 	 	 	 $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
7947  	 	 	 	 	 $ratio = floatval($ratio);
7948  	 	 	 	 	 if ($type == 'u') {
7949  	 	 	 	 	 	 $chrdiff = floor(($diff + 12) * $ratio);
7950  	 	 	 	 	 	 $shift = str_repeat(' ', $chrdiff);
7951  	 	 	 	 	 	 $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
7952  	 	 	 	 	 } else {
7953  	 	 	 	 	 	 $chrdiff = floor(($diff + 11) * $ratio);
7954  	 	 	 	 	 	 $shift = str_repeat(' ', $chrdiff);
7955  	 	 	 	 	 }
7956  	 	 	 	 	 $page = str_replace($aa, $shift, $page);
7957  	 	 	 	 }
7958  	 	 	 }
7959  	 	 }
7960  	 	 return $page;
7961  	 }
7962  
7963  	 /**
7964  	  * Set page boxes to be included on page descriptions.
7965  	  * @param array $boxes Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
7966  	  * @protected
7967  	  */
7968  	protected function setPageBoxTypes($boxes) {
7969  	 	 $this->page_boxes = array();
7970  	 	 foreach ($boxes as $box) {
7971  	 	 	 if (in_array($box, TCPDF_STATIC::$pageboxes)) {
7972  	 	 	 	 $this->page_boxes[] = $box;
7973  	 	 	 }
7974  	 	 }
7975  	 }
7976  
7977  	 /**
7978  	  * Output pages (and replace page number aliases).
7979  	  * @protected
7980  	  */
7981  	protected function _putpages() {
7982  	 	 $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
7983  	 	 // get internal aliases for page numbers
7984  	 	 $pnalias = $this->getAllInternalPageNumberAliases();
7985  	 	 $num_pages = $this->numpages;
7986  	 	 $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
7987  	 	 $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
7988  	 	 $ptp_num_chars = $this->GetNumChars($ptpa);
7989  	 	 $pagegroupnum = 0;
7990  	 	 $groupnum = 0;
7991  	 	 $ptgu = 1;
7992  	 	 $ptga = 1;
7993  	 	 $ptg_num_chars = 1;
7994  	 	 for ($n = 1; $n <= $num_pages; ++$n) {
7995  	 	 	 // get current page
7996  	 	 	 $temppage = $this->getPageBuffer($n);
7997  	 	 	 $pagelen = strlen($temppage);
7998  	 	 	 // set replacements for total pages number
7999  	 	 	 $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
8000  	 	 	 $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
8001  	 	 	 $pnp_num_chars = $this->GetNumChars($pnpa);
8002  	 	 	 $pdiff = 0; // difference used for right shift alignment of page numbers
8003  	 	 	 $gdiff = 0; // difference used for right shift alignment of page group numbers
8004  	 	 	 if (!empty($this->pagegroups)) {
8005  	 	 	 	 if (isset($this->newpagegroup[$n])) {
8006  	 	 	 	 	 $pagegroupnum = 0;
8007  	 	 	 	 	 ++$groupnum;
8008  	 	 	 	 	 $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
8009  	 	 	 	 	 $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
8010  	 	 	 	 	 $ptg_num_chars = $this->GetNumChars($ptga);
8011  	 	 	 	 }
8012  	 	 	 	 ++$pagegroupnum;
8013  	 	 	 	 $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
8014  	 	 	 	 $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
8015  	 	 	 	 $png_num_chars = $this->GetNumChars($pnga);
8016  	 	 	 	 // replace page numbers
8017  	 	 	 	 $replace = array();
8018  	 	 	 	 $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
8019  	 	 	 	 $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
8020  	 	 	 	 $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
8021  	 	 	 	 $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
8022  	 	 	 	 list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
8023  	 	 	 }
8024  	 	 	 // replace page numbers
8025  	 	 	 $replace = array();
8026  	 	 	 $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
8027  	 	 	 $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
8028  	 	 	 $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
8029  	 	 	 $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
8030  	 	 	 list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
8031  	 	 	 // replace right shift alias
8032  	 	 	 $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
8033  	 	 	 // replace EPS marker
8034  	 	 	 $temppage = str_replace($this->epsmarker, '', $temppage);
8035  	 	 	 //Page
8036  	 	 	 $this->page_obj_id[$n] = $this->_newobj();
8037  	 	 	 $out = '<<';
8038  	 	 	 $out .= ' /Type /Page';
8039  	 	 	 $out .= ' /Parent 1 0 R';
8040  	 	 	 if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
8041  	 	 	 	 $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
8042  	 	 	 }
8043  	 	 	 $out .= ' /Resources 2 0 R';
8044  	 	 	 foreach ($this->page_boxes as $box) {
8045  	 	 	 	 $out .= ' /'.$box;
8046  	 	 	 	 $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']);
8047  	 	 	 }
8048  	 	 	 if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
8049  	 	 	 	 $out .= ' /BoxColorInfo <<';
8050  	 	 	 	 foreach ($this->page_boxes as $box) {
8051  	 	 	 	 	 if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
8052  	 	 	 	 	 	 $out .= ' /'.$box.' <<';
8053  	 	 	 	 	 	 if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
8054  	 	 	 	 	 	 	 $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
8055  	 	 	 	 	 	 	 $out .= ' /C [';
8056  	 	 	 	 	 	 	 $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
8057  	 	 	 	 	 	 	 $out .= ' ]';
8058  	 	 	 	 	 	 }
8059  	 	 	 	 	 	 if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
8060  	 	 	 	 	 	 	 $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
8061  	 	 	 	 	 	 }
8062  	 	 	 	 	 	 if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
8063  	 	 	 	 	 	 	 $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
8064  	 	 	 	 	 	 }
8065  	 	 	 	 	 	 if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
8066  	 	 	 	 	 	 	 $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
8067  	 	 	 	 	 	 	 $out .= ' /D [';
8068  	 	 	 	 	 	 	 foreach ($dashes as $dash) {
8069  	 	 	 	 	 	 	 	 $out .= sprintf(' %F', ($dash * $this->k));
8070  	 	 	 	 	 	 	 }
8071  	 	 	 	 	 	 	 $out .= ' ]';
8072  	 	 	 	 	 	 }
8073  	 	 	 	 	 	 $out .= ' >>';
8074  	 	 	 	 	 }
8075  	 	 	 	 }
8076  	 	 	 	 $out .= ' >>';
8077  	 	 	 }
8078  	 	 	 $out .= ' /Contents '.($this->n + 1).' 0 R';
8079  	 	 	 $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
8080  	 	 	 if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
8081  	 	 	 	 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
8082  	 	 	 }
8083  	 	 	 if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
8084  	 	 	 	 // page transitions
8085  	 	 	 	 if (isset($this->pagedim[$n]['trans']['Dur'])) {
8086  	 	 	 	 	 $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
8087  	 	 	 	 }
8088  	 	 	 	 $out .= ' /Trans <<';
8089  	 	 	 	 $out .= ' /Type /Trans';
8090  	 	 	 	 if (isset($this->pagedim[$n]['trans']['S'])) {
8091  	 	 	 	 	 $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
8092  	 	 	 	 }
8093  	 	 	 	 if (isset($this->pagedim[$n]['trans']['D'])) {
8094  	 	 	 	 	 $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
8095  	 	 	 	 }
8096  	 	 	 	 if (isset($this->pagedim[$n]['trans']['Dm'])) {
8097  	 	 	 	 	 $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
8098  	 	 	 	 }
8099  	 	 	 	 if (isset($this->pagedim[$n]['trans']['M'])) {
8100  	 	 	 	 	 $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
8101  	 	 	 	 }
8102  	 	 	 	 if (isset($this->pagedim[$n]['trans']['Di'])) {
8103  	 	 	 	 	 $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
8104  	 	 	 	 }
8105  	 	 	 	 if (isset($this->pagedim[$n]['trans']['SS'])) {
8106  	 	 	 	 	 $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
8107  	 	 	 	 }
8108  	 	 	 	 if (isset($this->pagedim[$n]['trans']['B'])) {
8109  	 	 	 	 	 $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
8110  	 	 	 	 }
8111  	 	 	 	 $out .= ' >>';
8112  	 	 	 }
8113  	 	 	 $out .= $this->_getannotsrefs($n);
8114  	 	 	 $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
8115  	 	 	 $out .= ' >>';
8116  	 	 	 $out .= "\n".'endobj';
8117  	 	 	 $this->_out($out);
8118  	 	 	 //Page content
8119  	 	 	 $p = ($this->compress) ? gzcompress($temppage) : $temppage;
8120  	 	 	 $this->_newobj();
8121  	 	 	 $p = $this->_getrawstream($p);
8122  	 	 	 $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
8123  	 	 }
8124  	 	 //Pages root
8125  	 	 $out = $this->_getobj(1)."\n";
8126  	 	 $out .= '<< /Type /Pages /Kids [';
8127  	 	 foreach($this->page_obj_id as $page_obj) {
8128  	 	 	 $out .= ' '.$page_obj.' 0 R';
8129  	 	 }
8130  	 	 $out .= ' ] /Count '.$num_pages.' >>';
8131  	 	 $out .= "\n".'endobj';
8132  	 	 $this->_out($out);
8133  	 }
8134  
8135  	 /**
8136  	  * Get references to page annotations.
8137  	  * @param int $n page number
8138  	  * @return string
8139  	  * @protected
8140  	  * @author Nicola Asuni
8141  	  * @since 5.0.010 (2010-05-17)
8142  	  */
8143  	protected function _getannotsrefs($n) {
8144  	 	 if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
8145  	 	 	 return '';
8146  	 	 }
8147  	 	 $out = ' /Annots [';
8148  	 	 if (isset($this->PageAnnots[$n])) {
8149  	 	 	 foreach ($this->PageAnnots[$n] as $key => $val) {
8150  	 	 	 	 if (!in_array($val['n'], $this->radio_groups)) {
8151  	 	 	 	 	 $out .= ' '.$val['n'].' 0 R';
8152  	 	 	 	 }
8153  	 	 	 }
8154  	 	 	 // add radiobutton groups
8155  	 	 	 if (isset($this->radiobutton_groups[$n])) {
8156  	 	 	 	 foreach ($this->radiobutton_groups[$n] as $key => $data) {
8157  	 	 	 	 	 if (isset($data['n'])) {
8158  	 	 	 	 	 	 $out .= ' '.$data['n'].' 0 R';
8159  	 	 	 	 	 }
8160  	 	 	 	 }
8161  	 	 	 }
8162  	 	 }
8163  	 	 if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
8164  	 	 	 // set reference for signature object
8165  	 	 	 $out .= ' '.$this->sig_obj_id.' 0 R';
8166  	 	 }
8167  	 	 if (!empty($this->empty_signature_appearance)) {
8168  	 	 	 foreach ($this->empty_signature_appearance as $esa) {
8169  	 	 	 	 if ($esa['page'] == $n) {
8170  	 	 	 	 	 // set reference for empty signature objects
8171  	 	 	 	 	 $out .= ' '.$esa['objid'].' 0 R';
8172  	 	 	 	 }
8173  	 	 	 }
8174  	 	 }
8175  	 	 $out .= ' ]';
8176  	 	 return $out;
8177  	 }
8178  
8179  	 /**
8180  	  * Output annotations objects for all pages.
8181  	  * !!! THIS METHOD IS NOT YET COMPLETED !!!
8182  	  * See section 12.5 of PDF 32000_2008 reference.
8183  	  * @protected
8184  	  * @author Nicola Asuni
8185  	  * @since 4.0.018 (2008-08-06)
8186  	  */
8187  	protected function _putannotsobjs() {
8188  	 	 // reset object counter
8189  	 	 for ($n=1; $n <= $this->numpages; ++$n) {
8190  	 	 	 if (isset($this->PageAnnots[$n])) {
8191  	 	 	 	 // set page annotations
8192  	 	 	 	 foreach ($this->PageAnnots[$n] as $key => $pl) {
8193  	 	 	 	 	 $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
8194  	 	 	 	 	 // create annotation object for grouping radiobuttons
8195  	 	 	 	 	 if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
8196  	 	 	 	 	 	 $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
8197  	 	 	 	 	 	 $annots = '<<';
8198  	 	 	 	 	 	 $annots .= ' /Type /Annot';
8199  	 	 	 	 	 	 $annots .= ' /Subtype /Widget';
8200  	 	 	 	 	 	 $annots .= ' /Rect [0 0 0 0]';
8201  	 	 	 	 	 	 if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
8202  	 	 	 	 	 	 	 // read only
8203  	 	 	 	 	 	 	 $annots .= ' /F 68';
8204  	 	 	 	 	 	 	 $annots .= ' /Ff 49153';
8205  	 	 	 	 	 	 } else {
8206  	 	 	 	 	 	 	 $annots .= ' /F 4'; // default print for PDF/A
8207  	 	 	 	 	 	 	 $annots .= ' /Ff 49152';
8208  	 	 	 	 	 	 }
8209  	 	 	 	 	 	 $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
8210  	 	 	 	 	 	 if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
8211  	 	 	 	 	 	 	 $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
8212  	 	 	 	 	 	 }
8213  	 	 	 	 	 	 $annots .= ' /FT /Btn';
8214  	 	 	 	 	 	 $annots .= ' /Kids [';
8215  	 	 	 	 	 	 $defval = '';
8216  	 	 	 	 	 	 foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
8217  	 	 	 	 	 	 	 if (isset($data['kid'])) {
8218  	 	 	 	 	 	 	 	 $annots .= ' '.$data['kid'].' 0 R';
8219  	 	 	 	 	 	 	 	 if ($data['def'] !== 'Off') {
8220  	 	 	 	 	 	 	 	 	 $defval = $data['def'];
8221  	 	 	 	 	 	 	 	 }
8222  	 	 	 	 	 	 	 }
8223  	 	 	 	 	 	 }
8224  	 	 	 	 	 	 $annots .= ' ]';
8225  	 	 	 	 	 	 if (!empty($defval)) {
8226  	 	 	 	 	 	 	 $annots .= ' /V /'.$defval;
8227  	 	 	 	 	 	 }
8228  	 	 	 	 	 	 $annots .= ' >>';
8229  	 	 	 	 	 	 $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
8230  	 	 	 	 	 	 $this->form_obj_id[] = $radio_button_obj_id;
8231  	 	 	 	 	 	 // store object id to be used on Parent entry of Kids
8232  	 	 	 	 	 	 $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
8233  	 	 	 	 	 }
8234  	 	 	 	 	 $formfield = false;
8235  	 	 	 	 	 $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
8236  	 	 	 	 	 $a = $pl['x'] * $this->k;
8237  	 	 	 	 	 $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
8238  	 	 	 	 	 $c = $pl['w'] * $this->k;
8239  	 	 	 	 	 $d = $pl['h'] * $this->k;
8240  	 	 	 	 	 $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
8241  	 	 	 	 	 // create new annotation object
8242  	 	 	 	 	 $annots = '<</Type /Annot';
8243  	 	 	 	 	 $annots .= ' /Subtype /'.$pl['opt']['subtype'];
8244  	 	 	 	 	 $annots .= ' /Rect ['.$rect.']';
8245  	 	 	 	 	 $ft = array('Btn', 'Tx', 'Ch', 'Sig');
8246  	 	 	 	 	 if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
8247  	 	 	 	 	 	 $annots .= ' /FT /'.$pl['opt']['ft'];
8248  	 	 	 	 	 	 $formfield = true;
8249  	 	 	 	 	 }
8250  	 	 	 	 	 if ($pl['opt']['subtype'] !== 'Link') {
8251  	 	 	 	 	 	 $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
8252  	 	 	 	 	 }
8253  	 	 	 	 	 $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
8254  	 	 	 	 	 $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
8255  	 	 	 	 	 $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
8256  	 	 	 	 	 if (isset($pl['opt']['f'])) {
8257  	 	 	 	 	 	 $fval = 0;
8258  	 	 	 	 	 	 if (is_array($pl['opt']['f'])) {
8259  	 	 	 	 	 	 	 foreach ($pl['opt']['f'] as $f) {
8260  	 	 	 	 	 	 	 	 switch (strtolower($f)) {
8261  	 	 	 	 	 	 	 	 	 case 'invisible': {
8262  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 0;
8263  	 	 	 	 	 	 	 	 	 	 break;
8264  	 	 	 	 	 	 	 	 	 }
8265  	 	 	 	 	 	 	 	 	 case 'hidden': {
8266  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 1;
8267  	 	 	 	 	 	 	 	 	 	 break;
8268  	 	 	 	 	 	 	 	 	 }
8269  	 	 	 	 	 	 	 	 	 case 'print': {
8270  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 2;
8271  	 	 	 	 	 	 	 	 	 	 break;
8272  	 	 	 	 	 	 	 	 	 }
8273  	 	 	 	 	 	 	 	 	 case 'nozoom': {
8274  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 3;
8275  	 	 	 	 	 	 	 	 	 	 break;
8276  	 	 	 	 	 	 	 	 	 }
8277  	 	 	 	 	 	 	 	 	 case 'norotate': {
8278  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 4;
8279  	 	 	 	 	 	 	 	 	 	 break;
8280  	 	 	 	 	 	 	 	 	 }
8281  	 	 	 	 	 	 	 	 	 case 'noview': {
8282  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 5;
8283  	 	 	 	 	 	 	 	 	 	 break;
8284  	 	 	 	 	 	 	 	 	 }
8285  	 	 	 	 	 	 	 	 	 case 'readonly': {
8286  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 6;
8287  	 	 	 	 	 	 	 	 	 	 break;
8288  	 	 	 	 	 	 	 	 	 }
8289  	 	 	 	 	 	 	 	 	 case 'locked': {
8290  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 8;
8291  	 	 	 	 	 	 	 	 	 	 break;
8292  	 	 	 	 	 	 	 	 	 }
8293  	 	 	 	 	 	 	 	 	 case 'togglenoview': {
8294  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 9;
8295  	 	 	 	 	 	 	 	 	 	 break;
8296  	 	 	 	 	 	 	 	 	 }
8297  	 	 	 	 	 	 	 	 	 case 'lockedcontents': {
8298  	 	 	 	 	 	 	 	 	 	 $fval += 1 << 10;
8299  	 	 	 	 	 	 	 	 	 	 break;
8300  	 	 	 	 	 	 	 	 	 }
8301  	 	 	 	 	 	 	 	 	 default: {
8302  	 	 	 	 	 	 	 	 	 	 break;
8303  	 	 	 	 	 	 	 	 	 }
8304  	 	 	 	 	 	 	 	 }
8305  	 	 	 	 	 	 	 }
8306  	 	 	 	 	 	 } else {
8307  	 	 	 	 	 	 	 $fval = intval($pl['opt']['f']);
8308  	 	 	 	 	 	 }
8309  	 	 	 	 	 } else {
8310  	 	 	 	 	 	 $fval = 4;
8311  	 	 	 	 	 }
8312  	 	 	 	 	 if ($this->pdfa_mode) {
8313  	 	 	 	 	 	 // force print flag for PDF/A mode
8314  	 	 	 	 	 	 $fval |= 4;
8315  	 	 	 	 	 }
8316  	 	 	 	 	 $annots .= ' /F '.intval($fval);
8317  	 	 	 	 	 if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
8318  	 	 	 	 	 	 $annots .= ' /AS /'.$pl['opt']['as'];
8319  	 	 	 	 	 }
8320  	 	 	 	 	 if (isset($pl['opt']['ap'])) {
8321  	 	 	 	 	 	 // appearance stream
8322  	 	 	 	 	 	 $annots .= ' /AP <<';
8323  	 	 	 	 	 	 if (is_array($pl['opt']['ap'])) {
8324  	 	 	 	 	 	 	 foreach ($pl['opt']['ap'] as $apmode => $apdef) {
8325  	 	 	 	 	 	 	 	 // $apmode can be: n = normal; r = rollover; d = down;
8326  	 	 	 	 	 	 	 	 $annots .= ' /'.strtoupper($apmode);
8327  	 	 	 	 	 	 	 	 if (is_array($apdef)) {
8328  	 	 	 	 	 	 	 	 	 $annots .= ' <<';
8329  	 	 	 	 	 	 	 	 	 foreach ($apdef as $apstate => $stream) {
8330  	 	 	 	 	 	 	 	 	 	 // reference to XObject that define the appearance for this mode-state
8331  	 	 	 	 	 	 	 	 	 	 $apsobjid = $this->_putAPXObject($c, $d, $stream);
8332  	 	 	 	 	 	 	 	 	 	 $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
8333  	 	 	 	 	 	 	 	 	 }
8334  	 	 	 	 	 	 	 	 	 $annots .= ' >>';
8335  	 	 	 	 	 	 	 	 } else {
8336  	 	 	 	 	 	 	 	 	 // reference to XObject that define the appearance for this mode
8337  	 	 	 	 	 	 	 	 	 $apsobjid = $this->_putAPXObject($c, $d, $apdef);
8338  	 	 	 	 	 	 	 	 	 $annots .= ' '.$apsobjid.' 0 R';
8339  	 	 	 	 	 	 	 	 }
8340  	 	 	 	 	 	 	 }
8341  	 	 	 	 	 	 } else {
8342  	 	 	 	 	 	 	 $annots .= $pl['opt']['ap'];
8343  	 	 	 	 	 	 }
8344  	 	 	 	 	 	 $annots .= ' >>';
8345  	 	 	 	 	 }
8346  	 	 	 	 	 if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
8347  	 	 	 	 	 	 $annots .= ' /BS <<';
8348  	 	 	 	 	 	 $annots .= ' /Type /Border';
8349  	 	 	 	 	 	 if (isset($pl['opt']['bs']['w'])) {
8350  	 	 	 	 	 	 	 $annots .= ' /W '.intval($pl['opt']['bs']['w']);
8351  	 	 	 	 	 	 }
8352  	 	 	 	 	 	 $bstyles = array('S', 'D', 'B', 'I', 'U');
8353  	 	 	 	 	 	 if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
8354  	 	 	 	 	 	 	 $annots .= ' /S /'.$pl['opt']['bs']['s'];
8355  	 	 	 	 	 	 }
8356  	 	 	 	 	 	 if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
8357  	 	 	 	 	 	 	 $annots .= ' /D [';
8358  	 	 	 	 	 	 	 foreach ($pl['opt']['bs']['d'] as $cord) {
8359  	 	 	 	 	 	 	 	 $annots .= ' '.intval($cord);
8360  	 	 	 	 	 	 	 }
8361  	 	 	 	 	 	 	 $annots .= ']';
8362  	 	 	 	 	 	 }
8363  	 	 	 	 	 	 $annots .= ' >>';
8364  	 	 	 	 	 } else {
8365  	 	 	 	 	 	 $annots .= ' /Border [';
8366  	 	 	 	 	 	 if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
8367  	 	 	 	 	 	 	 $annots .= intval($pl['opt']['border'][0]).' ';
8368  	 	 	 	 	 	 	 $annots .= intval($pl['opt']['border'][1]).' ';
8369  	 	 	 	 	 	 	 $annots .= intval($pl['opt']['border'][2]);
8370  	 	 	 	 	 	 	 if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
8371  	 	 	 	 	 	 	 	 $annots .= ' [';
8372  	 	 	 	 	 	 	 	 foreach ($pl['opt']['border'][3] as $dash) {
8373  	 	 	 	 	 	 	 	 	 $annots .= intval($dash).' ';
8374  	 	 	 	 	 	 	 	 }
8375  	 	 	 	 	 	 	 	 $annots .= ']';
8376  	 	 	 	 	 	 	 }
8377  	 	 	 	 	 	 } else {
8378  	 	 	 	 	 	 	 $annots .= '0 0 0';
8379  	 	 	 	 	 	 }
8380  	 	 	 	 	 	 $annots .= ']';
8381  	 	 	 	 	 }
8382  	 	 	 	 	 if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
8383  	 	 	 	 	 	 $annots .= ' /BE <<';
8384  	 	 	 	 	 	 $bstyles = array('S', 'C');
8385  	 	 	 	 	 	 if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
8386  	 	 	 	 	 	 	 $annots .= ' /S /'.$pl['opt']['bs']['s'];
8387  	 	 	 	 	 	 } else {
8388  	 	 	 	 	 	 	 $annots .= ' /S /S';
8389  	 	 	 	 	 	 }
8390  	 	 	 	 	 	 if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
8391  	 	 	 	 	 	 	 $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
8392  	 	 	 	 	 	 }
8393  	 	 	 	 	 	 $annots .= '>>';
8394  	 	 	 	 	 }
8395  	 	 	 	 	 if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
8396  	 	 	 	 	 	 $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
8397  	 	 	 	 	 }
8398  	 	 	 	 	 //$annots .= ' /StructParent ';
8399  	 	 	 	 	 //$annots .= ' /OC ';
8400  	 	 	 	 	 $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
8401  	 	 	 	 	 if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
8402  	 	 	 	 	 	 // this is a markup type
8403  	 	 	 	 	 	 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
8404  	 	 	 	 	 	 	 $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
8405  	 	 	 	 	 	 }
8406  	 	 	 	 	 	 //$annots .= ' /Popup ';
8407  	 	 	 	 	 	 if (isset($pl['opt']['ca'])) {
8408  	 	 	 	 	 	 	 $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
8409  	 	 	 	 	 	 }
8410  	 	 	 	 	 	 if (isset($pl['opt']['rc'])) {
8411  	 	 	 	 	 	 	 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
8412  	 	 	 	 	 	 }
8413  	 	 	 	 	 	 $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
8414  	 	 	 	 	 	 //$annots .= ' /IRT ';
8415  	 	 	 	 	 	 if (isset($pl['opt']['subj'])) {
8416  	 	 	 	 	 	 	 $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
8417  	 	 	 	 	 	 }
8418  	 	 	 	 	 	 //$annots .= ' /RT ';
8419  	 	 	 	 	 	 //$annots .= ' /IT ';
8420  	 	 	 	 	 	 //$annots .= ' /ExData ';
8421  	 	 	 	 	 }
8422  	 	 	 	 	 $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
8423  	 	 	 	 	 // Annotation types
8424  	 	 	 	 	 switch (strtolower($pl['opt']['subtype'])) {
8425  	 	 	 	 	 	 case 'text': {
8426  	 	 	 	 	 	 	 if (isset($pl['opt']['open'])) {
8427  	 	 	 	 	 	 	 	 $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
8428  	 	 	 	 	 	 	 }
8429  	 	 	 	 	 	 	 $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
8430  	 	 	 	 	 	 	 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8431  	 	 	 	 	 	 	 	 $annots .= ' /Name /'.$pl['opt']['name'];
8432  	 	 	 	 	 	 	 } else {
8433  	 	 	 	 	 	 	 	 $annots .= ' /Name /Note';
8434  	 	 	 	 	 	 	 }
8435  	 	 	 	 	 	 	 $hasStateModel = isset($pl['opt']['statemodel']);
8436  	 	 	 	 	 	 	 $hasState = isset($pl['opt']['state']);
8437  	 	 	 	 	 	 	 $statemodels = array('Marked', 'Review');
8438  	 	 	 	 	 	 	 if (!$hasStateModel && !$hasState) {
8439  	 	 	 	 	 	 	 	 break;
8440  	 	 	 	 	 	 	 }
8441  	 	 	 	 	 	 	 if ($hasStateModel AND in_array($pl['opt']['statemodel'], $statemodels)) {
8442  	 	 	 	 	 	 	 	 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
8443  	 	 	 	 	 	 	 } else {
8444  	 	 	 	 	 	 	 	 $pl['opt']['statemodel'] = 'Marked';
8445  	 	 	 	 	 	 	 	 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
8446  	 	 	 	 	 	 	 }
8447  	 	 	 	 	 	 	 if ($pl['opt']['statemodel'] == 'Marked') {
8448  	 	 	 	 	 	 	 	 $states = array('Accepted', 'Unmarked');
8449  	 	 	 	 	 	 	 } else {
8450  	 	 	 	 	 	 	 	 $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
8451  	 	 	 	 	 	 	 }
8452  	 	 	 	 	 	 	 if ($hasState AND in_array($pl['opt']['state'], $states)) {
8453  	 	 	 	 	 	 	 	 $annots .= ' /State /'.$pl['opt']['state'];
8454  	 	 	 	 	 	 	 } else {
8455  	 	 	 	 	 	 	 	 if ($pl['opt']['statemodel'] == 'Marked') {
8456  	 	 	 	 	 	 	 	 	 $annots .= ' /State /Unmarked';
8457  	 	 	 	 	 	 	 	 } else {
8458  	 	 	 	 	 	 	 	 	 $annots .= ' /State /None';
8459  	 	 	 	 	 	 	 	 }
8460  	 	 	 	 	 	 	 }
8461  	 	 	 	 	 	 	 break;
8462  	 	 	 	 	 	 }
8463  	 	 	 	 	 	 case 'link': {
8464  	 	 	 	 	 	 	 if (is_string($pl['txt']) && !empty($pl['txt'])) {
8465  	 	 	 	 	 	 	 	 if ($pl['txt'][0] == '#') {
8466  	 	 	 	 	 	 	 	 	 // internal destination
8467  	 	 	 	 	 	 	 	 	 $annots .= ' /A <</S /GoTo /D /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1)).'>>';
8468  	 	 	 	 	 	 	 	 } elseif ($pl['txt'][0] == '%') {
8469  	 	 	 	 	 	 	 	 	 // embedded PDF file
8470  	 	 	 	 	 	 	 	 	 $filename = basename(substr($pl['txt'], 1));
8471  	 	 	 	 	 	 	 	 	 $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
8472  	 	 	 	 	 	 	 	 } elseif ($pl['txt'][0] == '*') {
8473  	 	 	 	 	 	 	 	 	 // embedded generic file
8474  	 	 	 	 	 	 	 	 	 $filename = basename(substr($pl['txt'], 1));
8475  	 	 	 	 	 	 	 	 	 $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});';
8476  	 	 	 	 	 	 	 	 	 $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
8477  	 	 	 	 	 	 	 	 } else {
8478  	 	 	 	 	 	 	 	 	 $parsedUrl = parse_url($pl['txt']);
8479  	 	 	 	 	 	 	 	 	 if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
8480  	 	 	 	 	 	 	 	 	 	 // relative link to a PDF file
8481  	 	 	 	 	 	 	 	 	 	 $dest = '[0 /Fit]'; // default page 0
8482  	 	 	 	 	 	 	 	 	 	 if (!empty($parsedUrl['fragment'])) {
8483  	 	 	 	 	 	 	 	 	 	 	 // check for named destination
8484  	 	 	 	 	 	 	 	 	 	 	 $tmp = explode('=', $parsedUrl['fragment']);
8485  	 	 	 	 	 	 	 	 	 	 	 $dest = '('.((count($tmp) == 2) ? $tmp[1] : $tmp[0]).')';
8486  	 	 	 	 	 	 	 	 	 	 }
8487  	 	 	 	 	 	 	 	 	 	 $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
8488  	 	 	 	 	 	 	 	 	 } else {
8489  	 	 	 	 	 	 	 	 	 	 // external URI link
8490  	 	 	 	 	 	 	 	 	 	 $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
8491  	 	 	 	 	 	 	 	 	 }
8492  	 	 	 	 	 	 	 	 }
8493  	 	 	 	 	 	 	 } elseif (isset($this->links[$pl['txt']])) {
8494  	 	 	 	 	 	 	 	 // internal link ID
8495  	 	 	 	 	 	 	 	 $l = $this->links[$pl['txt']];
8496  	 	 	 	 	 	 	 	 if (isset($this->page_obj_id[($l['p'])])) {
8497  	 	 	 	 	 	 	 	 	 $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)));
8498  	 	 	 	 	 	 	 	 }
8499  	 	 	 	 	 	 	 }
8500  	 	 	 	 	 	 	 $hmodes = array('N', 'I', 'O', 'P');
8501  	 	 	 	 	 	 	 if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
8502  	 	 	 	 	 	 	 	 $annots .= ' /H /'.$pl['opt']['h'];
8503  	 	 	 	 	 	 	 } else {
8504  	 	 	 	 	 	 	 	 $annots .= ' /H /I';
8505  	 	 	 	 	 	 	 }
8506  	 	 	 	 	 	 	 //$annots .= ' /PA ';
8507  	 	 	 	 	 	 	 //$annots .= ' /Quadpoints ';
8508  	 	 	 	 	 	 	 break;
8509  	 	 	 	 	 	 }
8510  	 	 	 	 	 	 case 'freetext': {
8511  	 	 	 	 	 	 	 if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
8512  	 	 	 	 	 	 	 	 $annots .= ' /DA ('.$pl['opt']['da'].')';
8513  	 	 	 	 	 	 	 }
8514  	 	 	 	 	 	 	 if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
8515  	 	 	 	 	 	 	 	 $annots .= ' /Q '.intval($pl['opt']['q']);
8516  	 	 	 	 	 	 	 }
8517  	 	 	 	 	 	 	 if (isset($pl['opt']['rc'])) {
8518  	 	 	 	 	 	 	 	 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
8519  	 	 	 	 	 	 	 }
8520  	 	 	 	 	 	 	 if (isset($pl['opt']['ds'])) {
8521  	 	 	 	 	 	 	 	 $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
8522  	 	 	 	 	 	 	 }
8523  	 	 	 	 	 	 	 if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
8524  	 	 	 	 	 	 	 	 $annots .= ' /CL [';
8525  	 	 	 	 	 	 	 	 foreach ($pl['opt']['cl'] as $cl) {
8526  	 	 	 	 	 	 	 	 	 $annots .= sprintf('%F ', $cl * $this->k);
8527  	 	 	 	 	 	 	 	 }
8528  	 	 	 	 	 	 	 	 $annots .= ']';
8529  	 	 	 	 	 	 	 }
8530  	 	 	 	 	 	 	 $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
8531  	 	 	 	 	 	 	 if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
8532  	 	 	 	 	 	 	 	 $annots .= ' /IT /'.$pl['opt']['it'];
8533  	 	 	 	 	 	 	 }
8534  	 	 	 	 	 	 	 if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
8535  	 	 	 	 	 	 	 	 $l = $pl['opt']['rd'][0] * $this->k;
8536  	 	 	 	 	 	 	 	 $r = $pl['opt']['rd'][1] * $this->k;
8537  	 	 	 	 	 	 	 	 $t = $pl['opt']['rd'][2] * $this->k;
8538  	 	 	 	 	 	 	 	 $b = $pl['opt']['rd'][3] * $this->k;
8539  	 	 	 	 	 	 	 	 $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
8540  	 	 	 	 	 	 	 }
8541  	 	 	 	 	 	 	 if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
8542  	 	 	 	 	 	 	 	 $annots .= ' /LE /'.$pl['opt']['le'];
8543  	 	 	 	 	 	 	 }
8544  	 	 	 	 	 	 	 break;
8545  	 	 	 	 	 	 }
8546  	 	 	 	 	 	 case 'line': {
8547  	 	 	 	 	 	 	 break;
8548  	 	 	 	 	 	 }
8549  	 	 	 	 	 	 case 'square': {
8550  	 	 	 	 	 	 	 break;
8551  	 	 	 	 	 	 }
8552  	 	 	 	 	 	 case 'circle': {
8553  	 	 	 	 	 	 	 break;
8554  	 	 	 	 	 	 }
8555  	 	 	 	 	 	 case 'polygon': {
8556  	 	 	 	 	 	 	 break;
8557  	 	 	 	 	 	 }
8558  	 	 	 	 	 	 case 'polyline': {
8559  	 	 	 	 	 	 	 break;
8560  	 	 	 	 	 	 }
8561  	 	 	 	 	 	 case 'highlight': {
8562  	 	 	 	 	 	 	 break;
8563  	 	 	 	 	 	 }
8564  	 	 	 	 	 	 case 'underline': {
8565  	 	 	 	 	 	 	 break;
8566  	 	 	 	 	 	 }
8567  	 	 	 	 	 	 case 'squiggly': {
8568  	 	 	 	 	 	 	 break;
8569  	 	 	 	 	 	 }
8570  	 	 	 	 	 	 case 'strikeout': {
8571  	 	 	 	 	 	 	 break;
8572  	 	 	 	 	 	 }
8573  	 	 	 	 	 	 case 'stamp': {
8574  	 	 	 	 	 	 	 break;
8575  	 	 	 	 	 	 }
8576  	 	 	 	 	 	 case 'caret': {
8577  	 	 	 	 	 	 	 break;
8578  	 	 	 	 	 	 }
8579  	 	 	 	 	 	 case 'ink': {
8580  	 	 	 	 	 	 	 break;
8581  	 	 	 	 	 	 }
8582  	 	 	 	 	 	 case 'popup': {
8583  	 	 	 	 	 	 	 break;
8584  	 	 	 	 	 	 }
8585  	 	 	 	 	 	 case 'fileattachment': {
8586  	 	 	 	 	 	 	 if ($this->pdfa_mode && $this->pdfa_version != 3) {
8587  	 	 	 	 	 	 	 	 // embedded files are not allowed in PDF/A mode version 1 and 2
8588  	 	 	 	 	 	 	 	 break;
8589  	 	 	 	 	 	 	 }
8590  	 	 	 	 	 	 	 if (!isset($pl['opt']['fs'])) {
8591  	 	 	 	 	 	 	 	 break;
8592  	 	 	 	 	 	 	 }
8593  	 	 	 	 	 	 	 $filename = basename($pl['opt']['fs']);
8594  	 	 	 	 	 	 	 if (isset($this->embeddedfiles[$filename]['f'])) {
8595  	 	 	 	 	 	 	 	 $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
8596  	 	 	 	 	 	 	 	 $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
8597  	 	 	 	 	 	 	 	 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8598  	 	 	 	 	 	 	 	 	 $annots .= ' /Name /'.$pl['opt']['name'];
8599  	 	 	 	 	 	 	 	 } else {
8600  	 	 	 	 	 	 	 	 	 $annots .= ' /Name /PushPin';
8601  	 	 	 	 	 	 	 	 }
8602  	 	 	 	 	 	 	 	 // index (zero-based) of the annotation in the Annots array of this page
8603  	 	 	 	 	 	 	 	 $this->embeddedfiles[$filename]['a'] = $key;
8604  	 	 	 	 	 	 	 }
8605  	 	 	 	 	 	 	 break;
8606  	 	 	 	 	 	 }
8607  	 	 	 	 	 	 case 'sound': {
8608  	 	 	 	 	 	 	 if (!isset($pl['opt']['fs'])) {
8609  	 	 	 	 	 	 	 	 break;
8610  	 	 	 	 	 	 	 }
8611  	 	 	 	 	 	 	 $filename = basename($pl['opt']['fs']);
8612  	 	 	 	 	 	 	 if (isset($this->embeddedfiles[$filename]['f'])) {
8613  	 	 	 	 	 	 	 	 // ... TO BE COMPLETED ...
8614  	 	 	 	 	 	 	 	 // /R /C /B /E /CO /CP
8615  	 	 	 	 	 	 	 	 $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
8616  	 	 	 	 	 	 	 	 $iconsapp = array('Speaker', 'Mic');
8617  	 	 	 	 	 	 	 	 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8618  	 	 	 	 	 	 	 	 	 $annots .= ' /Name /'.$pl['opt']['name'];
8619  	 	 	 	 	 	 	 	 } else {
8620  	 	 	 	 	 	 	 	 	 $annots .= ' /Name /Speaker';
8621  	 	 	 	 	 	 	 	 }
8622  	 	 	 	 	 	 	 }
8623  	 	 	 	 	 	 	 break;
8624  	 	 	 	 	 	 }
8625  	 	 	 	 	 	 case 'movie': {
8626  	 	 	 	 	 	 	 break;
8627  	 	 	 	 	 	 }
8628  	 	 	 	 	 	 case 'widget': {
8629  	 	 	 	 	 	 	 $hmode = array('N', 'I', 'O', 'P', 'T');
8630  	 	 	 	 	 	 	 if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
8631  	 	 	 	 	 	 	 	 $annots .= ' /H /'.$pl['opt']['h'];
8632  	 	 	 	 	 	 	 }
8633  	 	 	 	 	 	 	 if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
8634  	 	 	 	 	 	 	 	 $annots .= ' /MK <<';
8635  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['r'])) {
8636  	 	 	 	 	 	 	 	 	 $annots .= ' /R '.$pl['opt']['mk']['r'];
8637  	 	 	 	 	 	 	 	 }
8638  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
8639  	 	 	 	 	 	 	 	 	 $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
8640  	 	 	 	 	 	 	 	 }
8641  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
8642  	 	 	 	 	 	 	 	 	 $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
8643  	 	 	 	 	 	 	 	 }
8644  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['ca'])) {
8645  	 	 	 	 	 	 	 	 	 $annots .= ' /CA '.$pl['opt']['mk']['ca'];
8646  	 	 	 	 	 	 	 	 }
8647  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['rc'])) {
8648  	 	 	 	 	 	 	 	 	 $annots .= ' /RC '.$pl['opt']['mk']['rc'];
8649  	 	 	 	 	 	 	 	 }
8650  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['ac'])) {
8651  	 	 	 	 	 	 	 	 	 $annots .= ' /AC '.$pl['opt']['mk']['ac'];
8652  	 	 	 	 	 	 	 	 }
8653  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['i'])) {
8654  	 	 	 	 	 	 	 	 	 $info = $this->getImageBuffer($pl['opt']['mk']['i']);
8655  	 	 	 	 	 	 	 	 	 if ($info !== false) {
8656  	 	 	 	 	 	 	 	 	 	 $annots .= ' /I '.$info['n'].' 0 R';
8657  	 	 	 	 	 	 	 	 	 }
8658  	 	 	 	 	 	 	 	 }
8659  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['ri'])) {
8660  	 	 	 	 	 	 	 	 	 $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
8661  	 	 	 	 	 	 	 	 	 if ($info !== false) {
8662  	 	 	 	 	 	 	 	 	 	 $annots .= ' /RI '.$info['n'].' 0 R';
8663  	 	 	 	 	 	 	 	 	 }
8664  	 	 	 	 	 	 	 	 }
8665  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['ix'])) {
8666  	 	 	 	 	 	 	 	 	 $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
8667  	 	 	 	 	 	 	 	 	 if ($info !== false) {
8668  	 	 	 	 	 	 	 	 	 	 $annots .= ' /IX '.$info['n'].' 0 R';
8669  	 	 	 	 	 	 	 	 	 }
8670  	 	 	 	 	 	 	 	 }
8671  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
8672  	 	 	 	 	 	 	 	 	 $annots .= ' /IF <<';
8673  	 	 	 	 	 	 	 	 	 $if_sw = array('A', 'B', 'S', 'N');
8674  	 	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
8675  	 	 	 	 	 	 	 	 	 	 $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
8676  	 	 	 	 	 	 	 	 	 }
8677  	 	 	 	 	 	 	 	 	 $if_s = array('A', 'P');
8678  	 	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
8679  	 	 	 	 	 	 	 	 	 	 $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
8680  	 	 	 	 	 	 	 	 	 }
8681  	 	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
8682  	 	 	 	 	 	 	 	 	 	 $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
8683  	 	 	 	 	 	 	 	 	 }
8684  	 	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
8685  	 	 	 	 	 	 	 	 	 	 $annots .= ' /FB true';
8686  	 	 	 	 	 	 	 	 	 }
8687  	 	 	 	 	 	 	 	 	 $annots .= '>>';
8688  	 	 	 	 	 	 	 	 }
8689  	 	 	 	 	 	 	 	 if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
8690  	 	 	 	 	 	 	 	 	 $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
8691  	 	 	 	 	 	 	 	 }
8692  	 	 	 	 	 	 	 	 $annots .= '>>';
8693  	 	 	 	 	 	 	 } // end MK
8694  	 	 	 	 	 	 	 // --- Entries for field dictionaries ---
8695  	 	 	 	 	 	 	 if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
8696  	 	 	 	 	 	 	 	 // set parent
8697  	 	 	 	 	 	 	 	 $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
8698  	 	 	 	 	 	 	 }
8699  	 	 	 	 	 	 	 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
8700  	 	 	 	 	 	 	 	 $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
8701  	 	 	 	 	 	 	 }
8702  	 	 	 	 	 	 	 if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
8703  	 	 	 	 	 	 	 	 $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
8704  	 	 	 	 	 	 	 }
8705  	 	 	 	 	 	 	 if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
8706  	 	 	 	 	 	 	 	 $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
8707  	 	 	 	 	 	 	 }
8708  	 	 	 	 	 	 	 if (isset($pl['opt']['ff'])) {
8709  	 	 	 	 	 	 	 	 if (is_array($pl['opt']['ff'])) {
8710  	 	 	 	 	 	 	 	 	 // array of bit settings
8711  	 	 	 	 	 	 	 	 	 $flag = 0;
8712  	 	 	 	 	 	 	 	 	 foreach($pl['opt']['ff'] as $val) {
8713  	 	 	 	 	 	 	 	 	 	 $flag += 1 << ($val - 1);
8714  	 	 	 	 	 	 	 	 	 }
8715  	 	 	 	 	 	 	 	 } else {
8716  	 	 	 	 	 	 	 	 	 $flag = intval($pl['opt']['ff']);
8717  	 	 	 	 	 	 	 	 }
8718  	 	 	 	 	 	 	 	 $annots .= ' /Ff '.$flag;
8719  	 	 	 	 	 	 	 }
8720  	 	 	 	 	 	 	 if (isset($pl['opt']['maxlen'])) {
8721  	 	 	 	 	 	 	 	 $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
8722  	 	 	 	 	 	 	 }
8723  	 	 	 	 	 	 	 if (isset($pl['opt']['v'])) {
8724  	 	 	 	 	 	 	 	 $annots .= ' /V';
8725  	 	 	 	 	 	 	 	 if (is_array($pl['opt']['v'])) {
8726  	 	 	 	 	 	 	 	 	 foreach ($pl['opt']['v'] AS $optval) {
8727  	 	 	 	 	 	 	 	 	 	 if (is_float($optval)) {
8728  	 	 	 	 	 	 	 	 	 	 	 $optval = sprintf('%F', $optval);
8729  	 	 	 	 	 	 	 	 	 	 }
8730  	 	 	 	 	 	 	 	 	 	 $annots .= ' '.$optval;
8731  	 	 	 	 	 	 	 	 	 }
8732  	 	 	 	 	 	 	 	 } else {
8733  	 	 	 	 	 	 	 	 	 $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
8734  	 	 	 	 	 	 	 	 }
8735  	 	 	 	 	 	 	 }
8736  	 	 	 	 	 	 	 if (isset($pl['opt']['dv'])) {
8737  	 	 	 	 	 	 	 	 $annots .= ' /DV';
8738  	 	 	 	 	 	 	 	 if (is_array($pl['opt']['dv'])) {
8739  	 	 	 	 	 	 	 	 	 foreach ($pl['opt']['dv'] AS $optval) {
8740  	 	 	 	 	 	 	 	 	 	 if (is_float($optval)) {
8741  	 	 	 	 	 	 	 	 	 	 	 $optval = sprintf('%F', $optval);
8742  	 	 	 	 	 	 	 	 	 	 }
8743  	 	 	 	 	 	 	 	 	 	 $annots .= ' '.$optval;
8744  	 	 	 	 	 	 	 	 	 }
8745  	 	 	 	 	 	 	 	 } else {
8746  	 	 	 	 	 	 	 	 	 $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
8747  	 	 	 	 	 	 	 	 }
8748  	 	 	 	 	 	 	 }
8749  	 	 	 	 	 	 	 if (isset($pl['opt']['rv'])) {
8750  	 	 	 	 	 	 	 	 $annots .= ' /RV';
8751  	 	 	 	 	 	 	 	 if (is_array($pl['opt']['rv'])) {
8752  	 	 	 	 	 	 	 	 	 foreach ($pl['opt']['rv'] AS $optval) {
8753  	 	 	 	 	 	 	 	 	 	 if (is_float($optval)) {
8754  	 	 	 	 	 	 	 	 	 	 	 $optval = sprintf('%F', $optval);
8755  	 	 	 	 	 	 	 	 	 	 }
8756  	 	 	 	 	 	 	 	 	 	 $annots .= ' '.$optval;
8757  	 	 	 	 	 	 	 	 	 }
8758  	 	 	 	 	 	 	 	 } else {
8759  	 	 	 	 	 	 	 	 	 $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
8760  	 	 	 	 	 	 	 	 }
8761  	 	 	 	 	 	 	 }
8762  	 	 	 	 	 	 	 if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
8763  	 	 	 	 	 	 	 	 $annots .= ' /A << '.$pl['opt']['a'].' >>';
8764  	 	 	 	 	 	 	 }
8765  	 	 	 	 	 	 	 if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
8766  	 	 	 	 	 	 	 	 $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
8767  	 	 	 	 	 	 	 }
8768  	 	 	 	 	 	 	 if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
8769  	 	 	 	 	 	 	 	 $annots .= ' /DA ('.$pl['opt']['da'].')';
8770  	 	 	 	 	 	 	 }
8771  	 	 	 	 	 	 	 if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
8772  	 	 	 	 	 	 	 	 $annots .= ' /Q '.intval($pl['opt']['q']);
8773  	 	 	 	 	 	 	 }
8774  	 	 	 	 	 	 	 if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
8775  	 	 	 	 	 	 	 	 $annots .= ' /Opt [';
8776  	 	 	 	 	 	 	 	 foreach($pl['opt']['opt'] AS $copt) {
8777  	 	 	 	 	 	 	 	 	 if (is_array($copt)) {
8778  	 	 	 	 	 	 	 	 	 	 $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
8779  	 	 	 	 	 	 	 	 	 } else {
8780  	 	 	 	 	 	 	 	 	 	 $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
8781  	 	 	 	 	 	 	 	 	 }
8782  	 	 	 	 	 	 	 	 }
8783  	 	 	 	 	 	 	 	 $annots .= ']';
8784  	 	 	 	 	 	 	 }
8785  	 	 	 	 	 	 	 if (isset($pl['opt']['ti'])) {
8786  	 	 	 	 	 	 	 	 $annots .= ' /TI '.intval($pl['opt']['ti']);
8787  	 	 	 	 	 	 	 }
8788  	 	 	 	 	 	 	 if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
8789  	 	 	 	 	 	 	 	 $annots .= ' /I [';
8790  	 	 	 	 	 	 	 	 foreach($pl['opt']['i'] AS $copt) {
8791  	 	 	 	 	 	 	 	 	 $annots .= intval($copt).' ';
8792  	 	 	 	 	 	 	 	 }
8793  	 	 	 	 	 	 	 	 $annots .= ']';
8794  	 	 	 	 	 	 	 }
8795  	 	 	 	 	 	 	 break;
8796  	 	 	 	 	 	 }
8797  	 	 	 	 	 	 case 'screen': {
8798  	 	 	 	 	 	 	 break;
8799  	 	 	 	 	 	 }
8800  	 	 	 	 	 	 case 'printermark': {
8801  	 	 	 	 	 	 	 break;
8802  	 	 	 	 	 	 }
8803  	 	 	 	 	 	 case 'trapnet': {
8804  	 	 	 	 	 	 	 break;
8805  	 	 	 	 	 	 }
8806  	 	 	 	 	 	 case 'watermark': {
8807  	 	 	 	 	 	 	 break;
8808  	 	 	 	 	 	 }
8809  	 	 	 	 	 	 case '3d': {
8810  	 	 	 	 	 	 	 break;
8811  	 	 	 	 	 	 }
8812  	 	 	 	 	 	 default: {
8813  	 	 	 	 	 	 	 break;
8814  	 	 	 	 	 	 }
8815  	 	 	 	 	 }
8816  	 	 	 	 	 $annots .= '>>';
8817  	 	 	 	 	 // create new annotation object
8818  	 	 	 	 	 $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
8819  	 	 	 	 	 if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
8820  	 	 	 	 	 	 // store reference of form object
8821  	 	 	 	 	 	 $this->form_obj_id[] = $annot_obj_id;
8822  	 	 	 	 	 }
8823  	 	 	 	 }
8824  	 	 	 }
8825  	 	 } // end for each page
8826  	 }
8827  
8828  	 /**
8829  	  * Put appearance streams XObject used to define annotation's appearance states.
8830  	  * @param int $w annotation width
8831  	  * @param int $h annotation height
8832  	  * @param string $stream appearance stream
8833  	  * @return int object ID
8834  	  * @protected
8835  	  * @since 4.8.001 (2009-09-09)
8836  	  */
8837  	protected function _putAPXObject($w=0, $h=0, $stream='') {
8838  	 	 $stream = trim($stream);
8839  	 	 $out = $this->_getobj()."\n";
8840  	 	 $this->xobjects['AX'.$this->n] = array('n' => $this->n);
8841  	 	 $out .= '<<';
8842  	 	 $out .= ' /Type /XObject';
8843  	 	 $out .= ' /Subtype /Form';
8844  	 	 $out .= ' /FormType 1';
8845  	 	 if ($this->compress) {
8846  	 	 	 $stream = gzcompress($stream);
8847  	 	 	 $out .= ' /Filter /FlateDecode';
8848  	 	 }
8849  	 	 $rect = sprintf('%F %F', $w, $h);
8850  	 	 $out .= ' /BBox [0 0 '.$rect.']';
8851  	 	 $out .= ' /Matrix [1 0 0 1 0 0]';
8852  	 	 $out .= ' /Resources 2 0 R';
8853  	 	 $stream = $this->_getrawstream($stream);
8854  	 	 $out .= ' /Length '.strlen($stream);
8855  	 	 $out .= ' >>';
8856  	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
8857  	 	 $out .= "\n".'endobj';
8858  	 	 $this->_out($out);
8859  	 	 return $this->n;
8860  	 }
8861  
8862  	 /**
8863  	  * Output fonts.
8864  	  * @author Nicola Asuni
8865  	  * @protected
8866  	  */
8867  	protected function _putfonts() {
8868  	 	 $nf = $this->n;
8869  	 	 foreach ($this->diffs as $diff) {
8870  	 	 	 //Encodings
8871  	 	 	 $this->_newobj();
8872  	 	 	 $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
8873  	 	 }
8874  	 	 $mqr = TCPDF_STATIC::get_mqr();
8875  	 	 TCPDF_STATIC::set_mqr(false);
8876  	 	 foreach ($this->FontFiles as $file => $info) {
8877  	 	 	 // search and get font file to embedd
8878  	 	 	 $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
8879  	 	 	 if (!TCPDF_STATIC::empty_string($fontfile)) {
8880  	 	 	 	 $font = file_get_contents($fontfile);
8881  	 	 	 	 $compressed = (substr($file, -2) == '.z');
8882  	 	 	 	 if ((!$compressed) AND (isset($info['length2']))) {
8883  	 	 	 	 	 $header = (ord($font[0]) == 128);
8884  	 	 	 	 	 if ($header) {
8885  	 	 	 	 	 	 // strip first binary header
8886  	 	 	 	 	 	 $font = substr($font, 6);
8887  	 	 	 	 	 }
8888  	 	 	 	 	 if ($header AND (ord($font[$info['length1']]) == 128)) {
8889  	 	 	 	 	 	 // strip second binary header
8890  	 	 	 	 	 	 $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
8891  	 	 	 	 	 }
8892  	 	 	 	 } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
8893  	 	 	 	 	 if ($compressed) {
8894  	 	 	 	 	 	 // uncompress font
8895  	 	 	 	 	 	 $font = gzuncompress($font);
8896  	 	 	 	 	 }
8897  	 	 	 	 	 // merge subset characters
8898  	 	 	 	 	 $subsetchars = array(); // used chars
8899  	 	 	 	 	 foreach ($info['fontkeys'] as $fontkey) {
8900  	 	 	 	 	 	 $fontinfo = $this->getFontBuffer($fontkey);
8901  	 	 	 	 	 	 $subsetchars += $fontinfo['subsetchars'];
8902  	 	 	 	 	 }
8903  	 	 	 	 	 // rebuild a font subset
8904  	 	 	 	 	 $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
8905  	 	 	 	 	 // calculate new font length
8906  	 	 	 	 	 $info['length1'] = strlen($font);
8907  	 	 	 	 	 if ($compressed) {
8908  	 	 	 	 	 	 // recompress font
8909  	 	 	 	 	 	 $font = gzcompress($font);
8910  	 	 	 	 	 }
8911  	 	 	 	 }
8912  	 	 	 	 $this->_newobj();
8913  	 	 	 	 $this->FontFiles[$file]['n'] = $this->n;
8914  	 	 	 	 $stream = $this->_getrawstream($font);
8915  	 	 	 	 $out = '<< /Length '.strlen($stream);
8916  	 	 	 	 if ($compressed) {
8917  	 	 	 	 	 $out .= ' /Filter /FlateDecode';
8918  	 	 	 	 }
8919  	 	 	 	 $out .= ' /Length1 '.$info['length1'];
8920  	 	 	 	 if (isset($info['length2'])) {
8921  	 	 	 	 	 $out .= ' /Length2 '.$info['length2'].' /Length3 0';
8922  	 	 	 	 }
8923  	 	 	 	 $out .= ' >>';
8924  	 	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
8925  	 	 	 	 $out .= "\n".'endobj';
8926  	 	 	 	 $this->_out($out);
8927  	 	 	 }
8928  	 	 }
8929  	 	 TCPDF_STATIC::set_mqr($mqr);
8930  	 	 foreach ($this->fontkeys as $k) {
8931  	 	 	 //Font objects
8932  	 	 	 $font = $this->getFontBuffer($k);
8933  	 	 	 $type = $font['type'];
8934  	 	 	 $name = $font['name'];
8935  	 	 	 if ($type == 'core') {
8936  	 	 	 	 // standard core font
8937  	 	 	 	 $out = $this->_getobj($this->font_obj_ids[$k])."\n";
8938  	 	 	 	 $out .= '<</Type /Font';
8939  	 	 	 	 $out .= ' /Subtype /Type1';
8940  	 	 	 	 $out .= ' /BaseFont /'.$name;
8941  	 	 	 	 $out .= ' /Name /F'.$font['i'];
8942  	 	 	 	 if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
8943  	 	 	 	 	 $out .= ' /Encoding /WinAnsiEncoding';
8944  	 	 	 	 }
8945  	 	 	 	 if ($k == 'helvetica') {
8946  	 	 	 	 	 // add default font for annotations
8947  	 	 	 	 	 $this->annotation_fonts[$k] = $font['i'];
8948  	 	 	 	 }
8949  	 	 	 	 $out .= ' >>';
8950  	 	 	 	 $out .= "\n".'endobj';
8951  	 	 	 	 $this->_out($out);
8952  	 	 	 } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
8953  	 	 	 	 // additional Type1 or TrueType font
8954  	 	 	 	 $out = $this->_getobj($this->font_obj_ids[$k])."\n";
8955  	 	 	 	 $out .= '<</Type /Font';
8956  	 	 	 	 $out .= ' /Subtype /'.$type;
8957  	 	 	 	 $out .= ' /BaseFont /'.$name;
8958  	 	 	 	 $out .= ' /Name /F'.$font['i'];
8959  	 	 	 	 $out .= ' /FirstChar 32 /LastChar 255';
8960  	 	 	 	 $out .= ' /Widths '.($this->n + 1).' 0 R';
8961  	 	 	 	 $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
8962  	 	 	 	 if ($font['enc']) {
8963  	 	 	 	 	 if (isset($font['diff'])) {
8964  	 	 	 	 	 	 $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
8965  	 	 	 	 	 } else {
8966  	 	 	 	 	 	 $out .= ' /Encoding /WinAnsiEncoding';
8967  	 	 	 	 	 }
8968  	 	 	 	 }
8969  	 	 	 	 $out .= ' >>';
8970  	 	 	 	 $out .= "\n".'endobj';
8971  	 	 	 	 $this->_out($out);
8972  	 	 	 	 // Widths
8973  	 	 	 	 $this->_newobj();
8974  	 	 	 	 $s = '[';
8975  	 	 	 	 for ($i = 32; $i < 256; ++$i) {
8976  	 	 	 	 	 if (isset($font['cw'][$i])) {
8977  	 	 	 	 	 	 $s .= $font['cw'][$i].' ';
8978  	 	 	 	 	 } else {
8979  	 	 	 	 	 	 $s .= $font['dw'].' ';
8980  	 	 	 	 	 }
8981  	 	 	 	 }
8982  	 	 	 	 $s .= ']';
8983  	 	 	 	 $s .= "\n".'endobj';
8984  	 	 	 	 $this->_out($s);
8985  	 	 	 	 //Descriptor
8986  	 	 	 	 $this->_newobj();
8987  	 	 	 	 $s = '<</Type /FontDescriptor /FontName /'.$name;
8988  	 	 	 	 foreach ($font['desc'] as $fdk => $fdv) {
8989  	 	 	 	 	 if (is_float($fdv)) {
8990  	 	 	 	 	 	 $fdv = sprintf('%F', $fdv);
8991  	 	 	 	 	 }
8992  	 	 	 	 	 $s .= ' /'.$fdk.' '.$fdv.'';
8993  	 	 	 	 }
8994  	 	 	 	 if (!TCPDF_STATIC::empty_string($font['file'])) {
8995  	 	 	 	 	 $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
8996  	 	 	 	 }
8997  	 	 	 	 $s .= '>>';
8998  	 	 	 	 $s .= "\n".'endobj';
8999  	 	 	 	 $this->_out($s);
9000  	 	 	 } else {
9001  	 	 	 	 // additional types
9002  	 	 	 	 $mtd = '_put'.strtolower($type);
9003  	 	 	 	 if (!method_exists($this, $mtd)) {
9004  	 	 	 	 	 $this->Error('Unsupported font type: '.$type);
9005  	 	 	 	 }
9006  	 	 	 	 $this->$mtd($font);
9007  	 	 	 }
9008  	 	 }
9009  	 }
9010  
9011  	 /**
9012  	  * Adds unicode fonts.<br>
9013  	  * Based on PDF Reference 1.3 (section 5)
9014  	  * @param array $font font data
9015  	  * @protected
9016  	  * @author Nicola Asuni
9017  	  * @since 1.52.0.TC005 (2005-01-05)
9018  	  */
9019  	protected function _puttruetypeunicode($font) {
9020  	 	 $fontname = '';
9021  	 	 if ($font['subset']) {
9022  	 	 	 // change name for font subsetting
9023  	 	 	 $subtag = sprintf('%06u', $font['i']);
9024  	 	 	 $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
9025  	 	 	 $fontname .= $subtag.'+';
9026  	 	 }
9027  	 	 $fontname .= $font['name'];
9028  	 	 // Type0 Font
9029  	 	 // A composite font composed of other fonts, organized hierarchically
9030  	 	 $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
9031  	 	 $out .= '<< /Type /Font';
9032  	 	 $out .= ' /Subtype /Type0';
9033  	 	 $out .= ' /BaseFont /'.$fontname;
9034  	 	 $out .= ' /Name /F'.$font['i'];
9035  	 	 $out .= ' /Encoding /'.$font['enc'];
9036  	 	 $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
9037  	 	 $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
9038  	 	 $out .= ' >>';
9039  	 	 $out .= "\n".'endobj';
9040  	 	 $this->_out($out);
9041  	 	 // ToUnicode map for Identity-H
9042  	 	 $stream = TCPDF_FONT_DATA::$uni_identity_h;
9043  	 	 // ToUnicode Object
9044  	 	 $this->_newobj();
9045  	 	 $stream = ($this->compress) ? gzcompress($stream) : $stream;
9046  	 	 $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
9047  	 	 $stream = $this->_getrawstream($stream);
9048  	 	 $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
9049  	 	 // CIDFontType2
9050  	 	 // A CIDFont whose glyph descriptions are based on TrueType font technology
9051  	 	 $oid = $this->_newobj();
9052  	 	 $out = '<< /Type /Font';
9053  	 	 $out .= ' /Subtype /CIDFontType2';
9054  	 	 $out .= ' /BaseFont /'.$fontname;
9055  	 	 // A dictionary containing entries that define the character collection of the CIDFont.
9056  	 	 $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
9057  	 	 $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
9058  	 	 $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
9059  	 	 $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
9060  	 	 $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
9061  	 	 $out .= ' /DW '.$font['dw']; // default width
9062  	 	 $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
9063  	 	 if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
9064  	 	 	 $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
9065  	 	 }
9066  	 	 $out .= ' >>';
9067  	 	 $out .= "\n".'endobj';
9068  	 	 $this->_out($out);
9069  	 	 // Font descriptor
9070  	 	 // A font descriptor describing the CIDFont default metrics other than its glyph widths
9071  	 	 $this->_newobj();
9072  	 	 $out = '<< /Type /FontDescriptor';
9073  	 	 $out .= ' /FontName /'.$fontname;
9074  	 	 foreach ($font['desc'] as $key => $value) {
9075  	 	 	 if (is_float($value)) {
9076  	 	 	 	 $value = sprintf('%F', $value);
9077  	 	 	 }
9078  	 	 	 $out .= ' /'.$key.' '.$value;
9079  	 	 }
9080  	 	 $fontdir = false;
9081  	 	 if (!TCPDF_STATIC::empty_string($font['file'])) {
9082  	 	 	 // A stream containing a TrueType font
9083  	 	 	 $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
9084  	 	 	 $fontdir = $this->FontFiles[$font['file']]['fontdir'];
9085  	 	 }
9086  	 	 $out .= ' >>';
9087  	 	 $out .= "\n".'endobj';
9088  	 	 $this->_out($out);
9089  	 	 if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
9090  	 	 	 $this->_newobj();
9091  	 	 	 // Embed CIDToGIDMap
9092  	 	 	 // A specification of the mapping from CIDs to glyph indices
9093  	 	 	 // search and get CTG font file to embedd
9094  	 	 	 $ctgfile = strtolower($font['ctg']);
9095  	 	 	 // search and get ctg font file to embedd
9096  	 	 	 $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
9097  	 	 	 if (TCPDF_STATIC::empty_string($fontfile)) {
9098  	 	 	 	 $this->Error('Font file not found: '.$ctgfile);
9099  	 	 	 }
9100  	 	 	 $stream = $this->_getrawstream(file_get_contents($fontfile));
9101  	 	 	 $out = '<< /Length '.strlen($stream).'';
9102  	 	 	 if (substr($fontfile, -2) == '.z') { // check file extension
9103  	 	 	 	 // Decompresses data encoded using the public-domain
9104  	 	 	 	 // zlib/deflate compression method, reproducing the
9105  	 	 	 	 // original text or binary data
9106  	 	 	 	 $out .= ' /Filter /FlateDecode';
9107  	 	 	 }
9108  	 	 	 $out .= ' >>';
9109  	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
9110  	 	 	 $out .= "\n".'endobj';
9111  	 	 	 $this->_out($out);
9112  	 	 }
9113  	 }
9114  
9115  	 /**
9116  	  * Output CID-0 fonts.
9117  	  * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
9118  	  * @param array $font font data
9119  	  * @protected
9120  	  * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
9121  	  * @since 3.2.000 (2008-06-23)
9122  	  */
9123  	protected function _putcidfont0($font) {
9124  	 	 $cidoffset = 0;
9125  	 	 if (!isset($font['cw'][1])) {
9126  	 	 	 $cidoffset = 31;
9127  	 	 }
9128  	 	 if (isset($font['cidinfo']['uni2cid'])) {
9129  	 	 	 // convert unicode to cid.
9130  	 	 	 $uni2cid = $font['cidinfo']['uni2cid'];
9131  	 	 	 $cw = array();
9132  	 	 	 foreach ($font['cw'] as $uni => $width) {
9133  	 	 	 	 if (isset($uni2cid[$uni])) {
9134  	 	 	 	 	 $cw[($uni2cid[$uni] + $cidoffset)] = $width;
9135  	 	 	 	 } elseif ($uni < 256) {
9136  	 	 	 	 	 $cw[$uni] = $width;
9137  	 	 	 	 } // else unknown character
9138  	 	 	 }
9139  	 	 	 $font = array_merge($font, array('cw' => $cw));
9140  	 	 }
9141  	 	 $name = $font['name'];
9142  	 	 $enc = $font['enc'];
9143  	 	 if ($enc) {
9144  	 	 	 $longname = $name.'-'.$enc;
9145  	 	 } else {
9146  	 	 	 $longname = $name;
9147  	 	 }
9148  	 	 $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
9149  	 	 $out .= '<</Type /Font';
9150  	 	 $out .= ' /Subtype /Type0';
9151  	 	 $out .= ' /BaseFont /'.$longname;
9152  	 	 $out .= ' /Name /F'.$font['i'];
9153  	 	 if ($enc) {
9154  	 	 	 $out .= ' /Encoding /'.$enc;
9155  	 	 }
9156  	 	 $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
9157  	 	 $out .= ' >>';
9158  	 	 $out .= "\n".'endobj';
9159  	 	 $this->_out($out);
9160  	 	 $oid = $this->_newobj();
9161  	 	 $out = '<</Type /Font';
9162  	 	 $out .= ' /Subtype /CIDFontType0';
9163  	 	 $out .= ' /BaseFont /'.$name;
9164  	 	 $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
9165  	 	 $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
9166  	 	 $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
9167  	 	 $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
9168  	 	 $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
9169  	 	 $out .= ' /DW '.$font['dw'];
9170  	 	 $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
9171  	 	 $out .= ' >>';
9172  	 	 $out .= "\n".'endobj';
9173  	 	 $this->_out($out);
9174  	 	 $this->_newobj();
9175  	 	 $s = '<</Type /FontDescriptor /FontName /'.$name;
9176  	 	 foreach ($font['desc'] as $k => $v) {
9177  	 	 	 if ($k != 'Style') {
9178  	 	 	 	 if (is_float($v)) {
9179  	 	 	 	 	 $v = sprintf('%F', $v);
9180  	 	 	 	 }
9181  	 	 	 	 $s .= ' /'.$k.' '.$v.'';
9182  	 	 	 }
9183  	 	 }
9184  	 	 $s .= '>>';
9185  	 	 $s .= "\n".'endobj';
9186  	 	 $this->_out($s);
9187  	 }
9188  
9189  	 /**
9190  	  * Output images.
9191  	  * @protected
9192  	  */
9193  	protected function _putimages() {
9194  	 	 $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
9195  	 	 foreach ($this->imagekeys as $file) {
9196  	 	 	 $info = $this->getImageBuffer($file);
9197  	 	 	 // set object for alternate images array
9198  	 	 	 if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
9199  	 	 	 	 $altoid = $this->_newobj();
9200  	 	 	 	 $out = '[';
9201  	 	 	 	 foreach ($info['altimgs'] as $altimage) {
9202  	 	 	 	 	 if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
9203  	 	 	 	 	 	 $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
9204  	 	 	 	 	 	 $out .= ' /DefaultForPrinting';
9205  	 	 	 	 	 	 if ($altimage[1] === true) {
9206  	 	 	 	 	 	 	 $out .= ' true';
9207  	 	 	 	 	 	 } else {
9208  	 	 	 	 	 	 	 $out .= ' false';
9209  	 	 	 	 	 	 }
9210  	 	 	 	 	 	 $out .= ' >>';
9211  	 	 	 	 	 }
9212  	 	 	 	 }
9213  	 	 	 	 $out .= ' ]';
9214  	 	 	 	 $out .= "\n".'endobj';
9215  	 	 	 	 $this->_out($out);
9216  	 	 	 }
9217  	 	 	 // set image object
9218  	 	 	 $oid = $this->_newobj();
9219  	 	 	 $this->xobjects['I'.$info['i']] = array('n' => $oid);
9220  	 	 	 $this->setImageSubBuffer($file, 'n', $this->n);
9221  	 	 	 $out = '<</Type /XObject';
9222  	 	 	 $out .= ' /Subtype /Image';
9223  	 	 	 $out .= ' /Width '.$info['w'];
9224  	 	 	 $out .= ' /Height '.$info['h'];
9225  	 	 	 if (array_key_exists('masked', $info)) {
9226  	 	 	 	 $out .= ' /SMask '.($this->n - 1).' 0 R';
9227  	 	 	 }
9228  	 	 	 // set color space
9229  	 	 	 $icc = false;
9230  	 	 	 if (isset($info['icc']) AND ($info['icc'] !== false)) {
9231  	 	 	 	 // ICC Colour Space
9232  	 	 	 	 $icc = true;
9233  	 	 	 	 $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
9234  	 	 	 } elseif ($info['cs'] == 'Indexed') {
9235  	 	 	 	 // Indexed Colour Space
9236  	 	 	 	 $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
9237  	 	 	 } else {
9238  	 	 	 	 // Device Colour Space
9239  	 	 	 	 $out .= ' /ColorSpace /'.$info['cs'];
9240  	 	 	 }
9241  	 	 	 if ($info['cs'] == 'DeviceCMYK') {
9242  	 	 	 	 $out .= ' /Decode [1 0 1 0 1 0 1 0]';
9243  	 	 	 }
9244  	 	 	 $out .= ' /BitsPerComponent '.$info['bpc'];
9245  	 	 	 if (isset($altoid) AND ($altoid > 0)) {
9246  	 	 	 	 // reference to alternate images dictionary
9247  	 	 	 	 $out .= ' /Alternates '.$altoid.' 0 R';
9248  	 	 	 }
9249  	 	 	 if (isset($info['exurl']) AND !empty($info['exurl'])) {
9250  	 	 	 	 // external stream
9251  	 	 	 	 $out .= ' /Length 0';
9252  	 	 	 	 $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
9253  	 	 	 	 if (isset($info['f'])) {
9254  	 	 	 	 	 $out .= ' /FFilter /'.$info['f'];
9255  	 	 	 	 }
9256  	 	 	 	 $out .= ' >>';
9257  	 	 	 	 $out .= ' stream'."\n".'endstream';
9258  	 	 	 } else {
9259  	 	 	 	 if (isset($info['f'])) {
9260  	 	 	 	 	 $out .= ' /Filter /'.$info['f'];
9261  	 	 	 	 }
9262  	 	 	 	 if (isset($info['parms'])) {
9263  	 	 	 	 	 $out .= ' '.$info['parms'];
9264  	 	 	 	 }
9265  	 	 	 	 if (isset($info['trns']) AND is_array($info['trns'])) {
9266  	 	 	 	 	 $trns = '';
9267  	 	 	 	 	 $count_info = count($info['trns']);
9268  	 	 	 	 	 if ($info['cs'] == 'Indexed') {
9269  	 	 	 	 	 	 $maxval =(pow(2, $info['bpc']) - 1);
9270  	 	 	 	 	 	 for ($i = 0; $i < $count_info; ++$i) {
9271  	 	 	 	 	 	 	 if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
9272  	 	 	 	 	 	 	 	 // this is not a binary type mask @TODO: create a SMask
9273  	 	 	 	 	 	 	 	 $trns = '';
9274  	 	 	 	 	 	 	 	 break;
9275  	 	 	 	 	 	 	 } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
9276  	 	 	 	 	 	 	 	 // store the first fully transparent value
9277  	 	 	 	 	 	 	 	 $trns .= $i.' '.$i.' ';
9278  	 	 	 	 	 	 	 }
9279  	 	 	 	 	 	 }
9280  	 	 	 	 	 } else {
9281  	 	 	 	 	 	 // grayscale or RGB
9282  	 	 	 	 	 	 for ($i = 0; $i < $count_info; ++$i) {
9283  	 	 	 	 	 	 	 if ($info['trns'][$i] == 0) {
9284  	 	 	 	 	 	 	 	 $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
9285  	 	 	 	 	 	 	 }
9286  	 	 	 	 	 	 }
9287  	 	 	 	 	 }
9288  	 	 	 	 	 // Colour Key Masking
9289  	 	 	 	 	 if (!empty($trns)) {
9290  	 	 	 	 	 	 $out .= ' /Mask ['.$trns.']';
9291  	 	 	 	 	 }
9292  	 	 	 	 }
9293  	 	 	 	 $stream = $this->_getrawstream($info['data']);
9294  	 	 	 	 $out .= ' /Length '.strlen($stream).' >>';
9295  	 	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
9296  	 	 	 }
9297  	 	 	 $out .= "\n".'endobj';
9298  	 	 	 $this->_out($out);
9299  	 	 	 if ($icc) {
9300  	 	 	 	 // ICC colour profile
9301  	 	 	 	 $this->_newobj();
9302  	 	 	 	 $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
9303  	 	 	 	 $icc = $this->_getrawstream($icc);
9304  	 	 	 	 $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
9305  	 	 	 } elseif ($info['cs'] == 'Indexed') {
9306  	 	 	 	 // colour palette
9307  	 	 	 	 $this->_newobj();
9308  	 	 	 	 $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
9309  	 	 	 	 $pal = $this->_getrawstream($pal);
9310  	 	 	 	 $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
9311  	 	 	 }
9312  	 	 }
9313  	 }
9314  
9315  	 /**
9316  	  * Output Form XObjects Templates.
9317  	  * @author Nicola Asuni
9318  	  * @since 5.8.017 (2010-08-24)
9319  	  * @protected
9320  	  * @see startTemplate(), endTemplate(), printTemplate()
9321  	  */
9322  	protected function _putxobjects() {
9323  	 	 foreach ($this->xobjects as $key => $data) {
9324  	 	 	 if (isset($data['outdata'])) {
9325  	 	 	 	 $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
9326  	 	 	 	 $out = $this->_getobj($data['n'])."\n";
9327  	 	 	 	 $out .= '<<';
9328  	 	 	 	 $out .= ' /Type /XObject';
9329  	 	 	 	 $out .= ' /Subtype /Form';
9330  	 	 	 	 $out .= ' /FormType 1';
9331  	 	 	 	 if ($this->compress) {
9332  	 	 	 	 	 $stream = gzcompress($stream);
9333  	 	 	 	 	 $out .= ' /Filter /FlateDecode';
9334  	 	 	 	 }
9335  	 	 	 	 $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));
9336  	 	 	 	 $out .= ' /Matrix [1 0 0 1 0 0]';
9337  	 	 	 	 $out .= ' /Resources <<';
9338  	 	 	 	 $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
9339  	 	 	 	 if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
9340  	 	 	 	 	 // transparency
9341  	 	 	 	 	 if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
9342  	 	 	 	 	 	 $out .= ' /ExtGState <<';
9343  	 	 	 	 	 	 foreach ($data['extgstates'] as $k => $extgstate) {
9344  	 	 	 	 	 	 	 if (isset($this->extgstates[$k]['name'])) {
9345  	 	 	 	 	 	 	 	 $out .= ' /'.$this->extgstates[$k]['name'];
9346  	 	 	 	 	 	 	 } else {
9347  	 	 	 	 	 	 	 	 $out .= ' /GS'.$k;
9348  	 	 	 	 	 	 	 }
9349  	 	 	 	 	 	 	 $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
9350  	 	 	 	 	 	 }
9351  	 	 	 	 	 	 $out .= ' >>';
9352  	 	 	 	 	 }
9353  	 	 	 	 	 if (isset($data['gradients']) AND !empty($data['gradients'])) {
9354  	 	 	 	 	 	 $gp = '';
9355  	 	 	 	 	 	 $gs = '';
9356  	 	 	 	 	 	 foreach ($data['gradients'] as $id => $grad) {
9357  	 	 	 	 	 	 	 // gradient patterns
9358  	 	 	 	 	 	 	 $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
9359  	 	 	 	 	 	 	 // gradient shadings
9360  	 	 	 	 	 	 	 $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
9361  	 	 	 	 	 	 }
9362  	 	 	 	 	 	 $out .= ' /Pattern <<'.$gp.' >>';
9363  	 	 	 	 	 	 $out .= ' /Shading <<'.$gs.' >>';
9364  	 	 	 	 	 }
9365  	 	 	 	 }
9366  	 	 	 	 // spot colors
9367  	 	 	 	 if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
9368  	 	 	 	 	 $out .= ' /ColorSpace <<';
9369  	 	 	 	 	 foreach ($data['spot_colors'] as $name => $color) {
9370  	 	 	 	 	 	 $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
9371  	 	 	 	 	 }
9372  	 	 	 	 	 $out .= ' >>';
9373  	 	 	 	 }
9374  	 	 	 	 // fonts
9375  	 	 	 	 if (!empty($data['fonts'])) {
9376  	 	 	 	 	 $out .= ' /Font <<';
9377  	 	 	 	 	 foreach ($data['fonts'] as $fontkey => $fontid) {
9378  	 	 	 	 	 	 $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
9379  	 	 	 	 	 }
9380  	 	 	 	 	 $out .= ' >>';
9381  	 	 	 	 }
9382  	 	 	 	 // images or nested xobjects
9383  	 	 	 	 if (!empty($data['images']) OR !empty($data['xobjects'])) {
9384  	 	 	 	 	 $out .= ' /XObject <<';
9385  	 	 	 	 	 foreach ($data['images'] as $imgid) {
9386  	 	 	 	 	 	 $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
9387  	 	 	 	 	 }
9388  	 	 	 	 	 foreach ($data['xobjects'] as $sub_id => $sub_objid) {
9389  	 	 	 	 	 	 $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
9390  	 	 	 	 	 }
9391  	 	 	 	 	 $out .= ' >>';
9392  	 	 	 	 }
9393  	 	 	 	 $out .= ' >>'; //end resources
9394  	 	 	 	 if (isset($data['group']) AND ($data['group'] !== false)) {
9395  	 	 	 	 	 // set transparency group
9396  	 	 	 	 	 $out .= ' /Group << /Type /Group /S /Transparency';
9397  	 	 	 	 	 if (is_array($data['group'])) {
9398  	 	 	 	 	 	 if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
9399  	 	 	 	 	 	 	 $out .= ' /CS /'.$data['group']['CS'];
9400  	 	 	 	 	 	 }
9401  	 	 	 	 	 	 if (isset($data['group']['I'])) {
9402  	 	 	 	 	 	 	 $out .= ' /I /'.($data['group']['I']===true?'true':'false');
9403  	 	 	 	 	 	 }
9404  	 	 	 	 	 	 if (isset($data['group']['K'])) {
9405  	 	 	 	 	 	 	 $out .= ' /K /'.($data['group']['K']===true?'true':'false');
9406  	 	 	 	 	 	 }
9407  	 	 	 	 	 }
9408  	 	 	 	 	 $out .= ' >>';
9409  	 	 	 	 }
9410  	 	 	 	 $stream = $this->_getrawstream($stream, $data['n']);
9411  	 	 	 	 $out .= ' /Length '.strlen($stream);
9412  	 	 	 	 $out .= ' >>';
9413  	 	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
9414  	 	 	 	 $out .= "\n".'endobj';
9415  	 	 	 	 $this->_out($out);
9416  	 	 	 }
9417  	 	 }
9418  	 }
9419  
9420  	 /**
9421  	  * Output Spot Colors Resources.
9422  	  * @protected
9423  	  * @since 4.0.024 (2008-09-12)
9424  	  */
9425  	protected function _putspotcolors() {
9426  	 	 foreach ($this->spot_colors as $name => $color) {
9427  	 	 	 $this->_newobj();
9428  	 	 	 $this->spot_colors[$name]['n'] = $this->n;
9429  	 	 	 $out = '[/Separation /'.str_replace(' ', '#20', $name);
9430  	 	 	 $out .= ' /DeviceCMYK <<';
9431  	 	 	 $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
9432  	 	 	 $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
9433  	 	 	 $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
9434  	 	 	 $out .= "\n".'endobj';
9435  	 	 	 $this->_out($out);
9436  	 	 }
9437  	 }
9438  
9439  	 /**
9440  	  * Return XObjects Dictionary.
9441  	  * @return string XObjects dictionary
9442  	  * @protected
9443  	  * @since 5.8.014 (2010-08-23)
9444  	  */
9445  	protected function _getxobjectdict() {
9446  	 	 $out = '';
9447  	 	 foreach ($this->xobjects as $id => $objid) {
9448  	 	 	 $out .= ' /'.$id.' '.$objid['n'].' 0 R';
9449  	 	 }
9450  	 	 return $out;
9451  	 }
9452  
9453  	 /**
9454  	  * Output Resources Dictionary.
9455  	  * @protected
9456  	  */
9457  	protected function _putresourcedict() {
9458  	 	 $out = $this->_getobj(2)."\n";
9459  	 	 $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
9460  	 	 $out .= ' /Font <<';
9461  	 	 foreach ($this->fontkeys as $fontkey) {
9462  	 	 	 $font = $this->getFontBuffer($fontkey);
9463  	 	 	 $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
9464  	 	 }
9465  	 	 $out .= ' >>';
9466  	 	 $out .= ' /XObject <<';
9467  	 	 $out .= $this->_getxobjectdict();
9468  	 	 $out .= ' >>';
9469  	 	 // layers
9470  	 	 if (!empty($this->pdflayers)) {
9471  	 	 	 $out .= ' /Properties <<';
9472  	 	 	 foreach ($this->pdflayers as $layer) {
9473  	 	 	 	 $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
9474  	 	 	 }
9475  	 	 	 $out .= ' >>';
9476  	 	 }
9477  	 	 if (!$this->pdfa_mode || $this->pdfa_version >= 2) {
9478  	 	 	 // transparency
9479  	 	 	 if (isset($this->extgstates) AND !empty($this->extgstates)) {
9480  	 	 	 	 $out .= ' /ExtGState <<';
9481  	 	 	 	 foreach ($this->extgstates as $k => $extgstate) {
9482  	 	 	 	 	 if (isset($extgstate['name'])) {
9483  	 	 	 	 	 	 $out .= ' /'.$extgstate['name'];
9484  	 	 	 	 	 } else {
9485  	 	 	 	 	 	 $out .= ' /GS'.$k;
9486  	 	 	 	 	 }
9487  	 	 	 	 	 $out .= ' '.$extgstate['n'].' 0 R';
9488  	 	 	 	 }
9489  	 	 	 	 $out .= ' >>';
9490  	 	 	 }
9491  	 	 	 if (isset($this->gradients) AND !empty($this->gradients)) {
9492  	 	 	 	 $gp = '';
9493  	 	 	 	 $gs = '';
9494  	 	 	 	 foreach ($this->gradients as $id => $grad) {
9495  	 	 	 	 	 // gradient patterns
9496  	 	 	 	 	 $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
9497  	 	 	 	 	 // gradient shadings
9498  	 	 	 	 	 $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
9499  	 	 	 	 }
9500  	 	 	 	 $out .= ' /Pattern <<'.$gp.' >>';
9501  	 	 	 	 $out .= ' /Shading <<'.$gs.' >>';
9502  	 	 	 }
9503  	 	 }
9504  	 	 // spot colors
9505  	 	 if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
9506  	 	 	 $out .= ' /ColorSpace <<';
9507  	 	 	 foreach ($this->spot_colors as $color) {
9508  	 	 	 	 $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
9509  	 	 	 }
9510  	 	 	 $out .= ' >>';
9511  	 	 }
9512  	 	 $out .= ' >>';
9513  	 	 $out .= "\n".'endobj';
9514  	 	 $this->_out($out);
9515  	 }
9516  
9517  	 /**
9518  	  * Output Resources.
9519  	  * @protected
9520  	  */
9521  	protected function _putresources() {
9522  	 	 $this->_putextgstates();
9523  	 	 $this->_putocg();
9524  	 	 $this->_putfonts();
9525  	 	 $this->_putimages();
9526  	 	 $this->_putspotcolors();
9527  	 	 $this->_putshaders();
9528  	 	 $this->_putxobjects();
9529  	 	 $this->_putresourcedict();
9530  	 	 $this->_putdests();
9531  	 	 $this->_putEmbeddedFiles();
9532  	 	 $this->_putannotsobjs();
9533  	 	 $this->_putjavascript();
9534  	 	 $this->_putbookmarks();
9535  	 	 $this->_putencryption();
9536  	 }
9537  
9538  	 /**
9539  	  * Adds some Metadata information (Document Information Dictionary)
9540  	  * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
9541  	  * @return int object id
9542  	  * @protected
9543  	  */
9544  	protected function _putinfo() {
9545  	 	 $oid = $this->_newobj();
9546  	 	 $out = '<<';
9547  	 	 // store current isunicode value
9548  	 	 $prev_isunicode = $this->isunicode;
9549  	 	 if ($this->docinfounicode) {
9550  	 	 	 $this->isunicode = true;
9551  	 	 }
9552  	 	 if (!TCPDF_STATIC::empty_string($this->title)) {
9553  	 	 	 // The document's title.
9554  	 	 	 $out .= ' /Title '.$this->_textstring($this->title, $oid);
9555  	 	 }
9556  	 	 if (!TCPDF_STATIC::empty_string($this->author)) {
9557  	 	 	 // The name of the person who created the document.
9558  	 	 	 $out .= ' /Author '.$this->_textstring($this->author, $oid);
9559  	 	 }
9560  	 	 if (!TCPDF_STATIC::empty_string($this->subject)) {
9561  	 	 	 // The subject of the document.
9562  	 	 	 $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
9563  	 	 }
9564  	 	 if (!TCPDF_STATIC::empty_string($this->keywords)) {
9565  	 	 	 // Keywords associated with the document.
9566  	 	 	 $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
9567  	 	 }
9568  	 	 if (!TCPDF_STATIC::empty_string($this->creator)) {
9569  	 	 	 // 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.
9570  	 	 	 $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
9571  	 	 }
9572  	 	 // restore previous isunicode value
9573  	 	 $this->isunicode = $prev_isunicode;
9574  	 	 // default producer
9575  	 	 $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
9576  	 	 // The date and time the document was created, in human-readable form
9577  	 	 $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
9578  	 	 // The date and time the document was most recently modified, in human-readable form
9579  	 	 $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
9580  	 	 // A name object indicating whether the document has been modified to include trapping information
9581  	 	 $out .= ' /Trapped /False';
9582  	 	 $out .= ' >>';
9583  	 	 $out .= "\n".'endobj';
9584  	 	 $this->_out($out);
9585  	 	 return $oid;
9586  	 }
9587  
9588  	 /**
9589  	  * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
9590  	  * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
9591  	  * @param string $xmp Custom XMP data.
9592  	  * @since 5.9.128 (2011-10-06)
9593  	  * @public
9594  	  */
9595  	public function setExtraXMP($xmp) {
9596  	 	 $this->custom_xmp = $xmp;
9597  	 }
9598  
9599  	 /**
9600  	  * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag.
9601  	  * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
9602  	  * @param string $xmp Custom XMP RDF data.
9603  	  * @since 6.3.0 (2019-09-19)
9604  	  * @public
9605  	  */
9606  	public function setExtraXMPRDF($xmp) {
9607  	 	 $this->custom_xmp_rdf = $xmp;
9608  	 }
9609  
9610  	 /**
9611  	  * Put XMP data object and return ID.
9612  	  * @return int The object ID.
9613  	  * @since 5.9.121 (2011-09-28)
9614  	  * @protected
9615  	  */
9616  	protected function _putXMP() {
9617  	 	 $oid = $this->_newobj();
9618  	 	 // store current isunicode value
9619  	 	 $prev_isunicode = $this->isunicode;
9620  	 	 $this->isunicode = true;
9621  	 	 $prev_encrypted = $this->encrypted;
9622  	 	 $this->encrypted = false;
9623  	 	 // set XMP data
9624  	 	 $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
9625  	 	 $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";
9626  	 	 $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
9627  	 	 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
9628  	 	 $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
9629  	 	 $xmp .= "\t\t\t".'<dc:title>'."\n";
9630  	 	 $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
9631  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
9632  	 	 $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
9633  	 	 $xmp .= "\t\t\t".'</dc:title>'."\n";
9634  	 	 $xmp .= "\t\t\t".'<dc:creator>'."\n";
9635  	 	 $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
9636  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
9637  	 	 $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
9638  	 	 $xmp .= "\t\t\t".'</dc:creator>'."\n";
9639  	 	 $xmp .= "\t\t\t".'<dc:description>'."\n";
9640  	 	 $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
9641  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
9642  	 	 $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
9643  	 	 $xmp .= "\t\t\t".'</dc:description>'."\n";
9644  	 	 $xmp .= "\t\t\t".'<dc:subject>'."\n";
9645  	 	 $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
9646  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
9647  	 	 $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
9648  	 	 $xmp .= "\t\t\t".'</dc:subject>'."\n";
9649  	 	 $xmp .= "\t\t".'</rdf:Description>'."\n";
9650  	 	 // convert doc creation date format
9651  	 	 $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
9652  	 	 $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
9653  	 	 $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
9654  	 	 $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
9655  	 	 $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
9656  	 	 // convert doc modification date format
9657  	 	 $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
9658  	 	 $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
9659  	 	 $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
9660  	 	 $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
9661  	 	 $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
9662  	 	 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
9663  	 	 $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
9664  	 	 $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
9665  	 	 $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
9666  	 	 $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
9667  	 	 $xmp .= "\t\t".'</rdf:Description>'."\n";
9668  	 	 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
9669  	 	 $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
9670  	 	 $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
9671  	 	 $xmp .= "\t\t".'</rdf:Description>'."\n";
9672  	 	 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
9673  	 	 $uuid = 'uuid:'.substr($this->file_id, 0, 8).'-'.substr($this->file_id, 8, 4).'-'.substr($this->file_id, 12, 4).'-'.substr($this->file_id, 16, 4).'-'.substr($this->file_id, 20, 12);
9674  	 	 $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
9675  	 	 $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
9676  	 	 $xmp .= "\t\t".'</rdf:Description>'."\n";
9677  	 	 if ($this->pdfa_mode) {
9678  	 	 	 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
9679  	 	 	 $xmp .= "\t\t\t".'<pdfaid:part>'.$this->pdfa_version.'</pdfaid:part>'."\n";
9680  	 	 	 $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
9681  	 	 	 $xmp .= "\t\t".'</rdf:Description>'."\n";
9682  	 	 }
9683  	 	 // XMP extension schemas
9684  	 	 $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";
9685  	 	 $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
9686  	 	 $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
9687  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9688  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
9689  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
9690  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
9691  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
9692  	 	 $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
9693  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9694  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9695  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Adobe PDF Schema</pdfaProperty:description>'."\n";
9696  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
9697  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
9698  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9699  	 	 $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
9700  	 	 $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
9701  	 	 $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
9702  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9703  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
9704  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
9705  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
9706  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
9707  	 	 $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
9708  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9709  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9710  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
9711  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
9712  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
9713  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9714  	 	 $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
9715  	 	 $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
9716  	 	 $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
9717  	 	 $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9718  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
9719  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
9720  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
9721  	 	 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
9722  	 	 $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
9723  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9724  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9725  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
9726  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
9727  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
9728  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9729  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9730  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9731  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
9732  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
9733  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
9734  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9735  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9736  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9737  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
9738  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
9739  	 	 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
9740  	 	 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9741  	 	 $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
9742  	 	 $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
9743  	 	 $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
9744  	 	 $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
9745  	 	 $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
9746  	 	 $xmp .= "\t\t".'</rdf:Description>'."\n";
9747  	 	 $xmp .= $this->custom_xmp_rdf;
9748  	 	 $xmp .= "\t".'</rdf:RDF>'."\n";
9749  	 	 $xmp .= $this->custom_xmp;
9750  	 	 $xmp .= '</x:xmpmeta>'."\n";
9751  	 	 $xmp .= '<?xpacket end="w"?>';
9752  	 	 $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
9753  	 	 // restore previous isunicode value
9754  	 	 $this->isunicode = $prev_isunicode;
9755  	 	 $this->encrypted = $prev_encrypted;
9756  	 	 $this->_out($out);
9757  	 	 return $oid;
9758  	 }
9759  
9760  	 /**
9761  	  * Output Catalog.
9762  	  * @return int object id
9763  	  * @protected
9764  	  */
9765  	protected function _putcatalog() {
9766  	 	 // put XMP
9767  	 	 $xmpobj = $this->_putXMP();
9768  	 	 // if required, add standard sRGB ICC colour profile
9769  	 	 if ($this->pdfa_mode OR $this->force_srgb) {
9770  	 	 	 $iccobj = $this->_newobj();
9771  	 	 	 $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
9772  	 	 	 $filter = '';
9773  	 	 	 if ($this->compress) {
9774  	 	 	 	 $filter = ' /Filter /FlateDecode';
9775  	 	 	 	 $icc = gzcompress($icc);
9776  	 	 	 }
9777  	 	 	 $icc = $this->_getrawstream($icc);
9778  	 	 	 $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
9779  	 	 }
9780  	 	 // start catalog
9781  	 	 $oid = $this->_newobj();
9782  	 	 $out = '<< /Type /Catalog';
9783  	 	 $out .= ' /Version /'.$this->PDFVersion;
9784  	 	 //$out .= ' /Extensions <<>>';
9785  	 	 $out .= ' /Pages 1 0 R';
9786  	 	 //$out .= ' /PageLabels ' //...;
9787  	 	 $out .= ' /Names <<';
9788  	 	 if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
9789  	 	 	 $out .= ' /JavaScript '.$this->n_js;
9790  	 	 }
9791  	 	 if (!empty($this->efnames)) {
9792  	 	 	 $out .= ' /EmbeddedFiles <</Names [';
9793  	 	 	 foreach ($this->efnames AS $fn => $fref) {
9794  	 	 	 	 $out .= ' '.$this->_datastring($fn).' '.$fref;
9795  	 	 	 }
9796  	 	 	 $out .= ' ]>>';
9797  	 	 }
9798  	 	 $out .= ' >>';
9799  	 	 if (!empty($this->dests)) {
9800  	 	 	 $out .= ' /Dests '.($this->n_dests).' 0 R';
9801  	 	 }
9802  	 	 $out .= $this->_putviewerpreferences();
9803  	 	 if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
9804  	 	 	 $out .= ' /PageLayout /'.$this->LayoutMode;
9805  	 	 }
9806  	 	 if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
9807  	 	 	 $out .= ' /PageMode /'.$this->PageMode;
9808  	 	 }
9809  	 	 if (count($this->outlines) > 0) {
9810  	 	 	 $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
9811  	 	 	 $out .= ' /PageMode /UseOutlines';
9812  	 	 }
9813  	 	 //$out .= ' /Threads []';
9814  	 	 if ($this->ZoomMode == 'fullpage') {
9815  	 	 	 $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
9816  	 	 } elseif ($this->ZoomMode == 'fullwidth') {
9817  	 	 	 $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
9818  	 	 } elseif ($this->ZoomMode == 'real') {
9819  	 	 	 $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
9820  	 	 } elseif (!is_string($this->ZoomMode)) {
9821  	 	 	 $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
9822  	 	 }
9823  	 	 //$out .= ' /AA <<>>';
9824  	 	 //$out .= ' /URI <<>>';
9825  	 	 $out .= ' /Metadata '.$xmpobj.' 0 R';
9826  	 	 //$out .= ' /StructTreeRoot <<>>';
9827  	 	 //$out .= ' /MarkInfo <<>>';
9828  	 	 if (isset($this->l['a_meta_language'])) {
9829  	 	 	 $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
9830  	 	 }
9831  	 	 //$out .= ' /SpiderInfo <<>>';
9832  	 	 // set OutputIntent to sRGB IEC61966-2.1 if required
9833  	 	 if ($this->pdfa_mode OR $this->force_srgb) {
9834  	 	 	 $out .= ' /OutputIntents [<<';
9835  	 	 	 $out .= ' /Type /OutputIntent';
9836  	 	 	 $out .= ' /S /GTS_PDFA1';
9837  	 	 	 $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
9838  	 	 	 $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
9839  	 	 	 $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
9840  	 	 	 $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
9841  	 	 	 $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
9842  	 	 	 $out .= ' >>]';
9843  	 	 }
9844  	 	 //$out .= ' /PieceInfo <<>>';
9845  	 	 if (!empty($this->pdflayers)) {
9846  	 	 	 $lyrobjs = '';
9847  	 	 	 $lyrobjs_off = '';
9848  	 	 	 $lyrobjs_lock = '';
9849  	 	 	 foreach ($this->pdflayers as $layer) {
9850  	 	 	 	 $layer_obj_ref = ' '.$layer['objid'].' 0 R';
9851  	 	 	 	 $lyrobjs .= $layer_obj_ref;
9852  	 	 	 	 if ($layer['view'] === false) {
9853  	 	 	 	 	 $lyrobjs_off .= $layer_obj_ref;
9854  	 	 	 	 }
9855  	 	 	 	 if ($layer['lock']) {
9856  	 	 	 	 	 $lyrobjs_lock .= $layer_obj_ref;
9857  	 	 	 	 }
9858  	 	 	 }
9859  	 	 	 $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
9860  	 	 	 $out .= ' /D <<';
9861  	 	 	 $out .= ' /Name '.$this->_textstring('Layers', $oid);
9862  	 	 	 $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
9863  	 	 	 $out .= ' /BaseState /ON';
9864  	 	 	 $out .= ' /OFF ['.$lyrobjs_off.']';
9865  	 	 	 $out .= ' /Locked ['.$lyrobjs_lock.']';
9866  	 	 	 $out .= ' /Intent /View';
9867  	 	 	 $out .= ' /AS [';
9868  	 	 	 $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
9869  	 	 	 $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
9870  	 	 	 $out .= ' ]';
9871  	 	 	 $out .= ' /Order ['.$lyrobjs.']';
9872  	 	 	 $out .= ' /ListMode /AllPages';
9873  	 	 	 //$out .= ' /RBGroups ['..']';
9874  	 	 	 //$out .= ' /Locked ['..']';
9875  	 	 	 $out .= ' >>';
9876  	 	 	 $out .= ' >>';
9877  	 	 }
9878  	 	 // AcroForm
9879  	 	 if (!empty($this->form_obj_id)
9880  	 	 	 OR ($this->sign AND isset($this->signature_data['cert_type']))
9881  	 	 	 OR !empty($this->empty_signature_appearance)) {
9882  	 	 	 $out .= ' /AcroForm <<';
9883  	 	 	 $objrefs = '';
9884  	 	 	 if ($this->sign AND isset($this->signature_data['cert_type'])) {
9885  	 	 	 	 // set reference for signature object
9886  	 	 	 	 $objrefs .= $this->sig_obj_id.' 0 R';
9887  	 	 	 }
9888  	 	 	 if (!empty($this->empty_signature_appearance)) {
9889  	 	 	 	 foreach ($this->empty_signature_appearance as $esa) {
9890  	 	 	 	 	 // set reference for empty signature objects
9891  	 	 	 	 	 $objrefs .= ' '.$esa['objid'].' 0 R';
9892  	 	 	 	 }
9893  	 	 	 }
9894  	 	 	 if (!empty($this->form_obj_id)) {
9895  	 	 	 	 foreach($this->form_obj_id as $objid) {
9896  	 	 	 	 	 $objrefs .= ' '.$objid.' 0 R';
9897  	 	 	 	 }
9898  	 	 	 }
9899  	 	 	 $out .= ' /Fields ['.$objrefs.']';
9900  	 	 	 // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
9901  	 	 	 if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
9902  	 	 	 	 $out .= ' /NeedAppearances false';
9903  	 	 	 }
9904  	 	 	 if ($this->sign AND isset($this->signature_data['cert_type'])) {
9905  	 	 	 	 if ($this->signature_data['cert_type'] > 0) {
9906  	 	 	 	 	 $out .= ' /SigFlags 3';
9907  	 	 	 	 } else {
9908  	 	 	 	 	 $out .= ' /SigFlags 1';
9909  	 	 	 	 }
9910  	 	 	 }
9911  	 	 	 //$out .= ' /CO ';
9912  	 	 	 if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
9913  	 	 	 	 $out .= ' /DR <<';
9914  	 	 	 	 $out .= ' /Font <<';
9915  	 	 	 	 foreach ($this->annotation_fonts as $fontkey => $fontid) {
9916  	 	 	 	 	 $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
9917  	 	 	 	 }
9918  	 	 	 	 $out .= ' >> >>';
9919  	 	 	 }
9920  	 	 	 $font = $this->getFontBuffer('helvetica');
9921  	 	 	 $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
9922  	 	 	 $out .= ' /Q '.(($this->rtl)?'2':'0');
9923  	 	 	 //$out .= ' /XFA ';
9924  	 	 	 $out .= ' >>';
9925  	 	 	 // signatures
9926  	 	 	 if ($this->sign AND isset($this->signature_data['cert_type'])
9927  	 	 	 	 AND (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A'))) {
9928  	 	 	 	 if ($this->signature_data['cert_type'] > 0) {
9929  	 	 	 	 	 $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
9930  	 	 	 	 } else {
9931  	 	 	 	 	 $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
9932  	 	 	 	 }
9933  	 	 	 }
9934  	 	 }
9935  	 	 //$out .= ' /Legal <<>>';
9936  	 	 //$out .= ' /Requirements []';
9937  	 	 //$out .= ' /Collection <<>>';
9938  	 	 //$out .= ' /NeedsRendering true';
9939  	 	 $out .= ' >>';
9940  	 	 $out .= "\n".'endobj';
9941  	 	 $this->_out($out);
9942  	 	 return $oid;
9943  	 }
9944  
9945  	 /**
9946  	  * Output viewer preferences.
9947  	  * @return string for viewer preferences
9948  	  * @author Nicola asuni
9949  	  * @since 3.1.000 (2008-06-09)
9950  	  * @protected
9951  	  */
9952  	protected function _putviewerpreferences() {
9953  	 	 $vp = $this->viewer_preferences;
9954  	 	 $out = ' /ViewerPreferences <<';
9955  	 	 if ($this->rtl) {
9956  	 	 	 $out .= ' /Direction /R2L';
9957  	 	 } else {
9958  	 	 	 $out .= ' /Direction /L2R';
9959  	 	 }
9960  	 	 if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
9961  	 	 	 $out .= ' /HideToolbar true';
9962  	 	 }
9963  	 	 if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
9964  	 	 	 $out .= ' /HideMenubar true';
9965  	 	 }
9966  	 	 if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
9967  	 	 	 $out .= ' /HideWindowUI true';
9968  	 	 }
9969  	 	 if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
9970  	 	 	 $out .= ' /FitWindow true';
9971  	 	 }
9972  	 	 if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
9973  	 	 	 $out .= ' /CenterWindow true';
9974  	 	 }
9975  	 	 if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
9976  	 	 	 $out .= ' /DisplayDocTitle true';
9977  	 	 }
9978  	 	 if (isset($vp['NonFullScreenPageMode'])) {
9979  	 	 	 $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
9980  	 	 }
9981  	 	 if (isset($vp['ViewArea'])) {
9982  	 	 	 $out .= ' /ViewArea /'.$vp['ViewArea'];
9983  	 	 }
9984  	 	 if (isset($vp['ViewClip'])) {
9985  	 	 	 $out .= ' /ViewClip /'.$vp['ViewClip'];
9986  	 	 }
9987  	 	 if (isset($vp['PrintArea'])) {
9988  	 	 	 $out .= ' /PrintArea /'.$vp['PrintArea'];
9989  	 	 }
9990  	 	 if (isset($vp['PrintClip'])) {
9991  	 	 	 $out .= ' /PrintClip /'.$vp['PrintClip'];
9992  	 	 }
9993  	 	 if (isset($vp['PrintScaling'])) {
9994  	 	 	 $out .= ' /PrintScaling /'.$vp['PrintScaling'];
9995  	 	 }
9996  	 	 if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
9997  	 	 	 $out .= ' /Duplex /'.$vp['Duplex'];
9998  	 	 }
9999  	 	 if (isset($vp['PickTrayByPDFSize'])) {
10000  	 	 	 if ($vp['PickTrayByPDFSize']) {
10001  	 	 	 	 $out .= ' /PickTrayByPDFSize true';
10002  	 	 	 } else {
10003  	 	 	 	 $out .= ' /PickTrayByPDFSize false';
10004  	 	 	 }
10005  	 	 }
10006  	 	 if (isset($vp['PrintPageRange'])) {
10007  	 	 	 $PrintPageRangeNum = '';
10008  	 	 	 foreach ($vp['PrintPageRange'] as $k => $v) {
10009  	 	 	 	 $PrintPageRangeNum .= ' '.($v - 1).'';
10010  	 	 	 }
10011  	 	 	 $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
10012  	 	 }
10013  	 	 if (isset($vp['NumCopies'])) {
10014  	 	 	 $out .= ' /NumCopies '.intval($vp['NumCopies']);
10015  	 	 }
10016  	 	 $out .= ' >>';
10017  	 	 return $out;
10018  	 }
10019  
10020  	 /**
10021  	  * Output PDF File Header (7.5.2).
10022  	  * @protected
10023  	  */
10024  	protected function _putheader() {
10025  	 	 $this->_out('%PDF-'.$this->PDFVersion);
10026  	 	 $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
10027  	 }
10028  
10029  	 /**
10030  	  * Output end of document (EOF).
10031  	  * @protected
10032  	  */
10033  	protected function _enddoc() {
10034  	 	 if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
10035  	 	 	 // save subset chars of the previous font
10036  	 	 	 $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
10037  	 	 }
10038  	 	 $this->state = 1;
10039  	 	 $this->_putheader();
10040  	 	 $this->_putpages();
10041  	 	 $this->_putresources();
10042  	 	 // empty signature fields
10043  	 	 if (!empty($this->empty_signature_appearance)) {
10044  	 	 	 foreach ($this->empty_signature_appearance as $key => $esa) {
10045  	 	 	 	 // widget annotation for empty signature
10046  	 	 	 	 $out = $this->_getobj($esa['objid'])."\n";
10047  	 	 	 	 $out .= '<< /Type /Annot';
10048  	 	 	 	 $out .= ' /Subtype /Widget';
10049  	 	 	 	 $out .= ' /Rect ['.$esa['rect'].']';
10050  	 	 	 	 $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
10051  	 	 	 	 $out .= ' /F 4';
10052  	 	 	 	 $out .= ' /FT /Sig';
10053  	 	 	 	 $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
10054  	 	 	 	 $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
10055  	 	 	 	 $out .= ' /Ff 0';
10056  	 	 	 	 $out .= ' >>';
10057  	 	 	 	 $out .= "\n".'endobj';
10058  	 	 	 	 $this->_out($out);
10059  	 	 	 }
10060  	 	 }
10061  	 	 // Signature
10062  	 	 if ($this->sign AND isset($this->signature_data['cert_type'])) {
10063  	 	 	 // widget annotation for signature
10064  	 	 	 $out = $this->_getobj($this->sig_obj_id)."\n";
10065  	 	 	 $out .= '<< /Type /Annot';
10066  	 	 	 $out .= ' /Subtype /Widget';
10067  	 	 	 $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
10068  	 	 	 $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
10069  	 	 	 $out .= ' /F 4';
10070  	 	 	 $out .= ' /FT /Sig';
10071  	 	 	 $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
10072  	 	 	 $out .= ' /Ff 0';
10073  	 	 	 $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
10074  	 	 	 $out .= ' >>';
10075  	 	 	 $out .= "\n".'endobj';
10076  	 	 	 $this->_out($out);
10077  	 	 	 // signature
10078  	 	 	 $this->_putsignature();
10079  	 	 }
10080  	 	 // Info
10081  	 	 $objid_info = $this->_putinfo();
10082  	 	 // Catalog
10083  	 	 $objid_catalog = $this->_putcatalog();
10084  	 	 // Cross-ref
10085  	 	 $o = $this->bufferlen;
10086  	 	 // XREF section
10087  	 	 $this->_out('xref');
10088  	 	 $this->_out('0 '.($this->n + 1));
10089  	 	 $this->_out('0000000000 65535 f ');
10090  	 	 $freegen = ($this->n + 2);
10091  	 	 for ($i=1; $i <= $this->n; ++$i) {
10092  	 	 	 if (!isset($this->offsets[$i]) AND ($i > 1)) {
10093  	 	 	 	 $this->_out(sprintf('0000000000 %05d f ', $freegen));
10094  	 	 	 	 ++$freegen;
10095  	 	 	 } else {
10096  	 	 	 	 $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
10097  	 	 	 }
10098  	 	 }
10099  	 	 // TRAILER
10100  	 	 $out = 'trailer'."\n";
10101  	 	 $out .= '<<';
10102  	 	 $out .= ' /Size '.($this->n + 1);
10103  	 	 $out .= ' /Root '.$objid_catalog.' 0 R';
10104  	 	 $out .= ' /Info '.$objid_info.' 0 R';
10105  	 	 if ($this->encrypted) {
10106  	 	 	 $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
10107  	 	 }
10108  	 	 $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
10109  	 	 $out .= ' >>';
10110  	 	 $this->_out($out);
10111  	 	 $this->_out('startxref');
10112  	 	 $this->_out($o);
10113  	 	 $this->_out('%%EOF');
10114  	 	 $this->state = 3; // end-of-doc
10115  	 }
10116  
10117  	 /**
10118  	  * Initialize a new page.
10119  	  * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
10120  	  * @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().
10121  	  * @protected
10122  	  * @see getPageSizeFromFormat(), setPageFormat()
10123  	  */
10124  	protected function _beginpage($orientation='', $format='') {
10125  	 	 ++$this->page;
10126  	 	 $this->pageobjects[$this->page] = array();
10127  	 	 $this->setPageBuffer($this->page, '');
10128  	 	 // initialize array for graphics tranformation positions inside a page buffer
10129  	 	 $this->transfmrk[$this->page] = array();
10130  	 	 $this->state = 2;
10131  	 	 if (TCPDF_STATIC::empty_string($orientation)) {
10132  	 	 	 if (isset($this->CurOrientation)) {
10133  	 	 	 	 $orientation = $this->CurOrientation;
10134  	 	 	 } elseif ($this->fwPt > $this->fhPt) {
10135  	 	 	 	 // landscape
10136  	 	 	 	 $orientation = 'L';
10137  	 	 	 } else {
10138  	 	 	 	 // portrait
10139  	 	 	 	 $orientation = 'P';
10140  	 	 	 }
10141  	 	 }
10142  	 	 if (TCPDF_STATIC::empty_string($format)) {
10143  	 	 	 $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
10144  	 	 	 $this->setPageOrientation($orientation);
10145  	 	 } else {
10146  	 	 	 $this->setPageFormat($format, $orientation);
10147  	 	 }
10148  	 	 if ($this->rtl) {
10149  	 	 	 $this->x = $this->w - $this->rMargin;
10150  	 	 } else {
10151  	 	 	 $this->x = $this->lMargin;
10152  	 	 }
10153  	 	 $this->y = $this->tMargin;
10154  	 	 if (isset($this->newpagegroup[$this->page])) {
10155  	 	 	 // start a new group
10156  	 	 	 $this->currpagegroup = $this->newpagegroup[$this->page];
10157  	 	 	 $this->pagegroups[$this->currpagegroup] = 1;
10158  	 	 } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
10159  	 	 	 ++$this->pagegroups[$this->currpagegroup];
10160  	 	 }
10161  	 }
10162  
10163  	 /**
10164  	  * Mark end of page.
10165  	  * @protected
10166  	  */
10167  	protected function _endpage() {
10168  	 	 $this->setVisibility('all');
10169  	 	 $this->state = 1;
10170  	 }
10171  
10172  	 /**
10173  	  * Begin a new object and return the object number.
10174  	  * @return int object number
10175  	  * @protected
10176  	  */
10177  	protected function _newobj() {
10178  	 	 $this->_out($this->_getobj());
10179  	 	 return $this->n;
10180  	 }
10181  
10182  	 /**
10183  	  * Return the starting object string for the selected object ID.
10184  	  * @param int|null $objid Object ID (leave empty to get a new ID).
10185  	  * @return string the starting object string
10186  	  * @protected
10187  	  * @since 5.8.009 (2010-08-20)
10188  	  */
10189  	protected function _getobj($objid=null) {
10190  	 	 if (TCPDF_STATIC::empty_string($objid)) {
10191  	 	 	 ++$this->n;
10192  	 	 	 $objid = $this->n;
10193  	 	 }
10194  	 	 $this->offsets[$objid] = $this->bufferlen;
10195  	 	 $this->pageobjects[$this->page][] = $objid;
10196  	 	 return $objid.' 0 obj';
10197  	 }
10198  
10199  	 /**
10200  	  * Underline text.
10201  	  * @param int $x X coordinate
10202  	  * @param int $y Y coordinate
10203  	  * @param string $txt text to underline
10204  	  * @protected
10205  	  */
10206  	protected function _dounderline($x, $y, $txt) {
10207  	 	 $w = $this->GetStringWidth($txt);
10208  	 	 return $this->_dounderlinew($x, $y, $w);
10209  	 }
10210  
10211  	 /**
10212  	  * Underline for rectangular text area.
10213  	  * @param int $x X coordinate
10214  	  * @param int $y Y coordinate
10215  	  * @param int $w width to underline
10216  	  * @protected
10217  	  * @since 4.8.008 (2009-09-29)
10218  	  */
10219  	protected function _dounderlinew($x, $y, $w) {
10220  	 	 $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
10221  	 	 return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
10222  	 }
10223  
10224  	 /**
10225  	  * Line through text.
10226  	  * @param int $x X coordinate
10227  	  * @param int $y Y coordinate
10228  	  * @param string $txt text to linethrough
10229  	  * @protected
10230  	  */
10231  	protected function _dolinethrough($x, $y, $txt) {
10232  	 	 $w = $this->GetStringWidth($txt);
10233  	 	 return $this->_dolinethroughw($x, $y, $w);
10234  	 }
10235  
10236  	 /**
10237  	  * Line through for rectangular text area.
10238  	  * @param int $x X coordinate
10239  	  * @param int $y Y coordinate
10240  	  * @param int $w line length (width)
10241  	  * @protected
10242  	  * @since 4.9.008 (2009-09-29)
10243  	  */
10244  	protected function _dolinethroughw($x, $y, $w) {
10245  	 	 $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
10246  	 	 return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
10247  	 }
10248  
10249  	 /**
10250  	  * Overline text.
10251  	  * @param int $x X coordinate
10252  	  * @param int $y Y coordinate
10253  	  * @param string $txt text to overline
10254  	  * @protected
10255  	  * @since 4.9.015 (2010-04-19)
10256  	  */
10257  	protected function _dooverline($x, $y, $txt) {
10258  	 	 $w = $this->GetStringWidth($txt);
10259  	 	 return $this->_dooverlinew($x, $y, $w);
10260  	 }
10261  
10262  	 /**
10263  	  * Overline for rectangular text area.
10264  	  * @param int $x X coordinate
10265  	  * @param int $y Y coordinate
10266  	  * @param int $w width to overline
10267  	  * @protected
10268  	  * @since 4.9.015 (2010-04-19)
10269  	  */
10270  	protected function _dooverlinew($x, $y, $w) {
10271  	 	 $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
10272  	 	 return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
10273  
10274  	 }
10275  
10276  	 /**
10277  	  * Format a data string for meta information
10278  	  * @param string $s data string to escape.
10279  	  * @param int $n object ID
10280  	  * @return string escaped string.
10281  	  * @protected
10282  	  */
10283  	protected function _datastring($s, $n=0) {
10284  	 	 if ($n == 0) {
10285  	 	 	 $n = $this->n;
10286  	 	 }
10287  	 	 $s = $this->_encrypt_data($n, $s);
10288  	 	 return '('. TCPDF_STATIC::_escape($s).')';
10289  	 }
10290  
10291  	 /**
10292  	  * Set the document creation timestamp
10293  	  * @param mixed $time Document creation timestamp in seconds or date-time string.
10294  	  * @public
10295  	  * @since 5.9.152 (2012-03-23)
10296  	  */
10297  	public function setDocCreationTimestamp($time) {
10298  	 	 if (is_string($time)) {
10299  	 	 	 $time = TCPDF_STATIC::getTimestamp($time);
10300  	 	 }
10301  	 	 $this->doc_creation_timestamp = intval($time);
10302  	 }
10303  
10304  	 /**
10305  	  * Set the document modification timestamp
10306  	  * @param mixed $time Document modification timestamp in seconds or date-time string.
10307  	  * @public
10308  	  * @since 5.9.152 (2012-03-23)
10309  	  */
10310  	public function setDocModificationTimestamp($time) {
10311  	 	 if (is_string($time)) {
10312  	 	 	 $time = TCPDF_STATIC::getTimestamp($time);
10313  	 	 }
10314  	 	 $this->doc_modification_timestamp = intval($time);
10315  	 }
10316  
10317  	 /**
10318  	  * Returns document creation timestamp in seconds.
10319  	  * @return int Creation timestamp in seconds.
10320  	  * @public
10321  	  * @since 5.9.152 (2012-03-23)
10322  	  */
10323  	public function getDocCreationTimestamp() {
10324  	 	 return $this->doc_creation_timestamp;
10325  	 }
10326  
10327  	 /**
10328  	  * Returns document modification timestamp in seconds.
10329  	  * @return int Modfication timestamp in seconds.
10330  	  * @public
10331  	  * @since 5.9.152 (2012-03-23)
10332  	  */
10333  	public function getDocModificationTimestamp() {
10334  	 	 return $this->doc_modification_timestamp;
10335  	 }
10336  
10337  	 /**
10338  	  * Returns a formatted date for meta information
10339  	  * @param int $n Object ID.
10340  	  * @param int $timestamp Timestamp to convert.
10341  	  * @return string escaped date string.
10342  	  * @protected
10343  	  * @since 4.6.028 (2009-08-25)
10344  	  */
10345  	protected function _datestring($n=0, $timestamp=0) {
10346  	 	 if ((empty($timestamp)) OR ($timestamp < 0)) {
10347  	 	 	 $timestamp = $this->doc_creation_timestamp;
10348  	 	 }
10349  	 	 return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
10350  	 }
10351  
10352  	 /**
10353  	  * Format a text string for meta information
10354  	  * @param string $s string to escape.
10355  	  * @param int $n object ID
10356  	  * @return string escaped string.
10357  	  * @protected
10358  	  */
10359  	protected function _textstring($s, $n=0) {
10360  	 	 if ($this->isunicode) {
10361  	 	 	 //Convert string to UTF-16BE
10362  	 	 	 $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
10363  	 	 }
10364  	 	 return $this->_datastring($s, $n);
10365  	 }
10366  
10367  	 /**
10368  	  * get raw output stream.
10369  	  * @param string $s string to output.
10370  	  * @param int $n object reference for encryption mode
10371  	  * @protected
10372  	  * @author Nicola Asuni
10373  	  * @since 5.5.000 (2010-06-22)
10374  	  */
10375  	protected function _getrawstream($s, $n=0) {
10376  	 	 if ($n <= 0) {
10377  	 	 	 // default to current object
10378  	 	 	 $n = $this->n;
10379  	 	 }
10380  	 	 return $this->_encrypt_data($n, $s);
10381  	 }
10382  
10383  	 /**
10384  	  * Output a string to the document.
10385  	  * @param string $s string to output.
10386  	  * @protected
10387  	  */
10388  	protected function _out($s) {
10389  	 	 if ($this->state == 2) {
10390  	 	 	 if ($this->inxobj) {
10391  	 	 	 	 // we are inside an XObject template
10392  	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
10393  	 	 	 } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
10394  	 	 	 	 // puts data before page footer
10395  	 	 	 	 $pagebuff = $this->getPageBuffer($this->page);
10396  	 	 	 	 $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
10397  	 	 	 	 $footer = substr($pagebuff, -$this->footerlen[$this->page]);
10398  	 	 	 	 $this->setPageBuffer($this->page, $page.$s."\n".$footer);
10399  	 	 	 	 // update footer position
10400  	 	 	 	 $this->footerpos[$this->page] += strlen($s."\n");
10401  	 	 	 } else {
10402  	 	 	 	 // set page data
10403  	 	 	 	 $this->setPageBuffer($this->page, $s."\n", true);
10404  	 	 	 }
10405  	 	 } elseif ($this->state > 0) {
10406  	 	 	 // set general data
10407  	 	 	 $this->setBuffer($s."\n");
10408  	 	 }
10409  	 }
10410  
10411  	 /**
10412  	  * Set header font.
10413  	  * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
10414  	  * @phpstan-param array{0: string, 1: string, 2: float|null} $font
10415  	  * @public
10416  	  * @since 1.1
10417  	  */
10418  	public function setHeaderFont($font) {
10419  	 	 $this->header_font = $font;
10420  	 }
10421  
10422  	 /**
10423  	  * Get header font.
10424  	  * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
10425  	  * @phpstan-return array{0: string, 1: string, 2: float|null}
10426  	  * @public
10427  	  * @since 4.0.012 (2008-07-24)
10428  	  */
10429  	public function getHeaderFont() {
10430  	 	 return $this->header_font;
10431  	 }
10432  
10433  	 /**
10434  	  * Set footer font.
10435  	  * @param array<int,string|float|null> $font Array describing the basic font parameters: (family, style, size).
10436  	  * @phpstan-param array{0: string, 1: string, 2: float|null} $font
10437  	  * @public
10438  	  * @since 1.1
10439  	  */
10440  	public function setFooterFont($font) {
10441  	 	 $this->footer_font = $font;
10442  	 }
10443  
10444  	 /**
10445  	  * Get Footer font.
10446  	  * @return array<int,string|float|null> Array describing the basic font parameters: (family, style, size).
10447  	  * @phpstan-return array{0: string, 1: string, 2: float|null} $font
10448  	  * @public
10449  	  * @since 4.0.012 (2008-07-24)
10450  	  */
10451  	public function getFooterFont() {
10452  	 	 return $this->footer_font;
10453  	 }
10454  
10455  	 /**
10456  	  * Set language array.
10457  	  * @param array $language
10458  	  * @public
10459  	  * @since 1.1
10460  	  */
10461  	public function setLanguageArray($language) {
10462  	 	 $this->l = $language;
10463  	 	 if (isset($this->l['a_meta_dir'])) {
10464  	 	 	 $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
10465  	 	 } else {
10466  	 	 	 $this->rtl = false;
10467  	 	 }
10468  	 }
10469  
10470  	 /**
10471  	  * Returns the PDF data.
10472  	  * @public
10473  	  */
10474  	public function getPDFData() {
10475  	 	 if ($this->state < 3) {
10476  	 	 	 $this->Close();
10477  	 	 }
10478  	 	 return $this->buffer;
10479  	 }
10480  
10481  	 /**
10482  	  * Output anchor link.
10483  	  * @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;)
10484  	  * @param string $name link name
10485  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
10486  	  * @param boolean $firstline if true prints only the first line and return the remaining string.
10487  	  * @param array|null $color array of RGB text color
10488  	  * @param string $style font style (U, D, B, I)
10489  	  * @param boolean $firstblock if true the string is the starting of a line.
10490  	  * @return int the number of cells used or the remaining text if $firstline = true;
10491  	  * @public
10492  	  */
10493  	public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color=null, $style=-1, $firstblock=false) {
10494  	 	 if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
10495  	 	 	 // convert url to internal link
10496  	 	 	 $lnkdata = explode(',', $url);
10497  	 	 	 if (isset($lnkdata[0]) ) {
10498  	 	 	 	 $page = substr($lnkdata[0], 1);
10499  	 	 	 	 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
10500  	 	 	 	 	 $lnky = floatval($lnkdata[1]);
10501  	 	 	 	 } else {
10502  	 	 	 	 	 $lnky = 0;
10503  	 	 	 	 }
10504  	 	 	 	 $url = $this->AddLink();
10505  	 	 	 	 $this->setLink($url, $lnky, $page);
10506  	 	 	 }
10507  	 	 }
10508  	 	 // store current settings
10509  	 	 $prevcolor = $this->fgcolor;
10510  	 	 $prevstyle = $this->FontStyle;
10511  	 	 if (empty($color)) {
10512  	 	 	 $this->setTextColorArray($this->htmlLinkColorArray);
10513  	 	 } else {
10514  	 	 	 $this->setTextColorArray($color);
10515  	 	 }
10516  	 	 if ($style == -1) {
10517  	 	 	 $this->setFont('', $this->FontStyle.$this->htmlLinkFontStyle);
10518  	 	 } else {
10519  	 	 	 $this->setFont('', $this->FontStyle.$style);
10520  	 	 }
10521  	 	 $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
10522  	 	 // restore settings
10523  	 	 $this->setFont('', $prevstyle);
10524  	 	 $this->setTextColorArray($prevcolor);
10525  	 	 return $ret;
10526  	 }
10527  
10528  	 /**
10529  	  * Converts pixels to User's Units.
10530  	  * @param int $px pixels
10531  	  * @return float value in user's unit
10532  	  * @public
10533  	  * @see setImageScale(), getImageScale()
10534  	  */
10535  	public function pixelsToUnits($px) {
10536  	 	 return ($px / ($this->imgscale * $this->k));
10537  	 }
10538  
10539  	 /**
10540  	  * Reverse function for htmlentities.
10541  	  * Convert entities in UTF-8.
10542  	  * @param string $text_to_convert Text to convert.
10543  	  * @return string converted text string
10544  	  * @public
10545  	  */
10546  	public function unhtmlentities($text_to_convert) {
10547  	 	 return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
10548  	 }
10549  
10550  	 // ENCRYPTION METHODS ----------------------------------
10551  
10552  	 /**
10553  	  * Compute encryption key depending on object number where the encrypted data is stored.
10554  	  * This is used for all strings and streams without crypt filter specifier.
10555  	  * @param int $n object number
10556  	  * @return int object key
10557  	  * @protected
10558  	  * @author Nicola Asuni
10559  	  * @since 2.0.000 (2008-01-02)
10560  	  */
10561  	protected function _objectkey($n) {
10562  	 	 $objkey = $this->encryptdata['key'].pack('VXxx', $n);
10563  	 	 if ($this->encryptdata['mode'] == 2) { // AES-128
10564  	 	 	 // AES padding
10565  	 	 	 $objkey .= "\x73\x41\x6C\x54"; // sAlT
10566  	 	 }
10567  	 	 $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
10568  	 	 $objkey = substr($objkey, 0, 16);
10569  	 	 return $objkey;
10570  	 }
10571  
10572  	 /**
10573  	  * Encrypt the input string.
10574  	  * @param int $n object number
10575  	  * @param string $s data string to encrypt
10576  	  * @return string encrypted string
10577  	  * @protected
10578  	  * @author Nicola Asuni
10579  	  * @since 5.0.005 (2010-05-11)
10580  	  */
10581  	protected function _encrypt_data($n, $s) {
10582  	 	 if (!$this->encrypted) {
10583  	 	 	 return $s;
10584  	 	 }
10585  	 	 switch ($this->encryptdata['mode']) {
10586  	 	 	 case 0:   // RC4-40
10587  	 	 	 case 1: { // RC4-128
10588  	 	 	 	 $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
10589  	 	 	 	 break;
10590  	 	 	 }
10591  	 	 	 case 2: { // AES-128
10592  	 	 	 	 $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
10593  	 	 	 	 break;
10594  	 	 	 }
10595  	 	 	 case 3: { // AES-256
10596  	 	 	 	 $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
10597  	 	 	 	 break;
10598  	 	 	 }
10599  	 	 }
10600  	 	 return $s;
10601  	 }
10602  
10603  	 /**
10604  	  * Put encryption on PDF document.
10605  	  * @protected
10606  	  * @author Nicola Asuni
10607  	  * @since 2.0.000 (2008-01-02)
10608  	  */
10609  	protected function _putencryption() {
10610  	 	 if (!$this->encrypted) {
10611  	 	 	 return;
10612  	 	 }
10613  	 	 $this->encryptdata['objid'] = $this->_newobj();
10614  	 	 $out = '<<';
10615  	 	 if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
10616  	 	 	 $this->encryptdata['Filter'] = 'Standard';
10617  	 	 }
10618  	 	 $out .= ' /Filter /'.$this->encryptdata['Filter'];
10619  	 	 if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
10620  	 	 	 $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
10621  	 	 }
10622  	 	 if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
10623  	 	 	 $this->encryptdata['V'] = 1;
10624  	 	 }
10625  	 	 // V is a code specifying the algorithm to be used in encrypting and decrypting the document
10626  	 	 $out .= ' /V '.$this->encryptdata['V'];
10627  	 	 if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
10628  	 	 	 // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
10629  	 	 	 $out .= ' /Length '.$this->encryptdata['Length'];
10630  	 	 } else {
10631  	 	 	 $out .= ' /Length 40';
10632  	 	 }
10633  	 	 if ($this->encryptdata['V'] >= 4) {
10634  	 	 	 if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
10635  	 	 	 	 $this->encryptdata['StmF'] = 'Identity';
10636  	 	 	 }
10637  	 	 	 if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
10638  	 	 	 	 // The name of the crypt filter that shall be used when decrypting all strings in the document.
10639  	 	 	 	 $this->encryptdata['StrF'] = 'Identity';
10640  	 	 	 }
10641  	 	 	 // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
10642  	 	 	 if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
10643  	 	 	 	 $out .= ' /CF <<';
10644  	 	 	 	 $out .= ' /'.$this->encryptdata['StmF'].' <<';
10645  	 	 	 	 $out .= ' /Type /CryptFilter';
10646  	 	 	 	 if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
10647  	 	 	 	 	 // The method used
10648  	 	 	 	 	 $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
10649  	 	 	 	 	 if ($this->encryptdata['pubkey']) {
10650  	 	 	 	 	 	 $out .= ' /Recipients [';
10651  	 	 	 	 	 	 foreach ($this->encryptdata['Recipients'] as $rec) {
10652  	 	 	 	 	 	 	 $out .= ' <'.$rec.'>';
10653  	 	 	 	 	 	 }
10654  	 	 	 	 	 	 $out .= ' ]';
10655  	 	 	 	 	 	 if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
10656  	 	 	 	 	 	 	 $out .= ' /EncryptMetadata false';
10657  	 	 	 	 	 	 } else {
10658  	 	 	 	 	 	 	 $out .= ' /EncryptMetadata true';
10659  	 	 	 	 	 	 }
10660  	 	 	 	 	 }
10661  	 	 	 	 } else {
10662  	 	 	 	 	 $out .= ' /CFM /None';
10663  	 	 	 	 }
10664  	 	 	 	 if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
10665  	 	 	 	 	 // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
10666  	 	 	 	 	 $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
10667  	 	 	 	 } else {
10668  	 	 	 	 	 $out .= ' /AuthEvent /DocOpen';
10669  	 	 	 	 }
10670  	 	 	 	 if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
10671  	 	 	 	 	 // The bit length of the encryption key.
10672  	 	 	 	 	 $out .= ' /Length '.$this->encryptdata['CF']['Length'];
10673  	 	 	 	 }
10674  	 	 	 	 $out .= ' >> >>';
10675  	 	 	 }
10676  	 	 	 // The name of the crypt filter that shall be used by default when decrypting streams.
10677  	 	 	 $out .= ' /StmF /'.$this->encryptdata['StmF'];
10678  	 	 	 // The name of the crypt filter that shall be used when decrypting all strings in the document.
10679  	 	 	 $out .= ' /StrF /'.$this->encryptdata['StrF'];
10680  	 	 	 if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
10681  	 	 	 	 // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
10682  	 	 	 	 $out .= ' /EFF /'.$this->encryptdata[''];
10683  	 	 	 }
10684  	 	 }
10685  	 	 // Additional encryption dictionary entries for the standard security handler
10686  	 	 if ($this->encryptdata['pubkey']) {
10687  	 	 	 if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
10688  	 	 	 	 $out .= ' /Recipients [';
10689  	 	 	 	 foreach ($this->encryptdata['Recipients'] as $rec) {
10690  	 	 	 	 	 $out .= ' <'.$rec.'>';
10691  	 	 	 	 }
10692  	 	 	 	 $out .= ' ]';
10693  	 	 	 }
10694  	 	 } else {
10695  	 	 	 $out .= ' /R';
10696  	 	 	 if ($this->encryptdata['V'] == 5) { // AES-256
10697  	 	 	 	 $out .= ' 5';
10698  	 	 	 	 $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
10699  	 	 	 	 $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
10700  	 	 	 	 $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
10701  	 	 	 } elseif ($this->encryptdata['V'] == 4) { // AES-128
10702  	 	 	 	 $out .= ' 4';
10703  	 	 	 } elseif ($this->encryptdata['V'] < 2) { // RC-40
10704  	 	 	 	 $out .= ' 2';
10705  	 	 	 } else { // RC-128
10706  	 	 	 	 $out .= ' 3';
10707  	 	 	 }
10708  	 	 	 $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
10709  	 	 	 $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
10710  	 	 	 $out .= ' /P '.$this->encryptdata['P'];
10711  	 	 	 if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
10712  	 	 	 	 $out .= ' /EncryptMetadata false';
10713  	 	 	 } else {
10714  	 	 	 	 $out .= ' /EncryptMetadata true';
10715  	 	 	 }
10716  	 	 }
10717  	 	 $out .= ' >>';
10718  	 	 $out .= "\n".'endobj';
10719  	 	 $this->_out($out);
10720  	 }
10721  
10722  	 /**
10723  	  * Compute U value (used for encryption)
10724  	  * @return string U value
10725  	  * @protected
10726  	  * @since 2.0.000 (2008-01-02)
10727  	  * @author Nicola Asuni
10728  	  */
10729  	protected function _Uvalue() {
10730  	 	 if ($this->encryptdata['mode'] == 0) { // RC4-40
10731  	 	 	 return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
10732  	 	 } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
10733  	 	 	 $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
10734  	 	 	 $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
10735  	 	 	 $len = strlen($tmp);
10736  	 	 	 for ($i = 1; $i <= 19; ++$i) {
10737  	 	 	 	 $ek = '';
10738  	 	 	 	 for ($j = 0; $j < $len; ++$j) {
10739  	 	 	 	 	 $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
10740  	 	 	 	 }
10741  	 	 	 	 $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
10742  	 	 	 }
10743  	 	 	 $enc .= str_repeat("\x00", 16);
10744  	 	 	 return substr($enc, 0, 32);
10745  	 	 } elseif ($this->encryptdata['mode'] == 3) { // AES-256
10746  	 	 	 $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
10747  	 	 	 // User Validation Salt
10748  	 	 	 $this->encryptdata['UVS'] = substr($seed, 0, 8);
10749  	 	 	 // User Key Salt
10750  	 	 	 $this->encryptdata['UKS'] = substr($seed, 8, 16);
10751  	 	 	 return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
10752  	 	 }
10753  	 }
10754  
10755  	 /**
10756  	  * Compute UE value (used for encryption)
10757  	  * @return string UE value
10758  	  * @protected
10759  	  * @since 5.9.006 (2010-10-19)
10760  	  * @author Nicola Asuni
10761  	  */
10762  	protected function _UEvalue() {
10763  	 	 $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
10764  	 	 return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
10765  	 }
10766  
10767  	 /**
10768  	  * Compute O value (used for encryption)
10769  	  * @return string O value
10770  	  * @protected
10771  	  * @since 2.0.000 (2008-01-02)
10772  	  * @author Nicola Asuni
10773  	  */
10774  	protected function _Ovalue() {
10775  	 	 if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
10776  	 	 	 $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
10777  	 	 	 if ($this->encryptdata['mode'] > 0) {
10778  	 	 	 	 for ($i = 0; $i < 50; ++$i) {
10779  	 	 	 	 	 $tmp = TCPDF_STATIC::_md5_16($tmp);
10780  	 	 	 	 }
10781  	 	 	 }
10782  	 	 	 $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
10783  	 	 	 $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
10784  	 	 	 if ($this->encryptdata['mode'] > 0) {
10785  	 	 	 	 $len = strlen($owner_key);
10786  	 	 	 	 for ($i = 1; $i <= 19; ++$i) {
10787  	 	 	 	 	 $ek = '';
10788  	 	 	 	 	 for ($j = 0; $j < $len; ++$j) {
10789  	 	 	 	 	 	 $ek .= chr(ord($owner_key[$j]) ^ $i);
10790  	 	 	 	 	 }
10791  	 	 	 	 	 $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
10792  	 	 	 	 }
10793  	 	 	 }
10794  	 	 	 return $enc;
10795  	 	 } elseif ($this->encryptdata['mode'] == 3) { // AES-256
10796  	 	 	 $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
10797  	 	 	 // Owner Validation Salt
10798  	 	 	 $this->encryptdata['OVS'] = substr($seed, 0, 8);
10799  	 	 	 // Owner Key Salt
10800  	 	 	 $this->encryptdata['OKS'] = substr($seed, 8, 16);
10801  	 	 	 return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
10802  	 	 }
10803  	 }
10804  
10805  	 /**
10806  	  * Compute OE value (used for encryption)
10807  	  * @return string OE value
10808  	  * @protected
10809  	  * @since 5.9.006 (2010-10-19)
10810  	  * @author Nicola Asuni
10811  	  */
10812  	protected function _OEvalue() {
10813  	 	 $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
10814  	 	 return TCPDF_STATIC::_AESnopad($hashkey, $this->encryptdata['key']);
10815  	 }
10816  
10817  	 /**
10818  	  * Convert password for AES-256 encryption mode
10819  	  * @param string $password password
10820  	  * @return string password
10821  	  * @protected
10822  	  * @since 5.9.006 (2010-10-19)
10823  	  * @author Nicola Asuni
10824  	  */
10825  	protected function _fixAES256Password($password) {
10826  	 	 $psw = ''; // password to be returned
10827  	 	 $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
10828  	 	 foreach ($psw_array as $c) {
10829  	 	 	 $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
10830  	 	 }
10831  	 	 return substr($psw, 0, 127);
10832  	 }
10833  
10834  	 /**
10835  	  * Compute encryption key
10836  	  * @protected
10837  	  * @since 2.0.000 (2008-01-02)
10838  	  * @author Nicola Asuni
10839  	  */
10840  	protected function _generateencryptionkey() {
10841  	 	 $keybytelen = ($this->encryptdata['Length'] / 8);
10842  	 	 if (!$this->encryptdata['pubkey']) { // standard mode
10843  	 	 	 if ($this->encryptdata['mode'] == 3) { // AES-256
10844  	 	 	 	 // generate 256 bit random key
10845  	 	 	 	 $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
10846  	 	 	 	 // truncate passwords
10847  	 	 	 	 $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
10848  	 	 	 	 $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
10849  	 	 	 	 // Compute U value
10850  	 	 	 	 $this->encryptdata['U'] = $this->_Uvalue();
10851  	 	 	 	 // Compute UE value
10852  	 	 	 	 $this->encryptdata['UE'] = $this->_UEvalue();
10853  	 	 	 	 // Compute O value
10854  	 	 	 	 $this->encryptdata['O'] = $this->_Ovalue();
10855  	 	 	 	 // Compute OE value
10856  	 	 	 	 $this->encryptdata['OE'] = $this->_OEvalue();
10857  	 	 	 	 // Compute P value
10858  	 	 	 	 $this->encryptdata['P'] = $this->encryptdata['protection'];
10859  	 	 	 	 // Computing the encryption dictionary's Perms (permissions) value
10860  	 	 	 	 $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
10861  	 	 	 	 $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
10862  	 	 	 	 if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
10863  	 	 	 	 	 $perms .= 'F';
10864  	 	 	 	 } else {
10865  	 	 	 	 	 $perms .= 'T';
10866  	 	 	 	 }
10867  	 	 	 	 $perms .= 'adb'; // bytes 9-11
10868  	 	 	 	 $perms .= 'nick'; // bytes 12-15
10869  	 	 	 	 $this->encryptdata['perms'] = TCPDF_STATIC::_AESnopad($this->encryptdata['key'], $perms);
10870  	 	 	 } else { // RC4-40, RC4-128, AES-128
10871  	 	 	 	 // Pad passwords
10872  	 	 	 	 $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
10873  	 	 	 	 $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
10874  	 	 	 	 // Compute O value
10875  	 	 	 	 $this->encryptdata['O'] = $this->_Ovalue();
10876  	 	 	 	 // get default permissions (reverse byte order)
10877  	 	 	 	 $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
10878  	 	 	 	 // Compute encryption key
10879  	 	 	 	 $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
10880  	 	 	 	 if ($this->encryptdata['mode'] > 0) {
10881  	 	 	 	 	 for ($i = 0; $i < 50; ++$i) {
10882  	 	 	 	 	 	 $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
10883  	 	 	 	 	 }
10884  	 	 	 	 }
10885  	 	 	 	 $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
10886  	 	 	 	 // Compute U value
10887  	 	 	 	 $this->encryptdata['U'] = $this->_Uvalue();
10888  	 	 	 	 // Compute P value
10889  	 	 	 	 $this->encryptdata['P'] = $this->encryptdata['protection'];
10890  	 	 	 }
10891  	 	 } else { // Public-Key mode
10892  	 	 	 // random 20-byte seed
10893  	 	 	 $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
10894  	 	 	 $recipient_bytes = '';
10895  	 	 	 foreach ($this->encryptdata['pubkeys'] as $pubkey) {
10896  	 	 	 	 // for each public certificate
10897  	 	 	 	 if (isset($pubkey['p'])) {
10898  	 	 	 	 	 $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
10899  	 	 	 	 } else {
10900  	 	 	 	 	 $pkprotection = $this->encryptdata['protection'];
10901  	 	 	 	 }
10902  	 	 	 	 // get default permissions (reverse byte order)
10903  	 	 	 	 $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
10904  	 	 	 	 // envelope data
10905  	 	 	 	 $envelope = $seed.$pkpermissions;
10906  	 	 	 	 // write the envelope data to a temporary file
10907  	 	 	 	 $tempkeyfile = TCPDF_STATIC::getObjFilename('key', $this->file_id);
10908  	 	 	 	 $f = TCPDF_STATIC::fopenLocal($tempkeyfile, 'wb');
10909  	 	 	 	 if (!$f) {
10910  	 	 	 	 	 $this->Error('Unable to create temporary key file: '.$tempkeyfile);
10911  	 	 	 	 }
10912  	 	 	 	 $envelope_length = strlen($envelope);
10913  	 	 	 	 fwrite($f, $envelope, $envelope_length);
10914  	 	 	 	 fclose($f);
10915  	 	 	 	 $tempencfile = TCPDF_STATIC::getObjFilename('enc', $this->file_id);
10916  	 	 	 	 if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
10917  	 	 	 	 	 $this->Error('Unable to encrypt the file: '.$tempkeyfile);
10918  	 	 	 	 }
10919  	 	 	 	 // read encryption signature
10920  	 	 	 	 $signature = file_get_contents($tempencfile, false, null, $envelope_length);
10921  	 	 	 	 // extract signature
10922  	 	 	 	 $signature = substr($signature, strpos($signature, 'Content-Disposition'));
10923  	 	 	 	 $tmparr = explode("\n\n", $signature);
10924  	 	 	 	 $signature = trim($tmparr[1]);
10925  	 	 	 	 unset($tmparr);
10926  	 	 	 	 // decode signature
10927  	 	 	 	 $signature = base64_decode($signature);
10928  	 	 	 	 // convert signature to hex
10929  	 	 	 	 $hexsignature = current(unpack('H*', $signature));
10930  	 	 	 	 // store signature on recipients array
10931  	 	 	 	 $this->encryptdata['Recipients'][] = $hexsignature;
10932  	 	 	 	 // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
10933  	 	 	 	 $recipient_bytes .= $signature;
10934  	 	 	 }
10935  	 	 	 // calculate encryption key
10936  	 	 	 if ($this->encryptdata['mode'] == 3) { // AES-256
10937  	 	 	 	 $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
10938  	 	 	 } else { // RC4-40, RC4-128, AES-128
10939  	 	 	 	 $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
10940  	 	 	 }
10941  	 	 }
10942  	 }
10943  
10944  	 /**
10945  	  * Set document protection
10946  	  * Remark: the protection against modification is for people who have the full Acrobat product.
10947  	  * 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.
10948  	  * 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.
10949  	  * @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>
10950  	  * @param string $user_pass user password. Empty by default.
10951  	  * @param string|null $owner_pass owner password. If not specified, a random value is used.
10952  	  * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
10953  	  * @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')))
10954  	  * @public
10955  	  * @since 2.0.000 (2008-01-02)
10956  	  * @author Nicola Asuni
10957  	  */
10958  	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) {
10959  	 	 if ($this->pdfa_mode) {
10960  	 	 	 // encryption is not allowed in PDF/A mode
10961  	 	 	 return;
10962  	 	 }
10963  	 	 $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
10964  	 	 if (($pubkeys !== null) AND (is_array($pubkeys))) {
10965  	 	 	 // public-key mode
10966  	 	 	 $this->encryptdata['pubkeys'] = $pubkeys;
10967  	 	 	 if ($mode == 0) {
10968  	 	 	 	 // public-Key Security requires at least 128 bit
10969  	 	 	 	 $mode = 1;
10970  	 	 	 }
10971  	 	 	 if (!function_exists('openssl_pkcs7_encrypt')) {
10972  	 	 	 	 $this->Error('Public-Key Security requires openssl library.');
10973  	 	 	 }
10974  	 	 	 // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
10975  	 	 	 $this->encryptdata['pubkey'] = true;
10976  	 	 	 $this->encryptdata['Filter'] = 'Adobe.PubSec';
10977  	 	 	 $this->encryptdata['StmF'] = 'DefaultCryptFilter';
10978  	 	 	 $this->encryptdata['StrF'] = 'DefaultCryptFilter';
10979  	 	 } else {
10980  	 	 	 // standard mode (password mode)
10981  	 	 	 $this->encryptdata['pubkey'] = false;
10982  	 	 	 $this->encryptdata['Filter'] = 'Standard';
10983  	 	 	 $this->encryptdata['StmF'] = 'StdCF';
10984  	 	 	 $this->encryptdata['StrF'] = 'StdCF';
10985  	 	 }
10986  	 	 if ($mode > 1) { // AES
10987  	 	 	 if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
10988  	 	 	 	 $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
10989  	 	 	 }
10990  	 	 	 if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
10991  	 	 	 	 $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
10992  	 	 	 }
10993  	 	 	 if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
10994  	 	 	 	 $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
10995  	 	 	 }
10996  	 	 	 if (($mode == 3) AND !function_exists('hash')) {
10997  	 	 	 	 // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
10998  	 	 	 	 $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
10999  	 	 	 }
11000  	 	 }
11001  	 	 if ($owner_pass === null) {
11002  	 	 	 $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
11003  	 	 }
11004  	 	 $this->encryptdata['user_password'] = $user_pass;
11005  	 	 $this->encryptdata['owner_password'] = $owner_pass;
11006  	 	 $this->encryptdata['mode'] = $mode;
11007  	 	 switch ($mode) {
11008  	 	 	 case 0: { // RC4 40 bit
11009  	 	 	 	 $this->encryptdata['V'] = 1;
11010  	 	 	 	 $this->encryptdata['Length'] = 40;
11011  	 	 	 	 $this->encryptdata['CF']['CFM'] = 'V2';
11012  	 	 	 	 break;
11013  	 	 	 }
11014  	 	 	 case 1: { // RC4 128 bit
11015  	 	 	 	 $this->encryptdata['V'] = 2;
11016  	 	 	 	 $this->encryptdata['Length'] = 128;
11017  	 	 	 	 $this->encryptdata['CF']['CFM'] = 'V2';
11018  	 	 	 	 if ($this->encryptdata['pubkey']) {
11019  	 	 	 	 	 $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
11020  	 	 	 	 	 $this->encryptdata['Recipients'] = array();
11021  	 	 	 	 }
11022  	 	 	 	 break;
11023  	 	 	 }
11024  	 	 	 case 2: { // AES 128 bit
11025  	 	 	 	 $this->encryptdata['V'] = 4;
11026  	 	 	 	 $this->encryptdata['Length'] = 128;
11027  	 	 	 	 $this->encryptdata['CF']['CFM'] = 'AESV2';
11028  	 	 	 	 $this->encryptdata['CF']['Length'] = 128;
11029  	 	 	 	 if ($this->encryptdata['pubkey']) {
11030  	 	 	 	 	 $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
11031  	 	 	 	 	 $this->encryptdata['Recipients'] = array();
11032  	 	 	 	 }
11033  	 	 	 	 break;
11034  	 	 	 }
11035  	 	 	 case 3: { // AES 256 bit
11036  	 	 	 	 $this->encryptdata['V'] = 5;
11037  	 	 	 	 $this->encryptdata['Length'] = 256;
11038  	 	 	 	 $this->encryptdata['CF']['CFM'] = 'AESV3';
11039  	 	 	 	 $this->encryptdata['CF']['Length'] = 256;
11040  	 	 	 	 if ($this->encryptdata['pubkey']) {
11041  	 	 	 	 	 $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
11042  	 	 	 	 	 $this->encryptdata['Recipients'] = array();
11043  	 	 	 	 }
11044  	 	 	 	 break;
11045  	 	 	 }
11046  	 	 }
11047  	 	 $this->encrypted = true;
11048  	 	 $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
11049  	 	 $this->_generateencryptionkey();
11050  	 }
11051  
11052  	 // END OF ENCRYPTION FUNCTIONS -------------------------
11053  
11054  	 // START TRANSFORMATIONS SECTION -----------------------
11055  
11056  	 /**
11057  	  * Starts a 2D tranformation saving current graphic state.
11058  	  * This function must be called before scaling, mirroring, translation, rotation and skewing.
11059  	  * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
11060  	  * @public
11061  	  * @since 2.1.000 (2008-01-07)
11062  	  * @see StartTransform(), StopTransform()
11063  	  */
11064  	public function StartTransform() {
11065  	 	 if ($this->state != 2) {
11066  	 	 	 return;
11067  	 	 }
11068  	 	 $this->_outSaveGraphicsState();
11069  	 	 if ($this->inxobj) {
11070  	 	 	 // we are inside an XObject template
11071  	 	 	 $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
11072  	 	 } else {
11073  	 	 	 $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
11074  	 	 }
11075  	 	 ++$this->transfmatrix_key;
11076  	 	 $this->transfmatrix[$this->transfmatrix_key] = array();
11077  	 }
11078  
11079  	 /**
11080  	  * Stops a 2D tranformation restoring previous graphic state.
11081  	  * This function must be called after scaling, mirroring, translation, rotation and skewing.
11082  	  * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
11083  	  * @public
11084  	  * @since 2.1.000 (2008-01-07)
11085  	  * @see StartTransform(), StopTransform()
11086  	  */
11087  	public function StopTransform() {
11088  	 	 if ($this->state != 2) {
11089  	 	 	 return;
11090  	 	 }
11091  	 	 $this->_outRestoreGraphicsState();
11092  	 	 if (isset($this->transfmatrix[$this->transfmatrix_key])) {
11093  	 	 	 array_pop($this->transfmatrix[$this->transfmatrix_key]);
11094  	 	 	 --$this->transfmatrix_key;
11095  	 	 }
11096  	 	 if ($this->inxobj) {
11097  	 	 	 // we are inside an XObject template
11098  	 	 	 array_pop($this->xobjects[$this->xobjid]['transfmrk']);
11099  	 	 } else {
11100  	 	 	 array_pop($this->transfmrk[$this->page]);
11101  	 	 }
11102  	 }
11103  	 /**
11104  	  * Horizontal Scaling.
11105  	  * @param float $s_x scaling factor for width as percent. 0 is not allowed.
11106  	  * @param int $x abscissa of the scaling center. Default is current x position
11107  	  * @param int $y ordinate of the scaling center. Default is current y position
11108  	  * @public
11109  	  * @since 2.1.000 (2008-01-07)
11110  	  * @see StartTransform(), StopTransform()
11111  	  */
11112  	public function ScaleX($s_x, $x='', $y='') {
11113  	 	 $this->Scale($s_x, 100, $x, $y);
11114  	 }
11115  
11116  	 /**
11117  	  * Vertical Scaling.
11118  	  * @param float $s_y scaling factor for height as percent. 0 is not allowed.
11119  	  * @param int $x abscissa of the scaling center. Default is current x position
11120  	  * @param int $y ordinate of the scaling center. Default is current y position
11121  	  * @public
11122  	  * @since 2.1.000 (2008-01-07)
11123  	  * @see StartTransform(), StopTransform()
11124  	  */
11125  	public function ScaleY($s_y, $x='', $y='') {
11126  	 	 $this->Scale(100, $s_y, $x, $y);
11127  	 }
11128  
11129  	 /**
11130  	  * Vertical and horizontal proportional Scaling.
11131  	  * @param float $s scaling factor for width and height as percent. 0 is not allowed.
11132  	  * @param int $x abscissa of the scaling center. Default is current x position
11133  	  * @param int $y ordinate of the scaling center. Default is current y position
11134  	  * @public
11135  	  * @since 2.1.000 (2008-01-07)
11136  	  * @see StartTransform(), StopTransform()
11137  	  */
11138  	public function ScaleXY($s, $x='', $y='') {
11139  	 	 $this->Scale($s, $s, $x, $y);
11140  	 }
11141  
11142  	 /**
11143  	  * Vertical and horizontal non-proportional Scaling.
11144  	  * @param float $s_x scaling factor for width as percent. 0 is not allowed.
11145  	  * @param float $s_y scaling factor for height as percent. 0 is not allowed.
11146  	  * @param float|null $x abscissa of the scaling center. Default is current x position
11147  	  * @param float|null $y ordinate of the scaling center. Default is current y position
11148  	  * @public
11149  	  * @since 2.1.000 (2008-01-07)
11150  	  * @see StartTransform(), StopTransform()
11151  	  */
11152  	public function Scale($s_x, $s_y, $x=null, $y=null) {
11153  	 	 if (TCPDF_STATIC::empty_string($x)) {
11154  	 	 	 $x = $this->x;
11155  	 	 }
11156  	 	 if (TCPDF_STATIC::empty_string($y)) {
11157  	 	 	 $y = $this->y;
11158  	 	 }
11159  	 	 if (($s_x == 0) OR ($s_y == 0)) {
11160  	 	 	 $this->Error('Please do not use values equal to zero for scaling');
11161  	 	 }
11162  	 	 $y = ($this->h - $y) * $this->k;
11163  	 	 $x *= $this->k;
11164  	 	 //calculate elements of transformation matrix
11165  	 	 $s_x /= 100;
11166  	 	 $s_y /= 100;
11167  	 	 $tm = array();
11168  	 	 $tm[0] = $s_x;
11169  	 	 $tm[1] = 0;
11170  	 	 $tm[2] = 0;
11171  	 	 $tm[3] = $s_y;
11172  	 	 $tm[4] = $x * (1 - $s_x);
11173  	 	 $tm[5] = $y * (1 - $s_y);
11174  	 	 //scale the coordinate system
11175  	 	 $this->Transform($tm);
11176  	 }
11177  
11178  	 /**
11179  	  * Horizontal Mirroring.
11180  	  * @param float|null $x abscissa of the point. Default is current x position
11181  	  * @public
11182  	  * @since 2.1.000 (2008-01-07)
11183  	  * @see StartTransform(), StopTransform()
11184  	  */
11185  	public function MirrorH($x=null) {
11186  	 	 $this->Scale(-100, 100, $x);
11187  	 }
11188  
11189  	 /**
11190  	  * Verical Mirroring.
11191  	  * @param float|null $y ordinate of the point. Default is current y position
11192  	  * @public
11193  	  * @since 2.1.000 (2008-01-07)
11194  	  * @see StartTransform(), StopTransform()
11195  	  */
11196  	public function MirrorV($y=null) {
11197  	 	 $this->Scale(100, -100, null, $y);
11198  	 }
11199  
11200  	 /**
11201  	  * Point reflection mirroring.
11202  	  * @param float|null $x abscissa of the point. Default is current x position
11203  	  * @param float|null $y ordinate of the point. Default is current y position
11204  	  * @public
11205  	  * @since 2.1.000 (2008-01-07)
11206  	  * @see StartTransform(), StopTransform()
11207  	  */
11208  	public function MirrorP($x=null,$y=null) {
11209  	 	 $this->Scale(-100, -100, $x, $y);
11210  	 }
11211  
11212  	 /**
11213  	  * Reflection against a straight line through point (x, y) with the gradient angle (angle).
11214  	  * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
11215  	  * @param float|null $x abscissa of the point. Default is current x position
11216  	  * @param float|null $y ordinate of the point. Default is current y position
11217  	  * @public
11218  	  * @since 2.1.000 (2008-01-07)
11219  	  * @see StartTransform(), StopTransform()
11220  	  */
11221  	public function MirrorL($angle=0, $x=null,$y=null) {
11222  	 	 $this->Scale(-100, 100, $x, $y);
11223  	 	 $this->Rotate(-2*($angle-90), $x, $y);
11224  	 }
11225  
11226  	 /**
11227  	  * Translate graphic object horizontally.
11228  	  * @param int $t_x movement to the right (or left for RTL)
11229  	  * @public
11230  	  * @since 2.1.000 (2008-01-07)
11231  	  * @see StartTransform(), StopTransform()
11232  	  */
11233  	public function TranslateX($t_x) {
11234  	 	 $this->Translate($t_x, 0);
11235  	 }
11236  
11237  	 /**
11238  	  * Translate graphic object vertically.
11239  	  * @param int $t_y movement to the bottom
11240  	  * @public
11241  	  * @since 2.1.000 (2008-01-07)
11242  	  * @see StartTransform(), StopTransform()
11243  	  */
11244  	public function TranslateY($t_y) {
11245  	 	 $this->Translate(0, $t_y);
11246  	 }
11247  
11248  	 /**
11249  	  * Translate graphic object horizontally and vertically.
11250  	  * @param int $t_x movement to the right
11251  	  * @param int $t_y movement to the bottom
11252  	  * @public
11253  	  * @since 2.1.000 (2008-01-07)
11254  	  * @see StartTransform(), StopTransform()
11255  	  */
11256  	public function Translate($t_x, $t_y) {
11257  	 	 //calculate elements of transformation matrix
11258  	 	 $tm = array();
11259  	 	 $tm[0] = 1;
11260  	 	 $tm[1] = 0;
11261  	 	 $tm[2] = 0;
11262  	 	 $tm[3] = 1;
11263  	 	 $tm[4] = $t_x * $this->k;
11264  	 	 $tm[5] = -$t_y * $this->k;
11265  	 	 //translate the coordinate system
11266  	 	 $this->Transform($tm);
11267  	 }
11268  
11269  	 /**
11270  	  * Rotate object.
11271  	  * @param float $angle angle in degrees for counter-clockwise rotation
11272  	  * @param float|null $x abscissa of the rotation center. Default is current x position
11273  	  * @param float|null $y ordinate of the rotation center. Default is current y position
11274  	  * @public
11275  	  * @since 2.1.000 (2008-01-07)
11276  	  * @see StartTransform(), StopTransform()
11277  	  */
11278  	public function Rotate($angle, $x=null, $y=null) {
11279  	 	 if (TCPDF_STATIC::empty_string($x)) {
11280  	 	 	 $x = $this->x;
11281  	 	 }
11282  	 	 if (TCPDF_STATIC::empty_string($y)) {
11283  	 	 	 $y = $this->y;
11284  	 	 }
11285  	 	 $y = ($this->h - $y) * $this->k;
11286  	 	 $x *= $this->k;
11287  	 	 //calculate elements of transformation matrix
11288  	 	 $tm = array();
11289  	 	 $tm[0] = cos(deg2rad($angle));
11290  	 	 $tm[1] = sin(deg2rad($angle));
11291  	 	 $tm[2] = -$tm[1];
11292  	 	 $tm[3] = $tm[0];
11293  	 	 $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
11294  	 	 $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
11295  	 	 //rotate the coordinate system around ($x,$y)
11296  	 	 $this->Transform($tm);
11297  	 }
11298  
11299  	 /**
11300  	  * Skew horizontally.
11301  	  * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
11302  	  * @param float|null $x abscissa of the skewing center. default is current x position
11303  	  * @param float|null $y ordinate of the skewing center. default is current y position
11304  	  * @public
11305  	  * @since 2.1.000 (2008-01-07)
11306  	  * @see StartTransform(), StopTransform()
11307  	  */
11308  	public function SkewX($angle_x, $x=null, $y=null) {
11309  	 	 $this->Skew($angle_x, 0, $x, $y);
11310  	 }
11311  
11312  	 /**
11313  	  * Skew vertically.
11314  	  * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
11315  	  * @param float|null $x abscissa of the skewing center. default is current x position
11316  	  * @param float|null $y ordinate of the skewing center. default is current y position
11317  	  * @public
11318  	  * @since 2.1.000 (2008-01-07)
11319  	  * @see StartTransform(), StopTransform()
11320  	  */
11321  	public function SkewY($angle_y, $x=null, $y=null) {
11322  	 	 $this->Skew(0, $angle_y, $x, $y);
11323  	 }
11324  
11325  	 /**
11326  	  * Skew.
11327  	  * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
11328  	  * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
11329  	  * @param float|null $x abscissa of the skewing center. default is current x position
11330  	  * @param float|null $y ordinate of the skewing center. default is current y position
11331  	  * @public
11332  	  * @since 2.1.000 (2008-01-07)
11333  	  * @see StartTransform(), StopTransform()
11334  	  */
11335  	public function Skew($angle_x, $angle_y, $x=null, $y=null) {
11336  	 	 if (TCPDF_STATIC::empty_string($x)) {
11337  	 	 	 $x = $this->x;
11338  	 	 }
11339  	 	 if (TCPDF_STATIC::empty_string($y)) {
11340  	 	 	 $y = $this->y;
11341  	 	 }
11342  	 	 if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
11343  	 	 	 $this->Error('Please use values between -90 and +90 degrees for Skewing.');
11344  	 	 }
11345  	 	 $x *= $this->k;
11346  	 	 $y = ($this->h - $y) * $this->k;
11347  	 	 //calculate elements of transformation matrix
11348  	 	 $tm = array();
11349  	 	 $tm[0] = 1;
11350  	 	 $tm[1] = tan(deg2rad($angle_y));
11351  	 	 $tm[2] = tan(deg2rad($angle_x));
11352  	 	 $tm[3] = 1;
11353  	 	 $tm[4] = -$tm[2] * $y;
11354  	 	 $tm[5] = -$tm[1] * $x;
11355  	 	 //skew the coordinate system
11356  	 	 $this->Transform($tm);
11357  	 }
11358  
11359  	 /**
11360  	  * Apply graphic transformations.
11361  	  * @param array $tm transformation matrix
11362  	  * @protected
11363  	  * @since 2.1.000 (2008-01-07)
11364  	  * @see StartTransform(), StopTransform()
11365  	  */
11366  	protected function Transform($tm) {
11367  	 	 if ($this->state != 2) {
11368  	 	 	 return;
11369  	 	 }
11370  	 	 $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
11371  	 	 // add tranformation matrix
11372  	 	 $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
11373  	 	 // update transformation mark
11374  	 	 if ($this->inxobj) {
11375  	 	 	 // we are inside an XObject template
11376  	 	 	 if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
11377  	 	 	 	 $key = key($this->xobjects[$this->xobjid]['transfmrk']);
11378  	 	 	 	 $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
11379  	 	 	 }
11380  	 	 } elseif (end($this->transfmrk[$this->page]) !== false) {
11381  	 	 	 $key = key($this->transfmrk[$this->page]);
11382  	 	 	 $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
11383  	 	 }
11384  	 }
11385  
11386  	 // END TRANSFORMATIONS SECTION -------------------------
11387  
11388  	 // START GRAPHIC FUNCTIONS SECTION ---------------------
11389  	 // The following section is based on the code provided by David Hernandez Sanz
11390  
11391  	 /**
11392  	  * 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.
11393  	  * @param float $width The width.
11394  	  * @public
11395  	  * @since 1.0
11396  	  * @see Line(), Rect(), Cell(), MultiCell()
11397  	  */
11398  	public function setLineWidth($width) {
11399  	 	 //Set line width
11400  	 	 $this->LineWidth = $width;
11401  	 	 $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
11402  	 	 if ($this->state == 2) {
11403  	 	 	 $this->_out($this->linestyleWidth);
11404  	 	 }
11405  	 }
11406  
11407  	 /**
11408  	  * Returns the current the line width.
11409  	  * @return int Line width
11410  	  * @public
11411  	  * @since 2.1.000 (2008-01-07)
11412  	  * @see Line(), SetLineWidth()
11413  	  */
11414  	public function GetLineWidth() {
11415  	 	 return $this->LineWidth;
11416  	 }
11417  
11418  	 /**
11419  	  * Set line style.
11420  	  * @param array $style Line style. Array with keys among the following:
11421  	  * <ul>
11422  	  *	  <li>width (float): Width of the line in user units.</li>
11423  	  *	  <li>cap (string): Type of cap to put on the line. Possible values are:
11424  	  * butt, round, square. The difference between "square" and "butt" is that
11425  	  * "square" projects a flat end past the end of the line.</li>
11426  	  *	  <li>join (string): Type of join. Possible values are: miter, round,
11427  	  * bevel.</li>
11428  	  *	  <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
11429  	  * series of length values, which are the lengths of the on and off dashes.
11430  	  * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
11431  	  * 1 off, 2 on, 1 off, ...</li>
11432  	  *	  <li>phase (integer): Modifier on the dash pattern which is used to shift
11433  	  * the point at which the pattern starts.</li>
11434  	  *	  <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>
11435  	  * </ul>
11436  	  * @param boolean $ret if true do not send the command.
11437  	  * @return string the PDF command
11438  	  * @public
11439  	  * @since 2.1.000 (2008-01-08)
11440  	  */
11441  	public function setLineStyle($style, $ret=false) {
11442  	 	 $s = ''; // string to be returned
11443  	 	 if (!is_array($style)) {
11444  	 	 	 return $s;
11445  	 	 }
11446  	 	 if (isset($style['width'])) {
11447  	 	 	 $this->LineWidth = $style['width'];
11448  	 	 	 $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
11449  	 	 	 $s .= $this->linestyleWidth.' ';
11450  	 	 }
11451  	 	 if (isset($style['cap'])) {
11452  	 	 	 $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
11453  	 	 	 if (isset($ca[$style['cap']])) {
11454  	 	 	 	 $this->linestyleCap = $ca[$style['cap']].' J';
11455  	 	 	 	 $s .= $this->linestyleCap.' ';
11456  	 	 	 }
11457  	 	 }
11458  	 	 if (isset($style['join'])) {
11459  	 	 	 $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
11460  	 	 	 if (isset($ja[$style['join']])) {
11461  	 	 	 	 $this->linestyleJoin = $ja[$style['join']].' j';
11462  	 	 	 	 $s .= $this->linestyleJoin.' ';
11463  	 	 	 }
11464  	 	 }
11465  	 	 if (isset($style['dash'])) {
11466  	 	 	 $dash_string = '';
11467  	 	 	 if ($style['dash']) {
11468  	 	 	 	 if (preg_match('/^.+,/', $style['dash']) > 0) {
11469  	 	 	 	 	 $tab = explode(',', $style['dash']);
11470  	 	 	 	 } else {
11471  	 	 	 	 	 $tab = array($style['dash']);
11472  	 	 	 	 }
11473  	 	 	 	 $dash_string = '';
11474  	 	 	 	 foreach ($tab as $i => $v) {
11475  	 	 	 	 	 if ($i) {
11476  	 	 	 	 	 	 $dash_string .= ' ';
11477  	 	 	 	 	 }
11478  	 	 	 	 	 $dash_string .= sprintf('%F', $v);
11479  	 	 	 	 }
11480  	 	 	 }
11481  	 	 	 if (!isset($style['phase']) OR !$style['dash']) {
11482  	 	 	 	 $style['phase'] = 0;
11483  	 	 	 }
11484  	 	 	 $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
11485  	 	 	 $s .= $this->linestyleDash.' ';
11486  	 	 }
11487  	 	 if (isset($style['color'])) {
11488  	 	 	 $s .= $this->setDrawColorArray($style['color'], true).' ';
11489  	 	 }
11490  	 	 if (!$ret AND ($this->state == 2)) {
11491  	 	 	 $this->_out($s);
11492  	 	 }
11493  	 	 return $s;
11494  	 }
11495  
11496  	 /**
11497  	  * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
11498  	  * @param float $x Abscissa of point.
11499  	  * @param float $y Ordinate of point.
11500  	  * @protected
11501  	  * @since 2.1.000 (2008-01-08)
11502  	  */
11503  	protected function _outPoint($x, $y) {
11504  	 	 if ($this->state == 2) {
11505  	 	 	 $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
11506  	 	 }
11507  	 }
11508  
11509  	 /**
11510  	  * Append a straight line segment from the current point to the point (x, y).
11511  	  * The new current point shall be (x, y).
11512  	  * @param float $x Abscissa of end point.
11513  	  * @param float $y Ordinate of end point.
11514  	  * @protected
11515  	  * @since 2.1.000 (2008-01-08)
11516  	  */
11517  	protected function _outLine($x, $y) {
11518  	 	 if ($this->state == 2) {
11519  	 	 	 $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
11520  	 	 }
11521  	 }
11522  
11523  	 /**
11524  	  * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
11525  	  * @param float $x Abscissa of upper-left corner.
11526  	  * @param float $y Ordinate of upper-left corner.
11527  	  * @param float $w Width.
11528  	  * @param float $h Height.
11529  	  * @param string $op options
11530  	  * @protected
11531  	  * @since 2.1.000 (2008-01-08)
11532  	  */
11533  	protected function _outRect($x, $y, $w, $h, $op) {
11534  	 	 if ($this->state == 2) {
11535  	 	 	 $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
11536  	 	 }
11537  	 }
11538  
11539  	 /**
11540  	  * 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.
11541  	  * The new current point shall be (x3, y3).
11542  	  * @param float $x1 Abscissa of control point 1.
11543  	  * @param float $y1 Ordinate of control point 1.
11544  	  * @param float $x2 Abscissa of control point 2.
11545  	  * @param float $y2 Ordinate of control point 2.
11546  	  * @param float $x3 Abscissa of end point.
11547  	  * @param float $y3 Ordinate of end point.
11548  	  * @protected
11549  	  * @since 2.1.000 (2008-01-08)
11550  	  */
11551  	protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
11552  	 	 if ($this->state == 2) {
11553  	 	 	 $this->_out(sprintf('%F %F %F %F %F %F c', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
11554  	 	 }
11555  	 }
11556  
11557  	 /**
11558  	  * 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.
11559  	  * The new current point shall be (x3, y3).
11560  	  * @param float $x2 Abscissa of control point 2.
11561  	  * @param float $y2 Ordinate of control point 2.
11562  	  * @param float $x3 Abscissa of end point.
11563  	  * @param float $y3 Ordinate of end point.
11564  	  * @protected
11565  	  * @since 4.9.019 (2010-04-26)
11566  	  */
11567  	protected function _outCurveV($x2, $y2, $x3, $y3) {
11568  	 	 if ($this->state == 2) {
11569  	 	 	 $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
11570  	 	 }
11571  	 }
11572  
11573  	 /**
11574  	  * 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.
11575  	  * The new current point shall be (x3, y3).
11576  	  * @param float $x1 Abscissa of control point 1.
11577  	  * @param float $y1 Ordinate of control point 1.
11578  	  * @param float $x3 Abscissa of end point.
11579  	  * @param float $y3 Ordinate of end point.
11580  	  * @protected
11581  	  * @since 2.1.000 (2008-01-08)
11582  	  */
11583  	protected function _outCurveY($x1, $y1, $x3, $y3) {
11584  	 	 if ($this->state == 2) {
11585  	 	 	 $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
11586  	 	 }
11587  	 }
11588  
11589  	 /**
11590  	  * Draws a line between two points.
11591  	  * @param float $x1 Abscissa of first point.
11592  	  * @param float $y1 Ordinate of first point.
11593  	  * @param float $x2 Abscissa of second point.
11594  	  * @param float $y2 Ordinate of second point.
11595  	  * @param array $style Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
11596  	  * @public
11597  	  * @since 1.0
11598  	  * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
11599  	  */
11600  	public function Line($x1, $y1, $x2, $y2, $style=array()) {
11601  	 	 if ($this->state != 2) {
11602  	 	 	 return;
11603  	 	 }
11604  	 	 if (is_array($style)) {
11605  	 	 	 $this->setLineStyle($style);
11606  	 	 }
11607  	 	 $this->_outPoint($x1, $y1);
11608  	 	 $this->_outLine($x2, $y2);
11609  	 	 $this->_out('S');
11610  	 }
11611  
11612  	 /**
11613  	  * Draws a rectangle.
11614  	  * @param float $x Abscissa of upper-left corner.
11615  	  * @param float $y Ordinate of upper-left corner.
11616  	  * @param float $w Width.
11617  	  * @param float $h Height.
11618  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11619  	  * @param array $border_style Border style of rectangle. Array with keys among the following:
11620  	  * <ul>
11621  	  *	  <li>all: Line style of all borders. Array like for SetLineStyle().</li>
11622  	  *	  <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
11623  	  * </ul>
11624  	  * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
11625  	  * @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).
11626  	  * @public
11627  	  * @since 1.0
11628  	  * @see SetLineStyle()
11629  	  */
11630  	public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
11631  	 	 if ($this->state != 2) {
11632  	 	 	 return;
11633  	 	 }
11634  	 	 if (empty($style)) {
11635  	 	 	 $style = 'S';
11636  	 	 }
11637  	 	 if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
11638  	 	 	 // set background color
11639  	 	 	 $this->setFillColorArray($fill_color);
11640  	 	 }
11641  	 	 if (!empty($border_style)) {
11642  	 	 	 if (isset($border_style['all']) AND !empty($border_style['all'])) {
11643  	 	 	 	 //set global style for border
11644  	 	 	 	 $this->setLineStyle($border_style['all']);
11645  	 	 	 	 $border_style = array();
11646  	 	 	 } else {
11647  	 	 	 	 // remove stroke operator from style
11648  	 	 	 	 $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*' );
11649  	 	 	 	 if (isset($opnostroke[$style])) {
11650  	 	 	 	 	 $style = $opnostroke[$style];
11651  	 	 	 	 }
11652  	 	 	 }
11653  	 	 }
11654  	 	 if (!empty($style)) {
11655  	 	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
11656  	 	 	 $this->_outRect($x, $y, $w, $h, $op);
11657  	 	 }
11658  	 	 if (!empty($border_style)) {
11659  	 	 	 $border_style2 = array();
11660  	 	 	 foreach ($border_style as $line => $value) {
11661  	 	 	 	 $length = strlen($line);
11662  	 	 	 	 for ($i = 0; $i < $length; ++$i) {
11663  	 	 	 	 	 $border_style2[$line[$i]] = $value;
11664  	 	 	 	 }
11665  	 	 	 }
11666  	 	 	 $border_style = $border_style2;
11667  	 	 	 if (isset($border_style['L']) AND $border_style['L']) {
11668  	 	 	 	 $this->Line($x, $y, $x, $y + $h, $border_style['L']);
11669  	 	 	 }
11670  	 	 	 if (isset($border_style['T']) AND $border_style['T']) {
11671  	 	 	 	 $this->Line($x, $y, $x + $w, $y, $border_style['T']);
11672  	 	 	 }
11673  	 	 	 if (isset($border_style['R']) AND $border_style['R']) {
11674  	 	 	 	 $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
11675  	 	 	 }
11676  	 	 	 if (isset($border_style['B']) AND $border_style['B']) {
11677  	 	 	 	 $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
11678  	 	 	 }
11679  	 	 }
11680  	 }
11681  
11682  	 /**
11683  	  * Draws a Bezier curve.
11684  	  * The Bezier curve is a tangent to the line between the control points at
11685  	  * either end of the curve.
11686  	  * @param float $x0 Abscissa of start point.
11687  	  * @param float $y0 Ordinate of start point.
11688  	  * @param float $x1 Abscissa of control point 1.
11689  	  * @param float $y1 Ordinate of control point 1.
11690  	  * @param float $x2 Abscissa of control point 2.
11691  	  * @param float $y2 Ordinate of control point 2.
11692  	  * @param float $x3 Abscissa of end point.
11693  	  * @param float $y3 Ordinate of end point.
11694  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11695  	  * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
11696  	  * @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).
11697  	  * @public
11698  	  * @see SetLineStyle()
11699  	  * @since 2.1.000 (2008-01-08)
11700  	  */
11701  	public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
11702  	 	 if ($this->state != 2) {
11703  	 	 	 return;
11704  	 	 }
11705  	 	 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11706  	 	 	 $this->setFillColorArray($fill_color);
11707  	 	 }
11708  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
11709  	 	 if ($line_style) {
11710  	 	 	 $this->setLineStyle($line_style);
11711  	 	 }
11712  	 	 $this->_outPoint($x0, $y0);
11713  	 	 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
11714  	 	 $this->_out($op);
11715  	 }
11716  
11717  	 /**
11718  	  * Draws a poly-Bezier curve.
11719  	  * Each Bezier curve segment is a tangent to the line between the control points at
11720  	  * either end of the curve.
11721  	  * @param float $x0 Abscissa of start point.
11722  	  * @param float $y0 Ordinate of start point.
11723  	  * @param float[] $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
11724  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11725  	  * @param array $line_style Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
11726  	  * @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).
11727  	  * @public
11728  	  * @see SetLineStyle()
11729  	  * @since 3.0008 (2008-05-12)
11730  	  */
11731  	public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
11732  	 	 if ($this->state != 2) {
11733  	 	 	 return;
11734  	 	 }
11735  	 	 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11736  	 	 	 $this->setFillColorArray($fill_color);
11737  	 	 }
11738  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
11739  	 	 if ($op == 'f') {
11740  	 	 	 $line_style = array();
11741  	 	 }
11742  	 	 if ($line_style) {
11743  	 	 	 $this->setLineStyle($line_style);
11744  	 	 }
11745  	 	 $this->_outPoint($x0, $y0);
11746  	 	 foreach ($segments as $segment) {
11747  	 	 	 list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
11748  	 	 	 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
11749  	 	 }
11750  	 	 $this->_out($op);
11751  	 }
11752  
11753  	 /**
11754  	  * Draws an ellipse.
11755  	  * An ellipse is formed from n Bezier curves.
11756  	  * @param float $x0 Abscissa of center point.
11757  	  * @param float $y0 Ordinate of center point.
11758  	  * @param float $rx Horizontal radius.
11759  	  * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
11760  	  * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
11761  	  * @param float $astart Angle start of draw line. Default value: 0.
11762  	  * @param float $afinish Angle finish of draw line. Default value: 360.
11763  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11764  	  * @param array $line_style Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
11765  	  * @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).
11766  	  * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
11767  	  * @author Nicola Asuni
11768  	  * @public
11769  	  * @since 2.1.000 (2008-01-08)
11770  	  */
11771  	public function Ellipse($x0, $y0, $rx, $ry=0, $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
11772  	 	 if ($this->state != 2) {
11773  	 	 	 return;
11774  	 	 }
11775  	 	 if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
11776  	 	 	 $ry = $rx;
11777  	 	 }
11778  	 	 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11779  	 	 	 $this->setFillColorArray($fill_color);
11780  	 	 }
11781  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
11782  	 	 if ($op == 'f') {
11783  	 	 	 $line_style = array();
11784  	 	 }
11785  	 	 if ($line_style) {
11786  	 	 	 $this->setLineStyle($line_style);
11787  	 	 }
11788  	 	 $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
11789  	 	 $this->_out($op);
11790  	 }
11791  
11792  	 /**
11793  	  * Append an elliptical arc to the current path.
11794  	  * An ellipse is formed from n Bezier curves.
11795  	  * @param float $xc Abscissa of center point.
11796  	  * @param float $yc Ordinate of center point.
11797  	  * @param float $rx Horizontal radius.
11798  	  * @param float $ry Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
11799  	  * @param float $xang Angle between the X-axis and the major axis of the ellipse. Default value: 0.
11800  	  * @param float $angs Angle start of draw line. Default value: 0.
11801  	  * @param float $angf Angle finish of draw line. Default value: 360.
11802  	  * @param boolean $pie if true do not mark the border point (used to draw pie sectors).
11803  	  * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
11804  	  * @param boolean $startpoint if true output a starting point.
11805  	  * @param boolean $ccw if true draws in counter-clockwise.
11806  	  * @param boolean $svg if true the angles are in svg mode (already calculated).
11807  	  * @return array bounding box coordinates (x min, y min, x max, y max)
11808  	  * @author Nicola Asuni
11809  	  * @protected
11810  	  * @since 4.9.019 (2010-04-26)
11811  	  */
11812  	protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
11813  	 	 if (($rx <= 0) OR ($ry < 0)) {
11814  	 	 	 return;
11815  	 	 }
11816  	 	 $k = $this->k;
11817  	 	 if ($nc < 2) {
11818  	 	 	 $nc = 2;
11819  	 	 }
11820  	 	 $xmin = 2147483647;
11821  	 	 $ymin = 2147483647;
11822  	 	 $xmax = 0;
11823  	 	 $ymax = 0;
11824  	 	 if ($pie) {
11825  	 	 	 // center of the arc
11826  	 	 	 $this->_outPoint($xc, $yc);
11827  	 	 }
11828  	 	 $xang = deg2rad((float) $xang);
11829  	 	 $angs = deg2rad((float) $angs);
11830  	 	 $angf = deg2rad((float) $angf);
11831  	 	 if ($svg) {
11832  	 	 	 $as = $angs;
11833  	 	 	 $af = $angf;
11834  	 	 } else {
11835  	 	 	 $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
11836  	 	 	 $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
11837  	 	 }
11838  	 	 if ($as < 0) {
11839  	 	 	 $as += (2 * M_PI);
11840  	 	 }
11841  	 	 if ($af < 0) {
11842  	 	 	 $af += (2 * M_PI);
11843  	 	 }
11844  	 	 if ($ccw AND ($as > $af)) {
11845  	 	 	 // reverse rotation
11846  	 	 	 $as -= (2 * M_PI);
11847  	 	 } elseif (!$ccw AND ($as < $af)) {
11848  	 	 	 // reverse rotation
11849  	 	 	 $af -= (2 * M_PI);
11850  	 	 }
11851  	 	 $total_angle = ($af - $as);
11852  	 	 if ($nc < 2) {
11853  	 	 	 $nc = 2;
11854  	 	 }
11855  	 	 // total arcs to draw
11856  	 	 $nc *= (2 * abs($total_angle) / M_PI);
11857  	 	 $nc = round($nc) + 1;
11858  	 	 // angle of each arc
11859  	 	 $arcang = ($total_angle / $nc);
11860  	 	 // center point in PDF coordinates
11861  	 	 $x0 = $xc;
11862  	 	 $y0 = ($this->h - $yc);
11863  	 	 // starting angle
11864  	 	 $ang = $as;
11865  	 	 $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
11866  	 	 $cos_xang = cos($xang);
11867  	 	 $sin_xang = sin($xang);
11868  	 	 $cos_ang = cos($ang);
11869  	 	 $sin_ang = sin($ang);
11870  	 	 // first arc point
11871  	 	 $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
11872  	 	 $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
11873  	 	 // first Bezier control point
11874  	 	 $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
11875  	 	 $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
11876  	 	 if ($pie) {
11877  	 	 	 // line from center to arc starting point
11878  	 	 	 $this->_outLine($px1, $this->h - $py1);
11879  	 	 } elseif ($startpoint) {
11880  	 	 	 // arc starting point
11881  	 	 	 $this->_outPoint($px1, $this->h - $py1);
11882  	 	 }
11883  	 	 // draw arcs
11884  	 	 for ($i = 1; $i <= $nc; ++$i) {
11885  	 	 	 // starting angle
11886  	 	 	 $ang = $as + ($i * $arcang);
11887  	 	 	 if ($i == $nc) {
11888  	 	 	 	 $ang = $af;
11889  	 	 	 }
11890  	 	 	 $cos_ang = cos($ang);
11891  	 	 	 $sin_ang = sin($ang);
11892  	 	 	 // second arc point
11893  	 	 	 $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
11894  	 	 	 $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
11895  	 	 	 // second Bezier control point
11896  	 	 	 $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
11897  	 	 	 $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
11898  	 	 	 // draw arc
11899  	 	 	 $cx1 = ($px1 + $qx1);
11900  	 	 	 $cy1 = ($this->h - ($py1 + $qy1));
11901  	 	 	 $cx2 = ($px2 - $qx2);
11902  	 	 	 $cy2 = ($this->h - ($py2 - $qy2));
11903  	 	 	 $cx3 = $px2;
11904  	 	 	 $cy3 = ($this->h - $py2);
11905  	 	 	 $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
11906  	 	 	 // get bounding box coordinates
11907  	 	 	 $xmin = min($xmin, $cx1, $cx2, $cx3);
11908  	 	 	 $ymin = min($ymin, $cy1, $cy2, $cy3);
11909  	 	 	 $xmax = max($xmax, $cx1, $cx2, $cx3);
11910  	 	 	 $ymax = max($ymax, $cy1, $cy2, $cy3);
11911  	 	 	 // move to next point
11912  	 	 	 $px1 = $px2;
11913  	 	 	 $py1 = $py2;
11914  	 	 	 $qx1 = $qx2;
11915  	 	 	 $qy1 = $qy2;
11916  	 	 }
11917  	 	 if ($pie) {
11918  	 	 	 $this->_outLine($xc, $yc);
11919  	 	 	 // get bounding box coordinates
11920  	 	 	 $xmin = min($xmin, $xc);
11921  	 	 	 $ymin = min($ymin, $yc);
11922  	 	 	 $xmax = max($xmax, $xc);
11923  	 	 	 $ymax = max($ymax, $yc);
11924  	 	 }
11925  	 	 return array($xmin, $ymin, $xmax, $ymax);
11926  	 }
11927  
11928  	 /**
11929  	  * Draws a circle.
11930  	  * A circle is formed from n Bezier curves.
11931  	  * @param float $x0 Abscissa of center point.
11932  	  * @param float $y0 Ordinate of center point.
11933  	  * @param float $r Radius.
11934  	  * @param float $angstr Angle start of draw line. Default value: 0.
11935  	  * @param float $angend Angle finish of draw line. Default value: 360.
11936  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11937  	  * @param array $line_style Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
11938  	  * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
11939  	  * @param integer $nc Number of curves used to draw a 90 degrees portion of circle.
11940  	  * @public
11941  	  * @since 2.1.000 (2008-01-08)
11942  	  */
11943  	public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
11944  	 	 $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
11945  	 }
11946  
11947  	 /**
11948  	  * Draws a polygonal line
11949  	  * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
11950  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11951  	  * @param array $line_style Line style of polygon. Array with keys among the following:
11952  	  * <ul>
11953  	  *	  <li>all: Line style of all lines. Array like for SetLineStyle().</li>
11954  	  *	  <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
11955  	  * </ul>
11956  	  * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
11957  	  * @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).
11958  	  * @since 4.8.003 (2009-09-15)
11959  	  * @public
11960  	  */
11961  	public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
11962  	 	 $this->Polygon($p, $style, $line_style, $fill_color, false);
11963  	 }
11964  
11965  	 /**
11966  	  * Draws a polygon.
11967  	  * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
11968  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
11969  	  * @param array $line_style Line style of polygon. Array with keys among the following:
11970  	  * <ul>
11971  	  *	  <li>all: Line style of all lines. Array like for SetLineStyle().</li>
11972  	  *	  <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
11973  	  * </ul>
11974  	  * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
11975  	  * @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).
11976  	  * @param boolean $closed if true the polygon is closes, otherwise will remain open
11977  	  * @public
11978  	  * @since 2.1.000 (2008-01-08)
11979  	  */
11980  	public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
11981  	 	 if ($this->state != 2) {
11982  	 	 	 return;
11983  	 	 }
11984  	 	 $nc = count($p); // number of coordinates
11985  	 	 $np = $nc / 2; // number of points
11986  	 	 if ($closed) {
11987  	 	 	 // close polygon by adding the first 2 points at the end (one line)
11988  	 	 	 for ($i = 0; $i < 4; ++$i) {
11989  	 	 	 	 $p[$nc + $i] = $p[$i];
11990  	 	 	 }
11991  	 	 	 // copy style for the last added line
11992  	 	 	 if (isset($line_style[0])) {
11993  	 	 	 	 $line_style[$np] = $line_style[0];
11994  	 	 	 }
11995  	 	 	 $nc += 4;
11996  	 	 }
11997  	 	 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11998  	 	 	 $this->setFillColorArray($fill_color);
11999  	 	 }
12000  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
12001  	 	 if ($op == 'f') {
12002  	 	 	 $line_style = array();
12003  	 	 }
12004  	 	 $draw = true;
12005  	 	 if ($line_style) {
12006  	 	 	 if (isset($line_style['all'])) {
12007  	 	 	 	 $this->setLineStyle($line_style['all']);
12008  	 	 	 } else {
12009  	 	 	 	 $draw = false;
12010  	 	 	 	 if ($op == 'B') {
12011  	 	 	 	 	 // draw fill
12012  	 	 	 	 	 $op = 'f';
12013  	 	 	 	 	 $this->_outPoint($p[0], $p[1]);
12014  	 	 	 	 	 for ($i = 2; $i < $nc; $i = $i + 2) {
12015  	 	 	 	 	 	 $this->_outLine($p[$i], $p[$i + 1]);
12016  	 	 	 	 	 }
12017  	 	 	 	 	 $this->_out($op);
12018  	 	 	 	 }
12019  	 	 	 	 // draw outline
12020  	 	 	 	 $this->_outPoint($p[0], $p[1]);
12021  	 	 	 	 for ($i = 2; $i < $nc; $i = $i + 2) {
12022  	 	 	 	 	 $line_num = ($i / 2) - 1;
12023  	 	 	 	 	 if (isset($line_style[$line_num])) {
12024  	 	 	 	 	 	 if ($line_style[$line_num] != 0) {
12025  	 	 	 	 	 	 	 if (is_array($line_style[$line_num])) {
12026  	 	 	 	 	 	 	 	 $this->_out('S');
12027  	 	 	 	 	 	 	 	 $this->setLineStyle($line_style[$line_num]);
12028  	 	 	 	 	 	 	 	 $this->_outPoint($p[$i - 2], $p[$i - 1]);
12029  	 	 	 	 	 	 	 	 $this->_outLine($p[$i], $p[$i + 1]);
12030  	 	 	 	 	 	 	 	 $this->_out('S');
12031  	 	 	 	 	 	 	 	 $this->_outPoint($p[$i], $p[$i + 1]);
12032  	 	 	 	 	 	 	 } else {
12033  	 	 	 	 	 	 	 	 $this->_outLine($p[$i], $p[$i + 1]);
12034  	 	 	 	 	 	 	 }
12035  	 	 	 	 	 	 }
12036  	 	 	 	 	 } else {
12037  	 	 	 	 	 	 $this->_outLine($p[$i], $p[$i + 1]);
12038  	 	 	 	 	 }
12039  	 	 	 	 }
12040  	 	 	 	 $this->_out($op);
12041  	 	 	 }
12042  	 	 }
12043  	 	 if ($draw) {
12044  	 	 	 $this->_outPoint($p[0], $p[1]);
12045  	 	 	 for ($i = 2; $i < $nc; $i = $i + 2) {
12046  	 	 	 	 $this->_outLine($p[$i], $p[$i + 1]);
12047  	 	 	 }
12048  	 	 	 $this->_out($op);
12049  	 	 }
12050  	 }
12051  
12052  	 /**
12053  	  * Draws a regular polygon.
12054  	  * @param float $x0 Abscissa of center point.
12055  	  * @param float $y0 Ordinate of center point.
12056  	  * @param float $r Radius of inscribed circle.
12057  	  * @param integer $ns Number of sides.
12058  	  * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
12059  	  * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
12060  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
12061  	  * @param array $line_style Line style of polygon sides. Array with keys among the following:
12062  	  * <ul>
12063  	  *	  <li>all: Line style of all sides. Array like for SetLineStyle().</li>
12064  	  *	  <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
12065  	  * </ul>
12066  	  * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
12067  	  * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
12068  	  * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
12069  	  * <ul>
12070  	  *	  <li>D or empty string: Draw (default).</li>
12071  	  *	  <li>F: Fill.</li>
12072  	  *	  <li>DF or FD: Draw and fill.</li>
12073  	  *	  <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
12074  	  *	  <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
12075  	  * </ul>
12076  	  * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
12077  	  * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
12078  	  * @public
12079  	  * @since 2.1.000 (2008-01-08)
12080  	  */
12081  	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()) {
12082  	 	 if (3 > $ns) {
12083  	 	 	 $ns = 3;
12084  	 	 }
12085  	 	 if ($draw_circle) {
12086  	 	 	 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
12087  	 	 }
12088  	 	 $p = array();
12089  	 	 for ($i = 0; $i < $ns; ++$i) {
12090  	 	 	 $a = $angle + ($i * 360 / $ns);
12091  	 	 	 $a_rad = deg2rad((float) $a);
12092  	 	 	 $p[] = $x0 + ($r * sin($a_rad));
12093  	 	 	 $p[] = $y0 + ($r * cos($a_rad));
12094  	 	 }
12095  	 	 $this->Polygon($p, $style, $line_style, $fill_color);
12096  	 }
12097  
12098  	 /**
12099  	  * Draws a star polygon
12100  	  * @param float $x0 Abscissa of center point.
12101  	  * @param float $y0 Ordinate of center point.
12102  	  * @param float $r Radius of inscribed circle.
12103  	  * @param integer $nv Number of vertices.
12104  	  * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
12105  	  * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
12106  	  * @param boolean $draw_circle Draw inscribed circle or not. Default value is false.
12107  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
12108  	  * @param array $line_style Line style of polygon sides. Array with keys among the following:
12109  	  * <ul>
12110  	  *	  <li>all: Line style of all sides. Array like for
12111  	  * SetLineStyle().</li>
12112  	  *	  <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
12113  	  * </ul>
12114  	  * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
12115  	  * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
12116  	  * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
12117  	  * <ul>
12118  	  *	  <li>D or empty string: Draw (default).</li>
12119  	  *	  <li>F: Fill.</li>
12120  	  *	  <li>DF or FD: Draw and fill.</li>
12121  	  *	  <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
12122  	  *	  <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
12123  	  * </ul>
12124  	  * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
12125  	  * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
12126  	  * @public
12127  	  * @since 2.1.000 (2008-01-08)
12128  	  */
12129  	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()) {
12130  	 	 if ($nv < 2) {
12131  	 	 	 $nv = 2;
12132  	 	 }
12133  	 	 if ($draw_circle) {
12134  	 	 	 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
12135  	 	 }
12136  	 	 $p2 = array();
12137  	 	 $visited = array();
12138  	 	 for ($i = 0; $i < $nv; ++$i) {
12139  	 	 	 $a = $angle + ($i * 360 / $nv);
12140  	 	 	 $a_rad = deg2rad((float) $a);
12141  	 	 	 $p2[] = $x0 + ($r * sin($a_rad));
12142  	 	 	 $p2[] = $y0 + ($r * cos($a_rad));
12143  	 	 	 $visited[] = false;
12144  	 	 }
12145  	 	 $p = array();
12146  	 	 $i = 0;
12147  	 	 do {
12148  	 	 	 $p[] = $p2[$i * 2];
12149  	 	 	 $p[] = $p2[($i * 2) + 1];
12150  	 	 	 $visited[$i] = true;
12151  	 	 	 $i += $ng;
12152  	 	 	 $i %= $nv;
12153  	 	 } while (!$visited[$i]);
12154  	 	 $this->Polygon($p, $style, $line_style, $fill_color);
12155  	 }
12156  
12157  	 /**
12158  	  * Draws a rounded rectangle.
12159  	  * @param float $x Abscissa of upper-left corner.
12160  	  * @param float $y Ordinate of upper-left corner.
12161  	  * @param float $w Width.
12162  	  * @param float $h Height.
12163  	  * @param float $r the radius of the circle used to round off the corners of the rectangle.
12164  	  * @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").
12165  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
12166  	  * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
12167  	  * @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).
12168  	  * @public
12169  	  * @since 2.1.000 (2008-01-08)
12170  	  */
12171  	public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
12172  	 	 $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
12173  	 }
12174  
12175  	 /**
12176  	  * Draws a rounded rectangle.
12177  	  * @param float $x Abscissa of upper-left corner.
12178  	  * @param float $y Ordinate of upper-left corner.
12179  	  * @param float $w Width.
12180  	  * @param float $h Height.
12181  	  * @param float $rx the x-axis radius of the ellipse used to round off the corners of the rectangle.
12182  	  * @param float $ry the y-axis radius of the ellipse used to round off the corners of the rectangle.
12183  	  * @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").
12184  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
12185  	  * @param array $border_style Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
12186  	  * @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).
12187  	  * @public
12188  	  * @since 4.9.019 (2010-04-22)
12189  	  */
12190  	public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
12191  	 	 if ($this->state != 2) {
12192  	 	 	 return;
12193  	 	 }
12194  	 	 if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
12195  	 	 	 // Not rounded
12196  	 	 	 $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
12197  	 	 	 return;
12198  	 	 }
12199  	 	 // Rounded
12200  	 	 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
12201  	 	 	 $this->setFillColorArray($fill_color);
12202  	 	 }
12203  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
12204  	 	 if ($op == 'f') {
12205  	 	 	 $border_style = array();
12206  	 	 }
12207  	 	 if ($border_style) {
12208  	 	 	 $this->setLineStyle($border_style);
12209  	 	 }
12210  	 	 $MyArc = 4 / 3 * (sqrt(2) - 1);
12211  	 	 $this->_outPoint($x + $rx, $y);
12212  	 	 $xc = $x + $w - $rx;
12213  	 	 $yc = $y + $ry;
12214  	 	 $this->_outLine($xc, $y);
12215  	 	 if ($round_corner[0]) {
12216  	 	 	 $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
12217  	 	 } else {
12218  	 	 	 $this->_outLine($x + $w, $y);
12219  	 	 }
12220  	 	 $xc = $x + $w - $rx;
12221  	 	 $yc = $y + $h - $ry;
12222  	 	 $this->_outLine($x + $w, $yc);
12223  	 	 if ($round_corner[1]) {
12224  	 	 	 $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
12225  	 	 } else {
12226  	 	 	 $this->_outLine($x + $w, $y + $h);
12227  	 	 }
12228  	 	 $xc = $x + $rx;
12229  	 	 $yc = $y + $h - $ry;
12230  	 	 $this->_outLine($xc, $y + $h);
12231  	 	 if ($round_corner[2]) {
12232  	 	 	 $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
12233  	 	 } else {
12234  	 	 	 $this->_outLine($x, $y + $h);
12235  	 	 }
12236  	 	 $xc = $x + $rx;
12237  	 	 $yc = $y + $ry;
12238  	 	 $this->_outLine($x, $yc);
12239  	 	 if ($round_corner[3]) {
12240  	 	 	 $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
12241  	 	 } else {
12242  	 	 	 $this->_outLine($x, $y);
12243  	 	 	 $this->_outLine($x + $rx, $y);
12244  	 	 }
12245  	 	 $this->_out($op);
12246  	 }
12247  
12248  	 /**
12249  	  * Draws a grahic arrow.
12250  	  * @param float $x0 Abscissa of first point.
12251  	  * @param float $y0 Ordinate of first point.
12252  	  * @param float $x1 Abscissa of second point.
12253  	  * @param float $y1 Ordinate of second point.
12254  	  * @param int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
12255  	  * @param float $arm_size length of arrowhead arms
12256  	  * @param int $arm_angle angle between an arm and the shaft
12257  	  * @author Piotr Galecki, Nicola Asuni, Andy Meier
12258  	  * @since 4.6.018 (2009-07-10)
12259  	  */
12260  	public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
12261  	 	 // getting arrow direction angle
12262  	 	 // 0 deg angle is when both arms go along X axis. angle grows clockwise.
12263  	 	 $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
12264  	 	 if ($dir_angle < 0) {
12265  	 	 	 $dir_angle += (2 * M_PI);
12266  	 	 }
12267  	 	 $arm_angle = deg2rad($arm_angle);
12268  	 	 $sx1 = $x1;
12269  	 	 $sy1 = $y1;
12270  	 	 if ($head_style > 0) {
12271  	 	 	 // calculate the stopping point for the arrow shaft
12272  	 	 	 $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
12273  	 	 	 $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
12274  	 	 }
12275  	 	 // main arrow line / shaft
12276  	 	 $this->Line($x0, $y0, $sx1, $sy1);
12277  	 	 // left arrowhead arm tip
12278  	 	 $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
12279  	 	 $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
12280  	 	 // right arrowhead arm tip
12281  	 	 $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
12282  	 	 $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
12283  	 	 $mode = 'D';
12284  	 	 $style = array();
12285  	 	 switch ($head_style) {
12286  	 	 	 case 0: {
12287  	 	 	 	 // draw only arrowhead arms
12288  	 	 	 	 $mode = 'D';
12289  	 	 	 	 $style = array(1, 1, 0);
12290  	 	 	 	 break;
12291  	 	 	 }
12292  	 	 	 case 1: {
12293  	 	 	 	 // draw closed arrowhead, but no fill
12294  	 	 	 	 $mode = 'D';
12295  	 	 	 	 break;
12296  	 	 	 }
12297  	 	 	 case 2: {
12298  	 	 	 	 // closed and filled arrowhead
12299  	 	 	 	 $mode = 'DF';
12300  	 	 	 	 break;
12301  	 	 	 }
12302  	 	 	 case 3: {
12303  	 	 	 	 // filled arrowhead
12304  	 	 	 	 $mode = 'F';
12305  	 	 	 	 break;
12306  	 	 	 }
12307  	 	 }
12308  	 	 $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
12309  	 }
12310  
12311  	 // END GRAPHIC FUNCTIONS SECTION -----------------------
12312  
12313  	 /**
12314  	  * Add a Named Destination.
12315  	  * NOTE: destination names are unique, so only last entry will be saved.
12316  	  * @param string $name Destination name.
12317  	  * @param float $y Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
12318  	  * @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.
12319  	  * @param float $x X position in user units of the destiantion on the selected page (default = -1 = current position;).
12320  	  * @return string|false Stripped named destination identifier or false in case of error.
12321  	  * @public
12322  	  * @author Christian Deligant, Nicola Asuni
12323  	  * @since 5.9.097 (2011-06-23)
12324  	  */
12325  	public function setDestination($name, $y=-1, $page='', $x=-1) {
12326  	 	 // remove unsupported characters
12327  	 	 $name = TCPDF_STATIC::encodeNameObject($name);
12328  	 	 if (TCPDF_STATIC::empty_string($name)) {
12329  	 	 	 return false;
12330  	 	 }
12331  	 	 if ($y == -1) {
12332  	 	 	 $y = $this->GetY();
12333  	 	 } elseif ($y < 0) {
12334  	 	 	 $y = 0;
12335  	 	 } elseif ($y > $this->h) {
12336  	 	 	 $y = $this->h;
12337  	 	 }
12338  	 	 if ($x == -1) {
12339  	 	 	 $x = $this->GetX();
12340  	 	 } elseif ($x < 0) {
12341  	 	 	 $x = 0;
12342  	 	 } elseif ($x > $this->w) {
12343  	 	 	 $x = $this->w;
12344  	 	 }
12345  	 	 $fixed = false;
12346  	 	 if (!empty($page) AND (substr($page, 0, 1) == '*')) {
12347  	 	 	 $page = intval(substr($page, 1));
12348  	 	 	 // this page number will not be changed when moving/add/deleting pages
12349  	 	 	 $fixed = true;
12350  	 	 }
12351  	 	 if (empty($page)) {
12352  	 	 	 $page = $this->PageNo();
12353  	 	 	 if (empty($page)) {
12354  	 	 	 	 return;
12355  	 	 	 }
12356  	 	 }
12357  	 	 $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed);
12358  	 	 return $name;
12359  	 }
12360  
12361  	 /**
12362  	  * Return the Named Destination array.
12363  	  * @return array Named Destination array.
12364  	  * @public
12365  	  * @author Nicola Asuni
12366  	  * @since 5.9.097 (2011-06-23)
12367  	  */
12368  	public function getDestination() {
12369  	 	 return $this->dests;
12370  	 }
12371  
12372  	 /**
12373  	  * Insert Named Destinations.
12374  	  * @protected
12375  	  * @author Johannes G\FCntert, Nicola Asuni
12376  	  * @since 5.9.098 (2011-06-23)
12377  	  */
12378  	protected function _putdests() {
12379  	 	 if (empty($this->dests)) {
12380  	 	 	 return;
12381  	 	 }
12382  	 	 $this->n_dests = $this->_newobj();
12383  	 	 $out = ' <<';
12384  	 	 foreach($this->dests as $name => $o) {
12385  	 	 	 $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)));
12386  	 	 }
12387  	 	 $out .= ' >>';
12388  	 	 $out .= "\n".'endobj';
12389  	 	 $this->_out($out);
12390  	 }
12391  
12392  	 /**
12393  	  * Adds a bookmark - alias for Bookmark().
12394  	  * @param string $txt Bookmark description.
12395  	  * @param int $level Bookmark level (minimum value is 0).
12396  	  * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
12397  	  * @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.
12398  	  * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
12399  	  * @param array $color RGB color array (values from 0 to 255).
12400  	  * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
12401  	  * @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).
12402  	  * @public
12403  	  */
12404  	public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
12405  	 	 $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
12406  	 }
12407  
12408  	 /**
12409  	  * Adds a bookmark.
12410  	  * @param string $txt Bookmark description.
12411  	  * @param int $level Bookmark level (minimum value is 0).
12412  	  * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
12413  	  * @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.
12414  	  * @param string $style Font style: B = Bold, I = Italic, BI = Bold + Italic.
12415  	  * @param array $color RGB color array (values from 0 to 255).
12416  	  * @param float $x X position in user units of the bookmark on the selected page (default = -1 = current position;).
12417  	  * @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).
12418  	  * @public
12419  	  * @since 2.1.002 (2008-02-12)
12420  	  */
12421  	public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
12422  	 	 if ($level < 0) {
12423  	 	 	 $level = 0;
12424  	 	 }
12425  	 	 if (isset($this->outlines[0])) {
12426  	 	 	 $lastoutline = end($this->outlines);
12427  	 	 	 $maxlevel = $lastoutline['l'] + 1;
12428  	 	 } else {
12429  	 	 	 $maxlevel = 0;
12430  	 	 }
12431  	 	 if ($level > $maxlevel) {
12432  	 	 	 $level = $maxlevel;
12433  	 	 }
12434  	 	 if ($y == -1) {
12435  	 	 	 $y = $this->GetY();
12436  	 	 } elseif ($y < 0) {
12437  	 	 	 $y = 0;
12438  	 	 } elseif ($y > $this->h) {
12439  	 	 	 $y = $this->h;
12440  	 	 }
12441  	 	 if ($x == -1) {
12442  	 	 	 $x = $this->GetX();
12443  	 	 } elseif ($x < 0) {
12444  	 	 	 $x = 0;
12445  	 	 } elseif ($x > $this->w) {
12446  	 	 	 $x = $this->w;
12447  	 	 }
12448  	 	 $fixed = false;
12449  	 	 $pageAsString = (string) $page;
12450  	 	 if ($pageAsString && $pageAsString[0] == '*') {
12451  	 	 	 $page = intval(substr($page, 1));
12452  	 	 	 // this page number will not be changed when moving/add/deleting pages
12453  	 	 	 $fixed = true;
12454  	 	 }
12455  	 	 if (empty($page)) {
12456  	 	 	 $page = $this->PageNo();
12457  	 	 	 if (empty($page)) {
12458  	 	 	 	 return;
12459  	 	 	 }
12460  	 	 }
12461  	 	 $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
12462  	 }
12463  
12464  	 /**
12465  	  * Sort bookmarks for page and key.
12466  	  * @protected
12467  	  * @since 5.9.119 (2011-09-19)
12468  	  */
12469  	protected function sortBookmarks() {
12470  	 	 // get sorting columns
12471  	 	 $outline_p = array();
12472  	 	 $outline_y = array();
12473  	 	 foreach ($this->outlines as $key => $row) {
12474  	 	 	 $outline_p[$key] = $row['p'];
12475  	 	 	 $outline_k[$key] = $key;
12476  	 	 }
12477  	 	 // sort outlines by page and original position
12478  	 	 array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
12479  	 }
12480  
12481  	 /**
12482  	  * Create a bookmark PDF string.
12483  	  * @protected
12484  	  * @author Olivier Plathey, Nicola Asuni
12485  	  * @since 2.1.002 (2008-02-12)
12486  	  */
12487  	protected function _putbookmarks() {
12488  	 	 $nb = count($this->outlines);
12489  	 	 if ($nb == 0) {
12490  	 	 	 return;
12491  	 	 }
12492  	 	 // sort bookmarks
12493  	 	 $this->sortBookmarks();
12494  	 	 $lru = array();
12495  	 	 $level = 0;
12496  	 	 foreach ($this->outlines as $i => $o) {
12497  	 	 	 if ($o['l'] > 0) {
12498  	 	 	 	 $parent = $lru[($o['l'] - 1)];
12499  	 	 	 	 //Set parent and last pointers
12500  	 	 	 	 $this->outlines[$i]['parent'] = $parent;
12501  	 	 	 	 $this->outlines[$parent]['last'] = $i;
12502  	 	 	 	 if ($o['l'] > $level) {
12503  	 	 	 	 	 //Level increasing: set first pointer
12504  	 	 	 	 	 $this->outlines[$parent]['first'] = $i;
12505  	 	 	 	 }
12506  	 	 	 } else {
12507  	 	 	 	 $this->outlines[$i]['parent'] = $nb;
12508  	 	 	 }
12509  	 	 	 if (($o['l'] <= $level) AND ($i > 0)) {
12510  	 	 	 	 //Set prev and next pointers
12511  	 	 	 	 $prev = $lru[$o['l']];
12512  	 	 	 	 $this->outlines[$prev]['next'] = $i;
12513  	 	 	 	 $this->outlines[$i]['prev'] = $prev;
12514  	 	 	 }
12515  	 	 	 $lru[$o['l']] = $i;
12516  	 	 	 $level = $o['l'];
12517  	 	 }
12518  	 	 //Outline items
12519  	 	 $n = $this->n + 1;
12520  	 	 $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';
12521  	 	 foreach ($this->outlines as $i => $o) {
12522  	 	 	 $oid = $this->_newobj();
12523  	 	 	 // covert HTML title to string
12524  	 	 	 $title = preg_replace($nltags, "\n", $o['t']);
12525  	 	 	 $title = preg_replace("/[\r]+/si", '', $title);
12526  	 	 	 $title = preg_replace("/[\n]+/si", "\n", $title);
12527  	 	 	 $title = strip_tags($title);
12528  	 	 	 $title = $this->stringTrim($title);
12529  	 	 	 $out = '<</Title '.$this->_textstring($title, $oid);
12530  	 	 	 $out .= ' /Parent '.($n + $o['parent']).' 0 R';
12531  	 	 	 if (isset($o['prev'])) {
12532  	 	 	 	 $out .= ' /Prev '.($n + $o['prev']).' 0 R';
12533  	 	 	 }
12534  	 	 	 if (isset($o['next'])) {
12535  	 	 	 	 $out .= ' /Next '.($n + $o['next']).' 0 R';
12536  	 	 	 }
12537  	 	 	 if (isset($o['first'])) {
12538  	 	 	 	 $out .= ' /First '.($n + $o['first']).' 0 R';
12539  	 	 	 }
12540  	 	 	 if (isset($o['last'])) {
12541  	 	 	 	 $out .= ' /Last '.($n + $o['last']).' 0 R';
12542  	 	 	 }
12543  	 	 	 if (isset($o['u']) AND !empty($o['u'])) {
12544  	 	 	 	 // link
12545  	 	 	 	 if (is_string($o['u'])) {
12546  	 	 	 	 	 if ($o['u'][0] == '#') {
12547  	 	 	 	 	 	 // internal destination
12548  	 	 	 	 	 	 $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
12549  	 	 	 	 	 } elseif ($o['u'][0] == '%') {
12550  	 	 	 	 	 	 // embedded PDF file
12551  	 	 	 	 	 	 $filename = basename(substr($o['u'], 1));
12552  	 	 	 	 	 	 $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
12553  	 	 	 	 	 } elseif ($o['u'][0] == '*') {
12554  	 	 	 	 	 	 // embedded generic file
12555  	 	 	 	 	 	 $filename = basename(substr($o['u'], 1));
12556  	 	 	 	 	 	 $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});';
12557  	 	 	 	 	 	 $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
12558  	 	 	 	 	 } else {
12559  	 	 	 	 	 	 // external URI link
12560  	 	 	 	 	 	 $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
12561  	 	 	 	 	 }
12562  	 	 	 	 } elseif (isset($this->links[$o['u']])) {
12563  	 	 	 	 	 // internal link ID
12564  	 	 	 	 	 $l = $this->links[$o['u']];
12565  	 	 	 	 	 if (isset($this->page_obj_id[($l['p'])])) {
12566  	 	 	 	 	 	 $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)));
12567  	 	 	 	 	 }
12568  	 	 	 	 }
12569  	 	 	 } elseif (isset($this->page_obj_id[($o['p'])])) {
12570  	 	 	 	 // link to a page
12571  	 	 	 	 $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)));
12572  	 	 	 }
12573  	 	 	 // set font style
12574  	 	 	 $style = 0;
12575  	 	 	 if (!empty($o['s'])) {
12576  	 	 	 	 // bold
12577  	 	 	 	 if (strpos($o['s'], 'B') !== false) {
12578  	 	 	 	 	 $style |= 2;
12579  	 	 	 	 }
12580  	 	 	 	 // oblique
12581  	 	 	 	 if (strpos($o['s'], 'I') !== false) {
12582  	 	 	 	 	 $style |= 1;
12583  	 	 	 	 }
12584  	 	 	 }
12585  	 	 	 $out .= sprintf(' /F %d', $style);
12586  	 	 	 // set bookmark color
12587  	 	 	 if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
12588  	 	 	 	 $color = array_values($o['c']);
12589  	 	 	 	 $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
12590  	 	 	 } else {
12591  	 	 	 	 // black
12592  	 	 	 	 $out .= ' /C [0.0 0.0 0.0]';
12593  	 	 	 }
12594  	 	 	 $out .= ' /Count 0'; // normally closed item
12595  	 	 	 $out .= ' >>';
12596  	 	 	 $out .= "\n".'endobj';
12597  	 	 	 $this->_out($out);
12598  	 	 }
12599  	 	 //Outline root
12600  	 	 $this->OutlineRoot = $this->_newobj();
12601  	 	 $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
12602  	 }
12603  
12604  	 // --- JAVASCRIPT ------------------------------------------------------
12605  
12606  	 /**
12607  	  * Adds a javascript
12608  	  * @param string $script Javascript code
12609  	  * @public
12610  	  * @author Johannes G\FCntert, Nicola Asuni
12611  	  * @since 2.1.002 (2008-02-12)
12612  	  */
12613  	public function IncludeJS($script) {
12614  	 	 $this->javascript .= $script;
12615  	 }
12616  
12617  	 /**
12618  	  * Adds a javascript object and return object ID
12619  	  * @param string $script Javascript code
12620  	  * @param boolean $onload if true executes this object when opening the document
12621  	  * @return int internal object ID
12622  	  * @public
12623  	  * @author Nicola Asuni
12624  	  * @since 4.8.000 (2009-09-07)
12625  	  */
12626  	public function addJavascriptObject($script, $onload=false) {
12627  	 	 if ($this->pdfa_mode) {
12628  	 	 	 // javascript is not allowed in PDF/A mode
12629  	 	 	 return false;
12630  	 	 }
12631  	 	 ++$this->n;
12632  	 	 $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
12633  	 	 return $this->n;
12634  	 }
12635  
12636  	 /**
12637  	  * Create a javascript PDF string.
12638  	  * @protected
12639  	  * @author Johannes G\FCntert, Nicola Asuni
12640  	  * @since 2.1.002 (2008-02-12)
12641  	  */
12642  	protected function _putjavascript() {
12643  	 	 if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
12644  	 	 	 return;
12645  	 	 }
12646  	 	 if (strpos($this->javascript, 'this.addField') > 0) {
12647  	 	 	 if (!$this->ur['enabled']) {
12648  	 	 	 	 //$this->setUserRights();
12649  	 	 	 }
12650  	 	 	 // the following two lines are used to avoid form fields duplication after saving
12651  	 	 	 // The addField method only works when releasing user rights (UR3)
12652  	 	 	 $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
12653  	 	 	 $jsb = "getField('tcpdfdocsaved').value='saved';";
12654  	 	 	 $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
12655  	 	 }
12656  	 	 // name tree for javascript
12657  	 	 $this->n_js = '<< /Names [';
12658  	 	 if (!empty($this->javascript)) {
12659  	 	 	 $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
12660  	 	 }
12661  	 	 if (!empty($this->js_objects)) {
12662  	 	 	 foreach ($this->js_objects as $key => $val) {
12663  	 	 	 	 if ($val['onload']) {
12664  	 	 	 	 	 $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
12665  	 	 	 	 }
12666  	 	 	 }
12667  	 	 }
12668  	 	 $this->n_js .= ' ] >>';
12669  	 	 // default Javascript object
12670  	 	 if (!empty($this->javascript)) {
12671  	 	 	 $obj_id = $this->_newobj();
12672  	 	 	 $out = '<< /S /JavaScript';
12673  	 	 	 $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
12674  	 	 	 $out .= ' >>';
12675  	 	 	 $out .= "\n".'endobj';
12676  	 	 	 $this->_out($out);
12677  	 	 }
12678  	 	 // additional Javascript objects
12679  	 	 if (!empty($this->js_objects)) {
12680  	 	 	 foreach ($this->js_objects as $key => $val) {
12681  	 	 	 	 $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
12682  	 	 	 	 $this->_out($out);
12683  	 	 	 }
12684  	 	 }
12685  	 }
12686  
12687  	 /**
12688  	  * Adds a javascript form field.
12689  	  * @param string $type field type
12690  	  * @param string $name field name
12691  	  * @param int $x horizontal position
12692  	  * @param int $y vertical position
12693  	  * @param int $w width
12694  	  * @param int $h height
12695  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12696  	  * @protected
12697  	  * @author Denis Van Nuffelen, Nicola Asuni
12698  	  * @since 2.1.002 (2008-02-12)
12699  	  */
12700  	protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
12701  	 	 if ($this->rtl) {
12702  	 	 	 $x = $x - $w;
12703  	 	 }
12704  	 	 // the followind avoid fields duplication after saving the document
12705  	 	 $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
12706  	 	 $k = $this->k;
12707  	 	 $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";
12708  	 	 $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
12709  	 	 foreach($prop as $key => $val) {
12710  	 	 	 if (strcmp(substr($key, -5), 'Color') == 0) {
12711  	 	 	 	 $val = TCPDF_COLORS::_JScolor($val);
12712  	 	 	 } else {
12713  	 	 	 	 $val = "'".$val."'";
12714  	 	 	 }
12715  	 	 	 $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
12716  	 	 }
12717  	 	 if ($this->rtl) {
12718  	 	 	 $this->x -= $w;
12719  	 	 } else {
12720  	 	 	 $this->x += $w;
12721  	 	 }
12722  	 	 $this->javascript .= '}';
12723  	 }
12724  
12725  	 // --- FORM FIELDS -----------------------------------------------------
12726  
12727  
12728  
12729  	 /**
12730  	  * Set default properties for form fields.
12731  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12732  	  * @public
12733  	  * @author Nicola Asuni
12734  	  * @since 4.8.000 (2009-09-06)
12735  	  */
12736  	public function setFormDefaultProp($prop=array()) {
12737  	 	 $this->default_form_prop = $prop;
12738  	 }
12739  
12740  	 /**
12741  	  * Return the default properties for form fields.
12742  	  * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12743  	  * @public
12744  	  * @author Nicola Asuni
12745  	  * @since 4.8.000 (2009-09-06)
12746  	  */
12747  	public function getFormDefaultProp() {
12748  	 	 return $this->default_form_prop;
12749  	 }
12750  
12751  	 /**
12752  	  * Creates a text field
12753  	  * @param string $name field name
12754  	  * @param float $w Width of the rectangle
12755  	  * @param float $h Height of the rectangle
12756  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12757  	  * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
12758  	  * @param float|null $x Abscissa of the upper-left corner of the rectangle
12759  	  * @param float|null $y Ordinate of the upper-left corner of the rectangle
12760  	  * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
12761  	  * @public
12762  	  * @author Nicola Asuni
12763  	  * @since 4.8.000 (2009-09-07)
12764  	  */
12765  	public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
12766  	 	 if (TCPDF_STATIC::empty_string($x)) {
12767  	 	 	 $x = $this->x;
12768  	 	 }
12769  	 	 if (TCPDF_STATIC::empty_string($y)) {
12770  	 	 	 $y = $this->y;
12771  	 	 }
12772  	 	 // check page for no-write regions and adapt page margins if necessary
12773  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
12774  	 	 if ($js) {
12775  	 	 	 $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
12776  	 	 	 return;
12777  	 	 }
12778  	 	 // get default style
12779  	 	 $prop = array_merge($this->getFormDefaultProp(), $prop);
12780  	 	 // get annotation data
12781  	 	 $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
12782  	 	 // set default appearance stream
12783  	 	 $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
12784  	 	 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
12785  	 	 $popt['da'] = $fontstyle;
12786  	 	 // build appearance stream
12787  	 	 $popt['ap'] = array();
12788  	 	 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
12789  	 	 $text = '';
12790  	 	 if (isset($prop['value']) AND !empty($prop['value'])) {
12791  	 	 	 $text = $prop['value'];
12792  	 	 } elseif (isset($opt['v']) AND !empty($opt['v'])) {
12793  	 	 	 $text = $opt['v'];
12794  	 	 }
12795  	 	 $tmpid = $this->startTemplate($w, $h, false);
12796  	 	 $align = '';
12797  	 	 if (isset($popt['q'])) {
12798  	 	 	 switch ($popt['q']) {
12799  	 	 	 	 case 0: {
12800  	 	 	 	 	 $align = 'L';
12801  	 	 	 	 	 break;
12802  	 	 	 	 }
12803  	 	 	 	 case 1: {
12804  	 	 	 	 	 $align = 'C';
12805  	 	 	 	 	 break;
12806  	 	 	 	 }
12807  	 	 	 	 case 2: {
12808  	 	 	 	 	 $align = 'R';
12809  	 	 	 	 	 break;
12810  	 	 	 	 }
12811  	 	 	 	 default: {
12812  	 	 	 	 	 $align = '';
12813  	 	 	 	 	 break;
12814  	 	 	 	 }
12815  	 	 	 }
12816  	 	 }
12817  	 	 $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
12818  	 	 $this->endTemplate();
12819  	 	 --$this->n;
12820  	 	 $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
12821  	 	 unset($this->xobjects[$tmpid]);
12822  	 	 $popt['ap']['n'] .= 'Q EMC';
12823  	 	 // merge options
12824  	 	 $opt = array_merge($popt, $opt);
12825  	 	 // remove some conflicting options
12826  	 	 unset($opt['bs']);
12827  	 	 // set remaining annotation data
12828  	 	 $opt['Subtype'] = 'Widget';
12829  	 	 $opt['ft'] = 'Tx';
12830  	 	 $opt['t'] = $name;
12831  	 	 // Additional annotation's parameters (check _putannotsobj() method):
12832  	 	 //$opt['f']
12833  	 	 //$opt['as']
12834  	 	 //$opt['bs']
12835  	 	 //$opt['be']
12836  	 	 //$opt['c']
12837  	 	 //$opt['border']
12838  	 	 //$opt['h']
12839  	 	 //$opt['mk'];
12840  	 	 //$opt['mk']['r']
12841  	 	 //$opt['mk']['bc'];
12842  	 	 //$opt['mk']['bg'];
12843  	 	 unset($opt['mk']['ca']);
12844  	 	 unset($opt['mk']['rc']);
12845  	 	 unset($opt['mk']['ac']);
12846  	 	 unset($opt['mk']['i']);
12847  	 	 unset($opt['mk']['ri']);
12848  	 	 unset($opt['mk']['ix']);
12849  	 	 unset($opt['mk']['if']);
12850  	 	 //$opt['mk']['if']['sw'];
12851  	 	 //$opt['mk']['if']['s'];
12852  	 	 //$opt['mk']['if']['a'];
12853  	 	 //$opt['mk']['if']['fb'];
12854  	 	 unset($opt['mk']['tp']);
12855  	 	 //$opt['tu']
12856  	 	 //$opt['tm']
12857  	 	 //$opt['ff']
12858  	 	 //$opt['v']
12859  	 	 //$opt['dv']
12860  	 	 //$opt['a']
12861  	 	 //$opt['aa']
12862  	 	 //$opt['q']
12863  	 	 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
12864  	 	 if ($this->rtl) {
12865  	 	 	 $this->x -= $w;
12866  	 	 } else {
12867  	 	 	 $this->x += $w;
12868  	 	 }
12869  	 }
12870  
12871  	 /**
12872  	  * Creates a RadioButton field.
12873  	  * @param string $name Field name.
12874  	  * @param int $w Width of the radio button.
12875  	  * @param array $prop Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12876  	  * @param array $opt Annotation parameters. Possible values are described on official PDF32000_2008 reference.
12877  	  * @param string $onvalue Value to be returned if selected.
12878  	  * @param boolean $checked Define the initial state.
12879  	  * @param float|null $x Abscissa of the upper-left corner of the rectangle
12880  	  * @param float|null $y Ordinate of the upper-left corner of the rectangle
12881  	  * @param boolean $js If true put the field using JavaScript (requires Acrobat Writer to be rendered).
12882  	  * @public
12883  	  * @author Nicola Asuni
12884  	  * @since 4.8.000 (2009-09-07)
12885  	  */
12886  	public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x=null, $y=null, $js=false) {
12887  	 	 if (TCPDF_STATIC::empty_string($x)) {
12888  	 	 	 $x = $this->x;
12889  	 	 }
12890  	 	 if (TCPDF_STATIC::empty_string($y)) {
12891  	 	 	 $y = $this->y;
12892  	 	 }
12893  	 	 // check page for no-write regions and adapt page margins if necessary
12894  	 	 list($x, $y) = $this->checkPageRegions($w, $x, $y);
12895  	 	 if ($js) {
12896  	 	 	 $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
12897  	 	 	 return;
12898  	 	 }
12899  	 	 if (TCPDF_STATIC::empty_string($onvalue)) {
12900  	 	 	 $onvalue = 'On';
12901  	 	 }
12902  	 	 if ($checked) {
12903  	 	 	 $defval = $onvalue;
12904  	 	 } else {
12905  	 	 	 $defval = 'Off';
12906  	 	 }
12907  	 	 // set font
12908  	 	 $font = 'zapfdingbats';
12909  	 	 if ($this->pdfa_mode) {
12910  	 	 	 // all fonts must be embedded
12911  	 	 	 $font = 'pdfa'.$font;
12912  	 	 }
12913  	 	 $this->AddFont($font);
12914  	 	 $tmpfont = $this->getFontBuffer($font);
12915  	 	 // set data for parent group
12916  	 	 if (!isset($this->radiobutton_groups[$this->page])) {
12917  	 	 	 $this->radiobutton_groups[$this->page] = array();
12918  	 	 }
12919  	 	 if (!isset($this->radiobutton_groups[$this->page][$name])) {
12920  	 	 	 $this->radiobutton_groups[$this->page][$name] = array();
12921  	 	 	 ++$this->n;
12922  	 	 	 $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
12923  	 	 	 $this->radio_groups[] = $this->n;
12924  	 	 }
12925  	 	 $kid = ($this->n + 1);
12926  	 	 // save object ID to be added on Kids entry on parent object
12927  	 	 $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
12928  	 	 // get default style
12929  	 	 $prop = array_merge($this->getFormDefaultProp(), $prop);
12930  	 	 $prop['NoToggleToOff'] = 'true';
12931  	 	 $prop['Radio'] = 'true';
12932  	 	 $prop['borderStyle'] = 'inset';
12933  	 	 // get annotation data
12934  	 	 $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
12935  	 	 // set additional default options
12936  	 	 $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
12937  	 	 $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
12938  	 	 $popt['da'] = $fontstyle;
12939  	 	 // build appearance stream
12940  	 	 $popt['ap'] = array();
12941  	 	 $popt['ap']['n'] = array();
12942  	 	 $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
12943  	 	 $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
12944  	 	 $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);
12945  	 	 $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);
12946  	 	 if (!isset($popt['mk'])) {
12947  	 	 	 $popt['mk'] = array();
12948  	 	 }
12949  	 	 $popt['mk']['ca'] = '(l)';
12950  	 	 // merge options
12951  	 	 $opt = array_merge($popt, $opt);
12952  	 	 // set remaining annotation data
12953  	 	 $opt['Subtype'] = 'Widget';
12954  	 	 $opt['ft'] = 'Btn';
12955  	 	 if ($checked) {
12956  	 	 	 $opt['v'] = array('/'.$onvalue);
12957  	 	 	 $opt['as'] = $onvalue;
12958  	 	 } else {
12959  	 	 	 $opt['as'] = 'Off';
12960  	 	 }
12961  	 	 // store readonly flag
12962  	 	 if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
12963  	 	 	 $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
12964  	 	 }
12965  	 	 $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
12966  	 	 $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
12967  	 	 if ($this->rtl) {
12968  	 	 	 $this->x -= $w;
12969  	 	 } else {
12970  	 	 	 $this->x += $w;
12971  	 	 }
12972  	 }
12973  
12974  	 /**
12975  	  * Creates a List-box field
12976  	  * @param string $name field name
12977  	  * @param int $w width
12978  	  * @param int $h height
12979  	  * @param array $values array containing the list of values.
12980  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12981  	  * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
12982  	  * @param float|null $x Abscissa of the upper-left corner of the rectangle
12983  	  * @param float|null $y Ordinate of the upper-left corner of the rectangle
12984  	  * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
12985  	  * @public
12986  	  * @author Nicola Asuni
12987  	  * @since 4.8.000 (2009-09-07)
12988  	  */
12989  	public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
12990  	 	 if (TCPDF_STATIC::empty_string($x)) {
12991  	 	 	 $x = $this->x;
12992  	 	 }
12993  	 	 if (TCPDF_STATIC::empty_string($y)) {
12994  	 	 	 $y = $this->y;
12995  	 	 }
12996  	 	 // check page for no-write regions and adapt page margins if necessary
12997  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
12998  	 	 if ($js) {
12999  	 	 	 $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
13000  	 	 	 $s = '';
13001  	 	 	 foreach ($values as $value) {
13002  	 	 	 	 if (is_array($value)) {
13003  	 	 	 	 	 $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
13004  	 	 	 	 } else {
13005  	 	 	 	 	 $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
13006  	 	 	 	 }
13007  	 	 	 }
13008  	 	 	 $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
13009  	 	 	 return;
13010  	 	 }
13011  	 	 // get default style
13012  	 	 $prop = array_merge($this->getFormDefaultProp(), $prop);
13013  	 	 // get annotation data
13014  	 	 $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
13015  	 	 // set additional default values
13016  	 	 $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
13017  	 	 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
13018  	 	 $popt['da'] = $fontstyle;
13019  	 	 // build appearance stream
13020  	 	 $popt['ap'] = array();
13021  	 	 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
13022  	 	 $text = '';
13023  	 	 foreach($values as $item) {
13024  	 	 	 if (is_array($item)) {
13025  	 	 	 	 $text .= $item[1]."\n";
13026  	 	 	 } else {
13027  	 	 	 	 $text .= $item."\n";
13028  	 	 	 }
13029  	 	 }
13030  	 	 $tmpid = $this->startTemplate($w, $h, false);
13031  	 	 $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
13032  	 	 $this->endTemplate();
13033  	 	 --$this->n;
13034  	 	 $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
13035  	 	 unset($this->xobjects[$tmpid]);
13036  	 	 $popt['ap']['n'] .= 'Q EMC';
13037  	 	 // merge options
13038  	 	 $opt = array_merge($popt, $opt);
13039  	 	 // set remaining annotation data
13040  	 	 $opt['Subtype'] = 'Widget';
13041  	 	 $opt['ft'] = 'Ch';
13042  	 	 $opt['t'] = $name;
13043  	 	 $opt['opt'] = $values;
13044  	 	 unset($opt['mk']['ca']);
13045  	 	 unset($opt['mk']['rc']);
13046  	 	 unset($opt['mk']['ac']);
13047  	 	 unset($opt['mk']['i']);
13048  	 	 unset($opt['mk']['ri']);
13049  	 	 unset($opt['mk']['ix']);
13050  	 	 unset($opt['mk']['if']);
13051  	 	 unset($opt['mk']['tp']);
13052  	 	 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
13053  	 	 if ($this->rtl) {
13054  	 	 	 $this->x -= $w;
13055  	 	 } else {
13056  	 	 	 $this->x += $w;
13057  	 	 }
13058  	 }
13059  
13060  	 /**
13061  	  * Creates a Combo-box field
13062  	  * @param string $name field name
13063  	  * @param int $w width
13064  	  * @param int $h height
13065  	  * @param array $values array containing the list of values.
13066  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
13067  	  * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
13068  	  * @param float|null $x Abscissa of the upper-left corner of the rectangle
13069  	  * @param float|null $y Ordinate of the upper-left corner of the rectangle
13070  	  * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
13071  	  * @public
13072  	  * @author Nicola Asuni
13073  	  * @since 4.8.000 (2009-09-07)
13074  	  */
13075  	public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
13076  	 	 if (TCPDF_STATIC::empty_string($x)) {
13077  	 	 	 $x = $this->x;
13078  	 	 }
13079  	 	 if (TCPDF_STATIC::empty_string($y)) {
13080  	 	 	 $y = $this->y;
13081  	 	 }
13082  	 	 // check page for no-write regions and adapt page margins if necessary
13083  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
13084  	 	 if ($js) {
13085  	 	 	 $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
13086  	 	 	 $s = '';
13087  	 	 	 foreach ($values as $value) {
13088  	 	 	 	 if (is_array($value)) {
13089  	 	 	 	 	 $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
13090  	 	 	 	 } else {
13091  	 	 	 	 	 $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
13092  	 	 	 	 }
13093  	 	 	 }
13094  	 	 	 $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
13095  	 	 	 return;
13096  	 	 }
13097  	 	 // get default style
13098  	 	 $prop = array_merge($this->getFormDefaultProp(), $prop);
13099  	 	 $prop['Combo'] = true;
13100  	 	 // get annotation data
13101  	 	 $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
13102  	 	 // set additional default options
13103  	 	 $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
13104  	 	 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
13105  	 	 $popt['da'] = $fontstyle;
13106  	 	 // build appearance stream
13107  	 	 $popt['ap'] = array();
13108  	 	 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
13109  	 	 $text = '';
13110  	 	 foreach($values as $item) {
13111  	 	 	 if (is_array($item)) {
13112  	 	 	 	 $text .= $item[1]."\n";
13113  	 	 	 } else {
13114  	 	 	 	 $text .= $item."\n";
13115  	 	 	 }
13116  	 	 }
13117  	 	 $tmpid = $this->startTemplate($w, $h, false);
13118  	 	 $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
13119  	 	 $this->endTemplate();
13120  	 	 --$this->n;
13121  	 	 $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
13122  	 	 unset($this->xobjects[$tmpid]);
13123  	 	 $popt['ap']['n'] .= 'Q EMC';
13124  	 	 // merge options
13125  	 	 $opt = array_merge($popt, $opt);
13126  	 	 // set remaining annotation data
13127  	 	 $opt['Subtype'] = 'Widget';
13128  	 	 $opt['ft'] = 'Ch';
13129  	 	 $opt['t'] = $name;
13130  	 	 $opt['opt'] = $values;
13131  	 	 unset($opt['mk']['ca']);
13132  	 	 unset($opt['mk']['rc']);
13133  	 	 unset($opt['mk']['ac']);
13134  	 	 unset($opt['mk']['i']);
13135  	 	 unset($opt['mk']['ri']);
13136  	 	 unset($opt['mk']['ix']);
13137  	 	 unset($opt['mk']['if']);
13138  	 	 unset($opt['mk']['tp']);
13139  	 	 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
13140  	 	 if ($this->rtl) {
13141  	 	 	 $this->x -= $w;
13142  	 	 } else {
13143  	 	 	 $this->x += $w;
13144  	 	 }
13145  	 }
13146  
13147  	 /**
13148  	  * Creates a CheckBox field
13149  	  * @param string $name field name
13150  	  * @param int $w width
13151  	  * @param boolean $checked define the initial state.
13152  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
13153  	  * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
13154  	  * @param string $onvalue value to be returned if selected.
13155  	  * @param float|null $x Abscissa of the upper-left corner of the rectangle
13156  	  * @param float|null $y Ordinate of the upper-left corner of the rectangle
13157  	  * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
13158  	  * @public
13159  	  * @author Nicola Asuni
13160  	  * @since 4.8.000 (2009-09-07)
13161  	  */
13162  	public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x=null, $y=null, $js=false) {
13163  	 	 if (TCPDF_STATIC::empty_string($x)) {
13164  	 	 	 $x = $this->x;
13165  	 	 }
13166  	 	 if (TCPDF_STATIC::empty_string($y)) {
13167  	 	 	 $y = $this->y;
13168  	 	 }
13169  	 	 // check page for no-write regions and adapt page margins if necessary
13170  	 	 list($x, $y) = $this->checkPageRegions($w, $x, $y);
13171  	 	 if ($js) {
13172  	 	 	 $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
13173  	 	 	 return;
13174  	 	 }
13175  	 	 if (!isset($prop['value'])) {
13176  	 	 	 $prop['value'] = array('Yes');
13177  	 	 }
13178  	 	 // get default style
13179  	 	 $prop = array_merge($this->getFormDefaultProp(), $prop);
13180  	 	 $prop['borderStyle'] = 'inset';
13181  	 	 // get annotation data
13182  	 	 $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
13183  	 	 // set additional default options
13184  	 	 $font = 'zapfdingbats';
13185  	 	 if ($this->pdfa_mode) {
13186  	 	 	 // all fonts must be embedded
13187  	 	 	 $font = 'pdfa'.$font;
13188  	 	 }
13189  	 	 $this->AddFont($font);
13190  	 	 $tmpfont = $this->getFontBuffer($font);
13191  	 	 $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
13192  	 	 $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
13193  	 	 $popt['da'] = $fontstyle;
13194  	 	 // build appearance stream
13195  	 	 $popt['ap'] = array();
13196  	 	 $popt['ap']['n'] = array();
13197  	 	 $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
13198  	 	 $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
13199  	 	 $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);
13200  	 	 $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);
13201  	 	 // merge options
13202  	 	 $opt = array_merge($popt, $opt);
13203  	 	 // set remaining annotation data
13204  	 	 $opt['Subtype'] = 'Widget';
13205  	 	 $opt['ft'] = 'Btn';
13206  	 	 $opt['t'] = $name;
13207  	 	 if (TCPDF_STATIC::empty_string($onvalue)) {
13208  	 	 	 $onvalue = 'Yes';
13209  	 	 }
13210  	 	 $opt['opt'] = array($onvalue);
13211  	 	 if ($checked) {
13212  	 	 	 $opt['v'] = array('/Yes');
13213  	 	 	 $opt['as'] = 'Yes';
13214  	 	 } else {
13215  	 	 	 $opt['v'] = array('/Off');
13216  	 	 	 $opt['as'] = 'Off';
13217  	 	 }
13218  	 	 $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
13219  	 	 if ($this->rtl) {
13220  	 	 	 $this->x -= $w;
13221  	 	 } else {
13222  	 	 	 $this->x += $w;
13223  	 	 }
13224  	 }
13225  
13226  	 /**
13227  	  * Creates a button field
13228  	  * @param string $name field name
13229  	  * @param int $w width
13230  	  * @param int $h height
13231  	  * @param string $caption caption.
13232  	  * @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.
13233  	  * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
13234  	  * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
13235  	  * @param float|null $x Abscissa of the upper-left corner of the rectangle
13236  	  * @param float|null $y Ordinate of the upper-left corner of the rectangle
13237  	  * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
13238  	  * @public
13239  	  * @author Nicola Asuni
13240  	  * @since 4.8.000 (2009-09-07)
13241  	  */
13242  	public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x=null, $y=null, $js=false) {
13243  	 	 if (TCPDF_STATIC::empty_string($x)) {
13244  	 	 	 $x = $this->x;
13245  	 	 }
13246  	 	 if (TCPDF_STATIC::empty_string($y)) {
13247  	 	 	 $y = $this->y;
13248  	 	 }
13249  	 	 // check page for no-write regions and adapt page margins if necessary
13250  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
13251  	 	 if ($js) {
13252  	 	 	 $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
13253  	 	 	 $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
13254  	 	 	 $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
13255  	 	 	 $this->javascript .= 'f'.$name.".highlight='push';\n";
13256  	 	 	 $this->javascript .= 'f'.$name.".print=false;\n";
13257  	 	 	 return;
13258  	 	 }
13259  	 	 // get default style
13260  	 	 $prop = array_merge($this->getFormDefaultProp(), $prop);
13261  	 	 $prop['Pushbutton'] = 'true';
13262  	 	 $prop['highlight'] = 'push';
13263  	 	 $prop['display'] = 'display.noPrint';
13264  	 	 // get annotation data
13265  	 	 $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
13266  	 	 $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
13267  	 	 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
13268  	 	 $popt['da'] = $fontstyle;
13269  	 	 // build appearance stream
13270  	 	 $popt['ap'] = array();
13271  	 	 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
13272  	 	 $tmpid = $this->startTemplate($w, $h, false);
13273  	 	 $bw = (2 / $this->k); // border width
13274  	 	 $border = array(
13275  	 	 	 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
13276  	 	 	 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
13277  	 	 	 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
13278  	 	 	 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
13279  	 	 $this->setFillColor(204);
13280  	 	 $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
13281  	 	 $this->endTemplate();
13282  	 	 --$this->n;
13283  	 	 $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
13284  	 	 unset($this->xobjects[$tmpid]);
13285  	 	 $popt['ap']['n'] .= 'Q EMC';
13286  	 	 // set additional default options
13287  	 	 if (!isset($popt['mk'])) {
13288  	 	 	 $popt['mk'] = array();
13289  	 	 }
13290  	 	 $ann_obj_id = ($this->n + 1);
13291  	 	 if (!empty($action) AND !is_array($action)) {
13292  	 	 	 $ann_obj_id = ($this->n + 2);
13293  	 	 }
13294  	 	 $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
13295  	 	 $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
13296  	 	 $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
13297  	 	 // merge options
13298  	 	 $opt = array_merge($popt, $opt);
13299  	 	 // set remaining annotation data
13300  	 	 $opt['Subtype'] = 'Widget';
13301  	 	 $opt['ft'] = 'Btn';
13302  	 	 $opt['t'] = $caption;
13303  	 	 $opt['v'] = $name;
13304  	 	 if (!empty($action)) {
13305  	 	 	 if (is_array($action)) {
13306  	 	 	 	 // form action options as on section 12.7.5 of PDF32000_2008.
13307  	 	 	 	 $opt['aa'] = '/D <<';
13308  	 	 	 	 $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
13309  	 	 	 	 foreach ($action AS $key => $val) {
13310  	 	 	 	 	 if (($key == 'S') AND in_array($val, $bmode)) {
13311  	 	 	 	 	 	 $opt['aa'] .= ' /S /'.$val;
13312  	 	 	 	 	 } elseif (($key == 'F') AND (!empty($val))) {
13313  	 	 	 	 	 	 $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
13314  	 	 	 	 	 } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
13315  	 	 	 	 	 	 $opt['aa'] .= ' /Fields [';
13316  	 	 	 	 	 	 foreach ($val AS $field) {
13317  	 	 	 	 	 	 	 $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
13318  	 	 	 	 	 	 }
13319  	 	 	 	 	 	 $opt['aa'] .= ']';
13320  	 	 	 	 	 } elseif (($key == 'Flags')) {
13321  	 	 	 	 	 	 $ff = 0;
13322  	 	 	 	 	 	 if (is_array($val)) {
13323  	 	 	 	 	 	 	 foreach ($val AS $flag) {
13324  	 	 	 	 	 	 	 	 switch ($flag) {
13325  	 	 	 	 	 	 	 	 	 case 'Include/Exclude': {
13326  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 0;
13327  	 	 	 	 	 	 	 	 	 	 break;
13328  	 	 	 	 	 	 	 	 	 }
13329  	 	 	 	 	 	 	 	 	 case 'IncludeNoValueFields': {
13330  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 1;
13331  	 	 	 	 	 	 	 	 	 	 break;
13332  	 	 	 	 	 	 	 	 	 }
13333  	 	 	 	 	 	 	 	 	 case 'ExportFormat': {
13334  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 2;
13335  	 	 	 	 	 	 	 	 	 	 break;
13336  	 	 	 	 	 	 	 	 	 }
13337  	 	 	 	 	 	 	 	 	 case 'GetMethod': {
13338  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 3;
13339  	 	 	 	 	 	 	 	 	 	 break;
13340  	 	 	 	 	 	 	 	 	 }
13341  	 	 	 	 	 	 	 	 	 case 'SubmitCoordinates': {
13342  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 4;
13343  	 	 	 	 	 	 	 	 	 	 break;
13344  	 	 	 	 	 	 	 	 	 }
13345  	 	 	 	 	 	 	 	 	 case 'XFDF': {
13346  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 5;
13347  	 	 	 	 	 	 	 	 	 	 break;
13348  	 	 	 	 	 	 	 	 	 }
13349  	 	 	 	 	 	 	 	 	 case 'IncludeAppendSaves': {
13350  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 6;
13351  	 	 	 	 	 	 	 	 	 	 break;
13352  	 	 	 	 	 	 	 	 	 }
13353  	 	 	 	 	 	 	 	 	 case 'IncludeAnnotations': {
13354  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 7;
13355  	 	 	 	 	 	 	 	 	 	 break;
13356  	 	 	 	 	 	 	 	 	 }
13357  	 	 	 	 	 	 	 	 	 case 'SubmitPDF': {
13358  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 8;
13359  	 	 	 	 	 	 	 	 	 	 break;
13360  	 	 	 	 	 	 	 	 	 }
13361  	 	 	 	 	 	 	 	 	 case 'CanonicalFormat': {
13362  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 9;
13363  	 	 	 	 	 	 	 	 	 	 break;
13364  	 	 	 	 	 	 	 	 	 }
13365  	 	 	 	 	 	 	 	 	 case 'ExclNonUserAnnots': {
13366  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 10;
13367  	 	 	 	 	 	 	 	 	 	 break;
13368  	 	 	 	 	 	 	 	 	 }
13369  	 	 	 	 	 	 	 	 	 case 'ExclFKey': {
13370  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 11;
13371  	 	 	 	 	 	 	 	 	 	 break;
13372  	 	 	 	 	 	 	 	 	 }
13373  	 	 	 	 	 	 	 	 	 case 'EmbedForm': {
13374  	 	 	 	 	 	 	 	 	 	 $ff += 1 << 13;
13375  	 	 	 	 	 	 	 	 	 	 break;
13376  	 	 	 	 	 	 	 	 	 }
13377  	 	 	 	 	 	 	 	 }
13378  	 	 	 	 	 	 	 }
13379  	 	 	 	 	 	 } else {
13380  	 	 	 	 	 	 	 $ff = intval($val);
13381  	 	 	 	 	 	 }
13382  	 	 	 	 	 	 $opt['aa'] .= ' /Flags '.$ff;
13383  	 	 	 	 	 }
13384  	 	 	 	 }
13385  	 	 	 	 $opt['aa'] .= ' >>';
13386  	 	 	 } else {
13387  	 	 	 	 // Javascript action or raw action command
13388  	 	 	 	 $js_obj_id = $this->addJavascriptObject($action);
13389  	 	 	 	 $opt['aa'] = '/D '.$js_obj_id.' 0 R';
13390  	 	 	 }
13391  	 	 }
13392  	 	 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
13393  	 	 if ($this->rtl) {
13394  	 	 	 $this->x -= $w;
13395  	 	 } else {
13396  	 	 	 $this->x += $w;
13397  	 	 }
13398  	 }
13399  
13400  	 // --- END FORMS FIELDS ------------------------------------------------
13401  
13402  	 /**
13403  	  * Add certification signature (DocMDP or UR3)
13404  	  * You can set only one signature type
13405  	  * @protected
13406  	  * @author Nicola Asuni
13407  	  * @since 4.6.008 (2009-05-07)
13408  	  */
13409  	protected function _putsignature() {
13410  	 	 if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
13411  	 	 	 return;
13412  	 	 }
13413  	 	 $sigobjid = ($this->sig_obj_id + 1);
13414  	 	 $out = $this->_getobj($sigobjid)."\n";
13415  	 	 $out .= '<< /Type /Sig';
13416  	 	 $out .= ' /Filter /Adobe.PPKLite';
13417  	 	 $out .= ' /SubFilter /adbe.pkcs7.detached';
13418  	 	 $out .= ' '.TCPDF_STATIC::$byterange_string;
13419  	 	 $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
13420  	 	 if (empty($this->signature_data['approval']) OR ($this->signature_data['approval'] != 'A')) {
13421  	 	 	 $out .= ' /Reference ['; // array of signature reference dictionaries
13422  	 	 	 $out .= ' << /Type /SigRef';
13423  	 	 	 if ($this->signature_data['cert_type'] > 0) {
13424  	 	 	 	 $out .= ' /TransformMethod /DocMDP';
13425  	 	 	 	 $out .= ' /TransformParams <<';
13426  	 	 	 	 $out .= ' /Type /TransformParams';
13427  	 	 	 	 $out .= ' /P '.$this->signature_data['cert_type'];
13428  	 	 	 	 $out .= ' /V /1.2';
13429  	 	 	 } else {
13430  	 	 	 	 $out .= ' /TransformMethod /UR3';
13431  	 	 	 	 $out .= ' /TransformParams <<';
13432  	 	 	 	 $out .= ' /Type /TransformParams';
13433  	 	 	 	 $out .= ' /V /2.2';
13434  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
13435  	 	 	 	 	 $out .= ' /Document['.$this->ur['document'].']';
13436  	 	 	 	 }
13437  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
13438  	 	 	 	 	 $out .= ' /Form['.$this->ur['form'].']';
13439  	 	 	 	 }
13440  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
13441  	 	 	 	 	 $out .= ' /Signature['.$this->ur['signature'].']';
13442  	 	 	 	 }
13443  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
13444  	 	 	 	 	 $out .= ' /Annots['.$this->ur['annots'].']';
13445  	 	 	 	 }
13446  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
13447  	 	 	 	 	 $out .= ' /EF['.$this->ur['ef'].']';
13448  	 	 	 	 }
13449  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
13450  	 	 	 	 	 $out .= ' /FormEX['.$this->ur['formex'].']';
13451  	 	 	 	 }
13452  	 	 	 }
13453  	 	 	 $out .= ' >>'; // close TransformParams
13454  	 	 	 // optional digest data (values must be calculated and replaced later)
13455  	 	 	 //$out .= ' /Data ********** 0 R';
13456  	 	 	 //$out .= ' /DigestMethod/MD5';
13457  	 	 	 //$out .= ' /DigestLocation[********** 34]';
13458  	 	 	 //$out .= ' /DigestValue<********************************>';
13459  	 	 	 $out .= ' >>';
13460  	 	 	 $out .= ' ]'; // end of reference
13461  	 	 }
13462  	 	 if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
13463  	 	 	 $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
13464  	 	 }
13465  	 	 if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
13466  	 	 	 $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
13467  	 	 }
13468  	 	 if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
13469  	 	 	 $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
13470  	 	 }
13471  	 	 if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
13472  	 	 	 $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
13473  	 	 }
13474  	 	 $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
13475  	 	 $out .= ' >>';
13476  	 	 $out .= "\n".'endobj';
13477  	 	 $this->_out($out);
13478  	 }
13479  
13480  	 /**
13481  	  * Set User's Rights for PDF Reader
13482  	  * WARNING: This is experimental and currently do not work.
13483  	  * Check the PDF Reference 8.7.1 Transform Methods,
13484  	  * Table 8.105 Entries in the UR transform parameters dictionary
13485  	  * @param boolean $enable if true enable user's rights on PDF reader
13486  	  * @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.
13487  	  * @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.
13488  	  * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
13489  	  * @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.
13490  	  * @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
13491  	  Names specifying additional embedded-files-related usage rights for the document.
13492  	  * @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.
13493  	  * @public
13494  	  * @author Nicola Asuni
13495  	  * @since 2.9.000 (2008-03-26)
13496  	  */
13497  	public function setUserRights(
13498  	 	 	 $enable=true,
13499  	 	 	 $document='/FullSave',
13500  	 	 	 $annots='/Create/Delete/Modify/Copy/Import/Export',
13501  	 	 	 $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
13502  	 	 	 $signature='/Modify',
13503  	 	 	 $ef='/Create/Delete/Modify/Import',
13504  	 	 	 $formex='') {
13505  	 	 $this->ur['enabled'] = $enable;
13506  	 	 $this->ur['document'] = $document;
13507  	 	 $this->ur['annots'] = $annots;
13508  	 	 $this->ur['form'] = $form;
13509  	 	 $this->ur['signature'] = $signature;
13510  	 	 $this->ur['ef'] = $ef;
13511  	 	 $this->ur['formex'] = $formex;
13512  	 	 if (!$this->sign) {
13513  	 	 	 $this->setSignature('', '', '', '', 0, array());
13514  	 	 }
13515  	 }
13516  
13517  	 /**
13518  	  * Enable document signature (requires the OpenSSL Library).
13519  	  * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
13520  	  * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
13521  	  * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
13522  	  * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
13523  	  * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
13524  	  * @param mixed $private_key private key (string or filename prefixed with 'file://')
13525  	  * @param string $private_key_password password
13526  	  * @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.
13527  	  * @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.
13528  	  * @param array $info array of option information: Name, Location, Reason, ContactInfo.
13529  	  * @param string $approval Enable approval signature eg. for PDF incremental update
13530  	  * @public
13531  	  * @author Nicola Asuni
13532  	  * @since 4.6.005 (2009-04-24)
13533  	  */
13534  	public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') {
13535  	 	 // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
13536  	 	 // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
13537  	 	 // to convert pfx certificate to pem: openssl
13538  	 	 //     OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
13539  	 	 $this->sign = true;
13540  	 	 ++$this->n;
13541  	 	 $this->sig_obj_id = $this->n; // signature widget
13542  	 	 ++$this->n; // signature object ($this->sig_obj_id + 1)
13543  	 	 $this->signature_data = array();
13544  	 	 if (strlen($signing_cert) == 0) {
13545  	 	 	 $this->Error('Please provide a certificate file and password!');
13546  	 	 }
13547  	 	 if (strlen($private_key) == 0) {
13548  	 	 	 $private_key = $signing_cert;
13549  	 	 }
13550  	 	 $this->signature_data['signcert'] = $signing_cert;
13551  	 	 $this->signature_data['privkey'] = $private_key;
13552  	 	 $this->signature_data['password'] = $private_key_password;
13553  	 	 $this->signature_data['extracerts'] = $extracerts;
13554  	 	 $this->signature_data['cert_type'] = $cert_type;
13555  	 	 $this->signature_data['info'] = $info;
13556  	 	 $this->signature_data['approval'] = $approval;
13557  	 }
13558  
13559  	 /**
13560  	  * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
13561  	  * @param float $x Abscissa of the upper-left corner.
13562  	  * @param float $y Ordinate of the upper-left corner.
13563  	  * @param float $w Width of the signature area.
13564  	  * @param float $h Height of the signature area.
13565  	  * @param int $page option page number (if < 0 the current page is used).
13566  	  * @param string $name Name of the signature.
13567  	  * @public
13568  	  * @author Nicola Asuni
13569  	  * @since 5.3.011 (2010-06-17)
13570  	  */
13571  	public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
13572  	 	 $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
13573  	 }
13574  
13575  	 /**
13576  	  * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
13577  	  * @param float $x Abscissa of the upper-left corner.
13578  	  * @param float $y Ordinate of the upper-left corner.
13579  	  * @param float $w Width of the signature area.
13580  	  * @param float $h Height of the signature area.
13581  	  * @param int $page option page number (if < 0 the current page is used).
13582  	  * @param string $name Name of the signature.
13583  	  * @public
13584  	  * @author Nicola Asuni
13585  	  * @since 5.9.101 (2011-07-06)
13586  	  */
13587  	public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
13588  	 	 ++$this->n;
13589  	 	 $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
13590  	 }
13591  
13592  	 /**
13593  	  * Get the array that defines the signature appearance (page and rectangle coordinates).
13594  	  * @param float $x Abscissa of the upper-left corner.
13595  	  * @param float $y Ordinate of the upper-left corner.
13596  	  * @param float $w Width of the signature area.
13597  	  * @param float $h Height of the signature area.
13598  	  * @param int $page option page number (if < 0 the current page is used).
13599  	  * @param string $name Name of the signature.
13600  	  * @return array Array defining page and rectangle coordinates of signature appearance.
13601  	  * @protected
13602  	  * @author Nicola Asuni
13603  	  * @since 5.9.101 (2011-07-06)
13604  	  */
13605  	protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
13606  	 	 $sigapp = array();
13607  	 	 if (($page < 1) OR ($page > $this->numpages)) {
13608  	 	 	 $sigapp['page'] = $this->page;
13609  	 	 } else {
13610  	 	 	 $sigapp['page'] = intval($page);
13611  	 	 }
13612  	 	 if (empty($name)) {
13613  	 	 	 $sigapp['name'] = 'Signature';
13614  	 	 } else {
13615  	 	 	 $sigapp['name'] = $name;
13616  	 	 }
13617  	 	 $a = $x * $this->k;
13618  	 	 $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
13619  	 	 $c = $w * $this->k;
13620  	 	 $d = $h * $this->k;
13621  	 	 $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
13622  	 	 return $sigapp;
13623  	 }
13624  
13625  	 /**
13626  	  * Enable document timestamping (requires the OpenSSL Library).
13627  	  * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
13628  	  * Use with digital signature only!
13629  	  * @param string $tsa_host Time Stamping Authority (TSA) server (prefixed with 'https://')
13630  	  * @param string $tsa_username Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
13631  	  * @param string $tsa_password Specifies the password for TSA authorization (optional)
13632  	  * @param string $tsa_cert Specifies the location of TSA certificate for authorization (optional for cURL)
13633  	  * @public
13634  	  * @author Richard Stockinger
13635  	  * @since 6.0.090 (2014-06-16)
13636  	  */
13637  	public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') {
13638  	 	 $this->tsa_data = array();
13639  	 	 if (!function_exists('curl_init')) {
13640  	 	 	 $this->Error('Please enable cURL PHP extension!');
13641  	 	 }
13642  	 	 if (strlen($tsa_host) == 0) {
13643  	 	 	 $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
13644  	 	 }
13645  	 	 $this->tsa_data['tsa_host'] = $tsa_host;
13646  	 	 if (is_file($tsa_username)) {
13647  	 	 	 $this->tsa_data['tsa_auth'] = $tsa_username;
13648  	 	 } else {
13649  	 	 	 $this->tsa_data['tsa_username'] = $tsa_username;
13650  	 	 }
13651  	 	 $this->tsa_data['tsa_password'] = $tsa_password;
13652  	 	 $this->tsa_data['tsa_cert'] = $tsa_cert;
13653  	 	 $this->tsa_timestamp = true;
13654  	 }
13655  
13656  	 /**
13657  	  * NOT YET IMPLEMENTED
13658  	  * Request TSA for a timestamp
13659  	  * @param string $signature Digital signature as binary string
13660  	  * @return string Timestamped digital signature
13661  	  * @protected
13662  	  * @author Richard Stockinger
13663  	  * @since 6.0.090 (2014-06-16)
13664  	  */
13665  	protected function applyTSA($signature) {
13666  	 	 if (!$this->tsa_timestamp) {
13667  	 	 	 return $signature;
13668  	 	 }
13669  	 	 //@TODO: implement this feature
13670  	 	 return $signature;
13671  	 }
13672  
13673  	 /**
13674  	  * Create a new page group.
13675  	  * NOTE: call this function before calling AddPage()
13676  	  * @param int|null $page starting group page (leave empty for next page).
13677  	  * @public
13678  	  * @since 3.0.000 (2008-03-27)
13679  	  */
13680  	public function startPageGroup($page=null) {
13681  	 	 if (empty($page)) {
13682  	 	 	 $page = $this->page + 1;
13683  	 	 }
13684  	 	 $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
13685  	 }
13686  
13687  	 /**
13688  	  * Set the starting page number.
13689  	  * @param int $num Starting page number.
13690  	  * @since 5.9.093 (2011-06-16)
13691  	  * @public
13692  	  */
13693  	public function setStartingPageNumber($num=1) {
13694  	 	 $this->starting_page_number = max(0, intval($num));
13695  	 }
13696  
13697  	 /**
13698  	  * Returns the string alias used right align page numbers.
13699  	  * If the current font is unicode type, the returned string wil contain an additional open curly brace.
13700  	  * @return string
13701  	  * @since 5.9.099 (2011-06-27)
13702  	  * @public
13703  	  */
13704  	public function getAliasRightShift() {
13705  	 	 // calculate aproximatively the ratio between widths of aliases and replacements.
13706  	 	 $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
13707  	 	 $rep = str_repeat(' ', $this->GetNumChars($ref));
13708  	 	 $wrep = $this->GetStringWidth($rep);
13709  	 	 if ($wrep > 0) {
13710  	 	 	 $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
13711  	 	 } else {
13712  	 	 	 $wdiff = 1;
13713  	 	 }
13714  	 	 $sdiff = sprintf('%F', $wdiff);
13715  	 	 $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
13716  	 	 if ($this->isUnicodeFont()) {
13717  	 	 	 $alias = '{'.$alias;
13718  	 	 }
13719  	 	 return $alias;
13720  	 }
13721  
13722  	 /**
13723  	  * Returns the string alias used for the total number of pages.
13724  	  * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13725  	  * This alias will be replaced by the total number of pages in the document.
13726  	  * @return string
13727  	  * @since 4.0.018 (2008-08-08)
13728  	  * @public
13729  	  */
13730  	public function getAliasNbPages() {
13731  	 	 if ($this->isUnicodeFont()) {
13732  	 	 	 return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
13733  	 	 }
13734  	 	 return TCPDF_STATIC::$alias_tot_pages;
13735  	 }
13736  
13737  	 /**
13738  	  * Returns the string alias used for the page number.
13739  	  * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13740  	  * This alias will be replaced by the page number.
13741  	  * @return string
13742  	  * @since 4.5.000 (2009-01-02)
13743  	  * @public
13744  	  */
13745  	public function getAliasNumPage() {
13746  	 	 if ($this->isUnicodeFont()) {
13747  	 	 	 return '{'.TCPDF_STATIC::$alias_num_page.'}';
13748  	 	 }
13749  	 	 return TCPDF_STATIC::$alias_num_page;
13750  	 }
13751  
13752  	 /**
13753  	  * Return the alias for the total number of pages in the current page group.
13754  	  * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13755  	  * This alias will be replaced by the total number of pages in this group.
13756  	  * @return string alias of the current page group
13757  	  * @public
13758  	  * @since 3.0.000 (2008-03-27)
13759  	  */
13760  	public function getPageGroupAlias() {
13761  	 	 if ($this->isUnicodeFont()) {
13762  	 	 	 return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
13763  	 	 }
13764  	 	 return TCPDF_STATIC::$alias_group_tot_pages;
13765  	 }
13766  
13767  	 /**
13768  	  * Return the alias for the page number on the current page group.
13769  	  * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13770  	  * This alias will be replaced by the page number (relative to the belonging group).
13771  	  * @return string alias of the current page group
13772  	  * @public
13773  	  * @since 4.5.000 (2009-01-02)
13774  	  */
13775  	public function getPageNumGroupAlias() {
13776  	 	 if ($this->isUnicodeFont()) {
13777  	 	 	 return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
13778  	 	 }
13779  	 	 return TCPDF_STATIC::$alias_group_num_page;
13780  	 }
13781  
13782  	 /**
13783  	  * Return the current page in the group.
13784  	  * @return int current page in the group
13785  	  * @public
13786  	  * @since 3.0.000 (2008-03-27)
13787  	  */
13788  	public function getGroupPageNo() {
13789  	 	 return $this->pagegroups[$this->currpagegroup];
13790  	 }
13791  
13792  	 /**
13793  	  * Returns the current group page number formatted as a string.
13794  	  * @public
13795  	  * @since 4.3.003 (2008-11-18)
13796  	  * @see PaneNo(), formatPageNumber()
13797  	  */
13798  	public function getGroupPageNoFormatted() {
13799  	 	 return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
13800  	 }
13801  
13802  	 /**
13803  	  * Returns the current page number formatted as a string.
13804  	  * @public
13805  	  * @since 4.2.005 (2008-11-06)
13806  	  * @see PaneNo(), formatPageNumber()
13807  	  */
13808  	public function PageNoFormatted() {
13809  	 	 return TCPDF_STATIC::formatPageNumber($this->PageNo());
13810  	 }
13811  
13812  	 /**
13813  	  * Put pdf layers.
13814  	  * @protected
13815  	  * @since 3.0.000 (2008-03-27)
13816  	  */
13817  	protected function _putocg() {
13818  	 	 if (empty($this->pdflayers)) {
13819  	 	 	 return;
13820  	 	 }
13821  	 	 foreach ($this->pdflayers as $key => $layer) {
13822  	 	 	  $this->pdflayers[$key]['objid'] = $this->_newobj();
13823  	 	 	  $out = '<< /Type /OCG';
13824  	 	 	  $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
13825  	 	 	  $out .= ' /Usage <<';
13826  	 	 	  if (isset($layer['print']) AND ($layer['print'] !== NULL)) {
13827  	 	 	 	 $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
13828  	 	 	  }
13829  	 	 	  $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
13830  	 	 	  $out .= ' >> >>';
13831  	 	 	  $out .= "\n".'endobj';
13832  	 	 	  $this->_out($out);
13833  	 	 }
13834  	 }
13835  
13836  	 /**
13837  	  * Start a new pdf layer.
13838  	  * @param string $name Layer name (only a-z letters and numbers). Leave empty for automatic name.
13839  	  * @param boolean|null $print Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
13840  	  * @param boolean $view Set to true to view this layer.
13841  	  * @param boolean $lock If true lock the layer
13842  	  * @public
13843  	  * @since 5.9.102 (2011-07-13)
13844  	  */
13845  	public function startLayer($name='', $print=true, $view=true, $lock=true) {
13846  	 	 if ($this->state != 2) {
13847  	 	 	 return;
13848  	 	 }
13849  	 	 $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
13850  	 	 if (empty($name)) {
13851  	 	 	 $name = $layer;
13852  	 	 } else {
13853  	 	 	 $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
13854  	 	 }
13855  	 	 $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock);
13856  	 	 $this->openMarkedContent = true;
13857  	 	 $this->_out('/OC /'.$layer.' BDC');
13858  	 }
13859  
13860  	 /**
13861  	  * End the current PDF layer.
13862  	  * @public
13863  	  * @since 5.9.102 (2011-07-13)
13864  	  */
13865  	public function endLayer() {
13866  	 	 if ($this->state != 2) {
13867  	 	 	 return;
13868  	 	 }
13869  	 	 if ($this->openMarkedContent) {
13870  	 	 	 // close existing open marked-content layer
13871  	 	 	 $this->_out('EMC');
13872  	 	 	 $this->openMarkedContent = false;
13873  	 	 }
13874  	 }
13875  
13876  	 /**
13877  	  * Set the visibility of the successive elements.
13878  	  * This can be useful, for instance, to put a background
13879  	  * image or color that will show on screen but won't print.
13880  	  * @param string $v visibility mode. Legal values are: all, print, screen or view.
13881  	  * @public
13882  	  * @since 3.0.000 (2008-03-27)
13883  	  */
13884  	public function setVisibility($v) {
13885  	 	 if ($this->state != 2) {
13886  	 	 	 return;
13887  	 	 }
13888  	 	 $this->endLayer();
13889  	 	 switch($v) {
13890  	 	 	 case 'print': {
13891  	 	 	 	 $this->startLayer('Print', true, false);
13892  	 	 	 	 break;
13893  	 	 	 }
13894  	 	 	 case 'view':
13895  	 	 	 case 'screen': {
13896  	 	 	 	 $this->startLayer('View', false, true);
13897  	 	 	 	 break;
13898  	 	 	 }
13899  	 	 	 case 'all': {
13900  	 	 	 	 $this->_out('');
13901  	 	 	 	 break;
13902  	 	 	 }
13903  	 	 	 default: {
13904  	 	 	 	 $this->Error('Incorrect visibility: '.$v);
13905  	 	 	 	 break;
13906  	 	 	 }
13907  	 	 }
13908  	 }
13909  
13910  	 /**
13911  	  * Add transparency parameters to the current extgstate
13912  	  * @param array $parms parameters
13913  	  * @return int|void the number of extgstates
13914  	  * @protected
13915  	  * @since 3.0.000 (2008-03-27)
13916  	  */
13917  	protected function addExtGState($parms) {
13918  	 	 if ($this->pdfa_mode || $this->pdfa_version >= 2) {
13919  	 	 	 // transparencies are not allowed in PDF/A mode
13920  	 	 	 return;
13921  	 	 }
13922  	 	 // check if this ExtGState already exist
13923  	 	 foreach ($this->extgstates as $i => $ext) {
13924  	 	 	 if ($ext['parms'] == $parms) {
13925  	 	 	 	 if ($this->inxobj) {
13926  	 	 	 	 	 // we are inside an XObject template
13927  	 	 	 	 	 $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
13928  	 	 	 	 }
13929  	 	 	 	 // return reference to existing ExtGState
13930  	 	 	 	 return $i;
13931  	 	 	 }
13932  	 	 }
13933  	 	 $n = (count($this->extgstates) + 1);
13934  	 	 $this->extgstates[$n] = array('parms' => $parms);
13935  	 	 if ($this->inxobj) {
13936  	 	 	 // we are inside an XObject template
13937  	 	 	 $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
13938  	 	 }
13939  	 	 return $n;
13940  	 }
13941  
13942  	 /**
13943  	  * Add an extgstate
13944  	  * @param int $gs extgstate
13945  	  * @protected
13946  	  * @since 3.0.000 (2008-03-27)
13947  	  */
13948  	protected function setExtGState($gs) {
13949  	 	 if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
13950  	 	 	 // transparency is not allowed in PDF/A-1 mode
13951  	 	 	 return;
13952  	 	 }
13953  	 	 $this->_out(sprintf('/GS%d gs', $gs));
13954  	 }
13955  
13956  	 /**
13957  	  * Put extgstates for object transparency
13958  	  * @protected
13959  	  * @since 3.0.000 (2008-03-27)
13960  	  */
13961  	protected function _putextgstates() {
13962  	 	 foreach ($this->extgstates as $i => $ext) {
13963  	 	 	 $this->extgstates[$i]['n'] = $this->_newobj();
13964  	 	 	 $out = '<< /Type /ExtGState';
13965  	 	 	 foreach ($ext['parms'] as $k => $v) {
13966  	 	 	 	 if (is_float($v)) {
13967  	 	 	 	 	 $v = sprintf('%F', $v);
13968  	 	 	 	 } elseif ($v === true) {
13969  	 	 	 	 	 $v = 'true';
13970  	 	 	 	 } elseif ($v === false) {
13971  	 	 	 	 	 $v = 'false';
13972  	 	 	 	 }
13973  	 	 	 	 $out .= ' /'.$k.' '.$v;
13974  	 	 	 }
13975  	 	 	 $out .= ' >>';
13976  	 	 	 $out .= "\n".'endobj';
13977  	 	 	 $this->_out($out);
13978  	 	 }
13979  	 }
13980  
13981  	 /**
13982  	  * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
13983  	  * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
13984  	  * @param boolean $stroking If true apply overprint for stroking operations.
13985  	  * @param boolean|null $nonstroking If true apply overprint for painting operations other than stroking.
13986  	  * @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).
13987  	  * @public
13988  	  * @since 5.9.152 (2012-03-23)
13989  	  */
13990  	public function setOverprint($stroking=true, $nonstroking=null, $mode=0) {
13991  	 	 if ($this->state != 2) {
13992  	 	 	 return;
13993  	 	 }
13994  	 	 $stroking = $stroking ? true : false;
13995  	 	 if (TCPDF_STATIC::empty_string($nonstroking)) {
13996  	 	 	 // default value if not set
13997  	 	 	 $nonstroking = $stroking;
13998  	 	 } else {
13999  	 	 	 $nonstroking = $nonstroking ? true : false;
14000  	 	 }
14001  	 	 if (($mode != 0) AND ($mode != 1)) {
14002  	 	 	 $mode = 0;
14003  	 	 }
14004  	 	 $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
14005  	 	 $gs = $this->addExtGState($this->overprint);
14006  	 	 $this->setExtGState($gs);
14007  	 }
14008  
14009  	 /**
14010  	  * Get the overprint mode array (OP, op, OPM).
14011  	  * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
14012  	  * @return array<string,bool|int>
14013  	  * @public
14014  	  * @since 5.9.152 (2012-03-23)
14015  	  */
14016  	public function getOverprint() {
14017  	 	 return $this->overprint;
14018  	 }
14019  
14020  	 /**
14021  	  * Set alpha for stroking (CA) and non-stroking (ca) operations.
14022  	  * @param float $stroking Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
14023  	  * @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
14024  	  * @param float|null $nonstroking Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
14025  	  * @param boolean $ais
14026  	  * @public
14027  	  * @since 3.0.000 (2008-03-27)
14028  	  */
14029  	public function setAlpha($stroking=1, $bm='Normal', $nonstroking=null, $ais=false) {
14030  	 	 if ($this->pdfa_mode && $this->pdfa_version < 2) {
14031  	 	 	 // transparency is not allowed in PDF/A-1 mode
14032  	 	 	 return;
14033  	 	 }
14034  	 	 $stroking = floatval($stroking);
14035  	 	 if (TCPDF_STATIC::empty_string($nonstroking)) {
14036  	 	 	 // default value if not set
14037  	 	 	 $nonstroking = $stroking;
14038  	 	 } else {
14039  	 	 	 $nonstroking = floatval($nonstroking);
14040  	 	 }
14041  	 	 if ($bm[0] == '/') {
14042  	 	 	 // remove trailing slash
14043  	 	 	 $bm = substr($bm, 1);
14044  	 	 }
14045  	 	 if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
14046  	 	 	 $bm = 'Normal';
14047  	 	 }
14048  	 	 $ais = $ais ? true : false;
14049  	 	 $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
14050  	 	 $gs = $this->addExtGState($this->alpha);
14051  	 	 $this->setExtGState($gs);
14052  	 }
14053  
14054  	 /**
14055  	  * Get the alpha mode array (CA, ca, BM, AIS).
14056  	  * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
14057  	  * @return array<string,bool|string>
14058  	  * @public
14059  	  * @since 5.9.152 (2012-03-23)
14060  	  */
14061  	public function getAlpha() {
14062  	 	 return $this->alpha;
14063  	 }
14064  
14065  	 /**
14066  	  * Set the default JPEG compression quality (1-100)
14067  	  * @param int $quality JPEG quality, integer between 1 and 100
14068  	  * @public
14069  	  * @since 3.0.000 (2008-03-27)
14070  	  */
14071  	public function setJPEGQuality($quality) {
14072  	 	 if (($quality < 1) OR ($quality > 100)) {
14073  	 	 	 $quality = 75;
14074  	 	 }
14075  	 	 $this->jpeg_quality = intval($quality);
14076  	 }
14077  
14078  	 /**
14079  	  * Set the default number of columns in a row for HTML tables.
14080  	  * @param int $cols number of columns
14081  	  * @public
14082  	  * @since 3.0.014 (2008-06-04)
14083  	  */
14084  	public function setDefaultTableColumns($cols=4) {
14085  	 	 $this->default_table_columns = intval($cols);
14086  	 }
14087  
14088  	 /**
14089  	  * Set the height of the cell (line height) respect the font height.
14090  	  * @param float $h cell proportion respect font height (typical value = 1.25).
14091  	  * @public
14092  	  * @since 3.0.014 (2008-06-04)
14093  	  */
14094  	public function setCellHeightRatio($h) {
14095  	 	 $this->cell_height_ratio = $h;
14096  	 }
14097  
14098  	 /**
14099  	  * return the height of cell repect font height.
14100  	  * @public
14101  	  * @return float
14102  	  * @since 4.0.012 (2008-07-24)
14103  	  */
14104  	public function getCellHeightRatio() {
14105  	 	 return $this->cell_height_ratio;
14106  	 }
14107  
14108  	 /**
14109  	  * Set the PDF version (check PDF reference for valid values).
14110  	  * @param string $version PDF document version.
14111  	  * @public
14112  	  * @since 3.1.000 (2008-06-09)
14113  	  */
14114  	public function setPDFVersion($version='1.7') {
14115  	 	 if ($this->pdfa_mode && $this->pdfa_version == 1 ) {
14116  	 	 	 // PDF/A-1 mode
14117  	 	 	 $this->PDFVersion = '1.4';
14118  	 	 } elseif ($this->pdfa_mode && $this->pdfa_version >= 2 ) {
14119              // PDF/A-2 mode
14120              $this->PDFVersion = '1.7';
14121          } else {
14122  	 	 	 $this->PDFVersion = $version;
14123  	 	 }
14124  	 }
14125  
14126  	 /**
14127  	  * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
14128  	  * (see Section 8.1 of PDF reference, "Viewer Preferences").
14129  	  * <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>
14130  	  * @param array $preferences array of options.
14131  	  * @author Nicola Asuni
14132  	  * @public
14133  	  * @since 3.1.000 (2008-06-09)
14134  	  */
14135  	public function setViewerPreferences($preferences) {
14136  	 	 $this->viewer_preferences = $preferences;
14137  	 }
14138  
14139  	 /**
14140  	  * Paints color transition registration bars
14141  	  * @param float $x abscissa of the top left corner of the rectangle.
14142  	  * @param float $y ordinate of the top left corner of the rectangle.
14143  	  * @param float $w width of the rectangle.
14144  	  * @param float $h height of the rectangle.
14145  	  * @param boolean $transition if true prints tcolor transitions to white.
14146  	  * @param boolean $vertical if true prints bar vertically.
14147  	  * @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.
14148  	  * @author Nicola Asuni
14149  	  * @since 4.9.000 (2010-03-26)
14150  	  * @public
14151  	  */
14152  	public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
14153  	 	 if (strpos($colors, 'ALLSPOT') !== false) {
14154  	 	 	 // expand spot colors
14155  	 	 	 $spot_colors = '';
14156  	 	 	 foreach ($this->spot_colors as $spot_color_name => $v) {
14157  	 	 	 	 $spot_colors .= ','.$spot_color_name;
14158  	 	 	 }
14159  	 	 	 if (!empty($spot_colors)) {
14160  	 	 	 	 $spot_colors = substr($spot_colors, 1);
14161  	 	 	 	 $colors = str_replace('ALLSPOT', $spot_colors, $colors);
14162  	 	 	 } else {
14163  	 	 	 	 $colors = str_replace('ALLSPOT', 'NONE', $colors);
14164  	 	 	 }
14165  	 	 }
14166  	 	 $bars = explode(',', $colors);
14167  	 	 $numbars = count($bars); // number of bars to print
14168  	 	 if ($numbars <= 0) {
14169  	 	 	 return;
14170  	 	 }
14171  	 	 // set bar measures
14172  	 	 if ($vertical) {
14173  	 	 	 $coords = array(0, 0, 0, 1);
14174  	 	 	 $wb = $w / $numbars; // bar width
14175  	 	 	 $hb = $h; // bar height
14176  	 	 	 $xd = $wb; // delta x
14177  	 	 	 $yd = 0; // delta y
14178  	 	 } else {
14179  	 	 	 $coords = array(1, 0, 0, 0);
14180  	 	 	 $wb = $w; // bar width
14181  	 	 	 $hb = $h / $numbars; // bar height
14182  	 	 	 $xd = 0; // delta x
14183  	 	 	 $yd = $hb; // delta y
14184  	 	 }
14185  	 	 $xb = $x;
14186  	 	 $yb = $y;
14187  	 	 foreach ($bars as $col) {
14188  	 	 	 switch ($col) {
14189  	 	 	 	 // set transition colors
14190  	 	 	 	 case 'A': { // BLACK (GRAYSCALE)
14191  	 	 	 	 	 $col_a = array(255);
14192  	 	 	 	 	 $col_b = array(0);
14193  	 	 	 	 	 break;
14194  	 	 	 	 }
14195  	 	 	 	 case 'W': { // WHITE (GRAYSCALE)
14196  	 	 	 	 	 $col_a = array(0);
14197  	 	 	 	 	 $col_b = array(255);
14198  	 	 	 	 	 break;
14199  	 	 	 	 }
14200  	 	 	 	 case 'R': { // RED (RGB)
14201  	 	 	 	 	 $col_a = array(255,255,255);
14202  	 	 	 	 	 $col_b = array(255,0,0);
14203  	 	 	 	 	 break;
14204  	 	 	 	 }
14205  	 	 	 	 case 'G': { // GREEN (RGB)
14206  	 	 	 	 	 $col_a = array(255,255,255);
14207  	 	 	 	 	 $col_b = array(0,255,0);
14208  	 	 	 	 	 break;
14209  	 	 	 	 }
14210  	 	 	 	 case 'B': { // BLUE (RGB)
14211  	 	 	 	 	 $col_a = array(255,255,255);
14212  	 	 	 	 	 $col_b = array(0,0,255);
14213  	 	 	 	 	 break;
14214  	 	 	 	 }
14215  	 	 	 	 case 'C': { // CYAN (CMYK)
14216  	 	 	 	 	 $col_a = array(0,0,0,0);
14217  	 	 	 	 	 $col_b = array(100,0,0,0);
14218  	 	 	 	 	 break;
14219  	 	 	 	 }
14220  	 	 	 	 case 'M': { // MAGENTA (CMYK)
14221  	 	 	 	 	 $col_a = array(0,0,0,0);
14222  	 	 	 	 	 $col_b = array(0,100,0,0);
14223  	 	 	 	 	 break;
14224  	 	 	 	 }
14225  	 	 	 	 case 'Y': { // YELLOW (CMYK)
14226  	 	 	 	 	 $col_a = array(0,0,0,0);
14227  	 	 	 	 	 $col_b = array(0,0,100,0);
14228  	 	 	 	 	 break;
14229  	 	 	 	 }
14230  	 	 	 	 case 'K': { // KEY - BLACK (CMYK)
14231  	 	 	 	 	 $col_a = array(0,0,0,0);
14232  	 	 	 	 	 $col_b = array(0,0,0,100);
14233  	 	 	 	 	 break;
14234  	 	 	 	 }
14235  	 	 	 	 case 'RGB': { // BLACK REGISTRATION (RGB)
14236  	 	 	 	 	 $col_a = array(255,255,255);
14237  	 	 	 	 	 $col_b = array(0,0,0);
14238  	 	 	 	 	 break;
14239  	 	 	 	 }
14240  	 	 	 	 case 'CMYK': { // BLACK REGISTRATION (CMYK)
14241  	 	 	 	 	 $col_a = array(0,0,0,0);
14242  	 	 	 	 	 $col_b = array(100,100,100,100);
14243  	 	 	 	 	 break;
14244  	 	 	 	 }
14245  	 	 	 	 case 'ALL': { // SPOT COLOR REGISTRATION
14246  	 	 	 	 	 $col_a = array(0,0,0,0,'None');
14247  	 	 	 	 	 $col_b = array(100,100,100,100,'All');
14248  	 	 	 	 	 break;
14249  	 	 	 	 }
14250  	 	 	 	 case 'NONE': { // SKIP THIS COLOR
14251  	 	 	 	 	 $col_a = array(0,0,0,0,'None');
14252  	 	 	 	 	 $col_b = array(0,0,0,0,'None');
14253  	 	 	 	 	 break;
14254  	 	 	 	 }
14255  	 	 	 	 default: { // SPECIFIC SPOT COLOR NAME
14256  	 	 	 	 	 $col_a = array(0,0,0,0,'None');
14257  	 	 	 	 	 $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
14258  	 	 	 	 	 if ($col_b === false) {
14259  	 	 	 	 	 	 // in case of error defaults to the registration color
14260  	 	 	 	 	 	 $col_b = array(100,100,100,100,'All');
14261  	 	 	 	 	 }
14262  	 	 	 	 	 break;
14263  	 	 	 	 }
14264  	 	 	 }
14265  	 	 	 if ($col != 'NONE') {
14266  	 	 	 	 if ($transition) {
14267  	 	 	 	 	 // color gradient
14268  	 	 	 	 	 $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
14269  	 	 	 	 } else {
14270  	 	 	 	 	 $this->setFillColorArray($col_b);
14271  	 	 	 	 	 // colored rectangle
14272  	 	 	 	 	 $this->Rect($xb, $yb, $wb, $hb, 'F', array());
14273  	 	 	 	 }
14274  	 	 	 	 $xb += $xd;
14275  	 	 	 	 $yb += $yd;
14276  	 	 	 }
14277  	 	 }
14278  	 }
14279  
14280  	 /**
14281  	  * Paints crop marks.
14282  	  * @param float $x abscissa of the crop mark center.
14283  	  * @param float $y ordinate of the crop mark center.
14284  	  * @param float $w width of the crop mark.
14285  	  * @param float $h height of the crop mark.
14286  	  * @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.
14287  	  * @param array $color crop mark color (default spot registration color).
14288  	  * @author Nicola Asuni
14289  	  * @since 4.9.000 (2010-03-26)
14290  	  * @public
14291  	  */
14292  	public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
14293  	 	 $this->setLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
14294  	 	 $type = strtoupper($type);
14295  	 	 $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
14296  	 	 // split type in single components
14297  	 	 $type = str_replace('-', ',', $type);
14298  	 	 $type = str_replace('TL', 'T,L', $type);
14299  	 	 $type = str_replace('TR', 'T,R', $type);
14300  	 	 $type = str_replace('BL', 'F,L', $type);
14301  	 	 $type = str_replace('BR', 'F,R', $type);
14302  	 	 $type = str_replace('A', 'T,L', $type);
14303  	 	 $type = str_replace('B', 'T,R', $type);
14304  	 	 $type = str_replace('T,RO', 'BO', $type);
14305  	 	 $type = str_replace('C', 'F,L', $type);
14306  	 	 $type = str_replace('D', 'F,R', $type);
14307  	 	 $crops = explode(',', strtoupper($type));
14308  	 	 // remove duplicates
14309  	 	 $crops = array_unique($crops);
14310  	 	 $dw = ($w / 4); // horizontal space to leave before the intersection point
14311  	 	 $dh = ($h / 4); // vertical space to leave before the intersection point
14312  	 	 foreach ($crops as $crop) {
14313  	 	 	 switch ($crop) {
14314  	 	 	 	 case 'T':
14315  	 	 	 	 case 'TOP': {
14316  	 	 	 	 	 $x1 = $x;
14317  	 	 	 	 	 $y1 = ($y - $h);
14318  	 	 	 	 	 $x2 = $x;
14319  	 	 	 	 	 $y2 = ($y - $dh);
14320  	 	 	 	 	 break;
14321  	 	 	 	 }
14322  	 	 	 	 case 'F':
14323  	 	 	 	 case 'BOTTOM': {
14324  	 	 	 	 	 $x1 = $x;
14325  	 	 	 	 	 $y1 = ($y + $dh);
14326  	 	 	 	 	 $x2 = $x;
14327  	 	 	 	 	 $y2 = ($y + $h);
14328  	 	 	 	 	 break;
14329  	 	 	 	 }
14330  	 	 	 	 case 'L':
14331  	 	 	 	 case 'LEFT': {
14332  	 	 	 	 	 $x1 = ($x - $w);
14333  	 	 	 	 	 $y1 = $y;
14334  	 	 	 	 	 $x2 = ($x - $dw);
14335  	 	 	 	 	 $y2 = $y;
14336  	 	 	 	 	 break;
14337  	 	 	 	 }
14338  	 	 	 	 case 'R':
14339  	 	 	 	 case 'RIGHT': {
14340  	 	 	 	 	 $x1 = ($x + $dw);
14341  	 	 	 	 	 $y1 = $y;
14342  	 	 	 	 	 $x2 = ($x + $w);
14343  	 	 	 	 	 $y2 = $y;
14344  	 	 	 	 	 break;
14345  	 	 	 	 }
14346  	 	 	 }
14347  	 	 	 $this->Line($x1, $y1, $x2, $y2);
14348  	 	 }
14349  	 }
14350  
14351  	 /**
14352  	  * Paints a registration mark
14353  	  * @param float $x abscissa of the registration mark center.
14354  	  * @param float $y ordinate of the registration mark center.
14355  	  * @param float $r radius of the crop mark.
14356  	  * @param boolean $double if true print two concentric crop marks.
14357  	  * @param array $cola crop mark color (default spot registration color 'All').
14358  	  * @param array $colb second crop mark color (default spot registration color 'None').
14359  	  * @author Nicola Asuni
14360  	  * @since 4.9.000 (2010-03-26)
14361  	  * @public
14362  	  */
14363  	public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
14364  	 	 $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
14365  	 	 $this->setFillColorArray($cola);
14366  	 	 $this->PieSector($x, $y, $r, 90, 180, 'F');
14367  	 	 $this->PieSector($x, $y, $r, 270, 360, 'F');
14368  	 	 $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
14369  	 	 if ($double) {
14370  	 	 	 $ri = $r * 0.5;
14371  	 	 	 $this->setFillColorArray($colb);
14372  	 	 	 $this->PieSector($x, $y, $ri, 90, 180, 'F');
14373  	 	 	 $this->PieSector($x, $y, $ri, 270, 360, 'F');
14374  	 	 	 $this->setFillColorArray($cola);
14375  	 	 	 $this->PieSector($x, $y, $ri, 0, 90, 'F');
14376  	 	 	 $this->PieSector($x, $y, $ri, 180, 270, 'F');
14377  	 	 	 $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
14378  	 	 }
14379  	 }
14380  
14381  	 /**
14382  	  * Paints a CMYK registration mark
14383  	  * @param float $x abscissa of the registration mark center.
14384  	  * @param float $y ordinate of the registration mark center.
14385  	  * @param float $r radius of the crop mark.
14386  	  * @author Nicola Asuni
14387  	  * @since 6.0.038 (2013-09-30)
14388  	  * @public
14389  	  */
14390  	public function registrationMarkCMYK($x, $y, $r) {
14391  	 	 // line width
14392  	 	 $lw = max((0.5 / $this->k),($r / 8));
14393  	 	 // internal radius
14394  	 	 $ri = ($r * 0.6);
14395  	 	 // external radius
14396  	 	 $re = ($r * 1.3);
14397  	 	 // Cyan
14398  	 	 $this->setFillColorArray(array(100,0,0,0));
14399  	 	 $this->PieSector($x, $y, $ri, 270, 360, 'F');
14400  	 	 // Magenta
14401  	 	 $this->setFillColorArray(array(0,100,0,0));
14402  	 	 $this->PieSector($x, $y, $ri, 0, 90, 'F');
14403  	 	 // Yellow
14404  	 	 $this->setFillColorArray(array(0,0,100,0));
14405  	 	 $this->PieSector($x, $y, $ri, 90, 180, 'F');
14406  	 	 // Key - black
14407  	 	 $this->setFillColorArray(array(0,0,0,100));
14408  	 	 $this->PieSector($x, $y, $ri, 180, 270, 'F');
14409  	 	 // registration color
14410  	 	 $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
14411  	 	 $this->setFillColorArray(array(100,100,100,100,'All'));
14412  	 	 // external circle
14413  	 	 $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
14414  	 	 // cross lines
14415  	 	 $this->Line($x, ($y - $re), $x, ($y - $ri));
14416  	 	 $this->Line($x, ($y + $ri), $x, ($y + $re));
14417  	 	 $this->Line(($x - $re), $y, ($x - $ri), $y);
14418  	 	 $this->Line(($x + $ri), $y, ($x + $re), $y);
14419  	 }
14420  
14421  	 /**
14422  	  * Paints a linear colour gradient.
14423  	  * @param float $x abscissa of the top left corner of the rectangle.
14424  	  * @param float $y ordinate of the top left corner of the rectangle.
14425  	  * @param float $w width of the rectangle.
14426  	  * @param float $h height of the rectangle.
14427  	  * @param array $col1 first color (Grayscale, RGB or CMYK components).
14428  	  * @param array $col2 second color (Grayscale, RGB or CMYK components).
14429  	  * @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).
14430  	  * @author Andreas W\FCrmser, Nicola Asuni
14431  	  * @since 3.1.000 (2008-06-09)
14432  	  * @public
14433  	  */
14434  	public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
14435  	 	 $this->Clip($x, $y, $w, $h);
14436  	 	 $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
14437  	 }
14438  
14439  	 /**
14440  	  * Paints a radial colour gradient.
14441  	  * @param float $x abscissa of the top left corner of the rectangle.
14442  	  * @param float $y ordinate of the top left corner of the rectangle.
14443  	  * @param float $w width of the rectangle.
14444  	  * @param float $h height of the rectangle.
14445  	  * @param array $col1 first color (Grayscale, RGB or CMYK components).
14446  	  * @param array $col2 second color (Grayscale, RGB or CMYK components).
14447  	  * @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.
14448  	  * @author Andreas W\FCrmser, Nicola Asuni
14449  	  * @since 3.1.000 (2008-06-09)
14450  	  * @public
14451  	  */
14452  	public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
14453  	 	 $this->Clip($x, $y, $w, $h);
14454  	 	 $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
14455  	 }
14456  
14457  	 /**
14458  	  * Paints a coons patch mesh.
14459  	  * @param float $x abscissa of the top left corner of the rectangle.
14460  	  * @param float $y ordinate of the top left corner of the rectangle.
14461  	  * @param float $w width of the rectangle.
14462  	  * @param float $h height of the rectangle.
14463  	  * @param array $col1 first color (lower left corner) (RGB components).
14464  	  * @param array $col2 second color (lower right corner) (RGB components).
14465  	  * @param array $col3 third color (upper right corner) (RGB components).
14466  	  * @param array $col4 fourth color (upper left corner) (RGB components).
14467  	  * @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>
14468  	  * @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
14469  	  * @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
14470  	  * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
14471  	  * @author Andreas W\FCrmser, Nicola Asuni
14472  	  * @since 3.1.000 (2008-06-09)
14473  	  * @public
14474  	  */
14475  	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) {
14476  	 	 if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
14477  	 	 	 return;
14478  	 	 }
14479  	 	 $this->Clip($x, $y, $w, $h);
14480  	 	 $n = count($this->gradients) + 1;
14481  	 	 $this->gradients[$n] = array();
14482  	 	 $this->gradients[$n]['type'] = 6; //coons patch mesh
14483  	 	 $this->gradients[$n]['coords'] = array();
14484  	 	 $this->gradients[$n]['antialias'] = $antialias;
14485  	 	 $this->gradients[$n]['colors'] = array();
14486  	 	 $this->gradients[$n]['transparency'] = false;
14487  	 	 //check the coords array if it is the simple array or the multi patch array
14488  	 	 if (!isset($coords[0]['f'])) {
14489  	 	 	 //simple array -> convert to multi patch array
14490  	 	 	 if (!isset($col1[1])) {
14491  	 	 	 	 $col1[1] = $col1[2] = $col1[0];
14492  	 	 	 }
14493  	 	 	 if (!isset($col2[1])) {
14494  	 	 	 	 $col2[1] = $col2[2] = $col2[0];
14495  	 	 	 }
14496  	 	 	 if (!isset($col3[1])) {
14497  	 	 	 	 $col3[1] = $col3[2] = $col3[0];
14498  	 	 	 }
14499  	 	 	 if (!isset($col4[1])) {
14500  	 	 	 	 $col4[1] = $col4[2] = $col4[0];
14501  	 	 	 }
14502  	 	 	 $patch_array[0]['f'] = 0;
14503  	 	 	 $patch_array[0]['points'] = $coords;
14504  	 	 	 $patch_array[0]['colors'][0]['r'] = $col1[0];
14505  	 	 	 $patch_array[0]['colors'][0]['g'] = $col1[1];
14506  	 	 	 $patch_array[0]['colors'][0]['b'] = $col1[2];
14507  	 	 	 $patch_array[0]['colors'][1]['r'] = $col2[0];
14508  	 	 	 $patch_array[0]['colors'][1]['g'] = $col2[1];
14509  	 	 	 $patch_array[0]['colors'][1]['b'] = $col2[2];
14510  	 	 	 $patch_array[0]['colors'][2]['r'] = $col3[0];
14511  	 	 	 $patch_array[0]['colors'][2]['g'] = $col3[1];
14512  	 	 	 $patch_array[0]['colors'][2]['b'] = $col3[2];
14513  	 	 	 $patch_array[0]['colors'][3]['r'] = $col4[0];
14514  	 	 	 $patch_array[0]['colors'][3]['g'] = $col4[1];
14515  	 	 	 $patch_array[0]['colors'][3]['b'] = $col4[2];
14516  	 	 } else {
14517  	 	 	 //multi patch array
14518  	 	 	 $patch_array = $coords;
14519  	 	 }
14520  	 	 $bpcd = 65535; //16 bits per coordinate
14521  	 	 //build the data stream
14522  	 	 $this->gradients[$n]['stream'] = '';
14523  	 	 $count_patch = count($patch_array);
14524  	 	 for ($i=0; $i < $count_patch; ++$i) {
14525  	 	 	 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
14526  	 	 	 $count_points = count($patch_array[$i]['points']);
14527  	 	 	 for ($j=0; $j < $count_points; ++$j) {
14528  	 	 	 	 //each point as 16 bit
14529  	 	 	 	 $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
14530  	 	 	 	 if ($patch_array[$i]['points'][$j] < 0) {
14531  	 	 	 	 	 $patch_array[$i]['points'][$j] = 0;
14532  	 	 	 	 }
14533  	 	 	 	 if ($patch_array[$i]['points'][$j] > $bpcd) {
14534  	 	 	 	 	 $patch_array[$i]['points'][$j] = $bpcd;
14535  	 	 	 	 }
14536  	 	 	 	 $this->gradients[$n]['stream'] .= chr((int) floor($patch_array[$i]['points'][$j] / 256));
14537  	 	 	 	 $this->gradients[$n]['stream'] .= chr((int) floor(intval($patch_array[$i]['points'][$j]) % 256));
14538  	 	 	 }
14539  	 	 	 $count_cols = count($patch_array[$i]['colors']);
14540  	 	 	 for ($j=0; $j < $count_cols; ++$j) {
14541  	 	 	 	 //each color component as 8 bit
14542  	 	 	 	 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
14543  	 	 	 	 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
14544  	 	 	 	 $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
14545  	 	 	 }
14546  	 	 }
14547  	 	 //paint the gradient
14548  	 	 $this->_out('/Sh'.$n.' sh');
14549  	 	 //restore previous Graphic State
14550  	 	 $this->_outRestoreGraphicsState();
14551  	 	 if ($this->inxobj) {
14552  	 	 	 // we are inside an XObject template
14553  	 	 	 $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
14554  	 	 }
14555  	 }
14556  
14557  	 /**
14558  	  * Set a rectangular clipping area.
14559  	  * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
14560  	  * @param float $y ordinate of the top left corner of the rectangle.
14561  	  * @param float $w width of the rectangle.
14562  	  * @param float $h height of the rectangle.
14563  	  * @author Andreas W\FCrmser, Nicola Asuni
14564  	  * @since 3.1.000 (2008-06-09)
14565  	  * @protected
14566  	  */
14567  	protected function Clip($x, $y, $w, $h) {
14568  	 	 if ($this->state != 2) {
14569  	 	 	  return;
14570  	 	 }
14571  	 	 if ($this->rtl) {
14572  	 	 	 $x = $this->w - $x - $w;
14573  	 	 }
14574  	 	 //save current Graphic State
14575  	 	 $s = 'q';
14576  	 	 //set clipping area
14577  	 	 $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
14578  	 	 //set up transformation matrix for gradient
14579  	 	 $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
14580  	 	 $this->_out($s);
14581  	 }
14582  
14583  	 /**
14584  	  * Output gradient.
14585  	  * @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)
14586  	  * @param array $coords array of coordinates.
14587  	  * @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).
14588  	  * @param array $background An array of colour components appropriate to the colour space, specifying a single background colour value.
14589  	  * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
14590  	  * @author Nicola Asuni
14591  	  * @since 3.1.000 (2008-06-09)
14592  	  * @public
14593  	  */
14594  	public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
14595  	 	 if (($this->pdfa_mode && $this->pdfa_version < 2) OR ($this->state != 2)) {
14596  	 	 	 return;
14597  	 	 }
14598  	 	 $n = count($this->gradients) + 1;
14599  	 	 $this->gradients[$n] = array();
14600  	 	 $this->gradients[$n]['type'] = $type;
14601  	 	 $this->gradients[$n]['coords'] = $coords;
14602  	 	 $this->gradients[$n]['antialias'] = $antialias;
14603  	 	 $this->gradients[$n]['colors'] = array();
14604  	 	 $this->gradients[$n]['transparency'] = false;
14605  	 	 // color space
14606  	 	 $numcolspace = count($stops[0]['color']);
14607  	 	 $bcolor = array_values($background);
14608  	 	 switch($numcolspace) {
14609  	 	 	 case 5:   // SPOT
14610  	 	 	 case 4: { // CMYK
14611  	 	 	 	 $this->gradients[$n]['colspace'] = 'DeviceCMYK';
14612  	 	 	 	 if (!empty($background)) {
14613  	 	 	 	 	 $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
14614  	 	 	 	 }
14615  	 	 	 	 break;
14616  	 	 	 }
14617  	 	 	 case 3: { // RGB
14618  	 	 	 	 $this->gradients[$n]['colspace'] = 'DeviceRGB';
14619  	 	 	 	 if (!empty($background)) {
14620  	 	 	 	 	 $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
14621  	 	 	 	 }
14622  	 	 	 	 break;
14623  	 	 	 }
14624  	 	 	 case 1: { // GRAY SCALE
14625  	 	 	 	 $this->gradients[$n]['colspace'] = 'DeviceGray';
14626  	 	 	 	 if (!empty($background)) {
14627  	 	 	 	 	 $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
14628  	 	 	 	 }
14629  	 	 	 	 break;
14630  	 	 	 }
14631  	 	 }
14632  	 	 $num_stops = count($stops);
14633  	 	 $last_stop_id = $num_stops - 1;
14634  	 	 foreach ($stops as $key => $stop) {
14635  	 	 	 $this->gradients[$n]['colors'][$key] = array();
14636  	 	 	 // offset represents a location along the gradient vector
14637  	 	 	 if (isset($stop['offset'])) {
14638  	 	 	 	 $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
14639  	 	 	 } else {
14640  	 	 	 	 if ($key == 0) {
14641  	 	 	 	 	 $this->gradients[$n]['colors'][$key]['offset'] = 0;
14642  	 	 	 	 } elseif ($key == $last_stop_id) {
14643  	 	 	 	 	 $this->gradients[$n]['colors'][$key]['offset'] = 1;
14644  	 	 	 	 } else {
14645  	 	 	 	 	 $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
14646  	 	 	 	 	 $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
14647  	 	 	 	 }
14648  	 	 	 }
14649  	 	 	 if (isset($stop['opacity'])) {
14650  	 	 	 	 $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
14651  	 	 	 	 if ((!($this->pdfa_mode && $this->pdfa_version < 2)) AND ($stop['opacity'] < 1)) {
14652  	 	 	 	 	 $this->gradients[$n]['transparency'] = true;
14653  	 	 	 	 }
14654  	 	 	 } else {
14655  	 	 	 	 $this->gradients[$n]['colors'][$key]['opacity'] = 1;
14656  	 	 	 }
14657  	 	 	 // exponent for the exponential interpolation function
14658  	 	 	 if (isset($stop['exponent'])) {
14659  	 	 	 	 $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
14660  	 	 	 } else {
14661  	 	 	 	 $this->gradients[$n]['colors'][$key]['exponent'] = 1;
14662  	 	 	 }
14663  	 	 	 // set colors
14664  	 	 	 $color = array_values($stop['color']);
14665  	 	 	 switch($numcolspace) {
14666  	 	 	 	 case 5:   // SPOT
14667  	 	 	 	 case 4: { // CMYK
14668  	 	 	 	 	 $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
14669  	 	 	 	 	 break;
14670  	 	 	 	 }
14671  	 	 	 	 case 3: { // RGB
14672  	 	 	 	 	 $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
14673  	 	 	 	 	 break;
14674  	 	 	 	 }
14675  	 	 	 	 case 1: { // GRAY SCALE
14676  	 	 	 	 	 $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
14677  	 	 	 	 	 break;
14678  	 	 	 	 }
14679  	 	 	 }
14680  	 	 }
14681  	 	 if ($this->gradients[$n]['transparency']) {
14682  	 	 	 // paint luminosity gradient
14683  	 	 	 $this->_out('/TGS'.$n.' gs');
14684  	 	 }
14685  	 	 //paint the gradient
14686  	 	 $this->_out('/Sh'.$n.' sh');
14687  	 	 //restore previous Graphic State
14688  	 	 $this->_outRestoreGraphicsState();
14689  	 	 if ($this->inxobj) {
14690  	 	 	 // we are inside an XObject template
14691  	 	 	 $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
14692  	 	 }
14693  	 }
14694  
14695  	 /**
14696  	  * Output gradient shaders.
14697  	  * @author Nicola Asuni
14698  	  * @since 3.1.000 (2008-06-09)
14699  	  * @protected
14700  	  */
14701  	function _putshaders() {
14702  	 	 if ($this->pdfa_mode && $this->pdfa_version < 2) {
14703  	 	 	 return;
14704  	 	 }
14705  	 	 $idt = count($this->gradients); //index for transparency gradients
14706  	 	 foreach ($this->gradients as $id => $grad) {
14707  	 	 	 if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
14708  	 	 	 	 $fc = $this->_newobj();
14709  	 	 	 	 $out = '<<';
14710  	 	 	 	 $out .= ' /FunctionType 3';
14711  	 	 	 	 $out .= ' /Domain [0 1]';
14712  	 	 	 	 $functions = '';
14713  	 	 	 	 $bounds = '';
14714  	 	 	 	 $encode = '';
14715  	 	 	 	 $i = 1;
14716  	 	 	 	 $num_cols = count($grad['colors']);
14717  	 	 	 	 $lastcols = $num_cols - 1;
14718  	 	 	 	 for ($i = 1; $i < $num_cols; ++$i) {
14719  	 	 	 	 	 $functions .= ($fc + $i).' 0 R ';
14720  	 	 	 	 	 if ($i < $lastcols) {
14721  	 	 	 	 	 	 $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
14722  	 	 	 	 	 }
14723  	 	 	 	 	 $encode .= '0 1 ';
14724  	 	 	 	 }
14725  	 	 	 	 $out .= ' /Functions ['.trim($functions).']';
14726  	 	 	 	 $out .= ' /Bounds ['.trim($bounds).']';
14727  	 	 	 	 $out .= ' /Encode ['.trim($encode).']';
14728  	 	 	 	 $out .= ' >>';
14729  	 	 	 	 $out .= "\n".'endobj';
14730  	 	 	 	 $this->_out($out);
14731  	 	 	 	 for ($i = 1; $i < $num_cols; ++$i) {
14732  	 	 	 	 	 $this->_newobj();
14733  	 	 	 	 	 $out = '<<';
14734  	 	 	 	 	 $out .= ' /FunctionType 2';
14735  	 	 	 	 	 $out .= ' /Domain [0 1]';
14736  	 	 	 	 	 $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
14737  	 	 	 	 	 $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
14738  	 	 	 	 	 $out .= ' /N '.$grad['colors'][$i]['exponent'];
14739  	 	 	 	 	 $out .= ' >>';
14740  	 	 	 	 	 $out .= "\n".'endobj';
14741  	 	 	 	 	 $this->_out($out);
14742  	 	 	 	 }
14743  	 	 	 	 // set transparency functions
14744  	 	 	 	 if ($grad['transparency']) {
14745  	 	 	 	 	 $ft = $this->_newobj();
14746  	 	 	 	 	 $out = '<<';
14747  	 	 	 	 	 $out .= ' /FunctionType 3';
14748  	 	 	 	 	 $out .= ' /Domain [0 1]';
14749  	 	 	 	 	 $functions = '';
14750  	 	 	 	 	 $i = 1;
14751  	 	 	 	 	 $num_cols = count($grad['colors']);
14752  	 	 	 	 	 for ($i = 1; $i < $num_cols; ++$i) {
14753  	 	 	 	 	 	 $functions .= ($ft + $i).' 0 R ';
14754  	 	 	 	 	 }
14755  	 	 	 	 	 $out .= ' /Functions ['.trim($functions).']';
14756  	 	 	 	 	 $out .= ' /Bounds ['.trim($bounds).']';
14757  	 	 	 	 	 $out .= ' /Encode ['.trim($encode).']';
14758  	 	 	 	 	 $out .= ' >>';
14759  	 	 	 	 	 $out .= "\n".'endobj';
14760  	 	 	 	 	 $this->_out($out);
14761  	 	 	 	 	 for ($i = 1; $i < $num_cols; ++$i) {
14762  	 	 	 	 	 	 $this->_newobj();
14763  	 	 	 	 	 	 $out = '<<';
14764  	 	 	 	 	 	 $out .= ' /FunctionType 2';
14765  	 	 	 	 	 	 $out .= ' /Domain [0 1]';
14766  	 	 	 	 	 	 $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
14767  	 	 	 	 	 	 $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
14768  	 	 	 	 	 	 $out .= ' /N '.$grad['colors'][$i]['exponent'];
14769  	 	 	 	 	 	 $out .= ' >>';
14770  	 	 	 	 	 	 $out .= "\n".'endobj';
14771  	 	 	 	 	 	 $this->_out($out);
14772  	 	 	 	 	 }
14773  	 	 	 	 }
14774  	 	 	 }
14775  	 	 	 // set shading object
14776  	 	 	 $this->_newobj();
14777  	 	 	 $out = '<< /ShadingType '.$grad['type'];
14778  	 	 	 if (isset($grad['colspace'])) {
14779  	 	 	 	 $out .= ' /ColorSpace /'.$grad['colspace'];
14780  	 	 	 } else {
14781  	 	 	 	 $out .= ' /ColorSpace /DeviceRGB';
14782  	 	 	 }
14783  	 	 	 if (isset($grad['background']) AND !empty($grad['background'])) {
14784  	 	 	 	 $out .= ' /Background ['.$grad['background'].']';
14785  	 	 	 }
14786  	 	 	 if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
14787  	 	 	 	 $out .= ' /AntiAlias true';
14788  	 	 	 }
14789  	 	 	 if ($grad['type'] == 2) {
14790  	 	 	 	 $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
14791  	 	 	 	 $out .= ' /Domain [0 1]';
14792  	 	 	 	 $out .= ' /Function '.$fc.' 0 R';
14793  	 	 	 	 $out .= ' /Extend [true true]';
14794  	 	 	 	 $out .= ' >>';
14795  	 	 	 } elseif ($grad['type'] == 3) {
14796  	 	 	 	 //x0, y0, r0, x1, y1, r1
14797  	 	 	 	 //at this this time radius of inner circle is 0
14798  	 	 	 	 $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
14799  	 	 	 	 $out .= ' /Domain [0 1]';
14800  	 	 	 	 $out .= ' /Function '.$fc.' 0 R';
14801  	 	 	 	 $out .= ' /Extend [true true]';
14802  	 	 	 	 $out .= ' >>';
14803  	 	 	 } elseif ($grad['type'] == 6) {
14804  	 	 	 	 $out .= ' /BitsPerCoordinate 16';
14805  	 	 	 	 $out .= ' /BitsPerComponent 8';
14806  	 	 	 	 $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
14807  	 	 	 	 $out .= ' /BitsPerFlag 8';
14808  	 	 	 	 $stream = $this->_getrawstream($grad['stream']);
14809  	 	 	 	 $out .= ' /Length '.strlen($stream);
14810  	 	 	 	 $out .= ' >>';
14811  	 	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
14812  	 	 	 }
14813  	 	 	 $out .= "\n".'endobj';
14814  	 	 	 $this->_out($out);
14815  	 	 	 if ($grad['transparency']) {
14816  	 	 	 	 $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
14817  	 	 	 	 $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
14818  	 	 	 }
14819  	 	 	 $this->gradients[$id]['id'] = $this->n;
14820  	 	 	 // set pattern object
14821  	 	 	 $this->_newobj();
14822  	 	 	 $out = '<< /Type /Pattern /PatternType 2';
14823  	 	 	 $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
14824  	 	 	 $out .= ' >>';
14825  	 	 	 $out .= "\n".'endobj';
14826  	 	 	 $this->_out($out);
14827  	 	 	 $this->gradients[$id]['pattern'] = $this->n;
14828  	 	 	 // set shading and pattern for transparency mask
14829  	 	 	 if ($grad['transparency']) {
14830  	 	 	 	 // luminosity pattern
14831  	 	 	 	 $idgs = $id + $idt;
14832  	 	 	 	 $this->_newobj();
14833  	 	 	 	 $this->_out($shading_transparency);
14834  	 	 	 	 $this->gradients[$idgs]['id'] = $this->n;
14835  	 	 	 	 $this->_newobj();
14836  	 	 	 	 $out = '<< /Type /Pattern /PatternType 2';
14837  	 	 	 	 $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
14838  	 	 	 	 $out .= ' >>';
14839  	 	 	 	 $out .= "\n".'endobj';
14840  	 	 	 	 $this->_out($out);
14841  	 	 	 	 $this->gradients[$idgs]['pattern'] = $this->n;
14842  	 	 	 	 // luminosity XObject
14843  	 	 	 	 $oid = $this->_newobj();
14844  	 	 	 	 $this->xobjects['LX'.$oid] = array('n' => $oid);
14845  	 	 	 	 $filter = '';
14846  	 	 	 	 $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
14847  	 	 	 	 if ($this->compress) {
14848  	 	 	 	 	 $filter = ' /Filter /FlateDecode';
14849  	 	 	 	 	 $stream = gzcompress($stream);
14850  	 	 	 	 }
14851  	 	 	 	 $stream = $this->_getrawstream($stream);
14852  	 	 	 	 $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
14853  	 	 	 	 $out .= ' /Length '.strlen($stream);
14854  	 	 	 	 $rect = sprintf('%F %F', $this->wPt, $this->hPt);
14855  	 	 	 	 $out .= ' /BBox [0 0 '.$rect.']';
14856  	 	 	 	 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
14857  	 	 	 	 $out .= ' /Resources <<';
14858  	 	 	 	 $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
14859  	 	 	 	 $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
14860  	 	 	 	 $out .= ' >>';
14861  	 	 	 	 $out .= ' >> ';
14862  	 	 	 	 $out .= ' stream'."\n".$stream."\n".'endstream';
14863  	 	 	 	 $out .= "\n".'endobj';
14864  	 	 	 	 $this->_out($out);
14865  	 	 	 	 // SMask
14866  	 	 	 	 $this->_newobj();
14867  	 	 	 	 $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
14868  	 	 	 	 $this->_out($out);
14869  	 	 	 	 // ExtGState
14870  	 	 	 	 $this->_newobj();
14871  	 	 	 	 $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
14872  	 	 	 	 $this->_out($out);
14873  	 	 	 	 $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
14874  	 	 	 }
14875  	 	 }
14876  	 }
14877  
14878  	 /**
14879  	  * Draw the sector of a circle.
14880  	  * It can be used for instance to render pie charts.
14881  	  * @param float $xc abscissa of the center.
14882  	  * @param float $yc ordinate of the center.
14883  	  * @param float $r radius.
14884  	  * @param float $a start angle (in degrees).
14885  	  * @param float $b end angle (in degrees).
14886  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
14887  	  * @param float $cw indicates whether to go clockwise (default: true).
14888  	  * @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.
14889  	  * @author Maxime Delorme, Nicola Asuni
14890  	  * @since 3.1.000 (2008-06-09)
14891  	  * @public
14892  	  */
14893  	public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
14894  	 	 $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
14895  	 }
14896  
14897  	 /**
14898  	  * Draw the sector of an ellipse.
14899  	  * It can be used for instance to render pie charts.
14900  	  * @param float $xc abscissa of the center.
14901  	  * @param float $yc ordinate of the center.
14902  	  * @param float $rx the x-axis radius.
14903  	  * @param float $ry the y-axis radius.
14904  	  * @param float $a start angle (in degrees).
14905  	  * @param float $b end angle (in degrees).
14906  	  * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
14907  	  * @param float $cw indicates whether to go clockwise.
14908  	  * @param float $o origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
14909  	  * @param integer $nc Number of curves used to draw a 90 degrees portion of arc.
14910  	  * @author Maxime Delorme, Nicola Asuni
14911  	  * @since 3.1.000 (2008-06-09)
14912  	  * @public
14913  	  */
14914  	public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
14915  	 	 if ($this->state != 2) {
14916  	 	 	  return;
14917  	 	 }
14918  	 	 if ($this->rtl) {
14919  	 	 	 $xc = ($this->w - $xc);
14920  	 	 }
14921  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style);
14922  	 	 if ($op == 'f') {
14923  	 	 	 $line_style = array();
14924  	 	 }
14925  	 	 if ($cw) {
14926  	 	 	 $d = $b;
14927  	 	 	 $b = (360 - $a + $o);
14928  	 	 	 $a = (360 - $d + $o);
14929  	 	 } else {
14930  	 	 	 $b += $o;
14931  	 	 	 $a += $o;
14932  	 	 }
14933  	 	 $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
14934  	 	 $this->_out($op);
14935  	 }
14936  
14937  	 /**
14938  	  * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
14939  	  * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
14940  	  * Only vector drawing is supported, not text or bitmap.
14941  	  * 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).
14942  	  * @param string $file Name of the file containing the image or a '@' character followed by the EPS/AI data string.
14943  	  * @param float|null $x Abscissa of the upper-left corner.
14944  	  * @param float|null $y Ordinate of the upper-left corner.
14945  	  * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
14946  	  * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
14947  	  * @param mixed $link URL or identifier returned by AddLink().
14948  	  * @param boolean $useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
14949  	  * @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>
14950  	  * @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>
14951  	  * @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)))
14952  	  * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
14953  	  * @param boolean $fixoutvals if true remove values outside the bounding box.
14954  	  * @author Valentin Schmidt, Nicola Asuni
14955  	  * @since 3.1.000 (2008-06-09)
14956  	  * @public
14957  	  */
14958  	public function ImageEps($file, $x=null, $y=null, $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
14959  	 	 if ($this->state != 2) {
14960  	 	 	  return;
14961  	 	 }
14962  	 	 if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
14963  	 	 	 // convert EPS to raster image using GD or ImageMagick libraries
14964  	 	 	 return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
14965  	 	 }
14966  	 	 if (TCPDF_STATIC::empty_string($x)) {
14967  	 	 	 $x = $this->x;
14968  	 	 }
14969  	 	 if (TCPDF_STATIC::empty_string($y)) {
14970  	 	 	 $y = $this->y;
14971  	 	 }
14972  	 	 // check page for no-write regions and adapt page margins if necessary
14973  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
14974  	 	 $k = $this->k;
14975  	 	 if ($file[0] === '@') { // image from string
14976  	 	 	 $data = substr($file, 1);
14977  	 	 } else { // EPS/AI file
14978              $data = $this->getCachedFileContents($file);
14979  	 	 }
14980  	 	 if ($data === FALSE) {
14981  	 	 	 $this->Error('EPS file not found: '.$file);
14982  	 	 }
14983  	 	 $regs = array();
14984  	 	 // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
14985  	 	 preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
14986  	 	 if (count($regs) > 1) {
14987  	 	 	 $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
14988  	 	 	 if (strpos($version_str, 'Adobe Illustrator') !== false) {
14989  	 	 	 	 $versexp = explode(' ', $version_str);
14990  	 	 	 	 $version = (float)array_pop($versexp);
14991  	 	 	 	 if ($version >= 9) {
14992  	 	 	 	 	 $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
14993  	 	 	 	 }
14994  	 	 	 }
14995  	 	 }
14996  	 	 // strip binary bytes in front of PS-header
14997  	 	 $start = strpos($data, '%!PS-Adobe');
14998  	 	 if ($start > 0) {
14999  	 	 	 $data = substr($data, $start);
15000  	 	 }
15001  	 	 // find BoundingBox params
15002  	 	 preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
15003  	 	 if (count($regs) > 1) {
15004  	 	 	 list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
15005  	 	 } else {
15006  	 	 	 $this->Error('No BoundingBox found in EPS/AI file: '.$file);
15007  	 	 }
15008  	 	 $start = strpos($data, '%%EndSetup');
15009  	 	 if ($start === false) {
15010  	 	 	 $start = strpos($data, '%%EndProlog');
15011  	 	 }
15012  	 	 if ($start === false) {
15013  	 	 	 $start = strpos($data, '%%BoundingBox');
15014  	 	 }
15015  	 	 $data = substr($data, $start);
15016  	 	 $end = strpos($data, '%%PageTrailer');
15017  	 	 if ($end===false) {
15018  	 	 	 $end = strpos($data, 'showpage');
15019  	 	 }
15020  	 	 if ($end) {
15021  	 	 	 $data = substr($data, 0, $end);
15022  	 	 }
15023  	 	 // calculate image width and height on document
15024  	 	 if (($w <= 0) AND ($h <= 0)) {
15025  	 	 	 $w = ($x2 - $x1) / $k;
15026  	 	 	 $h = ($y2 - $y1) / $k;
15027  	 	 } elseif ($w <= 0) {
15028  	 	 	 $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
15029  	 	 } elseif ($h <= 0) {
15030  	 	 	 $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
15031  	 	 }
15032  	 	 // fit the image on available space
15033  	 	 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
15034  	 	 if ($this->rasterize_vector_images) {
15035  	 	 	 // convert EPS to raster image using GD or ImageMagick libraries
15036  	 	 	 return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
15037  	 	 }
15038  	 	 // set scaling factors
15039  	 	 $scale_x = $w / (($x2 - $x1) / $k);
15040  	 	 $scale_y = $h / (($y2 - $y1) / $k);
15041  	 	 // set alignment
15042  	 	 $this->img_rb_y = $y + $h;
15043  	 	 // set alignment
15044  	 	 if ($this->rtl) {
15045  	 	 	 if ($palign == 'L') {
15046  	 	 	 	 $ximg = $this->lMargin;
15047  	 	 	 } elseif ($palign == 'C') {
15048  	 	 	 	 $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
15049  	 	 	 } elseif ($palign == 'R') {
15050  	 	 	 	 $ximg = $this->w - $this->rMargin - $w;
15051  	 	 	 } else {
15052  	 	 	 	 $ximg = $x - $w;
15053  	 	 	 }
15054  	 	 	 $this->img_rb_x = $ximg;
15055  	 	 } else {
15056  	 	 	 if ($palign == 'L') {
15057  	 	 	 	 $ximg = $this->lMargin;
15058  	 	 	 } elseif ($palign == 'C') {
15059  	 	 	 	 $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
15060  	 	 	 } elseif ($palign == 'R') {
15061  	 	 	 	 $ximg = $this->w - $this->rMargin - $w;
15062  	 	 	 } else {
15063  	 	 	 	 $ximg = $x;
15064  	 	 	 }
15065  	 	 	 $this->img_rb_x = $ximg + $w;
15066  	 	 }
15067  	 	 if ($useBoundingBox) {
15068  	 	 	 $dx = $ximg * $k - $x1;
15069  	 	 	 $dy = $y * $k - $y1;
15070  	 	 } else {
15071  	 	 	 $dx = $ximg * $k;
15072  	 	 	 $dy = $y * $k;
15073  	 	 }
15074  	 	 // save the current graphic state
15075  	 	 $this->_out('q'.$this->epsmarker);
15076  	 	 // translate
15077  	 	 $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
15078  	 	 // scale
15079  	 	 if (isset($scale_x)) {
15080  	 	 	 $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
15081  	 	 }
15082  	 	 // handle pc/unix/mac line endings
15083  	 	 $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
15084  	 	 $u=0;
15085  	 	 $cnt = count($lines);
15086  	 	 for ($i=0; $i < $cnt; ++$i) {
15087  	 	 	 $line = $lines[$i];
15088  	 	 	 if (($line == '') OR ($line[0] == '%')) {
15089  	 	 	 	 continue;
15090  	 	 	 }
15091  	 	 	 $len = strlen($line);
15092  	 	 	 // check for spot color names
15093  	 	 	 $color_name = '';
15094  	 	 	 if (strcasecmp('x', substr(trim($line), -1)) == 0) {
15095  	 	 	 	 if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
15096  	 	 	 	 	 // extract spot color name
15097  	 	 	 	 	 $color_name = $matches[0];
15098  	 	 	 	 	 // remove color name from string
15099  	 	 	 	 	 $line = str_replace(' '.$color_name, '', $line);
15100  	 	 	 	 	 // remove pharentesis from color name
15101  	 	 	 	 	 $color_name = substr($color_name, 1, -1);
15102  	 	 	 	 }
15103  	 	 	 }
15104  	 	 	 $chunks = explode(' ', $line);
15105  	 	 	 $cmd = trim(array_pop($chunks));
15106  	 	 	 // RGB
15107  	 	 	 if (($cmd == 'Xa') OR ($cmd == 'XA')) {
15108  	 	 	 	 $b = array_pop($chunks);
15109  	 	 	 	 $g = array_pop($chunks);
15110  	 	 	 	 $r = array_pop($chunks);
15111  	 	 	 	 $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!
15112  	 	 	 	 continue;
15113  	 	 	 }
15114  	 	 	 $skip = false;
15115  	 	 	 if ($fixoutvals) {
15116  	 	 	 	 // check for values outside the bounding box
15117  	 	 	 	 switch ($cmd) {
15118  	 	 	 	 	 case 'm':
15119  	 	 	 	 	 case 'l':
15120  	 	 	 	 	 case 'L': {
15121  	 	 	 	 	 	 // skip values outside bounding box
15122  	 	 	 	 	 	 foreach ($chunks as $key => $val) {
15123  	 	 	 	 	 	 	 if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
15124  	 	 	 	 	 	 	 	 $skip = true;
15125  	 	 	 	 	 	 	 } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
15126  	 	 	 	 	 	 	 	 $skip = true;
15127  	 	 	 	 	 	 	 }
15128  	 	 	 	 	 	 }
15129  	 	 	 	 	 }
15130  	 	 	 	 }
15131  	 	 	 }
15132  	 	 	 switch ($cmd) {
15133  	 	 	 	 case 'm':
15134  	 	 	 	 case 'l':
15135  	 	 	 	 case 'v':
15136  	 	 	 	 case 'y':
15137  	 	 	 	 case 'c':
15138  	 	 	 	 case 'k':
15139  	 	 	 	 case 'K':
15140  	 	 	 	 case 'g':
15141  	 	 	 	 case 'G':
15142  	 	 	 	 case 's':
15143  	 	 	 	 case 'S':
15144  	 	 	 	 case 'J':
15145  	 	 	 	 case 'j':
15146  	 	 	 	 case 'w':
15147  	 	 	 	 case 'M':
15148  	 	 	 	 case 'd':
15149  	 	 	 	 case 'n': {
15150  	 	 	 	 	 if ($skip) {
15151  	 	 	 	 	 	 break;
15152  	 	 	 	 	 }
15153  	 	 	 	 	 $this->_out($line);
15154  	 	 	 	 	 break;
15155  	 	 	 	 }
15156  	 	 	 	 case 'x': {// custom fill color
15157  	 	 	 	 	 if (empty($color_name)) {
15158  	 	 	 	 	 	 // CMYK color
15159  	 	 	 	 	 	 list($col_c, $col_m, $col_y, $col_k) = $chunks;
15160  	 	 	 	 	 	 $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
15161  	 	 	 	 	 } else {
15162  	 	 	 	 	 	 // Spot Color (CMYK + tint)
15163  	 	 	 	 	 	 list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
15164  	 	 	 	 	 	 $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
15165  	 	 	 	 	 	 $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
15166  	 	 	 	 	 	 $this->_out($color_cmd);
15167  	 	 	 	 	 }
15168  	 	 	 	 	 break;
15169  	 	 	 	 }
15170  	 	 	 	 case 'X': { // custom stroke color
15171  	 	 	 	 	 if (empty($color_name)) {
15172  	 	 	 	 	 	 // CMYK color
15173  	 	 	 	 	 	 list($col_c, $col_m, $col_y, $col_k) = $chunks;
15174  	 	 	 	 	 	 $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
15175  	 	 	 	 	 } else {
15176  	 	 	 	 	 	 // Spot Color (CMYK + tint)
15177  	 	 	 	 	 	 list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
15178  	 	 	 	 	 	 $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
15179  	 	 	 	 	 	 $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
15180  	 	 	 	 	 	 $this->_out($color_cmd);
15181  	 	 	 	 	 }
15182  	 	 	 	 	 break;
15183  	 	 	 	 }
15184  	 	 	 	 case 'Y':
15185  	 	 	 	 case 'N':
15186  	 	 	 	 case 'V':
15187  	 	 	 	 case 'L':
15188  	 	 	 	 case 'C': {
15189  	 	 	 	 	 if ($skip) {
15190  	 	 	 	 	 	 break;
15191  	 	 	 	 	 }
15192  	 	 	 	 	 $line[($len - 1)] = strtolower($cmd);
15193  	 	 	 	 	 $this->_out($line);
15194  	 	 	 	 	 break;
15195  	 	 	 	 }
15196  	 	 	 	 case 'b':
15197  	 	 	 	 case 'B': {
15198  	 	 	 	 	 $this->_out($cmd . '*');
15199  	 	 	 	 	 break;
15200  	 	 	 	 }
15201  	 	 	 	 case 'f':
15202  	 	 	 	 case 'F': {
15203  	 	 	 	 	 if ($u > 0) {
15204  	 	 	 	 	 	 $isU = false;
15205  	 	 	 	 	 	 $max = min(($i + 5), $cnt);
15206  	 	 	 	 	 	 for ($j = ($i + 1); $j < $max; ++$j) {
15207  	 	 	 	 	 	 	 $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
15208  	 	 	 	 	 	 }
15209  	 	 	 	 	 	 if ($isU) {
15210  	 	 	 	 	 	 	 $this->_out('f*');
15211  	 	 	 	 	 	 }
15212  	 	 	 	 	 } else {
15213  	 	 	 	 	 	 $this->_out('f*');
15214  	 	 	 	 	 }
15215  	 	 	 	 	 break;
15216  	 	 	 	 }
15217  	 	 	 	 case '*u': {
15218  	 	 	 	 	 ++$u;
15219  	 	 	 	 	 break;
15220  	 	 	 	 }
15221  	 	 	 	 case '*U': {
15222  	 	 	 	 	 --$u;
15223  	 	 	 	 	 break;
15224  	 	 	 	 }
15225  	 	 	 }
15226  	 	 }
15227  	 	 // restore previous graphic state
15228  	 	 $this->_out($this->epsmarker.'Q');
15229  	 	 if (!empty($border)) {
15230  	 	 	 $bx = $this->x;
15231  	 	 	 $by = $this->y;
15232  	 	 	 $this->x = $ximg;
15233  	 	 	 if ($this->rtl) {
15234  	 	 	 	 $this->x += $w;
15235  	 	 	 }
15236  	 	 	 $this->y = $y;
15237  	 	 	 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
15238  	 	 	 $this->x = $bx;
15239  	 	 	 $this->y = $by;
15240  	 	 }
15241  	 	 if ($link) {
15242  	 	 	 $this->Link($ximg, $y, $w, $h, $link, 0);
15243  	 	 }
15244  	 	 // set pointer to align the next text/objects
15245  	 	 switch($align) {
15246  	 	 	 case 'T':{
15247  	 	 	 	 $this->y = $y;
15248  	 	 	 	 $this->x = $this->img_rb_x;
15249  	 	 	 	 break;
15250  	 	 	 }
15251  	 	 	 case 'M':{
15252  	 	 	 	 $this->y = $y + round($h/2);
15253  	 	 	 	 $this->x = $this->img_rb_x;
15254  	 	 	 	 break;
15255  	 	 	 }
15256  	 	 	 case 'B':{
15257  	 	 	 	 $this->y = $this->img_rb_y;
15258  	 	 	 	 $this->x = $this->img_rb_x;
15259  	 	 	 	 break;
15260  	 	 	 }
15261  	 	 	 case 'N':{
15262  	 	 	 	 $this->setY($this->img_rb_y);
15263  	 	 	 	 break;
15264  	 	 	 }
15265  	 	 	 default:{
15266  	 	 	 	 break;
15267  	 	 	 }
15268  	 	 }
15269  	 	 $this->endlinex = $this->img_rb_x;
15270  	 }
15271  
15272  	 /**
15273  	  * Set document barcode.
15274  	  * @param string $bc barcode
15275  	  * @public
15276  	  */
15277  	public function setBarcode($bc='') {
15278  	 	 $this->barcode = $bc;
15279  	 }
15280  
15281  	 /**
15282  	  * Get current barcode.
15283  	  * @return string
15284  	  * @public
15285  	  * @since 4.0.012 (2008-07-24)
15286  	  */
15287  	public function getBarcode() {
15288  	 	 return $this->barcode;
15289  	 }
15290  
15291  	 /**
15292  	  * Print a Linear Barcode.
15293  	  * @param string $code code to print
15294  	  * @param string $type type of barcode (see tcpdf_barcodes_1d.php for supported formats).
15295  	  * @param float|null $x x position in user units (null = current x position)
15296  	  * @param float|null $y y position in user units (null = current y position)
15297  	  * @param float|null $w width in user units (null = remaining page width)
15298  	  * @param float|null $h height in user units (null = remaining page height)
15299  	  * @param float|null $xres width of the smallest bar in user units (null = default value = 0.4mm)
15300  	  * @param array $style array of options:<ul>
15301  	  * <li>boolean $style['border'] if true prints a border</li>
15302  	  * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
15303  	  * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
15304  	  * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
15305  	  * <li>array $style['fgcolor'] color array for bars and text</li>
15306  	  * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
15307  	  * <li>boolean $style['text'] if true prints text below the barcode</li>
15308  	  * <li>string $style['label'] override default label</li>
15309  	  * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
15310  	  * <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>
15311  	  * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
15312  	  * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
15313  	  * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
15314  	  * <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>
15315  	  * <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>
15316  	  * @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>
15317  	  * @author Nicola Asuni
15318  	  * @since 3.1.000 (2008-06-09)
15319  	  * @public
15320  	  */
15321  	public function write1DBarcode($code, $type, $x=null, $y=null, $w=null, $h=null, $xres=null, $style=array(), $align='') {
15322  	 	 if (TCPDF_STATIC::empty_string(trim($code))) {
15323  	 	 	 return;
15324  	 	 }
15325  	 	 require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
15326  	 	 // save current graphic settings
15327  	 	 $gvars = $this->getGraphicVars();
15328  	 	 // create new barcode object
15329  	 	 $barcodeobj = new TCPDFBarcode($code, $type);
15330  	 	 $arrcode = $barcodeobj->getBarcodeArray();
15331  	 	 if (empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
15332  	 	 	 $this->Error('Error in 1D barcode string');
15333  	 	 }
15334  	 	 if ($arrcode['maxh'] <= 0) {
15335  	 	 	 $arrcode['maxh'] = 1;
15336  	 	 }
15337  	 	 // set default values
15338  	 	 if (!isset($style['position'])) {
15339  	 	 	 $style['position'] = '';
15340  	 	 } elseif ($style['position'] == 'S') {
15341  	 	 	 // keep this for backward compatibility
15342  	 	 	 $style['position'] = '';
15343  	 	 	 $style['stretch'] = true;
15344  	 	 }
15345  	 	 if (!isset($style['fitwidth'])) {
15346  	 	 	 if (!isset($style['stretch'])) {
15347  	 	 	 	 $style['fitwidth'] = true;
15348  	 	 	 } else {
15349  	 	 	 	 $style['fitwidth'] = false;
15350  	 	 	 }
15351  	 	 }
15352  	 	 if ($style['fitwidth']) {
15353  	 	 	 // disable stretch
15354  	 	 	 $style['stretch'] = false;
15355  	 	 }
15356  	 	 if (!isset($style['stretch'])) {
15357  	 	 	 if (($w === '') OR ($w <= 0)) {
15358  	 	 	 	 $style['stretch'] = false;
15359  	 	 	 } else {
15360  	 	 	 	 $style['stretch'] = true;
15361  	 	 	 }
15362  	 	 }
15363  	 	 if (!isset($style['fgcolor'])) {
15364  	 	 	 $style['fgcolor'] = array(0,0,0); // default black
15365  	 	 }
15366  	 	 if (!isset($style['bgcolor'])) {
15367  	 	 	 $style['bgcolor'] = false; // default transparent
15368  	 	 }
15369  	 	 if (!isset($style['border'])) {
15370  	 	 	 $style['border'] = false;
15371  	 	 }
15372  	 	 $fontsize = 0;
15373  	 	 if (!isset($style['text'])) {
15374  	 	 	 $style['text'] = false;
15375  	 	 }
15376  	 	 if ($style['text'] AND isset($style['font'])) {
15377  	 	 	 if (isset($style['fontsize'])) {
15378  	 	 	 	 $fontsize = $style['fontsize'];
15379  	 	 	 }
15380  	 	 	 $this->setFont($style['font'], '', $fontsize);
15381  	 	 }
15382  	 	 if (!isset($style['stretchtext'])) {
15383  	 	 	 $style['stretchtext'] = 4;
15384  	 	 }
15385  	 	 if (TCPDF_STATIC::empty_string($x)) {
15386  	 	 	 $x = $this->x;
15387  	 	 }
15388  	 	 if (TCPDF_STATIC::empty_string($y)) {
15389  	 	 	 $y = $this->y;
15390  	 	 }
15391  	 	 // check page for no-write regions and adapt page margins if necessary
15392  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
15393  	 	 if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
15394  	 	 	 if ($this->rtl) {
15395  	 	 	 	 $w = $x - $this->lMargin;
15396  	 	 	 } else {
15397  	 	 	 	 $w = $this->w - $this->rMargin - $x;
15398  	 	 	 }
15399  	 	 }
15400  	 	 // padding
15401  	 	 if (!isset($style['padding'])) {
15402  	 	 	 $padding = 0;
15403  	 	 } elseif ($style['padding'] === 'auto') {
15404  	 	 	 $padding = 10 * ($w / ($arrcode['maxw'] + 20));
15405  	 	 } else {
15406  	 	 	 $padding = floatval($style['padding']);
15407  	 	 }
15408  	 	 // horizontal padding
15409  	 	 if (!isset($style['hpadding'])) {
15410  	 	 	 $hpadding = $padding;
15411  	 	 } elseif ($style['hpadding'] === 'auto') {
15412  	 	 	 $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
15413  	 	 } else {
15414  	 	 	 $hpadding = floatval($style['hpadding']);
15415  	 	 }
15416  	 	 // vertical padding
15417  	 	 if (!isset($style['vpadding'])) {
15418  	 	 	 $vpadding = $padding;
15419  	 	 } elseif ($style['vpadding'] === 'auto') {
15420  	 	 	 $vpadding = ($hpadding / 2);
15421  	 	 } else {
15422  	 	 	 $vpadding = floatval($style['vpadding']);
15423  	 	 }
15424  	 	 // calculate xres (single bar width)
15425  	 	 $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
15426  	 	 if ($style['stretch']) {
15427  	 	 	 $xres = $max_xres;
15428  	 	 } else {
15429  	 	 	 if (TCPDF_STATIC::empty_string($xres)) {
15430  	 	 	 	 $xres = (0.141 * $this->k); // default bar width = 0.4 mm
15431  	 	 	 }
15432  	 	 	 if ($xres > $max_xres) {
15433  	 	 	 	 // correct xres to fit on $w
15434  	 	 	 	 $xres = $max_xres;
15435  	 	 	 }
15436  	 	 	 if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
15437  	 	 	 	 OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
15438  	 	 	 	 $hpadding = 10 * $xres;
15439  	 	 	 	 if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
15440  	 	 	 	 	 $vpadding = ($hpadding / 2);
15441  	 	 	 	 }
15442  	 	 	 }
15443  	 	 }
15444  	 	 if ($style['fitwidth']) {
15445  	 	 	 $wold = $w;
15446  	 	 	 $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
15447  	 	 	 if (isset($style['cellfitalign'])) {
15448  	 	 	 	 switch ($style['cellfitalign']) {
15449  	 	 	 	 	 case 'L': {
15450  	 	 	 	 	 	 if ($this->rtl) {
15451  	 	 	 	 	 	 	 $x -= ($wold - $w);
15452  	 	 	 	 	 	 }
15453  	 	 	 	 	 	 break;
15454  	 	 	 	 	 }
15455  	 	 	 	 	 case 'R': {
15456  	 	 	 	 	 	 if (!$this->rtl) {
15457  	 	 	 	 	 	 	 $x += ($wold - $w);
15458  	 	 	 	 	 	 }
15459  	 	 	 	 	 	 break;
15460  	 	 	 	 	 }
15461  	 	 	 	 	 case 'C': {
15462  	 	 	 	 	 	 if ($this->rtl) {
15463  	 	 	 	 	 	 	 $x -= (($wold - $w) / 2);
15464  	 	 	 	 	 	 } else {
15465  	 	 	 	 	 	 	 $x += (($wold - $w) / 2);
15466  	 	 	 	 	 	 }
15467  	 	 	 	 	 	 break;
15468  	 	 	 	 	 }
15469  	 	 	 	 	 default : {
15470  	 	 	 	 	 	 break;
15471  	 	 	 	 	 }
15472  	 	 	 	 }
15473  	 	 	 }
15474  	 	 }
15475  	 	 $text_height = $this->getCellHeight($fontsize / $this->k);
15476  	 	 // height
15477  	 	 if (TCPDF_STATIC::empty_string($h) OR ($h <= 0)) {
15478  	 	 	 // set default height
15479  	 	 	 $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
15480  	 	 }
15481  	 	 $barh = $h - $text_height - (2 * $vpadding);
15482  	 	 if ($barh <=0) {
15483  	 	 	 // try to reduce font or padding to fit barcode on available height
15484  	 	 	 if ($text_height > $h) {
15485  	 	 	 	 $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
15486  	 	 	 	 $text_height = $this->getCellHeight($fontsize / $this->k);
15487  	 	 	 	 $this->setFont($style['font'], '', $fontsize);
15488  	 	 	 }
15489  	 	 	 if ($vpadding > 0) {
15490  	 	 	 	 $vpadding = (($h - $text_height) / 4);
15491  	 	 	 }
15492  	 	 	 $barh = $h - $text_height - (2 * $vpadding);
15493  	 	 }
15494  	 	 // fit the barcode on available space
15495  	 	 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
15496  	 	 // set alignment
15497  	 	 $this->img_rb_y = $y + $h;
15498  	 	 // set alignment
15499  	 	 if ($this->rtl) {
15500  	 	 	 if ($style['position'] == 'L') {
15501  	 	 	 	 $xpos = $this->lMargin;
15502  	 	 	 } elseif ($style['position'] == 'C') {
15503  	 	 	 	 $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
15504  	 	 	 } elseif ($style['position'] == 'R') {
15505  	 	 	 	 $xpos = $this->w - $this->rMargin - $w;
15506  	 	 	 } else {
15507  	 	 	 	 $xpos = $x - $w;
15508  	 	 	 }
15509  	 	 	 $this->img_rb_x = $xpos;
15510  	 	 } else {
15511  	 	 	 if ($style['position'] == 'L') {
15512  	 	 	 	 $xpos = $this->lMargin;
15513  	 	 	 } elseif ($style['position'] == 'C') {
15514  	 	 	 	 $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
15515  	 	 	 } elseif ($style['position'] == 'R') {
15516  	 	 	 	 $xpos = $this->w - $this->rMargin - $w;
15517  	 	 	 } else {
15518  	 	 	 	 $xpos = $x;
15519  	 	 	 }
15520  	 	 	 $this->img_rb_x = $xpos + $w;
15521  	 	 }
15522  	 	 $xpos_rect = $xpos;
15523  	 	 if (!isset($style['align'])) {
15524  	 	 	 $style['align'] = 'C';
15525  	 	 }
15526  	 	 switch ($style['align']) {
15527  	 	 	 case 'L': {
15528  	 	 	 	 $xpos = $xpos_rect + $hpadding;
15529  	 	 	 	 break;
15530  	 	 	 }
15531  	 	 	 case 'R': {
15532  	 	 	 	 $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
15533  	 	 	 	 break;
15534  	 	 	 }
15535  	 	 	 case 'C':
15536  	 	 	 default : {
15537  	 	 	 	 $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
15538  	 	 	 	 break;
15539  	 	 	 }
15540  	 	 }
15541  	 	 $xpos_text = $xpos;
15542  	 	 // barcode is always printed in LTR direction
15543  	 	 $tempRTL = $this->rtl;
15544  	 	 $this->rtl = false;
15545  	 	 // print background color
15546  	 	 if ($style['bgcolor']) {
15547  	 	 	 $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
15548  	 	 } elseif ($style['border']) {
15549  	 	 	 $this->Rect($xpos_rect, $y, $w, $h, 'D');
15550  	 	 }
15551  	 	 // set foreground color
15552  	 	 $this->setDrawColorArray($style['fgcolor']);
15553  	 	 $this->setTextColorArray($style['fgcolor']);
15554  	 	 // print bars
15555  	 	 foreach ($arrcode['bcode'] as $k => $v) {
15556  	 	 	 $bw = ($v['w'] * $xres);
15557  	 	 	 if ($v['t']) {
15558  	 	 	 	 // draw a vertical bar
15559  	 	 	 	 $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
15560  	 	 	 	 $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
15561  	 	 	 }
15562  	 	 	 $xpos += $bw;
15563  	 	 }
15564  	 	 // print text
15565  	 	 if ($style['text']) {
15566  	 	 	 if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
15567  	 	 	 	 $label = $style['label'];
15568  	 	 	 } else {
15569  	 	 	 	 $label = $code;
15570  	 	 	 }
15571  	 	 	 $txtwidth = ($arrcode['maxw'] * $xres);
15572  	 	 	 if ($this->GetStringWidth($label) > $txtwidth) {
15573  	 	 	 	 $style['stretchtext'] = 2;
15574  	 	 	 }
15575  	 	 	 // print text
15576  	 	 	 $this->x = $xpos_text;
15577  	 	 	 $this->y = $y + $vpadding + $barh;
15578  	 	 	 $cellpadding = $this->cell_padding;
15579  	 	 	 $this->setCellPadding(0);
15580  	 	 	 $this->Cell($txtwidth, 0, $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
15581  	 	 	 $this->cell_padding = $cellpadding;
15582  	 	 }
15583  	 	 // restore original direction
15584  	 	 $this->rtl = $tempRTL;
15585  	 	 // restore previous settings
15586  	 	 $this->setGraphicVars($gvars);
15587  	 	 // set pointer to align the next text/objects
15588  	 	 switch($align) {
15589  	 	 	 case 'T':{
15590  	 	 	 	 $this->y = $y;
15591  	 	 	 	 $this->x = $this->img_rb_x;
15592  	 	 	 	 break;
15593  	 	 	 }
15594  	 	 	 case 'M':{
15595  	 	 	 	 $this->y = $y + round($h / 2);
15596  	 	 	 	 $this->x = $this->img_rb_x;
15597  	 	 	 	 break;
15598  	 	 	 }
15599  	 	 	 case 'B':{
15600  	 	 	 	 $this->y = $this->img_rb_y;
15601  	 	 	 	 $this->x = $this->img_rb_x;
15602  	 	 	 	 break;
15603  	 	 	 }
15604  	 	 	 case 'N':{
15605  	 	 	 	 $this->setY($this->img_rb_y);
15606  	 	 	 	 break;
15607  	 	 	 }
15608  	 	 	 default:{
15609  	 	 	 	 break;
15610  	 	 	 }
15611  	 	 }
15612  	 	 $this->endlinex = $this->img_rb_x;
15613  	 }
15614  
15615  	 /**
15616  	  * Print 2D Barcode.
15617  	  * @param string $code code to print
15618  	  * @param string $type type of barcode (see tcpdf_barcodes_2d.php for supported formats).
15619  	  * @param float|null $x x position in user units
15620  	  * @param float|null $y y position in user units
15621  	  * @param float|null $w width in user units
15622  	  * @param float|null $h height in user units
15623  	  * @param array $style array of options:<ul>
15624  	  * <li>boolean $style['border'] if true prints a border around the barcode</li>
15625  	  * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
15626  	  * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
15627  	  * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
15628  	  * <li>int $style['module_width'] width of a single module in points</li>
15629  	  * <li>int $style['module_height'] height of a single module in points</li>
15630  	  * <li>array $style['fgcolor'] color array for bars and text</li>
15631  	  * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
15632  	  * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li>
15633  	  * @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>
15634  	  * @param boolean $distort if true distort the barcode to fit width and height, otherwise preserve aspect ratio
15635  	  * @author Nicola Asuni
15636  	  * @since 4.5.037 (2009-04-07)
15637  	  * @public
15638  	  */
15639  	public function write2DBarcode($code, $type, $x=null, $y=null, $w=null, $h=null, $style=array(), $align='', $distort=false) {
15640  	 	 if (TCPDF_STATIC::empty_string(trim($code))) {
15641  	 	 	 return;
15642  	 	 }
15643  	 	 require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
15644  	 	 // save current graphic settings
15645  	 	 $gvars = $this->getGraphicVars();
15646  	 	 // create new barcode object
15647  	 	 $barcodeobj = new TCPDF2DBarcode($code, $type);
15648  	 	 $arrcode = $barcodeobj->getBarcodeArray();
15649  	 	 if (empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
15650  	 	 	 $this->Error('Error in 2D barcode string');
15651  	 	 }
15652  	 	 // set default values
15653  	 	 if (!isset($style['position'])) {
15654  	 	 	 $style['position'] = '';
15655  	 	 }
15656  	 	 if (!isset($style['fgcolor'])) {
15657  	 	 	 $style['fgcolor'] = array(0,0,0); // default black
15658  	 	 }
15659  	 	 if (!isset($style['bgcolor'])) {
15660  	 	 	 $style['bgcolor'] = false; // default transparent
15661  	 	 }
15662  	 	 if (!isset($style['border'])) {
15663  	 	 	 $style['border'] = false;
15664  	 	 }
15665  	 	 // padding
15666  	 	 if (!isset($style['padding'])) {
15667  	 	 	 $style['padding'] = 0;
15668  	 	 } elseif ($style['padding'] === 'auto') {
15669  	 	 	 $style['padding'] = 4;
15670  	 	 }
15671  	 	 if (!isset($style['hpadding'])) {
15672  	 	 	 $style['hpadding'] = $style['padding'];
15673  	 	 } elseif ($style['hpadding'] === 'auto') {
15674  	 	 	 $style['hpadding'] = 4;
15675  	 	 }
15676  	 	 if (!isset($style['vpadding'])) {
15677  	 	 	 $style['vpadding'] = $style['padding'];
15678  	 	 } elseif ($style['vpadding'] === 'auto') {
15679  	 	 	 $style['vpadding'] = 4;
15680  	 	 }
15681  	 	 $hpad = (2 * $style['hpadding']);
15682  	 	 $vpad = (2 * $style['vpadding']);
15683  	 	 // cell (module) dimension
15684  	 	 if (!isset($style['module_width'])) {
15685  	 	 	 $style['module_width'] = 1; // width of a single module in points
15686  	 	 }
15687  	 	 if (!isset($style['module_height'])) {
15688  	 	 	 $style['module_height'] = 1; // height of a single module in points
15689  	 	 }
15690  	 	 if (TCPDF_STATIC::empty_string($x)) {
15691  	 	 	 $x = $this->x;
15692  	 	 }
15693  	 	 if (TCPDF_STATIC::empty_string($y)) {
15694  	 	 	 $y = $this->y;
15695  	 	 }
15696  	 	 // check page for no-write regions and adapt page margins if necessary
15697  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
15698  	 	 // number of barcode columns and rows
15699  	 	 $rows = $arrcode['num_rows'];
15700  	 	 $cols = $arrcode['num_cols'];
15701  	 	 if (($rows <= 0) || ($cols <= 0)){
15702  	 	 	 $this->Error('Error in 2D barcode string');
15703  	 	 }
15704  	 	 // module width and height
15705  	 	 $mw = $style['module_width'];
15706  	 	 $mh = $style['module_height'];
15707  	 	 if (($mw <= 0) OR ($mh <= 0)) {
15708  	 	 	 $this->Error('Error in 2D barcode string');
15709  	 	 }
15710  	 	 // get max dimensions
15711  	 	 if ($this->rtl) {
15712  	 	 	 $maxw = $x - $this->lMargin;
15713  	 	 } else {
15714  	 	 	 $maxw = $this->w - $this->rMargin - $x;
15715  	 	 }
15716  	 	 $maxh = ($this->h - $this->tMargin - $this->bMargin);
15717  	 	 $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
15718  	 	 $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
15719  	 	 if (!$distort) {
15720  	 	 	 if (($maxw * $ratioHW) > $maxh) {
15721  	 	 	 	 $maxw = $maxh * $ratioWH;
15722  	 	 	 }
15723  	 	 	 if (($maxh * $ratioWH) > $maxw) {
15724  	 	 	 	 $maxh = $maxw * $ratioHW;
15725  	 	 	 }
15726  	 	 }
15727  	 	 // set maximum dimensions
15728  	 	 if ($w > $maxw) {
15729  	 	 	 $w = $maxw;
15730  	 	 }
15731  	 	 if ($h > $maxh) {
15732  	 	 	 $h = $maxh;
15733  	 	 }
15734  	 	 // set dimensions
15735  	 	 if ((TCPDF_STATIC::empty_string($w) OR ($w <= 0)) AND (TCPDF_STATIC::empty_string($h) OR ($h <= 0))) {
15736  	 	 	 $w = ($cols + $hpad) * ($mw / $this->k);
15737  	 	 	 $h = ($rows + $vpad) * ($mh / $this->k);
15738  	 	 } elseif (($w === '') OR ($w <= 0)) {
15739  	 	 	 $w = $h * $ratioWH;
15740  	 	 } elseif (($h === '') OR ($h <= 0)) {
15741  	 	 	 $h = $w * $ratioHW;
15742  	 	 }
15743  	 	 // barcode size (excluding padding)
15744  	 	 $bw = ($w * $cols) / ($cols + $hpad);
15745  	 	 $bh = ($h * $rows) / ($rows + $vpad);
15746  	 	 // dimension of single barcode cell unit
15747  	 	 $cw = $bw / $cols;
15748  	 	 $ch = $bh / $rows;
15749  	 	 if (!$distort) {
15750  	 	 	 if (($cw / $ch) > ($mw / $mh)) {
15751  	 	 	 	 // correct horizontal distortion
15752  	 	 	 	 $cw = $ch * $mw / $mh;
15753  	 	 	 	 $bw = $cw * $cols;
15754  	 	 	 	 $style['hpadding'] = ($w - $bw) / (2 * $cw);
15755  	 	 	 } else {
15756  	 	 	 	 // correct vertical distortion
15757  	 	 	 	 $ch = $cw * $mh / $mw;
15758  	 	 	 	 $bh = $ch * $rows;
15759  	 	 	 	 $style['vpadding'] = ($h - $bh) / (2 * $ch);
15760  	 	 	 }
15761  	 	 }
15762  	 	 // fit the barcode on available space
15763  	 	 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
15764  	 	 // set alignment
15765  	 	 $this->img_rb_y = $y + $h;
15766  	 	 // set alignment
15767  	 	 if ($this->rtl) {
15768  	 	 	 if ($style['position'] == 'L') {
15769  	 	 	 	 $xpos = $this->lMargin;
15770  	 	 	 } elseif ($style['position'] == 'C') {
15771  	 	 	 	 $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
15772  	 	 	 } elseif ($style['position'] == 'R') {
15773  	 	 	 	 $xpos = $this->w - $this->rMargin - $w;
15774  	 	 	 } else {
15775  	 	 	 	 $xpos = $x - $w;
15776  	 	 	 }
15777  	 	 	 $this->img_rb_x = $xpos;
15778  	 	 } else {
15779  	 	 	 if ($style['position'] == 'L') {
15780  	 	 	 	 $xpos = $this->lMargin;
15781  	 	 	 } elseif ($style['position'] == 'C') {
15782  	 	 	 	 $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
15783  	 	 	 } elseif ($style['position'] == 'R') {
15784  	 	 	 	 $xpos = $this->w - $this->rMargin - $w;
15785  	 	 	 } else {
15786  	 	 	 	 $xpos = $x;
15787  	 	 	 }
15788  	 	 	 $this->img_rb_x = $xpos + $w;
15789  	 	 }
15790  	 	 $xstart = $xpos + ($style['hpadding'] * $cw);
15791  	 	 $ystart = $y + ($style['vpadding'] * $ch);
15792  	 	 // barcode is always printed in LTR direction
15793  	 	 $tempRTL = $this->rtl;
15794  	 	 $this->rtl = false;
15795  	 	 // print background color
15796  	 	 if ($style['bgcolor']) {
15797  	 	 	 $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
15798  	 	 } elseif ($style['border']) {
15799  	 	 	 $this->Rect($xpos, $y, $w, $h, 'D');
15800  	 	 }
15801  	 	 // set foreground color
15802  	 	 $this->setDrawColorArray($style['fgcolor']);
15803  	 	 // print barcode cells
15804  	 	 // for each row
15805  	 	 for ($r = 0; $r < $rows; ++$r) {
15806  	 	 	 $xr = $xstart;
15807  	 	 	 // for each column
15808  	 	 	 for ($c = 0; $c < $cols; ++$c) {
15809  	 	 	 	 if ($arrcode['bcode'][$r][$c] == 1) {
15810  	 	 	 	 	 // draw a single barcode cell
15811  	 	 	 	 	 $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
15812  	 	 	 	 }
15813  	 	 	 	 $xr += $cw;
15814  	 	 	 }
15815  	 	 	 $ystart += $ch;
15816  	 	 }
15817  	 	 // restore original direction
15818  	 	 $this->rtl = $tempRTL;
15819  	 	 // restore previous settings
15820  	 	 $this->setGraphicVars($gvars);
15821  	 	 // set pointer to align the next text/objects
15822  	 	 switch($align) {
15823  	 	 	 case 'T':{
15824  	 	 	 	 $this->y = $y;
15825  	 	 	 	 $this->x = $this->img_rb_x;
15826  	 	 	 	 break;
15827  	 	 	 }
15828  	 	 	 case 'M':{
15829  	 	 	 	 $this->y = $y + round($h/2);
15830  	 	 	 	 $this->x = $this->img_rb_x;
15831  	 	 	 	 break;
15832  	 	 	 }
15833  	 	 	 case 'B':{
15834  	 	 	 	 $this->y = $this->img_rb_y;
15835  	 	 	 	 $this->x = $this->img_rb_x;
15836  	 	 	 	 break;
15837  	 	 	 }
15838  	 	 	 case 'N':{
15839  	 	 	 	 $this->setY($this->img_rb_y);
15840  	 	 	 	 break;
15841  	 	 	 }
15842  	 	 	 default:{
15843  	 	 	 	 break;
15844  	 	 	 }
15845  	 	 }
15846  	 	 $this->endlinex = $this->img_rb_x;
15847  	 }
15848  
15849  	 /**
15850  	  * Returns an array containing current margins:
15851  	  * <ul>
15852  	 	 	 <li>$ret['left'] = left margin</li>
15853  	 	 	 <li>$ret['right'] = right margin</li>
15854  	 	 	 <li>$ret['top'] = top margin</li>
15855  	 	 	 <li>$ret['bottom'] = bottom margin</li>
15856  	 	 	 <li>$ret['header'] = header margin</li>
15857  	 	 	 <li>$ret['footer'] = footer margin</li>
15858  	 	 	 <li>$ret['cell'] = cell padding array</li>
15859  	 	 	 <li>$ret['padding_left'] = cell left padding</li>
15860  	 	 	 <li>$ret['padding_top'] = cell top padding</li>
15861  	 	 	 <li>$ret['padding_right'] = cell right padding</li>
15862  	 	 	 <li>$ret['padding_bottom'] = cell bottom padding</li>
15863  	  * </ul>
15864  	  * @return array containing all margins measures
15865  	  * @public
15866  	  * @since 3.2.000 (2008-06-23)
15867  	  */
15868  	public function getMargins() {
15869  	 	 $ret = array(
15870  	 	 	 'left' => $this->lMargin,
15871  	 	 	 'right' => $this->rMargin,
15872  	 	 	 'top' => $this->tMargin,
15873  	 	 	 'bottom' => $this->bMargin,
15874  	 	 	 'header' => $this->header_margin,
15875  	 	 	 'footer' => $this->footer_margin,
15876  	 	 	 'cell' => $this->cell_padding,
15877  	 	 	 'padding_left' => $this->cell_padding['L'],
15878  	 	 	 'padding_top' => $this->cell_padding['T'],
15879  	 	 	 'padding_right' => $this->cell_padding['R'],
15880  	 	 	 'padding_bottom' => $this->cell_padding['B']
15881  	 	 );
15882  	 	 return $ret;
15883  	 }
15884  
15885  	 /**
15886  	  * Returns an array containing original margins:
15887  	  * <ul>
15888  	 	 	 <li>$ret['left'] = left margin</li>
15889  	 	 	 <li>$ret['right'] = right margin</li>
15890  	  * </ul>
15891  	  * @return array containing all margins measures
15892  	  * @public
15893  	  * @since 4.0.012 (2008-07-24)
15894  	  */
15895  	public function getOriginalMargins() {
15896  	 	 $ret = array(
15897  	 	 	 'left' => $this->original_lMargin,
15898  	 	 	 'right' => $this->original_rMargin
15899  	 	 );
15900  	 	 return $ret;
15901  	 }
15902  
15903  	 /**
15904  	  * Returns the current font size.
15905  	  * @return float current font size
15906  	  * @public
15907  	  * @since 3.2.000 (2008-06-23)
15908  	  */
15909  	public function getFontSize() {
15910  	 	 return $this->FontSize;
15911  	 }
15912  
15913  	 /**
15914  	  * Returns the current font size in points unit.
15915  	  * @return int current font size in points unit
15916  	  * @public
15917  	  * @since 3.2.000 (2008-06-23)
15918  	  */
15919  	public function getFontSizePt() {
15920  	 	 return $this->FontSizePt;
15921  	 }
15922  
15923  	 /**
15924  	  * Returns the current font family name.
15925  	  * @return string current font family name
15926  	  * @public
15927  	  * @since 4.3.008 (2008-12-05)
15928  	  */
15929  	public function getFontFamily() {
15930  	 	 return $this->FontFamily;
15931  	 }
15932  
15933  	 /**
15934  	  * Returns the current font style.
15935  	  * @return string current font style
15936  	  * @public
15937  	  * @since 4.3.008 (2008-12-05)
15938  	  */
15939  	public function getFontStyle() {
15940  	 	 return $this->FontStyle;
15941  	 }
15942  
15943  	 /**
15944  	  * Cleanup HTML code (requires HTML Tidy library).
15945  	  * @param string $html htmlcode to fix
15946  	  * @param string $default_css CSS commands to add
15947  	  * @param array|null $tagvs parameters for setHtmlVSpace method
15948  	  * @param array|null $tidy_options options for tidy_parse_string function
15949  	  * @return string XHTML code cleaned up
15950  	  * @author Nicola Asuni
15951  	  * @public
15952  	  * @since 5.9.017 (2010-11-16)
15953  	  * @see setHtmlVSpace()
15954  	  */
15955  	public function fixHTMLCode($html, $default_css='', $tagvs=null, $tidy_options=null) {
15956  	 	 return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
15957  	 }
15958  
15959  	 /**
15960  	  * Returns the border width from CSS property
15961  	  * @param string $width border width
15962  	  * @return int with in user units
15963  	  * @protected
15964  	  * @since 5.7.000 (2010-08-02)
15965  	  */
15966  	protected function getCSSBorderWidth($width) {
15967  	 	 if ($width == 'thin') {
15968  	 	 	 $width = (2 / $this->k);
15969  	 	 } elseif ($width == 'medium') {
15970  	 	 	 $width = (4 / $this->k);
15971  	 	 } elseif ($width == 'thick') {
15972  	 	 	 $width = (6 / $this->k);
15973  	 	 } else {
15974  	 	 	 $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
15975  	 	 }
15976  	 	 return $width;
15977  	 }
15978  
15979  	 /**
15980  	  * Returns the border dash style from CSS property
15981  	  * @param string $style border style to convert
15982  	  * @return int sash style (return -1 in case of none or hidden border)
15983  	  * @protected
15984  	  * @since 5.7.000 (2010-08-02)
15985  	  */
15986  	protected function getCSSBorderDashStyle($style) {
15987  	 	 switch (strtolower($style)) {
15988  	 	 	 case 'none':
15989  	 	 	 case 'hidden': {
15990  	 	 	 	 $dash = -1;
15991  	 	 	 	 break;
15992  	 	 	 }
15993  	 	 	 case 'dotted': {
15994  	 	 	 	 $dash = 1;
15995  	 	 	 	 break;
15996  	 	 	 }
15997  	 	 	 case 'dashed': {
15998  	 	 	 	 $dash = 3;
15999  	 	 	 	 break;
16000  	 	 	 }
16001  	 	 	 case 'double':
16002  	 	 	 case 'groove':
16003  	 	 	 case 'ridge':
16004  	 	 	 case 'inset':
16005  	 	 	 case 'outset':
16006  	 	 	 case 'solid':
16007  	 	 	 default: {
16008  	 	 	 	 $dash = 0;
16009  	 	 	 	 break;
16010  	 	 	 }
16011  	 	 }
16012  	 	 return $dash;
16013  	 }
16014  
16015  	 /**
16016  	  * Returns the border style array from CSS border properties
16017  	  * @param string $cssborder border properties
16018  	  * @return array containing border properties
16019  	  * @protected
16020  	  * @since 5.7.000 (2010-08-02)
16021  	  */
16022  	protected function getCSSBorderStyle($cssborder) {
16023  	 	 $bprop = preg_split('/[\s]+/', trim($cssborder));
16024  	 	 $count = count($bprop);
16025  	 	 if ($count > 0 && $bprop[$count - 1] === '!important') {
16026  	 	 	 unset($bprop[$count - 1]);
16027  	 	 	 --$count;
16028  	 	 }
16029  
16030  	 	 $border = array(); // value to be returned
16031  	 	 switch ($count) {
16032  	 	 	 case 2: {
16033  	 	 	 	 $width = 'medium';
16034  	 	 	 	 $style = $bprop[0];
16035  	 	 	 	 $color = $bprop[1];
16036  	 	 	 	 break;
16037  	 	 	 }
16038  	 	 	 case 1: {
16039  	 	 	 	 $width = 'medium';
16040  	 	 	 	 $style = $bprop[0];
16041  	 	 	 	 $color = 'black';
16042  	 	 	 	 break;
16043  	 	 	 }
16044  	 	 	 case 0: {
16045  	 	 	 	 $width = 'medium';
16046  	 	 	 	 $style = 'solid';
16047  	 	 	 	 $color = 'black';
16048  	 	 	 	 break;
16049  	 	 	 }
16050  	 	 	 default: {
16051  	 	 	 	 $width = $bprop[0];
16052  	 	 	 	 $style = $bprop[1];
16053  	 	 	 	 $color = $bprop[2];
16054  	 	 	 	 break;
16055  	 	 	 }
16056  	 	 }
16057  	 	 if ($style == 'none') {
16058  	 	 	 return array();
16059  	 	 }
16060  	 	 $border['cap'] = 'square';
16061  	 	 $border['join'] = 'miter';
16062  	 	 $border['dash'] = $this->getCSSBorderDashStyle($style);
16063  	 	 if ($border['dash'] < 0) {
16064  	 	 	 return array();
16065  	 	 }
16066  	 	 $border['width'] = $this->getCSSBorderWidth($width);
16067  	 	 $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
16068  	 	 return $border;
16069  	 }
16070  
16071  	 /**
16072  	  * Get the internal Cell padding from CSS attribute.
16073  	  * @param string $csspadding padding properties
16074  	  * @param float $width width of the containing element
16075  	  * @return array of cell paddings
16076  	  * @public
16077  	  * @since 5.9.000 (2010-10-04)
16078  	  */
16079  	public function getCSSPadding($csspadding, $width=0) {
16080  	 	 $padding = preg_split('/[\s]+/', trim($csspadding));
16081  	 	 $cell_padding = array(); // value to be returned
16082  	 	 switch (count($padding)) {
16083  	 	 	 case 4: {
16084  	 	 	 	 $cell_padding['T'] = $padding[0];
16085  	 	 	 	 $cell_padding['R'] = $padding[1];
16086  	 	 	 	 $cell_padding['B'] = $padding[2];
16087  	 	 	 	 $cell_padding['L'] = $padding[3];
16088  	 	 	 	 break;
16089  	 	 	 }
16090  	 	 	 case 3: {
16091  	 	 	 	 $cell_padding['T'] = $padding[0];
16092  	 	 	 	 $cell_padding['R'] = $padding[1];
16093  	 	 	 	 $cell_padding['B'] = $padding[2];
16094  	 	 	 	 $cell_padding['L'] = $padding[1];
16095  	 	 	 	 break;
16096  	 	 	 }
16097  	 	 	 case 2: {
16098  	 	 	 	 $cell_padding['T'] = $padding[0];
16099  	 	 	 	 $cell_padding['R'] = $padding[1];
16100  	 	 	 	 $cell_padding['B'] = $padding[0];
16101  	 	 	 	 $cell_padding['L'] = $padding[1];
16102  	 	 	 	 break;
16103  	 	 	 }
16104  	 	 	 case 1: {
16105  	 	 	 	 $cell_padding['T'] = $padding[0];
16106  	 	 	 	 $cell_padding['R'] = $padding[0];
16107  	 	 	 	 $cell_padding['B'] = $padding[0];
16108  	 	 	 	 $cell_padding['L'] = $padding[0];
16109  	 	 	 	 break;
16110  	 	 	 }
16111  	 	 	 default: {
16112  	 	 	 	 return $this->cell_padding;
16113  	 	 	 }
16114  	 	 }
16115  	 	 if ($width == 0) {
16116  	 	 	 $width = $this->w - $this->lMargin - $this->rMargin;
16117  	 	 }
16118  	 	 $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
16119  	 	 $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
16120  	 	 $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
16121  	 	 $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
16122  	 	 return $cell_padding;
16123  	 }
16124  
16125  	 /**
16126  	  * Get the internal Cell margin from CSS attribute.
16127  	  * @param string $cssmargin margin properties
16128  	  * @param float $width width of the containing element
16129  	  * @return array of cell margins
16130  	  * @public
16131  	  * @since 5.9.000 (2010-10-04)
16132  	  */
16133  	public function getCSSMargin($cssmargin, $width=0) {
16134  	 	 $margin = preg_split('/[\s]+/', trim($cssmargin));
16135  	 	 $cell_margin = array(); // value to be returned
16136  	 	 switch (count($margin)) {
16137  	 	 	 case 4: {
16138  	 	 	 	 $cell_margin['T'] = $margin[0];
16139  	 	 	 	 $cell_margin['R'] = $margin[1];
16140  	 	 	 	 $cell_margin['B'] = $margin[2];
16141  	 	 	 	 $cell_margin['L'] = $margin[3];
16142  	 	 	 	 break;
16143  	 	 	 }
16144  	 	 	 case 3: {
16145  	 	 	 	 $cell_margin['T'] = $margin[0];
16146  	 	 	 	 $cell_margin['R'] = $margin[1];
16147  	 	 	 	 $cell_margin['B'] = $margin[2];
16148  	 	 	 	 $cell_margin['L'] = $margin[1];
16149  	 	 	 	 break;
16150  	 	 	 }
16151  	 	 	 case 2: {
16152  	 	 	 	 $cell_margin['T'] = $margin[0];
16153  	 	 	 	 $cell_margin['R'] = $margin[1];
16154  	 	 	 	 $cell_margin['B'] = $margin[0];
16155  	 	 	 	 $cell_margin['L'] = $margin[1];
16156  	 	 	 	 break;
16157  	 	 	 }
16158  	 	 	 case 1: {
16159  	 	 	 	 $cell_margin['T'] = $margin[0];
16160  	 	 	 	 $cell_margin['R'] = $margin[0];
16161  	 	 	 	 $cell_margin['B'] = $margin[0];
16162  	 	 	 	 $cell_margin['L'] = $margin[0];
16163  	 	 	 	 break;
16164  	 	 	 }
16165  	 	 	 default: {
16166  	 	 	 	 return $this->cell_margin;
16167  	 	 	 }
16168  	 	 }
16169  	 	 if ($width == 0) {
16170  	 	 	 $width = $this->w - $this->lMargin - $this->rMargin;
16171  	 	 }
16172  	 	 $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
16173  	 	 $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
16174  	 	 $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
16175  	 	 $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
16176  	 	 return $cell_margin;
16177  	 }
16178  
16179  	 /**
16180  	  * Get the border-spacing from CSS attribute.
16181  	  * @param string $cssbspace border-spacing CSS properties
16182  	  * @param float $width width of the containing element
16183  	  * @return array of border spacings
16184  	  * @public
16185  	  * @since 5.9.010 (2010-10-27)
16186  	  */
16187  	public function getCSSBorderMargin($cssbspace, $width=0) {
16188  	 	 $space = preg_split('/[\s]+/', trim($cssbspace));
16189  	 	 $border_spacing = array(); // value to be returned
16190  	 	 switch (count($space)) {
16191  	 	 	 case 2: {
16192  	 	 	 	 $border_spacing['H'] = $space[0];
16193  	 	 	 	 $border_spacing['V'] = $space[1];
16194  	 	 	 	 break;
16195  	 	 	 }
16196  	 	 	 case 1: {
16197  	 	 	 	 $border_spacing['H'] = $space[0];
16198  	 	 	 	 $border_spacing['V'] = $space[0];
16199  	 	 	 	 break;
16200  	 	 	 }
16201  	 	 	 default: {
16202  	 	 	 	 return array('H' => 0, 'V' => 0);
16203  	 	 	 }
16204  	 	 }
16205  	 	 if ($width == 0) {
16206  	 	 	 $width = $this->w - $this->lMargin - $this->rMargin;
16207  	 	 }
16208  	 	 $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
16209  	 	 $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
16210  	 	 return $border_spacing;
16211  	 }
16212  
16213  	 /**
16214  	  * Returns the letter-spacing value from CSS value
16215  	  * @param string $spacing letter-spacing value
16216  	  * @param float $parent font spacing (tracking) value of the parent element
16217  	  * @return float quantity to increases or decreases the space between characters in a text.
16218  	  * @protected
16219  	  * @since 5.9.000 (2010-10-02)
16220  	  */
16221  	protected function getCSSFontSpacing($spacing, $parent=0) {
16222  	 	 $val = 0; // value to be returned
16223  	 	 $spacing = trim($spacing);
16224  	 	 switch ($spacing) {
16225  	 	 	 case 'normal': {
16226  	 	 	 	 $val = 0;
16227  	 	 	 	 break;
16228  	 	 	 }
16229  	 	 	 case 'inherit': {
16230  	 	 	 	 if ($parent == 'normal') {
16231  	 	 	 	 	 $val = 0;
16232  	 	 	 	 } else {
16233  	 	 	 	 	 $val = $parent;
16234  	 	 	 	 }
16235  	 	 	 	 break;
16236  	 	 	 }
16237  	 	 	 default: {
16238  	 	 	 	 $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
16239  	 	 	 }
16240  	 	 }
16241  	 	 return $val;
16242  	 }
16243  
16244  	 /**
16245  	  * Returns the percentage of font stretching from CSS value
16246  	  * @param string $stretch stretch mode
16247  	  * @param float $parent stretch value of the parent element
16248  	  * @return float font stretching percentage
16249  	  * @protected
16250  	  * @since 5.9.000 (2010-10-02)
16251  	  */
16252  	protected function getCSSFontStretching($stretch, $parent=100) {
16253  	 	 $val = 100; // value to be returned
16254  	 	 $stretch = trim($stretch);
16255  	 	 switch ($stretch) {
16256  	 	 	 case 'ultra-condensed': {
16257  	 	 	 	 $val = 40;
16258  	 	 	 	 break;
16259  	 	 	 }
16260  	 	 	 case 'extra-condensed': {
16261  	 	 	 	 $val = 55;
16262  	 	 	 	 break;
16263  	 	 	 }
16264  	 	 	 case 'condensed': {
16265  	 	 	 	 $val = 70;
16266  	 	 	 	 break;
16267  	 	 	 }
16268  	 	 	 case 'semi-condensed': {
16269  	 	 	 	 $val = 85;
16270  	 	 	 	 break;
16271  	 	 	 }
16272  	 	 	 case 'normal': {
16273  	 	 	 	 $val = 100;
16274  	 	 	 	 break;
16275  	 	 	 }
16276  	 	 	 case 'semi-expanded': {
16277  	 	 	 	 $val = 115;
16278  	 	 	 	 break;
16279  	 	 	 }
16280  	 	 	 case 'expanded': {
16281  	 	 	 	 $val = 130;
16282  	 	 	 	 break;
16283  	 	 	 }
16284  	 	 	 case 'extra-expanded': {
16285  	 	 	 	 $val = 145;
16286  	 	 	 	 break;
16287  	 	 	 }
16288  	 	 	 case 'ultra-expanded': {
16289  	 	 	 	 $val = 160;
16290  	 	 	 	 break;
16291  	 	 	 }
16292  	 	 	 case 'wider': {
16293  	 	 	 	 $val = ($parent + 10);
16294  	 	 	 	 break;
16295  	 	 	 }
16296  	 	 	 case 'narrower': {
16297  	 	 	 	 $val = ($parent - 10);
16298  	 	 	 	 break;
16299  	 	 	 }
16300  	 	 	 case 'inherit': {
16301  	 	 	 	 if ($parent == 'normal') {
16302  	 	 	 	 	 $val = 100;
16303  	 	 	 	 } else {
16304  	 	 	 	 	 $val = $parent;
16305  	 	 	 	 }
16306  	 	 	 	 break;
16307  	 	 	 }
16308  	 	 	 default: {
16309  	 	 	 	 $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
16310  	 	 	 }
16311  	 	 }
16312  	 	 return $val;
16313  	 }
16314  
16315  	 /**
16316  	  * Convert HTML string containing font size value to points
16317  	  * @param string $val String containing font size value and unit.
16318  	  * @param float $refsize Reference font size in points.
16319  	  * @param float $parent_size Parent font size in points.
16320  	  * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
16321  	  * @return float value in points
16322  	  * @public
16323  	  */
16324  	public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
16325  	 	 $refsize = TCPDF_FONTS::getFontRefSize($refsize);
16326  	 	 $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
16327  	 	 switch ($val) {
16328  	 	 	 case 'xx-small': {
16329  	 	 	 	 $size = ($refsize - 4);
16330  	 	 	 	 break;
16331  	 	 	 }
16332  	 	 	 case 'x-small': {
16333  	 	 	 	 $size = ($refsize - 3);
16334  	 	 	 	 break;
16335  	 	 	 }
16336  	 	 	 case 'small': {
16337  	 	 	 	 $size = ($refsize - 2);
16338  	 	 	 	 break;
16339  	 	 	 }
16340  	 	 	 case 'medium': {
16341  	 	 	 	 $size = $refsize;
16342  	 	 	 	 break;
16343  	 	 	 }
16344  	 	 	 case 'large': {
16345  	 	 	 	 $size = ($refsize + 2);
16346  	 	 	 	 break;
16347  	 	 	 }
16348  	 	 	 case 'x-large': {
16349  	 	 	 	 $size = ($refsize + 4);
16350  	 	 	 	 break;
16351  	 	 	 }
16352  	 	 	 case 'xx-large': {
16353  	 	 	 	 $size = ($refsize + 6);
16354  	 	 	 	 break;
16355  	 	 	 }
16356  	 	 	 case 'smaller': {
16357  	 	 	 	 $size = ($parent_size - 3);
16358  	 	 	 	 break;
16359  	 	 	 }
16360  	 	 	 case 'larger': {
16361  	 	 	 	 $size = ($parent_size + 3);
16362  	 	 	 	 break;
16363  	 	 	 }
16364  	 	 	 default: {
16365  	 	 	 	 $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
16366  	 	 	 }
16367  	 	 }
16368  	 	 return $size;
16369  	 }
16370  
16371  	 /**
16372  	  * Returns the HTML DOM array.
16373  	  * @param string $html html code
16374  	  * @return array
16375  	  * @protected
16376  	  * @since 3.2.000 (2008-06-20)
16377  	  */
16378  	protected function getHtmlDomArray($html) {
16379  	 	 // array of CSS styles ( selector => properties).
16380  	 	 $css = array();
16381  	 	 // get CSS array defined at previous call
16382  	 	 $matches = array();
16383  	 	 if (preg_match_all('/<cssarray>([^\<]*?)<\/cssarray>/is', $html, $matches) > 0) {
16384  	 	 	 if (isset($matches[1][0])) {
16385  	 	 	 	 $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
16386  	 	 	 }
16387  	 	 	 $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/is', '', $html);
16388  	 	 }
16389  	 	 // extract external CSS files
16390  	 	 $matches = array();
16391  	 	 if (preg_match_all('/<link([^\>]*?)>/is', $html, $matches) > 0) {
16392  	 	 	 foreach ($matches[1] as $key => $link) {
16393  	 	 	 	 $type = array();
16394  	 	 	 	 if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
16395  	 	 	 	 	 $type = array();
16396  	 	 	 	 	 preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
16397  	 	 	 	 	 // get 'all' and 'print' media, other media types are discarded
16398  	 	 	 	 	 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
16399  	 	 	 	 	 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
16400  	 	 	 	 	 	 $type = array();
16401  	 	 	 	 	 	 if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
16402  	 	 	 	 	 	 	 // read CSS data file
16403                              $cssdata = $this->getCachedFileContents(trim($type[1]));
16404  	 	 	 	 	 	 	 if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
16405  	 	 	 	 	 	 	 	 $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
16406  	 	 	 	 	 	 	 }
16407  	 	 	 	 	 	 }
16408  	 	 	 	 	 }
16409  	 	 	 	 }
16410  	 	 	 }
16411  	 	 }
16412  	 	 // extract style tags
16413  	 	 $matches = array();
16414  	 	 if (preg_match_all('/<style([^\>]*?)>([^\<]*?)<\/style>/is', $html, $matches) > 0) {
16415  	 	 	 foreach ($matches[1] as $key => $media) {
16416  	 	 	 	 $type = array();
16417  	 	 	 	 preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
16418  	 	 	 	 // get 'all' and 'print' media, other media types are discarded
16419  	 	 	 	 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
16420  	 	 	 	 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
16421  	 	 	 	 	 $cssdata = $matches[2][$key];
16422  	 	 	 	 	 $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
16423  	 	 	 	 }
16424  	 	 	 }
16425  	 	 }
16426  	 	 // create a special tag to contain the CSS array (used for table content)
16427  	 	 $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
16428  	 	 // remove head and style blocks
16429  	 	 $html = preg_replace('/<head([^\>]*?)>(.*?)<\/head>/is', '', $html);
16430  	 	 $html = preg_replace('/<style([^\>]*?)>([^\<]*?)<\/style>/is', '', $html);
16431  	 	 // define block tags
16432  	 	 $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
16433  	 	 // define self-closing tags
16434  	 	 $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
16435  	 	 // remove all unsupported tags (the line below lists all supported tags)
16436  	 	 $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>');
16437  	 	 //replace some blank characters
16438  	 	 $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
16439  	 	 $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);
16440  	 	 $html = preg_replace('@(\r\n|\r)@', "\n", $html);
16441  	 	 $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
16442  	 	 $html = strtr($html, $repTable);
16443  	 	 $offset = 0;
16444  	 	 while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
16445  	 	 	 $html_a = substr($html, 0, $offset);
16446  	 	 	 $html_b = substr($html, $offset, ($pos - $offset + 6));
16447  	 	 	 while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
16448  	 	 	 	 // preserve newlines on <pre> tag
16449  	 	 	 	 $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
16450  	 	 	 }
16451  	 	 	 while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
16452  	 	 	 	 // preserve spaces on <pre> tag
16453  	 	 	 	 $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
16454  	 	 	 }
16455  	 	 	 $html = $html_a.$html_b.substr($html, $pos + 6);
16456  	 	 	 $offset = strlen($html_a.$html_b);
16457  	 	 }
16458  	 	 $offset = 0;
16459  	 	 while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
16460  	 	 	 $html_a = substr($html, 0, $offset);
16461  	 	 	 $html_b = substr($html, $offset, ($pos - $offset + 11));
16462  	 	 	 while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
16463  	 	 	 	 // preserve newlines on <textarea> tag
16464  	 	 	 	 $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
16465  	 	 	 	 $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
16466  	 	 	 }
16467  	 	 	 $html = $html_a.$html_b.substr($html, $pos + 11);
16468  	 	 	 $offset = strlen($html_a.$html_b);
16469  	 	 }
16470  	 	 $html = preg_replace('/([\s]*)<option/si', '<option', $html);
16471  	 	 $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
16472  	 	 $offset = 0;
16473  	 	 while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
16474  	 	 	 $html_a = substr($html, 0, $offset);
16475  	 	 	 $html_b = substr($html, $offset, ($pos - $offset + 9));
16476  	 	 	 while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
16477  	 	 	 	 $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
16478  	 	 	 	 $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
16479  	 	 	 }
16480  	 	 	 $html = $html_a.$html_b.substr($html, $pos + 9);
16481  	 	 	 $offset = strlen($html_a.$html_b);
16482  	 	 }
16483  	 	 if (preg_match("'</select'si", $html)) {
16484  	 	 	 $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
16485  	 	 	 $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
16486  	 	 }
16487  	 	 $html = str_replace("\n", ' ', $html);
16488  	 	 // restore textarea newlines
16489  	 	 $html = str_replace('<TBR>', "\n", $html);
16490  	 	 // remove extra spaces from code
16491  	 	 $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
16492  	 	 $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
16493  	 	 $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
16494  	 	 $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
16495  	 	 $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);
16496  	 	 $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
16497  	 	 $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
16498  	 	 $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
16499  	 	 $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
16500  	 	 $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
16501  	 	 $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
16502  	 	 $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
16503  	 	 $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
16504  	 	 $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
16505  	 	 $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
16506  	 	 $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
16507  	 	 $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
16508  	 	 $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
16509  	 	 $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
16510  	 	 // trim string
16511  	 	 $html = $this->stringTrim($html);
16512  	 	 // fix br tag after li
16513  	 	 $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
16514  	 	 // fix first image tag alignment
16515  	 	 $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
16516  	 	 // pattern for generic tag
16517  	 	 $tagpattern = '/(<[^>]+>)/';
16518  	 	 // explodes the string
16519  	 	 $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
16520  	 	 // count elements
16521  	 	 $maxel = count($a);
16522  	 	 $elkey = 0;
16523  	 	 $key = 0;
16524  	 	 // create an array of elements
16525  	 	 $dom = array();
16526  	 	 $dom[$key] = array();
16527  	 	 // set inheritable properties fot the first void element
16528  	 	 // 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
16529  	 	 $dom[$key]['tag'] = false;
16530  	 	 $dom[$key]['block'] = false;
16531  	 	 $dom[$key]['value'] = '';
16532  	 	 $dom[$key]['parent'] = 0;
16533  	 	 $dom[$key]['hide'] = false;
16534  	 	 $dom[$key]['fontname'] = $this->FontFamily;
16535  	 	 $dom[$key]['fontstyle'] = $this->FontStyle;
16536  	 	 $dom[$key]['fontsize'] = $this->FontSizePt;
16537  	 	 $dom[$key]['font-stretch'] = $this->font_stretching;
16538  	 	 $dom[$key]['letter-spacing'] = $this->font_spacing;
16539  	 	 $dom[$key]['stroke'] = $this->textstrokewidth;
16540  	 	 $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
16541  	 	 $dom[$key]['clip'] = ($this->textrendermode > 3);
16542  	 	 $dom[$key]['line-height'] = $this->cell_height_ratio;
16543  	 	 $dom[$key]['bgcolor'] = false;
16544  	 	 $dom[$key]['fgcolor'] = $this->fgcolor; // color
16545  	 	 $dom[$key]['strokecolor'] = $this->strokecolor;
16546  	 	 $dom[$key]['align'] = '';
16547  	 	 $dom[$key]['listtype'] = '';
16548  	 	 $dom[$key]['text-indent'] = 0;
16549  	 	 $dom[$key]['text-transform'] = '';
16550  	 	 $dom[$key]['border'] = array();
16551  	 	 $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
16552  	 	 $thead = false; // true when we are inside the THEAD tag
16553  	 	 ++$key;
16554  	 	 $level = array();
16555  	 	 array_push($level, 0); // root
16556  	 	 while ($elkey < $maxel) {
16557  	 	 	 $dom[$key] = array();
16558  	 	 	 $element = $a[$elkey];
16559  	 	 	 $dom[$key]['elkey'] = $elkey;
16560  	 	 	 if (preg_match($tagpattern, $element)) {
16561  	 	 	 	 // html tag
16562  	 	 	 	 $element = substr($element, 1, -1);
16563  	 	 	 	 // get tag name
16564  	 	 	 	 preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
16565  	 	 	 	 $tagname = strtolower($tag[1]);
16566  	 	 	 	 // check if we are inside a table header
16567  	 	 	 	 if ($tagname == 'thead') {
16568  	 	 	 	 	 if ($element[0] == '/') {
16569  	 	 	 	 	 	 $thead = false;
16570  	 	 	 	 	 } else {
16571  	 	 	 	 	 	 $thead = true;
16572  	 	 	 	 	 }
16573  	 	 	 	 	 ++$elkey;
16574  	 	 	 	 	 continue;
16575  	 	 	 	 }
16576  	 	 	 	 $dom[$key]['tag'] = true;
16577  	 	 	 	 $dom[$key]['value'] = $tagname;
16578  	 	 	 	 if (in_array($dom[$key]['value'], $blocktags)) {
16579  	 	 	 	 	 $dom[$key]['block'] = true;
16580  	 	 	 	 } else {
16581  	 	 	 	 	 $dom[$key]['block'] = false;
16582  	 	 	 	 }
16583  	 	 	 	 if ($element[0] == '/') {
16584  	 	 	 	 	 // *** closing html tag
16585  	 	 	 	 	 $dom[$key]['opening'] = false;
16586  	 	 	 	 	 $dom[$key]['parent'] = end($level);
16587  	 	 	 	 	 array_pop($level);
16588  	 	 	 	 	 $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
16589  	 	 	 	 	 $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
16590  	 	 	 	 	 $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
16591  	 	 	 	 	 $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
16592  	 	 	 	 	 $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
16593  	 	 	 	 	 $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
16594  	 	 	 	 	 $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
16595  	 	 	 	 	 $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
16596  	 	 	 	 	 $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
16597  	 	 	 	 	 $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
16598  	 	 	 	 	 $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
16599  	 	 	 	 	 $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
16600  	 	 	 	 	 $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
16601  	 	 	 	 	 $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
16602  	 	 	 	 	 $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
16603  	 	 	 	 	 $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
16604  	 	 	 	 	 if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
16605  	 	 	 	 	 	 $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
16606  	 	 	 	 	 }
16607  	 	 	 	 	 // set the number of columns in table tag
16608  	 	 	 	 	 if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
16609  	 	 	 	 	 	 $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
16610  	 	 	 	 	 }
16611  	 	 	 	 	 if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
16612  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
16613  	 	 	 	 	 	 for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
16614  	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
16615  	 	 	 	 	 	 }
16616  	 	 	 	 	 	 $key = $i;
16617  	 	 	 	 	 	 // mark nested tables
16618  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
16619  	 	 	 	 	 	 // remove thead sections from nested tables
16620  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
16621  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
16622  	 	 	 	 	 }
16623  	 	 	 	 	 // store header rows on a new table
16624  	 	 	 	 	 if (
16625  	 	 	 	 	 	 ($dom[$key]['value'] === 'tr')
16626  	 	 	 	 	 	 && !empty($dom[($dom[$key]['parent'])]['thead'])
16627  	 	 	 	 	 	 && ($dom[($dom[$key]['parent'])]['thead'] === true)
16628  	 	 	 	 	 ) {
16629  	 	 	 	 	 	 if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
16630  	 	 	 	 	 	 	 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
16631  	 	 	 	 	 	 }
16632  	 	 	 	 	 	 for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
16633  	 	 	 	 	 	 	 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
16634  	 	 	 	 	 	 }
16635  	 	 	 	 	 	 if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
16636  	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['attribute'] = array();
16637  	 	 	 	 	 	 }
16638  	 	 	 	 	 	 // header elements must be always contained in a single page
16639  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
16640  	 	 	 	 	 }
16641  	 	 	 	 	 if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
16642  	 	 	 	 	 	 // remove the nobr attributes from the table header
16643  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
16644  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
16645  	 	 	 	 	 }
16646  	 	 	 	 } else {
16647  	 	 	 	 	 // *** opening or self-closing html tag
16648  	 	 	 	 	 $dom[$key]['opening'] = true;
16649  	 	 	 	 	 $dom[$key]['parent'] = end($level);
16650  	 	 	 	 	 if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
16651  	 	 	 	 	 	 // self-closing tag
16652  	 	 	 	 	 	 $dom[$key]['self'] = true;
16653  	 	 	 	 	 } else {
16654  	 	 	 	 	 	 // opening tag
16655  	 	 	 	 	 	 array_push($level, $key);
16656  	 	 	 	 	 	 $dom[$key]['self'] = false;
16657  	 	 	 	 	 }
16658  	 	 	 	 	 // copy some values from parent
16659  	 	 	 	 	 $parentkey = 0;
16660  	 	 	 	 	 if ($key > 0) {
16661  	 	 	 	 	 	 $parentkey = $dom[$key]['parent'];
16662  	 	 	 	 	 	 $dom[$key]['hide'] = $dom[$parentkey]['hide'];
16663  	 	 	 	 	 	 $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
16664  	 	 	 	 	 	 $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
16665  	 	 	 	 	 	 $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
16666  	 	 	 	 	 	 $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
16667  	 	 	 	 	 	 $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
16668  	 	 	 	 	 	 $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
16669  	 	 	 	 	 	 $dom[$key]['fill'] = $dom[$parentkey]['fill'];
16670  	 	 	 	 	 	 $dom[$key]['clip'] = $dom[$parentkey]['clip'];
16671  	 	 	 	 	 	 $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
16672  	 	 	 	 	 	 $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
16673  	 	 	 	 	 	 $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
16674  	 	 	 	 	 	 $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
16675  	 	 	 	 	 	 $dom[$key]['align'] = $dom[$parentkey]['align'];
16676  	 	 	 	 	 	 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
16677  	 	 	 	 	 	 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
16678  	 	 	 	 	 	 $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
16679  	 	 	 	 	 	 $dom[$key]['border'] = array();
16680  	 	 	 	 	 	 $dom[$key]['dir'] = $dom[$parentkey]['dir'];
16681  	 	 	 	 	 }
16682  	 	 	 	 	 // get attributes
16683  	 	 	 	 	 preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
16684  	 	 	 	 	 $dom[$key]['attribute'] = array(); // reset attribute array
16685                      foreach($attr_array[1] as $id => $name) {
16686                          $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
16687                      }
16688  	 	 	 	 	 if (!empty($css)) {
16689  	 	 	 	 	 	 // merge CSS style to current style
16690  	 	 	 	 	 	 list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
16691  	 	 	 	 	 	 $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
16692  	 	 	 	 	 }
16693  	 	 	 	 	 // split style attributes
16694  	 	 	 	 	 if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
16695  	 	 	 	 	 	 // get style attributes
16696  	 	 	 	 	 	 preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
16697  	 	 	 	 	 	 $dom[$key]['style'] = array(); // reset style attribute array
16698                          foreach($style_array[1] as $id => $name) {
16699                              // in case of duplicate attribute the last replace the previous
16700                              $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
16701                          }
16702  	 	 	 	 	 	 // --- get some style attributes ---
16703  	 	 	 	 	 	 // text direction
16704  	 	 	 	 	 	 if (isset($dom[$key]['style']['direction'])) {
16705  	 	 	 	 	 	 	 $dom[$key]['dir'] = $dom[$key]['style']['direction'];
16706  	 	 	 	 	 	 }
16707  	 	 	 	 	 	 // display
16708  	 	 	 	 	 	 if (isset($dom[$key]['style']['display'])) {
16709  	 	 	 	 	 	 	 $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
16710  	 	 	 	 	 	 }
16711  	 	 	 	 	 	 // font family
16712  	 	 	 	 	 	 if (isset($dom[$key]['style']['font-family'])) {
16713  	 	 	 	 	 	 	 $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
16714  	 	 	 	 	 	 }
16715  	 	 	 	 	 	 // list-style-type
16716  	 	 	 	 	 	 if (isset($dom[$key]['style']['list-style-type'])) {
16717  	 	 	 	 	 	 	 $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
16718  	 	 	 	 	 	 	 if ($dom[$key]['listtype'] == 'inherit') {
16719  	 	 	 	 	 	 	 	 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
16720  	 	 	 	 	 	 	 }
16721  	 	 	 	 	 	 }
16722  	 	 	 	 	 	 // text-indent
16723  	 	 	 	 	 	 if (isset($dom[$key]['style']['text-indent'])) {
16724  	 	 	 	 	 	 	 $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
16725  	 	 	 	 	 	 	 if ($dom[$key]['text-indent'] == 'inherit') {
16726  	 	 	 	 	 	 	 	 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
16727  	 	 	 	 	 	 	 }
16728  	 	 	 	 	 	 }
16729  	 	 	 	 	 	 // text-transform
16730  	 	 	 	 	 	 if (isset($dom[$key]['style']['text-transform'])) {
16731  	 	 	 	 	 	 	 $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
16732  	 	 	 	 	 	 }
16733  	 	 	 	 	 	 // font size
16734  	 	 	 	 	 	 if (isset($dom[$key]['style']['font-size'])) {
16735  	 	 	 	 	 	 	 $fsize = trim($dom[$key]['style']['font-size']);
16736  	 	 	 	 	 	 	 $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
16737  	 	 	 	 	 	 }
16738  	 	 	 	 	 	 // font-stretch
16739  	 	 	 	 	 	 if (isset($dom[$key]['style']['font-stretch'])) {
16740  	 	 	 	 	 	 	 $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
16741  	 	 	 	 	 	 }
16742  	 	 	 	 	 	 // letter-spacing
16743  	 	 	 	 	 	 if (isset($dom[$key]['style']['letter-spacing'])) {
16744  	 	 	 	 	 	 	 $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
16745  	 	 	 	 	 	 }
16746  	 	 	 	 	 	 // line-height (internally is the cell height ratio)
16747  	 	 	 	 	 	 if (isset($dom[$key]['style']['line-height'])) {
16748  	 	 	 	 	 	 	 $lineheight = trim($dom[$key]['style']['line-height']);
16749  	 	 	 	 	 	 	 switch ($lineheight) {
16750  	 	 	 	 	 	 	 	 // A normal line height. This is default
16751  	 	 	 	 	 	 	 	 case 'normal': {
16752  	 	 	 	 	 	 	 	 	 $dom[$key]['line-height'] = $dom[0]['line-height'];
16753  	 	 	 	 	 	 	 	 	 break;
16754  	 	 	 	 	 	 	 	 }
16755  	 	 	 	 	 	 	 	 case 'inherit': {
16756  	 	 	 	 	 	 	 	 	 $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
16757  	 	 	 	 	 	 	 	 }
16758  	 	 	 	 	 	 	 	 default: {
16759  	 	 	 	 	 	 	 	 	 if (is_numeric($lineheight)) {
16760  	 	 	 	 	 	 	 	 	 	 // convert to percentage of font height
16761  	 	 	 	 	 	 	 	 	 	 $lineheight = ($lineheight * 100).'%';
16762  	 	 	 	 	 	 	 	 	 }
16763  	 	 	 	 	 	 	 	 	 $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
16764  	 	 	 	 	 	 	 	 	 if (substr($lineheight, -1) !== '%') {
16765  	 	 	 	 	 	 	 	 	 	 if ($dom[$key]['fontsize'] <= 0) {
16766  	 	 	 	 	 	 	 	 	 	 	 $dom[$key]['line-height'] = 1;
16767  	 	 	 	 	 	 	 	 	 	 } else {
16768  	 	 	 	 	 	 	 	 	 	 	 $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding['T'] - $this->cell_padding['B']) / $dom[$key]['fontsize']);
16769  	 	 	 	 	 	 	 	 	 	 }
16770  	 	 	 	 	 	 	 	 	 }
16771  	 	 	 	 	 	 	 	 }
16772  	 	 	 	 	 	 	 }
16773  	 	 	 	 	 	 }
16774  	 	 	 	 	 	 // font style
16775  	 	 	 	 	 	 if (isset($dom[$key]['style']['font-weight'])) {
16776  	 	 	 	 	 	 	 if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
16777  	 	 	 	 	 	 	 	 if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
16778  	 	 	 	 	 	 	 	 	 $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
16779  	 	 	 	 	 	 	 	 }
16780  	 	 	 	 	 	 	 } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
16781  	 	 	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'B';
16782  	 	 	 	 	 	 	 }
16783  	 	 	 	 	 	 }
16784  	 	 	 	 	 	 if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
16785  	 	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'I';
16786  	 	 	 	 	 	 }
16787  	 	 	 	 	 	 // font color
16788  	 	 	 	 	 	 if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
16789  	 	 	 	 	 	 	 $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
16790  	 	 	 	 	 	 } elseif ($dom[$key]['value'] == 'a') {
16791  	 	 	 	 	 	 	 $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
16792  	 	 	 	 	 	 }
16793  	 	 	 	 	 	 // background color
16794  	 	 	 	 	 	 if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
16795  	 	 	 	 	 	 	 $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
16796  	 	 	 	 	 	 }
16797  	 	 	 	 	 	 // text-decoration
16798  	 	 	 	 	 	 if (isset($dom[$key]['style']['text-decoration'])) {
16799  	 	 	 	 	 	 	 $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
16800  	 	 	 	 	 	 	 foreach ($decors as $dec) {
16801  	 	 	 	 	 	 	 	 $dec = trim($dec);
16802  	 	 	 	 	 	 	 	 if (!TCPDF_STATIC::empty_string($dec)) {
16803  	 	 	 	 	 	 	 	 	 if ($dec[0] == 'u') {
16804  	 	 	 	 	 	 	 	 	 	 // underline
16805  	 	 	 	 	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'U';
16806  	 	 	 	 	 	 	 	 	 } elseif ($dec[0] == 'l') {
16807  	 	 	 	 	 	 	 	 	 	 // line-through
16808  	 	 	 	 	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'D';
16809  	 	 	 	 	 	 	 	 	 } elseif ($dec[0] == 'o') {
16810  	 	 	 	 	 	 	 	 	 	 // overline
16811  	 	 	 	 	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'O';
16812  	 	 	 	 	 	 	 	 	 }
16813  	 	 	 	 	 	 	 	 }
16814  	 	 	 	 	 	 	 }
16815  	 	 	 	 	 	 } elseif ($dom[$key]['value'] == 'a') {
16816  	 	 	 	 	 	 	 $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
16817  	 	 	 	 	 	 }
16818  	 	 	 	 	 	 // check for width attribute
16819  	 	 	 	 	 	 if (isset($dom[$key]['style']['width'])) {
16820  	 	 	 	 	 	 	 $dom[$key]['width'] = $dom[$key]['style']['width'];
16821  	 	 	 	 	 	 }
16822  	 	 	 	 	 	 // check for height attribute
16823  	 	 	 	 	 	 if (isset($dom[$key]['style']['height'])) {
16824  	 	 	 	 	 	 	 $dom[$key]['height'] = $dom[$key]['style']['height'];
16825  	 	 	 	 	 	 }
16826  	 	 	 	 	 	 // check for text alignment
16827  	 	 	 	 	 	 if (isset($dom[$key]['style']['text-align'])) {
16828  	 	 	 	 	 	 	 $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
16829  	 	 	 	 	 	 }
16830  	 	 	 	 	 	 // check for CSS border properties
16831  	 	 	 	 	 	 if (isset($dom[$key]['style']['border'])) {
16832  	 	 	 	 	 	 	 $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
16833  	 	 	 	 	 	 	 if (!empty($borderstyle)) {
16834  	 	 	 	 	 	 	 	 $dom[$key]['border']['LTRB'] = $borderstyle;
16835  	 	 	 	 	 	 	 }
16836  	 	 	 	 	 	 }
16837  	 	 	 	 	 	 if (isset($dom[$key]['style']['border-color'])) {
16838  	 	 	 	 	 	 	 $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
16839  	 	 	 	 	 	 	 if (isset($brd_colors[3])) {
16840  	 	 	 	 	 	 	 	 $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
16841  	 	 	 	 	 	 	 }
16842  	 	 	 	 	 	 	 if (isset($brd_colors[1])) {
16843  	 	 	 	 	 	 	 	 $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
16844  	 	 	 	 	 	 	 }
16845  	 	 	 	 	 	 	 if (isset($brd_colors[0])) {
16846  	 	 	 	 	 	 	 	 $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
16847  	 	 	 	 	 	 	 }
16848  	 	 	 	 	 	 	 if (isset($brd_colors[2])) {
16849  	 	 	 	 	 	 	 	 $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
16850  	 	 	 	 	 	 	 }
16851  	 	 	 	 	 	 }
16852  	 	 	 	 	 	 if (isset($dom[$key]['style']['border-width'])) {
16853  	 	 	 	 	 	 	 $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
16854  	 	 	 	 	 	 	 if (isset($brd_widths[3])) {
16855  	 	 	 	 	 	 	 	 $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
16856  	 	 	 	 	 	 	 }
16857  	 	 	 	 	 	 	 if (isset($brd_widths[1])) {
16858  	 	 	 	 	 	 	 	 $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
16859  	 	 	 	 	 	 	 }
16860  	 	 	 	 	 	 	 if (isset($brd_widths[0])) {
16861  	 	 	 	 	 	 	 	 $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
16862  	 	 	 	 	 	 	 }
16863  	 	 	 	 	 	 	 if (isset($brd_widths[2])) {
16864  	 	 	 	 	 	 	 	 $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
16865  	 	 	 	 	 	 	 }
16866  	 	 	 	 	 	 }
16867  	 	 	 	 	 	 if (isset($dom[$key]['style']['border-style'])) {
16868  	 	 	 	 	 	 	 $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
16869  	 	 	 	 	 	 	 if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
16870  	 	 	 	 	 	 	 	 $dom[$key]['border']['L']['cap'] = 'square';
16871  	 	 	 	 	 	 	 	 $dom[$key]['border']['L']['join'] = 'miter';
16872  	 	 	 	 	 	 	 	 $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
16873  	 	 	 	 	 	 	 	 if ($dom[$key]['border']['L']['dash'] < 0) {
16874  	 	 	 	 	 	 	 	 	 $dom[$key]['border']['L'] = array();
16875  	 	 	 	 	 	 	 	 }
16876  	 	 	 	 	 	 	 }
16877  	 	 	 	 	 	 	 if (isset($brd_styles[1])) {
16878  	 	 	 	 	 	 	 	 $dom[$key]['border']['R']['cap'] = 'square';
16879  	 	 	 	 	 	 	 	 $dom[$key]['border']['R']['join'] = 'miter';
16880  	 	 	 	 	 	 	 	 $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
16881  	 	 	 	 	 	 	 	 if ($dom[$key]['border']['R']['dash'] < 0) {
16882  	 	 	 	 	 	 	 	 	 $dom[$key]['border']['R'] = array();
16883  	 	 	 	 	 	 	 	 }
16884  	 	 	 	 	 	 	 }
16885  	 	 	 	 	 	 	 if (isset($brd_styles[0])) {
16886  	 	 	 	 	 	 	 	 $dom[$key]['border']['T']['cap'] = 'square';
16887  	 	 	 	 	 	 	 	 $dom[$key]['border']['T']['join'] = 'miter';
16888  	 	 	 	 	 	 	 	 $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
16889  	 	 	 	 	 	 	 	 if ($dom[$key]['border']['T']['dash'] < 0) {
16890  	 	 	 	 	 	 	 	 	 $dom[$key]['border']['T'] = array();
16891  	 	 	 	 	 	 	 	 }
16892  	 	 	 	 	 	 	 }
16893  	 	 	 	 	 	 	 if (isset($brd_styles[2])) {
16894  	 	 	 	 	 	 	 	 $dom[$key]['border']['B']['cap'] = 'square';
16895  	 	 	 	 	 	 	 	 $dom[$key]['border']['B']['join'] = 'miter';
16896  	 	 	 	 	 	 	 	 $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
16897  	 	 	 	 	 	 	 	 if ($dom[$key]['border']['B']['dash'] < 0) {
16898  	 	 	 	 	 	 	 	 	 $dom[$key]['border']['B'] = array();
16899  	 	 	 	 	 	 	 	 }
16900  	 	 	 	 	 	 	 }
16901  	 	 	 	 	 	 }
16902  	 	 	 	 	 	 $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
16903  	 	 	 	 	 	 foreach ($cellside as $bsk => $bsv) {
16904  	 	 	 	 	 	 	 if (isset($dom[$key]['style']['border-'.$bsv])) {
16905  	 	 	 	 	 	 	 	 $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
16906  	 	 	 	 	 	 	 	 if (!empty($borderstyle)) {
16907  	 	 	 	 	 	 	 	 	 $dom[$key]['border'][$bsk] = $borderstyle;
16908  	 	 	 	 	 	 	 	 }
16909  	 	 	 	 	 	 	 }
16910  	 	 	 	 	 	 	 if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
16911  	 	 	 	 	 	 	 	 $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
16912  	 	 	 	 	 	 	 }
16913  	 	 	 	 	 	 	 if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
16914  	 	 	 	 	 	 	 	 $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
16915  	 	 	 	 	 	 	 }
16916  	 	 	 	 	 	 	 if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
16917  	 	 	 	 	 	 	 	 $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
16918  	 	 	 	 	 	 	 	 if ($dom[$key]['border'][$bsk]['dash'] < 0) {
16919  	 	 	 	 	 	 	 	 	 $dom[$key]['border'][$bsk] = array();
16920  	 	 	 	 	 	 	 	 }
16921  	 	 	 	 	 	 	 }
16922  	 	 	 	 	 	 }
16923  	 	 	 	 	 	 // check for CSS padding properties
16924  	 	 	 	 	 	 if (isset($dom[$key]['style']['padding'])) {
16925  	 	 	 	 	 	 	 $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
16926  	 	 	 	 	 	 } else {
16927  	 	 	 	 	 	 	 $dom[$key]['padding'] = $this->cell_padding;
16928  	 	 	 	 	 	 }
16929  	 	 	 	 	 	 foreach ($cellside as $psk => $psv) {
16930  	 	 	 	 	 	 	 if (isset($dom[$key]['style']['padding-'.$psv])) {
16931  	 	 	 	 	 	 	 	 $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
16932  	 	 	 	 	 	 	 }
16933  	 	 	 	 	 	 }
16934  	 	 	 	 	 	 // check for CSS margin properties
16935  	 	 	 	 	 	 if (isset($dom[$key]['style']['margin'])) {
16936  	 	 	 	 	 	 	 $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
16937  	 	 	 	 	 	 } else {
16938  	 	 	 	 	 	 	 $dom[$key]['margin'] = $this->cell_margin;
16939  	 	 	 	 	 	 }
16940  	 	 	 	 	 	 foreach ($cellside as $psk => $psv) {
16941  	 	 	 	 	 	 	 if (isset($dom[$key]['style']['margin-'.$psv])) {
16942  	 	 	 	 	 	 	 	 $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
16943  	 	 	 	 	 	 	 }
16944  	 	 	 	 	 	 }
16945  	 	 	 	 	 	 // check for CSS border-spacing properties
16946  	 	 	 	 	 	 if (isset($dom[$key]['style']['border-spacing'])) {
16947  	 	 	 	 	 	 	 $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
16948  	 	 	 	 	 	 }
16949  	 	 	 	 	 	 // page-break-inside
16950  	 	 	 	 	 	 if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
16951  	 	 	 	 	 	 	 $dom[$key]['attribute']['nobr'] = 'true';
16952  	 	 	 	 	 	 }
16953  	 	 	 	 	 	 // page-break-before
16954  	 	 	 	 	 	 if (isset($dom[$key]['style']['page-break-before'])) {
16955  	 	 	 	 	 	 	 if ($dom[$key]['style']['page-break-before'] == 'always') {
16956  	 	 	 	 	 	 	 	 $dom[$key]['attribute']['pagebreak'] = 'true';
16957  	 	 	 	 	 	 	 } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
16958  	 	 	 	 	 	 	 	 $dom[$key]['attribute']['pagebreak'] = 'left';
16959  	 	 	 	 	 	 	 } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
16960  	 	 	 	 	 	 	 	 $dom[$key]['attribute']['pagebreak'] = 'right';
16961  	 	 	 	 	 	 	 }
16962  	 	 	 	 	 	 }
16963  	 	 	 	 	 	 // page-break-after
16964  	 	 	 	 	 	 if (isset($dom[$key]['style']['page-break-after'])) {
16965  	 	 	 	 	 	 	 if ($dom[$key]['style']['page-break-after'] == 'always') {
16966  	 	 	 	 	 	 	 	 $dom[$key]['attribute']['pagebreakafter'] = 'true';
16967  	 	 	 	 	 	 	 } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
16968  	 	 	 	 	 	 	 	 $dom[$key]['attribute']['pagebreakafter'] = 'left';
16969  	 	 	 	 	 	 	 } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
16970  	 	 	 	 	 	 	 	 $dom[$key]['attribute']['pagebreakafter'] = 'right';
16971  	 	 	 	 	 	 	 }
16972  	 	 	 	 	 	 }
16973  	 	 	 	 	 }
16974  	 	 	 	 	 if (isset($dom[$key]['attribute']['display'])) {
16975  	 	 	 	 	 	 $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
16976  	 	 	 	 	 }
16977  	 	 	 	 	 if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
16978  	 	 	 	 	 	 $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
16979  	 	 	 	 	 	 if (!empty($borderstyle)) {
16980  	 	 	 	 	 	 	 $dom[$key]['border']['LTRB'] = $borderstyle;
16981  	 	 	 	 	 	 }
16982  	 	 	 	 	 }
16983  	 	 	 	 	 // check for font tag
16984  	 	 	 	 	 if ($dom[$key]['value'] == 'font') {
16985  	 	 	 	 	 	 // font family
16986  	 	 	 	 	 	 if (isset($dom[$key]['attribute']['face'])) {
16987  	 	 	 	 	 	 	 $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
16988  	 	 	 	 	 	 }
16989  	 	 	 	 	 	 // font size
16990  	 	 	 	 	 	 if (isset($dom[$key]['attribute']['size'])) {
16991  	 	 	 	 	 	 	 if ($key > 0) {
16992  	 	 	 	 	 	 	 	 if ($dom[$key]['attribute']['size'][0] == '+') {
16993  	 	 	 	 	 	 	 	 	 $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
16994  	 	 	 	 	 	 	 	 } elseif ($dom[$key]['attribute']['size'][0] == '-') {
16995  	 	 	 	 	 	 	 	 	 $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
16996  	 	 	 	 	 	 	 	 } else {
16997  	 	 	 	 	 	 	 	 	 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
16998  	 	 	 	 	 	 	 	 }
16999  	 	 	 	 	 	 	 } else {
17000  	 	 	 	 	 	 	 	 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
17001  	 	 	 	 	 	 	 }
17002  	 	 	 	 	 	 }
17003  	 	 	 	 	 }
17004  	 	 	 	 	 // force natural alignment for lists
17005  	 	 	 	 	 if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
17006  	 	 	 	 	 	 AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
17007  	 	 	 	 	 	 if ($this->rtl) {
17008  	 	 	 	 	 	 	 $dom[$key]['align'] = 'R';
17009  	 	 	 	 	 	 } else {
17010  	 	 	 	 	 	 	 $dom[$key]['align'] = 'L';
17011  	 	 	 	 	 	 }
17012  	 	 	 	 	 }
17013  	 	 	 	 	 if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
17014  	 	 	 	 	 	 if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
17015  	 	 	 	 	 	 	 $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
17016  	 	 	 	 	 	 }
17017  	 	 	 	 	 }
17018  	 	 	 	 	 if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
17019  	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'B';
17020  	 	 	 	 	 }
17021  	 	 	 	 	 if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
17022  	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'I';
17023  	 	 	 	 	 }
17024  	 	 	 	 	 if ($dom[$key]['value'] == 'u') {
17025  	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'U';
17026  	 	 	 	 	 }
17027  	 	 	 	 	 if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
17028  	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'D';
17029  	 	 	 	 	 }
17030  	 	 	 	 	 if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
17031  	 	 	 	 	 	 $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
17032  	 	 	 	 	 }
17033  	 	 	 	 	 if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
17034  	 	 	 	 	 	 $dom[$key]['fontname'] = $this->default_monospaced_font;
17035  	 	 	 	 	 }
17036  	 	 	 	 	 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)) {
17037  	 	 	 	 	 	 // headings h1, h2, h3, h4, h5, h6
17038  	 	 	 	 	 	 if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
17039  	 	 	 	 	 	 	 $headsize = (4 - intval($dom[$key]['value'][1])) * 2;
17040  	 	 	 	 	 	 	 $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
17041  	 	 	 	 	 	 }
17042  	 	 	 	 	 	 if (!isset($dom[$key]['style']['font-weight'])) {
17043  	 	 	 	 	 	 	 $dom[$key]['fontstyle'] .= 'B';
17044  	 	 	 	 	 	 }
17045  	 	 	 	 	 }
17046  	 	 	 	 	 if (($dom[$key]['value'] == 'table')) {
17047  	 	 	 	 	 	 $dom[$key]['rows'] = 0; // number of rows
17048  	 	 	 	 	 	 $dom[$key]['trids'] = array(); // IDs of TR elements
17049  	 	 	 	 	 	 $dom[$key]['thead'] = ''; // table header rows
17050  	 	 	 	 	 }
17051  	 	 	 	 	 if (($dom[$key]['value'] == 'tr')) {
17052  	 	 	 	 	 	 $dom[$key]['cols'] = 0;
17053  	 	 	 	 	 	 if ($thead) {
17054  	 	 	 	 	 	 	 $dom[$key]['thead'] = true;
17055  	 	 	 	 	 	 	 // rows on thead block are printed as a separate table
17056  	 	 	 	 	 	 } else {
17057  	 	 	 	 	 	 	 $dom[$key]['thead'] = false;
17058  	 	 	 	 	 	 	 $parent = $dom[$key]['parent'];
17059  
17060  	 	 	 	 	 	 	 if (!isset($dom[$parent]['rows'])) {
17061  	 	 	 	 	 	 	 	 $dom[$parent]['rows'] = 0;
17062  	 	 	 	 	 	 	 }
17063  	 	 	 	 	 	 	 // store the number of rows on table element
17064  	 	 	 	 	 	 	 ++$dom[$parent]['rows'];
17065  
17066  	 	 	 	 	 	 	 if (!isset($dom[$parent]['trids'])) {
17067  	 	 	 	 	 	 	 	 $dom[$parent]['trids'] = array();
17068  	 	 	 	 	 	 	 }
17069  
17070  	 	 	 	 	 	 	 // store the TR elements IDs on table element
17071  	 	 	 	 	 	 	 array_push($dom[$parent]['trids'], $key);
17072  	 	 	 	 	 	 }
17073  	 	 	 	 	 }
17074  	 	 	 	 	 if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
17075  	 	 	 	 	 	 if (isset($dom[$key]['attribute']['colspan'])) {
17076  	 	 	 	 	 	 	 $colspan = intval($dom[$key]['attribute']['colspan']);
17077  	 	 	 	 	 	 } else {
17078  	 	 	 	 	 	 	 $colspan = 1;
17079  	 	 	 	 	 	 }
17080  	 	 	 	 	 	 $dom[$key]['attribute']['colspan'] = $colspan;
17081  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['cols'] += $colspan;
17082  	 	 	 	 	 }
17083  	 	 	 	 	 // text direction
17084  	 	 	 	 	 if (isset($dom[$key]['attribute']['dir'])) {
17085  	 	 	 	 	 	 $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
17086  	 	 	 	 	 }
17087  	 	 	 	 	 // set foreground color attribute
17088  	 	 	 	 	 if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
17089  	 	 	 	 	 	 $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
17090  	 	 	 	 	 } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
17091  	 	 	 	 	 	 $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
17092  	 	 	 	 	 }
17093  	 	 	 	 	 // set background color attribute
17094  	 	 	 	 	 if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
17095  	 	 	 	 	 	 $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
17096  	 	 	 	 	 }
17097  	 	 	 	 	 // set stroke color attribute
17098  	 	 	 	 	 if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
17099  	 	 	 	 	 	 $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
17100  	 	 	 	 	 }
17101  	 	 	 	 	 // check for width attribute
17102  	 	 	 	 	 if (isset($dom[$key]['attribute']['width'])) {
17103  	 	 	 	 	 	 $dom[$key]['width'] = $dom[$key]['attribute']['width'];
17104  	 	 	 	 	 }
17105  	 	 	 	 	 // check for height attribute
17106  	 	 	 	 	 if (isset($dom[$key]['attribute']['height'])) {
17107  	 	 	 	 	 	 $dom[$key]['height'] = $dom[$key]['attribute']['height'];
17108  	 	 	 	 	 }
17109  	 	 	 	 	 // check for text alignment
17110  	 	 	 	 	 if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
17111  	 	 	 	 	 	 $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
17112  	 	 	 	 	 }
17113  	 	 	 	 	 // check for text rendering mode (the following attributes do not exist in HTML)
17114  	 	 	 	 	 if (isset($dom[$key]['attribute']['stroke'])) {
17115  	 	 	 	 	 	 // font stroke width
17116  	 	 	 	 	 	 $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
17117  	 	 	 	 	 }
17118  	 	 	 	 	 if (isset($dom[$key]['attribute']['fill'])) {
17119  	 	 	 	 	 	 // font fill
17120  	 	 	 	 	 	 if ($dom[$key]['attribute']['fill'] == 'true') {
17121  	 	 	 	 	 	 	 $dom[$key]['fill'] = true;
17122  	 	 	 	 	 	 } else {
17123  	 	 	 	 	 	 	 $dom[$key]['fill'] = false;
17124  	 	 	 	 	 	 }
17125  	 	 	 	 	 }
17126  	 	 	 	 	 if (isset($dom[$key]['attribute']['clip'])) {
17127  	 	 	 	 	 	 // clipping mode
17128  	 	 	 	 	 	 if ($dom[$key]['attribute']['clip'] == 'true') {
17129  	 	 	 	 	 	 	 $dom[$key]['clip'] = true;
17130  	 	 	 	 	 	 } else {
17131  	 	 	 	 	 	 	 $dom[$key]['clip'] = false;
17132  	 	 	 	 	 	 }
17133  	 	 	 	 	 }
17134  	 	 	 	 } // end opening tag
17135  	 	 	 } else {
17136  	 	 	 	 // text
17137  	 	 	 	 $dom[$key]['tag'] = false;
17138  	 	 	 	 $dom[$key]['block'] = false;
17139  	 	 	 	 $dom[$key]['parent'] = end($level);
17140  	 	 	 	 $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
17141  	 	 	 	 if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
17142  	 	 	 	 	 // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
17143  	 	 	 	 	 if (function_exists('mb_convert_case')) {
17144  	 	 	 	 	 	 $ttm = array('capitalize' => MB_CASE_TITLE, 'uppercase' => MB_CASE_UPPER, 'lowercase' => MB_CASE_LOWER);
17145  	 	 	 	 	 	 if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
17146  	 	 	 	 	 	 	 $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding);
17147  	 	 	 	 	 	 }
17148  	 	 	 	 	 } elseif (!$this->isunicode) {
17149  	 	 	 	 	 	 switch ($dom[$dom[$key]['parent']]['text-transform']) {
17150  	 	 	 	 	 	 	 case 'capitalize': {
17151  	 	 	 	 	 	 	 	 $element = ucwords(strtolower($element));
17152  	 	 	 	 	 	 	 	 break;
17153  	 	 	 	 	 	 	 }
17154  	 	 	 	 	 	 	 case 'uppercase': {
17155  	 	 	 	 	 	 	 	 $element = strtoupper($element);
17156  	 	 	 	 	 	 	 	 break;
17157  	 	 	 	 	 	 	 }
17158  	 	 	 	 	 	 	 case 'lowercase': {
17159  	 	 	 	 	 	 	 	 $element = strtolower($element);
17160  	 	 	 	 	 	 	 	 break;
17161  	 	 	 	 	 	 	 }
17162  	 	 	 	 	 	 }
17163  	 	 	 	 	 }
17164  	 	 	 	 	 $element = preg_replace("/&NBSP;/i", "&nbsp;", $element);
17165  	 	 	 	 }
17166  	 	 	 	 $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
17167  	 	 	 }
17168  	 	 	 ++$elkey;
17169  	 	 	 ++$key;
17170  	 	 }
17171  	 	 return $dom;
17172  	 }
17173  
17174  	 /**
17175  	  * Returns the string used to find spaces
17176  	  * @return string
17177  	  * @protected
17178  	  * @author Nicola Asuni
17179  	  * @since 4.8.024 (2010-01-15)
17180  	  */
17181  	protected function getSpaceString() {
17182  	 	 $spacestr = chr(32);
17183  	 	 if ($this->isUnicodeFont()) {
17184  	 	 	 $spacestr = chr(0).chr(32);
17185  	 	 }
17186  	 	 return $spacestr;
17187  	 }
17188  
17189  	 /**
17190  	  * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance.
17191  	  * @param string $data serialized data
17192  	  * @return string
17193  	  * @public static
17194  	  */
17195  	protected function getHashForTCPDFtagParams($data) {
17196  	 	 return md5(strlen($data).$this->file_id.$data);
17197  	 }
17198  
17199  	 /**
17200  	  * Serialize an array of parameters to be used with TCPDF tag in HTML code.
17201  	  * @param array $data parameters array
17202  	  * @return string containing serialized data
17203  	  * @public static
17204  	  */
17205  	public function serializeTCPDFtagParameters($data) {
17206  	 	 $encoded = urlencode(json_encode($data));
17207  	 	 return $this->getHashForTCPDFtagParams($encoded).$encoded;
17208  	 }
17209  
17210  	 /**
17211  	  * Unserialize parameters to be used with TCPDF tag in HTML code.
17212  	  * @param string $data serialized data
17213  	  * @return array containing unserialized data
17214  	  * @protected static
17215  	  */
17216  	protected function unserializeTCPDFtagParameters($data) {
17217  	 	 $hash = substr($data, 0, 32);
17218  	 	 $encoded = substr($data, 32);
17219  	 	 if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
17220  	 	 	 $this->Error('Invalid parameters');
17221  	 	 }
17222  	 	 return json_decode(urldecode($encoded), true);
17223  	 }
17224  
17225  	 /**
17226  	  * Prints a cell (rectangular area) with optional borders, background color and html text string.
17227  	  * 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 />
17228  	  * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
17229  	  * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
17230  	  * 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
17231  	  * NOTE: all the HTML attributes must be enclosed in double-quote.
17232  	  * @param float $w Cell width. If 0, the cell extends up to the right margin.
17233  	  * @param float $h Cell minimum height. The cell extends automatically if needed.
17234  	  * @param float|null $x upper-left corner X coordinate
17235  	  * @param float|null $y upper-left corner Y coordinate
17236  	  * @param string $html html text to print. Default value: empty string.
17237  	  * @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)))
17238  	  * @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>
17239  Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
17240  	  * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
17241  	  * @param boolean $reseth if true reset the last cell height (default true).
17242  	  * @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>
17243  	  * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
17244  	  * @see Multicell(), writeHTML()
17245  	  * @public
17246  	  */
17247  	public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
17248  	 	 return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
17249  	 }
17250  
17251  	 /**
17252  	  * Allows to preserve some HTML formatting (limited support).<br />
17253  	  * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
17254  	  * 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
17255  	  * NOTE: all the HTML attributes must be enclosed in double-quote.
17256  	  * @param string $html text to display
17257  	  * @param boolean $ln if true add a new line after text (default = true)
17258  	  * @param boolean $fill Indicates if the background must be painted (true) or transparent (false).
17259  	  * @param boolean $reseth if true reset the last cell height (default false).
17260  	  * @param boolean $cell if true add the current left (or right for RTL) padding to each Write (default false).
17261  	  * @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>
17262  	  * @public
17263  	  */
17264  	public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
17265  	 	 $gvars = $this->getGraphicVars();
17266  	 	 // store current values
17267  	 	 $prev_cell_margin = $this->cell_margin;
17268  	 	 $prev_cell_padding = $this->cell_padding;
17269  	 	 $prevPage = $this->page;
17270  	 	 $prevlMargin = $this->lMargin;
17271  	 	 $prevrMargin = $this->rMargin;
17272  	 	 $curfontname = $this->FontFamily;
17273  	 	 $curfontstyle = $this->FontStyle;
17274  	 	 $curfontsize = $this->FontSizePt;
17275  	 	 $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
17276  	 	 $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
17277  	 	 $curfontstretcing = $this->font_stretching;
17278  	 	 $curfonttracking = $this->font_spacing;
17279  	 	 $this->newline = true;
17280  	 	 $newline = true;
17281  	 	 $startlinepage = $this->page;
17282  	 	 $minstartliney = $this->y;
17283  	 	 $maxbottomliney = 0;
17284  	 	 $startlinex = $this->x;
17285  	 	 $startliney = $this->y;
17286  	 	 $yshift = 0;
17287  	 	 $loop = 0;
17288  	 	 $curpos = 0;
17289  	 	 $this_method_vars = array();
17290  	 	 $undo = false;
17291  	 	 $fontaligned = false;
17292  	 	 $reverse_dir = false; // true when the text direction is reversed
17293  	 	 $this->premode = false;
17294  	 	 if ($this->inxobj) {
17295  	 	 	 // we are inside an XObject template
17296  	 	 	 $pask = count($this->xobjects[$this->xobjid]['annotations']);
17297  	 	 } elseif (isset($this->PageAnnots[$this->page])) {
17298  	 	 	 $pask = count($this->PageAnnots[$this->page]);
17299  	 	 } else {
17300  	 	 	 $pask = 0;
17301  	 	 }
17302  	 	 if ($this->inxobj) {
17303  	 	 	 // we are inside an XObject template
17304  	 	 	 $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
17305  	 	 } elseif (!$this->InFooter) {
17306  	 	 	 if (isset($this->footerlen[$this->page])) {
17307  	 	 	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
17308  	 	 	 } else {
17309  	 	 	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page];
17310  	 	 	 }
17311  	 	 	 $startlinepos = $this->footerpos[$this->page];
17312  	 	 } else {
17313  	 	 	 // we are inside the footer
17314  	 	 	 $startlinepos = $this->pagelen[$this->page];
17315  	 	 }
17316  	 	 $lalign = $align;
17317  	 	 $plalign = $align;
17318  	 	 if ($this->rtl) {
17319  	 	 	 $w = $this->x - $this->lMargin;
17320  	 	 } else {
17321  	 	 	 $w = $this->w - $this->rMargin - $this->x;
17322  	 	 }
17323  	 	 $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
17324  	 	 if ($cell) {
17325  	 	 	 if ($this->rtl) {
17326  	 	 	 	 $this->x -= $this->cell_padding['R'];
17327  	 	 	 	 $this->lMargin += $this->cell_padding['L'];
17328  	 	 	 } else {
17329  	 	 	 	 $this->x += $this->cell_padding['L'];
17330  	 	 	 	 $this->rMargin += $this->cell_padding['R'];
17331  	 	 	 }
17332  	 	 }
17333  	 	 if ($this->customlistindent >= 0) {
17334  	 	 	 $this->listindent = $this->customlistindent;
17335  	 	 } else {
17336  	 	 	 $this->listindent = $this->GetStringWidth('000000');
17337  	 	 }
17338  	 	 $this->listindentlevel = 0;
17339  	 	 // save previous states
17340  	 	 $prev_cell_height_ratio = $this->cell_height_ratio;
17341  	 	 $prev_listnum = $this->listnum;
17342  	 	 $prev_listordered = $this->listordered;
17343  	 	 $prev_listcount = $this->listcount;
17344  	 	 $prev_lispacer = $this->lispacer;
17345  	 	 $this->listnum = 0;
17346  	 	 $this->listordered = array();
17347  	 	 $this->listcount = array();
17348  	 	 $this->lispacer = '';
17349  	 	 if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
17350  	 	 	 // reset row height
17351  	 	 	 $this->resetLastH();
17352  	 	 }
17353  	 	 $dom = $this->getHtmlDomArray($html);
17354  	 	 $maxel = count($dom);
17355  	 	 $key = 0;
17356  	 	 while ($key < $maxel) {
17357  	 	 	 if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
17358  	 	 	 	 // store the node key
17359  	 	 	 	 $hidden_node_key = $key;
17360  	 	 	 	 if ($dom[$key]['self']) {
17361  	 	 	 	 	 // skip just this self-closing tag
17362  	 	 	 	 	 ++$key;
17363  	 	 	 	 } else {
17364  	 	 	 	 	 // skip this and all children tags
17365  	 	 	 	 	 while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
17366  	 	 	 	 	 	 // skip hidden objects
17367  	 	 	 	 	 	 ++$key;
17368  	 	 	 	 	 }
17369  	 	 	 	 	 ++$key;
17370  	 	 	 	 }
17371  	 	 	 }
17372  	 	 	 if ($key == $maxel) break;
17373  	 	 	 if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
17374  	 	 	 	 // check for pagebreak
17375  	 	 	 	 if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
17376  	 	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
17377  	 	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
17378  	 	 	 	 	 $this->htmlvspace = ($this->PageBreakTrigger + 1);
17379  	 	 	 	 }
17380  	 	 	 	 if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
17381  	 	 	 	 	 OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
17382  	 	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
17383  	 	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
17384  	 	 	 	 	 $this->htmlvspace = ($this->PageBreakTrigger + 1);
17385  	 	 	 	 }
17386  	 	 	 }
17387  	 	 	 if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
17388  	 	 	 	 if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
17389  	 	 	 	 	 $dom[$key]['attribute']['nobr'] = false;
17390  	 	 	 	 } else {
17391  	 	 	 	 	 // store current object
17392  	 	 	 	 	 $this->startTransaction();
17393  	 	 	 	 	 // save this method vars
17394  	 	 	 	 	 $this_method_vars['html'] = $html;
17395  	 	 	 	 	 $this_method_vars['ln'] = $ln;
17396  	 	 	 	 	 $this_method_vars['fill'] = $fill;
17397  	 	 	 	 	 $this_method_vars['reseth'] = $reseth;
17398  	 	 	 	 	 $this_method_vars['cell'] = $cell;
17399  	 	 	 	 	 $this_method_vars['align'] = $align;
17400  	 	 	 	 	 $this_method_vars['gvars'] = $gvars;
17401  	 	 	 	 	 $this_method_vars['prevPage'] = $prevPage;
17402  	 	 	 	 	 $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
17403  	 	 	 	 	 $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
17404  	 	 	 	 	 $this_method_vars['prevlMargin'] = $prevlMargin;
17405  	 	 	 	 	 $this_method_vars['prevrMargin'] = $prevrMargin;
17406  	 	 	 	 	 $this_method_vars['curfontname'] = $curfontname;
17407  	 	 	 	 	 $this_method_vars['curfontstyle'] = $curfontstyle;
17408  	 	 	 	 	 $this_method_vars['curfontsize'] = $curfontsize;
17409  	 	 	 	 	 $this_method_vars['curfontascent'] = $curfontascent;
17410  	 	 	 	 	 $this_method_vars['curfontdescent'] = $curfontdescent;
17411  	 	 	 	 	 $this_method_vars['curfontstretcing'] = $curfontstretcing;
17412  	 	 	 	 	 $this_method_vars['curfonttracking'] = $curfonttracking;
17413  	 	 	 	 	 $this_method_vars['minstartliney'] = $minstartliney;
17414  	 	 	 	 	 $this_method_vars['maxbottomliney'] = $maxbottomliney;
17415  	 	 	 	 	 $this_method_vars['yshift'] = $yshift;
17416  	 	 	 	 	 $this_method_vars['startlinepage'] = $startlinepage;
17417  	 	 	 	 	 $this_method_vars['startlinepos'] = $startlinepos;
17418  	 	 	 	 	 $this_method_vars['startlinex'] = $startlinex;
17419  	 	 	 	 	 $this_method_vars['startliney'] = $startliney;
17420  	 	 	 	 	 $this_method_vars['newline'] = $newline;
17421  	 	 	 	 	 $this_method_vars['loop'] = $loop;
17422  	 	 	 	 	 $this_method_vars['curpos'] = $curpos;
17423  	 	 	 	 	 $this_method_vars['pask'] = $pask;
17424  	 	 	 	 	 $this_method_vars['lalign'] = $lalign;
17425  	 	 	 	 	 $this_method_vars['plalign'] = $plalign;
17426  	 	 	 	 	 $this_method_vars['w'] = $w;
17427  	 	 	 	 	 $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
17428  	 	 	 	 	 $this_method_vars['prev_listnum'] = $prev_listnum;
17429  	 	 	 	 	 $this_method_vars['prev_listordered'] = $prev_listordered;
17430  	 	 	 	 	 $this_method_vars['prev_listcount'] = $prev_listcount;
17431  	 	 	 	 	 $this_method_vars['prev_lispacer'] = $prev_lispacer;
17432  	 	 	 	 	 $this_method_vars['fontaligned'] = $fontaligned;
17433  	 	 	 	 	 $this_method_vars['key'] = $key;
17434  	 	 	 	 	 $this_method_vars['dom'] = $dom;
17435  	 	 	 	 }
17436  	 	 	 }
17437  	 	 	 // print THEAD block
17438  	 	 	 if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
17439  	 	 	 	 if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
17440  	 	 	 	 	 $this->inthead = true;
17441  	 	 	 	 	 // print table header (thead)
17442  	 	 	 	 	 $this->writeHTML($this->thead, false, false, false, false, '');
17443  	 	 	 	 	 // check if we are on a new page or on a new column
17444  	 	 	 	 	 if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
17445  	 	 	 	 	 	 // we are on a new page or on a new column and the total object height is less than the available vertical space.
17446  	 	 	 	 	 	 // restore previous object
17447  	 	 	 	 	 	 $this->rollbackTransaction(true);
17448  	 	 	 	 	 	 // restore previous values
17449  	 	 	 	 	 	 foreach ($this_method_vars as $vkey => $vval) {
17450  	 	 	 	 	 	 	 $$vkey = $vval;
17451  	 	 	 	 	 	 }
17452  	 	 	 	 	 	 // disable table header
17453  	 	 	 	 	 	 $tmp_thead = $this->thead;
17454  	 	 	 	 	 	 $this->thead = '';
17455  	 	 	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
17456  	 	 	 	 	 	 $pre_y = $this->y;
17457  	 	 	 	 	 	 if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
17458  	 	 	 	 	 	 	 // fix for multicolumn mode
17459  	 	 	 	 	 	 	 $startliney = $this->y;
17460  	 	 	 	 	 	 }
17461  	 	 	 	 	 	 $this->start_transaction_page = $this->page;
17462  	 	 	 	 	 	 $this->start_transaction_y = $this->y;
17463  	 	 	 	 	 	 // restore table header
17464  	 	 	 	 	 	 $this->thead = $tmp_thead;
17465  	 	 	 	 	 	 // fix table border properties
17466  	 	 	 	 	 	 if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
17467  	 	 	 	 	 	 	 $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
17468  	 	 	 	 	 	 } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
17469  	 	 	 	 	 	 	 $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
17470  	 	 	 	 	 	 } else {
17471  	 	 	 	 	 	 	 $tmp_cellspacing = 0;
17472  	 	 	 	 	 	 }
17473  	 	 	 	 	 	 $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
17474  	 	 	 	 	 	 $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
17475  	 	 	 	 	 	 $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
17476  	 	 	 	 	 	 $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
17477  	 	 	 	 	 	 $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
17478  	 	 	 	 	 	 $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
17479  	 	 	 	 	 	 // print table header (thead)
17480  	 	 	 	 	 	 $this->writeHTML($this->thead, false, false, false, false, '');
17481  	 	 	 	 	 }
17482  	 	 	 	 }
17483  	 	 	 	 // move $key index forward to skip THEAD block
17484  	 	 	 	 while ( ($key < $maxel) AND (!(
17485  	 	 	 	 	 ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
17486  	 	 	 	 	 OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
17487  	 	 	 	 	 ++$key;
17488  	 	 	 	 }
17489  	 	 	 }
17490  	 	 	 if ($dom[$key]['tag'] OR ($key == 0)) {
17491  	 	 	 	 if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
17492  	 	 	 	 	 $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
17493  	 	 	 	 }
17494  	 	 	 	 // vertically align image in line
17495  	 	 	 	 if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
17496  	 	 	 	 	 // get image height
17497  	 	 	 	 	 $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k), 'px');
17498  	 	 	 	 	 $autolinebreak = false;
17499  	 	 	 	 	 if (!empty($dom[$key]['width'])) {
17500  	 	 	 	 	 	 $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k), 'px', false);
17501  	 	 	 	 	 	 if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
17502  	 	 	 	 	 	 	 AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
17503  	 	 	 	 	 	 	 OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
17504  	 	 	 	 	 	 	 // add automatic line break
17505  	 	 	 	 	 	 	 $autolinebreak = true;
17506  	 	 	 	 	 	 	 $this->Ln('', $cell);
17507  	 	 	 	 	 	 	 if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
17508  	 	 	 	 	 	 	 	 // go back to evaluate this line break
17509  	 	 	 	 	 	 	 	 --$key;
17510  	 	 	 	 	 	 	 }
17511  	 	 	 	 	 	 }
17512  	 	 	 	 	 }
17513  	 	 	 	 	 if (!$autolinebreak) {
17514  	 	 	 	 	 	 if ($this->inPageBody()) {
17515  	 	 	 	 	 	 	 $pre_y = $this->y;
17516  	 	 	 	 	 	 	 // check for page break
17517  	 	 	 	 	 	 	 if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
17518  	 	 	 	 	 	 	 	 // fix for multicolumn mode
17519  	 	 	 	 	 	 	 	 $startliney = $this->y;
17520  	 	 	 	 	 	 	 }
17521  	 	 	 	 	 	 }
17522  	 	 	 	 	 	 if ($this->page > $startlinepage) {
17523  	 	 	 	 	 	 	 // fix line splitted over two pages
17524  	 	 	 	 	 	 	 if (isset($this->footerlen[$startlinepage])) {
17525  	 	 	 	 	 	 	 	 $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
17526  	 	 	 	 	 	 	 }
17527  	 	 	 	 	 	 	 // line to be moved one page forward
17528  	 	 	 	 	 	 	 $pagebuff = $this->getPageBuffer($startlinepage);
17529  	 	 	 	 	 	 	 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
17530  	 	 	 	 	 	 	 $tstart = substr($pagebuff, 0, $startlinepos);
17531  	 	 	 	 	 	 	 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
17532  	 	 	 	 	 	 	 // remove line from previous page
17533  	 	 	 	 	 	 	 $this->setPageBuffer($startlinepage, $tstart.''.$tend);
17534  	 	 	 	 	 	 	 $pagebuff = $this->getPageBuffer($this->page);
17535  	 	 	 	 	 	 	 $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
17536  	 	 	 	 	 	 	 $tend = substr($pagebuff, $this->cntmrk[$this->page]);
17537  	 	 	 	 	 	 	 // add line start to current page
17538  	 	 	 	 	 	 	 $yshift = ($minstartliney - $this->y);
17539  	 	 	 	 	 	 	 if ($fontaligned) {
17540  	 	 	 	 	 	 	 	 $yshift += ($curfontsize / $this->k);
17541  	 	 	 	 	 	 	 }
17542  	 	 	 	 	 	 	 $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
17543  	 	 	 	 	 	 	 $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
17544  	 	 	 	 	 	 	 // shift the annotations and links
17545  	 	 	 	 	 	 	 if (isset($this->PageAnnots[$this->page])) {
17546  	 	 	 	 	 	 	 	 $next_pask = count($this->PageAnnots[$this->page]);
17547  	 	 	 	 	 	 	 } else {
17548  	 	 	 	 	 	 	 	 $next_pask = 0;
17549  	 	 	 	 	 	 	 }
17550  	 	 	 	 	 	 	 if (isset($this->PageAnnots[$startlinepage])) {
17551  	 	 	 	 	 	 	 	 foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
17552  	 	 	 	 	 	 	 	 	 if ($pak >= $pask) {
17553  	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][] = $pac;
17554  	 	 	 	 	 	 	 	 	 	 unset($this->PageAnnots[$startlinepage][$pak]);
17555  	 	 	 	 	 	 	 	 	 	 $npak = count($this->PageAnnots[$this->page]) - 1;
17556  	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
17557  	 	 	 	 	 	 	 	 	 }
17558  	 	 	 	 	 	 	 	 }
17559  	 	 	 	 	 	 	 }
17560  	 	 	 	 	 	 	 $pask = $next_pask;
17561  	 	 	 	 	 	 	 $startlinepos = $this->cntmrk[$this->page];
17562  	 	 	 	 	 	 	 $startlinepage = $this->page;
17563  	 	 	 	 	 	 	 $startliney = $this->y;
17564  	 	 	 	 	 	 	 $this->newline = false;
17565  	 	 	 	 	 	 }
17566  	 	 	 	 	 	 $this->y += ($this->getCellHeight($curfontsize / $this->k) - ($curfontdescent * $this->cell_height_ratio) - $imgh);
17567  	 	 	 	 	 	 $minstartliney = min($this->y, $minstartliney);
17568  	 	 	 	 	 	 $maxbottomliney = ($startliney + $this->getCellHeight($curfontsize / $this->k));
17569  	 	 	 	 	 }
17570  	 	 	 	 } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
17571  	 	 	 	 	 // account for different font size
17572  	 	 	 	 	 $pfontname = $curfontname;
17573  	 	 	 	 	 $pfontstyle = $curfontstyle;
17574  	 	 	 	 	 $pfontsize = $curfontsize;
17575  	 	 	 	 	 $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
17576  	 	 	 	 	 $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
17577  	 	 	 	 	 $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
17578  	 	 	 	 	 $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
17579  	 	 	 	 	 $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
17580  	 	 	 	 	 if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
17581  	 	 	 	 	 	 OR ($this->cell_height_ratio != $dom[$key]['line-height'])
17582  	 	 	 	 	 	 OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
17583  	 	 	 	 	 	 if (($key < ($maxel - 1)) AND (
17584  	 	 	 	 	 	 	 	 ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
17585  	 	 	 	 	 	 	 	 OR ($this->cell_height_ratio != $dom[$key]['line-height'])
17586  	 	 	 	 	 	 	 	 OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize)
17587  	 	 	 	 	 	 	 	 AND ($fontsize >= 0) AND ($curfontsize >= 0)
17588  	 	 	 	 	 	 	 	 AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
17589  	 	 	 	 	 	 	 )) {
17590  	 	 	 	 	 	 	 if ($this->page > $startlinepage) {
17591  	 	 	 	 	 	 	 	 // fix lines splitted over two pages
17592  	 	 	 	 	 	 	 	 if (isset($this->footerlen[$startlinepage])) {
17593  	 	 	 	 	 	 	 	 	 $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
17594  	 	 	 	 	 	 	 	 }
17595  	 	 	 	 	 	 	 	 // line to be moved one page forward
17596  	 	 	 	 	 	 	 	 $pagebuff = $this->getPageBuffer($startlinepage);
17597  	 	 	 	 	 	 	 	 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
17598  	 	 	 	 	 	 	 	 $tstart = substr($pagebuff, 0, $startlinepos);
17599  	 	 	 	 	 	 	 	 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
17600  	 	 	 	 	 	 	 	 // remove line start from previous page
17601  	 	 	 	 	 	 	 	 $this->setPageBuffer($startlinepage, $tstart.''.$tend);
17602  	 	 	 	 	 	 	 	 $pagebuff = $this->getPageBuffer($this->page);
17603  	 	 	 	 	 	 	 	 $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
17604  	 	 	 	 	 	 	 	 $tend = substr($pagebuff, $this->cntmrk[$this->page]);
17605  	 	 	 	 	 	 	 	 // add line start to current page
17606  	 	 	 	 	 	 	 	 $yshift = ($minstartliney - $this->y);
17607  	 	 	 	 	 	 	 	 $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
17608  	 	 	 	 	 	 	 	 $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
17609  	 	 	 	 	 	 	 	 // shift the annotations and links
17610  	 	 	 	 	 	 	 	 if (isset($this->PageAnnots[$this->page])) {
17611  	 	 	 	 	 	 	 	 	 $next_pask = count($this->PageAnnots[$this->page]);
17612  	 	 	 	 	 	 	 	 } else {
17613  	 	 	 	 	 	 	 	 	 $next_pask = 0;
17614  	 	 	 	 	 	 	 	 }
17615  	 	 	 	 	 	 	 	 if (isset($this->PageAnnots[$startlinepage])) {
17616  	 	 	 	 	 	 	 	 	 foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
17617  	 	 	 	 	 	 	 	 	 	 if ($pak >= $pask) {
17618  	 	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][] = $pac;
17619  	 	 	 	 	 	 	 	 	 	 	 unset($this->PageAnnots[$startlinepage][$pak]);
17620  	 	 	 	 	 	 	 	 	 	 	 $npak = count($this->PageAnnots[$this->page]) - 1;
17621  	 	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
17622  	 	 	 	 	 	 	 	 	 	 }
17623  	 	 	 	 	 	 	 	 	 }
17624  	 	 	 	 	 	 	 	 }
17625  	 	 	 	 	 	 	 	 $pask = $next_pask;
17626  	 	 	 	 	 	 	 	 $startlinepos = $this->cntmrk[$this->page];
17627  	 	 	 	 	 	 	 	 $startlinepage = $this->page;
17628  	 	 	 	 	 	 	 	 $startliney = $this->y;
17629  	 	 	 	 	 	 	 }
17630  	 	 	 	 	 	 	 if (!isset($dom[$key]['line-height'])) {
17631  	 	 	 	 	 	 	 	 $dom[$key]['line-height'] = $this->cell_height_ratio;
17632  	 	 	 	 	 	 	 }
17633  	 	 	 	 	 	 	 if (!$dom[$key]['block']) {
17634  	 	 	 	 	 	 	 	 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']))) {
17635  	 	 	 	 	 	 	 	 	 $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
17636  	 	 	 	 	 	 	 	 }
17637  	 	 	 	 	 	 	 	 if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
17638  	 	 	 	 	 	 	 	 	 $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
17639  	 	 	 	 	 	 	 	 	 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)))) {
17640  	 	 	 	 	 	 	 	 	 	 $minstartliney = min($this->y, $line_align_data[1]);
17641  	 	 	 	 	 	 	 	 	 	 $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $line_align_data[2]);
17642  	 	 	 	 	 	 	 	 	 } else {
17643  	 	 	 	 	 	 	 	 	 	 $minstartliney = min($this->y, $minstartliney);
17644  	 	 	 	 	 	 	 	 	 	 $maxbottomliney = max(($this->y + $this->getCellHeight($fontsize / $this->k)), $maxbottomliney);
17645  	 	 	 	 	 	 	 	 	 }
17646  	 	 	 	 	 	 	 	 	 $line_align_data = $current_line_align_data;
17647  	 	 	 	 	 	 	 	 }
17648  	 	 	 	 	 	 	 }
17649  	 	 	 	 	 	 	 $this->cell_height_ratio = $dom[$key]['line-height'];
17650  	 	 	 	 	 	 	 $fontaligned = true;
17651  	 	 	 	 	 	 }
17652  	 	 	 	 	 	 $this->setFont($fontname, $fontstyle, $fontsize);
17653  	 	 	 	 	 	 // reset row height
17654  	 	 	 	 	 	 $this->resetLastH();
17655  	 	 	 	 	 	 $curfontname = $fontname;
17656  	 	 	 	 	 	 $curfontstyle = $fontstyle;
17657  	 	 	 	 	 	 $curfontsize = $fontsize;
17658  	 	 	 	 	 	 $curfontascent = $fontascent;
17659  	 	 	 	 	 	 $curfontdescent = $fontdescent;
17660  	 	 	 	 	 }
17661  	 	 	 	 }
17662  	 	 	 	 // set text rendering mode
17663  	 	 	 	 $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
17664  	 	 	 	 $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
17665  	 	 	 	 $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
17666  	 	 	 	 $this->setTextRenderingMode($textstroke, $textfill, $textclip);
17667  	 	 	 	 if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
17668  	 	 	 	 	 $this->setFontStretching($dom[$key]['font-stretch']);
17669  	 	 	 	 }
17670  	 	 	 	 if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
17671  	 	 	 	 	 $this->setFontSpacing($dom[$key]['letter-spacing']);
17672  	 	 	 	 }
17673  	 	 	 	 if (($plalign == 'J') AND $dom[$key]['block']) {
17674  	 	 	 	 	 $plalign = '';
17675  	 	 	 	 }
17676  	 	 	 	 // get current position on page buffer
17677  	 	 	 	 $curpos = $this->pagelen[$startlinepage];
17678  	 	 	 	 if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
17679  	 	 	 	 	 $this->setFillColorArray($dom[$key]['bgcolor']);
17680  	 	 	 	 	 $wfill = true;
17681  	 	 	 	 } else {
17682  	 	 	 	 	 $wfill = $fill | false;
17683  	 	 	 	 }
17684  	 	 	 	 if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
17685  	 	 	 	 	 $this->setTextColorArray($dom[$key]['fgcolor']);
17686  	 	 	 	 }
17687  	 	 	 	 if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
17688  	 	 	 	 	 $this->setDrawColorArray($dom[$key]['strokecolor']);
17689  	 	 	 	 }
17690  	 	 	 	 if (isset($dom[$key]['align'])) {
17691  	 	 	 	 	 $lalign = $dom[$key]['align'];
17692  	 	 	 	 }
17693  	 	 	 	 if (TCPDF_STATIC::empty_string($lalign)) {
17694  	 	 	 	 	 $lalign = $align;
17695  	 	 	 	 }
17696  	 	 	 }
17697  	 	 	 // align lines
17698  	 	 	 if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
17699  	 	 	 	 $newline = true;
17700  	 	 	 	 $fontaligned = false;
17701  	 	 	 	 // we are at the beginning of a new line
17702  	 	 	 	 if (isset($startlinex)) {
17703  	 	 	 	 	 $yshift = ($minstartliney - $startliney);
17704  	 	 	 	 	 if (($yshift > 0) OR ($this->page > $startlinepage)) {
17705  	 	 	 	 	 	 $yshift = 0;
17706  	 	 	 	 	 }
17707  	 	 	 	 	 $t_x = 0;
17708  	 	 	 	 	 // the last line must be shifted to be aligned as requested
17709  	 	 	 	 	 $linew = abs($this->endlinex - $startlinex);
17710  	 	 	 	 	 if ($this->inxobj) {
17711  	 	 	 	 	 	 // we are inside an XObject template
17712  	 	 	 	 	 	 $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
17713  	 	 	 	 	 	 if (isset($opentagpos)) {
17714  	 	 	 	 	 	 	 $midpos = $opentagpos;
17715  	 	 	 	 	 	 } else {
17716  	 	 	 	 	 	 	 $midpos = 0;
17717  	 	 	 	 	 	 }
17718  	 	 	 	 	 	 if ($midpos > 0) {
17719  	 	 	 	 	 	 	 $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
17720  	 	 	 	 	 	 	 $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
17721  	 	 	 	 	 	 } else {
17722  	 	 	 	 	 	 	 $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
17723  	 	 	 	 	 	 	 $pend = '';
17724  	 	 	 	 	 	 }
17725  	 	 	 	 	 } else {
17726  	 	 	 	 	 	 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
17727  	 	 	 	 	 	 if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
17728  	 	 	 	 	 	 	 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
17729  	 	 	 	 	 	 	 $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
17730  	 	 	 	 	 	 } elseif (isset($opentagpos)) {
17731  	 	 	 	 	 	 	 $midpos = $opentagpos;
17732  	 	 	 	 	 	 } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
17733  	 	 	 	 	 	 	 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
17734  	 	 	 	 	 	 	 $midpos = $this->footerpos[$startlinepage];
17735  	 	 	 	 	 	 } else {
17736  	 	 	 	 	 	 	 $midpos = 0;
17737  	 	 	 	 	 	 }
17738  	 	 	 	 	 	 if ($midpos > 0) {
17739  	 	 	 	 	 	 	 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
17740  	 	 	 	 	 	 	 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
17741  	 	 	 	 	 	 } else {
17742  	 	 	 	 	 	 	 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
17743  	 	 	 	 	 	 	 $pend = '';
17744  	 	 	 	 	 	 }
17745  	 	 	 	 	 }
17746  	 	 	 	 	 if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
17747  	 	 	 	 	 	 // calculate shifting amount
17748  	 	 	 	 	 	 $tw = $w;
17749  	 	 	 	 	 	 if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
17750  	 	 	 	 	 	 	 $tw += $this->cell_padding['R'];
17751  	 	 	 	 	 	 }
17752  	 	 	 	 	 	 if ($this->lMargin != $prevlMargin) {
17753  	 	 	 	 	 	 	 $tw += ($prevlMargin - $this->lMargin);
17754  	 	 	 	 	 	 }
17755  	 	 	 	 	 	 if ($this->rMargin != $prevrMargin) {
17756  	 	 	 	 	 	 	 $tw += ($prevrMargin - $this->rMargin);
17757  	 	 	 	 	 	 }
17758  	 	 	 	 	 	 $one_space_width = $this->GetStringWidth(chr(32));
17759  	 	 	 	 	 	 $no = 0; // number of spaces on a line contained on a single block
17760  	 	 	 	 	 	 if ($this->isRTLTextDir()) { // RTL
17761  	 	 	 	 	 	 	 // remove left space if exist
17762  	 	 	 	 	 	 	 $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
17763  	 	 	 	 	 	 	 if ($pos1 > 0) {
17764  	 	 	 	 	 	 	 	 $pos1 = intval($pos1);
17765  	 	 	 	 	 	 	 	 if ($this->isUnicodeFont()) {
17766  	 	 	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
17767  	 	 	 	 	 	 	 	 	 $spacelen = 2;
17768  	 	 	 	 	 	 	 	 } else {
17769  	 	 	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
17770  	 	 	 	 	 	 	 	 	 $spacelen = 1;
17771  	 	 	 	 	 	 	 	 }
17772  	 	 	 	 	 	 	 	 if ($pos1 == $pos2) {
17773  	 	 	 	 	 	 	 	 	 $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
17774  	 	 	 	 	 	 	 	 	 if (substr($pmid, $pos1, 4) == '[()]') {
17775  	 	 	 	 	 	 	 	 	 	 $linew -= $one_space_width;
17776  	 	 	 	 	 	 	 	 	 } elseif ($pos1 == strpos($pmid, '[(')) {
17777  	 	 	 	 	 	 	 	 	 	 $no = 1;
17778  	 	 	 	 	 	 	 	 	 }
17779  	 	 	 	 	 	 	 	 }
17780  	 	 	 	 	 	 	 }
17781  	 	 	 	 	 	 } else { // LTR
17782  	 	 	 	 	 	 	 // remove right space if exist
17783  	 	 	 	 	 	 	 $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
17784  	 	 	 	 	 	 	 if ($pos1 > 0) {
17785  	 	 	 	 	 	 	 	 $pos1 = intval($pos1);
17786  	 	 	 	 	 	 	 	 if ($this->isUnicodeFont()) {
17787  	 	 	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
17788  	 	 	 	 	 	 	 	 	 $spacelen = 2;
17789  	 	 	 	 	 	 	 	 } else {
17790  	 	 	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
17791  	 	 	 	 	 	 	 	 	 $spacelen = 1;
17792  	 	 	 	 	 	 	 	 }
17793  	 	 	 	 	 	 	 	 if ($pos1 == $pos2) {
17794  	 	 	 	 	 	 	 	 	 $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
17795  	 	 	 	 	 	 	 	 	 $linew -= $one_space_width;
17796  	 	 	 	 	 	 	 	 }
17797  	 	 	 	 	 	 	 }
17798  	 	 	 	 	 	 }
17799  	 	 	 	 	 	 $mdiff = ($tw - $linew);
17800  	 	 	 	 	 	 if ($plalign == 'C') {
17801  	 	 	 	 	 	 	 if ($this->rtl) {
17802  	 	 	 	 	 	 	 	 $t_x = -($mdiff / 2);
17803  	 	 	 	 	 	 	 } else {
17804  	 	 	 	 	 	 	 	 $t_x = ($mdiff / 2);
17805  	 	 	 	 	 	 	 }
17806  	 	 	 	 	 	 } elseif ($plalign == 'R') {
17807  	 	 	 	 	 	 	 // right alignment on LTR document
17808  	 	 	 	 	 	 	 $t_x = $mdiff;
17809  	 	 	 	 	 	 } elseif ($plalign == 'L') {
17810  	 	 	 	 	 	 	 // left alignment on RTL document
17811  	 	 	 	 	 	 	 $t_x = -$mdiff;
17812  	 	 	 	 	 	 } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
17813  	 	 	 	 	 	 	 // Justification
17814  	 	 	 	 	 	 	 if ($this->isRTLTextDir()) {
17815  	 	 	 	 	 	 	 	 // align text on the left
17816  	 	 	 	 	 	 	 	 $t_x = -$mdiff;
17817  	 	 	 	 	 	 	 }
17818  	 	 	 	 	 	 	 $ns = 0; // number of spaces
17819  	 	 	 	 	 	 	 $pmidtemp = $pmid;
17820  	 	 	 	 	 	 	 // escape special characters
17821  	 	 	 	 	 	 	 $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
17822  	 	 	 	 	 	 	 $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
17823  	 	 	 	 	 	 	 // search spaces
17824  	 	 	 	 	 	 	 if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
17825  	 	 	 	 	 	 	 	 $spacestr = $this->getSpaceString();
17826  	 	 	 	 	 	 	 	 $maxkk = count($lnstring[1]) - 1;
17827  	 	 	 	 	 	 	 	 for ($kk=0; $kk <= $maxkk; ++$kk) {
17828  	 	 	 	 	 	 	 	 	 // restore special characters
17829  	 	 	 	 	 	 	 	 	 $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
17830  	 	 	 	 	 	 	 	 	 $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
17831  	 	 	 	 	 	 	 	 	 // store number of spaces on the strings
17832  	 	 	 	 	 	 	 	 	 $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
17833  	 	 	 	 	 	 	 	 	 // count total spaces on line
17834  	 	 	 	 	 	 	 	 	 $ns += $lnstring[2][$kk];
17835  	 	 	 	 	 	 	 	 	 $lnstring[3][$kk] = $ns;
17836  	 	 	 	 	 	 	 	 }
17837  	 	 	 	 	 	 	 	 if ($ns == 0) {
17838  	 	 	 	 	 	 	 	 	 $ns = 1;
17839  	 	 	 	 	 	 	 	 }
17840  	 	 	 	 	 	 	 	 // calculate additional space to add to each existing space
17841  	 	 	 	 	 	 	 	 $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
17842  	 	 	 	 	 	 	 	 if ($this->FontSize <= 0) {
17843  	 	 	 	 	 	 	 	 	 $this->FontSize = 1;
17844  	 	 	 	 	 	 	 	 }
17845  	 	 	 	 	 	 	 	 $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
17846  	 	 	 	 	 	 	 	 if ($this->font_spacing != 0) {
17847  	 	 	 	 	 	 	 	 	 // fixed spacing mode
17848  	 	 	 	 	 	 	 	 	 $osw = -1000 * $this->font_spacing / $this->FontSize;
17849  	 	 	 	 	 	 	 	 	 $spacewidthu += $osw;
17850  	 	 	 	 	 	 	 	 }
17851  	 	 	 	 	 	 	 	 $nsmax = $ns;
17852  	 	 	 	 	 	 	 	 $ns = 0;
17853  	 	 	 	 	 	 	 	 reset($lnstring);
17854  	 	 	 	 	 	 	 	 $offset = 0;
17855  	 	 	 	 	 	 	 	 $strcount = 0;
17856  	 	 	 	 	 	 	 	 $prev_epsposbeg = 0;
17857  	 	 	 	 	 	 	 	 $textpos = 0;
17858  	 	 	 	 	 	 	 	 if ($this->isRTLTextDir()) {
17859  	 	 	 	 	 	 	 	 	 $textpos = $this->wPt;
17860  	 	 	 	 	 	 	 	 }
17861  	 	 	 	 	 	 	 	 while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
17862  	 	 	 	 	 	 	 	 	 // check if we are inside a string section '[( ... )]'
17863  	 	 	 	 	 	 	 	 	 $stroffset = strpos($pmid, '[(', $offset);
17864  	 	 	 	 	 	 	 	 	 if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
17865  	 	 	 	 	 	 	 	 	 	 // set offset to the end of string section
17866  	 	 	 	 	 	 	 	 	 	 $offset = strpos($pmid, ')]', $stroffset);
17867  	 	 	 	 	 	 	 	 	 	 while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
17868  	 	 	 	 	 	 	 	 	 	 	 $offset = strpos($pmid, ')]', ($offset + 1));
17869  	 	 	 	 	 	 	 	 	 	 }
17870  	 	 	 	 	 	 	 	 	 	 if ($offset === false) {
17871  	 	 	 	 	 	 	 	 	 	 	 $this->Error('HTML Justification: malformed PDF code.');
17872  	 	 	 	 	 	 	 	 	 	 }
17873  	 	 	 	 	 	 	 	 	 	 continue;
17874  	 	 	 	 	 	 	 	 	 }
17875  	 	 	 	 	 	 	 	 	 if ($this->isRTLTextDir()) {
17876  	 	 	 	 	 	 	 	 	 	 $spacew = ($spacewidth * ($nsmax - $ns));
17877  	 	 	 	 	 	 	 	 	 } else {
17878  	 	 	 	 	 	 	 	 	 	 $spacew = ($spacewidth * $ns);
17879  	 	 	 	 	 	 	 	 	 }
17880  	 	 	 	 	 	 	 	 	 $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
17881  	 	 	 	 	 	 	 	 	 $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset);
17882  	 	 	 	 	 	 	 	 	 if ($epsposend !== null) {
17883  	 	 	 	 	 	 	 	 	 	 $epsposend += strlen($this->epsmarker.'Q');
17884  	 	 	 	 	 	 	 	 	 	 $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
17885  	 	 	 	 	 	 	 	 	 	 if ($epsposbeg === null) {
17886  	 	 	 	 	 	 	 	 	 	 	 $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
17887  	 	 	 	 	 	 	 	 	 	 	 $prev_epsposbeg = $epsposbeg;
17888  	 	 	 	 	 	 	 	 	 	 }
17889  	 	 	 	 	 	 	 	 	 	 if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) {
17890  	 	 	 	 	 	 	 	 	 	 	 // shift EPS images
17891  	 	 	 	 	 	 	 	 	 	 	 $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
17892  	 	 	 	 	 	 	 	 	 	 	 $pmid_b = substr($pmid, 0, $epsposbeg);
17893  	 	 	 	 	 	 	 	 	 	 	 $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
17894  	 	 	 	 	 	 	 	 	 	 	 $pmid_e = substr($pmid, $epsposend);
17895  	 	 	 	 	 	 	 	 	 	 	 $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
17896  	 	 	 	 	 	 	 	 	 	 	 $offset = $epsposend;
17897  	 	 	 	 	 	 	 	 	 	 	 continue;
17898  	 	 	 	 	 	 	 	 	 	 }
17899  	 	 	 	 	 	 	 	 	 }
17900  	 	 	 	 	 	 	 	 	 $currentxpos = 0;
17901  	 	 	 	 	 	 	 	 	 // shift blocks of code
17902  	 	 	 	 	 	 	 	 	 switch ($strpiece[2][0]) {
17903  	 	 	 	 	 	 	 	 	 	 case 'Td':
17904  	 	 	 	 	 	 	 	 	 	 case 'cm':
17905  	 	 	 	 	 	 	 	 	 	 case 'm':
17906  	 	 	 	 	 	 	 	 	 	 case 'l': {
17907  	 	 	 	 	 	 	 	 	 	 	 // get current X position
17908  	 	 	 	 	 	 	 	 	 	 	 preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
17909  	 	 	 	 	 	 	 	 	 	 	 if (!isset($xmatches[1])) {
17910  	 	 	 	 	 	 	 	 	 	 	 	 break;
17911  	 	 	 	 	 	 	 	 	 	 	 }
17912  	 	 	 	 	 	 	 	 	 	 	 $currentxpos = $xmatches[1];
17913  	 	 	 	 	 	 	 	 	 	 	 $textpos = $currentxpos;
17914  	 	 	 	 	 	 	 	 	 	 	 if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
17915  	 	 	 	 	 	 	 	 	 	 	 	 $ns = $lnstring[3][$strcount];
17916  	 	 	 	 	 	 	 	 	 	 	 	 if ($this->isRTLTextDir()) {
17917  	 	 	 	 	 	 	 	 	 	 	 	 	 $spacew = ($spacewidth * ($nsmax - $ns));
17918  	 	 	 	 	 	 	 	 	 	 	 	 }
17919  	 	 	 	 	 	 	 	 	 	 	 	 ++$strcount;
17920  	 	 	 	 	 	 	 	 	 	 	 }
17921  	 	 	 	 	 	 	 	 	 	 	 // justify block
17922  	 	 	 	 	 	 	 	 	 	 	 if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
17923  	 	 	 	 	 	 	 	 	 	 	 	 $newpmid = sprintf('%F',(floatval($pmatch[1]) + $spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
17924  	 	 	 	 	 	 	 	 	 	 	 	 $pmid = str_replace($pmatch[0], $newpmid, $pmid);
17925  	 	 	 	 	 	 	 	 	 	 	 	 unset($pmatch, $newpmid);
17926  	 	 	 	 	 	 	 	 	 	 	 }
17927  	 	 	 	 	 	 	 	 	 	 	 break;
17928  	 	 	 	 	 	 	 	 	 	 }
17929  	 	 	 	 	 	 	 	 	 	 case 're': {
17930  	 	 	 	 	 	 	 	 	 	 	 // justify block
17931  	 	 	 	 	 	 	 	 	 	 	 if (!TCPDF_STATIC::empty_string($this->lispacer)) {
17932  	 	 	 	 	 	 	 	 	 	 	 	 $this->lispacer = '';
17933  	 	 	 	 	 	 	 	 	 	 	 	 break;
17934  	 	 	 	 	 	 	 	 	 	 	 }
17935  	 	 	 	 	 	 	 	 	 	 	 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
17936  	 	 	 	 	 	 	 	 	 	 	 if (!isset($xmatches[1])) {
17937  	 	 	 	 	 	 	 	 	 	 	 	 break;
17938  	 	 	 	 	 	 	 	 	 	 	 }
17939  	 	 	 	 	 	 	 	 	 	 	 $currentxpos = $xmatches[1];
17940  	 	 	 	 	 	 	 	 	 	 	 $x_diff = 0;
17941  	 	 	 	 	 	 	 	 	 	 	 $w_diff = 0;
17942  	 	 	 	 	 	 	 	 	 	 	 if ($this->isRTLTextDir()) { // RTL
17943  	 	 	 	 	 	 	 	 	 	 	 	 if ($currentxpos < $textpos) {
17944  	 	 	 	 	 	 	 	 	 	 	 	 	 $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
17945  	 	 	 	 	 	 	 	 	 	 	 	 	 $w_diff = ($spacewidth * $lnstring[2][$strcount]);
17946  	 	 	 	 	 	 	 	 	 	 	 	 } else {
17947  	 	 	 	 	 	 	 	 	 	 	 	 	 if ($strcount > 0) {
17948  	 	 	 	 	 	 	 	 	 	 	 	 	 	 $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
17949  	 	 	 	 	 	 	 	 	 	 	 	 	 	 $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
17950  	 	 	 	 	 	 	 	 	 	 	 	 	 }
17951  	 	 	 	 	 	 	 	 	 	 	 	 }
17952  	 	 	 	 	 	 	 	 	 	 	 } else { // LTR
17953  	 	 	 	 	 	 	 	 	 	 	 	 if ($currentxpos > $textpos) {
17954  	 	 	 	 	 	 	 	 	 	 	 	 	 if ($strcount > 0) {
17955  	 	 	 	 	 	 	 	 	 	 	 	 	 	 $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
17956  	 	 	 	 	 	 	 	 	 	 	 	 	 }
17957  	 	 	 	 	 	 	 	 	 	 	 	 	 $w_diff = ($spacewidth * $lnstring[2][$strcount]);
17958  	 	 	 	 	 	 	 	 	 	 	 	 } else {
17959  	 	 	 	 	 	 	 	 	 	 	 	 	 if ($strcount > 1) {
17960  	 	 	 	 	 	 	 	 	 	 	 	 	 	 $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
17961  	 	 	 	 	 	 	 	 	 	 	 	 	 }
17962  	 	 	 	 	 	 	 	 	 	 	 	 	 if ($strcount > 0) {
17963  	 	 	 	 	 	 	 	 	 	 	 	 	 	 $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
17964  	 	 	 	 	 	 	 	 	 	 	 	 	 }
17965  	 	 	 	 	 	 	 	 	 	 	 	 }
17966  	 	 	 	 	 	 	 	 	 	 	 }
17967  	 	 	 	 	 	 	 	 	 	 	 if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
17968  	 	 	 	 	 	 	 	 	 	 	 	 $newx = sprintf('%F',(floatval($pmatch[1]) + $x_diff));
17969  	 	 	 	 	 	 	 	 	 	 	 	 $neww = sprintf('%F',(floatval($pmatch[3]) + $w_diff));
17970  	 	 	 	 	 	 	 	 	 	 	 	 $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
17971  	 	 	 	 	 	 	 	 	 	 	 	 $pmid = str_replace($pmatch[0], $newpmid, $pmid);
17972  	 	 	 	 	 	 	 	 	 	 	 	 unset($pmatch, $newpmid, $newx, $neww);
17973  	 	 	 	 	 	 	 	 	 	 	 }
17974  	 	 	 	 	 	 	 	 	 	 	 break;
17975  	 	 	 	 	 	 	 	 	 	 }
17976  	 	 	 	 	 	 	 	 	 	 case 'c': {
17977  	 	 	 	 	 	 	 	 	 	 	 // get current X position
17978  	 	 	 	 	 	 	 	 	 	 	 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);
17979  	 	 	 	 	 	 	 	 	 	 	 if (!isset($xmatches[1])) {
17980  	 	 	 	 	 	 	 	 	 	 	 	 break;
17981  	 	 	 	 	 	 	 	 	 	 	 }
17982  	 	 	 	 	 	 	 	 	 	 	 $currentxpos = $xmatches[1];
17983  	 	 	 	 	 	 	 	 	 	 	 // justify block
17984  	 	 	 	 	 	 	 	 	 	 	 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) {
17985  	 	 	 	 	 	 	 	 	 	 	 	 $newx1 = sprintf('%F',(floatval($pmatch[1]) + $spacew));
17986  	 	 	 	 	 	 	 	 	 	 	 	 $newx2 = sprintf('%F',(floatval($pmatch[3]) + $spacew));
17987  	 	 	 	 	 	 	 	 	 	 	 	 $newx3 = sprintf('%F',(floatval($pmatch[5]) + $spacew));
17988  	 	 	 	 	 	 	 	 	 	 	 	 $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
17989  	 	 	 	 	 	 	 	 	 	 	 	 $pmid = str_replace($pmatch[0], $newpmid, $pmid);
17990  	 	 	 	 	 	 	 	 	 	 	 	 unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
17991  	 	 	 	 	 	 	 	 	 	 	 }
17992  	 	 	 	 	 	 	 	 	 	 	 break;
17993  	 	 	 	 	 	 	 	 	 	 }
17994  	 	 	 	 	 	 	 	 	 }
17995  	 	 	 	 	 	 	 	 	 // shift the annotations and links
17996  	 	 	 	 	 	 	 	 	 $cxpos = ($currentxpos / $this->k);
17997  	 	 	 	 	 	 	 	 	 $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
17998  	 	 	 	 	 	 	 	 	 if ($this->inxobj) {
17999  	 	 	 	 	 	 	 	 	 	 // we are inside an XObject template
18000  	 	 	 	 	 	 	 	 	 	 foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
18001  	 	 	 	 	 	 	 	 	 	 	 if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
18002  	 	 	 	 	 	 	 	 	 	 	 	 if ($cxpos > $lmpos) {
18003  	 	 	 	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
18004  	 	 	 	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
18005  	 	 	 	 	 	 	 	 	 	 	 	 } else {
18006  	 	 	 	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
18007  	 	 	 	 	 	 	 	 	 	 	 	 }
18008  	 	 	 	 	 	 	 	 	 	 	 	 break;
18009  	 	 	 	 	 	 	 	 	 	 	 }
18010  	 	 	 	 	 	 	 	 	 	 }
18011  	 	 	 	 	 	 	 	 	 } elseif (isset($this->PageAnnots[$this->page])) {
18012  	 	 	 	 	 	 	 	 	 	 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
18013  	 	 	 	 	 	 	 	 	 	 	 if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
18014  	 	 	 	 	 	 	 	 	 	 	 	 if ($cxpos > $lmpos) {
18015  	 	 	 	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
18016  	 	 	 	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
18017  	 	 	 	 	 	 	 	 	 	 	 	 } else {
18018  	 	 	 	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
18019  	 	 	 	 	 	 	 	 	 	 	 	 }
18020  	 	 	 	 	 	 	 	 	 	 	 	 break;
18021  	 	 	 	 	 	 	 	 	 	 	 }
18022  	 	 	 	 	 	 	 	 	 	 }
18023  	 	 	 	 	 	 	 	 	 }
18024  	 	 	 	 	 	 	 	 } // end of while
18025  	 	 	 	 	 	 	 	 // remove markers
18026  	 	 	 	 	 	 	 	 $pmid = str_replace('x*#!#*x', '', $pmid);
18027  	 	 	 	 	 	 	 	 if ($this->isUnicodeFont()) {
18028  	 	 	 	 	 	 	 	 	 // multibyte characters
18029  	 	 	 	 	 	 	 	 	 $spacew = $spacewidthu;
18030  	 	 	 	 	 	 	 	 	 if ($this->font_stretching != 100) {
18031  	 	 	 	 	 	 	 	 	 	 // word spacing is affected by stretching
18032  	 	 	 	 	 	 	 	 	 	 $spacew /= ($this->font_stretching / 100);
18033  	 	 	 	 	 	 	 	 	 }
18034  	 	 	 	 	 	 	 	 	 // escape special characters
18035  	 	 	 	 	 	 	 	 	 $pos = 0;
18036  	 	 	 	 	 	 	 	 	 $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
18037  	 	 	 	 	 	 	 	 	 $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
18038  	 	 	 	 	 	 	 	 	 if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
18039  	 	 	 	 	 	 	 	 	 	 foreach($pamatch[0] as $pk => $pmatch) {
18040  	 	 	 	 	 	 	 	 	 	 	 $replace = $pamatch[1][$pk];
18041  	 	 	 	 	 	 	 	 	 	 	 $replace = str_replace('#!#OP#!#', '(', $replace);
18042  	 	 	 	 	 	 	 	 	 	 	 $replace = str_replace('#!#CP#!#', ')', $replace);
18043  	 	 	 	 	 	 	 	 	 	 	 $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]';
18044  	 	 	 	 	 	 	 	 	 	 	 $pos = strpos($pmid, $pmatch, $pos);
18045  	 	 	 	 	 	 	 	 	 	 	 if ($pos !== FALSE) {
18046  	 	 	 	 	 	 	 	 	 	 	 	 $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch));
18047  	 	 	 	 	 	 	 	 	 	 	 }
18048  	 	 	 	 	 	 	 	 	 	 	 ++$pos;
18049  	 	 	 	 	 	 	 	 	 	 }
18050  	 	 	 	 	 	 	 	 	 	 unset($pamatch);
18051  	 	 	 	 	 	 	 	 	 }
18052  	 	 	 	 	 	 	 	 	 if ($this->inxobj) {
18053  	 	 	 	 	 	 	 	 	 	 // we are inside an XObject template
18054  	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
18055  	 	 	 	 	 	 	 	 	 } else {
18056  	 	 	 	 	 	 	 	 	 	 $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
18057  	 	 	 	 	 	 	 	 	 }
18058  	 	 	 	 	 	 	 	 	 $endlinepos = strlen($pstart."\n".$pmid."\n");
18059  	 	 	 	 	 	 	 	 } else {
18060  	 	 	 	 	 	 	 	 	 // non-unicode (single-byte characters)
18061  	 	 	 	 	 	 	 	 	 if ($this->font_stretching != 100) {
18062  	 	 	 	 	 	 	 	 	 	 // word spacing (Tw) is affected by stretching
18063  	 	 	 	 	 	 	 	 	 	 $spacewidth /= ($this->font_stretching / 100);
18064  	 	 	 	 	 	 	 	 	 }
18065  	 	 	 	 	 	 	 	 	 $rs = sprintf('%F Tw', $spacewidth);
18066  	 	 	 	 	 	 	 	 	 $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
18067  	 	 	 	 	 	 	 	 	 if ($this->inxobj) {
18068  	 	 	 	 	 	 	 	 	 	 // we are inside an XObject template
18069  	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
18070  	 	 	 	 	 	 	 	 	 } else {
18071  	 	 	 	 	 	 	 	 	 	 $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
18072  	 	 	 	 	 	 	 	 	 }
18073  	 	 	 	 	 	 	 	 	 $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
18074  	 	 	 	 	 	 	 	 }
18075  	 	 	 	 	 	 	 }
18076  	 	 	 	 	 	 } // end of J
18077  	 	 	 	 	 } // end if $startlinex
18078  	 	 	 	 	 if (($t_x != 0) OR ($yshift < 0)) {
18079  	 	 	 	 	 	 // shift the line
18080  	 	 	 	 	 	 $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
18081  	 	 	 	 	 	 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
18082  	 	 	 	 	 	 $endlinepos = strlen($pstart);
18083  	 	 	 	 	 	 if ($this->inxobj) {
18084  	 	 	 	 	 	 	 // we are inside an XObject template
18085  	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
18086  	 	 	 	 	 	 	 foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
18087  	 	 	 	 	 	 	 	 if ($pak >= $pask) {
18088  	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
18089  	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
18090  	 	 	 	 	 	 	 	 }
18091  	 	 	 	 	 	 	 }
18092  	 	 	 	 	 	 } else {
18093  	 	 	 	 	 	 	 $this->setPageBuffer($startlinepage, $pstart.$pend);
18094  	 	 	 	 	 	 	 // shift the annotations and links
18095  	 	 	 	 	 	 	 if (isset($this->PageAnnots[$this->page])) {
18096  	 	 	 	 	 	 	 	 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
18097  	 	 	 	 	 	 	 	 	 if ($pak >= $pask) {
18098  	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
18099  	 	 	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
18100  	 	 	 	 	 	 	 	 	 }
18101  	 	 	 	 	 	 	 	 }
18102  	 	 	 	 	 	 	 }
18103  	 	 	 	 	 	 }
18104  	 	 	 	 	 	 $this->y -= $yshift;
18105  	 	 	 	 	 }
18106  	 	 	 	 }
18107  	 	 	 	 $pbrk = $this->checkPageBreak($this->lasth);
18108  	 	 	 	 $this->newline = false;
18109  	 	 	 	 $startlinex = $this->x;
18110  	 	 	 	 $startliney = $this->y;
18111  	 	 	 	 if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
18112  	 	 	 	 	 $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
18113  	 	 	 	 } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
18114  	 	 	 	 	 $startliney -= (($this->FontSizePt / 0.7) / $this->k);
18115  	 	 	 	 } else {
18116  	 	 	 	 	 $minstartliney = $startliney;
18117  	 	 	 	 	 $maxbottomliney = ($this->y + $this->getCellHeight($fontsize / $this->k));
18118  	 	 	 	 }
18119  	 	 	 	 $startlinepage = $this->page;
18120  	 	 	 	 if (isset($endlinepos) AND (!$pbrk)) {
18121  	 	 	 	 	 $startlinepos = $endlinepos;
18122  	 	 	 	 } else {
18123  	 	 	 	 	 if ($this->inxobj) {
18124  	 	 	 	 	 	 // we are inside an XObject template
18125  	 	 	 	 	 	 $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
18126  	 	 	 	 	 } elseif (!$this->InFooter) {
18127  	 	 	 	 	 	 if (isset($this->footerlen[$this->page])) {
18128  	 	 	 	 	 	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
18129  	 	 	 	 	 	 } else {
18130  	 	 	 	 	 	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page];
18131  	 	 	 	 	 	 }
18132  	 	 	 	 	 	 $startlinepos = $this->footerpos[$this->page];
18133  	 	 	 	 	 } else {
18134  	 	 	 	 	 	 $startlinepos = $this->pagelen[$this->page];
18135  	 	 	 	 	 }
18136  	 	 	 	 }
18137  	 	 	 	 unset($endlinepos);
18138  	 	 	 	 $plalign = $lalign;
18139  	 	 	 	 if (isset($this->PageAnnots[$this->page])) {
18140  	 	 	 	 	 $pask = count($this->PageAnnots[$this->page]);
18141  	 	 	 	 } else {
18142  	 	 	 	 	 $pask = 0;
18143  	 	 	 	 }
18144  	 	 	 	 if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
18145  	 	 	 	 	 AND (isset($this->emptypagemrk[$this->page]))
18146  	 	 	 	 	 AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
18147  	 	 	 	 	 $this->setFont($fontname, $fontstyle, $fontsize);
18148  	 	 	 	 	 if ($wfill) {
18149  	 	 	 	 	 	 $this->setFillColorArray($this->bgcolor);
18150  	 	 	 	 	 }
18151  	 	 	 	 }
18152  	 	 	 } // end newline
18153  	 	 	 if (isset($opentagpos)) {
18154  	 	 	 	 unset($opentagpos);
18155  	 	 	 }
18156  	 	 	 if ($dom[$key]['tag']) {
18157  	 	 	 	 if ($dom[$key]['opening']) {
18158  	 	 	 	 	 // get text indentation (if any)
18159  	 	 	 	 	 if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
18160  	 	 	 	 	 	 $this->textindent = $dom[$key]['text-indent'];
18161  	 	 	 	 	 	 $this->newline = true;
18162  	 	 	 	 	 }
18163  	 	 	 	 	 // table
18164  	 	 	 	 	 if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
18165  	 	 	 	 	 	 // available page width
18166  	 	 	 	 	 	 if ($this->rtl) {
18167  	 	 	 	 	 	 	 $wtmp = $this->x - $this->lMargin;
18168  	 	 	 	 	 	 } else {
18169  	 	 	 	 	 	 	 $wtmp = $this->w - $this->rMargin - $this->x;
18170  	 	 	 	 	 	 }
18171  	 	 	 	 	 	 // get cell spacing
18172  	 	 	 	 	 	 if (isset($dom[$key]['attribute']['cellspacing'])) {
18173  	 	 	 	 	 	 	 $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
18174  	 	 	 	 	 	 	 $cellspacing = array('H' => $clsp, 'V' => $clsp);
18175  	 	 	 	 	 	 } elseif (isset($dom[$key]['border-spacing'])) {
18176  	 	 	 	 	 	 	 $cellspacing = $dom[$key]['border-spacing'];
18177  	 	 	 	 	 	 } else {
18178  	 	 	 	 	 	 	 $cellspacing = array('H' => 0, 'V' => 0);
18179  	 	 	 	 	 	 }
18180  	 	 	 	 	 	 // table width
18181  	 	 	 	 	 	 if (isset($dom[$key]['width'])) {
18182  	 	 	 	 	 	 	 $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
18183  	 	 	 	 	 	 } else {
18184  	 	 	 	 	 	 	 $table_width = $wtmp;
18185  	 	 	 	 	 	 }
18186  	 	 	 	 	 	 $table_width -= (2 * $cellspacing['H']);
18187  	 	 	 	 	 	 if (!$this->inthead) {
18188  	 	 	 	 	 	 	 $this->y += $cellspacing['V'];
18189  	 	 	 	 	 	 }
18190  	 	 	 	 	 	 if ($this->rtl) {
18191  	 	 	 	 	 	 	 $cellspacingx = -$cellspacing['H'];
18192  	 	 	 	 	 	 } else {
18193  	 	 	 	 	 	 	 $cellspacingx = $cellspacing['H'];
18194  	 	 	 	 	 	 }
18195  	 	 	 	 	 	 // total table width without cellspaces
18196  	 	 	 	 	 	 $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
18197  	 	 	 	 	 	 // minimum column width
18198  	 	 	 	 	 	 $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
18199  	 	 	 	 	 	 // array of custom column widths
18200  	 	 	 	 	 	 $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
18201  	 	 	 	 	 }
18202  	 	 	 	 	 // table row
18203  	 	 	 	 	 if ($dom[$key]['value'] == 'tr') {
18204  	 	 	 	 	 	 // reset column counter
18205  	 	 	 	 	 	 $colid = 0;
18206  	 	 	 	 	 }
18207  	 	 	 	 	 // table cell
18208  	 	 	 	 	 if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
18209  	 	 	 	 	 	 $trid = $dom[$key]['parent'];
18210  	 	 	 	 	 	 $table_el = $dom[$trid]['parent'];
18211  	 	 	 	 	 	 if (!isset($dom[$table_el]['cols'])) {
18212  	 	 	 	 	 	 	 $dom[$table_el]['cols'] = $dom[$trid]['cols'];
18213  	 	 	 	 	 	 }
18214  	 	 	 	 	 	 // store border info
18215  	 	 	 	 	 	 $tdborder = 0;
18216  	 	 	 	 	 	 if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
18217  	 	 	 	 	 	 	 $tdborder = $dom[$key]['border'];
18218  	 	 	 	 	 	 }
18219  	 	 	 	 	 	 $colspan = intval($dom[$key]['attribute']['colspan']);
18220  	 	 	 	 	 	 if ($colspan <= 0) {
18221  	 	 	 	 	 	 	 $colspan = 1;
18222  	 	 	 	 	 	 }
18223  	 	 	 	 	 	 $old_cell_padding = $this->cell_padding;
18224  	 	 	 	 	 	 if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
18225  	 	 	 	 	 	 	 $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
18226  	 	 	 	 	 	 	 $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
18227  	 	 	 	 	 	 } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
18228  	 	 	 	 	 	 	 $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
18229  	 	 	 	 	 	 } else {
18230  	 	 	 	 	 	 	 $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
18231  	 	 	 	 	 	 }
18232  	 	 	 	 	 	 $this->cell_padding = $current_cell_padding;
18233  	 	 	 	 	 	 if (isset($dom[$key]['height'])) {
18234  	 	 	 	 	 	 	 // minimum cell height
18235  	 	 	 	 	 	 	 $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
18236  	 	 	 	 	 	 } else {
18237  	 	 	 	 	 	 	 $cellh = 0;
18238  	 	 	 	 	 	 }
18239  	 	 	 	 	 	 if (isset($dom[$key]['content'])) {
18240  	 	 	 	 	 	 	 $cell_content = $dom[$key]['content'];
18241  	 	 	 	 	 	 } else {
18242  	 	 	 	 	 	 	 $cell_content = '&nbsp;';
18243  	 	 	 	 	 	 }
18244  	 	 	 	 	 	 $tagtype = $dom[$key]['value'];
18245  	 	 	 	 	 	 $parentid = $key;
18246  	 	 	 	 	 	 while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
18247  	 	 	 	 	 	 	 // move $key index forward
18248  	 	 	 	 	 	 	 ++$key;
18249  	 	 	 	 	 	 }
18250  	 	 	 	 	 	 if (!isset($dom[$trid]['startpage'])) {
18251  	 	 	 	 	 	 	 $dom[$trid]['startpage'] = $this->page;
18252  	 	 	 	 	 	 } else {
18253  	 	 	 	 	 	 	 $this->setPage($dom[$trid]['startpage']);
18254  	 	 	 	 	 	 }
18255  	 	 	 	 	 	 if (!isset($dom[$trid]['startcolumn'])) {
18256  	 	 	 	 	 	 	 $dom[$trid]['startcolumn'] = $this->current_column;
18257  	 	 	 	 	 	 } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
18258  	 	 	 	 	 	 	 $tmpx = $this->x;
18259  	 	 	 	 	 	 	 $this->selectColumn($dom[$trid]['startcolumn']);
18260  	 	 	 	 	 	 	 $this->x = $tmpx;
18261  	 	 	 	 	 	 }
18262  	 	 	 	 	 	 if (!isset($dom[$trid]['starty'])) {
18263  	 	 	 	 	 	 	 $dom[$trid]['starty'] = $this->y;
18264  	 	 	 	 	 	 } else {
18265  	 	 	 	 	 	 	 $this->y = $dom[$trid]['starty'];
18266  	 	 	 	 	 	 }
18267  	 	 	 	 	 	 if (!isset($dom[$trid]['startx'])) {
18268  	 	 	 	 	 	 	 $dom[$trid]['startx'] = $this->x;
18269  	 	 	 	 	 	 	 $this->x += $cellspacingx;
18270  	 	 	 	 	 	 } else {
18271  	 	 	 	 	 	 	 $this->x += ($cellspacingx / 2);
18272  	 	 	 	 	 	 }
18273  	 	 	 	 	 	 if (isset($dom[$parentid]['attribute']['rowspan'])) {
18274  	 	 	 	 	 	 	 $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
18275  	 	 	 	 	 	 } else {
18276  	 	 	 	 	 	 	 $rowspan = 1;
18277  	 	 	 	 	 	 }
18278  	 	 	 	 	 	 // skip row-spanned cells started on the previous rows
18279  	 	 	 	 	 	 if (isset($dom[$table_el]['rowspans'])) {
18280  	 	 	 	 	 	 	 $rsk = 0;
18281  	 	 	 	 	 	 	 $rskmax = count($dom[$table_el]['rowspans']);
18282  	 	 	 	 	 	 	 while ($rsk < $rskmax) {
18283  	 	 	 	 	 	 	 	 $trwsp = $dom[$table_el]['rowspans'][$rsk];
18284  	 	 	 	 	 	 	 	 $rsstartx = $trwsp['startx'];
18285  	 	 	 	 	 	 	 	 $rsendx = $trwsp['endx'];
18286  	 	 	 	 	 	 	 	 // account for margin changes
18287  	 	 	 	 	 	 	 	 if ($trwsp['startpage'] < $this->page) {
18288  	 	 	 	 	 	 	 	 	 if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
18289  	 	 	 	 	 	 	 	 	 	 $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
18290  	 	 	 	 	 	 	 	 	 	 $rsstartx -= $dl;
18291  	 	 	 	 	 	 	 	 	 	 $rsendx -= $dl;
18292  	 	 	 	 	 	 	 	 	 } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
18293  	 	 	 	 	 	 	 	 	 	 $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
18294  	 	 	 	 	 	 	 	 	 	 $rsstartx += $dl;
18295  	 	 	 	 	 	 	 	 	 	 $rsendx += $dl;
18296  	 	 	 	 	 	 	 	 	 }
18297  	 	 	 	 	 	 	 	 }
18298  	 	 	 	 	 	 	 	 if (($trwsp['rowspan'] > 0)
18299  	 	 	 	 	 	 	 	 	 AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
18300  	 	 	 	 	 	 	 	 	 AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
18301  	 	 	 	 	 	 	 	 	 AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
18302  	 	 	 	 	 	 	 	 	 // set the starting X position of the current cell
18303  	 	 	 	 	 	 	 	 	 $this->x = $rsendx + $cellspacingx;
18304  	 	 	 	 	 	 	 	 	 // increment column indicator
18305  	 	 	 	 	 	 	 	 	 $colid += $trwsp['colspan'];
18306  	 	 	 	 	 	 	 	 	 if (($trwsp['rowspan'] == 1)
18307  	 	 	 	 	 	 	 	 	 	 AND (isset($dom[$trid]['endy']))
18308  	 	 	 	 	 	 	 	 	 	 AND (isset($dom[$trid]['endpage']))
18309  	 	 	 	 	 	 	 	 	 	 AND (isset($dom[$trid]['endcolumn']))
18310  	 	 	 	 	 	 	 	 	 	 AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
18311  	 	 	 	 	 	 	 	 	 	 AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
18312  	 	 	 	 	 	 	 	 	 	 // set ending Y position for row
18313  	 	 	 	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
18314  	 	 	 	 	 	 	 	 	 	 $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
18315  	 	 	 	 	 	 	 	 	 }
18316  	 	 	 	 	 	 	 	 	 $rsk = 0;
18317  	 	 	 	 	 	 	 	 } else {
18318  	 	 	 	 	 	 	 	 	 ++$rsk;
18319  	 	 	 	 	 	 	 	 }
18320  	 	 	 	 	 	 	 }
18321  	 	 	 	 	 	 }
18322  	 	 	 	 	 	 if (isset($dom[$parentid]['width'])) {
18323  	 	 	 	 	 	 	 // user specified width
18324  	 	 	 	 	 	 	 $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
18325  	 	 	 	 	 	 	 $tmpcw = ($cellw / $colspan);
18326  	 	 	 	 	 	 	 for ($i = 0; $i < $colspan; ++$i) {
18327  	 	 	 	 	 	 	 	 $table_colwidths[($colid + $i)] = $tmpcw;
18328  	 	 	 	 	 	 	 }
18329  	 	 	 	 	 	 } else {
18330  	 	 	 	 	 	 	 // inherit column width
18331  	 	 	 	 	 	 	 $cellw = 0;
18332  	 	 	 	 	 	 	 for ($i = 0; $i < $colspan; ++$i) {
18333  	 	 	 	 	 	 	 	 $cellw += (isset($table_colwidths[($colid + $i)]) ? $table_colwidths[($colid + $i)] : 0);
18334  	 	 	 	 	 	 	 }
18335  	 	 	 	 	 	 }
18336  	 	 	 	 	 	 $cellw += (($colspan - 1) * $cellspacing['H']);
18337  	 	 	 	 	 	 // increment column indicator
18338  	 	 	 	 	 	 $colid += $colspan;
18339  	 	 	 	 	 	 // add rowspan information to table element
18340  	 	 	 	 	 	 if ($rowspan > 1) {
18341  	 	 	 	 	 	 	 $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));
18342  	 	 	 	 	 	 }
18343  	 	 	 	 	 	 $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
18344  	 	 	 	 	 	 if ($rowspan > 1) {
18345  	 	 	 	 	 	 	 $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
18346  	 	 	 	 	 	 }
18347  	 	 	 	 	 	 // push background colors
18348  	 	 	 	 	 	 if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
18349  	 	 	 	 	 	 	 $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
18350  	 	 	 	 	 	 }
18351  	 	 	 	 	 	 // store border info
18352  	 	 	 	 	 	 if (isset($tdborder) AND !empty($tdborder)) {
18353  	 	 	 	 	 	 	 $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
18354  	 	 	 	 	 	 }
18355  	 	 	 	 	 	 $prevLastH = $this->lasth;
18356  	 	 	 	 	 	 // store some info for multicolumn mode
18357  	 	 	 	 	 	 if ($this->rtl) {
18358  	 	 	 	 	 	 	 $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
18359  	 	 	 	 	 	 } else {
18360  	 	 	 	 	 	 	 $this->colxshift['x'] = $this->x - $this->lMargin;
18361  	 	 	 	 	 	 }
18362  	 	 	 	 	 	 $this->colxshift['s'] = $cellspacing;
18363  	 	 	 	 	 	 $this->colxshift['p'] = $current_cell_padding;
18364  	 	 	 	 	 	 // ****** write the cell content ******
18365  	 	 	 	 	 	 $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
18366  	 	 	 	 	 	 // restore some values
18367  	 	 	 	 	 	 $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
18368  	 	 	 	 	 	 $this->lasth = $prevLastH;
18369  	 	 	 	 	 	 $this->cell_padding = $old_cell_padding;
18370  	 	 	 	 	 	 $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
18371  	 	 	 	 	 	 // update the end of row position
18372  	 	 	 	 	 	 if ($rowspan <= 1) {
18373  	 	 	 	 	 	 	 if (isset($dom[$trid]['endy'])) {
18374  	 	 	 	 	 	 	 	 if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
18375  	 	 	 	 	 	 	 	 	 $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
18376  	 	 	 	 	 	 	 	 } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
18377  	 	 	 	 	 	 	 	 	 $dom[$trid]['endy'] = $this->y;
18378  	 	 	 	 	 	 	 	 }
18379  	 	 	 	 	 	 	 } else {
18380  	 	 	 	 	 	 	 	 $dom[$trid]['endy'] = $this->y;
18381  	 	 	 	 	 	 	 }
18382  	 	 	 	 	 	 	 if (isset($dom[$trid]['endpage'])) {
18383  	 	 	 	 	 	 	 	 $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
18384  	 	 	 	 	 	 	 } else {
18385  	 	 	 	 	 	 	 	 $dom[$trid]['endpage'] = $this->page;
18386  	 	 	 	 	 	 	 }
18387  	 	 	 	 	 	 	 if (isset($dom[$trid]['endcolumn'])) {
18388  	 	 	 	 	 	 	 	 $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
18389  	 	 	 	 	 	 	 } else {
18390  	 	 	 	 	 	 	 	 $dom[$trid]['endcolumn'] = $this->current_column;
18391  	 	 	 	 	 	 	 }
18392  	 	 	 	 	 	 } else {
18393  	 	 	 	 	 	 	 // account for row-spanned cells
18394  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
18395  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
18396  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
18397  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
18398  	 	 	 	 	 	 }
18399  	 	 	 	 	 	 if (isset($dom[$table_el]['rowspans'])) {
18400  	 	 	 	 	 	 	 // update endy and endpage on rowspanned cells
18401  	 	 	 	 	 	 	 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
18402  	 	 	 	 	 	 	 	 if ($trwsp['rowspan'] > 0) {
18403  	 	 	 	 	 	 	 	 	 if (isset($dom[$trid]['endpage'])) {
18404  	 	 	 	 	 	 	 	 	 	 if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
18405  	 	 	 	 	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
18406  	 	 	 	 	 	 	 	 	 	 } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
18407  	 	 	 	 	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
18408  	 	 	 	 	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
18409  	 	 	 	 	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
18410  	 	 	 	 	 	 	 	 	 	 } else {
18411  	 	 	 	 	 	 	 	 	 	 	 $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
18412  	 	 	 	 	 	 	 	 	 	 }
18413  	 	 	 	 	 	 	 	 	 }
18414  	 	 	 	 	 	 	 	 }
18415  	 	 	 	 	 	 	 }
18416  	 	 	 	 	 	 }
18417  	 	 	 	 	 	 $this->x += ($cellspacingx / 2);
18418  	 	 	 	 	 } else {
18419  	 	 	 	 	 	 // opening tag (or self-closing tag)
18420  	 	 	 	 	 	 if (!isset($opentagpos)) {
18421  	 	 	 	 	 	 	 if ($this->inxobj) {
18422  	 	 	 	 	 	 	 	 // we are inside an XObject template
18423  	 	 	 	 	 	 	 	 $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
18424  	 	 	 	 	 	 	 } elseif (!$this->InFooter) {
18425  	 	 	 	 	 	 	 	 if (isset($this->footerlen[$this->page])) {
18426  	 	 	 	 	 	 	 	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
18427  	 	 	 	 	 	 	 	 } else {
18428  	 	 	 	 	 	 	 	 	 $this->footerpos[$this->page] = $this->pagelen[$this->page];
18429  	 	 	 	 	 	 	 	 }
18430  	 	 	 	 	 	 	 	 $opentagpos = $this->footerpos[$this->page];
18431  	 	 	 	 	 	 	 }
18432  	 	 	 	 	 	 }
18433  	 	 	 	 	 	 $dom = $this->openHTMLTagHandler($dom, $key, $cell);
18434  	 	 	 	 	 }
18435  	 	 	 	 } else { // closing tag
18436  	 	 	 	 	 $prev_numpages = $this->numpages;
18437  	 	 	 	 	 $old_bordermrk = $this->bordermrk[$this->page];
18438  	 	 	 	 	 $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
18439  	 	 	 	 	 if ($this->bordermrk[$this->page] > $old_bordermrk) {
18440  	 	 	 	 	 	 $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
18441  	 	 	 	 	 }
18442  	 	 	 	 	 if ($prev_numpages > $this->numpages) {
18443  	 	 	 	 	 	 $startlinepage = $this->page;
18444  	 	 	 	 	 }
18445  	 	 	 	 }
18446  	 	 	 } elseif (strlen($dom[$key]['value']) > 0) {
18447  	 	 	 	 // print list-item
18448  	 	 	 	 if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
18449  	 	 	 	 	 $this->setFont($pfontname, $pfontstyle, $pfontsize);
18450  	 	 	 	 	 $this->resetLastH();
18451  	 	 	 	 	 $minstartliney = $this->y;
18452  	 	 	 	 	 $maxbottomliney = ($startliney + $this->getCellHeight($this->FontSize));
18453  	 	 	 	 	 if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
18454  	 	 	 	 	 	 $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
18455  	 	 	 	 	 }
18456  	 	 	 	 	 $this->setFont($curfontname, $curfontstyle, $curfontsize);
18457  	 	 	 	 	 $this->resetLastH();
18458  	 	 	 	 	 if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
18459  	 	 	 	 	 	 $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
18460  	 	 	 	 	 	 $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
18461  	 	 	 	 	 	 $this->y += ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
18462  	 	 	 	 	 	 $minstartliney = min($this->y, $minstartliney);
18463  	 	 	 	 	 	 $maxbottomliney = max(($this->y + $this->getCellHeight($pfontsize / $this->k)), $maxbottomliney);
18464  	 	 	 	 	 }
18465  	 	 	 	 }
18466  	 	 	 	 // text
18467  	 	 	 	 $this->htmlvspace = 0;
18468  	 	 	 	 $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']);
18469  	 	 	 	 if ((!$this->premode) AND $this->isRTLTextDir() AND !$isRTLString) {
18470  	 	 	 	 	 // reverse spaces order
18471  	 	 	 	 	 $lsp = ''; // left spaces
18472  	 	 	 	 	 $rsp = ''; // right spaces
18473  	 	 	 	 	 if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
18474  	 	 	 	 	 	 $lsp = $matches[1];
18475  	 	 	 	 	 }
18476  	 	 	 	 	 if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
18477  	 	 	 	 	 	 $rsp = $matches[1];
18478  	 	 	 	 	 }
18479  	 	 	 	 	 $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
18480  	 	 	 	 }
18481  	 	 	 	 if ($newline) {
18482  	 	 	 	 	 if (!$this->premode) {
18483  	 	 	 	 	 	 $prelen = strlen($dom[$key]['value']);
18484  	 	 	 	 	 	 if ($this->isRTLTextDir() AND !$isRTLString) {
18485  	 	 	 	 	 	 	 // right trim except non-breaking space
18486  	 	 	 	 	 	 	 $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
18487  	 	 	 	 	 	 } else {
18488  	 	 	 	 	 	 	 // left trim except non-breaking space
18489  	 	 	 	 	 	 	 $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
18490  	 	 	 	 	 	 }
18491  	 	 	 	 	 	 $postlen = strlen($dom[$key]['value']);
18492  	 	 	 	 	 	 if (($postlen == 0) AND ($prelen > 0)) {
18493  	 	 	 	 	 	 	 $dom[$key]['trimmed_space'] = true;
18494  	 	 	 	 	 	 }
18495  	 	 	 	 	 }
18496  	 	 	 	 	 $newline = false;
18497  	 	 	 	 	 $firstblock = true;
18498  	 	 	 	 } else {
18499  	 	 	 	 	 $firstblock = false;
18500  	 	 	 	 	 // replace empty multiple spaces string with a single space
18501  	 	 	 	 	 $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
18502  	 	 	 	 }
18503  	 	 	 	 $strrest = '';
18504  	 	 	 	 if ($this->rtl) {
18505  	 	 	 	 	 $this->x -= $this->textindent;
18506  	 	 	 	 } else {
18507  	 	 	 	 	 $this->x += $this->textindent;
18508  	 	 	 	 }
18509  	 	 	 	 if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
18510  	 	 	 	 	 $strlinelen = $this->GetStringWidth($dom[$key]['value']);
18511  	 	 	 	 	 if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
18512  	 	 	 	 	 	 // HTML <a> Link
18513  	 	 	 	 	 	 $hrefcolor = '';
18514  	 	 	 	 	 	 if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
18515  	 	 	 	 	 	 	 $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
18516  	 	 	 	 	 	 }
18517  	 	 	 	 	 	 $hrefstyle = -1;
18518  	 	 	 	 	 	 if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
18519  	 	 	 	 	 	 	 $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
18520  	 	 	 	 	 	 }
18521  	 	 	 	 	 	 $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
18522  	 	 	 	 	 } else {
18523  	 	 	 	 	 	 $wadj = 0; // space to leave for block continuity
18524  	 	 	 	 	 	 if ($this->rtl) {
18525  	 	 	 	 	 	 	 $cwa = ($this->x - $this->lMargin);
18526  	 	 	 	 	 	 } else {
18527  	 	 	 	 	 	 	 $cwa = ($this->w - $this->rMargin - $this->x);
18528  	 	 	 	 	 	 }
18529  	 	 	 	 	 	 if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
18530  	 	 	 	 	 	 	 // check the next text blocks for continuity
18531  	 	 	 	 	 	 	 $nkey = ($key + 1);
18532  	 	 	 	 	 	 	 $write_block = true;
18533  	 	 	 	 	 	 	 $same_textdir = true;
18534  	 	 	 	 	 	 	 $tmp_fontname = $this->FontFamily;
18535  	 	 	 	 	 	 	 $tmp_fontstyle = $this->FontStyle;
18536  	 	 	 	 	 	 	 $tmp_fontsize = $this->FontSizePt;
18537  	 	 	 	 	 	 	 while ($write_block AND isset($dom[$nkey])) {
18538  	 	 	 	 	 	 	 	 if ($dom[$nkey]['tag']) {
18539  	 	 	 	 	 	 	 	 	 if ($dom[$nkey]['block']) {
18540  	 	 	 	 	 	 	 	 	 	 // end of block
18541  	 	 	 	 	 	 	 	 	 	 $write_block = false;
18542  	 	 	 	 	 	 	 	 	 }
18543  	 	 	 	 	 	 	 	 	 $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
18544  	 	 	 	 	 	 	 	 	 $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
18545  	 	 	 	 	 	 	 	 	 $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
18546  	 	 	 	 	 	 	 	 	 $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
18547  	 	 	 	 	 	 	 	 } else {
18548  	 	 	 	 	 	 	 	 	 $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
18549  	 	 	 	 	 	 	 	 	 if (isset($nextstr[0]) AND $same_textdir) {
18550  	 	 	 	 	 	 	 	 	 	 $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
18551  	 	 	 	 	 	 	 	 	 	 if (isset($nextstr[1])) {
18552  	 	 	 	 	 	 	 	 	 	 	 $write_block = false;
18553  	 	 	 	 	 	 	 	 	 	 }
18554  	 	 	 	 	 	 	 	 	 }
18555  	 	 	 	 	 	 	 	 }
18556  	 	 	 	 	 	 	 	 ++$nkey;
18557  	 	 	 	 	 	 	 }
18558  	 	 	 	 	 	 }
18559  	 	 	 	 	 	 if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
18560  	 	 	 	 	 	 	 $wadj = 0;
18561  	 	 	 	 	 	 	 $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
18562  	 	 	 	 	 	 	 $numblks = count($nextstr);
18563  	 	 	 	 	 	 	 if ($numblks > 1) {
18564  	 	 	 	 	 	 	 	 // try to split on blank spaces
18565  	 	 	 	 	 	 	 	 $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
18566  	 	 	 	 	 	 	 } else {
18567  	 	 	 	 	 	 	 	 // set the entire block on new line
18568  	 	 	 	 	 	 	 	 $wadj = $this->GetStringWidth($nextstr[0]);
18569  	 	 	 	 	 	 	 }
18570  	 	 	 	 	 	 }
18571  	 	 	 	 	 	 // check for reversed text direction
18572  	 	 	 	 	 	 if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
18573  	 	 	 	 	 	 	 // LTR text on RTL direction or RTL text on LTR direction
18574  	 	 	 	 	 	 	 $reverse_dir = true;
18575  	 	 	 	 	 	 	 $this->rtl = !$this->rtl;
18576  	 	 	 	 	 	 	 $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
18577  	 	 	 	 	 	 	 if ($this->rtl) {
18578  	 	 	 	 	 	 	 	 $this->x += $revshift;
18579  	 	 	 	 	 	 	 } else {
18580  	 	 	 	 	 	 	 	 $this->x -= $revshift;
18581  	 	 	 	 	 	 	 }
18582  	 	 	 	 	 	 	 $xws = $this->x;
18583  	 	 	 	 	 	 }
18584  	 	 	 	 	 	 // ****** write only until the end of the line and get the rest ******
18585  	 	 	 	 	 	 $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
18586  	 	 	 	 	 	 // restore default direction
18587  	 	 	 	 	 	 if ($reverse_dir AND ($wadj == 0)) {
18588  	 	 	 	 	 	 	 $this->x = $xws;
18589  	 	 	 	 	 	 	 $this->rtl = !$this->rtl;
18590  	 	 	 	 	 	 	 $reverse_dir = false;
18591  	 	 	 	 	 	 }
18592  	 	 	 	 	 }
18593  	 	 	 	 }
18594  	 	 	 	 $this->textindent = 0;
18595  	 	 	 	 if (strlen($strrest) > 0) {
18596  	 	 	 	 	 // store the remaining string on the previous $key position
18597  	 	 	 	 	 $this->newline = true;
18598  	 	 	 	 	 if ($strrest == $dom[$key]['value']) {
18599  	 	 	 	 	 	 // used to avoid infinite loop
18600  	 	 	 	 	 	 ++$loop;
18601  	 	 	 	 	 } else {
18602  	 	 	 	 	 	 $loop = 0;
18603  	 	 	 	 	 }
18604  	 	 	 	 	 $dom[$key]['value'] = $strrest;
18605  	 	 	 	 	 if ($cell) {
18606  	 	 	 	 	 	 if ($this->rtl) {
18607  	 	 	 	 	 	 	 $this->x -= $this->cell_padding['R'];
18608  	 	 	 	 	 	 } else {
18609  	 	 	 	 	 	 	 $this->x += $this->cell_padding['L'];
18610  	 	 	 	 	 	 }
18611  	 	 	 	 	 }
18612  	 	 	 	 	 if ($loop < 3) {
18613  	 	 	 	 	 	 --$key;
18614  	 	 	 	 	 }
18615  	 	 	 	 } else {
18616  	 	 	 	 	 $loop = 0;
18617  	 	 	 	 	 // add the positive font spacing of the last character (if any)
18618  	 	 	 	 	  if ($this->font_spacing > 0) {
18619  	 	 	 	 	  	 if ($this->rtl) {
18620  	 	 	 	 	 	 	 $this->x -= $this->font_spacing;
18621  	 	 	 	 	 	 } else {
18622  	 	 	 	 	 	 	 $this->x += $this->font_spacing;
18623  	 	 	 	 	 	 }
18624  	 	 	 	 	 }
18625  	 	 	 	 }
18626  	 	 	 }
18627  	 	 	 ++$key;
18628  	 	 	 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')) {
18629  	 	 	 	 // check if we are on a new page or on a new column
18630  	 	 	 	 if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
18631  	 	 	 	 	 // we are on a new page or on a new column and the total object height is less than the available vertical space.
18632  	 	 	 	 	 // restore previous object
18633  	 	 	 	 	 $this->rollbackTransaction(true);
18634  	 	 	 	 	 // restore previous values
18635  	 	 	 	 	 foreach ($this_method_vars as $vkey => $vval) {
18636  	 	 	 	 	 	 $$vkey = $vval;
18637  	 	 	 	 	 }
18638  	 	 	 	 	 if (!empty($dom[$key]['thead'])) {
18639  	 	 	 	 	 	 $this->inthead = true;
18640  	 	 	 	 	 }
18641  	 	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
18642  	 	 	 	 	 $pre_y = $this->y;
18643  	 	 	 	 	 if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
18644  	 	 	 	 	 	 $startliney = $this->y;
18645  	 	 	 	 	 }
18646  	 	 	 	 	 $undo = true; // avoid infinite loop
18647  	 	 	 	 } else {
18648  	 	 	 	 	 $undo = false;
18649  	 	 	 	 }
18650  	 	 	 }
18651  	 	 } // end for each $key
18652  	 	 // align the last line
18653  	 	 if (isset($startlinex)) {
18654  	 	 	 $yshift = ($minstartliney - $startliney);
18655  	 	 	 if (($yshift > 0) OR ($this->page > $startlinepage)) {
18656  	 	 	 	 $yshift = 0;
18657  	 	 	 }
18658  	 	 	 $t_x = 0;
18659  	 	 	 // the last line must be shifted to be aligned as requested
18660  	 	 	 $linew = abs($this->endlinex - $startlinex);
18661  	 	 	 if ($this->inxobj) {
18662  	 	 	 	 // we are inside an XObject template
18663  	 	 	 	 $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
18664  	 	 	 	 if (isset($opentagpos)) {
18665  	 	 	 	 	 $midpos = $opentagpos;
18666  	 	 	 	 } else {
18667  	 	 	 	 	 $midpos = 0;
18668  	 	 	 	 }
18669  	 	 	 	 if ($midpos > 0) {
18670  	 	 	 	 	 $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
18671  	 	 	 	 	 $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
18672  	 	 	 	 } else {
18673  	 	 	 	 	 $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
18674  	 	 	 	 	 $pend = '';
18675  	 	 	 	 }
18676  	 	 	 } else {
18677  	 	 	 	 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
18678  	 	 	 	 if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
18679  	 	 	 	 	 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
18680  	 	 	 	 	 $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
18681  	 	 	 	 } elseif (isset($opentagpos)) {
18682  	 	 	 	 	 $midpos = $opentagpos;
18683  	 	 	 	 } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
18684  	 	 	 	 	 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
18685  	 	 	 	 	 $midpos = $this->footerpos[$startlinepage];
18686  	 	 	 	 } else {
18687  	 	 	 	 	 $midpos = 0;
18688  	 	 	 	 }
18689  	 	 	 	 if ($midpos > 0) {
18690  	 	 	 	 	 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
18691  	 	 	 	 	 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
18692  	 	 	 	 } else {
18693  	 	 	 	 	 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
18694  	 	 	 	 	 $pend = '';
18695  	 	 	 	 }
18696  	 	 	 }
18697  	 	 	 if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
18698  	 	 	 	 // calculate shifting amount
18699  	 	 	 	 $tw = $w;
18700  	 	 	 	 if ($this->lMargin != $prevlMargin) {
18701  	 	 	 	 	 $tw += ($prevlMargin - $this->lMargin);
18702  	 	 	 	 }
18703  	 	 	 	 if ($this->rMargin != $prevrMargin) {
18704  	 	 	 	 	 $tw += ($prevrMargin - $this->rMargin);
18705  	 	 	 	 }
18706  	 	 	 	 $one_space_width = $this->GetStringWidth(chr(32));
18707  	 	 	 	 $no = 0; // number of spaces on a line contained on a single block
18708  	 	 	 	 if ($this->isRTLTextDir()) { // RTL
18709  	 	 	 	 	 // remove left space if exist
18710  	 	 	 	 	 $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
18711  	 	 	 	 	 if ($pos1 > 0) {
18712  	 	 	 	 	 	 $pos1 = intval($pos1);
18713  	 	 	 	 	 	 if ($this->isUnicodeFont()) {
18714  	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
18715  	 	 	 	 	 	 	 $spacelen = 2;
18716  	 	 	 	 	 	 } else {
18717  	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
18718  	 	 	 	 	 	 	 $spacelen = 1;
18719  	 	 	 	 	 	 }
18720  	 	 	 	 	 	 if ($pos1 == $pos2) {
18721  	 	 	 	 	 	 	 $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
18722  	 	 	 	 	 	 	 if (substr($pmid, $pos1, 4) == '[()]') {
18723  	 	 	 	 	 	 	 	 $linew -= $one_space_width;
18724  	 	 	 	 	 	 	 } elseif ($pos1 == strpos($pmid, '[(')) {
18725  	 	 	 	 	 	 	 	 $no = 1;
18726  	 	 	 	 	 	 	 }
18727  	 	 	 	 	 	 }
18728  	 	 	 	 	 }
18729  	 	 	 	 } else { // LTR
18730  	 	 	 	 	 // remove right space if exist
18731  	 	 	 	 	 $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
18732  	 	 	 	 	 if ($pos1 > 0) {
18733  	 	 	 	 	 	 $pos1 = intval($pos1);
18734  	 	 	 	 	 	 if ($this->isUnicodeFont()) {
18735  	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
18736  	 	 	 	 	 	 	 $spacelen = 2;
18737  	 	 	 	 	 	 } else {
18738  	 	 	 	 	 	 	 $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
18739  	 	 	 	 	 	 	 $spacelen = 1;
18740  	 	 	 	 	 	 }
18741  	 	 	 	 	 	 if ($pos1 == $pos2) {
18742  	 	 	 	 	 	 	 $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
18743  	 	 	 	 	 	 	 $linew -= $one_space_width;
18744  	 	 	 	 	 	 }
18745  	 	 	 	 	 }
18746  	 	 	 	 }
18747  	 	 	 	 $mdiff = ($tw - $linew);
18748  	 	 	 	 if ($plalign == 'C') {
18749  	 	 	 	 	 if ($this->rtl) {
18750  	 	 	 	 	 	 $t_x = -($mdiff / 2);
18751  	 	 	 	 	 } else {
18752  	 	 	 	 	 	 $t_x = ($mdiff / 2);
18753  	 	 	 	 	 }
18754  	 	 	 	 } elseif ($plalign == 'R') {
18755  	 	 	 	 	 // right alignment on LTR document
18756  	 	 	 	 	 $t_x = $mdiff;
18757  	 	 	 	 } elseif ($plalign == 'L') {
18758  	 	 	 	 	 // left alignment on RTL document
18759  	 	 	 	 	 $t_x = -$mdiff;
18760  	 	 	 	 }
18761  	 	 	 } // end if startlinex
18762  	 	 	 if (($t_x != 0) OR ($yshift < 0)) {
18763  	 	 	 	 // shift the line
18764  	 	 	 	 $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
18765  	 	 	 	 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
18766  	 	 	 	 $endlinepos = strlen($pstart);
18767  	 	 	 	 if ($this->inxobj) {
18768  	 	 	 	 	 // we are inside an XObject template
18769  	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
18770  	 	 	 	 	 foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
18771  	 	 	 	 	 	 if ($pak >= $pask) {
18772  	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
18773  	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
18774  	 	 	 	 	 	 }
18775  	 	 	 	 	 }
18776  	 	 	 	 } else {
18777  	 	 	 	 	 $this->setPageBuffer($startlinepage, $pstart.$pend);
18778  	 	 	 	 	 // shift the annotations and links
18779  	 	 	 	 	 if (isset($this->PageAnnots[$this->page])) {
18780  	 	 	 	 	 	 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
18781  	 	 	 	 	 	 	 if ($pak >= $pask) {
18782  	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
18783  	 	 	 	 	 	 	 	 $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
18784  	 	 	 	 	 	 	 }
18785  	 	 	 	 	 	 }
18786  	 	 	 	 	 }
18787  	 	 	 	 }
18788  	 	 	 	 $this->y -= $yshift;
18789  	 	 	 	 $yshift = 0;
18790  	 	 	 }
18791  	 	 }
18792  	 	 // restore previous values
18793  	 	 $this->setGraphicVars($gvars);
18794  	 	 if ($this->num_columns > 1) {
18795  	 	 	 $this->selectColumn();
18796  	 	 } elseif ($this->page > $prevPage) {
18797  	 	 	 $this->lMargin = $this->pagedim[$this->page]['olm'];
18798  	 	 	 $this->rMargin = $this->pagedim[$this->page]['orm'];
18799  	 	 }
18800  	 	 // restore previous list state
18801  	 	 $this->cell_height_ratio = $prev_cell_height_ratio;
18802  	 	 $this->listnum = $prev_listnum;
18803  	 	 $this->listordered = $prev_listordered;
18804  	 	 $this->listcount = $prev_listcount;
18805  	 	 $this->lispacer = $prev_lispacer;
18806  	 	 if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
18807  	 	 	 $this->Ln($this->lasth);
18808  	 	 	 if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
18809  	 	 	 	 $this->y = $maxbottomliney;
18810  	 	 	 }
18811  	 	 }
18812  	 	 unset($dom);
18813  	 }
18814  
18815  	 /**
18816  	  * Process opening tags.
18817  	  * @param array $dom html dom array
18818  	  * @param int $key current element id
18819  	  * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
18820  	  * @return array $dom
18821  	  * @protected
18822  	  */
18823  	protected function openHTMLTagHandler($dom, $key, $cell) {
18824  	 	 $tag = $dom[$key];
18825  	 	 $parent = $dom[($dom[$key]['parent'])];
18826  	 	 $firsttag = ($key == 1);
18827  	 	 // check for text direction attribute
18828  	 	 if (isset($tag['dir'])) {
18829  	 	 	 $this->setTempRTL($tag['dir']);
18830  	 	 } else {
18831  	 	 	 $this->tmprtl = false;
18832  	 	 }
18833  	 	 if ($tag['block']) {
18834  	 	 	 $hbz = 0; // distance from y to line bottom
18835  	 	 	 $hb = 0; // vertical space between block tags
18836  	 	 	 // calculate vertical space for block tags
18837  	 	 	 if (isset($this->tagvspaces[$tag['value']][0]['h']) && !empty($this->tagvspaces[$tag['value']][0]['h']) && ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
18838  	 	 	 	 $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
18839  	 	 	 } elseif (isset($tag['fontsize'])) {
18840  	 	 	 	 $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k);
18841  	 	 	 } else {
18842  	 	 	 	 $cur_h = $this->getCellHeight($this->FontSize);
18843  	 	 	 }
18844  	 	 	 if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
18845  	 	 	 	 $on = $this->tagvspaces[$tag['value']][0]['n'];
18846  	 	 	 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
18847  	 	 	 	 $on = 0.6;
18848  	 	 	 } else {
18849  	 	 	 	 $on = 1;
18850  	 	 	 }
18851  	 	 	 if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) {
18852  	 	 	 	 $hb = 0;
18853  	 	 	 } else {
18854  	 	 	 	 $hb = ($on * $cur_h);
18855  	 	 	 }
18856  	 	 	 if (($this->htmlvspace <= 0) AND ($on > 0)) {
18857  	 	 	 	 if (isset($parent['fontsize'])) {
18858  	 	 	 	 	 $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
18859  	 	 	 	 } else {
18860  	 	 	 	 	 $hbz = $this->getCellHeight($this->FontSize);
18861  	 	 	 	 }
18862  	 	 	 }
18863  	 	 	 if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
18864  	 	 	 	 // fix vertical space after table
18865  	 	 	 	 $hbz = 0;
18866  	 	 	 }
18867  	 	 	 // closing vertical space
18868  	 	 	 $hbc = 0;
18869  	 	 	 if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
18870  	 	 	 	 $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
18871  	 	 	 } elseif (isset($parent['fontsize'])) {
18872  	 	 	 	 $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
18873  	 	 	 } else {
18874  	 	 	 	 $pre_h = $this->getCellHeight($this->FontSize);
18875  	 	 	 }
18876  	 	 	 if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
18877  	 	 	 	 $cn = $this->tagvspaces[$tag['value']][1]['n'];
18878  	 	 	 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
18879  	 	 	 	 $cn = 0.6;
18880  	 	 	 } else {
18881  	 	 	 	 $cn = 1;
18882  	 	 	 }
18883  	 	 	 if (isset($this->tagvspaces[$tag['value']][1])) {
18884  	 	 	 	 $hbc = ($cn * $pre_h);
18885  	 	 	 }
18886  	 	 }
18887  	 	 // Opening tag
18888  	 	 switch($tag['value']) {
18889  	 	 	 case 'table': {
18890  	 	 	 	 $cp = 0;
18891  	 	 	 	 $cs = 0;
18892  	 	 	 	 $dom[$key]['rowspans'] = array();
18893  	 	 	 	 if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
18894  	 	 	 	 	 $this->htmlvspace = 0;
18895  	 	 	 	 	 // set table header
18896  	 	 	 	 	 if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
18897  	 	 	 	 	 	 // set table header
18898  	 	 	 	 	 	 $this->thead = $dom[$key]['thead'];
18899  	 	 	 	 	 	 if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
18900  	 	 	 	 	 	 	 $this->theadMargins = array();
18901  	 	 	 	 	 	 	 $this->theadMargins['cell_padding'] = $this->cell_padding;
18902  	 	 	 	 	 	 	 $this->theadMargins['lmargin'] = $this->lMargin;
18903  	 	 	 	 	 	 	 $this->theadMargins['rmargin'] = $this->rMargin;
18904  	 	 	 	 	 	 	 $this->theadMargins['page'] = $this->page;
18905  	 	 	 	 	 	 	 $this->theadMargins['cell'] = $cell;
18906  	 	 	 	 	 	 	 $this->theadMargins['gvars'] = $this->getGraphicVars();
18907  	 	 	 	 	 	 }
18908  	 	 	 	 	 }
18909  	 	 	 	 }
18910  	 	 	 	 // store current margins and page
18911  	 	 	 	 $dom[$key]['old_cell_padding'] = $this->cell_padding;
18912  	 	 	 	 if (isset($tag['attribute']['cellpadding'])) {
18913  	 	 	 	 	 $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
18914  	 	 	 	 	 $this->setCellPadding($pad);
18915  	 	 	 	 } elseif (isset($tag['padding'])) {
18916  	 	 	 	 	 $this->cell_padding = $tag['padding'];
18917  	 	 	 	 }
18918  	 	 	 	 if (isset($tag['attribute']['cellspacing'])) {
18919  	 	 	 	 	 $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
18920  	 	 	 	 } elseif (isset($tag['border-spacing'])) {
18921  	 	 	 	 	 $cs = $tag['border-spacing']['V'];
18922  	 	 	 	 }
18923  	 	 	 	 $prev_y = $this->y;
18924  	 	 	 	 if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
18925  	 	 	 	 	 $this->inthead = true;
18926  	 	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
18927  	 	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
18928  	 	 	 	 }
18929  	 	 	 	 break;
18930  	 	 	 }
18931  	 	 	 case 'tr': {
18932  	 	 	 	 // array of columns positions
18933  	 	 	 	 $dom[$key]['cellpos'] = array();
18934  	 	 	 	 break;
18935  	 	 	 }
18936  	 	 	 case 'hr': {
18937  	 	 	 	 if ((isset($tag['height'])) AND ($tag['height'] != '')) {
18938  	 	 	 	 	 $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
18939  	 	 	 	 } else {
18940  	 	 	 	 	 $hrHeight = $this->GetLineWidth();
18941  	 	 	 	 }
18942  	 	 	 	 $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag);
18943  	 	 	 	 $x = $this->GetX();
18944  	 	 	 	 $y = $this->GetY();
18945  	 	 	 	 $wtmp = $this->w - $this->lMargin - $this->rMargin;
18946  	 	 	 	 if ($cell) {
18947  	 	 	 	 	 $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
18948  	 	 	 	 }
18949  	 	 	 	 if ((isset($tag['width'])) AND ($tag['width'] != '')) {
18950  	 	 	 	 	 $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
18951  	 	 	 	 } else {
18952  	 	 	 	 	 $hrWidth = $wtmp;
18953  	 	 	 	 }
18954  	 	 	 	 $prevlinewidth = $this->GetLineWidth();
18955  	 	 	 	 $this->setLineWidth($hrHeight);
18956  
18957  	 	 	 	 $lineStyle = array();
18958                      	 	 if (isset($tag['fgcolor'])) {
18959  	 	                         $lineStyle['color'] = $tag['fgcolor'];
18960                      	 	 }
18961  
18962                      	 	 if (isset($tag['fgcolor'])) {
18963                          	 	 $lineStyle['color'] = $tag['fgcolor'];
18964                      	 	 }
18965  
18966                      	 	 if (isset($tag['style']['cap'])) {
18967                          	 	 $lineStyle['cap'] = $tag['style']['cap'];
18968                      	 	 }
18969  
18970                      	 	 if (isset($tag['style']['join'])) {
18971                          	 	 $lineStyle['join'] = $tag['style']['join'];
18972                      	 	 }
18973  
18974                      	 	 if (isset($tag['style']['dash'])) {
18975                          	 	 $lineStyle['dash'] = $tag['style']['dash'];
18976                      	 	 }
18977  
18978                      	 	 if (isset($tag['style']['phase'])) {
18979                          	 	 $lineStyle['phase'] = $tag['style']['phase'];
18980                      	 	 }
18981  
18982  	 	 	 	 $lineStyle = array_filter($lineStyle);
18983  
18984  	 	 	 	 $this->Line($x, $y, $x + $hrWidth, $y, $lineStyle);
18985  	 	 	 	 $this->setLineWidth($prevlinewidth);
18986  	 	 	 	 $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key + 1)]));
18987  	 	 	 	 break;
18988  	 	 	 }
18989  	 	 	 case 'a': {
18990  	 	 	 	 if (array_key_exists('href', $tag['attribute'])) {
18991  	 	 	 	 	 $this->HREF['url'] = $tag['attribute']['href'];
18992  	 	 	 	 }
18993  	 	 	 	 break;
18994  	 	 	 }
18995  	 	 	 case 'img': {
18996  	 	 	 	 if (empty($tag['attribute']['src'])) {
18997  	 	 	 	 	 break;
18998  	 	 	 	 }
18999  	 	 	 	 $imgsrc = $tag['attribute']['src'];
19000  	 	 	 	 if ($imgsrc[0] === '@') {
19001  	 	 	 	 	 // data stream
19002  	 	 	 	 	 $imgsrc = '@'.base64_decode(substr($imgsrc, 1));
19003  	 	 	 	 	 $type = '';
19004  	 	 	 	 } elseif ( $this->allowLocalFiles && substr($imgsrc, 0, 7) === 'file://') {
19005                      // get image type from a local file path
19006                      $imgsrc = substr($imgsrc, 7);
19007                      $type = TCPDF_IMAGES::getImageFileType($imgsrc);
19008                  } else {
19009  	 	 	 	 	 if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
19010  	 	 	 	 	 	 // fix image path
19011  	 	 	 	 	 	 $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
19012  	 	 	 	 	 	 if (($findroot === false) OR ($findroot > 1)) {
19013  	 	 	 	 	 	 	 if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
19014  	 	 	 	 	 	 	 	 $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
19015  	 	 	 	 	 	 	 } else {
19016  	 	 	 	 	 	 	 	 $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
19017  	 	 	 	 	 	 	 }
19018  	 	 	 	 	 	 }
19019  	 	 	 	 	 	 $imgsrc = urldecode($imgsrc);
19020  	 	 	 	 	 	 $testscrtype = @parse_url($imgsrc);
19021  	 	 	 	 	 	 if (empty($testscrtype['query'])) {
19022  	 	 	 	 	 	 	 // convert URL to server path
19023  	 	 	 	 	 	 	 $imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
19024  	 	 	 	 	 	 } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
19025  	 	 	 	 	 	 	 // convert URL to server path
19026  	 	 	 	 	 	 	 $imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
19027  	 	 	 	 	 	 }
19028  	 	 	 	 	 }
19029  	 	 	 	 	 // get image type
19030  	 	 	 	 	 $type = TCPDF_IMAGES::getImageFileType($imgsrc);
19031  	 	 	 	 }
19032  	 	 	 	 if (!isset($tag['width'])) {
19033  	 	 	 	 	 $tag['width'] = 0;
19034  	 	 	 	 }
19035  	 	 	 	 if (!isset($tag['height'])) {
19036  	 	 	 	 	 $tag['height'] = 0;
19037  	 	 	 	 }
19038  	 	 	 	 //if (!isset($tag['attribute']['align'])) {
19039  	 	 	 	 	 // the only alignment supported is "bottom"
19040  	 	 	 	 	 // further development is required for other modes.
19041  	 	 	 	 	 $tag['attribute']['align'] = 'bottom';
19042  	 	 	 	 //}
19043  	 	 	 	 switch($tag['attribute']['align']) {
19044  	 	 	 	 	 case 'top': {
19045  	 	 	 	 	 	 $align = 'T';
19046  	 	 	 	 	 	 break;
19047  	 	 	 	 	 }
19048  	 	 	 	 	 case 'middle': {
19049  	 	 	 	 	 	 $align = 'M';
19050  	 	 	 	 	 	 break;
19051  	 	 	 	 	 }
19052  	 	 	 	 	 case 'bottom': {
19053  	 	 	 	 	 	 $align = 'B';
19054  	 	 	 	 	 	 break;
19055  	 	 	 	 	 }
19056  	 	 	 	 	 default: {
19057  	 	 	 	 	 	 $align = 'B';
19058  	 	 	 	 	 	 break;
19059  	 	 	 	 	 }
19060  	 	 	 	 }
19061  	 	 	 	 $prevy = $this->y;
19062  	 	 	 	 $xpos = $this->x;
19063  	 	 	 	 $imglink = '';
19064  	 	 	 	 if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
19065  	 	 	 	 	 $imglink = $this->HREF['url'];
19066  	 	 	 	 	 if ($imglink[0] == '#') {
19067  	 	 	 	 	 	 // convert url to internal link
19068  	 	 	 	 	 	 $lnkdata = explode(',', $imglink);
19069  	 	 	 	 	 	 if (isset($lnkdata[0])) {
19070  	 	 	 	 	 	 	 $page = intval(substr($lnkdata[0], 1));
19071  	 	 	 	 	 	 	 if (empty($page) OR ($page <= 0)) {
19072  	 	 	 	 	 	 	 	 $page = $this->page;
19073  	 	 	 	 	 	 	 }
19074  	 	 	 	 	 	 	 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
19075  	 	 	 	 	 	 	 	 $lnky = floatval($lnkdata[1]);
19076  	 	 	 	 	 	 	 } else {
19077  	 	 	 	 	 	 	 	 $lnky = 0;
19078  	 	 	 	 	 	 	 }
19079  	 	 	 	 	 	 	 $imglink = $this->AddLink();
19080  	 	 	 	 	 	 	 $this->setLink($imglink, $lnky, $page);
19081  	 	 	 	 	 	 }
19082  	 	 	 	 	 }
19083  	 	 	 	 }
19084  	 	 	 	 $border = 0;
19085  	 	 	 	 if (isset($tag['border']) AND !empty($tag['border'])) {
19086  	 	 	 	 	 // currently only support 1 (frame) or a combination of 'LTRB'
19087  	 	 	 	 	 $border = $tag['border'];
19088  	 	 	 	 }
19089  	 	 	 	 $iw = '';
19090  	 	 	 	 if (isset($tag['width'])) {
19091  	 	 	 	 	 $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k), 'px', false);
19092  	 	 	 	 }
19093  	 	 	 	 $ih = '';
19094  	 	 	 	 if (isset($tag['height'])) {
19095  	 	 	 	 	 $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false);
19096  	 	 	 	 }
19097  	 	 	 	 if (($type == 'eps') OR ($type == 'ai')) {
19098  	 	 	 	 	 $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
19099  	 	 	 	 } elseif ($type == 'svg') {
19100  	 	 	 	 	 $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
19101  	 	 	 	 } else {
19102  	 	 	 	 	 $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
19103  	 	 	 	 }
19104  	 	 	 	 switch($align) {
19105  	 	 	 	 	 case 'T': {
19106  	 	 	 	 	 	 $this->y = $prevy;
19107  	 	 	 	 	 	 break;
19108  	 	 	 	 	 }
19109  	 	 	 	 	 case 'M': {
19110  	 	 	 	 	 	 $this->y = (($this->img_rb_y + $prevy - ($this->getCellHeight($tag['fontsize'] / $this->k))) / 2);
19111  	 	 	 	 	 	 break;
19112  	 	 	 	 	 }
19113  	 	 	 	 	 case 'B': {
19114  	 	 	 	 	 	 $this->y = $this->img_rb_y - ($this->getCellHeight($tag['fontsize'] / $this->k) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio));
19115  	 	 	 	 	 	 break;
19116  	 	 	 	 	 }
19117  	 	 	 	 }
19118  	 	 	 	 break;
19119  	 	 	 }
19120  	 	 	 case 'dl': {
19121  	 	 	 	 ++$this->listnum;
19122  	 	 	 	 if ($this->listnum == 1) {
19123  	 	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19124  	 	 	 	 } else {
19125  	 	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
19126  	 	 	 	 }
19127  	 	 	 	 break;
19128  	 	 	 }
19129  	 	 	 case 'dt': {
19130  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19131  	 	 	 	 break;
19132  	 	 	 }
19133  	 	 	 case 'dd': {
19134  	 	 	 	 if ($this->rtl) {
19135  	 	 	 	 	 $this->rMargin += $this->listindent;
19136  	 	 	 	 } else {
19137  	 	 	 	 	 $this->lMargin += $this->listindent;
19138  	 	 	 	 }
19139  	 	 	 	 ++$this->listindentlevel;
19140  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19141  	 	 	 	 break;
19142  	 	 	 }
19143  	 	 	 case 'ul':
19144  	 	 	 case 'ol': {
19145  	 	 	 	 ++$this->listnum;
19146  	 	 	 	 if ($tag['value'] == 'ol') {
19147  	 	 	 	 	 $this->listordered[$this->listnum] = true;
19148  	 	 	 	 } else {
19149  	 	 	 	 	 $this->listordered[$this->listnum] = false;
19150  	 	 	 	 }
19151  	 	 	 	 if (isset($tag['attribute']['start'])) {
19152  	 	 	 	 	 $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
19153  	 	 	 	 } else {
19154  	 	 	 	 	 $this->listcount[$this->listnum] = 0;
19155  	 	 	 	 }
19156  	 	 	 	 if ($this->rtl) {
19157  	 	 	 	 	 $this->rMargin += $this->listindent;
19158  	 	 	 	 	 $this->x -= $this->listindent;
19159  	 	 	 	 } else {
19160  	 	 	 	 	 $this->lMargin += $this->listindent;
19161  	 	 	 	 	 $this->x += $this->listindent;
19162  	 	 	 	 }
19163  	 	 	 	 ++$this->listindentlevel;
19164  	 	 	 	 if ($this->listnum == 1) {
19165  	 	 	 	 	 if ($key > 1) {
19166  	 	 	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19167  	 	 	 	 	 }
19168  	 	 	 	 } else {
19169  	 	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
19170  	 	 	 	 }
19171  	 	 	 	 break;
19172  	 	 	 }
19173  	 	 	 case 'li': {
19174  	 	 	 	 if ($key > 2) {
19175  	 	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19176  	 	 	 	 }
19177  	 	 	 	 if ($this->listordered[$this->listnum]) {
19178  	 	 	 	 	 // ordered item
19179  	 	 	 	 	 if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
19180  	 	 	 	 	 	 $this->lispacer = $parent['attribute']['type'];
19181  	 	 	 	 	 } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
19182  	 	 	 	 	 	 $this->lispacer = $parent['listtype'];
19183  	 	 	 	 	 } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
19184  	 	 	 	 	 	 $this->lispacer = $this->lisymbol;
19185  	 	 	 	 	 } else {
19186  	 	 	 	 	 	 $this->lispacer = '#';
19187  	 	 	 	 	 }
19188  	 	 	 	 	 ++$this->listcount[$this->listnum];
19189  	 	 	 	 	 if (isset($tag['attribute']['value'])) {
19190  	 	 	 	 	 	 $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
19191  	 	 	 	 	 }
19192  	 	 	 	 } else {
19193  	 	 	 	 	 // unordered item
19194  	 	 	 	 	 if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
19195  	 	 	 	 	 	 $this->lispacer = $parent['attribute']['type'];
19196  	 	 	 	 	 } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
19197  	 	 	 	 	 	 $this->lispacer = $parent['listtype'];
19198  	 	 	 	 	 } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
19199  	 	 	 	 	 	 $this->lispacer = $this->lisymbol;
19200  	 	 	 	 	 } else {
19201  	 	 	 	 	 	 $this->lispacer = '!';
19202  	 	 	 	 	 }
19203  	 	 	 	 }
19204  	 	 	 	 break;
19205  	 	 	 }
19206  	 	 	 case 'blockquote': {
19207  	 	 	 	 if ($this->rtl) {
19208  	 	 	 	 	 $this->rMargin += $this->listindent;
19209  	 	 	 	 } else {
19210  	 	 	 	 	 $this->lMargin += $this->listindent;
19211  	 	 	 	 }
19212  	 	 	 	 ++$this->listindentlevel;
19213  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19214  	 	 	 	 break;
19215  	 	 	 }
19216  	 	 	 case 'br': {
19217  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19218  	 	 	 	 break;
19219  	 	 	 }
19220  	 	 	 case 'div': {
19221  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19222  	 	 	 	 break;
19223  	 	 	 }
19224  	 	 	 case 'p': {
19225  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19226  	 	 	 	 break;
19227  	 	 	 }
19228  	 	 	 case 'pre': {
19229  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19230  	 	 	 	 $this->premode = true;
19231  	 	 	 	 break;
19232  	 	 	 }
19233  	 	 	 case 'sup': {
19234  	 	 	 	 $this->setXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
19235  	 	 	 	 break;
19236  	 	 	 }
19237  	 	 	 case 'sub': {
19238  	 	 	 	 $this->setXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
19239  	 	 	 	 break;
19240  	 	 	 }
19241  	 	 	 case 'h1':
19242  	 	 	 case 'h2':
19243  	 	 	 case 'h3':
19244  	 	 	 case 'h4':
19245  	 	 	 case 'h5':
19246  	 	 	 case 'h6': {
19247  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19248  	 	 	 	 break;
19249  	 	 	 }
19250  	 	 	 // Form fields (since 4.8.000 - 2009-09-07)
19251  	 	 	 case 'form': {
19252  	 	 	 	 if (isset($tag['attribute']['action'])) {
19253  	 	 	 	 	 $this->form_action = $tag['attribute']['action'];
19254  	 	 	 	 } else {
19255  	 	 	 	 	 $this->Error('Please explicitly set action attribute path!');
19256  	 	 	 	 }
19257  	 	 	 	 if (isset($tag['attribute']['enctype'])) {
19258  	 	 	 	 	 $this->form_enctype = $tag['attribute']['enctype'];
19259  	 	 	 	 } else {
19260  	 	 	 	 	 $this->form_enctype = 'application/x-www-form-urlencoded';
19261  	 	 	 	 }
19262  	 	 	 	 if (isset($tag['attribute']['method'])) {
19263  	 	 	 	 	 $this->form_mode = $tag['attribute']['method'];
19264  	 	 	 	 } else {
19265  	 	 	 	 	 $this->form_mode = 'post';
19266  	 	 	 	 }
19267  	 	 	 	 break;
19268  	 	 	 }
19269  	 	 	 case 'input': {
19270  	 	 	 	 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
19271  	 	 	 	 	 $name = $tag['attribute']['name'];
19272  	 	 	 	 } else {
19273  	 	 	 	 	 break;
19274  	 	 	 	 }
19275  	 	 	 	 $prop = array();
19276  	 	 	 	 $opt = array();
19277  	 	 	 	 if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
19278  	 	 	 	 	 $prop['readonly'] = true;
19279  	 	 	 	 }
19280  	 	 	 	 if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
19281  	 	 	 	 	 $value = $tag['attribute']['value'];
19282  	 	 	 	 }
19283  	 	 	 	 if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
19284  	 	 	 	 	 $opt['maxlen'] = intval($tag['attribute']['maxlength']);
19285  	 	 	 	 }
19286  	 	 	 	 $h = $this->getCellHeight($this->FontSize);
19287  	 	 	 	 if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
19288  	 	 	 	 	 $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
19289  	 	 	 	 } else {
19290  	 	 	 	 	 $w = $h;
19291  	 	 	 	 }
19292  	 	 	 	 if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
19293  	 	 	 	 	 $checked = true;
19294  	 	 	 	 } else {
19295  	 	 	 	 	 $checked = false;
19296  	 	 	 	 }
19297  	 	 	 	 if (isset($tag['align'])) {
19298  	 	 	 	 	 switch ($tag['align']) {
19299  	 	 	 	 	 	 case 'C': {
19300  	 	 	 	 	 	 	 $opt['q'] = 1;
19301  	 	 	 	 	 	 	 break;
19302  	 	 	 	 	 	 }
19303  	 	 	 	 	 	 case 'R': {
19304  	 	 	 	 	 	 	 $opt['q'] = 2;
19305  	 	 	 	 	 	 	 break;
19306  	 	 	 	 	 	 }
19307  	 	 	 	 	 	 case 'L':
19308  	 	 	 	 	 	 default: {
19309  	 	 	 	 	 	 	 break;
19310  	 	 	 	 	 	 }
19311  	 	 	 	 	 }
19312  	 	 	 	 }
19313  	 	 	 	 switch ($tag['attribute']['type']) {
19314  	 	 	 	 	 case 'text': {
19315  	 	 	 	 	 	 if (isset($value)) {
19316  	 	 	 	 	 	 	 $opt['v'] = $value;
19317  	 	 	 	 	 	 }
19318  	 	 	 	 	 	 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19319  	 	 	 	 	 	 break;
19320  	 	 	 	 	 }
19321  	 	 	 	 	 case 'password': {
19322  	 	 	 	 	 	 if (isset($value)) {
19323  	 	 	 	 	 	 	 $opt['v'] = $value;
19324  	 	 	 	 	 	 }
19325  	 	 	 	 	 	 $prop['password'] = 'true';
19326  	 	 	 	 	 	 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19327  	 	 	 	 	 	 break;
19328  	 	 	 	 	 }
19329  	 	 	 	 	 case 'checkbox': {
19330  	 	 	 	 	 	 if (!isset($value)) {
19331  	 	 	 	 	 	 	 break;
19332  	 	 	 	 	 	 }
19333  	 	 	 	 	 	 $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
19334  	 	 	 	 	 	 break;
19335  	 	 	 	 	 }
19336  	 	 	 	 	 case 'radio': {
19337  	 	 	 	 	 	 if (!isset($value)) {
19338  	 	 	 	 	 	 	 break;
19339  	 	 	 	 	 	 }
19340  	 	 	 	 	 	 $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
19341  	 	 	 	 	 	 break;
19342  	 	 	 	 	 }
19343  	 	 	 	 	 case 'submit': {
19344  	 	 	 	 	 	 if (!isset($value)) {
19345  	 	 	 	 	 	 	 $value = 'submit';
19346  	 	 	 	 	 	 }
19347  	 	 	 	 	 	 $w = $this->GetStringWidth($value) * 1.5;
19348  	 	 	 	 	 	 $h *= 1.6;
19349  	 	 	 	 	 	 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19350  	 	 	 	 	 	 $action = array();
19351  	 	 	 	 	 	 $action['S'] = 'SubmitForm';
19352  	 	 	 	 	 	 $action['F'] = $this->form_action;
19353  	 	 	 	 	 	 if ($this->form_enctype != 'FDF') {
19354  	 	 	 	 	 	 	 $action['Flags'] = array('ExportFormat');
19355  	 	 	 	 	 	 }
19356  	 	 	 	 	 	 if ($this->form_mode == 'get') {
19357  	 	 	 	 	 	 	 $action['Flags'] = array('GetMethod');
19358  	 	 	 	 	 	 }
19359  	 	 	 	 	 	 $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
19360  	 	 	 	 	 	 break;
19361  	 	 	 	 	 }
19362  	 	 	 	 	 case 'reset': {
19363  	 	 	 	 	 	 if (!isset($value)) {
19364  	 	 	 	 	 	 	 $value = 'reset';
19365  	 	 	 	 	 	 }
19366  	 	 	 	 	 	 $w = $this->GetStringWidth($value) * 1.5;
19367  	 	 	 	 	 	 $h *= 1.6;
19368  	 	 	 	 	 	 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19369  	 	 	 	 	 	 $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
19370  	 	 	 	 	 	 break;
19371  	 	 	 	 	 }
19372  	 	 	 	 	 case 'file': {
19373  	 	 	 	 	 	 $prop['fileSelect'] = 'true';
19374  	 	 	 	 	 	 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19375  	 	 	 	 	 	 if (!isset($value)) {
19376  	 	 	 	 	 	 	 $value = '*';
19377  	 	 	 	 	 	 }
19378  	 	 	 	 	 	 $w = $this->GetStringWidth($value) * 2;
19379  	 	 	 	 	 	 $h *= 1.2;
19380  	 	 	 	 	 	 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19381  	 	 	 	 	 	 $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
19382  	 	 	 	 	 	 $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
19383  	 	 	 	 	 	 break;
19384  	 	 	 	 	 }
19385  	 	 	 	 	 case 'hidden': {
19386  	 	 	 	 	 	 if (isset($value)) {
19387  	 	 	 	 	 	 	 $opt['v'] = $value;
19388  	 	 	 	 	 	 }
19389  	 	 	 	 	 	 $opt['f'] = array('invisible', 'hidden');
19390  	 	 	 	 	 	 $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
19391  	 	 	 	 	 	 break;
19392  	 	 	 	 	 }
19393  	 	 	 	 	 case 'image': {
19394  	 	 	 	 	 	 // THIS TYPE MUST BE FIXED
19395  	 	 	 	 	 	 if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
19396  	 	 	 	 	 	 	 $img = $tag['attribute']['src'];
19397  	 	 	 	 	 	 } else {
19398  	 	 	 	 	 	 	 break;
19399  	 	 	 	 	 	 }
19400  	 	 	 	 	 	 $value = 'img';
19401  	 	 	 	 	 	 //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
19402  	 	 	 	 	 	 if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
19403  	 	 	 	 	 	 	 $jsaction = $tag['attribute']['onclick'];
19404  	 	 	 	 	 	 } else {
19405  	 	 	 	 	 	 	 $jsaction = '';
19406  	 	 	 	 	 	 }
19407  	 	 	 	 	 	 $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
19408  	 	 	 	 	 	 break;
19409  	 	 	 	 	 }
19410  	 	 	 	 	 case 'button': {
19411  	 	 	 	 	 	 if (!isset($value)) {
19412  	 	 	 	 	 	 	 $value = ' ';
19413  	 	 	 	 	 	 }
19414  	 	 	 	 	 	 $w = $this->GetStringWidth($value) * 1.5;
19415  	 	 	 	 	 	 $h *= 1.6;
19416  	 	 	 	 	 	 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19417  	 	 	 	 	 	 if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
19418  	 	 	 	 	 	 	 $jsaction = $tag['attribute']['onclick'];
19419  	 	 	 	 	 	 } else {
19420  	 	 	 	 	 	 	 $jsaction = '';
19421  	 	 	 	 	 	 }
19422  	 	 	 	 	 	 $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
19423  	 	 	 	 	 	 break;
19424  	 	 	 	 	 }
19425  	 	 	 	 }
19426  	 	 	 	 break;
19427  	 	 	 }
19428  	 	 	 case 'textarea': {
19429  	 	 	 	 $prop = array();
19430  	 	 	 	 $opt = array();
19431  	 	 	 	 if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
19432  	 	 	 	 	 $prop['readonly'] = true;
19433  	 	 	 	 }
19434  	 	 	 	 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
19435  	 	 	 	 	 $name = $tag['attribute']['name'];
19436  	 	 	 	 } else {
19437  	 	 	 	 	 break;
19438  	 	 	 	 }
19439  	 	 	 	 if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
19440  	 	 	 	 	 $opt['v'] = $tag['attribute']['value'];
19441  	 	 	 	 }
19442  	 	 	 	 if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
19443  	 	 	 	 	 $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
19444  	 	 	 	 } else {
19445  	 	 	 	 	 $w = 40;
19446  	 	 	 	 }
19447  	 	 	 	 if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
19448  	 	 	 	 	 $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize);
19449  	 	 	 	 } else {
19450  	 	 	 	 	 $h = 10;
19451  	 	 	 	 }
19452  	 	 	 	 $prop['multiline'] = 'true';
19453  	 	 	 	 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19454  	 	 	 	 break;
19455  	 	 	 }
19456  	 	 	 case 'select': {
19457  	 	 	 	 $h = $this->getCellHeight($this->FontSize);
19458  	 	 	 	 if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
19459  	 	 	 	 	 $h *= ($tag['attribute']['size'] + 1);
19460  	 	 	 	 }
19461  	 	 	 	 $prop = array();
19462  	 	 	 	 $opt = array();
19463  	 	 	 	 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
19464  	 	 	 	 	 $name = $tag['attribute']['name'];
19465  	 	 	 	 } else {
19466  	 	 	 	 	 break;
19467  	 	 	 	 }
19468  	 	 	 	 $w = 0;
19469  	 	 	 	 if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
19470  	 	 	 	 	 $options = explode('#!NwL!#', $tag['attribute']['opt']);
19471  	 	 	 	 	 $values = array();
19472  	 	 	 	 	 foreach ($options as $val) {
19473  	 	 	 	 	 	 if (strpos($val, '#!TaB!#') !== false) {
19474  	 	 	 	 	 	 	 $opts = explode('#!TaB!#', $val);
19475  	 	 	 	 	 	 	 $values[] = $opts;
19476  	 	 	 	 	 	 	 $w = max($w, $this->GetStringWidth($opts[1]));
19477  	 	 	 	 	 	 } else {
19478  	 	 	 	 	 	 	 $values[] = $val;
19479  	 	 	 	 	 	 	 $w = max($w, $this->GetStringWidth($val));
19480  	 	 	 	 	 	 }
19481  	 	 	 	 	 }
19482  	 	 	 	 } else {
19483  	 	 	 	 	 break;
19484  	 	 	 	 }
19485  	 	 	 	 $w *= 2;
19486  	 	 	 	 if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
19487  	 	 	 	 	 $prop['multipleSelection'] = 'true';
19488  	 	 	 	 	 $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
19489  	 	 	 	 } else {
19490  	 	 	 	 	 $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
19491  	 	 	 	 }
19492  	 	 	 	 break;
19493  	 	 	 }
19494  	 	 	 case 'tcpdf': {
19495  	 	 	 	 if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
19496  	 	 	 	 	 // Special tag used to call TCPDF methods
19497  	 	 	 	 	 if (isset($tag['attribute']['method'])) {
19498  	 	 	 	 	 	 $tcpdf_method = $tag['attribute']['method'];
19499  	 	 	 	 	 	 if (method_exists($this, $tcpdf_method)) {
19500  	 	 	 	 	 	 	 if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
19501  	 	 	 	 	 	 	 	 $params = $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
19502  	 	 	 	 	 	 	 	 call_user_func_array(array($this, $tcpdf_method), $params);
19503  	 	 	 	 	 	 	 } else {
19504  	 	 	 	 	 	 	 	 $this->$tcpdf_method();
19505  	 	 	 	 	 	 	 }
19506  	 	 	 	 	 	 	 $this->newline = true;
19507  	 	 	 	 	 	 }
19508  	 	 	 	 	 }
19509  	 	 	 	 }
19510  	 	 	 	 break;
19511  	 	 	 }
19512  	 	 	 default: {
19513  	 	 	 	 break;
19514  	 	 	 }
19515  	 	 }
19516  	 	 // define tags that support borders and background colors
19517  	 	 $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
19518  	 	 if (in_array($tag['value'], $bordertags)) {
19519  	 	 	 // set border
19520  	 	 	 $dom[$key]['borderposition'] = $this->getBorderStartPosition();
19521  	 	 }
19522  	 	 if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
19523  	 	 	 $pba = $dom[$key]['attribute']['pagebreakafter'];
19524  	 	 	 // check for pagebreak
19525  	 	 	 if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
19526  	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19527  	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
19528  	 	 	 }
19529  	 	 	 if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
19530  	 	 	 	 OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
19531  	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19532  	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
19533  	 	 	 }
19534  	 	 }
19535  	 	 return $dom;
19536  	 }
19537  
19538  	 /**
19539  	  * Process closing tags.
19540  	  * @param array $dom html dom array
19541  	  * @param int $key current element id
19542  	  * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
19543  	  * @param int $maxbottomliney maximum y value of current line
19544  	  * @return array $dom
19545  	  * @protected
19546  	  */
19547  	protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
19548  	 	 $tag = $dom[$key];
19549  	 	 $parent = $dom[($dom[$key]['parent'])];
19550  	 	 $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
19551  	 	 $in_table_head = false;
19552  	 	 // maximum x position (used to draw borders)
19553  	 	 if ($this->rtl) {
19554  	 	 	 $xmax = $this->w;
19555  	 	 } else {
19556  	 	 	 $xmax = 0;
19557  	 	 }
19558  	 	 if ($tag['block']) {
19559  	 	 	 $hbz = 0; // distance from y to line bottom
19560  	 	 	 $hb = 0; // vertical space between block tags
19561  	 	 	 // calculate vertical space for block tags
19562  	 	 	 if (isset($this->tagvspaces[$tag['value']][1]['h']) && !empty($this->tagvspaces[$tag['value']][1]['h']) && ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
19563  	 	 	 	 $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
19564  	 	 	 } elseif (isset($parent['fontsize'])) {
19565  	 	 	 	 $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k);
19566  	 	 	 } else {
19567  	 	 	 	 $pre_h = $this->getCellHeight($this->FontSize);
19568  	 	 	 }
19569  	 	 	 if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
19570  	 	 	 	 $cn = $this->tagvspaces[$tag['value']][1]['n'];
19571  	 	 	 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
19572  	 	 	 	 $cn = 0.6;
19573  	 	 	 } else {
19574  	 	 	 	 $cn = 1;
19575  	 	 	 }
19576  	 	 	 if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
19577  	 	 	 	 $hb = 0;
19578  	 	 	 } else {
19579  	 	 	 	 $hb = ($cn * $pre_h);
19580  	 	 	 }
19581  	 	 	 if ($maxbottomliney > $this->PageBreakTrigger) {
19582  	 	 	 	 $hbz = $this->getCellHeight($this->FontSize);
19583  	 	 	 } elseif ($this->y < $maxbottomliney) {
19584  	 	 	 	 $hbz = ($maxbottomliney - $this->y);
19585  	 	 	 }
19586  	 	 }
19587  	 	 // Closing tag
19588  	 	 switch($tag['value']) {
19589  	 	 	 case 'tr': {
19590  	 	 	 	 $table_el = $dom[($dom[$key]['parent'])]['parent'];
19591  	 	 	 	 if (!isset($parent['endy'])) {
19592  	 	 	 	 	 $dom[($dom[$key]['parent'])]['endy'] = $this->y;
19593  	 	 	 	 	 $parent['endy'] = $this->y;
19594  	 	 	 	 }
19595  	 	 	 	 if (!isset($parent['endpage'])) {
19596  	 	 	 	 	 $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
19597  	 	 	 	 	 $parent['endpage'] = $this->page;
19598  	 	 	 	 }
19599  	 	 	 	 if (!isset($parent['endcolumn'])) {
19600  	 	 	 	 	 $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
19601  	 	 	 	 	 $parent['endcolumn'] = $this->current_column;
19602  	 	 	 	 }
19603  	 	 	 	 // update row-spanned cells
19604  	 	 	 	 if (isset($dom[$table_el]['rowspans'])) {
19605  	 	 	 	 	 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
19606  	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
19607  	 	 	 	 	 	 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
19608  	 	 	 	 	 	 	 if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
19609  	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
19610  	 	 	 	 	 	 	 } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
19611  	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
19612  	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
19613  	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
19614  	 	 	 	 	 	 	 }
19615  	 	 	 	 	 	 }
19616  	 	 	 	 	 }
19617  	 	 	 	 	 // report new endy and endpage to the rowspanned cells
19618  	 	 	 	 	 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
19619  	 	 	 	 	 	 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
19620  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
19621  	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
19622  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
19623  	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
19624  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
19625  	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
19626  	 	 	 	 	 	 }
19627  	 	 	 	 	 }
19628  	 	 	 	 	 // update remaining rowspanned cells
19629  	 	 	 	 	 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
19630  	 	 	 	 	 	 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
19631  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
19632  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
19633  	 	 	 	 	 	 	 $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
19634  	 	 	 	 	 	 }
19635  	 	 	 	 	 }
19636  	 	 	 	 }
19637  	 	 	 	 $prev_page = $this->page;
19638  	 	 	 	 $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
19639  	 	 	 	 if ($this->num_columns > 1) {
19640  	 	 	 	 	 if (($prev_page < $this->page)
19641  	 	 	 	 	 	 AND ((($this->current_column == 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns - 1)))
19642  	 	 	 	 	 	 	 OR ($this->current_column == $dom[($dom[$key]['parent'])]['endcolumn']))) {
19643  	 	 	 	 	 	 // page jump
19644  	 	 	 	 	 	 $this->selectColumn(0);
19645  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
19646  	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['endy'] = $this->y;
19647  	 	 	 	 	 } else {
19648  	 	 	 	 	 	 $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
19649  	 	 	 	 	 	 $this->y = $dom[($dom[$key]['parent'])]['endy'];
19650  	 	 	 	 	 }
19651  	 	 	 	 } else {
19652  	 	 	 	 	 $this->y = $dom[($dom[$key]['parent'])]['endy'];
19653  	 	 	 	 }
19654  	 	 	 	 if (isset($dom[$table_el]['attribute']['cellspacing'])) {
19655  	 	 	 	 	 $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
19656  	 	 	 	 } elseif (isset($dom[$table_el]['border-spacing'])) {
19657  	 	 	 	 	 $this->y += $dom[$table_el]['border-spacing']['V'];
19658  	 	 	 	 }
19659  	 	 	 	 $this->Ln(0, $cell);
19660  	 	 	 	 if ($this->current_column == $parent['startcolumn']) {
19661  	 	 	 	 	 $this->x = $parent['startx'];
19662  	 	 	 	 }
19663  	 	 	 	 // account for booklet mode
19664  	 	 	 	 if ($this->page > $parent['startpage']) {
19665  	 	 	 	 	 if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
19666  	 	 	 	 	 	 $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
19667  	 	 	 	 	 } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
19668  	 	 	 	 	 	 $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
19669  	 	 	 	 	 }
19670  	 	 	 	 }
19671  	 	 	 	 break;
19672  	 	 	 }
19673  	 	 	 case 'tablehead':
19674  	 	 	 	 // closing tag used for the thead part
19675  	 	 	 	 $in_table_head = true;
19676  	 	 	 	 $this->inthead = false;
19677  	 	 	 case 'table': {
19678  	 	 	 	 $table_el = $parent;
19679  	 	 	 	 // set default border
19680  	 	 	 	 if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
19681  	 	 	 	 	 // set default border
19682  	 	 	 	 	 $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
19683  	 	 	 	 } else {
19684  	 	 	 	 	 $border = 0;
19685  	 	 	 	 }
19686  	 	 	 	 $default_border = $border;
19687  	 	 	 	 // fix bottom line alignment of last line before page break
19688  	 	 	 	 foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
19689  	 	 	 	 	 // update row-spanned cells
19690  	 	 	 	 	 if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
19691  	 	 	 	 	 	 foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
19692  	 	 	 	 	 	 	 if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
19693  	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
19694  	 	 	 	 	 	 	 }
19695  	 	 	 	 	 	 	 if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
19696  	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
19697  	 	 	 	 	 	 	 }
19698  	 	 	 	 	 	 }
19699  	 	 	 	 	 }
19700  	 	 	 	 	 if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
19701  	 	 	 	 	 	 $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
19702  	 	 	 	 	 	 $dom[$prevtrkey]['endy'] = $pgendy;
19703  	 	 	 	 	 	 // update row-spanned cells
19704  	 	 	 	 	 	 if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
19705  	 	 	 	 	 	 	 foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
19706  	 	 	 	 	 	 	 	 if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
19707  	 	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
19708  	 	 	 	 	 	 	 	 	 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
19709  	 	 	 	 	 	 	 	 }
19710  	 	 	 	 	 	 	 }
19711  	 	 	 	 	 	 }
19712  	 	 	 	 	 }
19713  	 	 	 	 	 $prevtrkey = $trkey;
19714  	 	 	 	 	 $table_el = $dom[($dom[$key]['parent'])];
19715  	 	 	 	 }
19716  	 	 	 	 // for each row
19717  	 	 	 	 if (count($table_el['trids']) > 0) {
19718  	 	 	 	 	 unset($xmax);
19719  	 	 	 	 }
19720  	 	 	 	 foreach ($table_el['trids'] as $j => $trkey) {
19721  	 	 	 	 	 $parent = $dom[$trkey];
19722  	 	 	 	 	 if (!isset($xmax)) {
19723  	 	 	 	 	 	 $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
19724  	 	 	 	 	 }
19725  	 	 	 	 	 // for each cell on the row
19726  	 	 	 	 	 foreach ($parent['cellpos'] as $k => $cellpos) {
19727  	 	 	 	 	 	 if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
19728  	 	 	 	 	 	 	 $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
19729  	 	 	 	 	 	 	 $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
19730  	 	 	 	 	 	 	 $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
19731  	 	 	 	 	 	 	 $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
19732  	 	 	 	 	 	 	 $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
19733  	 	 	 	 	 	 	 $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
19734  	 	 	 	 	 	 	 $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
19735  	 	 	 	 	 	 } else {
19736  	 	 	 	 	 	 	 $endy = $parent['endy'];
19737  	 	 	 	 	 	 	 $startpage = $parent['startpage'];
19738  	 	 	 	 	 	 	 $endpage = $parent['endpage'];
19739  	 	 	 	 	 	 	 $startcolumn = $parent['startcolumn'];
19740  	 	 	 	 	 	 	 $endcolumn = $parent['endcolumn'];
19741  	 	 	 	 	 	 }
19742  	 	 	 	 	 	 if ($this->num_columns == 0) {
19743  	 	 	 	 	 	 	 $this->num_columns = 1;
19744  	 	 	 	 	 	 }
19745  	 	 	 	 	 	 if (isset($cellpos['border'])) {
19746  	 	 	 	 	 	 	 $border = $cellpos['border'];
19747  	 	 	 	 	 	 }
19748  	 	 	 	 	 	 if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
19749  	 	 	 	 	 	 	 $this->setFillColorArray($cellpos['bgcolor']);
19750  	 	 	 	 	 	 	 $fill = true;
19751  	 	 	 	 	 	 } else {
19752  	 	 	 	 	 	 	 $fill = false;
19753  	 	 	 	 	 	 }
19754  	 	 	 	 	 	 $x = $cellpos['startx'];
19755  	 	 	 	 	 	 $y = $parent['starty'];
19756  	 	 	 	 	 	 $starty = $y;
19757  	 	 	 	 	 	 $w = abs($cellpos['endx'] - $cellpos['startx']);
19758  	 	 	 	 	 	 // get border modes
19759  	 	 	 	 	 	 $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
19760  	 	 	 	 	 	 $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
19761  	 	 	 	 	 	 $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
19762  	 	 	 	 	 	 // design borders around HTML cells.
19763  	 	 	 	 	 	 for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
19764  	 	 	 	 	 	 	 $ccode = '';
19765  	 	 	 	 	 	 	 $this->setPage($page);
19766  	 	 	 	 	 	 	 if ($this->num_columns < 2) {
19767  	 	 	 	 	 	 	 	 // single-column mode
19768  	 	 	 	 	 	 	 	 $this->x = $x;
19769  	 	 	 	 	 	 	 	 $this->y = $this->tMargin;
19770  	 	 	 	 	 	 	 }
19771  	 	 	 	 	 	 	 // account for margin changes
19772  	 	 	 	 	 	 	 if ($page > $startpage) {
19773  	 	 	 	 	 	 	 	 if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
19774  	 	 	 	 	 	 	 	 	 $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
19775  	 	 	 	 	 	 	 	 } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
19776  	 	 	 	 	 	 	 	 	 $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
19777  	 	 	 	 	 	 	 	 }
19778  	 	 	 	 	 	 	 }
19779  	 	 	 	 	 	 	 if ($startpage == $endpage) { // single page
19780  	 	 	 	 	 	 	 	 $deltacol = 0;
19781  	 	 	 	 	 	 	 	 $deltath = 0;
19782  	 	 	 	 	 	 	 	 for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
19783  	 	 	 	 	 	 	 	 	 $this->selectColumn($column);
19784  	 	 	 	 	 	 	 	 	 if ($startcolumn == $endcolumn) { // single column
19785  	 	 	 	 	 	 	 	 	 	 $cborder = $border;
19786  	 	 	 	 	 	 	 	 	 	 $h = $endy - $parent['starty'];
19787  	 	 	 	 	 	 	 	 	 	 $this->y = $y;
19788  	 	 	 	 	 	 	 	 	 	 $this->x = $x;
19789  	 	 	 	 	 	 	 	 	 } elseif ($column == $startcolumn) { // first column
19790  	 	 	 	 	 	 	 	 	 	 $cborder = $border_start;
19791  	 	 	 	 	 	 	 	 	 	 $this->y = $starty;
19792  	 	 	 	 	 	 	 	 	 	 $this->x = $x;
19793  	 	 	 	 	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
19794  	 	 	 	 	 	 	 	 	 	 if ($this->rtl) {
19795  	 	 	 	 	 	 	 	 	 	 	 $deltacol = $this->x + $this->rMargin - $this->w;
19796  	 	 	 	 	 	 	 	 	 	 } else {
19797  	 	 	 	 	 	 	 	 	 	 	 $deltacol = $this->x - $this->lMargin;
19798  	 	 	 	 	 	 	 	 	 	 }
19799  	 	 	 	 	 	 	 	 	 } elseif ($column == $endcolumn) { // end column
19800  	 	 	 	 	 	 	 	 	 	 $cborder = $border_end;
19801  	 	 	 	 	 	 	 	 	 	 if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
19802  	 	 	 	 	 	 	 	 	 	 	 $this->y = $this->columns[$column]['th']['\''.$page.'\''];
19803  	 	 	 	 	 	 	 	 	 	 }
19804  	 	 	 	 	 	 	 	 	 	 $this->x += $deltacol;
19805  	 	 	 	 	 	 	 	 	 	 $h = $endy - $this->y;
19806  	 	 	 	 	 	 	 	 	 } else { // middle column
19807  	 	 	 	 	 	 	 	 	 	 $cborder = $border_middle;
19808  	 	 	 	 	 	 	 	 	 	 if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
19809  	 	 	 	 	 	 	 	 	 	 	 $this->y = $this->columns[$column]['th']['\''.$page.'\''];
19810  	 	 	 	 	 	 	 	 	 	 }
19811  	 	 	 	 	 	 	 	 	 	 $this->x += $deltacol;
19812  	 	 	 	 	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
19813  	 	 	 	 	 	 	 	 	 }
19814  	 	 	 	 	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19815  	 	 	 	 	 	 	 	 } // end for each column
19816  	 	 	 	 	 	 	 } elseif ($page == $startpage) { // first page
19817  	 	 	 	 	 	 	 	 $deltacol = 0;
19818  	 	 	 	 	 	 	 	 $deltath = 0;
19819  	 	 	 	 	 	 	 	 for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
19820  	 	 	 	 	 	 	 	 	 $this->selectColumn($column);
19821  	 	 	 	 	 	 	 	 	 if ($column == $startcolumn) { // first column
19822  	 	 	 	 	 	 	 	 	 	 $cborder = $border_start;
19823  	 	 	 	 	 	 	 	 	 	 $this->y = $starty;
19824  	 	 	 	 	 	 	 	 	 	 $this->x = $x;
19825  	 	 	 	 	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
19826  	 	 	 	 	 	 	 	 	 	 if ($this->rtl) {
19827  	 	 	 	 	 	 	 	 	 	 	 $deltacol = $this->x + $this->rMargin - $this->w;
19828  	 	 	 	 	 	 	 	 	 	 } else {
19829  	 	 	 	 	 	 	 	 	 	 	 $deltacol = $this->x - $this->lMargin;
19830  	 	 	 	 	 	 	 	 	 	 }
19831  	 	 	 	 	 	 	 	 	 } else { // middle column
19832  	 	 	 	 	 	 	 	 	 	 $cborder = $border_middle;
19833  	 	 	 	 	 	 	 	 	 	 if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
19834  	 	 	 	 	 	 	 	 	 	 	 $this->y = $this->columns[$column]['th']['\''.$page.'\''];
19835  	 	 	 	 	 	 	 	 	 	 }
19836  	 	 	 	 	 	 	 	 	 	 $this->x += $deltacol;
19837  	 	 	 	 	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
19838  	 	 	 	 	 	 	 	 	 }
19839  	 	 	 	 	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19840  	 	 	 	 	 	 	 	 } // end for each column
19841  	 	 	 	 	 	 	 } elseif ($page == $endpage) { // last page
19842  	 	 	 	 	 	 	 	 $deltacol = 0;
19843  	 	 	 	 	 	 	 	 $deltath = 0;
19844  	 	 	 	 	 	 	 	 for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
19845  	 	 	 	 	 	 	 	 	 $this->selectColumn($column);
19846  	 	 	 	 	 	 	 	 	 if ($column == $endcolumn) { // end column
19847  	 	 	 	 	 	 	 	 	 	 $cborder = $border_end;
19848  	 	 	 	 	 	 	 	 	 	 if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
19849  	 	 	 	 	 	 	 	 	 	 	 $this->y = $this->columns[$column]['th']['\''.$page.'\''];
19850  	 	 	 	 	 	 	 	 	 	 }
19851  	 	 	 	 	 	 	 	 	 	 $this->x += $deltacol;
19852  	 	 	 	 	 	 	 	 	 	 $h = $endy - $this->y;
19853  	 	 	 	 	 	 	 	 	 } else { // middle column
19854  	 	 	 	 	 	 	 	 	 	 $cborder = $border_middle;
19855  	 	 	 	 	 	 	 	 	 	 if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
19856  	 	 	 	 	 	 	 	 	 	 	 $this->y = $this->columns[$column]['th']['\''.$page.'\''];
19857  	 	 	 	 	 	 	 	 	 	 }
19858  	 	 	 	 	 	 	 	 	 	 $this->x += $deltacol;
19859  	 	 	 	 	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
19860  	 	 	 	 	 	 	 	 	 }
19861  	 	 	 	 	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19862  	 	 	 	 	 	 	 	 } // end for each column
19863  	 	 	 	 	 	 	 } else { // middle page
19864  	 	 	 	 	 	 	 	 $deltacol = 0;
19865  	 	 	 	 	 	 	 	 $deltath = 0;
19866  	 	 	 	 	 	 	 	 for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
19867  	 	 	 	 	 	 	 	 	 $this->selectColumn($column);
19868  	 	 	 	 	 	 	 	 	 $cborder = $border_middle;
19869  	 	 	 	 	 	 	 	 	 if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
19870  	 	 	 	 	 	 	 	 	 	 $this->y = $this->columns[$column]['th']['\''.$page.'\''];
19871  	 	 	 	 	 	 	 	 	 }
19872  	 	 	 	 	 	 	 	 	 $this->x += $deltacol;
19873  	 	 	 	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
19874  	 	 	 	 	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19875  	 	 	 	 	 	 	 	 } // end for each column
19876  	 	 	 	 	 	 	 }
19877  	 	 	 	 	 	 	 if (!empty($cborder) OR !empty($fill)) {
19878  	 	 	 	 	 	 	 	 $offsetlen = strlen($ccode);
19879  	 	 	 	 	 	 	 	 // draw border and fill
19880  	 	 	 	 	 	 	 	 if ($this->inxobj) {
19881  	 	 	 	 	 	 	 	 	 // we are inside an XObject template
19882  	 	 	 	 	 	 	 	 	 if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
19883  	 	 	 	 	 	 	 	 	 	 $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
19884  	 	 	 	 	 	 	 	 	 	 $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
19885  	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
19886  	 	 	 	 	 	 	 	 	 } else {
19887  	 	 	 	 	 	 	 	 	 	 $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
19888  	 	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
19889  	 	 	 	 	 	 	 	 	 }
19890  	 	 	 	 	 	 	 	 	 $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
19891  	 	 	 	 	 	 	 	 	 $pstart = substr($pagebuff, 0, $pagemark);
19892  	 	 	 	 	 	 	 	 	 $pend = substr($pagebuff, $pagemark);
19893  	 	 	 	 	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
19894  	 	 	 	 	 	 	 	 } else {
19895  	 	 	 	 	 	 	 	 	 // draw border and fill
19896  	 	 	 	 	 	 	 	 	 if (end($this->transfmrk[$this->page]) !== false) {
19897  	 	 	 	 	 	 	 	 	 	 $pagemarkkey = key($this->transfmrk[$this->page]);
19898  	 	 	 	 	 	 	 	 	 	 $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
19899  	 	 	 	 	 	 	 	 	 } elseif ($this->InFooter) {
19900  	 	 	 	 	 	 	 	 	 	 $pagemark = $this->footerpos[$this->page];
19901  	 	 	 	 	 	 	 	 	 } else {
19902  	 	 	 	 	 	 	 	 	 	 $pagemark = $this->intmrk[$this->page];
19903  	 	 	 	 	 	 	 	 	 }
19904  	 	 	 	 	 	 	 	 	 $pagebuff = $this->getPageBuffer($this->page);
19905  	 	 	 	 	 	 	 	 	 $pstart = substr($pagebuff, 0, $pagemark);
19906  	 	 	 	 	 	 	 	 	 $pend = substr($pagebuff, $pagemark);
19907  	 	 	 	 	 	 	 	 	 $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
19908  	 	 	 	 	 	 	 	 }
19909  	 	 	 	 	 	 	 }
19910  	 	 	 	 	 	 } // end for each page
19911  	 	 	 	 	 	 // restore default border
19912  	 	 	 	 	 	 $border = $default_border;
19913  	 	 	 	 	 } // end for each cell on the row
19914  	 	 	 	 	 if (isset($table_el['attribute']['cellspacing'])) {
19915  	 	 	 	 	 	 $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
19916  	 	 	 	 	 } elseif (isset($table_el['border-spacing'])) {
19917  	 	 	 	 	 	 $this->y += $table_el['border-spacing']['V'];
19918  	 	 	 	 	 }
19919  	 	 	 	 	 $this->Ln(0, $cell);
19920  	 	 	 	 	 $this->x = $parent['startx'];
19921  	 	 	 	 	 if ($endpage > $startpage) {
19922  	 	 	 	 	 	 if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
19923  	 	 	 	 	 	 	 $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
19924  	 	 	 	 	 	 } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
19925  	 	 	 	 	 	 	 $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
19926  	 	 	 	 	 	 }
19927  	 	 	 	 	 }
19928  	 	 	 	 }
19929  	 	 	 	 if (!$in_table_head) { // we are not inside a thead section
19930  	 	 	 	 	 $this->cell_padding = isset($table_el['old_cell_padding']) ? $table_el['old_cell_padding'] : null;
19931  	 	 	 	 	 // reset row height
19932  	 	 	 	 	 $this->resetLastH();
19933  	 	 	 	 	 if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
19934  	 	 	 	 	 	 $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
19935  	 	 	 	 	 	 if (($plendiff > 0) AND ($plendiff < 60)) {
19936  	 	 	 	 	 	 	 $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
19937  	 	 	 	 	 	 	 if (substr($pagediff, 0, 5) == 'BT /F') {
19938  	 	 	 	 	 	 	 	 // the difference is only a font setting
19939  	 	 	 	 	 	 	 	 $plendiff = 0;
19940  	 	 	 	 	 	 	 }
19941  	 	 	 	 	 	 }
19942  	 	 	 	 	 	 if ($plendiff == 0) {
19943  	 	 	 	 	 	 	 // remove last blank page
19944  	 	 	 	 	 	 	 $this->deletePage($this->numpages);
19945  	 	 	 	 	 	 }
19946  	 	 	 	 	 }
19947  	 	 	 	 	 if (isset($this->theadMargins['top'])) {
19948  	 	 	 	 	 	 // restore top margin
19949  	 	 	 	 	 	 $this->tMargin = $this->theadMargins['top'];
19950  	 	 	 	 	 }
19951  	 	 	 	 	 if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
19952  	 	 	 	 	 	 // reset main table header
19953  	 	 	 	 	 	 $this->thead = '';
19954  	 	 	 	 	 	 $this->theadMargins = array();
19955  	 	 	 	 	 	 $this->pagedim[$this->page]['tm'] = $this->tMargin;
19956  	 	 	 	 	 }
19957  	 	 	 	 }
19958  	 	 	 	 $parent = $table_el;
19959  	 	 	 	 break;
19960  	 	 	 }
19961  	 	 	 case 'a': {
19962  	 	 	 	 $this->HREF = array();
19963  	 	 	 	 break;
19964  	 	 	 }
19965  	 	 	 case 'sup': {
19966  	 	 	 	 $this->setXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
19967  	 	 	 	 break;
19968  	 	 	 }
19969  	 	 	 case 'sub': {
19970  	 	 	 	 $this->setXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
19971  	 	 	 	 break;
19972  	 	 	 }
19973  	 	 	 case 'div': {
19974  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19975  	 	 	 	 break;
19976  	 	 	 }
19977  	 	 	 case 'blockquote': {
19978  	 	 	 	 if ($this->rtl) {
19979  	 	 	 	 	 $this->rMargin -= $this->listindent;
19980  	 	 	 	 } else {
19981  	 	 	 	 	 $this->lMargin -= $this->listindent;
19982  	 	 	 	 }
19983  	 	 	 	 --$this->listindentlevel;
19984  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19985  	 	 	 	 break;
19986  	 	 	 }
19987  	 	 	 case 'p': {
19988  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19989  	 	 	 	 break;
19990  	 	 	 }
19991  	 	 	 case 'pre': {
19992  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19993  	 	 	 	 $this->premode = false;
19994  	 	 	 	 break;
19995  	 	 	 }
19996  	 	 	 case 'dl': {
19997  	 	 	 	 --$this->listnum;
19998  	 	 	 	 if ($this->listnum <= 0) {
19999  	 	 	 	 	 $this->listnum = 0;
20000  	 	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
20001  	 	 	 	 } else {
20002  	 	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
20003  	 	 	 	 }
20004  	 	 	 	 $this->resetLastH();
20005  	 	 	 	 break;
20006  	 	 	 }
20007  	 	 	 case 'dt': {
20008  	 	 	 	 $this->lispacer = '';
20009  	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
20010  	 	 	 	 break;
20011  	 	 	 }
20012  	 	 	 case 'dd': {
20013  	 	 	 	 $this->lispacer = '';
20014  	 	 	 	 if ($this->rtl) {
20015  	 	 	 	 	 $this->rMargin -= $this->listindent;
20016  	 	 	 	 } else {
20017  	 	 	 	 	 $this->lMargin -= $this->listindent;
20018  	 	 	 	 }
20019  	 	 	 	 --$this->listindentlevel;
20020  	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
20021  	 	 	 	 break;
20022  	 	 	 }
20023  	 	 	 case 'ul':
20024  	 	 	 case 'ol': {
20025  	 	 	 	 --$this->listnum;
20026  	 	 	 	 $this->lispacer = '';
20027  	 	 	 	 if ($this->rtl) {
20028  	 	 	 	 	 $this->rMargin -= $this->listindent;
20029  	 	 	 	 } else {
20030  	 	 	 	 	 $this->lMargin -= $this->listindent;
20031  	 	 	 	 }
20032  	 	 	 	 --$this->listindentlevel;
20033  	 	 	 	 if ($this->listnum <= 0) {
20034  	 	 	 	 	 $this->listnum = 0;
20035  	 	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
20036  	 	 	 	 } else {
20037  	 	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
20038  	 	 	 	 }
20039  	 	 	 	 $this->resetLastH();
20040  	 	 	 	 break;
20041  	 	 	 }
20042  	 	 	 case 'li': {
20043  	 	 	 	 $this->lispacer = '';
20044  	 	 	 	 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
20045  	 	 	 	 break;
20046  	 	 	 }
20047  	 	 	 case 'h1':
20048  	 	 	 case 'h2':
20049  	 	 	 case 'h3':
20050  	 	 	 case 'h4':
20051  	 	 	 case 'h5':
20052  	 	 	 case 'h6': {
20053  	 	 	 	 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
20054  	 	 	 	 break;
20055  	 	 	 }
20056  	 	 	 // Form fields (since 4.8.000 - 2009-09-07)
20057  	 	 	 case 'form': {
20058  	 	 	 	 $this->form_action = '';
20059  	 	 	 	 $this->form_enctype = 'application/x-www-form-urlencoded';
20060  	 	 	 	 break;
20061  	 	 	 }
20062  	 	 	 default : {
20063  	 	 	 	 break;
20064  	 	 	 }
20065  	 	 }
20066  	 	 // draw border and background (if any)
20067  	 	 $this->drawHTMLTagBorder($parent, $xmax);
20068  	 	 if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
20069  	 	 	 $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
20070  	 	 	 // check for pagebreak
20071  	 	 	 if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
20072  	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
20073  	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
20074  	 	 	 }
20075  	 	 	 if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
20076  	 	 	 	 OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
20077  	 	 	 	 // add a page (or trig AcceptPageBreak() for multicolumn mode)
20078  	 	 	 	 $this->checkPageBreak($this->PageBreakTrigger + 1);
20079  	 	 	 }
20080  	 	 }
20081  	 	 $this->tmprtl = false;
20082  	 	 return $dom;
20083  	 }
20084  
20085  	 /**
20086  	  * Add vertical spaces if needed.
20087  	  * @param string $hbz Distance between current y and line bottom.
20088  	  * @param string $hb The height of the break.
20089  	  * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
20090  	  * @param boolean $firsttag set to true when the tag is the first.
20091  	  * @param boolean $lasttag set to true when the tag is the last.
20092  	  * @protected
20093  	  */
20094  	protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
20095  	 	 if ($firsttag) {
20096  	 	 	 $this->Ln(0, $cell);
20097  	 	 	 $this->htmlvspace = 0;
20098  	 	 	 return;
20099  	 	 }
20100  	 	 if ($lasttag) {
20101  	 	 	 $this->Ln($hbz, $cell);
20102  	 	 	 $this->htmlvspace = 0;
20103  	 	 	 return;
20104  	 	 }
20105  	 	 if ($hb < $this->htmlvspace) {
20106  	 	 	 $hd = 0;
20107  	 	 } else {
20108  	 	 	 $hd = $hb - $this->htmlvspace;
20109  	 	 	 $this->htmlvspace = $hb;
20110  	 	 }
20111  	 	 $this->Ln(($hbz + $hd), $cell);
20112  	 }
20113  
20114  	 /**
20115  	  * Return the starting coordinates to draw an html border
20116  	  * @return array containing top-left border coordinates
20117  	  * @protected
20118  	  * @since 5.7.000 (2010-08-03)
20119  	  */
20120  	protected function getBorderStartPosition() {
20121  	 	 if ($this->rtl) {
20122  	 	 	 $xmax = $this->lMargin;
20123  	 	 } else {
20124  	 	 	 $xmax = $this->w - $this->rMargin;
20125  	 	 }
20126  	 	 return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
20127  	 }
20128  
20129  	 /**
20130  	  * Draw an HTML block border and fill
20131  	  * @param array $tag array of tag properties.
20132  	  * @param int $xmax end X coordinate for border.
20133  	  * @protected
20134  	  * @since 5.7.000 (2010-08-03)
20135  	  */
20136  	protected function drawHTMLTagBorder($tag, $xmax) {
20137  	 	 if (!isset($tag['borderposition'])) {
20138  	 	 	 // nothing to draw
20139  	 	 	 return;
20140  	 	 }
20141  	 	 $prev_x = $this->x;
20142  	 	 $prev_y = $this->y;
20143  	 	 $prev_lasth = $this->lasth;
20144  	 	 $border = 0;
20145  	 	 $fill = false;
20146  	 	 $this->lasth = 0;
20147  	 	 if (isset($tag['border']) AND !empty($tag['border'])) {
20148  	 	 	 // get border style
20149  	 	 	 $border = $tag['border'];
20150  	 	 	 if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
20151  	 	 	 	 // border for table header
20152  	 	 	 	 $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
20153  	 	 	 }
20154  	 	 }
20155  	 	 if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
20156  	 	 	 // get background color
20157  	 	 	 $old_bgcolor = $this->bgcolor;
20158  	 	 	 $this->setFillColorArray($tag['bgcolor']);
20159  	 	 	 $fill = true;
20160  	 	 }
20161  	 	 if (!$border AND !$fill) {
20162  	 	 	 // nothing to draw
20163  	 	 	 return;
20164  	 	 }
20165  	 	 if (isset($tag['attribute']['cellspacing'])) {
20166  	 	 	 $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
20167  	 	 	 $cellspacing = array('H' => $clsp, 'V' => $clsp);
20168  	 	 } elseif (isset($tag['border-spacing'])) {
20169  	 	 	 $cellspacing = $tag['border-spacing'];
20170  	 	 } else {
20171  	 	 	 $cellspacing = array('H' => 0, 'V' => 0);
20172  	 	 }
20173  	 	 if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
20174  	 	 	 // draw the border externally respect the sqare edge.
20175  	 	 	 $border['mode'] = 'ext';
20176  	 	 }
20177  	 	 if ($this->rtl) {
20178  	 	 	 if ($xmax >= $tag['borderposition']['x']) {
20179  	 	 	 	 $xmax = $tag['borderposition']['xmax'];
20180  	 	 	 }
20181  	 	 	 $w = ($tag['borderposition']['x'] - $xmax);
20182  	 	 } else {
20183  	 	 	 if ($xmax <= $tag['borderposition']['x']) {
20184  	 	 	 	 $xmax = $tag['borderposition']['xmax'];
20185  	 	 	 }
20186  	 	 	 $w = ($xmax - $tag['borderposition']['x']);
20187  	 	 }
20188  	 	 if ($w <= 0) {
20189  	 	 	 return;
20190  	 	 }
20191  	 	 $w += $cellspacing['H'];
20192  	 	 $startpage = $tag['borderposition']['page'];
20193  	 	 $startcolumn = $tag['borderposition']['column'];
20194  	 	 $x = $tag['borderposition']['x'];
20195  	 	 $y = $tag['borderposition']['y'];
20196  	 	 $endpage = $this->page;
20197  	 	 $starty = $tag['borderposition']['y'] - $cellspacing['V'];
20198  	 	 $currentY = $this->y;
20199  	 	 $this->x = $x;
20200  	 	 // get latest column
20201  	 	 $endcolumn = $this->current_column;
20202  	 	 if ($this->num_columns == 0) {
20203  	 	 	 $this->num_columns = 1;
20204  	 	 }
20205  	 	 // get border modes
20206  	 	 $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
20207  	 	 $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
20208  	 	 $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
20209  	 	 // temporary disable page regions
20210  	 	 $temp_page_regions = $this->page_regions;
20211  	 	 $this->page_regions = array();
20212  	 	 // design borders around HTML cells.
20213  	 	 for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
20214  	 	 	 $ccode = '';
20215  	 	 	 $this->setPage($page);
20216  	 	 	 if ($this->num_columns < 2) {
20217  	 	 	 	 // single-column mode
20218  	 	 	 	 $this->x = $x;
20219  	 	 	 	 $this->y = $this->tMargin;
20220  	 	 	 }
20221  	 	 	 // account for margin changes
20222  	 	 	 if ($page > $startpage) {
20223  	 	 	 	 if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
20224  	 	 	 	 	 $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
20225  	 	 	 	 } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
20226  	 	 	 	 	 $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
20227  	 	 	 	 }
20228  	 	 	 }
20229  	 	 	 if ($startpage == $endpage) {
20230  	 	 	 	 // single page
20231  	 	 	 	 for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
20232  	 	 	 	 	 $this->selectColumn($column);
20233  	 	 	 	 	 if ($startcolumn == $endcolumn) { // single column
20234  	 	 	 	 	 	 $cborder = $border;
20235  	 	 	 	 	 	 $h = ($currentY - $y) + $cellspacing['V'];
20236  	 	 	 	 	 	 $this->y = $starty;
20237  	 	 	 	 	 } elseif ($column == $startcolumn) { // first column
20238  	 	 	 	 	 	 $cborder = $border_start;
20239  	 	 	 	 	 	 $this->y = $starty;
20240  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
20241  	 	 	 	 	 } elseif ($column == $endcolumn) { // end column
20242  	 	 	 	 	 	 $cborder = $border_end;
20243  	 	 	 	 	 	 $h = $currentY - $this->y;
20244  	 	 	 	 	 } else { // middle column
20245  	 	 	 	 	 	 $cborder = $border_middle;
20246  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
20247  	 	 	 	 	 }
20248  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20249  	 	 	 	 } // end for each column
20250  	 	 	 } elseif ($page == $startpage) { // first page
20251  	 	 	 	 for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
20252  	 	 	 	 	 $this->selectColumn($column);
20253  	 	 	 	 	 if ($column == $startcolumn) { // first column
20254  	 	 	 	 	 	 $cborder = $border_start;
20255  	 	 	 	 	 	 $this->y = $starty;
20256  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
20257  	 	 	 	 	 } else { // middle column
20258  	 	 	 	 	 	 $cborder = $border_middle;
20259  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
20260  	 	 	 	 	 }
20261  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20262  	 	 	 	 } // end for each column
20263  	 	 	 } elseif ($page == $endpage) { // last page
20264  	 	 	 	 for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
20265  	 	 	 	 	 $this->selectColumn($column);
20266  	 	 	 	 	 if ($column == $endcolumn) {
20267  	 	 	 	 	 	 // end column
20268  	 	 	 	 	 	 $cborder = $border_end;
20269  	 	 	 	 	 	 $h = $currentY - $this->y;
20270  	 	 	 	 	 } else {
20271  	 	 	 	 	 	 // middle column
20272  	 	 	 	 	 	 $cborder = $border_middle;
20273  	 	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
20274  	 	 	 	 	 }
20275  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20276  	 	 	 	 } // end for each column
20277  	 	 	 } else { // middle page
20278  	 	 	 	 for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
20279  	 	 	 	 	 $this->selectColumn($column);
20280  	 	 	 	 	 $cborder = $border_middle;
20281  	 	 	 	 	 $h = $this->h - $this->y - $this->bMargin;
20282  	 	 	 	 	 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20283  	 	 	 	 } // end for each column
20284  	 	 	 }
20285  	 	 	 if ($cborder OR $fill) {
20286  	 	 	 	 $offsetlen = strlen($ccode);
20287  	 	 	 	 // draw border and fill
20288  	 	 	 	 if ($this->inxobj) {
20289  	 	 	 	 	 // we are inside an XObject template
20290  	 	 	 	 	 if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
20291  	 	 	 	 	 	 $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
20292  	 	 	 	 	 	 $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
20293  	 	 	 	 	 	 $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
20294  	 	 	 	 	 } else {
20295  	 	 	 	 	 	 $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
20296  	 	 	 	 	 	 $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
20297  	 	 	 	 	 }
20298  	 	 	 	 	 $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
20299  	 	 	 	 	 $pstart = substr($pagebuff, 0, $pagemark);
20300  	 	 	 	 	 $pend = substr($pagebuff, $pagemark);
20301  	 	 	 	 	 $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
20302  	 	 	 	 } else {
20303  	 	 	 	 	 if (end($this->transfmrk[$this->page]) !== false) {
20304  	 	 	 	 	 	 $pagemarkkey = key($this->transfmrk[$this->page]);
20305  	 	 	 	 	 	 $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
20306  	 	 	 	 	 } elseif ($this->InFooter) {
20307  	 	 	 	 	 	 $pagemark = $this->footerpos[$this->page];
20308  	 	 	 	 	 } else {
20309  	 	 	 	 	 	 $pagemark = $this->intmrk[$this->page];
20310  	 	 	 	 	 }
20311  	 	 	 	 	 $pagebuff = $this->getPageBuffer($this->page);
20312  	 	 	 	 	 $pstart = substr($pagebuff, 0, $pagemark);
20313  	 	 	 	 	 $pend = substr($pagebuff, $pagemark);
20314  	 	 	 	 	 $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
20315  	 	 	 	 	 $this->bordermrk[$this->page] += $offsetlen;
20316  	 	 	 	 	 $this->cntmrk[$this->page] += $offsetlen;
20317  	 	 	 	 }
20318  	 	 	 }
20319  	 	 } // end for each page
20320  	 	 // restore page regions
20321  	 	 $this->page_regions = $temp_page_regions;
20322  	 	 if (isset($old_bgcolor)) {
20323  	 	 	 // restore background color
20324  	 	 	 $this->setFillColorArray($old_bgcolor);
20325  	 	 }
20326  	 	 // restore pointer position
20327  	 	 $this->x = $prev_x;
20328  	 	 $this->y = $prev_y;
20329  	 	 $this->lasth = $prev_lasth;
20330  	 }
20331  
20332  	 /**
20333  	  * Set the default bullet to be used as LI bullet symbol
20334  	  * @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')
20335  	  * @public
20336  	  * @since 4.0.028 (2008-09-26)
20337  	  */
20338  	public function setLIsymbol($symbol='!') {
20339  	 	 // check for custom image symbol
20340  	 	 if (substr($symbol, 0, 4) == 'img|') {
20341  	 	 	 $this->lisymbol = $symbol;
20342  	 	 	 return;
20343  	 	 }
20344  	 	 $symbol = strtolower($symbol);
20345  	 	 $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');
20346  	 	 if (in_array($symbol, $valid_symbols)) {
20347  	 	 	 $this->lisymbol = $symbol;
20348  	 	 } else {
20349  	 	 	 $this->lisymbol = '';
20350  	 	 }
20351  	 }
20352  
20353  	 /**
20354  	  * Set the booklet mode for double-sided pages.
20355  	  * @param boolean $booklet true set the booklet mode on, false otherwise.
20356  	  * @param float $inner Inner page margin.
20357  	  * @param float $outer Outer page margin.
20358  	  * @public
20359  	  * @since 4.2.000 (2008-10-29)
20360  	  */
20361  	public function setBooklet($booklet=true, $inner=-1, $outer=-1) {
20362  	 	 $this->booklet = $booklet;
20363  	 	 if ($inner >= 0) {
20364  	 	 	 $this->lMargin = $inner;
20365  	 	 }
20366  	 	 if ($outer >= 0) {
20367  	 	 	 $this->rMargin = $outer;
20368  	 	 }
20369  	 }
20370  
20371  	 /**
20372  	  * Swap the left and right margins.
20373  	  * @param boolean $reverse if true swap left and right margins.
20374  	  * @protected
20375  	  * @since 4.2.000 (2008-10-29)
20376  	  */
20377  	protected function swapMargins($reverse=true) {
20378  	 	 if ($reverse) {
20379  	 	 	 // swap left and right margins
20380  	 	 	 $mtemp = $this->original_lMargin;
20381  	 	 	 $this->original_lMargin = $this->original_rMargin;
20382  	 	 	 $this->original_rMargin = $mtemp;
20383  	 	 	 $deltam = $this->original_lMargin - $this->original_rMargin;
20384  	 	 	 $this->lMargin += $deltam;
20385  	 	 	 $this->rMargin -= $deltam;
20386  	 	 }
20387  	 }
20388  
20389  	 /**
20390  	  * Set the vertical spaces for HTML tags.
20391  	  * The array must have the following structure (example):
20392  	  * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
20393  	  * The first array level contains the tag names,
20394  	  * the second level contains 0 for opening tags or 1 for closing tags,
20395  	  * the third level contains the vertical space unit (h) and the number spaces to add (n).
20396  	  * If the h parameter is not specified, default values are used.
20397  	  * @param array $tagvs array of tags and relative vertical spaces.
20398  	  * @public
20399  	  * @since 4.2.001 (2008-10-30)
20400  	  */
20401  	public function setHtmlVSpace($tagvs) {
20402  	 	 $this->tagvspaces = $tagvs;
20403  	 }
20404  
20405  	 /**
20406  	  * Set custom width for list indentation.
20407  	  * @param float $width width of the indentation. Use negative value to disable it.
20408  	  * @public
20409  	  * @since 4.2.007 (2008-11-12)
20410  	  */
20411  	public function setListIndentWidth($width) {
20412  	 	 return $this->customlistindent = floatval($width);
20413  	 }
20414  
20415  	 /**
20416  	  * Set the top/bottom cell sides to be open or closed when the cell cross the page.
20417  	  * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
20418  	  * @public
20419  	  * @since 4.2.010 (2008-11-14)
20420  	  */
20421  	public function setOpenCell($isopen) {
20422  	 	 $this->opencell = $isopen;
20423  	 }
20424  
20425  	 /**
20426  	  * Set the color and font style for HTML links.
20427  	  * @param array $color RGB array of colors
20428  	  * @param string $fontstyle additional font styles to add
20429  	  * @public
20430  	  * @since 4.4.003 (2008-12-09)
20431  	  */
20432  	public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
20433  	 	 $this->htmlLinkColorArray = $color;
20434  	 	 $this->htmlLinkFontStyle = $fontstyle;
20435  	 }
20436  
20437  	 /**
20438  	  * Convert HTML string containing value and unit of measure to user's units or points.
20439  	  * @param string $htmlval String containing values and unit.
20440  	  * @param string $refsize Reference value in points.
20441  	  * @param string $defaultunit Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
20442  	  * @param boolean $points If true returns points, otherwise returns value in user's units.
20443  	  * @return float value in user's unit or point if $points=true
20444  	  * @public
20445  	  * @since 4.4.004 (2008-12-10)
20446  	  */
20447  	public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
20448  	 	 $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
20449  	 	 $retval = 0;
20450  	 	 $value = 0;
20451  	 	 $unit = 'px';
20452  	 	 if ($points) {
20453  	 	 	 $k = 1;
20454  	 	 } else {
20455  	 	 	 $k = $this->k;
20456  	 	 }
20457  	 	 if (in_array($defaultunit, $supportedunits)) {
20458  	 	 	 $unit = $defaultunit;
20459  	 	 }
20460  	 	 if (is_numeric($htmlval)) {
20461  	 	 	 $value = floatval($htmlval);
20462  	 	 } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
20463  	 	 	 $value = floatval($mnum[1]);
20464  	 	 	 if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
20465  	 	 	 	 if (in_array($munit[1], $supportedunits)) {
20466  	 	 	 	 	 $unit = $munit[1];
20467  	 	 	 	 }
20468  	 	 	 }
20469  	 	 }
20470  	 	 switch ($unit) {
20471  	 	 	 // percentage
20472  	 	 	 case '%': {
20473  	 	 	 	 $retval = (($value * $refsize) / 100);
20474  	 	 	 	 break;
20475  	 	 	 }
20476  	 	 	 // relative-size
20477  	 	 	 case 'em': {
20478  	 	 	 	 $retval = ($value * $refsize);
20479  	 	 	 	 break;
20480  	 	 	 }
20481  	 	 	 // height of lower case 'x' (about half the font-size)
20482  	 	 	 case 'ex': {
20483  	 	 	 	 $retval = ($value * ($refsize / 2));
20484  	 	 	 	 break;
20485  	 	 	 }
20486  	 	 	 // absolute-size
20487  	 	 	 case 'in': {
20488  	 	 	 	 $retval = (($value * $this->dpi) / $k);
20489  	 	 	 	 break;
20490  	 	 	 }
20491  	 	 	 // centimeters
20492  	 	 	 case 'cm': {
20493  	 	 	 	 $retval = (($value / 2.54 * $this->dpi) / $k);
20494  	 	 	 	 break;
20495  	 	 	 }
20496  	 	 	 // millimeters
20497  	 	 	 case 'mm': {
20498  	 	 	 	 $retval = (($value / 25.4 * $this->dpi) / $k);
20499  	 	 	 	 break;
20500  	 	 	 }
20501  	 	 	 // one pica is 12 points
20502  	 	 	 case 'pc': {
20503  	 	 	 	 $retval = (($value * 12) / $k);
20504  	 	 	 	 break;
20505  	 	 	 }
20506  	 	 	 // points
20507  	 	 	 case 'pt': {
20508  	 	 	 	 $retval = ($value / $k);
20509  	 	 	 	 break;
20510  	 	 	 }
20511  	 	 	 // pixels
20512  	 	 	 case 'px': {
20513  	 	 	 	 $retval = $this->pixelsToUnits($value);
20514  	 	 	 	 if ($points) {
20515  	 	 	 	 	 $retval *= $this->k;
20516  	 	 	 	 }
20517  	 	 	 	 break;
20518  	 	 	 }
20519  	 	 }
20520  	 	 return $retval;
20521  	 }
20522  
20523  	 /**
20524  	  * Output an HTML list bullet or ordered item symbol
20525  	  * @param int $listdepth list nesting level
20526  	  * @param string $listtype type of list
20527  	  * @param float $size current font size
20528  	  * @protected
20529  	  * @since 4.4.004 (2008-12-10)
20530  	  */
20531  	protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
20532  	 	 if ($this->state != 2) {
20533  	 	 	 return;
20534  	 	 }
20535  	 	 $size /= $this->k;
20536  	 	 $fill = '';
20537  	 	 $bgcolor = $this->bgcolor;
20538  	 	 $color = $this->fgcolor;
20539  	 	 $strokecolor = $this->strokecolor;
20540  	 	 $width = 0;
20541  	 	 $textitem = '';
20542  	 	 $tmpx = $this->x;
20543  	 	 $lspace = $this->GetStringWidth('  ');
20544  	 	 if ($listtype == '^') {
20545  	 	 	 // special symbol used for avoid justification of rect bullet
20546  	 	 	 $this->lispacer = '';
20547  	 	 	 return;
20548  	 	 } elseif ($listtype == '!') {
20549  	 	 	 // set default list type for unordered list
20550  	 	 	 $deftypes = array('disc', 'circle', 'square');
20551  	 	 	 $listtype = $deftypes[($listdepth - 1) % 3];
20552  	 	 } elseif ($listtype == '#') {
20553  	 	 	 // set default list type for ordered list
20554  	 	 	 $listtype = 'decimal';
20555  	 	 } elseif (substr($listtype, 0, 4) == 'img|') {
20556  	 	 	 // custom image type ('img|type|width|height|image.ext')
20557  	 	 	 $img = explode('|', $listtype);
20558  	 	 	 $listtype = 'img';
20559  	 	 }
20560  	 	 switch ($listtype) {
20561  	 	 	 // unordered types
20562  	 	 	 case 'none': {
20563  	 	 	 	 break;
20564  	 	 	 }
20565  	 	 	 case 'disc': {
20566  	 	 	 	 $r = $size / 6;
20567  	 	 	 	 $lspace += (2 * $r);
20568  	 	 	 	 if ($this->rtl) {
20569  	 	 	 	 	 $this->x += $lspace;
20570  	 	 	 	 } else {
20571  	 	 	 	 	 $this->x -= $lspace;
20572  	 	 	 	 }
20573  	 	 	 	 $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
20574  	 	 	 	 break;
20575  	 	 	 }
20576  	 	 	 case 'circle': {
20577  	 	 	 	 $r = $size / 6;
20578  	 	 	 	 $lspace += (2 * $r);
20579  	 	 	 	 if ($this->rtl) {
20580  	 	 	 	 	 $this->x += $lspace;
20581  	 	 	 	 } else {
20582  	 	 	 	 	 $this->x -= $lspace;
20583  	 	 	 	 }
20584  	 	 	 	 $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
20585  	 	 	 	 $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
20586  	 	 	 	 $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
20587  	 	 	 	 $this->_out($prev_line_style); // restore line settings
20588  	 	 	 	 break;
20589  	 	 	 }
20590  	 	 	 case 'square': {
20591  	 	 	 	 $l = $size / 3;
20592  	 	 	 	 $lspace += $l;
20593  	 	 	 	 if ($this->rtl) {;
20594  	 	 	 	 	 $this->x += $lspace;
20595  	 	 	 	 } else {
20596  	 	 	 	 	 $this->x -= $lspace;
20597  	 	 	 	 }
20598  	 	 	 	 $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
20599  	 	 	 	 break;
20600  	 	 	 }
20601  	 	 	 case 'img': {
20602  	 	 	 	 // 1=>type, 2=>width, 3=>height, 4=>image.ext
20603  	 	 	 	 $lspace += $img[2];
20604  	 	 	 	 if ($this->rtl) {;
20605  	 	 	 	 	 $this->x += $lspace;
20606  	 	 	 	 } else {
20607  	 	 	 	 	 $this->x -= $lspace;
20608  	 	 	 	 }
20609  	 	 	 	 $imgtype = strtolower($img[1]);
20610  	 	 	 	 $prev_y = $this->y;
20611  	 	 	 	 switch ($imgtype) {
20612  	 	 	 	 	 case 'svg': {
20613  	 	 	 	 	 	 $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
20614  	 	 	 	 	 	 break;
20615  	 	 	 	 	 }
20616  	 	 	 	 	 case 'ai':
20617  	 	 	 	 	 case 'eps': {
20618  	 	 	 	 	 	 $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
20619  	 	 	 	 	 	 break;
20620  	 	 	 	 	 }
20621  	 	 	 	 	 default: {
20622  	 	 	 	 	 	 $this->Image($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], $img[1], '', 'T', false, 300, '', false, false, 0, false, false, false);
20623  	 	 	 	 	 	 break;
20624  	 	 	 	 	 }
20625  	 	 	 	 }
20626  	 	 	 	 $this->y = $prev_y;
20627  	 	 	 	 break;
20628  	 	 	 }
20629  	 	 	 // ordered types
20630  	 	 	 // $this->listcount[$this->listnum];
20631  	 	 	 // $textitem
20632  	 	 	 case '1':
20633  	 	 	 case 'decimal': {
20634  	 	 	 	 $textitem = $this->listcount[$this->listnum];
20635  	 	 	 	 break;
20636  	 	 	 }
20637  	 	 	 case 'decimal-leading-zero': {
20638  	 	 	 	 $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
20639  	 	 	 	 break;
20640  	 	 	 }
20641  	 	 	 case 'i':
20642  	 	 	 case 'lower-roman': {
20643  	 	 	 	 $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
20644  	 	 	 	 break;
20645  	 	 	 }
20646  	 	 	 case 'I':
20647  	 	 	 case 'upper-roman': {
20648  	 	 	 	 $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
20649  	 	 	 	 break;
20650  	 	 	 }
20651  	 	 	 case 'a':
20652  	 	 	 case 'lower-alpha':
20653  	 	 	 case 'lower-latin': {
20654  	 	 	 	 $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
20655  	 	 	 	 break;
20656  	 	 	 }
20657  	 	 	 case 'A':
20658  	 	 	 case 'upper-alpha':
20659  	 	 	 case 'upper-latin': {
20660  	 	 	 	 $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
20661  	 	 	 	 break;
20662  	 	 	 }
20663  	 	 	 case 'lower-greek': {
20664  	 	 	 	 $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
20665  	 	 	 	 break;
20666  	 	 	 }
20667  	 	 	 /*
20668  	 	 	 // Types to be implemented (special handling)
20669  	 	 	 case 'hebrew': {
20670  	 	 	 	 break;
20671  	 	 	 }
20672  	 	 	 case 'armenian': {
20673  	 	 	 	 break;
20674  	 	 	 }
20675  	 	 	 case 'georgian': {
20676  	 	 	 	 break;
20677  	 	 	 }
20678  	 	 	 case 'cjk-ideographic': {
20679  	 	 	 	 break;
20680  	 	 	 }
20681  	 	 	 case 'hiragana': {
20682  	 	 	 	 break;
20683  	 	 	 }
20684  	 	 	 case 'katakana': {
20685  	 	 	 	 break;
20686  	 	 	 }
20687  	 	 	 case 'hiragana-iroha': {
20688  	 	 	 	 break;
20689  	 	 	 }
20690  	 	 	 case 'katakana-iroha': {
20691  	 	 	 	 break;
20692  	 	 	 }
20693  	 	 	 */
20694  	 	 	 default: {
20695  	 	 	 	 $textitem = $this->listcount[$this->listnum];
20696  	 	 	 }
20697  	 	 }
20698  	 	 if (!TCPDF_STATIC::empty_string($textitem)) {
20699  	 	 	 // Check whether we need a new page or new column
20700  	 	 	 $prev_y = $this->y;
20701  	 	 	 $h = $this->getCellHeight($this->FontSize);
20702  	 	 	 if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
20703  	 	 	 	 $tmpx = $this->x;
20704  	 	 	 }
20705  	 	 	 // print ordered item
20706  	 	 	 if ($this->rtl) {
20707  	 	 	 	 $textitem = '.'.$textitem;
20708  	 	 	 } else {
20709  	 	 	 	 $textitem = $textitem.'.';
20710  	 	 	 }
20711  	 	 	 $lspace += $this->GetStringWidth($textitem);
20712  	 	 	 if ($this->rtl) {
20713  	 	 	 	 $this->x += $lspace;
20714  	 	 	 } else {
20715  	 	 	 	 $this->x -= $lspace;
20716  	 	 	 }
20717  	 	 	 $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
20718  	 	 }
20719  	 	 $this->x = $tmpx;
20720  	 	 $this->lispacer = '^';
20721  	 	 // restore colors
20722  	 	 $this->setFillColorArray($bgcolor);
20723  	 	 $this->setDrawColorArray($strokecolor);
20724  	 	 $this->settextColorArray($color);
20725  	 }
20726  
20727  	 /**
20728  	  * Returns current graphic variables as array.
20729  	  * @return array of graphic variables
20730  	  * @protected
20731  	  * @since 4.2.010 (2008-11-14)
20732  	  */
20733  	protected function getGraphicVars() {
20734  	 	 $grapvars = array(
20735  	 	 	 'FontFamily' => $this->FontFamily,
20736  	 	 	 'FontStyle' => $this->FontStyle,
20737  	 	 	 'FontSizePt' => $this->FontSizePt,
20738  	 	 	 'rMargin' => $this->rMargin,
20739  	 	 	 'lMargin' => $this->lMargin,
20740  	 	 	 'cell_padding' => $this->cell_padding,
20741  	 	 	 'cell_margin' => $this->cell_margin,
20742  	 	 	 'LineWidth' => $this->LineWidth,
20743  	 	 	 'linestyleWidth' => $this->linestyleWidth,
20744  	 	 	 'linestyleCap' => $this->linestyleCap,
20745  	 	 	 'linestyleJoin' => $this->linestyleJoin,
20746  	 	 	 'linestyleDash' => $this->linestyleDash,
20747  	 	 	 'textrendermode' => $this->textrendermode,
20748  	 	 	 'textstrokewidth' => $this->textstrokewidth,
20749  	 	 	 'DrawColor' => $this->DrawColor,
20750  	 	 	 'FillColor' => $this->FillColor,
20751  	 	 	 'TextColor' => $this->TextColor,
20752  	 	 	 'ColorFlag' => $this->ColorFlag,
20753  	 	 	 'bgcolor' => $this->bgcolor,
20754  	 	 	 'fgcolor' => $this->fgcolor,
20755  	 	 	 'htmlvspace' => $this->htmlvspace,
20756  	 	 	 'listindent' => $this->listindent,
20757  	 	 	 'listindentlevel' => $this->listindentlevel,
20758  	 	 	 'listnum' => $this->listnum,
20759  	 	 	 'listordered' => $this->listordered,
20760  	 	 	 'listcount' => $this->listcount,
20761  	 	 	 'lispacer' => $this->lispacer,
20762  	 	 	 'cell_height_ratio' => $this->cell_height_ratio,
20763  	 	 	 'font_stretching' => $this->font_stretching,
20764  	 	 	 'font_spacing' => $this->font_spacing,
20765  	 	 	 'alpha' => $this->alpha,
20766  	 	 	 // extended
20767  	 	 	 'lasth' => $this->lasth,
20768  	 	 	 'tMargin' => $this->tMargin,
20769  	 	 	 'bMargin' => $this->bMargin,
20770  	 	 	 'AutoPageBreak' => $this->AutoPageBreak,
20771  	 	 	 'PageBreakTrigger' => $this->PageBreakTrigger,
20772  	 	 	 'x' => $this->x,
20773  	 	 	 'y' => $this->y,
20774  	 	 	 'w' => $this->w,
20775  	 	 	 'h' => $this->h,
20776  	 	 	 'wPt' => $this->wPt,
20777  	 	 	 'hPt' => $this->hPt,
20778  	 	 	 'fwPt' => $this->fwPt,
20779  	 	 	 'fhPt' => $this->fhPt,
20780  	 	 	 'page' => $this->page,
20781  	 	 	 'current_column' => $this->current_column,
20782  	 	 	 'num_columns' => $this->num_columns
20783  	 	 	 );
20784  	 	 return $grapvars;
20785  	 }
20786  
20787  	 /**
20788  	  * Set graphic variables.
20789  	  * @param array $gvars array of graphic variablesto restore
20790  	  * @param boolean $extended if true restore extended graphic variables
20791  	  * @protected
20792  	  * @since 4.2.010 (2008-11-14)
20793  	  */
20794  	protected function setGraphicVars($gvars, $extended=false) {
20795  	 	 if ($this->state != 2) {
20796  	 	 	  return;
20797  	 	 }
20798  	 	 $this->FontFamily = $gvars['FontFamily'];
20799  	 	 $this->FontStyle = $gvars['FontStyle'];
20800  	 	 $this->FontSizePt = $gvars['FontSizePt'];
20801  	 	 $this->rMargin = $gvars['rMargin'];
20802  	 	 $this->lMargin = $gvars['lMargin'];
20803  	 	 $this->cell_padding = $gvars['cell_padding'];
20804  	 	 $this->cell_margin = $gvars['cell_margin'];
20805  	 	 $this->LineWidth = $gvars['LineWidth'];
20806  	 	 $this->linestyleWidth = $gvars['linestyleWidth'];
20807  	 	 $this->linestyleCap = $gvars['linestyleCap'];
20808  	 	 $this->linestyleJoin = $gvars['linestyleJoin'];
20809  	 	 $this->linestyleDash = $gvars['linestyleDash'];
20810  	 	 $this->textrendermode = $gvars['textrendermode'];
20811  	 	 $this->textstrokewidth = $gvars['textstrokewidth'];
20812  	 	 $this->DrawColor = $gvars['DrawColor'];
20813  	 	 $this->FillColor = $gvars['FillColor'];
20814  	 	 $this->TextColor = $gvars['TextColor'];
20815  	 	 $this->ColorFlag = $gvars['ColorFlag'];
20816  	 	 $this->bgcolor = $gvars['bgcolor'];
20817  	 	 $this->fgcolor = $gvars['fgcolor'];
20818  	 	 $this->htmlvspace = $gvars['htmlvspace'];
20819  	 	 $this->listindent = $gvars['listindent'];
20820  	 	 $this->listindentlevel = $gvars['listindentlevel'];
20821  	 	 $this->listnum = $gvars['listnum'];
20822  	 	 $this->listordered = $gvars['listordered'];
20823  	 	 $this->listcount = $gvars['listcount'];
20824  	 	 $this->lispacer = $gvars['lispacer'];
20825  	 	 $this->cell_height_ratio = $gvars['cell_height_ratio'];
20826  	 	 $this->font_stretching = $gvars['font_stretching'];
20827  	 	 $this->font_spacing = $gvars['font_spacing'];
20828  	 	 $this->alpha = $gvars['alpha'];
20829  	 	 if ($extended) {
20830  	 	 	 // restore extended values
20831  	 	 	 $this->lasth = $gvars['lasth'];
20832  	 	 	 $this->tMargin = $gvars['tMargin'];
20833  	 	 	 $this->bMargin = $gvars['bMargin'];
20834  	 	 	 $this->AutoPageBreak = $gvars['AutoPageBreak'];
20835  	 	 	 $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
20836  	 	 	 $this->x = $gvars['x'];
20837  	 	 	 $this->y = $gvars['y'];
20838  	 	 	 $this->w = $gvars['w'];
20839  	 	 	 $this->h = $gvars['h'];
20840  	 	 	 $this->wPt = $gvars['wPt'];
20841  	 	 	 $this->hPt = $gvars['hPt'];
20842  	 	 	 $this->fwPt = $gvars['fwPt'];
20843  	 	 	 $this->fhPt = $gvars['fhPt'];
20844  	 	 	 $this->page = $gvars['page'];
20845  	 	 	 $this->current_column = $gvars['current_column'];
20846  	 	 	 $this->num_columns = $gvars['num_columns'];
20847  	 	 }
20848  	 	 $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
20849  	 	 if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
20850  	 	 	 $this->setFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
20851  	 	 }
20852  	 }
20853  
20854  	 /**
20855  	  * Outputs the "save graphics state" operator 'q'
20856  	  * @protected
20857  	  */
20858  	protected function _outSaveGraphicsState() {
20859  	 	 $this->_out('q');
20860  	 }
20861  
20862  	 /**
20863  	  * Outputs the "restore graphics state" operator 'Q'
20864  	  * @protected
20865  	  */
20866  	protected function _outRestoreGraphicsState() {
20867  	 	 $this->_out('Q');
20868  	 }
20869  
20870  	 /**
20871  	  * Set buffer content (always append data).
20872  	  * @param string $data data
20873  	  * @protected
20874  	  * @since 4.5.000 (2009-01-02)
20875  	  */
20876  	protected function setBuffer($data) {
20877  	 	 $this->bufferlen += strlen($data);
20878  	 	 $this->buffer .= $data;
20879  	 }
20880  
20881  	 /**
20882  	  * Replace the buffer content
20883  	  * @param string $data data
20884  	  * @protected
20885  	  * @since 5.5.000 (2010-06-22)
20886  	  */
20887  	protected function replaceBuffer($data) {
20888  	 	 $this->bufferlen = strlen($data);
20889  	 	 $this->buffer = $data;
20890  	 }
20891  
20892  	 /**
20893  	  * Get buffer content.
20894  	  * @return string buffer content
20895  	  * @protected
20896  	  * @since 4.5.000 (2009-01-02)
20897  	  */
20898  	protected function getBuffer() {
20899  	 	 return $this->buffer;
20900  	 }
20901  
20902  	 /**
20903  	  * Set page buffer content.
20904  	  * @param int $page page number
20905  	  * @param string $data page data
20906  	  * @param boolean $append if true append data, false replace.
20907  	  * @protected
20908  	  * @since 4.5.000 (2008-12-31)
20909  	  */
20910  	protected function setPageBuffer($page, $data, $append=false) {
20911  	 	 if ($append) {
20912  	 	 	 $this->pages[$page] .= $data;
20913  	 	 } else {
20914  	 	 	 $this->pages[$page] = $data;
20915  	 	 }
20916  	 	 if ($append AND isset($this->pagelen[$page])) {
20917  	 	 	 $this->pagelen[$page] += strlen($data);
20918  	 	 } else {
20919  	 	 	 $this->pagelen[$page] = strlen($data);
20920  	 	 }
20921  	 }
20922  
20923  	 /**
20924  	  * Get page buffer content.
20925  	  * @param int $page page number
20926  	  * @return string page buffer content or false in case of error
20927  	  * @protected
20928  	  * @since 4.5.000 (2008-12-31)
20929  	  */
20930  	protected function getPageBuffer($page) {
20931  	 	 if (isset($this->pages[$page])) {
20932  	 	 	 return $this->pages[$page];
20933  	 	 }
20934  	 	 return false;
20935  	 }
20936  
20937  	 /**
20938  	  * Set image buffer content.
20939  	  * @param string $image image key
20940  	  * @param array $data image data
20941  	  * @return int image index number
20942  	  * @protected
20943  	  * @since 4.5.000 (2008-12-31)
20944  	  */
20945  	protected function setImageBuffer($image, $data) {
20946  	 	 if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
20947  	 	 	 $this->imagekeys[$this->numimages] = $image;
20948  	 	 	 $data['i'] = $this->numimages;
20949  	 	 	 ++$this->numimages;
20950  	 	 }
20951  	 	 $this->images[$image] = $data;
20952  	 	 return $data['i'];
20953  	 }
20954  
20955  	 /**
20956  	  * Set image buffer content for a specified sub-key.
20957  	  * @param string $image image key
20958  	  * @param string $key image sub-key
20959  	  * @param array $data image data
20960  	  * @protected
20961  	  * @since 4.5.000 (2008-12-31)
20962  	  */
20963  	protected function setImageSubBuffer($image, $key, $data) {
20964  	 	 if (!isset($this->images[$image])) {
20965  	 	 	 $this->setImageBuffer($image, array());
20966  	 	 }
20967  	 	 $this->images[$image][$key] = $data;
20968  	 }
20969  
20970  	 /**
20971  	  * Get image buffer content.
20972  	  * @param string $image image key
20973  	  * @return string|false image buffer content or false in case of error
20974  	  * @protected
20975  	  * @since 4.5.000 (2008-12-31)
20976  	  */
20977  	protected function getImageBuffer($image) {
20978  	 	 if (isset($this->images[$image])) {
20979  	 	 	 return $this->images[$image];
20980  	 	 }
20981  	 	 return false;
20982  	 }
20983  
20984  	 /**
20985  	  * Set font buffer content.
20986  	  * @param string $font font key
20987  	  * @param array $data font data
20988  	  * @protected
20989  	  * @since 4.5.000 (2009-01-02)
20990  	  */
20991  	protected function setFontBuffer($font, $data) {
20992  	 	 $this->fonts[$font] = $data;
20993  	 	 if (!in_array($font, $this->fontkeys)) {
20994  	 	 	 $this->fontkeys[] = $font;
20995  	 	 	 // store object ID for current font
20996  	 	 	 ++$this->n;
20997  	 	 	 $this->font_obj_ids[$font] = $this->n;
20998  	 	 	 $this->setFontSubBuffer($font, 'n', $this->n);
20999  	 	 }
21000  	 }
21001  
21002  	 /**
21003  	  * Set font buffer content.
21004  	  * @param string $font font key
21005  	  * @param string $key font sub-key
21006  	  * @param mixed $data font data
21007  	  * @protected
21008  	  * @since 4.5.000 (2009-01-02)
21009  	  */
21010  	protected function setFontSubBuffer($font, $key, $data) {
21011  	 	 if (!isset($this->fonts[$font])) {
21012  	 	 	 $this->setFontBuffer($font, array());
21013  	 	 }
21014  	 	 $this->fonts[$font][$key] = $data;
21015  	 }
21016  
21017  	 /**
21018  	  * Get font buffer content.
21019  	  * @param string $font font key
21020  	  * @return string|false font buffer content or false in case of error
21021  	  * @protected
21022  	  * @since 4.5.000 (2009-01-02)
21023  	  */
21024  	protected function getFontBuffer($font) {
21025  	 	 if (isset($this->fonts[$font])) {
21026  	 	 	 return $this->fonts[$font];
21027  	 	 }
21028  	 	 return false;
21029  	 }
21030  
21031  	 /**
21032  	  * Move a page to a previous position.
21033  	  * @param int $frompage number of the source page
21034  	  * @param int $topage number of the destination page (must be less than $frompage)
21035  	  * @return bool true in case of success, false in case of error.
21036  	  * @public
21037  	  * @since 4.5.000 (2009-01-02)
21038  	  */
21039  	public function movePage($frompage, $topage) {
21040  	 	 if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
21041  	 	 	 return false;
21042  	 	 }
21043  	 	 if ($frompage == $this->page) {
21044  	 	 	 // close the page before moving it
21045  	 	 	 $this->endPage();
21046  	 	 }
21047  	 	 // move all page-related states
21048  	 	 $tmppage = $this->getPageBuffer($frompage);
21049  	 	 $tmppagedim = $this->pagedim[$frompage];
21050  	 	 $tmppagelen = $this->pagelen[$frompage];
21051  	 	 $tmpintmrk = $this->intmrk[$frompage];
21052  	 	 $tmpbordermrk = $this->bordermrk[$frompage];
21053  	 	 $tmpcntmrk = $this->cntmrk[$frompage];
21054  	 	 $tmppageobjects = $this->pageobjects[$frompage];
21055  	 	 if (isset($this->footerpos[$frompage])) {
21056  	 	 	 $tmpfooterpos = $this->footerpos[$frompage];
21057  	 	 }
21058  	 	 if (isset($this->footerlen[$frompage])) {
21059  	 	 	 $tmpfooterlen = $this->footerlen[$frompage];
21060  	 	 }
21061  	 	 if (isset($this->transfmrk[$frompage])) {
21062  	 	 	 $tmptransfmrk = $this->transfmrk[$frompage];
21063  	 	 }
21064  	 	 if (isset($this->PageAnnots[$frompage])) {
21065  	 	 	 $tmpannots = $this->PageAnnots[$frompage];
21066  	 	 }
21067  	 	 if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
21068  	 	 	 for ($i = $frompage; $i > $topage; --$i) {
21069  	 	 	 	 if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
21070  	 	 	 	 	 --$this->pagegroups[$this->newpagegroup[$i]];
21071  	 	 	 	 	 break;
21072  	 	 	 	 }
21073  	 	 	 }
21074  	 	 	 for ($i = $topage; $i > 0; --$i) {
21075  	 	 	 	 if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
21076  	 	 	 	 	 ++$this->pagegroups[$this->newpagegroup[$i]];
21077  	 	 	 	 	 break;
21078  	 	 	 	 }
21079  	 	 	 }
21080  	 	 }
21081  	 	 for ($i = $frompage; $i > $topage; --$i) {
21082  	 	 	 $j = $i - 1;
21083  	 	 	 // shift pages down
21084  	 	 	 $this->setPageBuffer($i, $this->getPageBuffer($j));
21085  	 	 	 $this->pagedim[$i] = $this->pagedim[$j];
21086  	 	 	 $this->pagelen[$i] = $this->pagelen[$j];
21087  	 	 	 $this->intmrk[$i] = $this->intmrk[$j];
21088  	 	 	 $this->bordermrk[$i] = $this->bordermrk[$j];
21089  	 	 	 $this->cntmrk[$i] = $this->cntmrk[$j];
21090  	 	 	 $this->pageobjects[$i] = $this->pageobjects[$j];
21091  	 	 	 if (isset($this->footerpos[$j])) {
21092  	 	 	 	 $this->footerpos[$i] = $this->footerpos[$j];
21093  	 	 	 } elseif (isset($this->footerpos[$i])) {
21094  	 	 	 	 unset($this->footerpos[$i]);
21095  	 	 	 }
21096  	 	 	 if (isset($this->footerlen[$j])) {
21097  	 	 	 	 $this->footerlen[$i] = $this->footerlen[$j];
21098  	 	 	 } elseif (isset($this->footerlen[$i])) {
21099  	 	 	 	 unset($this->footerlen[$i]);
21100  	 	 	 }
21101  	 	 	 if (isset($this->transfmrk[$j])) {
21102  	 	 	 	 $this->transfmrk[$i] = $this->transfmrk[$j];
21103  	 	 	 } elseif (isset($this->transfmrk[$i])) {
21104  	 	 	 	 unset($this->transfmrk[$i]);
21105  	 	 	 }
21106  	 	 	 if (isset($this->PageAnnots[$j])) {
21107  	 	 	 	 $this->PageAnnots[$i] = $this->PageAnnots[$j];
21108  	 	 	 } elseif (isset($this->PageAnnots[$i])) {
21109  	 	 	 	 unset($this->PageAnnots[$i]);
21110  	 	 	 }
21111  	 	 	 if (isset($this->newpagegroup[$j])) {
21112  	 	 	 	 $this->newpagegroup[$i] = $this->newpagegroup[$j];
21113  	 	 	 	 unset($this->newpagegroup[$j]);
21114  	 	 	 }
21115  	 	 	 if ($this->currpagegroup == $j) {
21116  	 	 	 	 $this->currpagegroup = $i;
21117  	 	 	 }
21118  	 	 }
21119  	 	 $this->setPageBuffer($topage, $tmppage);
21120  	 	 $this->pagedim[$topage] = $tmppagedim;
21121  	 	 $this->pagelen[$topage] = $tmppagelen;
21122  	 	 $this->intmrk[$topage] = $tmpintmrk;
21123  	 	 $this->bordermrk[$topage] = $tmpbordermrk;
21124  	 	 $this->cntmrk[$topage] = $tmpcntmrk;
21125  	 	 $this->pageobjects[$topage] = $tmppageobjects;
21126  	 	 if (isset($tmpfooterpos)) {
21127  	 	 	 $this->footerpos[$topage] = $tmpfooterpos;
21128  	 	 } elseif (isset($this->footerpos[$topage])) {
21129  	 	 	 unset($this->footerpos[$topage]);
21130  	 	 }
21131  	 	 if (isset($tmpfooterlen)) {
21132  	 	 	 $this->footerlen[$topage] = $tmpfooterlen;
21133  	 	 } elseif (isset($this->footerlen[$topage])) {
21134  	 	 	 unset($this->footerlen[$topage]);
21135  	 	 }
21136  	 	 if (isset($tmptransfmrk)) {
21137  	 	 	 $this->transfmrk[$topage] = $tmptransfmrk;
21138  	 	 } elseif (isset($this->transfmrk[$topage])) {
21139  	 	 	 unset($this->transfmrk[$topage]);
21140  	 	 }
21141  	 	 if (isset($tmpannots)) {
21142  	 	 	 $this->PageAnnots[$topage] = $tmpannots;
21143  	 	 } elseif (isset($this->PageAnnots[$topage])) {
21144  	 	 	 unset($this->PageAnnots[$topage]);
21145  	 	 }
21146  	 	 // adjust outlines
21147  	 	 $tmpoutlines = $this->outlines;
21148  	 	 foreach ($tmpoutlines as $key => $outline) {
21149  	 	 	 if (!$outline['f']) {
21150  	 	 	 	 if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
21151  	 	 	 	 	 $this->outlines[$key]['p'] = ($outline['p'] + 1);
21152  	 	 	 	 } elseif ($outline['p'] == $frompage) {
21153  	 	 	 	 	 $this->outlines[$key]['p'] = $topage;
21154  	 	 	 	 }
21155  	 	 	 }
21156  	 	 }
21157  	 	 // adjust dests
21158  	 	 $tmpdests = $this->dests;
21159  	 	 foreach ($tmpdests as $key => $dest) {
21160  	 	 	 if (!$dest['f']) {
21161  	 	 	 	 if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
21162  	 	 	 	 	 $this->dests[$key]['p'] = ($dest['p'] + 1);
21163  	 	 	 	 } elseif ($dest['p'] == $frompage) {
21164  	 	 	 	 	 $this->dests[$key]['p'] = $topage;
21165  	 	 	 	 }
21166  	 	 	 }
21167  	 	 }
21168  	 	 // adjust links
21169  	 	 $tmplinks = $this->links;
21170  	 	 foreach ($tmplinks as $key => $link) {
21171  	 	 	 if (!$link['f']) {
21172  	 	 	 	 if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
21173  	 	 	 	 	 $this->links[$key]['p'] = ($link['p'] + 1);
21174  	 	 	 	 } elseif ($link['p'] == $frompage) {
21175  	 	 	 	 	 $this->links[$key]['p'] = $topage;
21176  	 	 	 	 }
21177  	 	 	 }
21178  	 	 }
21179  	 	 // adjust javascript
21180  	 	 $jfrompage = $frompage;
21181  	 	 $jtopage = $topage;
21182  	 	 if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
21183  	 	 	 foreach($pamatch[0] as $pk => $pmatch) {
21184  	 	 	 	 $pagenum = intval($pamatch[3][$pk]) + 1;
21185  	 	 	 	 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
21186  	 	 	 	 	 $newpage = ($pagenum + 1);
21187  	 	 	 	 } elseif ($pagenum == $jfrompage) {
21188  	 	 	 	 	 $newpage = $jtopage;
21189  	 	 	 	 } else {
21190  	 	 	 	 	 $newpage = $pagenum;
21191  	 	 	 	 }
21192  	 	 	 	 --$newpage;
21193  	 	 	 	 $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
21194  	 	 	 	 $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
21195  	 	 	 }
21196  	 	 	 unset($pamatch);
21197  	 	 }
21198  	 	 // return to last page
21199  	 	 $this->lastPage(true);
21200  	 	 return true;
21201  	 }
21202  
21203  	 /**
21204  	  * Remove the specified page.
21205  	  * @param int $page page to remove
21206  	  * @return bool true in case of success, false in case of error.
21207  	  * @public
21208  	  * @since 4.6.004 (2009-04-23)
21209  	  */
21210  	public function deletePage($page) {
21211  	 	 if (($page < 1) OR ($page > $this->numpages)) {
21212  	 	 	 return false;
21213  	 	 }
21214  	 	 // delete current page
21215  	 	 unset($this->pages[$page]);
21216  	 	 unset($this->pagedim[$page]);
21217  	 	 unset($this->pagelen[$page]);
21218  	 	 unset($this->intmrk[$page]);
21219  	 	 unset($this->bordermrk[$page]);
21220  	 	 unset($this->cntmrk[$page]);
21221  	 	 foreach ($this->pageobjects[$page] as $oid) {
21222  	 	 	 if (isset($this->offsets[$oid])){
21223  	 	 	 	 unset($this->offsets[$oid]);
21224  	 	 	 }
21225  	 	 }
21226  	 	 unset($this->pageobjects[$page]);
21227  	 	 if (isset($this->footerpos[$page])) {
21228  	 	 	 unset($this->footerpos[$page]);
21229  	 	 }
21230  	 	 if (isset($this->footerlen[$page])) {
21231  	 	 	 unset($this->footerlen[$page]);
21232  	 	 }
21233  	 	 if (isset($this->transfmrk[$page])) {
21234  	 	 	 unset($this->transfmrk[$page]);
21235  	 	 }
21236  	 	 if (isset($this->PageAnnots[$page])) {
21237  	 	 	 unset($this->PageAnnots[$page]);
21238  	 	 }
21239  	 	 if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
21240  	 	 	 for ($i = $page; $i > 0; --$i) {
21241  	 	 	 	 if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
21242  	 	 	 	 	 --$this->pagegroups[$this->newpagegroup[$i]];
21243  	 	 	 	 	 break;
21244  	 	 	 	 }
21245  	 	 	 }
21246  	 	 }
21247  	 	 if (isset($this->pageopen[$page])) {
21248  	 	 	 unset($this->pageopen[$page]);
21249  	 	 }
21250  	 	 if ($page < $this->numpages) {
21251  	 	 	 // update remaining pages
21252  	 	 	 for ($i = $page; $i < $this->numpages; ++$i) {
21253  	 	 	 	 $j = $i + 1;
21254  	 	 	 	 // shift pages
21255  	 	 	 	 $this->setPageBuffer($i, $this->getPageBuffer($j));
21256  	 	 	 	 $this->pagedim[$i] = $this->pagedim[$j];
21257  	 	 	 	 $this->pagelen[$i] = $this->pagelen[$j];
21258  	 	 	 	 $this->intmrk[$i] = $this->intmrk[$j];
21259  	 	 	 	 $this->bordermrk[$i] = $this->bordermrk[$j];
21260  	 	 	 	 $this->cntmrk[$i] = $this->cntmrk[$j];
21261  	 	 	 	 $this->pageobjects[$i] = $this->pageobjects[$j];
21262  	 	 	 	 if (isset($this->footerpos[$j])) {
21263  	 	 	 	 	 $this->footerpos[$i] = $this->footerpos[$j];
21264  	 	 	 	 } elseif (isset($this->footerpos[$i])) {
21265  	 	 	 	 	 unset($this->footerpos[$i]);
21266  	 	 	 	 }
21267  	 	 	 	 if (isset($this->footerlen[$j])) {
21268  	 	 	 	 	 $this->footerlen[$i] = $this->footerlen[$j];
21269  	 	 	 	 } elseif (isset($this->footerlen[$i])) {
21270  	 	 	 	 	 unset($this->footerlen[$i]);
21271  	 	 	 	 }
21272  	 	 	 	 if (isset($this->transfmrk[$j])) {
21273  	 	 	 	 	 $this->transfmrk[$i] = $this->transfmrk[$j];
21274  	 	 	 	 } elseif (isset($this->transfmrk[$i])) {
21275  	 	 	 	 	 unset($this->transfmrk[$i]);
21276  	 	 	 	 }
21277  	 	 	 	 if (isset($this->PageAnnots[$j])) {
21278  	 	 	 	 	 $this->PageAnnots[$i] = $this->PageAnnots[$j];
21279  	 	 	 	 } elseif (isset($this->PageAnnots[$i])) {
21280  	 	 	 	 	 unset($this->PageAnnots[$i]);
21281  	 	 	 	 }
21282  	 	 	 	 if (isset($this->newpagegroup[$j])) {
21283  	 	 	 	 	 $this->newpagegroup[$i] = $this->newpagegroup[$j];
21284  	 	 	 	 	 unset($this->newpagegroup[$j]);
21285  	 	 	 	 }
21286  	 	 	 	 if ($this->currpagegroup == $j) {
21287  	 	 	 	 	 $this->currpagegroup = $i;
21288  	 	 	 	 }
21289  	 	 	 	 if (isset($this->pageopen[$j])) {
21290  	 	 	 	 	 $this->pageopen[$i] = $this->pageopen[$j];
21291  	 	 	 	 } elseif (isset($this->pageopen[$i])) {
21292  	 	 	 	 	 unset($this->pageopen[$i]);
21293  	 	 	 	 }
21294  	 	 	 }
21295  	 	 	 // remove last page
21296  	 	 	 unset($this->pages[$this->numpages]);
21297  	 	 	 unset($this->pagedim[$this->numpages]);
21298  	 	 	 unset($this->pagelen[$this->numpages]);
21299  	 	 	 unset($this->intmrk[$this->numpages]);
21300  	 	 	 unset($this->bordermrk[$this->numpages]);
21301  	 	 	 unset($this->cntmrk[$this->numpages]);
21302  	 	 	 foreach ($this->pageobjects[$this->numpages] as $oid) {
21303  	 	 	 	 if (isset($this->offsets[$oid])){
21304  	 	 	 	 	 unset($this->offsets[$oid]);
21305  	 	 	 	 }
21306  	 	 	 }
21307  	 	 	 unset($this->pageobjects[$this->numpages]);
21308  	 	 	 if (isset($this->footerpos[$this->numpages])) {
21309  	 	 	 	 unset($this->footerpos[$this->numpages]);
21310  	 	 	 }
21311  	 	 	 if (isset($this->footerlen[$this->numpages])) {
21312  	 	 	 	 unset($this->footerlen[$this->numpages]);
21313  	 	 	 }
21314  	 	 	 if (isset($this->transfmrk[$this->numpages])) {
21315  	 	 	 	 unset($this->transfmrk[$this->numpages]);
21316  	 	 	 }
21317  	 	 	 if (isset($this->PageAnnots[$this->numpages])) {
21318  	 	 	 	 unset($this->PageAnnots[$this->numpages]);
21319  	 	 	 }
21320  	 	 	 if (isset($this->newpagegroup[$this->numpages])) {
21321  	 	 	 	 unset($this->newpagegroup[$this->numpages]);
21322  	 	 	 }
21323  	 	 	 if ($this->currpagegroup == $this->numpages) {
21324  	 	 	 	 $this->currpagegroup = ($this->numpages - 1);
21325  	 	 	 }
21326  	 	 	 if (isset($this->pagegroups[$this->numpages])) {
21327  	 	 	 	 unset($this->pagegroups[$this->numpages]);
21328  	 	 	 }
21329  	 	 	 if (isset($this->pageopen[$this->numpages])) {
21330  	 	 	 	 unset($this->pageopen[$this->numpages]);
21331  	 	 	 }
21332  	 	 }
21333  	 	 --$this->numpages;
21334  	 	 $this->page = $this->numpages;
21335  	 	 // adjust outlines
21336  	 	 $tmpoutlines = $this->outlines;
21337  	 	 foreach ($tmpoutlines as $key => $outline) {
21338  	 	 	 if (!$outline['f']) {
21339  	 	 	 	 if ($outline['p'] > $page) {
21340  	 	 	 	 	 $this->outlines[$key]['p'] = $outline['p'] - 1;
21341  	 	 	 	 } elseif ($outline['p'] == $page) {
21342  	 	 	 	 	 unset($this->outlines[$key]);
21343  	 	 	 	 }
21344  	 	 	 }
21345  	 	 }
21346  	 	 // adjust dests
21347  	 	 $tmpdests = $this->dests;
21348  	 	 foreach ($tmpdests as $key => $dest) {
21349  	 	 	 if (!$dest['f']) {
21350  	 	 	 	 if ($dest['p'] > $page) {
21351  	 	 	 	 	 $this->dests[$key]['p'] = $dest['p'] - 1;
21352  	 	 	 	 } elseif ($dest['p'] == $page) {
21353  	 	 	 	 	 unset($this->dests[$key]);
21354  	 	 	 	 }
21355  	 	 	 }
21356  	 	 }
21357  	 	 // adjust links
21358  	 	 $tmplinks = $this->links;
21359  	 	 foreach ($tmplinks as $key => $link) {
21360  	 	 	 if (!$link['f']) {
21361  	 	 	 	 if ($link['p'] > $page) {
21362  	 	 	 	 	 $this->links[$key]['p'] = $link['p'] - 1;
21363  	 	 	 	 } elseif ($link['p'] == $page) {
21364  	 	 	 	 	 unset($this->links[$key]);
21365  	 	 	 	 }
21366  	 	 	 }
21367  	 	 }
21368  	 	 // adjust javascript
21369  	 	 $jpage = $page;
21370  	 	 if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript, $pamatch) > 0) {
21371  	 	 	 foreach($pamatch[0] as $pk => $pmatch) {
21372  	 	 	 	 $pagenum = intval($pamatch[3][$pk]) + 1;
21373  	 	 	 	 if ($pagenum >= $jpage) {
21374  	 	 	 	 	 $newpage = ($pagenum - 1);
21375  	 	 	 	 } elseif ($pagenum == $jpage) {
21376  	 	 	 	 	 $newpage = 1;
21377  	 	 	 	 } else {
21378  	 	 	 	 	 $newpage = $pagenum;
21379  	 	 	 	 }
21380  	 	 	 	 --$newpage;
21381  	 	 	 	 $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
21382  	 	 	 	 $this->javascript = str_replace($pmatch, $newjs, $this->javascript);
21383  	 	 	 }
21384  	 	 	 unset($pamatch);
21385  	 	 }
21386  	 	 // return to last page
21387  	 	 if ($this->numpages > 0) {
21388  	 	 	 $this->lastPage(true);
21389  	 	 }
21390  	 	 return true;
21391  	 }
21392  
21393  	 /**
21394  	  * Clone the specified page to a new page.
21395  	  * @param int $page number of page to copy (0 = current page)
21396  	  * @return bool true in case of success, false in case of error.
21397  	  * @public
21398  	  * @since 4.9.015 (2010-04-20)
21399  	  */
21400  	public function copyPage($page=0) {
21401  	 	 if ($page == 0) {
21402  	 	 	 // default value
21403  	 	 	 $page = $this->page;
21404  	 	 }
21405  	 	 if (($page < 1) OR ($page > $this->numpages)) {
21406  	 	 	 return false;
21407  	 	 }
21408  	 	 // close the last page
21409  	 	 $this->endPage();
21410  	 	 // copy all page-related states
21411  	 	 ++$this->numpages;
21412  	 	 $this->page = $this->numpages;
21413  	 	 $this->setPageBuffer($this->page, $this->getPageBuffer($page));
21414  	 	 $this->pagedim[$this->page] = $this->pagedim[$page];
21415  	 	 $this->pagelen[$this->page] = $this->pagelen[$page];
21416  	 	 $this->intmrk[$this->page] = $this->intmrk[$page];
21417  	 	 $this->bordermrk[$this->page] = $this->bordermrk[$page];
21418  	 	 $this->cntmrk[$this->page] = $this->cntmrk[$page];
21419  	 	 $this->pageobjects[$this->page] = $this->pageobjects[$page];
21420  	 	 $this->pageopen[$this->page] = false;
21421  	 	 if (isset($this->footerpos[$page])) {
21422  	 	 	 $this->footerpos[$this->page] = $this->footerpos[$page];
21423  	 	 }
21424  	 	 if (isset($this->footerlen[$page])) {
21425  	 	 	 $this->footerlen[$this->page] = $this->footerlen[$page];
21426  	 	 }
21427  	 	 if (isset($this->transfmrk[$page])) {
21428  	 	 	 $this->transfmrk[$this->page] = $this->transfmrk[$page];
21429  	 	 }
21430  	 	 if (isset($this->PageAnnots[$page])) {
21431  	 	 	 $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
21432  	 	 }
21433  	 	 if (isset($this->newpagegroup[$page])) {
21434  	 	 	 // start a new group
21435  	 	 	 $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
21436  	 	 	 $this->currpagegroup = $this->newpagegroup[$this->page];
21437  	 	 	 $this->pagegroups[$this->currpagegroup] = 1;
21438  	 	 } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
21439  	 	 	 ++$this->pagegroups[$this->currpagegroup];
21440  	 	 }
21441  	 	 // copy outlines
21442  	 	 $tmpoutlines = $this->outlines;
21443  	 	 foreach ($tmpoutlines as $key => $outline) {
21444  	 	 	 if ($outline['p'] == $page) {
21445  	 	 	 	 $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']);
21446  	 	 	 }
21447  	 	 }
21448  	 	 // copy links
21449  	 	 $tmplinks = $this->links;
21450  	 	 foreach ($tmplinks as $key => $link) {
21451  	 	 	 if ($link['p'] == $page) {
21452  	 	 	 	 $this->links[] = array('p' => $this->page, 'y' => $link['y'], 'f' => $link['f']);
21453  	 	 	 }
21454  	 	 }
21455  	 	 // return to last page
21456  	 	 $this->lastPage(true);
21457  	 	 return true;
21458  	 }
21459  
21460  	 /**
21461  	  * Output a Table of Content Index (TOC).
21462  	  * This method must be called after all Bookmarks were set.
21463  	  * Before calling this method you have to open the page using the addTOCPage() method.
21464  	  * After calling this method you have to call endTOCPage() to close the TOC page.
21465  	  * You can override this method to achieve different styles.
21466  	  * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
21467  	  * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
21468  	  * @param string $filler string used to fill the space between text and page number.
21469  	  * @param string $toc_name name to use for TOC bookmark.
21470  	  * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
21471  	  * @param array $color RGB color array for bookmark title (values from 0 to 255).
21472  	  * @public
21473  	  * @author Nicola Asuni
21474  	  * @since 4.5.000 (2009-01-02)
21475  	  * @see addTOCPage(), endTOCPage(), addHTMLTOC()
21476  	  */
21477  	public function addTOC($page=null, $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
21478  	 	 $fontsize = $this->FontSizePt;
21479  	 	 $fontfamily = $this->FontFamily;
21480  	 	 $fontstyle = $this->FontStyle;
21481  	 	 $w = $this->w - $this->lMargin - $this->rMargin;
21482  	 	 $spacer = $this->GetStringWidth(chr(32)) * 4;
21483  	 	 $lmargin = $this->lMargin;
21484  	 	 $rmargin = $this->rMargin;
21485  	 	 $x_start = $this->GetX();
21486  	 	 $page_first = $this->page;
21487  	 	 $current_page = $this->page;
21488  	 	 $page_fill_start = false;
21489  	 	 $page_fill_end = false;
21490  	 	 $current_column = $this->current_column;
21491  	 	 if (TCPDF_STATIC::empty_string($numbersfont)) {
21492  	 	 	 $numbersfont = $this->default_monospaced_font;
21493  	 	 }
21494  	 	 if (TCPDF_STATIC::empty_string($filler)) {
21495  	 	 	 $filler = ' ';
21496  	 	 }
21497  	 	 if (TCPDF_STATIC::empty_string($page)) {
21498  	 	 	 $gap = ' ';
21499  	 	 } else {
21500  	 	 	 $gap = '';
21501  	 	 	 if ($page < 1) {
21502  	 	 	 	 $page = 1;
21503  	 	 	 }
21504  	 	 }
21505  	 	 $this->setFont($numbersfont, $fontstyle, $fontsize);
21506  	 	 $numwidth = $this->GetStringWidth('00000');
21507  	 	 $maxpage = 0; //used for pages on attached documents
21508  	 	 foreach ($this->outlines as $key => $outline) {
21509  	 	 	 // check for extra pages (used for attachments)
21510  	 	 	 if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
21511  	 	 	 	 $outline['p'] += ($this->page - $page_first);
21512  	 	 	 }
21513  	 	 	 if ($this->rtl) {
21514  	 	 	 	 $aligntext = 'R';
21515  	 	 	 	 $alignnum = 'L';
21516  	 	 	 } else {
21517  	 	 	 	 $aligntext = 'L';
21518  	 	 	 	 $alignnum = 'R';
21519  	 	 	 }
21520  	 	 	 if ($outline['l'] == 0) {
21521  	 	 	 	 $this->setFont($fontfamily, $outline['s'].'B', $fontsize);
21522  	 	 	 } else {
21523  	 	 	 	 $this->setFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
21524  	 	 	 }
21525  	 	 	 $this->setTextColorArray($outline['c']);
21526  	 	 	 // check for page break
21527  	 	 	 $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize));
21528  	 	 	 // set margins and X position
21529  	 	 	 if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
21530  	 	 	 	 $this->lMargin = $lmargin;
21531  	 	 	 	 $this->rMargin = $rmargin;
21532  	 	 	 } else {
21533  	 	 	 	 if ($this->current_column != $current_column) {
21534  	 	 	 	 	 if ($this->rtl) {
21535  	 	 	 	 	 	 $x_start = $this->w - $this->columns[$this->current_column]['x'];
21536  	 	 	 	 	 } else {
21537  	 	 	 	 	 	 $x_start = $this->columns[$this->current_column]['x'];
21538  	 	 	 	 	 }
21539  	 	 	 	 }
21540  	 	 	 	 $lmargin = $this->lMargin;
21541  	 	 	 	 $rmargin = $this->rMargin;
21542  	 	 	 	 $current_page = $this->page;
21543  	 	 	 	 $current_column = $this->current_column;
21544  	 	 	 }
21545  	 	 	 $this->setX($x_start);
21546  	 	 	 $indent = ($spacer * $outline['l']);
21547  	 	 	 if ($this->rtl) {
21548  	 	 	 	 $this->x -= $indent;
21549  	 	 	 	 $this->rMargin = $this->w - $this->x;
21550  	 	 	 } else {
21551  	 	 	 	 $this->x += $indent;
21552  	 	 	 	 $this->lMargin = $this->x;
21553  	 	 	 }
21554  	 	 	 $link = $this->AddLink();
21555  	 	 	 $this->setLink($link, $outline['y'], $outline['p']);
21556  	 	 	 // write the text
21557  	 	 	 if ($this->rtl) {
21558  	 	 	 	 $txt = ' '.$outline['t'];
21559  	 	 	 } else {
21560  	 	 	 	 $txt = $outline['t'].' ';
21561  	 	 	 }
21562  	 	 	 $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
21563  	 	 	 if ($this->rtl) {
21564  	 	 	 	 $tw = $this->x - $this->lMargin;
21565  	 	 	 } else {
21566  	 	 	 	 $tw = $this->w - $this->rMargin - $this->x;
21567  	 	 	 }
21568  	 	 	 $this->setFont($numbersfont, $fontstyle, $fontsize);
21569  	 	 	 if (TCPDF_STATIC::empty_string($page)) {
21570  	 	 	 	 $pagenum = $outline['p'];
21571  	 	 	 } else {
21572  	 	 	 	 // placemark to be replaced with the correct number
21573  	 	 	 	 $pagenum = '{#'.($outline['p']).'}';
21574  	 	 	 	 if ($this->isUnicodeFont()) {
21575  	 	 	 	 	 $pagenum = '{'.$pagenum.'}';
21576  	 	 	 	 }
21577  	 	 	 	 $maxpage = max($maxpage, $outline['p']);
21578  	 	 	 }
21579  	 	 	 $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
21580  	 	 	 $wfiller = $this->GetStringWidth($filler);
21581  	 	 	 if ($wfiller > 0) {
21582  	 	 	 	 $numfills = floor($fw / $wfiller);
21583  	 	 	 } else {
21584  	 	 	 	 $numfills = 0;
21585  	 	 	 }
21586  	 	 	 if ($numfills > 0) {
21587  	 	 	 	 $rowfill = str_repeat($filler, $numfills);
21588  	 	 	 } else {
21589  	 	 	 	 $rowfill = '';
21590  	 	 	 }
21591  	 	 	 if ($this->rtl) {
21592  	 	 	 	 $pagenum = $pagenum.$gap.$rowfill;
21593  	 	 	 } else {
21594  	 	 	 	 $pagenum = $rowfill.$gap.$pagenum;
21595  	 	 	 }
21596  	 	 	 // write the number
21597  	 	 	 $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
21598  	 	 }
21599  	 	 $page_last = $this->getPage();
21600  	 	 $numpages = ($page_last - $page_first + 1);
21601  	 	 // account for booklet mode
21602  	 	 if ($this->booklet) {
21603  	 	 	 // check if a blank page is required before TOC
21604  	 	 	 $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
21605  	 	 	 $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
21606  	 	 	 if ($page_fill_start) {
21607  	 	 	 	 // add a page at the end (to be moved before TOC)
21608  	 	 	 	 $this->addPage();
21609  	 	 	 	 ++$page_last;
21610  	 	 	 	 ++$numpages;
21611  	 	 	 }
21612  	 	 	 if ($page_fill_end) {
21613  	 	 	 	 // add a page at the end
21614  	 	 	 	 $this->addPage();
21615  	 	 	 	 ++$page_last;
21616  	 	 	 	 ++$numpages;
21617  	 	 	 }
21618  	 	 }
21619  	 	 $maxpage = max($maxpage, $page_last);
21620  	 	 if (!TCPDF_STATIC::empty_string($page)) {
21621  	 	 	 for ($p = $page_first; $p <= $page_last; ++$p) {
21622  	 	 	 	 // get page data
21623  	 	 	 	 $temppage = $this->getPageBuffer($p);
21624  	 	 	 	 for ($n = 1; $n <= $maxpage; ++$n) {
21625  	 	 	 	 	 // update page numbers
21626  	 	 	 	 	 $a = '{#'.$n.'}';
21627  	 	 	 	 	 // get page number aliases
21628  	 	 	 	 	 $pnalias = $this->getInternalPageNumberAliases($a);
21629  	 	 	 	 	 // calculate replacement number
21630  	 	 	 	 	 if (($n >= $page) AND ($n <= $this->numpages)) {
21631  	 	 	 	 	 	 $np = $n + $numpages;
21632  	 	 	 	 	 } else {
21633  	 	 	 	 	 	 $np = $n;
21634  	 	 	 	 	 }
21635  	 	 	 	 	 $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
21636  	 	 	 	 	 $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
21637  	 	 	 	 	 // replace aliases with numbers
21638  	 	 	 	 	 foreach ($pnalias['u'] as $u) {
21639  	 	 	 	 	 	 $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
21640  	 	 	 	 	 	 if ($this->rtl) {
21641  	 	 	 	 	 	 	 $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
21642  	 	 	 	 	 	 } else {
21643  	 	 	 	 	 	 	 $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
21644  	 	 	 	 	 	 }
21645  	 	 	 	 	 	 $temppage = str_replace($u, $nr, $temppage);
21646  	 	 	 	 	 }
21647  	 	 	 	 	 foreach ($pnalias['a'] as $a) {
21648  	 	 	 	 	 	 $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
21649  	 	 	 	 	 	 if ($this->rtl) {
21650  	 	 	 	 	 	 	 $nr = $na.' '.$sfill;
21651  	 	 	 	 	 	 } else {
21652  	 	 	 	 	 	 	 $nr = $sfill.' '.$na;
21653  	 	 	 	 	 	 }
21654  	 	 	 	 	 	 $temppage = str_replace($a, $nr, $temppage);
21655  	 	 	 	 	 }
21656  	 	 	 	 }
21657  	 	 	 	 // save changes
21658  	 	 	 	 $this->setPageBuffer($p, $temppage);
21659  	 	 	 }
21660  	 	 	 // move pages
21661  	 	 	 $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
21662  	 	 	 if ($page_fill_start) {
21663  	 	 	 	 $this->movePage($page_last, $page_first);
21664  	 	 	 }
21665  	 	 	 for ($i = 0; $i < $numpages; ++$i) {
21666  	 	 	 	 $this->movePage($page_last, $page);
21667  	 	 	 }
21668  	 	 }
21669  	 }
21670  
21671  	 /**
21672  	  * Output a Table Of Content Index (TOC) using HTML templates.
21673  	  * This method must be called after all Bookmarks were set.
21674  	  * Before calling this method you have to open the page using the addTOCPage() method.
21675  	  * After calling this method you have to call endTOCPage() to close the TOC page.
21676  	  * @param int|null $page page number where this TOC should be inserted (leave empty for current page).
21677  	  * @param string $toc_name name to use for TOC bookmark.
21678  	  * @param array $templates array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
21679  	  * @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)
21680  	  * @param string $style Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
21681  	  * @param array $color RGB color array for title (values from 0 to 255).
21682  	  * @public
21683  	  * @author Nicola Asuni
21684  	  * @since 5.0.001 (2010-05-06)
21685  	  * @see addTOCPage(), endTOCPage(), addTOC()
21686  	  */
21687  	public function addHTMLTOC($page=null, $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
21688  	 	 $filler = ' ';
21689  	 	 $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
21690  	 	 $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
21691  	 	 // set new style for link
21692  	 	 $this->htmlLinkColorArray = array();
21693  	 	 $this->htmlLinkFontStyle = '';
21694  	 	 $page_first = $this->getPage();
21695  	 	 $page_fill_start = false;
21696  	 	 $page_fill_end = false;
21697  	 	 // get the font type used for numbers in each template
21698  	 	 $current_font = $this->FontFamily;
21699  	 	 foreach ($templates as $level => $html) {
21700  	 	 	 $dom = $this->getHtmlDomArray($html);
21701  	 	 	 foreach ($dom as $key => $value) {
21702  	 	 	 	 if ($value['value'] == '#TOC_PAGE_NUMBER#') {
21703  	 	 	 	 	 $this->setFont($dom[($key - 1)]['fontname']);
21704  	 	 	 	 	 $templates['F'.$level] = $this->isUnicodeFont();
21705  	 	 	 	 }
21706  	 	 	 }
21707  	 	 }
21708  	 	 $this->setFont($current_font);
21709  	 	 $maxpage = 0; //used for pages on attached documents
21710  	 	 foreach ($this->outlines as $key => $outline) {
21711  	 	 	 // get HTML template
21712  	 	 	 $row = $templates[$outline['l']];
21713  	 	 	 if (TCPDF_STATIC::empty_string($page)) {
21714  	 	 	 	 $pagenum = $outline['p'];
21715  	 	 	 } else {
21716  	 	 	 	 // placemark to be replaced with the correct number
21717  	 	 	 	 $pagenum = '{#'.($outline['p']).'}';
21718  	 	 	 	 if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
21719  	 	 	 	 	 $pagenum = '{'.$pagenum.'}';
21720  	 	 	 	 }
21721  	 	 	 	 $maxpage = max($maxpage, $outline['p']);
21722  	 	 	 }
21723  	 	 	 // replace templates with current values
21724  	 	 	 $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
21725  	 	 	 $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
21726  	 	 	 // add link to page
21727  	 	 	 $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
21728  	 	 	 // write bookmark entry
21729  	 	 	 $this->writeHTML($row, false, false, true, false, '');
21730  	 	 }
21731  	 	 // restore link styles
21732  	 	 $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
21733  	 	 $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
21734  	 	 // move TOC page and replace numbers
21735  	 	 $page_last = $this->getPage();
21736  	 	 $numpages = ($page_last - $page_first + 1);
21737  	 	 // account for booklet mode
21738  	 	 if ($this->booklet) {
21739  	 	 	 // check if a blank page is required before TOC
21740  	 	 	 $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
21741  	 	 	 $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
21742  	 	 	 if ($page_fill_start) {
21743  	 	 	 	 // add a page at the end (to be moved before TOC)
21744  	 	 	 	 $this->addPage();
21745  	 	 	 	 ++$page_last;
21746  	 	 	 	 ++$numpages;
21747  	 	 	 }
21748  	 	 	 if ($page_fill_end) {
21749  	 	 	 	 // add a page at the end
21750  	 	 	 	 $this->addPage();
21751  	 	 	 	 ++$page_last;
21752  	 	 	 	 ++$numpages;
21753  	 	 	 }
21754  	 	 }
21755  	 	 $maxpage = max($maxpage, $page_last);
21756  	 	 if (!TCPDF_STATIC::empty_string($page)) {
21757  	 	 	 for ($p = $page_first; $p <= $page_last; ++$p) {
21758  	 	 	 	 // get page data
21759  	 	 	 	 $temppage = $this->getPageBuffer($p);
21760  	 	 	 	 for ($n = 1; $n <= $maxpage; ++$n) {
21761  	 	 	 	 	 // update page numbers
21762  	 	 	 	 	 $a = '{#'.$n.'}';
21763  	 	 	 	 	 // get page number aliases
21764  	 	 	 	 	 $pnalias = $this->getInternalPageNumberAliases($a);
21765  	 	 	 	 	 // calculate replacement number
21766  	 	 	 	 	 if ($n >= $page) {
21767  	 	 	 	 	 	 $np = $n + $numpages;
21768  	 	 	 	 	 } else {
21769  	 	 	 	 	 	 $np = $n;
21770  	 	 	 	 	 }
21771  	 	 	 	 	 $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
21772  	 	 	 	 	 $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
21773  	 	 	 	 	 // replace aliases with numbers
21774  	 	 	 	 	 foreach ($pnalias['u'] as $u) {
21775  	 	 	 	 	 	 if ($correct_align) {
21776  	 	 	 	 	 	 	 $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
21777  	 	 	 	 	 	 	 if ($this->rtl) {
21778  	 	 	 	 	 	 	 	 $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
21779  	 	 	 	 	 	 	 } else {
21780  	 	 	 	 	 	 	 	 $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
21781  	 	 	 	 	 	 	 }
21782  	 	 	 	 	 	 } else {
21783  	 	 	 	 	 	 	 $nr = $nu;
21784  	 	 	 	 	 	 }
21785  	 	 	 	 	 	 $temppage = str_replace($u, $nr, $temppage);
21786  	 	 	 	 	 }
21787  	 	 	 	 	 foreach ($pnalias['a'] as $a) {
21788  	 	 	 	 	 	 if ($correct_align) {
21789  	 	 	 	 	 	 	 $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
21790  	 	 	 	 	 	 	 if ($this->rtl) {
21791  	 	 	 	 	 	 	 	 $nr = $na.' '.$sfill;
21792  	 	 	 	 	 	 	 } else {
21793  	 	 	 	 	 	 	 	 $nr = $sfill.' '.$na;
21794  	 	 	 	 	 	 	 }
21795  	 	 	 	 	 	 } else {
21796  	 	 	 	 	 	 	 $nr = $na;
21797  	 	 	 	 	 	 }
21798  	 	 	 	 	 	 $temppage = str_replace($a, $nr, $temppage);
21799  	 	 	 	 	 }
21800  	 	 	 	 }
21801  	 	 	 	 // save changes
21802  	 	 	 	 $this->setPageBuffer($p, $temppage);
21803  	 	 	 }
21804  	 	 	 // move pages
21805  	 	 	 $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
21806  	 	 	 if ($page_fill_start) {
21807  	 	 	 	 $this->movePage($page_last, $page_first);
21808  	 	 	 }
21809  	 	 	 for ($i = 0; $i < $numpages; ++$i) {
21810  	 	 	 	 $this->movePage($page_last, $page);
21811  	 	 	 }
21812  	 	 }
21813  	 }
21814  
21815  	 /**
21816  	  * Stores a copy of the current TCPDF object used for undo operation.
21817  	  * @public
21818  	  * @since 4.5.029 (2009-03-19)
21819  	  */
21820  	public function startTransaction() {
21821  	 	 if (isset($this->objcopy)) {
21822  	 	 	 // remove previous copy
21823  	 	 	 $this->commitTransaction();
21824  	 	 }
21825  	 	 // record current page number and Y position
21826  	 	 $this->start_transaction_page = $this->page;
21827  	 	 $this->start_transaction_y = $this->y;
21828  	 	 // clone current object
21829  	 	 $this->objcopy = TCPDF_STATIC::objclone($this);
21830  	 }
21831  
21832  	 /**
21833  	  * Delete the copy of the current TCPDF object used for undo operation.
21834  	  * @public
21835  	  * @since 4.5.029 (2009-03-19)
21836  	  */
21837  	public function commitTransaction() {
21838  	 	 if (isset($this->objcopy)) {
21839  	 	 	 $this->objcopy->_destroy(true, true);
21840  	 	 	 /* The unique file_id should not be used during cleanup again */
21841  	 	 	 $this->objcopy->file_id = NULL;
21842  	 	 	 unset($this->objcopy);
21843  	 	 }
21844  	 }
21845  
21846  	 /**
21847  	  * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
21848  	  * @param boolean $self if true restores current class object to previous state without the need of reassignment via the returned value.
21849  	  * @return TCPDF object.
21850  	  * @public
21851  	  * @since 4.5.029 (2009-03-19)
21852  	  */
21853  	public function rollbackTransaction($self=false) {
21854  	 	 if (isset($this->objcopy)) {
21855  	 	 	 $objcopy = $this->objcopy;
21856  	 	 	 $this->_destroy(true, true);
21857  	 	 	 if ($self) {
21858  	 	 	 	 $objvars = get_object_vars($objcopy);
21859  	 	 	 	 foreach ($objvars as $key => $value) {
21860  	 	 	 	 	 $this->$key = $value;
21861  	 	 	 	 }
21862  	 	 	 	 $objcopy->_destroy(true, true);
21863  	 	 	 	 /* The unique file_id should not be used during cleanup again */
21864  	 	 	 	 $objcopy->file_id = NULL;
21865  	 	 	 	 unset($objcopy);
21866  	 	 	 	 return $this;
21867  	 	 	 }
21868  	 	 	 /* The unique file_id should not be used during cleanup again */
21869  	 	 	 $this->file_id = NULL;
21870  	 	 	 return $objcopy;
21871  	 	 }
21872  	 	 return $this;
21873  	 }
21874  
21875  	 // --- MULTI COLUMNS METHODS -----------------------
21876  
21877  	 /**
21878  	  * Set multiple columns of the same size
21879  	  * @param int $numcols number of columns (set to zero to disable columns mode)
21880  	  * @param int $width column width
21881  	  * @param int|null $y column starting Y position (leave empty for current Y position)
21882  	  * @public
21883  	  * @since 4.9.001 (2010-03-28)
21884  	  */
21885  	public function setEqualColumns($numcols=0, $width=0, $y=null) {
21886  	 	 $this->columns = array();
21887  	 	 if ($numcols < 2) {
21888  	 	 	 $numcols = 0;
21889  	 	 	 $this->columns = array();
21890  	 	 } else {
21891  	 	 	 // maximum column width
21892  	 	 	 $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
21893  	 	 	 if (($width == 0) OR ($width > $maxwidth)) {
21894  	 	 	 	 $width = $maxwidth;
21895  	 	 	 }
21896  	 	 	 if (TCPDF_STATIC::empty_string($y)) {
21897  	 	 	 	 $y = $this->y;
21898  	 	 	 }
21899  	 	 	 // space between columns
21900  	 	 	 $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
21901  	 	 	 // fill the columns array (with, space, starting Y position)
21902  	 	 	 for ($i = 0; $i < $numcols; ++$i) {
21903  	 	 	 	 $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
21904  	 	 	 }
21905  	 	 }
21906  	 	 $this->num_columns = $numcols;
21907  	 	 $this->current_column = 0;
21908  	 	 $this->column_start_page = $this->page;
21909  	 	 $this->selectColumn(0);
21910  	 }
21911  
21912  	 /**
21913  	  * Remove columns and reset page margins.
21914  	  * @public
21915  	  * @since 5.9.072 (2011-04-26)
21916  	  */
21917  	public function resetColumns() {
21918  	 	 $this->lMargin = $this->original_lMargin;
21919  	 	 $this->rMargin = $this->original_rMargin;
21920  	 	 $this->setEqualColumns();
21921  	 }
21922  
21923  	 /**
21924  	  * Set columns array.
21925  	  * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
21926  	  * @param array $columns
21927  	  * @public
21928  	  * @since 4.9.001 (2010-03-28)
21929  	  */
21930  	public function setColumnsArray($columns) {
21931  	 	 $this->columns = $columns;
21932  	 	 $this->num_columns = count($columns);
21933  	 	 $this->current_column = 0;
21934  	 	 $this->column_start_page = $this->page;
21935  	 	 $this->selectColumn(0);
21936  	 }
21937  
21938  	 /**
21939  	  * Set position at a given column
21940  	  * @param int|null $col column number (from 0 to getNumberOfColumns()-1); empty string = current column.
21941  	  * @public
21942  	  * @since 4.9.001 (2010-03-28)
21943  	  */
21944  	public function selectColumn($col=null) {
21945  	 	 if (TCPDF_STATIC::empty_string($col)) {
21946  	 	 	 $col = $this->current_column;
21947  	 	 } elseif ($col >= $this->num_columns) {
21948  	 	 	 $col = 0;
21949  	 	 }
21950  	 	 $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
21951  	 	 $enable_thead = false;
21952  	 	 if ($this->num_columns > 1) {
21953  	 	 	 if ($col != $this->current_column) {
21954  	 	 	 	 // move Y pointer at the top of the column
21955  	 	 	 	 if ($this->column_start_page == $this->page) {
21956  	 	 	 	 	 $this->y = $this->columns[$col]['y'];
21957  	 	 	 	 } else {
21958  	 	 	 	 	 $this->y = $this->tMargin;
21959  	 	 	 	 }
21960  	 	 	 	 // Avoid to write table headers more than once
21961  	 	 	 	 if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
21962  	 	 	 	 	 $enable_thead = true;
21963  	 	 	 	 	 $this->maxselcol['page'] = $this->page;
21964  	 	 	 	 	 $this->maxselcol['column'] = $col;
21965  	 	 	 	 }
21966  	 	 	 }
21967  	 	 	 $xshift = $this->colxshift;
21968  	 	 	 // set X position of the current column by case
21969  	 	 	 $listindent = ($this->listindentlevel * $this->listindent);
21970  	 	 	 // calculate column X position
21971  	 	 	 $colpos = 0;
21972  	 	 	 for ($i = 0; $i < $col; ++$i) {
21973  	 	 	 	 $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
21974  	 	 	 }
21975  	 	 	 if ($this->rtl) {
21976  	 	 	 	 $x = $this->w - $this->original_rMargin - $colpos;
21977  	 	 	 	 $this->rMargin = ($this->w - $x + $listindent);
21978  	 	 	 	 $this->lMargin = ($x - $this->columns[$col]['w']);
21979  	 	 	 	 $this->x = $x - $listindent;
21980  	 	 	 } else {
21981  	 	 	 	 $x = $this->original_lMargin + $colpos;
21982  	 	 	 	 $this->lMargin = ($x + $listindent);
21983  	 	 	 	 $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
21984  	 	 	 	 $this->x = $x + $listindent;
21985  	 	 	 }
21986  	 	 	 $this->columns[$col]['x'] = $x;
21987  	 	 }
21988  	 	 $this->current_column = $col;
21989  	 	 // fix for HTML mode
21990  	 	 $this->newline = true;
21991  	 	 // print HTML table header (if any)
21992  	 	 if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
21993  	 	 	 if ($enable_thead) {
21994  	 	 	 	 // print table header
21995  	 	 	 	 $this->writeHTML($this->thead, false, false, false, false, '');
21996  	 	 	 	 $this->y += $xshift['s']['V'];
21997  	 	 	 	 // store end of header position
21998  	 	 	 	 if (!isset($this->columns[$col]['th'])) {
21999  	 	 	 	 	 $this->columns[$col]['th'] = array();
22000  	 	 	 	 }
22001  	 	 	 	 $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
22002  	 	 	 	 $this->lasth = 0;
22003  	 	 	 } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
22004  	 	 	 	 $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
22005  	 	 	 }
22006  	 	 }
22007  	 	 // account for an html table cell over multiple columns
22008  	 	 if ($this->rtl) {
22009  	 	 	 $this->rMargin += $xshift['x'];
22010  	 	 	 $this->x -= ($xshift['x'] + $xshift['p']['R']);
22011  	 	 } else {
22012  	 	 	 $this->lMargin += $xshift['x'];
22013  	 	 	 $this->x += $xshift['x'] + $xshift['p']['L'];
22014  	 	 }
22015  	 }
22016  
22017  	 /**
22018  	  * Return the current column number
22019  	  * @return int current column number
22020  	  * @public
22021  	  * @since 5.5.011 (2010-07-08)
22022  	  */
22023  	public function getColumn() {
22024  	 	 return $this->current_column;
22025  	 }
22026  
22027  	 /**
22028  	  * Return the current number of columns.
22029  	  * @return int number of columns
22030  	  * @public
22031  	  * @since 5.8.018 (2010-08-25)
22032  	  */
22033  	public function getNumberOfColumns() {
22034  	 	 return $this->num_columns;
22035  	 }
22036  
22037  	 /**
22038  	  * Set Text rendering mode.
22039  	  * @param int $stroke outline size in user units (0 = disable).
22040  	  * @param boolean $fill if true fills the text (default).
22041  	  * @param boolean $clip if true activate clipping mode
22042  	  * @public
22043  	  * @since 4.9.008 (2009-04-02)
22044  	  */
22045  	public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
22046  	 	 // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
22047  	 	 // convert text rendering parameters
22048  	 	 if ($stroke < 0) {
22049  	 	 	 $stroke = 0;
22050  	 	 }
22051  	 	 if ($fill === true) {
22052  	 	 	 if ($stroke > 0) {
22053  	 	 	 	 if ($clip === true) {
22054  	 	 	 	 	 // Fill, then stroke text and add to path for clipping
22055  	 	 	 	 	 $textrendermode = 6;
22056  	 	 	 	 } else {
22057  	 	 	 	 	 // Fill, then stroke text
22058  	 	 	 	 	 $textrendermode = 2;
22059  	 	 	 	 }
22060  	 	 	 	 $textstrokewidth = $stroke;
22061  	 	 	 } else {
22062  	 	 	 	 if ($clip === true) {
22063  	 	 	 	 	 // Fill text and add to path for clipping
22064  	 	 	 	 	 $textrendermode = 4;
22065  	 	 	 	 } else {
22066  	 	 	 	 	 // Fill text
22067  	 	 	 	 	 $textrendermode = 0;
22068  	 	 	 	 }
22069  	 	 	 }
22070  	 	 } else {
22071  	 	 	 if ($stroke > 0) {
22072  	 	 	 	 if ($clip === true) {
22073  	 	 	 	 	 // Stroke text and add to path for clipping
22074  	 	 	 	 	 $textrendermode = 5;
22075  	 	 	 	 } else {
22076  	 	 	 	 	 // Stroke text
22077  	 	 	 	 	 $textrendermode = 1;
22078  	 	 	 	 }
22079  	 	 	 	 $textstrokewidth = $stroke;
22080  	 	 	 } else {
22081  	 	 	 	 if ($clip === true) {
22082  	 	 	 	 	 // Add text to path for clipping
22083  	 	 	 	 	 $textrendermode = 7;
22084  	 	 	 	 } else {
22085  	 	 	 	 	 // Neither fill nor stroke text (invisible)
22086  	 	 	 	 	 $textrendermode = 3;
22087  	 	 	 	 }
22088  	 	 	 }
22089  	 	 }
22090  	 	 $this->textrendermode = $textrendermode;
22091  	 	 $this->textstrokewidth = $stroke;
22092  	 }
22093  
22094  	 /**
22095  	  * Set parameters for drop shadow effect for text.
22096  	  * @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.
22097  	  * @since 5.9.174 (2012-07-25)
22098  	  * @public
22099  	 */
22100  	public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
22101  	 	 if (isset($params['enabled'])) {
22102  	 	 	 $this->txtshadow['enabled'] = $params['enabled']?true:false;
22103  	 	 } else {
22104  	 	 	 $this->txtshadow['enabled'] = false;
22105  	 	 }
22106  	 	 if (isset($params['depth_w'])) {
22107  	 	 	 $this->txtshadow['depth_w'] = floatval($params['depth_w']);
22108  	 	 } else {
22109  	 	 	 $this->txtshadow['depth_w'] = 0;
22110  	 	 }
22111  	 	 if (isset($params['depth_h'])) {
22112  	 	 	 $this->txtshadow['depth_h'] = floatval($params['depth_h']);
22113  	 	 } else {
22114  	 	 	 $this->txtshadow['depth_h'] = 0;
22115  	 	 }
22116  	 	 if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
22117  	 	 	 $this->txtshadow['color'] = $params['color'];
22118  	 	 } else {
22119  	 	 	 $this->txtshadow['color'] = $this->strokecolor;
22120  	 	 }
22121  	 	 if (isset($params['opacity'])) {
22122  	 	 	 $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
22123  	 	 } else {
22124  	 	 	 $this->txtshadow['opacity'] = 1;
22125  	 	 }
22126  	 	 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'))) {
22127  	 	 	 $this->txtshadow['blend_mode'] = $params['blend_mode'];
22128  	 	 } else {
22129  	 	 	 $this->txtshadow['blend_mode'] = 'Normal';
22130  	 	 }
22131  	 	 if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
22132  	 	 	 $this->txtshadow['enabled'] = false;
22133  	 	 }
22134  	 }
22135  
22136  	 /**
22137  	  * Return the text shadow parameters array.
22138  	  * @return array array of parameters.
22139  	  * @since 5.9.174 (2012-07-25)
22140  	  * @public
22141  	  */
22142  	public function getTextShadow() {
22143  	 	 return $this->txtshadow;
22144  	 }
22145  
22146  	 /**
22147  	  * Returns an array of chars containing soft hyphens.
22148  	  * @param array $word array of chars
22149  	  * @param array $patterns Array of hypenation patterns.
22150  	  * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
22151  	  * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
22152  	  * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
22153  	  * @param int $charmin Minimum word length to apply the hyphenation algorithm.
22154  	  * @param int $charmax Maximum length of broken piece of word.
22155  	  * @return array text with soft hyphens
22156  	  * @author Nicola Asuni
22157  	  * @since 4.9.012 (2010-04-12)
22158  	  * @protected
22159  	  */
22160  	protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
22161  	 	 $hyphenword = array(); // hyphens positions
22162  	 	 $numchars = count($word);
22163  	 	 if ($numchars <= $charmin) {
22164  	 	 	 return $word;
22165  	 	 }
22166  	 	 $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
22167  	 	 // some words will be returned as-is
22168  	 	 $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})(\]?)$/';
22169  	 	 if (preg_match($pattern, $word_string) > 0) {
22170  	 	 	 // email
22171  	 	 	 return $word;
22172  	 	 }
22173  	 	 $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})(\]?)$/';
22174  	 	 if (preg_match($pattern, $word_string) > 0) {
22175  	 	 	 // URL
22176  	 	 	 return $word;
22177  	 	 }
22178  	 	 if (isset($dictionary[$word_string])) {
22179  	 	 	 return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
22180  	 	 }
22181  	 	 // surround word with '_' characters
22182  	 	 $tmpword = array_merge(array(46), $word, array(46));
22183  	 	 $tmpnumchars = $numchars + 2;
22184  	 	 $maxpos = $tmpnumchars - 1;
22185  	 	 for ($pos = 0; $pos < $maxpos; ++$pos) {
22186  	 	 	 $imax = min(($tmpnumchars - $pos), $charmax);
22187  	 	 	 for ($i = 1; $i <= $imax; ++$i) {
22188  	 	 	 	 $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
22189  	 	 	 	 if (isset($patterns[$subword])) {
22190  	 	 	 	 	 $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
22191  	 	 	 	 	 $pattern_length = count($pattern);
22192  	 	 	 	 	 $digits = 1;
22193  	 	 	 	 	 for ($j = 0; $j < $pattern_length; ++$j) {
22194  	 	 	 	 	 	 // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
22195  	 	 	 	 	 	 if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
22196  	 	 	 	 	 	 	 if ($j == 0) {
22197  	 	 	 	 	 	 	 	 $zero = $pos - 1;
22198  	 	 	 	 	 	 	 } else {
22199  	 	 	 	 	 	 	 	 $zero = $pos + $j - $digits;
22200  	 	 	 	 	 	 	 }
22201  	 	 	 	 	 	 	 // get hyphenation level
22202  	 	 	 	 	 	 	 $level = ($pattern[$j] - 48);
22203  	 	 	 	 	 	 	 // if two levels from two different patterns match at the same point, the higher one is selected.
22204  	 	 	 	 	 	 	 if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
22205  	 	 	 	 	 	 	 	 $hyphenword[$zero] = $level;
22206  	 	 	 	 	 	 	 }
22207  	 	 	 	 	 	 	 ++$digits;
22208  	 	 	 	 	 	 }
22209  	 	 	 	 	 }
22210  	 	 	 	 }
22211  	 	 	 }
22212  	 	 }
22213  	 	 $inserted = 0;
22214  	 	 $maxpos = $numchars - $rightmin;
22215  	 	 for ($i = $leftmin; $i <= $maxpos; ++$i) {
22216  	 	 	 // only odd levels indicate allowed hyphenation points
22217  	 	 	 if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
22218  	 	 	 	 // 173 = soft hyphen character
22219  	 	 	 	 array_splice($word, $i + $inserted, 0, 173);
22220  	 	 	 	 ++$inserted;
22221  	 	 	 }
22222  	 	 }
22223  	 	 return $word;
22224  	 }
22225  
22226  	 /**
22227  	  * Returns text with soft hyphens.
22228  	  * @param string $text text to process
22229  	  * @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/
22230  	  * @param array $dictionary Array of words to be returned without applying the hyphenation algorithm.
22231  	  * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
22232  	  * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
22233  	  * @param int $charmin Minimum word length to apply the hyphenation algorithm.
22234  	  * @param int $charmax Maximum length of broken piece of word.
22235  	  * @return string text with soft hyphens
22236  	  * @author Nicola Asuni
22237  	  * @since 4.9.012 (2010-04-12)
22238  	  * @public
22239  	  */
22240  	public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
22241  	 	 $text = $this->unhtmlentities($text);
22242  	 	 $word = array(); // last word
22243  	 	 $txtarr = array(); // text to be returned
22244  	 	 $intag = false; // true if we are inside an HTML tag
22245  	 	 $skip = false; // true to skip hyphenation
22246  	 	 if (!is_array($patterns)) {
22247  	 	 	 $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
22248  	 	 }
22249  	 	 // get array of characters
22250  	 	 $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
22251  	 	 // for each char
22252  	 	 foreach ($unichars as $char) {
22253  	 	 	 if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
22254  	 	 	 	 // letter character
22255  	 	 	 	 $word[] = $char;
22256  	 	 	 } else {
22257  	 	 	 	 // other type of character
22258  	 	 	 	 if (!TCPDF_STATIC::empty_string($word)) {
22259  	 	 	 	 	 // hypenate the word
22260  	 	 	 	 	 $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
22261  	 	 	 	 	 $word = array();
22262  	 	 	 	 }
22263  	 	 	 	 $txtarr[] = $char;
22264  	 	 	 	 if (chr($char) == '<') {
22265  	 	 	 	 	 // we are inside an HTML tag
22266  	 	 	 	 	 $intag = true;
22267  	 	 	 	 } elseif ($intag AND (chr($char) == '>')) {
22268  	 	 	 	 	 // end of HTML tag
22269  	 	 	 	 	 $intag = false;
22270  	 	 	 	 	 // check for style tag
22271  	 	 	 	 	 $expected = array(115, 116, 121, 108, 101); // = 'style'
22272  	 	 	 	 	 $current = array_slice($txtarr, -6, 5); // last 5 chars
22273  	 	 	 	 	 $compare = array_diff($expected, $current);
22274  	 	 	 	 	 if (empty($compare)) {
22275  	 	 	 	 	 	 // check if it is a closing tag
22276  	 	 	 	 	 	 $expected = array(47); // = '/'
22277  	 	 	 	 	 	 $current = array_slice($txtarr, -7, 1);
22278  	 	 	 	 	 	 $compare = array_diff($expected, $current);
22279  	 	 	 	 	 	 if (empty($compare)) {
22280  	 	 	 	 	 	 	 // closing style tag
22281  	 	 	 	 	 	 	 $skip = false;
22282  	 	 	 	 	 	 } else {
22283  	 	 	 	 	 	 	 // opening style tag
22284  	 	 	 	 	 	 	 $skip = true;
22285  	 	 	 	 	 	 }
22286  	 	 	 	 	 }
22287  	 	 	 	 }
22288  	 	 	 }
22289  	 	 }
22290  	 	 if (!TCPDF_STATIC::empty_string($word)) {
22291  	 	 	 // hypenate the word
22292  	 	 	 $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
22293  	 	 }
22294  	 	 // convert char array to string and return
22295  	 	 return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
22296  	 }
22297  
22298  	 /**
22299  	  * Enable/disable rasterization of vector images using ImageMagick library.
22300  	  * @param boolean $mode if true enable rasterization, false otherwise.
22301  	  * @public
22302  	  * @since 5.0.000 (2010-04-27)
22303  	  */
22304  	public function setRasterizeVectorImages($mode) {
22305  	 	 $this->rasterize_vector_images = $mode;
22306  	 }
22307  
22308  	 /**
22309  	  * Enable or disable default option for font subsetting.
22310  	  * @param boolean $enable if true enable font subsetting by default.
22311  	  * @author Nicola Asuni
22312  	  * @public
22313  	  * @since 5.3.002 (2010-06-07)
22314  	  */
22315  	public function setFontSubsetting($enable=true) {
22316  	 	 if ($this->pdfa_mode) {
22317  	 	 	 $this->font_subsetting = false;
22318  	 	 } else {
22319  	 	 	 $this->font_subsetting = $enable ? true : false;
22320  	 	 }
22321  	 }
22322  
22323  	 /**
22324  	  * Return the default option for font subsetting.
22325  	  * @return bool default font subsetting state.
22326  	  * @author Nicola Asuni
22327  	  * @public
22328  	  * @since 5.3.002 (2010-06-07)
22329  	  */
22330  	public function getFontSubsetting() {
22331  	 	 return $this->font_subsetting;
22332  	 }
22333  
22334  	 /**
22335  	  * Left trim the input string
22336  	  * @param string $str string to trim
22337  	  * @param string $replace string that replace spaces.
22338  	  * @return string left trimmed string
22339  	  * @author Nicola Asuni
22340  	  * @public
22341  	  * @since 5.8.000 (2010-08-11)
22342  	  */
22343  	public function stringLeftTrim($str, $replace='') {
22344  	 	 return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
22345  	 }
22346  
22347  	 /**
22348  	  * Right trim the input string
22349  	  * @param string $str string to trim
22350  	  * @param string $replace string that replace spaces.
22351  	  * @return string right trimmed string
22352  	  * @author Nicola Asuni
22353  	  * @public
22354  	  * @since 5.8.000 (2010-08-11)
22355  	  */
22356  	public function stringRightTrim($str, $replace='') {
22357  	 	 return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
22358  	 }
22359  
22360  	 /**
22361  	  * Trim the input string
22362  	  * @param string $str string to trim
22363  	  * @param string $replace string that replace spaces.
22364  	  * @return string trimmed string
22365  	  * @author Nicola Asuni
22366  	  * @public
22367  	  * @since 5.8.000 (2010-08-11)
22368  	  */
22369  	public function stringTrim($str, $replace='') {
22370  	 	 $str = $this->stringLeftTrim($str, $replace);
22371  	 	 $str = $this->stringRightTrim($str, $replace);
22372  	 	 return $str;
22373  	 }
22374  
22375  	 /**
22376  	  * Return true if the current font is unicode type.
22377  	  * @return bool true for unicode font, false otherwise.
22378  	  * @author Nicola Asuni
22379  	  * @public
22380  	  * @since 5.8.002 (2010-08-14)
22381  	  */
22382  	public function isUnicodeFont() {
22383  	 	 return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
22384  	 }
22385  
22386  	 /**
22387  	  * Return normalized font name
22388  	  * @param string $fontfamily property string containing font family names
22389  	  * @return string normalized font name
22390  	  * @author Nicola Asuni
22391  	  * @public
22392  	  * @since 5.8.004 (2010-08-17)
22393  	  */
22394  	public function getFontFamilyName($fontfamily) {
22395  	 	 // remove spaces and symbols
22396  	 	 $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
22397  	 	 // extract all font names
22398  	 	 $fontslist = preg_split('/[,]/', $fontfamily);
22399  	 	 // find first valid font name
22400  	 	 foreach ($fontslist as $font) {
22401  	 	 	 // replace font variations
22402  	 	 	 $font = preg_replace('/regular$/', '', $font);
22403  	 	 	 $font = preg_replace('/italic$/', 'I', $font);
22404  	 	 	 $font = preg_replace('/oblique$/', 'I', $font);
22405  	 	 	 $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
22406  	 	 	 // replace common family names and core fonts
22407  	 	 	 $pattern = array();
22408  	 	 	 $replacement = array();
22409  	 	 	 $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
22410  	 	 	 $replacement[] = 'times';
22411  	 	 	 $pattern[] = '/^sansserif/';
22412  	 	 	 $replacement[] = 'helvetica';
22413  	 	 	 $pattern[] = '/^monospace/';
22414  	 	 	 $replacement[] = 'courier';
22415  	 	 	 $font = preg_replace($pattern, $replacement, $font);
22416  	 	 	 if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
22417  	 	 	 	 return $font;
22418  	 	 	 }
22419  	 	 }
22420  	 	 // return current font as default
22421  	 	 return $this->CurrentFont['fontkey'];
22422  	 }
22423  
22424  	 /**
22425  	  * Start a new XObject Template.
22426  	  * 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).
22427  	  * 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.
22428  	  * Note: X,Y coordinates will be reset to 0,0.
22429  	  * @param int $w Template width in user units (empty string or zero = page width less margins).
22430  	  * @param int $h Template height in user units (empty string or zero = page height less margins).
22431  	  * @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).
22432  	  * @return string|false the XObject Template ID in case of success or false in case of error.
22433  	  * @author Nicola Asuni
22434  	  * @public
22435  	  * @since 5.8.017 (2010-08-24)
22436  	  * @see endTemplate(), printTemplate()
22437  	  */
22438  	public function startTemplate($w=0, $h=0, $group=false) {
22439  	 	 if ($this->inxobj) {
22440  	 	 	 // we are already inside an XObject template
22441  	 	 	 return false;
22442  	 	 }
22443  	 	 $this->inxobj = true;
22444  	 	 ++$this->n;
22445  	 	 // XObject ID
22446  	 	 $this->xobjid = 'XT'.$this->n;
22447  	 	 // object ID
22448  	 	 $this->xobjects[$this->xobjid] = array('n' => $this->n);
22449  	 	 // store current graphic state
22450  	 	 $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
22451  	 	 // initialize data
22452  	 	 $this->xobjects[$this->xobjid]['intmrk'] = 0;
22453  	 	 $this->xobjects[$this->xobjid]['transfmrk'] = array();
22454  	 	 $this->xobjects[$this->xobjid]['outdata'] = '';
22455  	 	 $this->xobjects[$this->xobjid]['xobjects'] = array();
22456  	 	 $this->xobjects[$this->xobjid]['images'] = array();
22457  	 	 $this->xobjects[$this->xobjid]['fonts'] = array();
22458  	 	 $this->xobjects[$this->xobjid]['annotations'] = array();
22459  	 	 $this->xobjects[$this->xobjid]['extgstates'] = array();
22460  	 	 $this->xobjects[$this->xobjid]['gradients'] = array();
22461  	 	 $this->xobjects[$this->xobjid]['spot_colors'] = array();
22462  	 	 // set new environment
22463  	 	 $this->num_columns = 1;
22464  	 	 $this->current_column = 0;
22465  	 	 $this->setAutoPageBreak(false);
22466  	 	 if (($w === '') OR ($w <= 0)) {
22467  	 	 	 $w = $this->w - $this->lMargin - $this->rMargin;
22468  	 	 }
22469  	 	 if (($h === '') OR ($h <= 0)) {
22470  	 	 	 $h = $this->h - $this->tMargin - $this->bMargin;
22471  	 	 }
22472  	 	 $this->xobjects[$this->xobjid]['x'] = 0;
22473  	 	 $this->xobjects[$this->xobjid]['y'] = 0;
22474  	 	 $this->xobjects[$this->xobjid]['w'] = $w;
22475  	 	 $this->xobjects[$this->xobjid]['h'] = $h;
22476  	 	 $this->w = $w;
22477  	 	 $this->h = $h;
22478  	 	 $this->wPt = $this->w * $this->k;
22479  	 	 $this->hPt = $this->h * $this->k;
22480  	 	 $this->fwPt = $this->wPt;
22481  	 	 $this->fhPt = $this->hPt;
22482  	 	 $this->x = 0;
22483  	 	 $this->y = 0;
22484  	 	 $this->lMargin = 0;
22485  	 	 $this->rMargin = 0;
22486  	 	 $this->tMargin = 0;
22487  	 	 $this->bMargin = 0;
22488  	 	 // set group mode
22489  	 	 $this->xobjects[$this->xobjid]['group'] = $group;
22490  	 	 return $this->xobjid;
22491  	 }
22492  
22493  	 /**
22494  	  * End the current XObject Template started with startTemplate() and restore the previous graphic state.
22495  	  * 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).
22496  	  * 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.
22497  	  * @return string|false the XObject Template ID in case of success or false in case of error.
22498  	  * @author Nicola Asuni
22499  	  * @public
22500  	  * @since 5.8.017 (2010-08-24)
22501  	  * @see startTemplate(), printTemplate()
22502  	  */
22503  	public function endTemplate() {
22504  	 	 if (!$this->inxobj) {
22505  	 	 	 // we are not inside a template
22506  	 	 	 return false;
22507  	 	 }
22508  	 	 $this->inxobj = false;
22509  	 	 // restore previous graphic state
22510  	 	 $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
22511  	 	 return $this->xobjid;
22512  	 }
22513  
22514  	 /**
22515  	  * Print an XObject Template.
22516  	  * You can print an XObject Template inside the currently opened Template.
22517  	  * 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).
22518  	  * 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.
22519  	  * @param string $id The ID of XObject Template to print.
22520  	  * @param float|null $x X position in user units (empty string = current x position)
22521  	  * @param float|null $y Y position in user units (empty string = current y position)
22522  	  * @param float $w Width in user units (zero = remaining page width)
22523  	  * @param float $h Height in user units (zero = remaining page height)
22524  	  * @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>
22525  	  * @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>
22526  	  * @param boolean $fitonpage If true the template is resized to not exceed page dimensions.
22527  	  * @author Nicola Asuni
22528  	  * @public
22529  	  * @since 5.8.017 (2010-08-24)
22530  	  * @see startTemplate(), endTemplate()
22531  	  */
22532  	public function printTemplate($id, $x=null, $y=null, $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
22533  	 	 if ($this->state != 2) {
22534  	 	 	  return;
22535  	 	 }
22536  	 	 if (!isset($this->xobjects[$id])) {
22537  	 	 	 $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
22538  	 	 }
22539  	 	 if ($this->inxobj) {
22540  	 	 	 if ($id == $this->xobjid) {
22541  	 	 	 	 // close current template
22542  	 	 	 	 $this->endTemplate();
22543  	 	 	 } else {
22544  	 	 	 	 // use the template as resource for the template currently opened
22545  	 	 	 	 $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
22546  	 	 	 }
22547  	 	 }
22548  	 	 // set default values
22549  	 	 if (TCPDF_STATIC::empty_string($x)) {
22550  	 	 	 $x = $this->x;
22551  	 	 }
22552  	 	 if (TCPDF_STATIC::empty_string($y)) {
22553  	 	 	 $y = $this->y;
22554  	 	 }
22555  	 	 // check page for no-write regions and adapt page margins if necessary
22556  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
22557  	 	 $ow = $this->xobjects[$id]['w'];
22558  	 	 if ($ow <= 0) {
22559  	 	 	 $ow = 1;
22560  	 	 }
22561  	 	 $oh = $this->xobjects[$id]['h'];
22562  	 	 if ($oh <= 0) {
22563  	 	 	 $oh = 1;
22564  	 	 }
22565  	 	 // calculate template width and height on document
22566  	 	 if (($w <= 0) AND ($h <= 0)) {
22567  	 	 	 $w = $ow;
22568  	 	 	 $h = $oh;
22569  	 	 } elseif ($w <= 0) {
22570  	 	 	 $w = $h * $ow / $oh;
22571  	 	 } elseif ($h <= 0) {
22572  	 	 	 $h = $w * $oh / $ow;
22573  	 	 }
22574  	 	 // fit the template on available space
22575  	 	 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
22576  	 	 // set page alignment
22577  	 	 $rb_y = $y + $h;
22578  	 	 // set alignment
22579  	 	 if ($this->rtl) {
22580  	 	 	 if ($palign == 'L') {
22581  	 	 	 	 $xt = $this->lMargin;
22582  	 	 	 } elseif ($palign == 'C') {
22583  	 	 	 	 $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
22584  	 	 	 } elseif ($palign == 'R') {
22585  	 	 	 	 $xt = $this->w - $this->rMargin - $w;
22586  	 	 	 } else {
22587  	 	 	 	 $xt = $x - $w;
22588  	 	 	 }
22589  	 	 	 $rb_x = $xt;
22590  	 	 } else {
22591  	 	 	 if ($palign == 'L') {
22592  	 	 	 	 $xt = $this->lMargin;
22593  	 	 	 } elseif ($palign == 'C') {
22594  	 	 	 	 $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
22595  	 	 	 } elseif ($palign == 'R') {
22596  	 	 	 	 $xt = $this->w - $this->rMargin - $w;
22597  	 	 	 } else {
22598  	 	 	 	 $xt = $x;
22599  	 	 	 }
22600  	 	 	 $rb_x = $xt + $w;
22601  	 	 }
22602  	 	 // print XObject Template + Transformation matrix
22603  	 	 $this->StartTransform();
22604  	 	 // translate and scale
22605  	 	 $sx = ($w / $ow);
22606  	 	 $sy = ($h / $oh);
22607  	 	 $tm = array();
22608  	 	 $tm[0] = $sx;
22609  	 	 $tm[1] = 0;
22610  	 	 $tm[2] = 0;
22611  	 	 $tm[3] = $sy;
22612  	 	 $tm[4] = $xt * $this->k;
22613  	 	 $tm[5] = ($this->h - $h - $y) * $this->k;
22614  	 	 $this->Transform($tm);
22615  	 	 // set object
22616  	 	 $this->_out('/'.$id.' Do');
22617  	 	 $this->StopTransform();
22618  	 	 // add annotations
22619  	 	 if (!empty($this->xobjects[$id]['annotations'])) {
22620  	 	 	 foreach ($this->xobjects[$id]['annotations'] as $annot) {
22621  	 	 	 	 // transform original coordinates
22622  	 	 	 	 $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
22623  	 	 	 	 $ax = ($coordlt[4] / $this->k);
22624  	 	 	 	 $ay = ($this->h - $h - ($coordlt[5] / $this->k));
22625  	 	 	 	 $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
22626  	 	 	 	 $aw = ($coordrb[4] / $this->k) - $ax;
22627  	 	 	 	 $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
22628  	 	 	 	 $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
22629  	 	 	 }
22630  	 	 }
22631  	 	 // set pointer to align the next text/objects
22632  	 	 switch($align) {
22633  	 	 	 case 'T': {
22634  	 	 	 	 $this->y = $y;
22635  	 	 	 	 $this->x = $rb_x;
22636  	 	 	 	 break;
22637  	 	 	 }
22638  	 	 	 case 'M': {
22639  	 	 	 	 $this->y = $y + round($h/2);
22640  	 	 	 	 $this->x = $rb_x;
22641  	 	 	 	 break;
22642  	 	 	 }
22643  	 	 	 case 'B': {
22644  	 	 	 	 $this->y = $rb_y;
22645  	 	 	 	 $this->x = $rb_x;
22646  	 	 	 	 break;
22647  	 	 	 }
22648  	 	 	 case 'N': {
22649  	 	 	 	 $this->setY($rb_y);
22650  	 	 	 	 break;
22651  	 	 	 }
22652  	 	 	 default:{
22653  	 	 	 	 break;
22654  	 	 	 }
22655  	 	 }
22656  	 }
22657  
22658  	 /**
22659  	  * Set the percentage of character stretching.
22660  	  * @param int $perc percentage of stretching (100 = no stretching)
22661  	  * @author Nicola Asuni
22662  	  * @public
22663  	  * @since 5.9.000 (2010-09-29)
22664  	  */
22665  	public function setFontStretching($perc=100) {
22666  	 	 $this->font_stretching = $perc;
22667  	 }
22668  
22669  	 /**
22670  	  * Get the percentage of character stretching.
22671  	  * @return float stretching value
22672  	  * @author Nicola Asuni
22673  	  * @public
22674  	  * @since 5.9.000 (2010-09-29)
22675  	  */
22676  	public function getFontStretching() {
22677  	 	 return $this->font_stretching;
22678  	 }
22679  
22680  	 /**
22681  	  * Set the amount to increase or decrease the space between characters in a text.
22682  	  * @param float $spacing amount to increase or decrease the space between characters in a text (0 = default spacing)
22683  	  * @author Nicola Asuni
22684  	  * @public
22685  	  * @since 5.9.000 (2010-09-29)
22686  	  */
22687  	public function setFontSpacing($spacing=0) {
22688  	 	 $this->font_spacing = $spacing;
22689  	 }
22690  
22691  	 /**
22692  	  * Get the amount to increase or decrease the space between characters in a text.
22693  	  * @return int font spacing (tracking) value
22694  	  * @author Nicola Asuni
22695  	  * @public
22696  	  * @since 5.9.000 (2010-09-29)
22697  	  */
22698  	public function getFontSpacing() {
22699  	 	 return $this->font_spacing;
22700  	 }
22701  
22702  	 /**
22703  	  * Return an array of no-write page regions
22704  	  * @return array of no-write page regions
22705  	  * @author Nicola Asuni
22706  	  * @public
22707  	  * @since 5.9.003 (2010-10-13)
22708  	  * @see setPageRegions(), addPageRegion()
22709  	  */
22710  	public function getPageRegions() {
22711  	 	 return $this->page_regions;
22712  	 }
22713  
22714  	 /**
22715  	  * Set no-write regions on page.
22716  	  * 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.
22717  	  * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
22718  	  * You can set multiple regions for the same page.
22719  	  * @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.
22720  	  * @author Nicola Asuni
22721  	  * @public
22722  	  * @since 5.9.003 (2010-10-13)
22723  	  * @see addPageRegion(), getPageRegions()
22724  	  */
22725  	public function setPageRegions($regions=array()) {
22726  	 	 // empty current regions array
22727  	 	 $this->page_regions = array();
22728  	 	 // add regions
22729  	 	 foreach ($regions as $data) {
22730  	 	 	 $this->addPageRegion($data);
22731  	 	 }
22732  	 }
22733  
22734  	 /**
22735  	  * Add a single no-write region on selected page.
22736  	  * 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.
22737  	  * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
22738  	  * You can set multiple regions for the same page.
22739  	  * @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).
22740  	  * @author Nicola Asuni
22741  	  * @public
22742  	  * @since 5.9.003 (2010-10-13)
22743  	  * @see setPageRegions(), getPageRegions()
22744  	  */
22745  	public function addPageRegion($region) {
22746  	 	 if (!isset($region['page']) OR empty($region['page'])) {
22747  	 	 	 $region['page'] = $this->page;
22748  	 	 }
22749  	 	 if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
22750  	 	 	 AND isset($region['yt'])  AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
22751  	 	 	 AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
22752  	 	 	 $this->page_regions[] = $region;
22753  	 	 }
22754  	 }
22755  
22756  	 /**
22757  	  * Remove a single no-write region.
22758  	  * @param int $key region key
22759  	  * @author Nicola Asuni
22760  	  * @public
22761  	  * @since 5.9.003 (2010-10-13)
22762  	  * @see setPageRegions(), getPageRegions()
22763  	  */
22764  	public function removePageRegion($key) {
22765  	 	 if (isset($this->page_regions[$key])) {
22766  	 	 	 unset($this->page_regions[$key]);
22767  	 	 }
22768  	 }
22769  
22770  	 /**
22771  	  * Check page for no-write regions and adapt current coordinates and page margins if necessary.
22772  	  * 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.
22773  	  * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
22774  	  * @param float $h height of the text/image/object to print in user units
22775  	  * @param float $x current X coordinate in user units
22776  	  * @param float $y current Y coordinate in user units
22777  	  * @return float[] array($x, $y)
22778  	  * @author Nicola Asuni
22779  	  * @protected
22780  	  * @since 5.9.003 (2010-10-13)
22781  	  */
22782  	protected function checkPageRegions($h, $x, $y) {
22783  	 	 // set default values
22784  	 	 if ($x === '') {
22785  	 	 	 $x = $this->x;
22786  	 	 }
22787  	 	 if ($y === '') {
22788  	 	 	 $y = $this->y;
22789  	 	 }
22790  	 	 if (!$this->check_page_regions OR empty($this->page_regions)) {
22791  	 	 	 // no page regions defined
22792  	 	 	 return array($x, $y);
22793  	 	 }
22794  	 	 if (empty($h)) {
22795  	 	 	 $h = $this->getCellHeight($this->FontSize);
22796  	 	 }
22797  	 	 // check for page break
22798  	 	 if ($this->checkPageBreak($h, $y)) {
22799  	 	 	 // the content will be printed on a new page
22800  	 	 	 $x = $this->x;
22801  	 	 	 $y = $this->y;
22802  	 	 }
22803  	 	 if ($this->num_columns > 1) {
22804  	 	 	 if ($this->rtl) {
22805  	 	 	 	 $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
22806  	 	 	 } else {
22807  	 	 	 	 $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
22808  	 	 	 }
22809  	 	 } else {
22810  	 	 	 if ($this->rtl) {
22811  	 	 	 	 $this->lMargin = max($this->clMargin, $this->original_lMargin);
22812  	 	 	 } else {
22813  	 	 	 	 $this->rMargin = max($this->crMargin, $this->original_rMargin);
22814  	 	 	 }
22815  	 	 }
22816  	 	 // adjust coordinates and page margins
22817  	 	 foreach ($this->page_regions as $regid => $regdata) {
22818  	 	 	 if ($regdata['page'] == $this->page) {
22819  	 	 	 	 // check region boundaries
22820  	 	 	 	 if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
22821  	 	 	 	 	 // Y is inside the region
22822  	 	 	 	 	 $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
22823  	 	 	 	 	 $yt = max($y, $regdata['yt']);
22824  	 	 	 	 	 $yb = min(($yt + $h), $regdata['yb']);
22825  	 	 	 	 	 $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
22826  	 	 	 	 	 $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
22827  	 	 	 	 	 if ($regdata['side'] == 'L') { // left side
22828  	 	 	 	 	 	 $new_margin = max($xt, $xb);
22829  	 	 	 	 	 	 if ($this->lMargin < $new_margin) {
22830  	 	 	 	 	 	 	 if ($this->rtl) {
22831  	 	 	 	 	 	 	 	 // adjust left page margin
22832  	 	 	 	 	 	 	 	 $this->lMargin = max(0, $new_margin);
22833  	 	 	 	 	 	 	 }
22834  	 	 	 	 	 	 	 if ($x < $new_margin) {
22835  	 	 	 	 	 	 	 	 // adjust x position
22836  	 	 	 	 	 	 	 	 $x = $new_margin;
22837  	 	 	 	 	 	 	 	 if ($new_margin > ($this->w - $this->rMargin)) {
22838  	 	 	 	 	 	 	 	 	 // adjust y position
22839  	 	 	 	 	 	 	 	 	 $y = $regdata['yb'] - $h;
22840  	 	 	 	 	 	 	 	 }
22841  	 	 	 	 	 	 	 }
22842  	 	 	 	 	 	 }
22843  	 	 	 	 	 } elseif ($regdata['side'] == 'R') { // right side
22844  	 	 	 	 	 	 $new_margin = min($xt, $xb);
22845  	 	 	 	 	 	 if (($this->w - $this->rMargin) > $new_margin) {
22846  	 	 	 	 	 	 	 if (!$this->rtl) {
22847  	 	 	 	 	 	 	 	 // adjust right page margin
22848  	 	 	 	 	 	 	 	 $this->rMargin = max(0, ($this->w - $new_margin));
22849  	 	 	 	 	 	 	 }
22850  	 	 	 	 	 	 	 if ($x > $new_margin) {
22851  	 	 	 	 	 	 	 	 // adjust x position
22852  	 	 	 	 	 	 	 	 $x = $new_margin;
22853  	 	 	 	 	 	 	 	 if ($new_margin > $this->lMargin) {
22854  	 	 	 	 	 	 	 	 	 // adjust y position
22855  	 	 	 	 	 	 	 	 	 $y = $regdata['yb'] - $h;
22856  	 	 	 	 	 	 	 	 }
22857  	 	 	 	 	 	 	 }
22858  	 	 	 	 	 	 }
22859  	 	 	 	 	 }
22860  	 	 	 	 }
22861  	 	 	 }
22862  	 	 }
22863  	 	 return array($x, $y);
22864  	 }
22865  
22866  	 // --- SVG METHODS ---------------------------------------------------------
22867  
22868  	 /**
22869  	  * Embedd a Scalable Vector Graphics (SVG) image.
22870  	  * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
22871  	  * @param string $file Name of the SVG file or a '@' character followed by the SVG data string.
22872  	  * @param float|null $x Abscissa of the upper-left corner.
22873  	  * @param float|null $y Ordinate of the upper-left corner.
22874  	  * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
22875  	  * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
22876  	  * @param mixed $link URL or identifier returned by AddLink().
22877  	  * @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.
22878  	  * @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>
22879  	  * @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)))
22880  	  * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
22881  	  * @author Nicola Asuni
22882  	  * @since 5.0.000 (2010-05-02)
22883  	  * @public
22884  	  */
22885  	public function ImageSVG($file, $x=null, $y=null, $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
22886  	 	 if ($this->state != 2) {
22887  	 	 	  return;
22888  	 	 }
22889  	 	 // reset SVG vars
22890  	 	 $this->svggradients = array();
22891  	 	 $this->svggradientid = 0;
22892  	 	 $this->svgdefsmode = false;
22893  	 	 $this->svgdefs = array();
22894  	 	 $this->svgclipmode = false;
22895  	 	 $this->svgclippaths = array();
22896  	 	 $this->svgcliptm = array();
22897  	 	 $this->svgclipid = 0;
22898  	 	 $this->svgtext = '';
22899  	 	 $this->svgtextmode = array();
22900  	 	 if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
22901  	 	 	 // convert SVG to raster image using GD or ImageMagick libraries
22902  	 	 	 return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
22903  	 	 }
22904  	 	 if ($file[0] === '@') { // image from string
22905  	 	 	 $this->svgdir = '';
22906  	 	 	 $svgdata = substr($file, 1);
22907  	 	 } else { // SVG file
22908  	 	 	 $this->svgdir = dirname($file);
22909              $svgdata = $this->getCachedFileContents($file);
22910  	 	 }
22911  	 	 if ($svgdata === FALSE) {
22912  	 	 	 $this->Error('SVG file not found: '.$file);
22913  	 	 }
22914  	 	 if (TCPDF_STATIC::empty_string($x)) {
22915  	 	 	 $x = $this->x;
22916  	 	 }
22917  	 	 if (TCPDF_STATIC::empty_string($y)) {
22918  	 	 	 $y = $this->y;
22919  	 	 }
22920  	 	 // check page for no-write regions and adapt page margins if necessary
22921  	 	 list($x, $y) = $this->checkPageRegions($h, $x, $y);
22922  	 	 $k = $this->k;
22923  	 	 $ox = 0;
22924  	 	 $oy = 0;
22925  	 	 $ow = $w;
22926  	 	 $oh = $h;
22927  	 	 $aspect_ratio_align = 'xMidYMid';
22928  	 	 $aspect_ratio_ms = 'meet';
22929  	 	 $regs = array();
22930  	 	 // get original image width and height
22931  	 	 preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
22932  	 	 if (isset($regs[1]) AND !empty($regs[1])) {
22933  	 	 	 $tmp = array();
22934  	 	 	 if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22935  	 	 	 	 $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
22936  	 	 	 }
22937  	 	 	 $tmp = array();
22938  	 	 	 if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22939  	 	 	 	 $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
22940  	 	 	 }
22941  	 	 	 $tmp = array();
22942  	 	 	 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22943  	 	 	 	 $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
22944  	 	 	 }
22945  	 	 	 $tmp = array();
22946  	 	 	 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22947  	 	 	 	 $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
22948  	 	 	 }
22949  	 	 	 $tmp = array();
22950  	 	 	 $view_box = array();
22951  	 	 	 if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
22952  	 	 	 	 if (count($tmp) == 5) {
22953  	 	 	 	 	 array_shift($tmp);
22954  	 	 	 	 	 foreach ($tmp as $key => $val) {
22955  	 	 	 	 	 	 $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
22956  	 	 	 	 	 }
22957  	 	 	 	 	 $ox = $view_box[0];
22958  	 	 	 	 	 $oy = $view_box[1];
22959  	 	 	 	 }
22960  	 	 	 	 // get aspect ratio
22961  	 	 	 	 $tmp = array();
22962  	 	 	 	 if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22963  	 	 	 	 	 $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
22964  	 	 	 	 	 switch (count($aspect_ratio)) {
22965  	 	 	 	 	 	 case 3: {
22966  	 	 	 	 	 	 	 $aspect_ratio_align = $aspect_ratio[1];
22967  	 	 	 	 	 	 	 $aspect_ratio_ms = $aspect_ratio[2];
22968  	 	 	 	 	 	 	 break;
22969  	 	 	 	 	 	 }
22970  	 	 	 	 	 	 case 2: {
22971  	 	 	 	 	 	 	 $aspect_ratio_align = $aspect_ratio[0];
22972  	 	 	 	 	 	 	 $aspect_ratio_ms = $aspect_ratio[1];
22973  	 	 	 	 	 	 	 break;
22974  	 	 	 	 	 	 }
22975  	 	 	 	 	 	 case 1: {
22976  	 	 	 	 	 	 	 $aspect_ratio_align = $aspect_ratio[0];
22977  	 	 	 	 	 	 	 $aspect_ratio_ms = 'meet';
22978  	 	 	 	 	 	 	 break;
22979  	 	 	 	 	 	 }
22980  	 	 	 	 	 }
22981  	 	 	 	 }
22982  	 	 	 }
22983  	 	 }
22984  	 	 if ($ow <= 0) {
22985  	 	 	 $ow = 1;
22986  	 	 }
22987  	 	 if ($oh <= 0) {
22988  	 	 	 $oh = 1;
22989  	 	 }
22990  	 	 // calculate image width and height on document
22991  	 	 if (($w <= 0) AND ($h <= 0)) {
22992  	 	 	 // convert image size to document unit
22993  	 	 	 $w = $ow;
22994  	 	 	 $h = $oh;
22995  	 	 } elseif ($w <= 0) {
22996  	 	 	 $w = $h * $ow / $oh;
22997  	 	 } elseif ($h <= 0) {
22998  	 	 	 $h = $w * $oh / $ow;
22999  	 	 }
23000  	 	 // fit the image on available space
23001  	 	 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
23002  	 	 if ($this->rasterize_vector_images) {
23003  	 	 	 // convert SVG to raster image using GD or ImageMagick libraries
23004  	 	 	 return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
23005  	 	 }
23006  	 	 // set alignment
23007  	 	 $this->img_rb_y = $y + $h;
23008  	 	 // set alignment
23009  	 	 if ($this->rtl) {
23010  	 	 	 if ($palign == 'L') {
23011  	 	 	 	 $ximg = $this->lMargin;
23012  	 	 	 } elseif ($palign == 'C') {
23013  	 	 	 	 $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
23014  	 	 	 } elseif ($palign == 'R') {
23015  	 	 	 	 $ximg = $this->w - $this->rMargin - $w;
23016  	 	 	 } else {
23017  	 	 	 	 $ximg = $x - $w;
23018  	 	 	 }
23019  	 	 	 $this->img_rb_x = $ximg;
23020  	 	 } else {
23021  	 	 	 if ($palign == 'L') {
23022  	 	 	 	 $ximg = $this->lMargin;
23023  	 	 	 } elseif ($palign == 'C') {
23024  	 	 	 	 $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
23025  	 	 	 } elseif ($palign == 'R') {
23026  	 	 	 	 $ximg = $this->w - $this->rMargin - $w;
23027  	 	 	 } else {
23028  	 	 	 	 $ximg = $x;
23029  	 	 	 }
23030  	 	 	 $this->img_rb_x = $ximg + $w;
23031  	 	 }
23032  	 	 // store current graphic vars
23033  	 	 $gvars = $this->getGraphicVars();
23034  	 	 // store SVG position and scale factors
23035  	 	 $svgoffset_x = ($ximg - $ox) * $this->k;
23036  	 	 $svgoffset_y = -($y - $oy) * $this->k;
23037  	 	 if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
23038  	 	 	 $ow = $view_box[2];
23039  	 	 	 $oh = $view_box[3];
23040  	 	 } else {
23041  	 	 	 if ($ow <= 0) {
23042  	 	 	 	 $ow = $w;
23043  	 	 	 }
23044  	 	 	 if ($oh <= 0) {
23045  	 	 	 	 $oh = $h;
23046  	 	 	 }
23047  	 	 }
23048  	 	 $svgscale_x = $w / $ow;
23049  	 	 $svgscale_y = $h / $oh;
23050  	 	 // scaling and alignment
23051  	 	 if ($aspect_ratio_align != 'none') {
23052  	 	 	 // store current scaling values
23053  	 	 	 $svgscale_old_x = $svgscale_x;
23054  	 	 	 $svgscale_old_y = $svgscale_y;
23055  	 	 	 // force uniform scaling
23056  	 	 	 if ($aspect_ratio_ms == 'slice') {
23057  	 	 	 	 // the entire viewport is covered by the viewBox
23058  	 	 	 	 if ($svgscale_x > $svgscale_y) {
23059  	 	 	 	 	 $svgscale_y = $svgscale_x;
23060  	 	 	 	 } elseif ($svgscale_x < $svgscale_y) {
23061  	 	 	 	 	 $svgscale_x = $svgscale_y;
23062  	 	 	 	 }
23063  	 	 	 } else { // meet
23064  	 	 	 	 // the entire viewBox is visible within the viewport
23065  	 	 	 	 if ($svgscale_x < $svgscale_y) {
23066  	 	 	 	 	 $svgscale_y = $svgscale_x;
23067  	 	 	 	 } elseif ($svgscale_x > $svgscale_y) {
23068  	 	 	 	 	 $svgscale_x = $svgscale_y;
23069  	 	 	 	 }
23070  	 	 	 }
23071  	 	 	 // correct X alignment
23072  	 	 	 switch (substr($aspect_ratio_align, 1, 3)) {
23073  	 	 	 	 case 'Min': {
23074  	 	 	 	 	 // do nothing
23075  	 	 	 	 	 break;
23076  	 	 	 	 }
23077  	 	 	 	 case 'Max': {
23078  	 	 	 	 	 $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
23079  	 	 	 	 	 break;
23080  	 	 	 	 }
23081  	 	 	 	 default:
23082  	 	 	 	 case 'Mid': {
23083  	 	 	 	 	 $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
23084  	 	 	 	 	 break;
23085  	 	 	 	 }
23086  	 	 	 }
23087  	 	 	 // correct Y alignment
23088  	 	 	 switch (substr($aspect_ratio_align, 5)) {
23089  	 	 	 	 case 'Min': {
23090  	 	 	 	 	 // do nothing
23091  	 	 	 	 	 break;
23092  	 	 	 	 }
23093  	 	 	 	 case 'Max': {
23094  	 	 	 	 	 $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
23095  	 	 	 	 	 break;
23096  	 	 	 	 }
23097  	 	 	 	 default:
23098  	 	 	 	 case 'Mid': {
23099  	 	 	 	 	 $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
23100  	 	 	 	 	 break;
23101  	 	 	 	 }
23102  	 	 	 }
23103  	 	 }
23104  	 	 // store current page break mode
23105  	 	 $page_break_mode = $this->AutoPageBreak;
23106  	 	 $page_break_margin = $this->getBreakMargin();
23107  	 	 $cell_padding = $this->cell_padding;
23108  	 	 $this->setCellPadding(0);
23109  	 	 $this->setAutoPageBreak(false);
23110  	 	 // save the current graphic state
23111  	 	 $this->_out('q'.$this->epsmarker);
23112  	 	 // set initial clipping mask
23113  	 	 $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array());
23114  	 	 // scale and translate
23115  	 	 $e = $ox * $this->k * (1 - $svgscale_x);
23116  	 	 $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
23117  	 	 $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
23118  	 	 // creates a new XML parser to be used by the other XML functions
23119  	 	 $parser = xml_parser_create('UTF-8');
23120  	 	 // the following function allows to use parser inside object
23121  	 	 xml_set_object($parser, $this);
23122  	 	 // disable case-folding for this XML parser
23123  	 	 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
23124  	 	 // sets the element handler functions for the XML parser
23125  	 	 xml_set_element_handler($parser, 'startSVGElementHandler', 'endSVGElementHandler');
23126  	 	 // sets the character data handler function for the XML parser
23127  	 	 xml_set_character_data_handler($parser, 'segSVGContentHandler');
23128  	 	 // start parsing an XML document
23129  	 	 if (!xml_parse($parser, $svgdata)) {
23130  	 	 	 $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
23131  	 	 	 $this->Error($error_message);
23132  	 	 }
23133  	 	 // free this XML parser
23134  	 	 xml_parser_free($parser);
23135  
23136  	 	 // >= PHP 7.0.0 "explicitly unset the reference to parser to avoid memory leaks"
23137  	 	 unset($parser);
23138  
23139  	 	 // restore previous graphic state
23140  	 	 $this->_out($this->epsmarker.'Q');
23141  	 	 // restore graphic vars
23142  	 	 $this->setGraphicVars($gvars);
23143  	 	 $this->lasth = $gvars['lasth'];
23144  	 	 if (!empty($border)) {
23145  	 	 	 $bx = $this->x;
23146  	 	 	 $by = $this->y;
23147  	 	 	 $this->x = $ximg;
23148  	 	 	 if ($this->rtl) {
23149  	 	 	 	 $this->x += $w;
23150  	 	 	 }
23151  	 	 	 $this->y = $y;
23152  	 	 	 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
23153  	 	 	 $this->x = $bx;
23154  	 	 	 $this->y = $by;
23155  	 	 }
23156  	 	 if ($link) {
23157  	 	 	 $this->Link($ximg, $y, $w, $h, $link, 0);
23158  	 	 }
23159  	 	 // set pointer to align the next text/objects
23160  	 	 switch($align) {
23161  	 	 	 case 'T':{
23162  	 	 	 	 $this->y = $y;
23163  	 	 	 	 $this->x = $this->img_rb_x;
23164  	 	 	 	 break;
23165  	 	 	 }
23166  	 	 	 case 'M':{
23167  	 	 	 	 $this->y = $y + round($h/2);
23168  	 	 	 	 $this->x = $this->img_rb_x;
23169  	 	 	 	 break;
23170  	 	 	 }
23171  	 	 	 case 'B':{
23172  	 	 	 	 $this->y = $this->img_rb_y;
23173  	 	 	 	 $this->x = $this->img_rb_x;
23174  	 	 	 	 break;
23175  	 	 	 }
23176  	 	 	 case 'N':{
23177  	 	 	 	 $this->setY($this->img_rb_y);
23178  	 	 	 	 break;
23179  	 	 	 }
23180  	 	 	 default:{
23181  	 	 	 	 // restore pointer to starting position
23182  	 	 	 	 $this->x = $gvars['x'];
23183  	 	 	 	 $this->y = $gvars['y'];
23184  	 	 	 	 $this->page = $gvars['page'];
23185  	 	 	 	 $this->current_column = $gvars['current_column'];
23186  	 	 	 	 $this->tMargin = $gvars['tMargin'];
23187  	 	 	 	 $this->bMargin = $gvars['bMargin'];
23188  	 	 	 	 $this->w = $gvars['w'];
23189  	 	 	 	 $this->h = $gvars['h'];
23190  	 	 	 	 $this->wPt = $gvars['wPt'];
23191  	 	 	 	 $this->hPt = $gvars['hPt'];
23192  	 	 	 	 $this->fwPt = $gvars['fwPt'];
23193  	 	 	 	 $this->fhPt = $gvars['fhPt'];
23194  	 	 	 	 break;
23195  	 	 	 }
23196  	 	 }
23197  	 	 $this->endlinex = $this->img_rb_x;
23198  	 	 // restore page break
23199  	 	 $this->setAutoPageBreak($page_break_mode, $page_break_margin);
23200  	 	 $this->cell_padding = $cell_padding;
23201  	 }
23202  
23203  	 /**
23204  	  * Convert SVG transformation matrix to PDF.
23205  	  * @param array $tm original SVG transformation matrix
23206  	  * @return array transformation matrix
23207  	  * @protected
23208  	  * @since 5.0.000 (2010-05-02)
23209  	  */
23210  	protected function convertSVGtMatrix($tm) {
23211  	 	 $a = $tm[0];
23212  	 	 $b = -$tm[1];
23213  	 	 $c = -$tm[2];
23214  	 	 $d = $tm[3];
23215  	 	 $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
23216  	 	 $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
23217  	 	 $x = 0;
23218  	 	 $y = $this->h * $this->k;
23219  	 	 $e = ($x * (1 - $a)) - ($y * $c) + $e;
23220  	 	 $f = ($y * (1 - $d)) - ($x * $b) + $f;
23221  	 	 return array($a, $b, $c, $d, $e, $f);
23222  	 }
23223  
23224  	 /**
23225  	  * Apply SVG graphic transformation matrix.
23226  	  * @param array $tm original SVG transformation matrix
23227  	  * @protected
23228  	  * @since 5.0.000 (2010-05-02)
23229  	  */
23230  	protected function SVGTransform($tm) {
23231  	 	 $this->Transform($this->convertSVGtMatrix($tm));
23232  	 }
23233  
23234  	 /**
23235  	  * Apply the requested SVG styles (*** TO BE COMPLETED ***)
23236  	  * @param array $svgstyle array of SVG styles to apply
23237  	  * @param array $prevsvgstyle array of previous SVG style
23238  	  * @param int $x X origin of the bounding box
23239  	  * @param int $y Y origin of the bounding box
23240  	  * @param int $w width of the bounding box
23241  	  * @param int $h height of the bounding box
23242  	  * @param string $clip_function clip function
23243  	  * @param array $clip_params array of parameters for clipping function
23244  	  * @return string style
23245  	  * @author Nicola Asuni
23246  	  * @since 5.0.000 (2010-05-02)
23247  	  * @protected
23248  	  */
23249  	protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
23250  	 	 if ($this->state != 2) {
23251  	 	 	  return;
23252  	 	 }
23253  	 	 $objstyle = '';
23254  	 	 $minlen = (0.01 / $this->k); // minimum acceptable length
23255  	 	 if (!isset($svgstyle['opacity'])) {
23256  	 	 	 return $objstyle;
23257  	 	 }
23258  	 	 // clip-path
23259  	 	 $regs = array();
23260  	 	 if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
23261  	 	 	 $clip_path = $this->svgclippaths[$regs[1]];
23262  	 	 	 foreach ($clip_path as $cp) {
23263  	 	 	 	 $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
23264  	 	 	 }
23265  	 	 }
23266  	 	 // opacity
23267  	 	 if ($svgstyle['opacity'] != 1) {
23268  	 	 	 $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
23269  	 	 }
23270  	 	 // color
23271  	 	 $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
23272  	 	 $this->setFillColorArray($fill_color);
23273  	 	 // text color
23274  	 	 $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
23275  	 	 $this->setTextColorArray($text_color);
23276  	 	 // clip
23277  	 	 if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
23278  	 	 	 $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
23279  	 	 	 $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
23280  	 	 	 $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
23281  	 	 	 $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
23282  	 	 	 $cx = $x + $left;
23283  	 	 	 $cy = $y + $top;
23284  	 	 	 $cw = $w - $left - $right;
23285  	 	 	 $ch = $h - $top - $bottom;
23286  	 	 	 if ($svgstyle['clip-rule'] == 'evenodd') {
23287  	 	 	 	 $clip_rule = 'CNZ';
23288  	 	 	 } else {
23289  	 	 	 	 $clip_rule = 'CEO';
23290  	 	 	 }
23291  	 	 	 $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
23292  	 	 }
23293  	 	 // fill
23294  	 	 $regs = array();
23295  	 	 if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
23296  	 	 	 // gradient
23297  	 	 	 $gradient = $this->svggradients[$regs[1]];
23298  	 	 	 if (isset($gradient['xref'])) {
23299  	 	 	 	 // reference to another gradient definition
23300  	 	 	 	 $newgradient = $this->svggradients[$gradient['xref']];
23301  	 	 	 	 $newgradient['coords'] = $gradient['coords'];
23302  	 	 	 	 $newgradient['mode'] = $gradient['mode'];
23303  	 	 	 	 $newgradient['type'] = $gradient['type'];
23304  	 	 	 	 $newgradient['gradientUnits'] = $gradient['gradientUnits'];
23305  	 	 	 	 if (isset($gradient['gradientTransform'])) {
23306  	 	 	 	 	 $newgradient['gradientTransform'] = $gradient['gradientTransform'];
23307  	 	 	 	 }
23308  	 	 	 	 $gradient = $newgradient;
23309  	 	 	 }
23310  	 	 	 //save current Graphic State
23311  	 	 	 $this->_outSaveGraphicsState();
23312  	 	 	 //set clipping area
23313  	 	 	 if (!empty($clip_function) AND method_exists($this, $clip_function)) {
23314  	 	 	 	 $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
23315  	 	 	 	 if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
23316  	 	 	 	 	 list($x, $y, $w, $h) = $bbox;
23317  	 	 	 	 }
23318  	 	 	 }
23319  	 	 	 if ($gradient['mode'] == 'measure') {
23320  	 	 	 	 if (!isset($gradient['coords'][4])) {
23321  	 	 	 	 	 $gradient['coords'][4] = 0.5;
23322  	 	 	 	 }
23323  	 	 	 	 if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
23324  	 	 	 	 	 $gtm = $gradient['gradientTransform'];
23325  	 	 	 	 	 // apply transformation matrix
23326  	 	 	 	 	 $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
23327  	 	 	 	 	 $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
23328  	 	 	 	 	 $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
23329  	 	 	 	 	 $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
23330  	 	 	 	 	 $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
23331  	 	 	 	 	 $gradient['coords'][0] = $xa;
23332  	 	 	 	 	 $gradient['coords'][1] = $ya;
23333  	 	 	 	 	 $gradient['coords'][2] = $xb;
23334  	 	 	 	 	 $gradient['coords'][3] = $yb;
23335  	 	 	 	 	 $gradient['coords'][4] = $r;
23336  	 	 	 	 }
23337  	 	 	 	 // convert SVG coordinates to user units
23338  	 	 	 	 $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
23339  	 	 	 	 $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
23340  	 	 	 	 $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
23341  	 	 	 	 $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
23342  	 	 	 	 $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
23343  	 	 	 	 if ($w <= $minlen) {
23344  	 	 	 	 	 $w = $minlen;
23345  	 	 	 	 }
23346  	 	 	 	 if ($h <= $minlen) {
23347  	 	 	 	 	 $h = $minlen;
23348  	 	 	 	 }
23349  	 	 	 	 // shift units
23350  	 	 	 	 if ($gradient['gradientUnits'] == 'objectBoundingBox') {
23351  	 	 	 	 	 // convert to SVG coordinate system
23352  	 	 	 	 	 $gradient['coords'][0] += $x;
23353  	 	 	 	 	 $gradient['coords'][1] += $y;
23354  	 	 	 	 	 $gradient['coords'][2] += $x;
23355  	 	 	 	 	 $gradient['coords'][3] += $y;
23356  	 	 	 	 }
23357  	 	 	 	 // calculate percentages
23358  	 	 	 	 $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
23359  	 	 	 	 $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
23360  	 	 	 	 $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
23361  	 	 	 	 $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
23362  	 	 	 	 $gradient['coords'][4] /= $w;
23363  	 	 	 } elseif ($gradient['mode'] == 'percentage') {
23364  	 	 	 	 foreach($gradient['coords'] as $key => $val) {
23365  	 	 	 	 	 $gradient['coords'][$key] = (intval($val) / 100);
23366  	 	 	 	 	 if ($val < 0) {
23367  	 	 	 	 	 	 $gradient['coords'][$key] = 0;
23368  	 	 	 	 	 } elseif ($val > 1) {
23369  	 	 	 	 	 	 $gradient['coords'][$key] = 1;
23370  	 	 	 	 	 }
23371  	 	 	 	 }
23372  	 	 	 }
23373  	 	 	 if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
23374  	 	 	 	 // single color (no shading)
23375  	 	 	 	 $gradient['coords'][0] = 1;
23376  	 	 	 	 $gradient['coords'][1] = 0;
23377  	 	 	 	 $gradient['coords'][2] = 0.999;
23378  	 	 	 	 $gradient['coords'][3] = 0;
23379  	 	 	 }
23380  	 	 	 // swap Y coordinates
23381  	 	 	 $tmp = $gradient['coords'][1];
23382  	 	 	 $gradient['coords'][1] = $gradient['coords'][3];
23383  	 	 	 $gradient['coords'][3] = $tmp;
23384  	 	 	 // set transformation map for gradient
23385  	 	 	 $cy = ($this->h - $y);
23386  	 	 	 if ($gradient['type'] == 3) {
23387  	 	 	 	 // circular gradient
23388  	 	 	 	 $cy -= ($gradient['coords'][1] * ($w + $h));
23389  	 	 	 	 $h = $w = max($w, $h);
23390  	 	 	 } else {
23391  	 	 	 	 $cy -= $h;
23392  	 	 	 }
23393  	 	 	 $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), ($cy * $this->k)));
23394  	 	 	 if (count($gradient['stops']) > 1) {
23395  	 	 	 	 $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
23396  	 	 	 }
23397  	 	 } elseif ($svgstyle['fill'] != 'none') {
23398  	 	 	 $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
23399  	 	 	 if ($svgstyle['fill-opacity'] != 1) {
23400  	 	 	 	 $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
23401  	 	 	 }
23402  	 	 	 $this->setFillColorArray($fill_color);
23403  	 	 	 if ($svgstyle['fill-rule'] == 'evenodd') {
23404  	 	 	 	 $objstyle .= 'F*';
23405  	 	 	 } else {
23406  	 	 	 	 $objstyle .= 'F';
23407  	 	 	 }
23408  	 	 }
23409  	 	 // stroke
23410  	 	 if ($svgstyle['stroke'] != 'none') {
23411  	 	 	 if ($svgstyle['stroke-opacity'] != 1) {
23412  	 	 	 	 $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
23413  	 	 	 } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) {
23414  	 	 	 	 $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha['ca'], false);
23415  	 	 	 }
23416  	 	 	 $stroke_style = array(
23417  	 	 	 	 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
23418  	 	 	 	 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
23419  	 	 	 	 'cap' => $svgstyle['stroke-linecap'],
23420  	 	 	 	 'join' => $svgstyle['stroke-linejoin']
23421  	 	 	 	 );
23422  	 	 	 if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
23423  	 	 	 	 $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
23424  	 	 	 }
23425  	 	 	 $this->setLineStyle($stroke_style);
23426  	 	 	 $objstyle .= 'D';
23427  	 	 }
23428  	 	 // font
23429  	 	 $regs = array();
23430  	 	 if (!empty($svgstyle['font'])) {
23431  	 	 	 if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
23432  	 	 	 	 $font_family = $this->getFontFamilyName($regs[1]);
23433  	 	 	 } else {
23434  	 	 	 	 $font_family = $svgstyle['font-family'];
23435  	 	 	 }
23436  	 	 	 if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23437  	 	 	 	 $font_size = trim($regs[1]);
23438  	 	 	 } else {
23439  	 	 	 	 $font_size = $svgstyle['font-size'];
23440  	 	 	 }
23441  	 	 	 if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23442  	 	 	 	 $font_style = trim($regs[1]);
23443  	 	 	 } else {
23444  	 	 	 	 $font_style = $svgstyle['font-style'];
23445  	 	 	 }
23446  	 	 	 if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23447  	 	 	 	 $font_weight = trim($regs[1]);
23448  	 	 	 } else {
23449  	 	 	 	 $font_weight = $svgstyle['font-weight'];
23450  	 	 	 }
23451  	 	 	 if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23452  	 	 	 	 $font_stretch = trim($regs[1]);
23453  	 	 	 } else {
23454  	 	 	 	 $font_stretch = $svgstyle['font-stretch'];
23455  	 	 	 }
23456  	 	 	 if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23457  	 	 	 	 $font_spacing = trim($regs[1]);
23458  	 	 	 } else {
23459  	 	 	 	 $font_spacing = $svgstyle['letter-spacing'];
23460  	 	 	 }
23461  	 	 } else {
23462  	 	 	 $font_family = $this->getFontFamilyName($svgstyle['font-family']);
23463  	 	 	 $font_size = $svgstyle['font-size'];
23464  	 	 	 $font_style = $svgstyle['font-style'];
23465  	 	 	 $font_weight = $svgstyle['font-weight'];
23466  	 	 	 $font_stretch = $svgstyle['font-stretch'];
23467  	 	 	 $font_spacing = $svgstyle['letter-spacing'];
23468  	 	 }
23469  	 	 $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
23470  	 	 $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
23471  	 	 $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
23472  	 	 switch ($font_style) {
23473  	 	 	 case 'italic': {
23474  	 	 	 	 $font_style = 'I';
23475  	 	 	 	 break;
23476  	 	 	 }
23477  	 	 	 case 'oblique': {
23478  	 	 	 	 $font_style = 'I';
23479  	 	 	 	 break;
23480  	 	 	 }
23481  	 	 	 default:
23482  	 	 	 case 'normal': {
23483  	 	 	 	 $font_style = '';
23484  	 	 	 	 break;
23485  	 	 	 }
23486  	 	 }
23487  	 	 switch ($font_weight) {
23488  	 	 	 case 'bold':
23489  	 	 	 case 'bolder': {
23490  	 	 	 	 $font_style .= 'B';
23491  	 	 	 	 break;
23492  	 	 	 }
23493  	 	 	 case 'normal': {
23494  	 	 	 	 if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) {
23495  	 	 	 	 	 $font_family = substr($font_family, 0, -2).'I';
23496  	 	 	 	 } elseif (substr($font_family, -1) == 'B') {
23497  	 	 	 	 	 $font_family = substr($font_family, 0, -1);
23498  	 	 	 	 }
23499  	 	 	 	 break;
23500  	 	 	 }
23501  	 	 }
23502  	 	 switch ($svgstyle['text-decoration']) {
23503  	 	 	 case 'underline': {
23504  	 	 	 	 $font_style .= 'U';
23505  	 	 	 	 break;
23506  	 	 	 }
23507  	 	 	 case 'overline': {
23508  	 	 	 	 $font_style .= 'O';
23509  	 	 	 	 break;
23510  	 	 	 }
23511  	 	 	 case 'line-through': {
23512  	 	 	 	 $font_style .= 'D';
23513  	 	 	 	 break;
23514  	 	 	 }
23515  	 	 	 default:
23516  	 	 	 case 'none': {
23517  	 	 	 	 break;
23518  	 	 	 }
23519  	 	 }
23520  	 	 $this->setFont($font_family, $font_style, $font_size);
23521  	 	 $this->setFontStretching($font_stretch);
23522  	 	 $this->setFontSpacing($font_spacing);
23523  	 	 return $objstyle;
23524  	 }
23525  
23526  	 /**
23527  	  * Draws an SVG path
23528  	  * @param string $d attribute d of the path SVG element
23529  	  * @param string $style Style of rendering. Possible values are:
23530  	  * <ul>
23531  	  *	  <li>D or empty string: Draw (default).</li>
23532  	  *	  <li>F: Fill.</li>
23533  	  *	  <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
23534  	  *	  <li>DF or FD: Draw and fill.</li>
23535  	  *	  <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
23536  	  *	  <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
23537  	  *	  <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
23538  	  * </ul>
23539  	  * @return array of container box measures (x, y, w, h)
23540  	  * @author Nicola Asuni
23541  	  * @since 5.0.000 (2010-05-02)
23542  	  * @protected
23543  	  */
23544  	protected function SVGPath($d, $style='') {
23545  	 	 if ($this->state != 2) {
23546  	 	 	 return;
23547  	 	 }
23548  	 	 // set fill/stroke style
23549  	 	 $op = TCPDF_STATIC::getPathPaintOperator($style, '');
23550  	 	 if (empty($op)) {
23551  	 	 	 return;
23552  	 	 }
23553  	 	 $paths = array();
23554  	 	 $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
23555  	 	 $d = preg_replace('/(\.[0-9]+)(\.)/s', '\\1 \\2', $d);
23556  	 	 preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
23557  	 	 $x = 0;
23558  	 	 $y = 0;
23559  	 	 $x1 = 0;
23560  	 	 $y1 = 0;
23561  	 	 $x2 = 0;
23562  	 	 $y2 = 0;
23563  	 	 $xmin = 2147483647;
23564  	 	 $xmax = 0;
23565  	 	 $ymin = 2147483647;
23566  	 	 $ymax = 0;
23567  	 	 $xinitial = 0;
23568  	 	 $yinitial = 0;
23569  	 	 $relcoord = false;
23570  	 	 $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
23571  	 	 $firstcmd = true; // used to print first point
23572  	 	 // draw curve pieces
23573  	 	 foreach ($paths as $key => $val) {
23574  	 	 	 // get curve type
23575  	 	 	 $cmd = trim($val[1]);
23576  	 	 	 if (strtolower($cmd) == $cmd) {
23577  	 	 	 	 // use relative coordinated instead of absolute
23578  	 	 	 	 $relcoord = true;
23579  	 	 	 	 $xoffset = $x;
23580  	 	 	 	 $yoffset = $y;
23581  	 	 	 } else {
23582  	 	 	 	 $relcoord = false;
23583  	 	 	 	 $xoffset = 0;
23584  	 	 	 	 $yoffset = 0;
23585  	 	 	 }
23586  	 	 	 $params = array();
23587  	 	 	 if (isset($val[2])) {
23588  	 	 	 	 // get curve parameters
23589  	 	 	 	 $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
23590  	 	 	 	 $params = array();
23591  	 	 	 	 foreach ($rawparams as $ck => $cp) {
23592  	 	 	 	 	 $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
23593  	 	 	 	 	 if (abs($params[$ck]) < $minlen) {
23594  	 	 	 	 	 	 // approximate little values to zero
23595  	 	 	 	 	 	 $params[$ck] = 0;
23596  	 	 	 	 	 }
23597  	 	 	 	 }
23598  	 	 	 }
23599  	 	 	 // store current origin point
23600  	 	 	 $x0 = $x;
23601  	 	 	 $y0 = $y;
23602  	 	 	 switch (strtoupper($cmd)) {
23603  	 	 	 	 case 'M': { // moveto
23604  	 	 	 	 	 foreach ($params as $ck => $cp) {
23605  	 	 	 	 	 	 if (($ck % 2) == 0) {
23606  	 	 	 	 	 	 	 $x = $cp + $xoffset;
23607  	 	 	 	 	 	 } else {
23608  	 	 	 	 	 	 	 $y = $cp + $yoffset;
23609  	 	 	 	 	 	 	 if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23610  	 	 	 	 	 	 	 	 if ($ck == 1) {
23611  	 	 	 	 	 	 	 	 	 $this->_outPoint($x, $y);
23612  	 	 	 	 	 	 	 	 	 $firstcmd = false;
23613  	 	 	 	 	 	 	 	 	 $xinitial = $x;
23614  	 	 	 	 	 	 	 	 	 $yinitial = $y;
23615  	 	 	 	 	 	 	 	 } else {
23616  	 	 	 	 	 	 	 	 	 $this->_outLine($x, $y);
23617  	 	 	 	 	 	 	 	 }
23618  	 	 	 	 	 	 	 	 $x0 = $x;
23619  	 	 	 	 	 	 	 	 $y0 = $y;
23620  	 	 	 	 	 	 	 }
23621  	 	 	 	 	 	 	 $xmin = min($xmin, $x);
23622  	 	 	 	 	 	 	 $ymin = min($ymin, $y);
23623  	 	 	 	 	 	 	 $xmax = max($xmax, $x);
23624  	 	 	 	 	 	 	 $ymax = max($ymax, $y);
23625  	 	 	 	 	 	 	 if ($relcoord) {
23626  	 	 	 	 	 	 	 	 $xoffset = $x;
23627  	 	 	 	 	 	 	 	 $yoffset = $y;
23628  	 	 	 	 	 	 	 }
23629  	 	 	 	 	 	 }
23630  	 	 	 	 	 }
23631  	 	 	 	 	 break;
23632  	 	 	 	 }
23633  	 	 	 	 case 'L': { // lineto
23634  	 	 	 	 	 foreach ($params as $ck => $cp) {
23635  	 	 	 	 	 	 if (($ck % 2) == 0) {
23636  	 	 	 	 	 	 	 $x = $cp + $xoffset;
23637  	 	 	 	 	 	 } else {
23638  	 	 	 	 	 	 	 $y = $cp + $yoffset;
23639  	 	 	 	 	 	 	 if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23640  	 	 	 	 	 	 	 	 $this->_outLine($x, $y);
23641  	 	 	 	 	 	 	 	 $x0 = $x;
23642  	 	 	 	 	 	 	 	 $y0 = $y;
23643  	 	 	 	 	 	 	 }
23644  	 	 	 	 	 	 	 $xmin = min($xmin, $x);
23645  	 	 	 	 	 	 	 $ymin = min($ymin, $y);
23646  	 	 	 	 	 	 	 $xmax = max($xmax, $x);
23647  	 	 	 	 	 	 	 $ymax = max($ymax, $y);
23648  	 	 	 	 	 	 	 if ($relcoord) {
23649  	 	 	 	 	 	 	 	 $xoffset = $x;
23650  	 	 	 	 	 	 	 	 $yoffset = $y;
23651  	 	 	 	 	 	 	 }
23652  	 	 	 	 	 	 }
23653  	 	 	 	 	 }
23654  	 	 	 	 	 break;
23655  	 	 	 	 }
23656  	 	 	 	 case 'H': { // horizontal lineto
23657  	 	 	 	 	 foreach ($params as $ck => $cp) {
23658  	 	 	 	 	 	 $x = $cp + $xoffset;
23659  	 	 	 	 	 	 if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23660  	 	 	 	 	 	 	 $this->_outLine($x, $y);
23661  	 	 	 	 	 	 	 $x0 = $x;
23662  	 	 	 	 	 	 	 $y0 = $y;
23663  	 	 	 	 	 	 }
23664  	 	 	 	 	 	 $xmin = min($xmin, $x);
23665  	 	 	 	 	 	 $xmax = max($xmax, $x);
23666  	 	 	 	 	 	 if ($relcoord) {
23667  	 	 	 	 	 	 	 $xoffset = $x;
23668  	 	 	 	 	 	 }
23669  	 	 	 	 	 }
23670  	 	 	 	 	 break;
23671  	 	 	 	 }
23672  	 	 	 	 case 'V': { // vertical lineto
23673  	 	 	 	 	 foreach ($params as $ck => $cp) {
23674  	 	 	 	 	 	 $y = $cp + $yoffset;
23675  	 	 	 	 	 	 if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23676  	 	 	 	 	 	 	 $this->_outLine($x, $y);
23677  	 	 	 	 	 	 	 $x0 = $x;
23678  	 	 	 	 	 	 	 $y0 = $y;
23679  	 	 	 	 	 	 }
23680  	 	 	 	 	 	 $ymin = min($ymin, $y);
23681  	 	 	 	 	 	 $ymax = max($ymax, $y);
23682  	 	 	 	 	 	 if ($relcoord) {
23683  	 	 	 	 	 	 	 $yoffset = $y;
23684  	 	 	 	 	 	 }
23685  	 	 	 	 	 }
23686  	 	 	 	 	 break;
23687  	 	 	 	 }
23688  	 	 	 	 case 'C': { // curveto
23689  	 	 	 	 	 foreach ($params as $ck => $cp) {
23690  	 	 	 	 	 	 $params[$ck] = $cp;
23691  	 	 	 	 	 	 if ((($ck + 1) % 6) == 0) {
23692  	 	 	 	 	 	 	 $x1 = $params[($ck - 5)] + $xoffset;
23693  	 	 	 	 	 	 	 $y1 = $params[($ck - 4)] + $yoffset;
23694  	 	 	 	 	 	 	 $x2 = $params[($ck - 3)] + $xoffset;
23695  	 	 	 	 	 	 	 $y2 = $params[($ck - 2)] + $yoffset;
23696  	 	 	 	 	 	 	 $x = $params[($ck - 1)] + $xoffset;
23697  	 	 	 	 	 	 	 $y = $params[($ck)] + $yoffset;
23698  	 	 	 	 	 	 	 $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
23699  	 	 	 	 	 	 	 $xmin = min($xmin, $x, $x1, $x2);
23700  	 	 	 	 	 	 	 $ymin = min($ymin, $y, $y1, $y2);
23701  	 	 	 	 	 	 	 $xmax = max($xmax, $x, $x1, $x2);
23702  	 	 	 	 	 	 	 $ymax = max($ymax, $y, $y1, $y2);
23703  	 	 	 	 	 	 	 if ($relcoord) {
23704  	 	 	 	 	 	 	 	 $xoffset = $x;
23705  	 	 	 	 	 	 	 	 $yoffset = $y;
23706  	 	 	 	 	 	 	 }
23707  	 	 	 	 	 	 }
23708  	 	 	 	 	 }
23709  	 	 	 	 	 break;
23710  	 	 	 	 }
23711  	 	 	 	 case 'S': { // shorthand/smooth curveto
23712  	 	 	 	 	 foreach ($params as $ck => $cp) {
23713  	 	 	 	 	 	 $params[$ck] = $cp;
23714  	 	 	 	 	 	 if ((($ck + 1) % 4) == 0) {
23715  	 	 	 	 	 	 	 if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
23716  	 	 	 	 	 	 	 	 $x1 = (2 * $x) - $x2;
23717  	 	 	 	 	 	 	 	 $y1 = (2 * $y) - $y2;
23718  	 	 	 	 	 	 	 } else {
23719  	 	 	 	 	 	 	 	 $x1 = $x;
23720  	 	 	 	 	 	 	 	 $y1 = $y;
23721  	 	 	 	 	 	 	 }
23722  	 	 	 	 	 	 	 $x2 = $params[($ck - 3)] + $xoffset;
23723  	 	 	 	 	 	 	 $y2 = $params[($ck - 2)] + $yoffset;
23724  	 	 	 	 	 	 	 $x = $params[($ck - 1)] + $xoffset;
23725  	 	 	 	 	 	 	 $y = $params[($ck)] + $yoffset;
23726  	 	 	 	 	 	 	 $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
23727  	 	 	 	 	 	 	 $xmin = min($xmin, $x, $x1, $x2);
23728  	 	 	 	 	 	 	 $ymin = min($ymin, $y, $y1, $y2);
23729  	 	 	 	 	 	 	 $xmax = max($xmax, $x, $x1, $x2);
23730  	 	 	 	 	 	 	 $ymax = max($ymax, $y, $y1, $y2);
23731  	 	 	 	 	 	 	 if ($relcoord) {
23732  	 	 	 	 	 	 	 	 $xoffset = $x;
23733  	 	 	 	 	 	 	 	 $yoffset = $y;
23734  	 	 	 	 	 	 	 }
23735  	 	 	 	 	 	 }
23736  	 	 	 	 	 }
23737  	 	 	 	 	 break;
23738  	 	 	 	 }
23739  	 	 	 	 case 'Q': { // quadratic Bezier curveto
23740  	 	 	 	 	 foreach ($params as $ck => $cp) {
23741  	 	 	 	 	 	 $params[$ck] = $cp;
23742  	 	 	 	 	 	 if ((($ck + 1) % 4) == 0) {
23743  	 	 	 	 	 	 	 // convert quadratic points to cubic points
23744  	 	 	 	 	 	 	 $x1 = $params[($ck - 3)] + $xoffset;
23745  	 	 	 	 	 	 	 $y1 = $params[($ck - 2)] + $yoffset;
23746  	 	 	 	 	 	 	 $xa = ($x + (2 * $x1)) / 3;
23747  	 	 	 	 	 	 	 $ya = ($y + (2 * $y1)) / 3;
23748  	 	 	 	 	 	 	 $x = $params[($ck - 1)] + $xoffset;
23749  	 	 	 	 	 	 	 $y = $params[($ck)] + $yoffset;
23750  	 	 	 	 	 	 	 $xb = ($x + (2 * $x1)) / 3;
23751  	 	 	 	 	 	 	 $yb = ($y + (2 * $y1)) / 3;
23752  	 	 	 	 	 	 	 $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
23753  	 	 	 	 	 	 	 $xmin = min($xmin, $x, $xa, $xb);
23754  	 	 	 	 	 	 	 $ymin = min($ymin, $y, $ya, $yb);
23755  	 	 	 	 	 	 	 $xmax = max($xmax, $x, $xa, $xb);
23756  	 	 	 	 	 	 	 $ymax = max($ymax, $y, $ya, $yb);
23757  	 	 	 	 	 	 	 if ($relcoord) {
23758  	 	 	 	 	 	 	 	 $xoffset = $x;
23759  	 	 	 	 	 	 	 	 $yoffset = $y;
23760  	 	 	 	 	 	 	 }
23761  	 	 	 	 	 	 }
23762  	 	 	 	 	 }
23763  	 	 	 	 	 break;
23764  	 	 	 	 }
23765  	 	 	 	 case 'T': { // shorthand/smooth quadratic Bezier curveto
23766  	 	 	 	 	 foreach ($params as $ck => $cp) {
23767  	 	 	 	 	 	 $params[$ck] = $cp;
23768  	 	 	 	 	 	 if (($ck % 2) != 0) {
23769  	 	 	 	 	 	 	 if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
23770  	 	 	 	 	 	 	 	 $x1 = (2 * $x) - $x1;
23771  	 	 	 	 	 	 	 	 $y1 = (2 * $y) - $y1;
23772  	 	 	 	 	 	 	 } else {
23773  	 	 	 	 	 	 	 	 $x1 = $x;
23774  	 	 	 	 	 	 	 	 $y1 = $y;
23775  	 	 	 	 	 	 	 }
23776  	 	 	 	 	 	 	 // convert quadratic points to cubic points
23777  	 	 	 	 	 	 	 $xa = ($x + (2 * $x1)) / 3;
23778  	 	 	 	 	 	 	 $ya = ($y + (2 * $y1)) / 3;
23779  	 	 	 	 	 	 	 $x = $params[($ck - 1)] + $xoffset;
23780  	 	 	 	 	 	 	 $y = $params[($ck)] + $yoffset;
23781  	 	 	 	 	 	 	 $xb = ($x + (2 * $x1)) / 3;
23782  	 	 	 	 	 	 	 $yb = ($y + (2 * $y1)) / 3;
23783  	 	 	 	 	 	 	 $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
23784  	 	 	 	 	 	 	 $xmin = min($xmin, $x, $xa, $xb);
23785  	 	 	 	 	 	 	 $ymin = min($ymin, $y, $ya, $yb);
23786  	 	 	 	 	 	 	 $xmax = max($xmax, $x, $xa, $xb);
23787  	 	 	 	 	 	 	 $ymax = max($ymax, $y, $ya, $yb);
23788  	 	 	 	 	 	 	 if ($relcoord) {
23789  	 	 	 	 	 	 	 	 $xoffset = $x;
23790  	 	 	 	 	 	 	 	 $yoffset = $y;
23791  	 	 	 	 	 	 	 }
23792  	 	 	 	 	 	 }
23793  	 	 	 	 	 }
23794  	 	 	 	 	 break;
23795  	 	 	 	 }
23796  	 	 	 	 case 'A': { // elliptical arc
23797  	 	 	 	 	 foreach ($params as $ck => $cp) {
23798  	 	 	 	 	 	 $params[$ck] = $cp;
23799  	 	 	 	 	 	 if ((($ck + 1) % 7) == 0) {
23800  	 	 	 	 	 	 	 $x0 = $x;
23801  	 	 	 	 	 	 	 $y0 = $y;
23802  	 	 	 	 	 	 	 $rx = max(abs($params[($ck - 6)]), .000000001);
23803  	 	 	 	 	 	 	 $ry = max(abs($params[($ck - 5)]), .000000001);
23804  	 	 	 	 	 	 	 $ang = -$rawparams[($ck - 4)];
23805  	 	 	 	 	 	 	 $angle = deg2rad($ang);
23806  	 	 	 	 	 	 	 $fa = $rawparams[($ck - 3)]; // large-arc-flag
23807  	 	 	 	 	 	 	 $fs = $rawparams[($ck - 2)]; // sweep-flag
23808  	 	 	 	 	 	 	 $x = $params[($ck - 1)] + $xoffset;
23809  	 	 	 	 	 	 	 $y = $params[$ck] + $yoffset;
23810  	 	 	 	 	 	 	 if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
23811  	 	 	 	 	 	 	 	 // endpoints are almost identical
23812  	 	 	 	 	 	 	 	 $xmin = min($xmin, $x);
23813  	 	 	 	 	 	 	 	 $ymin = min($ymin, $y);
23814  	 	 	 	 	 	 	 	 $xmax = max($xmax, $x);
23815  	 	 	 	 	 	 	 	 $ymax = max($ymax, $y);
23816  	 	 	 	 	 	 	 } else {
23817  	 	 	 	 	 	 	 	 $cos_ang = cos($angle);
23818  	 	 	 	 	 	 	 	 $sin_ang = sin($angle);
23819  	 	 	 	 	 	 	 	 $a = (($x0 - $x) / 2);
23820  	 	 	 	 	 	 	 	 $b = (($y0 - $y) / 2);
23821  	 	 	 	 	 	 	 	 $xa = ($a * $cos_ang) - ($b * $sin_ang);
23822  	 	 	 	 	 	 	 	 $ya = ($a * $sin_ang) + ($b * $cos_ang);
23823  	 	 	 	 	 	 	 	 $rx2 = $rx * $rx;
23824  	 	 	 	 	 	 	 	 $ry2 = $ry * $ry;
23825  	 	 	 	 	 	 	 	 $xa2 = $xa * $xa;
23826  	 	 	 	 	 	 	 	 $ya2 = $ya * $ya;
23827  	 	 	 	 	 	 	 	 $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
23828  	 	 	 	 	 	 	 	 if ($delta > 1) {
23829  	 	 	 	 	 	 	 	 	 $rx *= sqrt($delta);
23830  	 	 	 	 	 	 	 	 	 $ry *= sqrt($delta);
23831  	 	 	 	 	 	 	 	 	 $rx2 = $rx * $rx;
23832  	 	 	 	 	 	 	 	 	 $ry2 = $ry * $ry;
23833  	 	 	 	 	 	 	 	 }
23834  	 	 	 	 	 	 	 	 $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
23835  	 	 	 	 	 	 	 	 if ($numerator < 0) {
23836  	 	 	 	 	 	 	 	 	 $root = 0;
23837  	 	 	 	 	 	 	 	 } else {
23838  	 	 	 	 	 	 	 	 	 $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
23839  	 	 	 	 	 	 	 	 }
23840  	 	 	 	 	 	 	 	 if ($fa == $fs){
23841  	 	 	 	 	 	 	 	 	 $root *= -1;
23842  	 	 	 	 	 	 	 	 }
23843  	 	 	 	 	 	 	 	 $cax = $root * (($rx * $ya) / $ry);
23844  	 	 	 	 	 	 	 	 $cay = -$root * (($ry * $xa) / $rx);
23845  	 	 	 	 	 	 	 	 // coordinates of ellipse center
23846  	 	 	 	 	 	 	 	 $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
23847  	 	 	 	 	 	 	 	 $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
23848  	 	 	 	 	 	 	 	 // get angles
23849  	 	 	 	 	 	 	 	 $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
23850  	 	 	 	 	 	 	 	 $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
23851  	 	 	 	 	 	 	 	 if (($fs == 0) AND ($dang > 0)) {
23852  	 	 	 	 	 	 	 	 	 $dang -= (2 * M_PI);
23853  	 	 	 	 	 	 	 	 } elseif (($fs == 1) AND ($dang < 0)) {
23854  	 	 	 	 	 	 	 	 	 $dang += (2 * M_PI);
23855  	 	 	 	 	 	 	 	 }
23856  	 	 	 	 	 	 	 	 $angf = $angs - $dang;
23857  	 	 	 	 	 	 	 	 if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
23858  	 	 	 	 	 	 	 	 	 // reverse angles
23859  	 	 	 	 	 	 	 	 	 $tmp = $angs;
23860  	 	 	 	 	 	 	 	 	 $angs = $angf;
23861  	 	 	 	 	 	 	 	 	 $angf = $tmp;
23862  	 	 	 	 	 	 	 	 }
23863  	 	 	 	 	 	 	 	 $angs = round(rad2deg($angs), 6);
23864  	 	 	 	 	 	 	 	 $angf = round(rad2deg($angf), 6);
23865  	 	 	 	 	 	 	 	 // covent angles to positive values
23866  	 	 	 	 	 	 	 	 if (($angs < 0) AND ($angf < 0)) {
23867  	 	 	 	 	 	 	 	 	 $angs += 360;
23868  	 	 	 	 	 	 	 	 	 $angf += 360;
23869  	 	 	 	 	 	 	 	 }
23870  	 	 	 	 	 	 	 	 $pie = false;
23871  	 	 	 	 	 	 	 	 if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
23872  	 	 	 	 	 	 	 	 	 $pie = true;
23873  	 	 	 	 	 	 	 	 }
23874  	 	 	 	 	 	 	 	 list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
23875  	 	 	 	 	 	 	 	 $xmin = min($xmin, $x, $axmin);
23876  	 	 	 	 	 	 	 	 $ymin = min($ymin, $y, $aymin);
23877  	 	 	 	 	 	 	 	 $xmax = max($xmax, $x, $axmax);
23878  	 	 	 	 	 	 	 	 $ymax = max($ymax, $y, $aymax);
23879  	 	 	 	 	 	 	 }
23880  	 	 	 	 	 	 	 if ($relcoord) {
23881  	 	 	 	 	 	 	 	 $xoffset = $x;
23882  	 	 	 	 	 	 	 	 $yoffset = $y;
23883  	 	 	 	 	 	 	 }
23884  	 	 	 	 	 	 }
23885  	 	 	 	 	 }
23886  	 	 	 	 	 break;
23887  	 	 	 	 }
23888  	 	 	 	 case 'Z': {
23889  	 	 	 	 	 $this->_out('h');
23890  	 	 	 	 	 $x = $x0 = $xinitial;
23891  	 	 	 	 	 $y = $y0 = $yinitial;
23892  	 	 	 	 	 break;
23893  	 	 	 	 }
23894  	 	 	 }
23895  	 	 	 $firstcmd = false;
23896  	 	 } // end foreach
23897  	 	 if (!empty($op)) {
23898  	 	 	 $this->_out($op);
23899  	 	 }
23900  	 	 return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
23901  	 }
23902  
23903  	 /**
23904  	  * Return the tag name without the namespace
23905  	  * @param string $name Tag name
23906  	  * @protected
23907  	  */
23908  	protected function removeTagNamespace($name) {
23909  	 	 if(strpos($name, ':') !== false) {
23910  	 	 	 $parts = explode(':', $name);
23911  	 	 	 return $parts[(sizeof($parts) - 1)];
23912  	 	 }
23913  	 	 return $name;
23914  	 }
23915  
23916  	 /**
23917  	  * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
23918  	  * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
23919  	  * @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.
23920  	  * @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.
23921  	  * @param array $ctm tranformation matrix for clipping mode (starting transformation matrix).
23922  	  * @author Nicola Asuni
23923  	  * @since 5.0.000 (2010-05-02)
23924  	  * @protected
23925  	  */
23926  	protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
23927  	 	 $name = $this->removeTagNamespace($name);
23928  	 	 // check if we are in clip mode
23929  	 	 if ($this->svgclipmode) {
23930  	 	 	 $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
23931  	 	 	 return;
23932  	 	 }
23933  	 	 if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
23934  	 	 	 if (isset($attribs['id'])) {
23935  	 	 	 	 $attribs['child_elements'] = array();
23936  	 	 	 	 $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
23937  	 	 	 	 return;
23938  	 	 	 }
23939  	 	 	 if (end($this->svgdefs) !== FALSE) {
23940  	 	 	 	 $last_svgdefs_id = key($this->svgdefs);
23941  	 	 	 	 if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
23942  	 	 	 	 	 $attribs['id'] = 'DF_'.(count($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements']) + 1);
23943  	 	 	 	 	 $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
23944  	 	 	 	 	 return;
23945  	 	 	 	 }
23946  	 	 	 }
23947  	 	 	 return;
23948  	 	 }
23949  	 	 $clipping = false;
23950  	 	 if ($parser == 'clip-path') {
23951  	 	 	 // set clipping mode
23952  	 	 	 $clipping = true;
23953  	 	 }
23954  	 	 // get styling properties
23955  	 	 $prev_svgstyle = $this->svgstyles[max(0,(count($this->svgstyles) - 1))]; // previous style
23956  	 	 $svgstyle = $this->svgstyles[0]; // set default style
23957  	 	 if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
23958  	 	 	 // default fill attribute for clipping
23959  	 	 	 $attribs['fill'] = 'none';
23960  	 	 }
23961  	 	 if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
23962  	 	 	 // fix style for regular expression
23963  	 	 	 $attribs['style'] = ';'.$attribs['style'];
23964  	 	 }
23965  	 	 foreach ($prev_svgstyle as $key => $val) {
23966  	 	 	 if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
23967  	 	 	 	 // inherit previous value
23968  	 	 	 	 $svgstyle[$key] = $val;
23969  	 	 	 }
23970  	 	 	 if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
23971  	 	 	 	 // specific attribute settings
23972  	 	 	 	 if ($attribs[$key] == 'inherit') {
23973  	 	 	 	 	 $svgstyle[$key] = $val;
23974  	 	 	 	 } else {
23975  	 	 	 	 	 $svgstyle[$key] = $attribs[$key];
23976  	 	 	 	 }
23977  	 	 	 } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
23978  	 	 	 	 // CSS style syntax
23979  	 	 	 	 $attrval = array();
23980  	 	 	 	 if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
23981  	 	 	 	 	 if ($attrval[1] == 'inherit') {
23982  	 	 	 	 	 	 $svgstyle[$key] = $val;
23983  	 	 	 	 	 } else {
23984  	 	 	 	 	 	 $svgstyle[$key] = $attrval[1];
23985  	 	 	 	 	 }
23986  	 	 	 	 }
23987  	 	 	 }
23988  	 	 }
23989  	 	 // transformation matrix
23990  	 	 if (!empty($ctm)) {
23991  	 	 	 $tm = $ctm;
23992  	 	 } else {
23993  	 	 	 $tm = array(1,0,0,1,0,0);
23994  	 	 }
23995  	 	 if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
23996  	 	 	 $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
23997  	 	 }
23998  	 	 $svgstyle['transfmatrix'] = $tm;
23999  	 	 $invisible = false;
24000  	 	 if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
24001  	 	 	 // the current graphics element is invisible (nothing is painted)
24002  	 	 	 $invisible = true;
24003  	 	 }
24004  	 	 // process tag
24005  	 	 switch($name) {
24006  	 	 	 case 'defs': {
24007  	 	 	 	 $this->svgdefsmode = true;
24008  	 	 	 	 break;
24009  	 	 	 }
24010  	 	 	 // clipPath
24011  	 	 	 case 'clipPath': {
24012  	 	 	 	 if ($invisible) {
24013  	 	 	 	 	 break;
24014  	 	 	 	 }
24015  	 	 	 	 $this->svgclipmode = true;
24016  	 	 	 	 if (!isset($attribs['id'])) {
24017  	 	 	 	 	 $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
24018  	 	 	 	 }
24019  	 	 	 	 $this->svgclipid = $attribs['id'];
24020  	 	 	 	 $this->svgclippaths[$this->svgclipid] = array();
24021  	 	 	 	 $this->svgcliptm[$this->svgclipid] = $tm;
24022  	 	 	 	 break;
24023  	 	 	 }
24024  	 	 	 case 'svg': {
24025  	 	 	 	 // start of SVG object
24026  	 	 	 	 if(++$this->svg_tag_depth <= 1) {
24027  	 	 	 	 	 break;
24028  	 	 	 	 }
24029  	 	 	 	 // inner SVG
24030  	 	 	 	 array_push($this->svgstyles, $svgstyle);
24031  	 	 	 	 $this->StartTransform();
24032  	 	 	 	 $svgX = (isset($attribs['x'])?$attribs['x']:0);
24033  	 	 	 	 $svgY = (isset($attribs['y'])?$attribs['y']:0);
24034  	 	 	 	 $svgW = (isset($attribs['width'])?$attribs['width']:0);
24035  	 	 	 	 $svgH = (isset($attribs['height'])?$attribs['height']:0);
24036  	 	 	 	 // set x, y position using transform matrix
24037  	 	 	 	 $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY));
24038  	 	 	 	 $this->SVGTransform($tm);
24039  	 	 	 	 // set clipping for width and height
24040  	 	 	 	 $x = 0;
24041  	 	 	 	 $y = 0;
24042  	 	 	 	 $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):$this->w);
24043  	 	 	 	 $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):$this->h);
24044  	 	 	 	 // draw clipping rect
24045  	 	 	 	 $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
24046  	 	 	 	 // parse viewbox, calculate extra transformation matrix
24047  	 	 	 	 if (isset($attribs['viewBox'])) {
24048  	 	 	 	 	 $tmp = array();
24049  	 	 	 	 	 preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp);
24050  	 	 	 	 	 $tmp = $tmp[0];
24051  	 	 	 	 	 if (sizeof($tmp) == 4) {
24052  	 	 	 	 	 	 $vx = $tmp[0];
24053  	 	 	 	 	 	 $vy = $tmp[1];
24054  	 	 	 	 	 	 $vw = $tmp[2];
24055  	 	 	 	 	 	 $vh = $tmp[3];
24056  	 	 	 	 	 	 // get aspect ratio
24057  	 	 	 	 	 	 $tmp = array();
24058  	 	 	 	 	 	 $aspectX = 'xMid';
24059  	 	 	 	 	 	 $aspectY = 'YMid';
24060  	 	 	 	 	 	 $fit = 'meet';
24061  	 	 	 	 	 	 if (isset($attribs['preserveAspectRatio'])) {
24062  	 	 	 	 	 	 	 if($attribs['preserveAspectRatio'] == 'none') {
24063  	 	 	 	 	 	 	 	 $fit = 'none';
24064  	 	 	 	 	 	 	 } else {
24065  	 	 	 	 	 	 	 	 preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp);
24066  	 	 	 	 	 	 	 	 $tmp = $tmp[0];
24067  	 	 	 	 	 	 	 	 if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) {
24068  	 	 	 	 	 	 	 	 	 $aspectX = substr($tmp[0], 0, 4);
24069  	 	 	 	 	 	 	 	 	 $aspectY = substr($tmp[0], 4, 4);
24070  	 	 	 	 	 	 	 	 	 $fit = $tmp[1];
24071  	 	 	 	 	 	 	 	 }
24072  	 	 	 	 	 	 	 }
24073  	 	 	 	 	 	 }
24074  	 	 	 	 	 	 $wr = ($svgW / $vw);
24075  	 	 	 	 	 	 $hr = ($svgH / $vh);
24076  	 	 	 	 	 	 $ax = $ay = 0;
24077  	 	 	 	 	 	 if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) {
24078  	 	 	 	 	 	 	 if ($aspectX == 'xMax') {
24079  	 	 	 	 	 	 	 	 $ax = (($vw * ($wr / $hr)) - $vw);
24080  	 	 	 	 	 	 	 }
24081  	 	 	 	 	 	 	 if ($aspectX == 'xMid') {
24082  	 	 	 	 	 	 	 	 $ax = ((($vw * ($wr / $hr)) - $vw) / 2);
24083  	 	 	 	 	 	 	 }
24084  	 	 	 	 	 	 	 $wr = $hr;
24085  	 	 	 	 	 	 } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) {
24086  	 	 	 	 	 	 	 if ($aspectY == 'YMax') {
24087  	 	 	 	 	 	 	 	 $ay = (($vh * ($hr / $wr)) - $vh);
24088  	 	 	 	 	 	 	 }
24089  	 	 	 	 	 	 	 if ($aspectY == 'YMid') {
24090  	 	 	 	 	 	 	 	 $ay = ((($vh * ($hr / $wr)) - $vh) / 2);
24091  	 	 	 	 	 	 	 }
24092  	 	 	 	 	 	 	 $hr = $wr;
24093  	 	 	 	 	 	 }
24094  	 	 	 	 	 	 $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY));
24095  	 	 	 	 	 	 $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, $newtm);
24096  	 	 	 	 	 	 $this->SVGTransform($tm);
24097  	 	 	 	 	 }
24098  	 	 	 	 }
24099  	 	 	 	 $this->setSVGStyles($svgstyle, $prev_svgstyle);
24100  	 	 	 	 break;
24101  	 	 	 }
24102  	 	 	 case 'g': {
24103  	 	 	 	 // group together related graphics elements
24104  	 	 	 	 array_push($this->svgstyles, $svgstyle);
24105  	 	 	 	 $this->StartTransform();
24106  	 	 	 	 $x = (isset($attribs['x'])?$attribs['x']:0);
24107  	 	 	 	 $y = (isset($attribs['y'])?$attribs['y']:0);
24108  	 	 	 	 $w = 1;//(isset($attribs['width'])?$attribs['width']:1);
24109  	 	 	 	 $h = 1;//(isset($attribs['height'])?$attribs['height']:1);
24110  	 	 	 	 $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
24111  	 	 	 	 $this->SVGTransform($tm);
24112  	 	 	 	 $this->setSVGStyles($svgstyle, $prev_svgstyle);
24113  	 	 	 	 break;
24114  	 	 	 }
24115  	 	 	 case 'linearGradient': {
24116  	 	 	 	 if ($this->pdfa_mode && $this->pdfa_version < 2) {
24117  	 	 	 	 	 break;
24118  	 	 	 	 }
24119  	 	 	 	 if (!isset($attribs['id'])) {
24120  	 	 	 	 	 $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
24121  	 	 	 	 }
24122  	 	 	 	 $this->svggradientid = $attribs['id'];
24123  	 	 	 	 $this->svggradients[$this->svggradientid] = array();
24124  	 	 	 	 $this->svggradients[$this->svggradientid]['type'] = 2;
24125  	 	 	 	 $this->svggradients[$this->svggradientid]['stops'] = array();
24126  	 	 	 	 if (isset($attribs['gradientUnits'])) {
24127  	 	 	 	 	 $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
24128  	 	 	 	 } else {
24129  	 	 	 	 	 $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
24130  	 	 	 	 }
24131  	 	 	 	 //$attribs['spreadMethod']
24132  	 	 	 	 if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
24133  	 	 	 	 	 OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
24134  	 	 	 	 	 	 OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
24135  	 	 	 	 	 	 OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
24136  	 	 	 	 	 	 OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
24137  	 	 	 	 	 $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
24138  	 	 	 	 } else {
24139  	 	 	 	 	 $this->svggradients[$this->svggradientid]['mode'] = 'measure';
24140  	 	 	 	 }
24141  	 	 	 	 $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
24142  	 	 	 	 $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
24143  	 	 	 	 $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
24144  	 	 	 	 $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
24145  	 	 	 	 if (isset($attribs['gradientTransform'])) {
24146  	 	 	 	 	 $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
24147  	 	 	 	 }
24148  	 	 	 	 $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
24149  	 	 	 	 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
24150  	 	 	 	 	 // gradient is defined on another place
24151  	 	 	 	 	 $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
24152  	 	 	 	 }
24153  	 	 	 	 break;
24154  	 	 	 }
24155  	 	 	 case 'radialGradient': {
24156  	 	 	 	 if ($this->pdfa_mode && $this->pdfa_version < 2) {
24157  	 	 	 	 	 break;
24158  	 	 	 	 }
24159  	 	 	 	 if (!isset($attribs['id'])) {
24160  	 	 	 	 	 $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
24161  	 	 	 	 }
24162  	 	 	 	 $this->svggradientid = $attribs['id'];
24163  	 	 	 	 $this->svggradients[$this->svggradientid] = array();
24164  	 	 	 	 $this->svggradients[$this->svggradientid]['type'] = 3;
24165  	 	 	 	 $this->svggradients[$this->svggradientid]['stops'] = array();
24166  	 	 	 	 if (isset($attribs['gradientUnits'])) {
24167  	 	 	 	 	 $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
24168  	 	 	 	 } else {
24169  	 	 	 	 	 $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
24170  	 	 	 	 }
24171  	 	 	 	 //$attribs['spreadMethod']
24172  	 	 	 	 if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
24173  	 	 	 	 	 OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
24174  	 	 	 	 	 OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
24175  	 	 	 	 	 $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
24176  	 	 	 	 } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
24177  	 	 	 	 	 $this->svggradients[$this->svggradientid]['mode'] = 'ratio';
24178  	 	 	 	 } else {
24179  	 	 	 	 	 $this->svggradients[$this->svggradientid]['mode'] = 'measure';
24180  	 	 	 	 }
24181  	 	 	 	 $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
24182  	 	 	 	 $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
24183  	 	 	 	 $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
24184  	 	 	 	 $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
24185  	 	 	 	 $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
24186  	 	 	 	 if (isset($attribs['gradientTransform'])) {
24187  	 	 	 	 	 $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
24188  	 	 	 	 }
24189  	 	 	 	 $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
24190  	 	 	 	 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
24191  	 	 	 	 	 // gradient is defined on another place
24192  	 	 	 	 	 $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
24193  	 	 	 	 }
24194  	 	 	 	 break;
24195  	 	 	 }
24196  	 	 	 case 'stop': {
24197  	 	 	 	 // gradient stops
24198  	 	 	 	 if (substr($attribs['offset'], -1) == '%') {
24199  	 	 	 	 	 $offset = floatval(substr($attribs['offset'], 0, -1)) / 100;
24200  	 	 	 	 } else {
24201  	 	 	 	 	 $offset = floatval($attribs['offset']);
24202  	 	 	 	 	 if ($offset > 1) {
24203  	 	 	 	 	 	 $offset /= 100;
24204  	 	 	 	 	 }
24205  	 	 	 	 }
24206  	 	 	 	 $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
24207  	 	 	 	 $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
24208  	 	 	 	 $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
24209  	 	 	 	 break;
24210  	 	 	 }
24211  	 	 	 // paths
24212  	 	 	 case 'path': {
24213  	 	 	 	 if ($invisible) {
24214  	 	 	 	 	 break;
24215  	 	 	 	 }
24216  	 	 	 	 if (isset($attribs['d'])) {
24217  	 	 	 	 	 $d = trim($attribs['d']);
24218  	 	 	 	 	 if (!empty($d)) {
24219  	 	 	 	 	 	 $x = (isset($attribs['x'])?$attribs['x']:0);
24220  	 	 	 	 	 	 $y = (isset($attribs['y'])?$attribs['y']:0);
24221  	 	 	 	 	 	 $w = (isset($attribs['width'])?$attribs['width']:1);
24222  	 	 	 	 	 	 $h = (isset($attribs['height'])?$attribs['height']:1);
24223  	 	 	 	 	 	 $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
24224  	 	 	 	 	 	 if ($clipping) {
24225  	 	 	 	 	 	 	 $this->SVGTransform($tm);
24226  	 	 	 	 	 	 	 $this->SVGPath($d, 'CNZ');
24227  	 	 	 	 	 	 } else {
24228  	 	 	 	 	 	 	 $this->StartTransform();
24229  	 	 	 	 	 	 	 $this->SVGTransform($tm);
24230  	 	 	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
24231  	 	 	 	 	 	 	 if (!empty($obstyle)) {
24232  	 	 	 	 	 	 	 	 $this->SVGPath($d, $obstyle);
24233  	 	 	 	 	 	 	 }
24234  	 	 	 	 	 	 	 $this->StopTransform();
24235  	 	 	 	 	 	 }
24236  	 	 	 	 	 }
24237  	 	 	 	 }
24238  	 	 	 	 break;
24239  	 	 	 }
24240  	 	 	 // shapes
24241  	 	 	 case 'rect': {
24242  	 	 	 	 if ($invisible) {
24243  	 	 	 	 	 break;
24244  	 	 	 	 }
24245  	 	 	 	 $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
24246  	 	 	 	 $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
24247  	 	 	 	 $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
24248  	 	 	 	 $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
24249  	 	 	 	 $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
24250  	 	 	 	 $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
24251  	 	 	 	 if ($clipping) {
24252  	 	 	 	 	 $this->SVGTransform($tm);
24253  	 	 	 	 	 $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
24254  	 	 	 	 } else {
24255  	 	 	 	 	 $this->StartTransform();
24256  	 	 	 	 	 $this->SVGTransform($tm);
24257  	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
24258  	 	 	 	 	 if (!empty($obstyle)) {
24259  	 	 	 	 	 	 $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
24260  	 	 	 	 	 }
24261  	 	 	 	 	 $this->StopTransform();
24262  	 	 	 	 }
24263  	 	 	 	 break;
24264  	 	 	 }
24265  	 	 	 case 'circle': {
24266  	 	 	 	 if ($invisible) {
24267  	 	 	 	 	 break;
24268  	 	 	 	 }
24269  	 	 	 	 $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
24270  	 	 	 	 $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
24271  	 	 	 	 $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
24272  	 	 	 	 $x = ($cx - $r);
24273  	 	 	 	 $y = ($cy - $r);
24274  	 	 	 	 $w = (2 * $r);
24275  	 	 	 	 $h = $w;
24276  	 	 	 	 if ($clipping) {
24277  	 	 	 	 	 $this->SVGTransform($tm);
24278  	 	 	 	 	 $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
24279  	 	 	 	 } else {
24280  	 	 	 	 	 $this->StartTransform();
24281  	 	 	 	 	 $this->SVGTransform($tm);
24282  	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
24283  	 	 	 	 	 if (!empty($obstyle)) {
24284  	 	 	 	 	 	 $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
24285  	 	 	 	 	 }
24286  	 	 	 	 	 $this->StopTransform();
24287  	 	 	 	 }
24288  	 	 	 	 break;
24289  	 	 	 }
24290  	 	 	 case 'ellipse': {
24291  	 	 	 	 if ($invisible) {
24292  	 	 	 	 	 break;
24293  	 	 	 	 }
24294  	 	 	 	 $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
24295  	 	 	 	 $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
24296  	 	 	 	 $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
24297  	 	 	 	 $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
24298  	 	 	 	 $x = ($cx - $rx);
24299  	 	 	 	 $y = ($cy - $ry);
24300  	 	 	 	 $w = (2 * $rx);
24301  	 	 	 	 $h = (2 * $ry);
24302  	 	 	 	 if ($clipping) {
24303  	 	 	 	 	 $this->SVGTransform($tm);
24304  	 	 	 	 	 $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
24305  	 	 	 	 } else {
24306  	 	 	 	 	 $this->StartTransform();
24307  	 	 	 	 	 $this->SVGTransform($tm);
24308  	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
24309  	 	 	 	 	 if (!empty($obstyle)) {
24310  	 	 	 	 	 	 $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
24311  	 	 	 	 	 }
24312  	 	 	 	 	 $this->StopTransform();
24313  	 	 	 	 }
24314  	 	 	 	 break;
24315  	 	 	 }
24316  	 	 	 case 'line': {
24317  	 	 	 	 if ($invisible) {
24318  	 	 	 	 	 break;
24319  	 	 	 	 }
24320  	 	 	 	 $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
24321  	 	 	 	 $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
24322  	 	 	 	 $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
24323  	 	 	 	 $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
24324  	 	 	 	 $x = $x1;
24325  	 	 	 	 $y = $y1;
24326  	 	 	 	 $w = abs($x2 - $x1);
24327  	 	 	 	 $h = abs($y2 - $y1);
24328  	 	 	 	 if (!$clipping) {
24329  	 	 	 	 	 $this->StartTransform();
24330  	 	 	 	 	 $this->SVGTransform($tm);
24331  	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
24332  	 	 	 	 	 $this->Line($x1, $y1, $x2, $y2);
24333  	 	 	 	 	 $this->StopTransform();
24334  	 	 	 	 }
24335  	 	 	 	 break;
24336  	 	 	 }
24337  	 	 	 case 'polyline':
24338  	 	 	 case 'polygon': {
24339  	 	 	 	 if ($invisible) {
24340  	 	 	 	 	 break;
24341  	 	 	 	 }
24342  	 	 	 	 $points = (isset($attribs['points'])?$attribs['points']:'0 0');
24343  	 	 	 	 $points = trim($points);
24344  	 	 	 	 // note that point may use a complex syntax not covered here
24345  	 	 	 	 $points = preg_split('/[\,\s]+/si', $points);
24346  	 	 	 	 if (count($points) < 4) {
24347  	 	 	 	 	 break;
24348  	 	 	 	 }
24349  	 	 	 	 $p = array();
24350  	 	 	 	 $xmin = 2147483647;
24351  	 	 	 	 $xmax = 0;
24352  	 	 	 	 $ymin = 2147483647;
24353  	 	 	 	 $ymax = 0;
24354  	 	 	 	 foreach ($points as $key => $val) {
24355  	 	 	 	 	 $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
24356  	 	 	 	 	 if (($key % 2) == 0) {
24357  	 	 	 	 	 	 // X coordinate
24358  	 	 	 	 	 	 $xmin = min($xmin, $p[$key]);
24359  	 	 	 	 	 	 $xmax = max($xmax, $p[$key]);
24360  	 	 	 	 	 } else {
24361  	 	 	 	 	 	 // Y coordinate
24362  	 	 	 	 	 	 $ymin = min($ymin, $p[$key]);
24363  	 	 	 	 	 	 $ymax = max($ymax, $p[$key]);
24364  	 	 	 	 	 }
24365  	 	 	 	 }
24366  	 	 	 	 $x = $xmin;
24367  	 	 	 	 $y = $ymin;
24368  	 	 	 	 $w = ($xmax - $xmin);
24369  	 	 	 	 $h = ($ymax - $ymin);
24370  	 	 	 	 if ($name == 'polyline') {
24371  	 	 	 	 	 $this->StartTransform();
24372  	 	 	 	 	 $this->SVGTransform($tm);
24373  	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
24374  	 	 	 	 	 if (!empty($obstyle)) {
24375  	 	 	 	 	 	 $this->PolyLine($p, $obstyle, array(), array());
24376  	 	 	 	 	 }
24377  	 	 	 	 	 $this->StopTransform();
24378  	 	 	 	 } else { // polygon
24379  	 	 	 	 	 if ($clipping) {
24380  	 	 	 	 	 	 $this->SVGTransform($tm);
24381  	 	 	 	 	 	 $this->Polygon($p, 'CNZ', array(), array(), true);
24382  	 	 	 	 	 } else {
24383  	 	 	 	 	 	 $this->StartTransform();
24384  	 	 	 	 	 	 $this->SVGTransform($tm);
24385  	 	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
24386  	 	 	 	 	 	 if (!empty($obstyle)) {
24387  	 	 	 	 	 	 	 $this->Polygon($p, $obstyle, array(), array(), true);
24388  	 	 	 	 	 	 }
24389  	 	 	 	 	 	 $this->StopTransform();
24390  	 	 	 	 	 }
24391  	 	 	 	 }
24392  	 	 	 	 break;
24393  	 	 	 }
24394  	 	 	 // image
24395  	 	 	 case 'image': {
24396  	 	 	 	 if ($invisible) {
24397  	 	 	 	 	 break;
24398  	 	 	 	 }
24399  	 	 	 	 if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
24400  	 	 	 	 	 break;
24401  	 	 	 	 }
24402  	 	 	 	 $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
24403  	 	 	 	 $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
24404  	 	 	 	 $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
24405  	 	 	 	 $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
24406  	 	 	 	 $img = $attribs['xlink:href'];
24407  	 	 	 	 if (!$clipping) {
24408  	 	 	 	 	 $this->StartTransform();
24409  	 	 	 	 	 $this->SVGTransform($tm);
24410  	 	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
24411  	 	 	 	 	 if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
24412  	 	 	 	 	 	 // embedded image encoded as base64
24413  	 	 	 	 	 	 $img = '@'.base64_decode(substr($img, strlen($m[0])));
24414  	 	 	 	 	 } else {
24415  	 	 	 	 	 	 // fix image path
24416  	 	 	 	 	 	 if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img[0] == '.') OR (basename($img) == $img))) {
24417  	 	 	 	 	 	 	 // replace relative path with full server path
24418  	 	 	 	 	 	 	 $img = $this->svgdir.'/'.$img;
24419  	 	 	 	 	 	 }
24420  	 	 	 	 	 	 if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
24421  	 	 	 	 	 	 	 $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
24422  	 	 	 	 	 	 	 if (($findroot === false) OR ($findroot > 1)) {
24423  	 	 	 	 	 	 	 	 if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
24424  	 	 	 	 	 	 	 	 	 $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
24425  	 	 	 	 	 	 	 	 } else {
24426  	 	 	 	 	 	 	 	 	 $img = $_SERVER['DOCUMENT_ROOT'].$img;
24427  	 	 	 	 	 	 	 	 }
24428  	 	 	 	 	 	 	 }
24429  	 	 	 	 	 	 }
24430  	 	 	 	 	 	 $img = urldecode($img);
24431  	 	 	 	 	 	 $testscrtype = @parse_url($img);
24432  	 	 	 	 	 	 if (empty($testscrtype['query'])) {
24433  	 	 	 	 	 	 	 // convert URL to server path
24434  	 	 	 	 	 	 	 $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
24435  	 	 	 	 	 	 } elseif (preg_match('|^https?://|', $img) !== 1) {
24436  	 	 	 	 	 	 	 // convert server path to URL
24437  	 	 	 	 	 	 	 $img = str_replace(K_PATH_MAIN, K_PATH_URL, $img);
24438  	 	 	 	 	 	 }
24439  	 	 	 	 	 }
24440  	 	 	 	 	 // get image type
24441  	 	 	 	 	 $imgtype = TCPDF_IMAGES::getImageFileType($img);
24442  	 	 	 	 	 if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
24443  	 	 	 	 	 	 $this->ImageEps($img, $x, $y, $w, $h);
24444  	 	 	 	 	 } elseif ($imgtype == 'svg') {
24445  	 	 	 	 	 	 // store SVG vars
24446  	 	 	 	 	 	 $svggradients = $this->svggradients;
24447  	 	 	 	 	 	 $svggradientid = $this->svggradientid;
24448  	 	 	 	 	 	 $svgdefsmode = $this->svgdefsmode;
24449  	 	 	 	 	 	 $svgdefs = $this->svgdefs;
24450  	 	 	 	 	 	 $svgclipmode = $this->svgclipmode;
24451  	 	 	 	 	 	 $svgclippaths = $this->svgclippaths;
24452  	 	 	 	 	 	 $svgcliptm = $this->svgcliptm;
24453  	 	 	 	 	 	 $svgclipid = $this->svgclipid;
24454  	 	 	 	 	 	 $svgtext = $this->svgtext;
24455  	 	 	 	 	 	 $svgtextmode = $this->svgtextmode;
24456  	 	 	 	 	 	 $this->ImageSVG($img, $x, $y, $w, $h);
24457  	 	 	 	 	 	 // restore SVG vars
24458  	 	 	 	 	 	 $this->svggradients = $svggradients;
24459  	 	 	 	 	 	 $this->svggradientid = $svggradientid;
24460  	 	 	 	 	 	 $this->svgdefsmode = $svgdefsmode;
24461  	 	 	 	 	 	 $this->svgdefs = $svgdefs;
24462  	 	 	 	 	 	 $this->svgclipmode = $svgclipmode;
24463  	 	 	 	 	 	 $this->svgclippaths = $svgclippaths;
24464  	 	 	 	 	 	 $this->svgcliptm = $svgcliptm;
24465  	 	 	 	 	 	 $this->svgclipid = $svgclipid;
24466  	 	 	 	 	 	 $this->svgtext = $svgtext;
24467  	 	 	 	 	 	 $this->svgtextmode = $svgtextmode;
24468  	 	 	 	 	 } else {
24469  	 	 	 	 	 	 $this->Image($img, $x, $y, $w, $h);
24470  	 	 	 	 	 }
24471  	 	 	 	 	 $this->StopTransform();
24472  	 	 	 	 }
24473  	 	 	 	 break;
24474  	 	 	 }
24475  	 	 	 // text
24476  	 	 	 case 'text':
24477  	 	 	 case 'tspan': {
24478  	 	 	 	 if (isset($this->svgtextmode['text-anchor']) AND !empty($this->svgtext)) {
24479  	 	 	 	 	 // @TODO: unsupported feature
24480  	 	 	 	 }
24481  	 	 	 	 // only basic support - advanced features must be implemented
24482  	 	 	 	 $this->svgtextmode['invisible'] = $invisible;
24483  	 	 	 	 if ($invisible) {
24484  	 	 	 	 	 break;
24485  	 	 	 	 }
24486  	 	 	 	 array_push($this->svgstyles, $svgstyle);
24487  	 	 	 	 if (isset($attribs['x'])) {
24488  	 	 	 	 	 $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
24489  	 	 	 	 } elseif ($name == 'tspan') {
24490  	 	 	 	 	 $x = $this->x;
24491  	 	 	 	 } else {
24492  	 	 	 	 	 $x = 0;
24493  	 	 	 	 }
24494  	 	 	 	 if (isset($attribs['dx'])) {
24495  	 	 	 	 	 $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
24496  	 	 	 	 }
24497  	 	 	 	 if (isset($attribs['y'])) {
24498  	 	 	 	 	 $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
24499  	 	 	 	 } elseif ($name == 'tspan') {
24500  	 	 	 	 	 $y = $this->y;
24501  	 	 	 	 } else {
24502  	 	 	 	 	 $y = 0;
24503  	 	 	 	 }
24504  	 	 	 	 if (isset($attribs['dy'])) {
24505  	 	 	 	 	 $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
24506  	 	 	 	 }
24507  	 	 	 	 $svgstyle['text-color'] = $svgstyle['fill'];
24508  	 	 	 	 $this->svgtext = '';
24509  	 	 	 	 if (isset($svgstyle['text-anchor'])) {
24510  	 	 	 	 	 $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
24511  	 	 	 	 } else {
24512  	 	 	 	 	 $this->svgtextmode['text-anchor'] = 'start';
24513  	 	 	 	 }
24514  	 	 	 	 if (isset($svgstyle['direction'])) {
24515  	 	 	 	 	 if ($svgstyle['direction'] == 'rtl') {
24516  	 	 	 	 	 	 $this->svgtextmode['rtl'] = true;
24517  	 	 	 	 	 } else {
24518  	 	 	 	 	 	 $this->svgtextmode['rtl'] = false;
24519  	 	 	 	 	 }
24520  	 	 	 	 } else {
24521  	 	 	 	 	 $this->svgtextmode['rtl'] = false;
24522  	 	 	 	 }
24523  	 	 	 	 if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
24524  	 	 	 	 	 $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
24525  	 	 	 	 } else {
24526  	 	 	 	 	 $this->svgtextmode['stroke'] = false;
24527  	 	 	 	 }
24528  	 	 	 	 $this->StartTransform();
24529  	 	 	 	 $this->SVGTransform($tm);
24530  	 	 	 	 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
24531  	 	 	 	 $this->x = $x;
24532  	 	 	 	 $this->y = $y;
24533  	 	 	 	 break;
24534  	 	 	 }
24535  	 	 	 // use
24536  	 	 	 case 'use': {
24537  	 	 	 	 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
24538  	 	 	 	 	 $svgdefid = substr($attribs['xlink:href'], 1);
24539  	 	 	 	 	 if (isset($this->svgdefs[$svgdefid])) {
24540  	 	 	 	 	 	 $use = $this->svgdefs[$svgdefid];
24541  	 	 	 	 	 	 if (isset($attribs['xlink:href'])) {
24542  	 	 	 	 	 	 	 unset($attribs['xlink:href']);
24543  	 	 	 	 	 	 }
24544  	 	 	 	 	 	 if (isset($attribs['id'])) {
24545  	 	 	 	 	 	 	 unset($attribs['id']);
24546  	 	 	 	 	 	 }
24547  	 	 	 	 	 	 if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
24548  	 	 	 	 	 	 	 $attribs['x'] += $use['attribs']['x'];
24549  	 	 	 	 	 	 }
24550  	 	 	 	 	 	 if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
24551  	 	 	 	 	 	 	 $attribs['y'] += $use['attribs']['y'];
24552  	 	 	 	 	 	 }
24553  	 	 	 	 	 	 if (empty($attribs['style'])) {
24554  	 	 	 	 	 	 	 $attribs['style'] = '';
24555  	 	 	 	 	 	 }
24556  	 	 	 	 	 	 if (!empty($use['attribs']['style'])) {
24557  	 	 	 	 	 	 	 // merge styles
24558  	 	 	 	 	 	 	 $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']);
24559  	 	 	 	 	 	 }
24560  	 	 	 	 	 	 $attribs = array_merge($use['attribs'], $attribs);
24561  	 	 	 	 	 	 $this->startSVGElementHandler($parser, $use['name'], $attribs);
24562  	 	 	 	 	 	 return;
24563  	 	 	 	 	 }
24564  	 	 	 	 }
24565  	 	 	 	 break;
24566  	 	 	 }
24567  	 	 	 default: {
24568  	 	 	 	 break;
24569  	 	 	 }
24570  	 	 } // end of switch
24571  	 	 // process child elements
24572  	 	 if (!empty($attribs['child_elements'])) {
24573  	 	 	 $child_elements = $attribs['child_elements'];
24574  	 	 	 unset($attribs['child_elements']);
24575  	 	 	 foreach($child_elements as $child_element) {
24576  	 	 	 	 if (empty($child_element['attribs']['closing_tag'])) {
24577  	 	 	 	 	 $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
24578  	 	 	 	 } else {
24579  	 	 	 	 	 if (isset($child_element['attribs']['content'])) {
24580  	 	 	 	 	 	 $this->svgtext = $child_element['attribs']['content'];
24581  	 	 	 	 	 }
24582  	 	 	 	 	 $this->endSVGElementHandler('child-tag', $child_element['name']);
24583  	 	 	 	 }
24584  	 	 	 }
24585  	 	 }
24586  	 }
24587  
24588  	 /**
24589  	  * Sets the closing SVG element handler function for the XML parser.
24590  	  * @param resource|string $parser The first parameter, parser, is a reference to the XML parser calling the handler.
24591  	  * @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.
24592  	  * @author Nicola Asuni
24593  	  * @since 5.0.000 (2010-05-02)
24594  	  * @protected
24595  	  */
24596  	protected function endSVGElementHandler($parser, $name) {
24597  	 	 $name = $this->removeTagNamespace($name);
24598  	 	 if ($this->svgdefsmode AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
24599  	 	 	 if (end($this->svgdefs) !== FALSE) {
24600  	 	 	 	 $last_svgdefs_id = key($this->svgdefs);
24601  	 	 	 	 if (isset($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'])) {
24602  	 	 	 	 	 foreach($this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
24603  	 	 	 	 	 	 if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
24604  	 	 	 	 	 	 	 $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
24605  	 	 	 	 	 	 	 return;
24606  	 	 	 	 	 	 }
24607  	 	 	 	 	 }
24608  	 	 	 	 	 if ($this->svgdefs[$last_svgdefs_id]['name'] == $name) {
24609  	 	 	 	 	 	 $this->svgdefs[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext));
24610  	 	 	 	 	 	 return;
24611  	 	 	 	 	 }
24612  	 	 	 	 }
24613  	 	 	 }
24614  	 	 	 return;
24615  	 	 }
24616  	 	 switch($name) {
24617  	 	 	 case 'defs': {
24618  	 	 	 	 $this->svgdefsmode = false;
24619  	 	 	 	 break;
24620  	 	 	 }
24621  	 	 	 // clipPath
24622  	 	 	 case 'clipPath': {
24623  	 	 	 	 $this->svgclipmode = false;
24624  	 	 	 	 break;
24625  	 	 	 }
24626  	 	 	 case 'svg': {
24627  	 	 	 	 if (--$this->svg_tag_depth <= 0) {
24628  	 	 	 	 	 break;
24629  	 	 	 	 }
24630  	 	 	 }
24631  	 	 	 case 'g': {
24632  	 	 	 	 // ungroup: remove last style from array
24633  	 	 	 	 array_pop($this->svgstyles);
24634  	 	 	 	 $this->StopTransform();
24635  	 	 	 	 break;
24636  	 	 	 }
24637  	 	 	 case 'text':
24638  	 	 	 case 'tspan': {
24639  	 	 	 	 if ($this->svgtextmode['invisible']) {
24640  	 	 	 	 	 // This implementation must be fixed to following the rule:
24641  	 	 	 	 	 // 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.
24642  	 	 	 	 	 break;
24643  	 	 	 	 }
24644  	 	 	 	 // print text
24645  	 	 	 	 $text = $this->svgtext;
24646  	 	 	 	 //$text = $this->stringTrim($text);
24647  	 	 	 	 $textlen = $this->GetStringWidth($text);
24648  	 	 	 	 if ($this->svgtextmode['text-anchor'] != 'start') {
24649  	 	 	 	 	 // check if string is RTL text
24650  	 	 	 	 	 if ($this->svgtextmode['text-anchor'] == 'end') {
24651  	 	 	 	 	 	 if ($this->svgtextmode['rtl']) {
24652  	 	 	 	 	 	 	 $this->x += $textlen;
24653  	 	 	 	 	 	 } else {
24654  	 	 	 	 	 	 	 $this->x -= $textlen;
24655  	 	 	 	 	 	 }
24656  	 	 	 	 	 } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
24657  	 	 	 	 	 	 if ($this->svgtextmode['rtl']) {
24658  	 	 	 	 	 	 	 $this->x += ($textlen / 2);
24659  	 	 	 	 	 	 } else {
24660  	 	 	 	 	 	 	 $this->x -= ($textlen / 2);
24661  	 	 	 	 	 	 }
24662  	 	 	 	 	 }
24663  	 	 	 	 }
24664  	 	 	 	 $textrendermode = $this->textrendermode;
24665  	 	 	 	 $textstrokewidth = $this->textstrokewidth;
24666  	 	 	 	 $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
24667  	 	 	 	 if ($name == 'text') {
24668  	 	 	 	 	 // store current coordinates
24669  	 	 	 	 	 $tmpx = $this->x;
24670  	 	 	 	 	 $tmpy = $this->y;
24671  	 	 	 	 }
24672  	 	 	 	 // print the text
24673  	 	 	 	 $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
24674  	 	 	 	 if ($name == 'text') {
24675  	 	 	 	 	 // restore coordinates
24676  	 	 	 	 	 $this->x = $tmpx;
24677  	 	 	 	 	 $this->y = $tmpy;
24678  	 	 	 	 }
24679  	 	 	 	 // restore previous rendering mode
24680  	 	 	 	 $this->textrendermode = $textrendermode;
24681  	 	 	 	 $this->textstrokewidth = $textstrokewidth;
24682  	 	 	 	 $this->svgtext = '';
24683  	 	 	 	 $this->StopTransform();
24684  	 	 	 	 if (!$this->svgdefsmode) {
24685  	 	 	 	 	 array_pop($this->svgstyles);
24686  	 	 	 	 }
24687  	 	 	 	 break;
24688  	 	 	 }
24689  	 	 	 default: {
24690  	 	 	 	 break;
24691  	 	 	 }
24692  	 	 }
24693  	 }
24694  
24695  	 /**
24696  	  * Sets the character data handler function for the XML parser.
24697  	  * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
24698  	  * @param string $data The second parameter, data, contains the character data as a string.
24699  	  * @author Nicola Asuni
24700  	  * @since 5.0.000 (2010-05-02)
24701  	  * @protected
24702  	  */
24703  	protected function segSVGContentHandler($parser, $data) {
24704  	 	 $this->svgtext .= $data;
24705  	 }
24706  
24707  	 // --- END SVG METHODS -----------------------------------------------------
24708  
24709      /**
24710       * Keeps files in memory, so it doesn't need to downloaded everytime in a loop
24711       * @param string $file
24712       * @return string
24713       */
24714      protected function getCachedFileContents($file)
24715      {
24716          if (!isset($this->fileContentCache[$file])) {
24717              $this->fileContentCache[$file] = TCPDF_STATIC::fileGetContents($file);
24718          }
24719          return $this->fileContentCache[$file];
24720      }
24721  
24722      /**
24723       * Avoid multiple calls to an external server to see if a file exists
24724       * @param string $file
24725       * @return bool
24726       */
24727      protected function fileExists($file)
24728      {
24729          if (isset($this->fileContentCache[$file]) || false !== $this->getImageBuffer($file)) {
24730              return true;
24731          }
24732  
24733          return TCPDF_STATIC::file_exists($file);
24734      }
24735  
24736  } // END OF TCPDF CLASS
24737  
24738  //============================================================+
24739  // END OF FILE
24740  //============================================================+