/libs/tcpdf/tcpdf.php

https://github.com/CodeYellowBV/piwik · PHP · 24144 lines · 16660 code · 681 blank · 6803 comment · 3711 complexity · 5c02ba6d7a3dba39c140ca7aa25d22f0 MD5 · raw file

  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 6.0.044
  5. // Begin : 2002-08-03
  6. // Last Update : 2013-10-29
  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-2013 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can ioredistribute 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 ImagMagick (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 Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  50. // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  51. // * automatic page header and footer management;
  52. // * document encryption up to 256 bit and digital signature certifications;
  53. // * transactions to UNDO commands;
  54. // * PDF annotations, including links, text and file attachments;
  55. // * text rendering modes (fill, stroke and clipping);
  56. // * multiple columns mode;
  57. // * no-write page regions;
  58. // * bookmarks, named destinations and table of content;
  59. // * text hyphenation;
  60. // * text stretching and spacing (tracking);
  61. // * automatic page break, line break and text alignments including justification;
  62. // * automatic page numbering and page groups;
  63. // * move and delete pages;
  64. // * page compression (requires php-zlib extension);
  65. // * XOBject Templates;
  66. // * Layers and object visibility.
  67. // * PDF/A-1b support
  68. //============================================================+
  69. /**
  70. * @file
  71. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  72. * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  73. * <h3>TCPDF main features are:</h3>
  74. * <ul>
  75. * <li>no external libraries are required for the basic functions;</li>
  76. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  77. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  78. * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
  79. * <li>font subsetting;</li>
  80. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  81. * <li>images, graphic (geometric figures) and transformation methods;
  82. * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
  83. * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
  84. * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  85. * <li>automatic page header and footer management;</li>
  86. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  87. * <li>transactions to UNDO commands;</li>
  88. * <li>PDF annotations, including links, text and file attachments;</li>
  89. * <li>text rendering modes (fill, stroke and clipping);</li>
  90. * <li>multiple columns mode;</li>
  91. * <li>no-write page regions;</li>
  92. * <li>bookmarks, named destinations and table of content;</li>
  93. * <li>text hyphenation;</li>
  94. * <li>text stretching and spacing (tracking);</li>
  95. * <li>automatic page break, line break and text alignments including justification;</li>
  96. * <li>automatic page numbering and page groups;</li>
  97. * <li>move and delete pages;</li>
  98. * <li>page compression (requires php-zlib extension);</li>
  99. * <li>XOBject Templates;</li>
  100. * <li>Layers and object visibility;</li>
  101. * <li>PDF/A-1b support.</li>
  102. * </ul>
  103. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  104. * @package com.tecnick.tcpdf
  105. * @author Nicola Asuni
  106. * @version 6.0.044
  107. */
  108. // TCPDF configuration
  109. require_once(dirname(__FILE__).'/tcpdf_autoconfig.php');
  110. // TCPDF static font methods and data
  111. require_once(dirname(__FILE__).'/include/tcpdf_font_data.php');
  112. // TCPDF static font methods and data
  113. require_once(dirname(__FILE__).'/include/tcpdf_fonts.php');
  114. // TCPDF static color methods and data
  115. require_once(dirname(__FILE__).'/include/tcpdf_colors.php');
  116. // TCPDF static image methods and data
  117. require_once(dirname(__FILE__).'/include/tcpdf_images.php');
  118. // TCPDF static methods and data
  119. require_once(dirname(__FILE__).'/include/tcpdf_static.php');
  120. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  121. /**
  122. * @class TCPDF
  123. * PHP class for generating PDF documents without requiring external extensions.
  124. * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
  125. * @package com.tecnick.tcpdf
  126. * @brief PHP class for generating PDF documents without requiring external extensions.
  127. * @version 6.0.044
  128. * @author Nicola Asuni - info@tecnick.com
  129. */
  130. class TCPDF {
  131. // Protected properties
  132. /**
  133. * Current page number.
  134. * @protected
  135. */
  136. protected $page;
  137. /**
  138. * Current object number.
  139. * @protected
  140. */
  141. protected $n;
  142. /**
  143. * Array of object offsets.
  144. * @protected
  145. */
  146. protected $offsets = array();
  147. /**
  148. * Array of object IDs for each page.
  149. * @protected
  150. */
  151. protected $pageobjects = array();
  152. /**
  153. * Buffer holding in-memory PDF.
  154. * @protected
  155. */
  156. protected $buffer;
  157. /**
  158. * Array containing pages.
  159. * @protected
  160. */
  161. protected $pages = array();
  162. /**
  163. * Current document state.
  164. * @protected
  165. */
  166. protected $state;
  167. /**
  168. * Compression flag.
  169. * @protected
  170. */
  171. protected $compress;
  172. /**
  173. * Current page orientation (P = Portrait, L = Landscape).
  174. * @protected
  175. */
  176. protected $CurOrientation;
  177. /**
  178. * Page dimensions.
  179. * @protected
  180. */
  181. protected $pagedim = array();
  182. /**
  183. * Scale factor (number of points in user unit).
  184. * @protected
  185. */
  186. protected $k;
  187. /**
  188. * Width of page format in points.
  189. * @protected
  190. */
  191. protected $fwPt;
  192. /**
  193. * Height of page format in points.
  194. * @protected
  195. */
  196. protected $fhPt;
  197. /**
  198. * Current width of page in points.
  199. * @protected
  200. */
  201. protected $wPt;
  202. /**
  203. * Current height of page in points.
  204. * @protected
  205. */
  206. protected $hPt;
  207. /**
  208. * Current width of page in user unit.
  209. * @protected
  210. */
  211. protected $w;
  212. /**
  213. * Current height of page in user unit.
  214. * @protected
  215. */
  216. protected $h;
  217. /**
  218. * Left margin.
  219. * @protected
  220. */
  221. protected $lMargin;
  222. /**
  223. * Right margin.
  224. * @protected
  225. */
  226. protected $rMargin;
  227. /**
  228. * Cell left margin (used by regions).
  229. * @protected
  230. */
  231. protected $clMargin;
  232. /**
  233. * Cell right margin (used by regions).
  234. * @protected
  235. */
  236. protected $crMargin;
  237. /**
  238. * Top margin.
  239. * @protected
  240. */
  241. protected $tMargin;
  242. /**
  243. * Page break margin.
  244. * @protected
  245. */
  246. protected $bMargin;
  247. /**
  248. * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  249. * @since 5.9.000 (2010-10-03)
  250. * @protected
  251. */
  252. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  253. /**
  254. * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
  255. * @since 5.9.000 (2010-10-04)
  256. * @protected
  257. */
  258. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  259. /**
  260. * Current horizontal position in user unit for cell positioning.
  261. * @protected
  262. */
  263. protected $x;
  264. /**
  265. * Current vertical position in user unit for cell positioning.
  266. * @protected
  267. */
  268. protected $y;
  269. /**
  270. * Height of last cell printed.
  271. * @protected
  272. */
  273. protected $lasth;
  274. /**
  275. * Line width in user unit.
  276. * @protected
  277. */
  278. protected $LineWidth;
  279. /**
  280. * Array of standard font names.
  281. * @protected
  282. */
  283. protected $CoreFonts;
  284. /**
  285. * Array of used fonts.
  286. * @protected
  287. */
  288. protected $fonts = array();
  289. /**
  290. * Array of font files.
  291. * @protected
  292. */
  293. protected $FontFiles = array();
  294. /**
  295. * Array of encoding differences.
  296. * @protected
  297. */
  298. protected $diffs = array();
  299. /**
  300. * Array of used images.
  301. * @protected
  302. */
  303. protected $images = array();
  304. /**
  305. * Array of cached files.
  306. * @protected
  307. */
  308. protected $cached_files = array();
  309. /**
  310. * Array of Annotations in pages.
  311. * @protected
  312. */
  313. protected $PageAnnots = array();
  314. /**
  315. * Array of internal links.
  316. * @protected
  317. */
  318. protected $links = array();
  319. /**
  320. * Current font family.
  321. * @protected
  322. */
  323. protected $FontFamily;
  324. /**
  325. * Current font style.
  326. * @protected
  327. */
  328. protected $FontStyle;
  329. /**
  330. * Current font ascent (distance between font top and baseline).
  331. * @protected
  332. * @since 2.8.000 (2007-03-29)
  333. */
  334. protected $FontAscent;
  335. /**
  336. * Current font descent (distance between font bottom and baseline).
  337. * @protected
  338. * @since 2.8.000 (2007-03-29)
  339. */
  340. protected $FontDescent;
  341. /**
  342. * Underlining flag.
  343. * @protected
  344. */
  345. protected $underline;
  346. /**
  347. * Overlining flag.
  348. * @protected
  349. */
  350. protected $overline;
  351. /**
  352. * Current font info.
  353. * @protected
  354. */
  355. protected $CurrentFont;
  356. /**
  357. * Current font size in points.
  358. * @protected
  359. */
  360. protected $FontSizePt;
  361. /**
  362. * Current font size in user unit.
  363. * @protected
  364. */
  365. protected $FontSize;
  366. /**
  367. * Commands for drawing color.
  368. * @protected
  369. */
  370. protected $DrawColor;
  371. /**
  372. * Commands for filling color.
  373. * @protected
  374. */
  375. protected $FillColor;
  376. /**
  377. * Commands for text color.
  378. * @protected
  379. */
  380. protected $TextColor;
  381. /**
  382. * Indicates whether fill and text colors are different.
  383. * @protected
  384. */
  385. protected $ColorFlag;
  386. /**
  387. * Automatic page breaking.
  388. * @protected
  389. */
  390. protected $AutoPageBreak;
  391. /**
  392. * Threshold used to trigger page breaks.
  393. * @protected
  394. */
  395. protected $PageBreakTrigger;
  396. /**
  397. * Flag set when processing page header.
  398. * @protected
  399. */
  400. protected $InHeader = false;
  401. /**
  402. * Flag set when processing page footer.
  403. * @protected
  404. */
  405. protected $InFooter = false;
  406. /**
  407. * Zoom display mode.
  408. * @protected
  409. */
  410. protected $ZoomMode;
  411. /**
  412. * Layout display mode.
  413. * @protected
  414. */
  415. protected $LayoutMode;
  416. /**
  417. * If true set the document information dictionary in Unicode.
  418. * @protected
  419. */
  420. protected $docinfounicode = true;
  421. /**
  422. * Document title.
  423. * @protected
  424. */
  425. protected $title = '';
  426. /**
  427. * Document subject.
  428. * @protected
  429. */
  430. protected $subject = '';
  431. /**
  432. * Document author.
  433. * @protected
  434. */
  435. protected $author = '';
  436. /**
  437. * Document keywords.
  438. * @protected
  439. */
  440. protected $keywords = '';
  441. /**
  442. * Document creator.
  443. * @protected
  444. */
  445. protected $creator = '';
  446. /**
  447. * Starting page number.
  448. * @protected
  449. */
  450. protected $starting_page_number = 1;
  451. /**
  452. * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
  453. * @since 2002-07-31
  454. * @author Nicola Asuni
  455. * @protected
  456. */
  457. protected $img_rb_x;
  458. /**
  459. * The right-bottom corner Y coordinate of last inserted image.
  460. * @since 2002-07-31
  461. * @author Nicola Asuni
  462. * @protected
  463. */
  464. protected $img_rb_y;
  465. /**
  466. * Adjusting factor to convert pixels to user units.
  467. * @since 2004-06-14
  468. * @author Nicola Asuni
  469. * @protected
  470. */
  471. protected $imgscale = 1;
  472. /**
  473. * Boolean flag set to true when the input text is unicode (require unicode fonts).
  474. * @since 2005-01-02
  475. * @author Nicola Asuni
  476. * @protected
  477. */
  478. protected $isunicode = false;
  479. /**
  480. * PDF version.
  481. * @since 1.5.3
  482. * @protected
  483. */
  484. protected $PDFVersion = '1.7';
  485. /**
  486. * ID of the stored default header template (-1 = not set).
  487. * @protected
  488. */
  489. protected $header_xobjid = -1;
  490. /**
  491. * If true reset the Header Xobject template at each page
  492. * @protected
  493. */
  494. protected $header_xobj_autoreset = false;
  495. /**
  496. * Minimum distance between header and top page margin.
  497. * @protected
  498. */
  499. protected $header_margin;
  500. /**
  501. * Minimum distance between footer and bottom page margin.
  502. * @protected
  503. */
  504. protected $footer_margin;
  505. /**
  506. * Original left margin value.
  507. * @protected
  508. * @since 1.53.0.TC013
  509. */
  510. protected $original_lMargin;
  511. /**
  512. * Original right margin value.
  513. * @protected
  514. * @since 1.53.0.TC013
  515. */
  516. protected $original_rMargin;
  517. /**
  518. * Default font used on page header.
  519. * @protected
  520. */
  521. protected $header_font;
  522. /**
  523. * Default font used on page footer.
  524. * @protected
  525. */
  526. protected $footer_font;
  527. /**
  528. * Language templates.
  529. * @protected
  530. */
  531. protected $l;
  532. /**
  533. * Barcode to print on page footer (only if set).
  534. * @protected
  535. */
  536. protected $barcode = false;
  537. /**
  538. * Boolean flag to print/hide page header.
  539. * @protected
  540. */
  541. protected $print_header = true;
  542. /**
  543. * Boolean flag to print/hide page footer.
  544. * @protected
  545. */
  546. protected $print_footer = true;
  547. /**
  548. * Header image logo.
  549. * @protected
  550. */
  551. protected $header_logo = '';
  552. /**
  553. * Width of header image logo in user units.
  554. * @protected
  555. */
  556. protected $header_logo_width = 30;
  557. /**
  558. * Title to be printed on default page header.
  559. * @protected
  560. */
  561. protected $header_title = '';
  562. /**
  563. * String to pring on page header after title.
  564. * @protected
  565. */
  566. protected $header_string = '';
  567. /**
  568. * Color for header text (RGB array).
  569. * @since 5.9.174 (2012-07-25)
  570. * @protected
  571. */
  572. protected $header_text_color = array(0,0,0);
  573. /**
  574. * Color for header line (RGB array).
  575. * @since 5.9.174 (2012-07-25)
  576. * @protected
  577. */
  578. protected $header_line_color = array(0,0,0);
  579. /**
  580. * Color for footer text (RGB array).
  581. * @since 5.9.174 (2012-07-25)
  582. * @protected
  583. */
  584. protected $footer_text_color = array(0,0,0);
  585. /**
  586. * Color for footer line (RGB array).
  587. * @since 5.9.174 (2012-07-25)
  588. * @protected
  589. */
  590. protected $footer_line_color = array(0,0,0);
  591. /**
  592. * Text shadow data array.
  593. * @since 5.9.174 (2012-07-25)
  594. * @protected
  595. */
  596. protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
  597. /**
  598. * Default number of columns for html table.
  599. * @protected
  600. */
  601. protected $default_table_columns = 4;
  602. // variables for html parser
  603. /**
  604. * HTML PARSER: array to store current link and rendering styles.
  605. * @protected
  606. */
  607. protected $HREF = array();
  608. /**
  609. * List of available fonts on filesystem.
  610. * @protected
  611. */
  612. protected $fontlist = array();
  613. /**
  614. * Current foreground color.
  615. * @protected
  616. */
  617. protected $fgcolor;
  618. /**
  619. * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  620. * @protected
  621. */
  622. protected $listordered = array();
  623. /**
  624. * HTML PARSER: array count list items on nested lists.
  625. * @protected
  626. */
  627. protected $listcount = array();
  628. /**
  629. * HTML PARSER: current list nesting level.
  630. * @protected
  631. */
  632. protected $listnum = 0;
  633. /**
  634. * HTML PARSER: indent amount for lists.
  635. * @protected
  636. */
  637. protected $listindent = 0;
  638. /**
  639. * HTML PARSER: current list indententation level.
  640. * @protected
  641. */
  642. protected $listindentlevel = 0;
  643. /**
  644. * Current background color.
  645. * @protected
  646. */
  647. protected $bgcolor;
  648. /**
  649. * Temporary font size in points.
  650. * @protected
  651. */
  652. protected $tempfontsize = 10;
  653. /**
  654. * Spacer string for LI tags.
  655. * @protected
  656. */
  657. protected $lispacer = '';
  658. /**
  659. * Default encoding.
  660. * @protected
  661. * @since 1.53.0.TC010
  662. */
  663. protected $encoding = 'UTF-8';
  664. /**
  665. * PHP internal encoding.
  666. * @protected
  667. * @since 1.53.0.TC016
  668. */
  669. protected $internal_encoding;
  670. /**
  671. * Boolean flag to indicate if the document language is Right-To-Left.
  672. * @protected
  673. * @since 2.0.000
  674. */
  675. protected $rtl = false;
  676. /**
  677. * Boolean flag used to force RTL or LTR string direction.
  678. * @protected
  679. * @since 2.0.000
  680. */
  681. protected $tmprtl = false;
  682. // --- Variables used for document encryption:
  683. /**
  684. * IBoolean flag indicating whether document is protected.
  685. * @protected
  686. * @since 2.0.000 (2008-01-02)
  687. */
  688. protected $encrypted;
  689. /**
  690. * Array containing encryption settings.
  691. * @protected
  692. * @since 5.0.005 (2010-05-11)
  693. */
  694. protected $encryptdata = array();
  695. /**
  696. * Last RC4 key encrypted (cached for optimisation).
  697. * @protected
  698. * @since 2.0.000 (2008-01-02)
  699. */
  700. protected $last_enc_key;
  701. /**
  702. * Last RC4 computed key.
  703. * @protected
  704. * @since 2.0.000 (2008-01-02)
  705. */
  706. protected $last_enc_key_c;
  707. /**
  708. * File ID (used on document trailer).
  709. * @protected
  710. * @since 5.0.005 (2010-05-12)
  711. */
  712. protected $file_id;
  713. // --- bookmark ---
  714. /**
  715. * Outlines for bookmark.
  716. * @protected
  717. * @since 2.1.002 (2008-02-12)
  718. */
  719. protected $outlines = array();
  720. /**
  721. * Outline root for bookmark.
  722. * @protected
  723. * @since 2.1.002 (2008-02-12)
  724. */
  725. protected $OutlineRoot;
  726. // --- javascript and form ---
  727. /**
  728. * Javascript code.
  729. * @protected
  730. * @since 2.1.002 (2008-02-12)
  731. */
  732. protected $javascript = '';
  733. /**
  734. * Javascript counter.
  735. * @protected
  736. * @since 2.1.002 (2008-02-12)
  737. */
  738. protected $n_js;
  739. /**
  740. * line through state
  741. * @protected
  742. * @since 2.8.000 (2008-03-19)
  743. */
  744. protected $linethrough;
  745. /**
  746. * Array with additional document-wide usage rights for the document.
  747. * @protected
  748. * @since 5.8.014 (2010-08-23)
  749. */
  750. protected $ur = array();
  751. /**
  752. * DPI (Dot Per Inch) Document Resolution (do not change).
  753. * @protected
  754. * @since 3.0.000 (2008-03-27)
  755. */
  756. protected $dpi = 72;
  757. /**
  758. * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
  759. * @protected
  760. * @since 3.0.000 (2008-03-27)
  761. */
  762. protected $newpagegroup = array();
  763. /**
  764. * Array that contains the number of pages in each page group.
  765. * @protected
  766. * @since 3.0.000 (2008-03-27)
  767. */
  768. protected $pagegroups = array();
  769. /**
  770. * Current page group number.
  771. * @protected
  772. * @since 3.0.000 (2008-03-27)
  773. */
  774. protected $currpagegroup = 0;
  775. /**
  776. * Array of transparency objects and parameters.
  777. * @protected
  778. * @since 3.0.000 (2008-03-27)
  779. */
  780. protected $extgstates;
  781. /**
  782. * Set the default JPEG compression quality (1-100).
  783. * @protected
  784. * @since 3.0.000 (2008-03-27)
  785. */
  786. protected $jpeg_quality;
  787. /**
  788. * Default cell height ratio.
  789. * @protected
  790. * @since 3.0.014 (2008-05-23)
  791. */
  792. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  793. /**
  794. * PDF viewer preferences.
  795. * @protected
  796. * @since 3.1.000 (2008-06-09)
  797. */
  798. protected $viewer_preferences;
  799. /**
  800. * A name object specifying how the document should be displayed when opened.
  801. * @protected
  802. * @since 3.1.000 (2008-06-09)
  803. */
  804. protected $PageMode;
  805. /**
  806. * Array for storing gradient information.
  807. * @protected
  808. * @since 3.1.000 (2008-06-09)
  809. */
  810. protected $gradients = array();
  811. /**
  812. * Array used to store positions inside the pages buffer (keys are the page numbers).
  813. * @protected
  814. * @since 3.2.000 (2008-06-26)
  815. */
  816. protected $intmrk = array();
  817. /**
  818. * Array used to store positions inside the pages buffer (keys are the page numbers).
  819. * @protected
  820. * @since 5.7.000 (2010-08-03)
  821. */
  822. protected $bordermrk = array();
  823. /**
  824. * Array used to store page positions to track empty pages (keys are the page numbers).
  825. * @protected
  826. * @since 5.8.007 (2010-08-18)
  827. */
  828. protected $emptypagemrk = array();
  829. /**
  830. * Array used to store content positions inside the pages buffer (keys are the page numbers).
  831. * @protected
  832. * @since 4.6.021 (2009-07-20)
  833. */
  834. protected $cntmrk = array();
  835. /**
  836. * Array used to store footer positions of each page.
  837. * @protected
  838. * @since 3.2.000 (2008-07-01)
  839. */
  840. protected $footerpos = array();
  841. /**
  842. * Array used to store footer length of each page.
  843. * @protected
  844. * @since 4.0.014 (2008-07-29)
  845. */
  846. protected $footerlen = array();
  847. /**
  848. * Boolean flag to indicate if a new line is created.
  849. * @protected
  850. * @since 3.2.000 (2008-07-01)
  851. */
  852. protected $newline = true;
  853. /**
  854. * End position of the latest inserted line.
  855. * @protected
  856. * @since 3.2.000 (2008-07-01)
  857. */
  858. protected $endlinex = 0;
  859. /**
  860. * PDF string for width value of the last line.
  861. * @protected
  862. * @since 4.0.006 (2008-07-16)
  863. */
  864. protected $linestyleWidth = '';
  865. /**
  866. * PDF string for CAP value of the last line.
  867. * @protected
  868. * @since 4.0.006 (2008-07-16)
  869. */
  870. protected $linestyleCap = '0 J';
  871. /**
  872. * PDF string for join value of the last line.
  873. * @protected
  874. * @since 4.0.006 (2008-07-16)
  875. */
  876. protected $linestyleJoin = '0 j';
  877. /**
  878. * PDF string for dash value of the last line.
  879. * @protected
  880. * @since 4.0.006 (2008-07-16)
  881. */
  882. protected $linestyleDash = '[] 0 d';
  883. /**
  884. * Boolean flag to indicate if marked-content sequence is open.
  885. * @protected
  886. * @since 4.0.013 (2008-07-28)
  887. */
  888. protected $openMarkedContent = false;
  889. /**
  890. * Count the latest inserted vertical spaces on HTML.
  891. * @protected
  892. * @since 4.0.021 (2008-08-24)
  893. */
  894. protected $htmlvspace = 0;
  895. /**
  896. * Array of Spot colors.
  897. * @protected
  898. * @since 4.0.024 (2008-09-12)
  899. */
  900. protected $spot_colors = array();
  901. /**
  902. * Symbol used for HTML unordered list items.
  903. * @protected
  904. * @since 4.0.028 (2008-09-26)
  905. */
  906. protected $lisymbol = '';
  907. /**
  908. * String used to mark the beginning and end of EPS image blocks.
  909. * @protected
  910. * @since 4.1.000 (2008-10-18)
  911. */
  912. protected $epsmarker = 'x#!#EPS#!#x';
  913. /**
  914. * Array of transformation matrix.
  915. * @protected
  916. * @since 4.2.000 (2008-10-29)
  917. */
  918. protected $transfmatrix = array();
  919. /**
  920. * Current key for transformation matrix.
  921. * @protected
  922. * @since 4.8.005 (2009-09-17)
  923. */
  924. protected $transfmatrix_key = 0;
  925. /**
  926. * Booklet mode for double-sided pages.
  927. * @protected
  928. * @since 4.2.000 (2008-10-29)
  929. */
  930. protected $booklet = false;
  931. /**
  932. * Epsilon value used for float calculations.
  933. * @protected
  934. * @since 4.2.000 (2008-10-29)
  935. */
  936. protected $feps = 0.005;
  937. /**
  938. * Array used for custom vertical spaces for HTML tags.
  939. * @protected
  940. * @since 4.2.001 (2008-10-30)
  941. */
  942. protected $tagvspaces = array();
  943. /**
  944. * HTML PARSER: custom indent amount for lists. Negative value means disabled.
  945. * @protected
  946. * @since 4.2.007 (2008-11-12)
  947. */
  948. protected $customlistindent = -1;
  949. /**
  950. * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
  951. * @protected
  952. * @since 4.2.010 (2008-11-14)
  953. */
  954. protected $opencell = true;
  955. /**
  956. * Array of files to embedd.
  957. * @protected
  958. * @since 4.4.000 (2008-12-07)
  959. */
  960. protected $embeddedfiles = array();
  961. /**
  962. * Boolean flag to indicate if we are inside a PRE tag.
  963. * @protected
  964. * @since 4.4.001 (2008-12-08)
  965. */
  966. protected $premode = false;
  967. /**
  968. * Array used to store positions of graphics transformation blocks inside the page buffer.
  969. * keys are the page numbers
  970. * @protected
  971. * @since 4.4.002 (2008-12-09)
  972. */
  973. protected $transfmrk = array();
  974. /**
  975. * Default color for html links.
  976. * @protected
  977. * @since 4.4.003 (2008-12-09)
  978. */
  979. protected $htmlLinkColorArray = array(0, 0, 255);
  980. /**
  981. * Default font style to add to html links.
  982. * @protected
  983. * @since 4.4.003 (2008-12-09)
  984. */
  985. protected $htmlLinkFontStyle = 'U';
  986. /**
  987. * Counts the number of pages.
  988. * @protected
  989. * @since 4.5.000 (2008-12-31)
  990. */
  991. protected $numpages = 0;
  992. /**
  993. * Array containing page lengths in bytes.
  994. * @protected
  995. * @since 4.5.000 (2008-12-31)
  996. */
  997. protected $pagelen = array();
  998. /**
  999. * Counts the number of pages.
  1000. * @protected
  1001. * @since 4.5.000 (2008-12-31)
  1002. */
  1003. protected $numimages = 0;
  1004. /**
  1005. * Store the image keys.
  1006. * @protected
  1007. * @since 4.5.000 (2008-12-31)
  1008. */
  1009. protected $imagekeys = array();
  1010. /**
  1011. * Length of the buffer in bytes.
  1012. * @protected
  1013. * @since 4.5.000 (2008-12-31)
  1014. */
  1015. protected $bufferlen = 0;
  1016. /**
  1017. * If true enables disk caching.
  1018. * @protected
  1019. * @since 4.5.000 (2008-12-31)
  1020. */
  1021. protected $diskcache = false;
  1022. /**
  1023. * Counts the number of fonts.
  1024. * @protected
  1025. * @since 4.5.000 (2009-01-02)
  1026. */
  1027. protected $numfonts = 0;
  1028. /**
  1029. * Store the font keys.
  1030. * @protected
  1031. * @since 4.5.000 (2009-01-02)
  1032. */
  1033. protected $fontkeys = array();
  1034. /**
  1035. * Store the font object IDs.
  1036. * @protected
  1037. * @since 4.8.001 (2009-09-09)
  1038. */
  1039. protected $font_obj_ids = array();
  1040. /**
  1041. * Store the fage status (true when opened, false when closed).
  1042. * @protected
  1043. * @since 4.5.000 (2009-01-02)
  1044. */
  1045. protected $pageopen = array();
  1046. /**
  1047. * Default monospace font.
  1048. * @protected
  1049. * @since 4.5.025 (2009-03-10)
  1050. */
  1051. protected $default_monospaced_font = 'courier';
  1052. /**
  1053. * Cloned copy of the current class object.
  1054. * @protected
  1055. * @since 4.5.029 (2009-03-19)
  1056. */
  1057. protected $objcopy;
  1058. /**
  1059. * Array used to store the lengths of cache files.
  1060. * @protected
  1061. * @since 4.5.029 (2009-03-19)
  1062. */
  1063. protected $cache_file_length = array();
  1064. /**
  1065. * Table header content to be repeated on each new page.
  1066. * @protected
  1067. * @since 4.5.030 (2009-03-20)
  1068. */
  1069. protected $thead = '';
  1070. /**
  1071. * Margins used for table header.
  1072. * @protected
  1073. * @since 4.5.030 (2009-03-20)
  1074. */
  1075. protected $theadMargins = array();
  1076. /**
  1077. * Boolean flag to enable document digital signature.
  1078. * @protected
  1079. * @since 4.6.005 (2009-04-24)
  1080. */
  1081. protected $sign = false;
  1082. /**
  1083. * Digital signature data.
  1084. * @protected
  1085. * @since 4.6.005 (2009-04-24)
  1086. */
  1087. protected $signature_data = array();
  1088. /**
  1089. * Digital signature max length.
  1090. * @protected
  1091. * @since 4.6.005 (2009-04-24)
  1092. */
  1093. protected $signature_max_length = 11742;
  1094. /**
  1095. * Data for digital signature appearance.
  1096. * @protected
  1097. * @since 5.3.011 (2010-06-16)
  1098. */
  1099. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1100. /**
  1101. * Array of empty digital signature appearances.
  1102. * @protected
  1103. * @since 5.9.101 (2011-07-06)
  1104. */
  1105. protected $empty_signature_appearance = array();
  1106. /**
  1107. * Regular expression used to find blank characters (required for word-wrapping).
  1108. * @protected
  1109. * @since 4.6.006 (2009-04-28)
  1110. */
  1111. protected $re_spaces = '/[^\S\xa0]/';
  1112. /**
  1113. * Array of $re_spaces parts.
  1114. * @protected
  1115. * @since 5.5.011 (2010-07-09)
  1116. */
  1117. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1118. /**
  1119. * Digital signature object ID.
  1120. * @protected
  1121. * @since 4.6.022 (2009-06-23)
  1122. */
  1123. protected $sig_obj_id = 0;
  1124. /**
  1125. * ID of page objects.
  1126. * @protected
  1127. * @since 4.7.000 (2009-08-29)
  1128. */
  1129. protected $page_obj_id = array();
  1130. /**
  1131. * List of form annotations IDs.
  1132. * @protected
  1133. * @since 4.8.000 (2009-09-07)
  1134. */
  1135. protected $form_obj_id = array();
  1136. /**
  1137. * 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.
  1138. * @protected
  1139. * @since 4.8.000 (2009-09-07)
  1140. */
  1141. protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1142. /**
  1143. * Javascript objects array.
  1144. * @protected
  1145. * @since 4.8.000 (2009-09-07)
  1146. */
  1147. protected $js_objects = array();
  1148. /**
  1149. * Current form action (used during XHTML rendering).
  1150. * @protected
  1151. * @since 4.8.000 (2009-09-07)
  1152. */
  1153. protected $form_action = '';
  1154. /**
  1155. * Current form encryption type (used during XHTML rendering).
  1156. * @protected
  1157. * @since 4.8.000 (2009-09-07)
  1158. */
  1159. protected $form_enctype = 'application/x-www-form-urlencoded';
  1160. /**
  1161. * Current method to submit forms.
  1162. * @protected
  1163. * @since 4.8.000 (2009-09-07)
  1164. */
  1165. protected $form_mode = 'post';
  1166. /**
  1167. * List of fonts used on form fields (fontname => fontkey).
  1168. * @protected
  1169. * @since 4.8.001 (2009-09-09)
  1170. */
  1171. protected $annotation_fonts = array();
  1172. /**
  1173. * List of radio buttons parent objects.
  1174. * @protected
  1175. * @since 4.8.001 (2009-09-09)
  1176. */
  1177. protected $radiobutton_groups = array();
  1178. /**
  1179. * List of radio group objects IDs.
  1180. * @protected
  1181. * @since 4.8.001 (2009-09-09)
  1182. */
  1183. protected $radio_groups = array();
  1184. /**
  1185. * Text indentation value (used for text-indent CSS attribute).
  1186. * @protected
  1187. * @since 4.8.006 (2009-09-23)
  1188. */
  1189. protected $textindent = 0;
  1190. /**
  1191. * Store page number when startTransaction() is called.
  1192. * @protected
  1193. * @since 4.8.006 (2009-09-23)
  1194. */
  1195. protected $start_transaction_page = 0;
  1196. /**
  1197. * Store Y position when startTransaction() is called.
  1198. * @protected
  1199. * @since 4.9.001 (2010-03-28)
  1200. */
  1201. protected $start_transaction_y = 0;
  1202. /**
  1203. * True when we are printing the thead section on a new page.
  1204. * @protected
  1205. * @since 4.8.027 (2010-01-25)
  1206. */
  1207. protected $inthead = false;
  1208. /**
  1209. * Array of column measures (width, space, starting Y position).
  1210. * @protected
  1211. * @since 4.9.001 (2010-03-28)
  1212. */
  1213. protected $columns = array();
  1214. /**
  1215. * Number of colums.
  1216. * @protected
  1217. * @since 4.9.001 (2010-03-28)
  1218. */
  1219. protected $num_columns = 1;
  1220. /**
  1221. * Current column number.
  1222. * @protected
  1223. * @since 4.9.001 (2010-03-28)
  1224. */
  1225. protected $current_column = 0;
  1226. /**
  1227. * Starting page for columns.
  1228. * @protected
  1229. * @since 4.9.001 (2010-03-28)
  1230. */
  1231. protected $column_start_page = 0;
  1232. /**
  1233. * Maximum page and column selected.
  1234. * @protected
  1235. * @since 5.8.000 (2010-08-11)
  1236. */
  1237. protected $maxselcol = array('page' => 0, 'column' => 0);
  1238. /**
  1239. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
  1240. * @protected
  1241. * @since 5.8.000 (2010-08-11)
  1242. */
  1243. protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  1244. /**
  1245. * 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.
  1246. * @protected
  1247. * @since 4.9.008 (2010-04-03)
  1248. */
  1249. protected $textrendermode = 0;
  1250. /**
  1251. * Text stroke width in doc units.
  1252. * @protected
  1253. * @since 4.9.008 (2010-04-03)
  1254. */
  1255. protected $textstrokewidth = 0;
  1256. /**
  1257. * Current stroke color.
  1258. * @protected
  1259. * @since 4.9.008 (2010-04-03)
  1260. */
  1261. protected $strokecolor;
  1262. /**
  1263. * Default unit of measure for document.
  1264. * @protected
  1265. * @since 5.0.000 (2010-04-22)
  1266. */
  1267. protected $pdfunit = 'mm';
  1268. /**
  1269. * Boolean flag true when we are on TOC (Table Of Content) page.
  1270. * @protected
  1271. */
  1272. protected $tocpage = false;
  1273. /**
  1274. * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1275. * @protected
  1276. * @since 5.0.000 (2010-04-26)
  1277. */
  1278. protected $rasterize_vector_images = false;
  1279. /**
  1280. * Boolean flag: if true enables font subsetting by default.
  1281. * @protected
  1282. * @since 5.3.002 (2010-06-07)
  1283. */
  1284. protected $font_subsetting = true;
  1285. /**
  1286. * Array of default graphic settings.
  1287. * @protected
  1288. * @since 5.5.008 (2010-07-02)
  1289. */
  1290. protected $default_graphic_vars = array();
  1291. /**
  1292. * Array of XObjects.
  1293. * @protected
  1294. * @since 5.8.014 (2010-08-23)
  1295. */
  1296. protected $xobjects = array();
  1297. /**
  1298. * Boolean value true when we are inside an XObject.
  1299. * @protected
  1300. * @since 5.8.017 (2010-08-24)
  1301. */
  1302. protected $inxobj = false;
  1303. /**
  1304. * Current XObject ID.
  1305. * @protected
  1306. * @since 5.8.017 (2010-08-24)
  1307. */
  1308. protected $xobjid = '';
  1309. /**
  1310. * Percentage of character stretching.
  1311. * @protected
  1312. * @since 5.9.000 (2010-09-29)
  1313. */
  1314. protected $font_stretching = 100;
  1315. /**
  1316. * Increases or decreases the space between characters in a text by the specified amount (tracking).
  1317. * @protected
  1318. * @since 5.9.000 (2010-09-29)
  1319. */
  1320. protected $font_spacing = 0;
  1321. /**
  1322. * Array of no-write regions.
  1323. * ('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)
  1324. * @protected
  1325. * @since 5.9.003 (2010-10-14)
  1326. */
  1327. protected $page_regions = array();
  1328. /**
  1329. * Boolean value true when page region check is active.
  1330. * @protected
  1331. */
  1332. protected $check_page_regions = true;
  1333. /**
  1334. * Array of PDF layers data.
  1335. * @protected
  1336. * @since 5.9.102 (2011-07-13)
  1337. */
  1338. protected $pdflayers = array();
  1339. /**
  1340. * A dictionary of names and corresponding destinations (Dests key on document Catalog).
  1341. * @protected
  1342. * @since 5.9.097 (2011-06-23)
  1343. */
  1344. protected $dests = array();
  1345. /**
  1346. * Object ID for Named Destinations
  1347. * @protected
  1348. * @since 5.9.097 (2011-06-23)
  1349. */
  1350. protected $n_dests;
  1351. /**
  1352. * Embedded Files Names
  1353. * @protected
  1354. * @since 5.9.204 (2013-01-23)
  1355. */
  1356. protected $efnames = array();
  1357. /**
  1358. * Directory used for the last SVG image.
  1359. * @protected
  1360. * @since 5.0.000 (2010-05-05)
  1361. */
  1362. protected $svgdir = '';
  1363. /**
  1364. * Deafult unit of measure for SVG.
  1365. * @protected
  1366. * @since 5.0.000 (2010-05-02)
  1367. */
  1368. protected $svgunit = 'px';
  1369. /**
  1370. * Array of SVG gradients.
  1371. * @protected
  1372. * @since 5.0.000 (2010-05-02)
  1373. */
  1374. protected $svggradients = array();
  1375. /**
  1376. * ID of last SVG gradient.
  1377. * @protected
  1378. * @since 5.0.000 (2010-05-02)
  1379. */
  1380. protected $svggradientid = 0;
  1381. /**
  1382. * Boolean value true when in SVG defs group.
  1383. * @protected
  1384. * @since 5.0.000 (2010-05-02)
  1385. */
  1386. protected $svgdefsmode = false;
  1387. /**
  1388. * Array of SVG defs.
  1389. * @protected
  1390. * @since 5.0.000 (2010-05-02)
  1391. */
  1392. protected $svgdefs = array();
  1393. /**
  1394. * Boolean value true when in SVG clipPath tag.
  1395. * @protected
  1396. * @since 5.0.000 (2010-04-26)
  1397. */
  1398. protected $svgclipmode = false;
  1399. /**
  1400. * Array of SVG clipPath commands.
  1401. * @protected
  1402. * @since 5.0.000 (2010-05-02)
  1403. */
  1404. protected $svgclippaths = array();
  1405. /**
  1406. * Array of SVG clipPath tranformation matrix.
  1407. * @protected
  1408. * @since 5.8.022 (2010-08-31)
  1409. */
  1410. protected $svgcliptm = array();
  1411. /**
  1412. * ID of last SVG clipPath.
  1413. * @protected
  1414. * @since 5.0.000 (2010-05-02)
  1415. */
  1416. protected $svgclipid = 0;
  1417. /**
  1418. * SVG text.
  1419. * @protected
  1420. * @since 5.0.000 (2010-05-02)
  1421. */
  1422. protected $svgtext = '';
  1423. /**
  1424. * SVG text properties.
  1425. * @protected
  1426. * @since 5.8.013 (2010-08-23)
  1427. */
  1428. protected $svgtextmode = array();
  1429. /**
  1430. * Array of SVG properties.
  1431. * @protected
  1432. * @since 5.0.000 (2010-05-02)
  1433. */
  1434. protected $svgstyles = array(array(
  1435. 'alignment-baseline' => 'auto',
  1436. 'baseline-shift' => 'baseline',
  1437. 'clip' => 'auto',
  1438. 'clip-path' => 'none',
  1439. 'clip-rule' => 'nonzero',
  1440. 'color' => 'black',
  1441. 'color-interpolation' => 'sRGB',
  1442. 'color-interpolation-filters' => 'linearRGB',
  1443. 'color-profile' => 'auto',
  1444. 'color-rendering' => 'auto',
  1445. 'cursor' => 'auto',
  1446. 'direction' => 'ltr',
  1447. 'display' => 'inline',
  1448. 'dominant-baseline' => 'auto',
  1449. 'enable-background' => 'accumulate',
  1450. 'fill' => 'black',
  1451. 'fill-opacity' => 1,
  1452. 'fill-rule' => 'nonzero',
  1453. 'filter' => 'none',
  1454. 'flood-color' => 'black',
  1455. 'flood-opacity' => 1,
  1456. 'font' => '',
  1457. 'font-family' => 'helvetica',
  1458. 'font-size' => 'medium',
  1459. 'font-size-adjust' => 'none',
  1460. 'font-stretch' => 'normal',
  1461. 'font-style' => 'normal',
  1462. 'font-variant' => 'normal',
  1463. 'font-weight' => 'normal',
  1464. 'glyph-orientation-horizontal' => '0deg',
  1465. 'glyph-orientation-vertical' => 'auto',
  1466. 'image-rendering' => 'auto',
  1467. 'kerning' => 'auto',
  1468. 'letter-spacing' => 'normal',
  1469. 'lighting-color' => 'white',
  1470. 'marker' => '',
  1471. 'marker-end' => 'none',
  1472. 'marker-mid' => 'none',
  1473. 'marker-start' => 'none',
  1474. 'mask' => 'none',
  1475. 'opacity' => 1,
  1476. 'overflow' => 'auto',
  1477. 'pointer-events' => 'visiblePainted',
  1478. 'shape-rendering' => 'auto',
  1479. 'stop-color' => 'black',
  1480. 'stop-opacity' => 1,
  1481. 'stroke' => 'none',
  1482. 'stroke-dasharray' => 'none',
  1483. 'stroke-dashoffset' => 0,
  1484. 'stroke-linecap' => 'butt',
  1485. 'stroke-linejoin' => 'miter',
  1486. 'stroke-miterlimit' => 4,
  1487. 'stroke-opacity' => 1,
  1488. 'stroke-width' => 1,
  1489. 'text-anchor' => 'start',
  1490. 'text-decoration' => 'none',
  1491. 'text-rendering' => 'auto',
  1492. 'unicode-bidi' => 'normal',
  1493. 'visibility' => 'visible',
  1494. 'word-spacing' => 'normal',
  1495. 'writing-mode' => 'lr-tb',
  1496. 'text-color' => 'black',
  1497. 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
  1498. ));
  1499. /**
  1500. * If true force sRGB color profile for all document.
  1501. * @protected
  1502. * @since 5.9.121 (2011-09-28)
  1503. */
  1504. protected $force_srgb = false;
  1505. /**
  1506. * If true set the document to PDF/A mode.
  1507. * @protected
  1508. * @since 5.9.121 (2011-09-27)
  1509. */
  1510. protected $pdfa_mode = false;
  1511. /**
  1512. * Document creation date-time
  1513. * @protected
  1514. * @since 5.9.152 (2012-03-22)
  1515. */
  1516. protected $doc_creation_timestamp;
  1517. /**
  1518. * Document modification date-time
  1519. * @protected
  1520. * @since 5.9.152 (2012-03-22)
  1521. */
  1522. protected $doc_modification_timestamp;
  1523. /**
  1524. * Custom XMP data.
  1525. * @protected
  1526. * @since 5.9.128 (2011-10-06)
  1527. */
  1528. protected $custom_xmp = '';
  1529. /**
  1530. * Overprint mode array.
  1531. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1532. * @protected
  1533. * @since 5.9.152 (2012-03-23)
  1534. */
  1535. protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
  1536. /**
  1537. * Alpha mode array.
  1538. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  1539. * @protected
  1540. * @since 5.9.152 (2012-03-23)
  1541. */
  1542. protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
  1543. /**
  1544. * Define the page boundaries boxes to be set on document.
  1545. * @protected
  1546. * @since 5.9.152 (2012-03-23)
  1547. */
  1548. protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  1549. /**
  1550. * If true print TCPDF meta link.
  1551. * @protected
  1552. * @since 5.9.152 (2012-03-23)
  1553. */
  1554. protected $tcpdflink = true;
  1555. /**
  1556. * Cache array for computed GD gamma values.
  1557. * @protected
  1558. * @since 5.9.1632 (2012-06-05)
  1559. */
  1560. protected $gdgammacache = array();
  1561. //------------------------------------------------------------
  1562. // METHODS
  1563. //------------------------------------------------------------
  1564. /**
  1565. * This is the class constructor.
  1566. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1567. *
  1568. * IMPORTANT: Please note that this method sets the mb_internal_encoding to ASCII, so if you are using the mbstring module functions with TCPDF you need to correctly set/unset the mb_internal_encoding when needed.
  1569. *
  1570. * @param $orientation (string) 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>
  1571. * @param $unit (string) 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.
  1572. * @param $format (mixed) 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().
  1573. * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
  1574. * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8.
  1575. * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1576. * @param $pdfa (boolean) If TRUE set the document to PDF/A mode.
  1577. * @public
  1578. * @see getPageSizeFromFormat(), setPageFormat()
  1579. */
  1580. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
  1581. /* Set internal character encoding to ASCII */
  1582. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1583. $this->internal_encoding = mb_internal_encoding();
  1584. mb_internal_encoding('ASCII');
  1585. }
  1586. $this->font_obj_ids = array();
  1587. $this->page_obj_id = array();
  1588. $this->form_obj_id = array();
  1589. // set pdf/a mode
  1590. $this->pdfa_mode = $pdfa;
  1591. $this->force_srgb = false;
  1592. // set disk caching
  1593. $this->diskcache = $diskcache ? true : false;
  1594. // set language direction
  1595. $this->rtl = false;
  1596. $this->tmprtl = false;
  1597. // some checks
  1598. $this->_dochecks();
  1599. // initialization of properties
  1600. $this->isunicode = $unicode;
  1601. $this->page = 0;
  1602. $this->transfmrk[0] = array();
  1603. $this->pagedim = array();
  1604. $this->n = 2;
  1605. $this->buffer = '';
  1606. $this->pages = array();
  1607. $this->state = 0;
  1608. $this->fonts = array();
  1609. $this->FontFiles = array();
  1610. $this->diffs = array();
  1611. $this->images = array();
  1612. $this->links = array();
  1613. $this->gradients = array();
  1614. $this->InFooter = false;
  1615. $this->lasth = 0;
  1616. $this->FontFamily = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  1617. $this->FontStyle = '';
  1618. $this->FontSizePt = 12;
  1619. $this->underline = false;
  1620. $this->overline = false;
  1621. $this->linethrough = false;
  1622. $this->DrawColor = '0 G';
  1623. $this->FillColor = '0 g';
  1624. $this->TextColor = '0 g';
  1625. $this->ColorFlag = false;
  1626. $this->pdflayers = array();
  1627. // encryption values
  1628. $this->encrypted = false;
  1629. $this->last_enc_key = '';
  1630. // standard Unicode fonts
  1631. $this->CoreFonts = array(
  1632. 'courier'=>'Courier',
  1633. 'courierB'=>'Courier-Bold',
  1634. 'courierI'=>'Courier-Oblique',
  1635. 'courierBI'=>'Courier-BoldOblique',
  1636. 'helvetica'=>'Helvetica',
  1637. 'helveticaB'=>'Helvetica-Bold',
  1638. 'helveticaI'=>'Helvetica-Oblique',
  1639. 'helveticaBI'=>'Helvetica-BoldOblique',
  1640. 'times'=>'Times-Roman',
  1641. 'timesB'=>'Times-Bold',
  1642. 'timesI'=>'Times-Italic',
  1643. 'timesBI'=>'Times-BoldItalic',
  1644. 'symbol'=>'Symbol',
  1645. 'zapfdingbats'=>'ZapfDingbats'
  1646. );
  1647. // set scale factor
  1648. $this->setPageUnit($unit);
  1649. // set page format and orientation
  1650. $this->setPageFormat($format, $orientation);
  1651. // page margins (1 cm)
  1652. $margin = 28.35 / $this->k;
  1653. $this->SetMargins($margin, $margin);
  1654. $this->clMargin = $this->lMargin;
  1655. $this->crMargin = $this->rMargin;
  1656. // internal cell padding
  1657. $cpadding = $margin / 10;
  1658. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1659. // cell margins
  1660. $this->setCellMargins(0, 0, 0, 0);
  1661. // line width (0.2 mm)
  1662. $this->LineWidth = 0.57 / $this->k;
  1663. $this->linestyleWidth = sprintf('%F w', ($this->LineWidth * $this->k));
  1664. $this->linestyleCap = '0 J';
  1665. $this->linestyleJoin = '0 j';
  1666. $this->linestyleDash = '[] 0 d';
  1667. // automatic page break
  1668. $this->SetAutoPageBreak(true, (2 * $margin));
  1669. // full width display mode
  1670. $this->SetDisplayMode('fullwidth');
  1671. // compression
  1672. $this->SetCompression();
  1673. // set default PDF version number
  1674. $this->setPDFVersion();
  1675. $this->tcpdflink = true;
  1676. $this->encoding = $encoding;
  1677. $this->HREF = array();
  1678. $this->getFontsList();
  1679. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1680. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1681. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1682. $this->extgstates = array();
  1683. $this->setTextShadow();
  1684. // user's rights
  1685. $this->sign = false;
  1686. $this->ur['enabled'] = false;
  1687. $this->ur['document'] = '/FullSave';
  1688. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1689. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1690. $this->ur['signature'] = '/Modify';
  1691. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1692. $this->ur['formex'] = '';
  1693. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
  1694. $this->empty_signature_appearance = array();
  1695. // set default JPEG quality
  1696. $this->jpeg_quality = 75;
  1697. // initialize some settings
  1698. TCPDF_FONTS::utf8Bidi(array(''), '', false, $this->isunicode, $this->CurrentFont);
  1699. // set default font
  1700. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1701. // check if PCRE Unicode support is enabled
  1702. if ($this->isunicode AND (@preg_match('/\pL/u', 'a') == 1)) {
  1703. // PCRE unicode support is turned ON
  1704. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1705. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1706. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1707. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1708. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1709. } else {
  1710. // PCRE unicode support is turned OFF
  1711. $this->setSpacesRE('/[^\S\xa0]/');
  1712. }
  1713. $this->default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
  1714. // set file ID for trailer
  1715. $serformat = (is_array($format) ? serialize($format) : $format);
  1716. $this->file_id = md5(TCPDF_STATIC::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
  1717. // set document creation and modification timestamp
  1718. $this->doc_creation_timestamp = time();
  1719. $this->doc_modification_timestamp = $this->doc_creation_timestamp;
  1720. // get default graphic vars
  1721. $this->default_graphic_vars = $this->getGraphicVars();
  1722. $this->header_xobj_autoreset = false;
  1723. $this->custom_xmp = '';
  1724. }
  1725. /**
  1726. * Default destructor.
  1727. * @public
  1728. * @since 1.53.0.TC016
  1729. */
  1730. public function __destruct() {
  1731. // restore internal encoding
  1732. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1733. mb_internal_encoding($this->internal_encoding);
  1734. }
  1735. // unset all class variables
  1736. $this->_destroy(true);
  1737. }
  1738. /**
  1739. * Set the units of measure for the document.
  1740. * @param $unit (string) 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.
  1741. * @public
  1742. * @since 3.0.015 (2008-06-06)
  1743. */
  1744. public function setPageUnit($unit) {
  1745. $unit = strtolower($unit);
  1746. //Set scale factor
  1747. switch ($unit) {
  1748. // points
  1749. case 'px':
  1750. case 'pt': {
  1751. $this->k = 1;
  1752. break;
  1753. }
  1754. // millimeters
  1755. case 'mm': {
  1756. $this->k = $this->dpi / 25.4;
  1757. break;
  1758. }
  1759. // centimeters
  1760. case 'cm': {
  1761. $this->k = $this->dpi / 2.54;
  1762. break;
  1763. }
  1764. // inches
  1765. case 'in': {
  1766. $this->k = $this->dpi;
  1767. break;
  1768. }
  1769. // unsupported unit
  1770. default : {
  1771. $this->Error('Incorrect unit: '.$unit);
  1772. break;
  1773. }
  1774. }
  1775. $this->pdfunit = $unit;
  1776. if (isset($this->CurOrientation)) {
  1777. $this->setPageOrientation($this->CurOrientation);
  1778. }
  1779. }
  1780. /**
  1781. * Change the format of the current page
  1782. * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numners (width, height) or an array containing the following measures and options:<ul>
  1783. * <li>['format'] = page format name (one of the above);</li>
  1784. * <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>
  1785. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  1786. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  1787. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  1788. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  1789. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  1790. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  1791. * <li>['CropBox'] : the visible region of default user space:</li>
  1792. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  1793. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  1794. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  1795. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  1796. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  1797. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  1798. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  1799. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  1800. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  1801. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  1802. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  1803. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  1804. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  1805. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  1806. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  1807. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  1808. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  1809. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  1810. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  1811. * <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>
  1812. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  1813. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  1814. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  1815. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  1816. * <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>
  1817. * <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>
  1818. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  1819. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  1820. * <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>
  1821. * <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>
  1822. * <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>
  1823. * <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>
  1824. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  1825. * </ul>
  1826. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
  1827. * <li>P or Portrait (default)</li>
  1828. * <li>L or Landscape</li>
  1829. * <li>'' (empty string) for automatic orientation</li>
  1830. * </ul>
  1831. * @protected
  1832. * @since 3.0.015 (2008-06-06)
  1833. * @see getPageSizeFromFormat()
  1834. */
  1835. protected function setPageFormat($format, $orientation='P') {
  1836. if (!empty($format) AND isset($this->pagedim[$this->page])) {
  1837. // remove inherited values
  1838. unset($this->pagedim[$this->page]);
  1839. }
  1840. if (is_string($format)) {
  1841. // get page measures from format name
  1842. $pf = TCPDF_STATIC::getPageSizeFromFormat($format);
  1843. $this->fwPt = $pf[0];
  1844. $this->fhPt = $pf[1];
  1845. } else {
  1846. // the boundaries of the physical medium on which the page shall be displayed or printed
  1847. if (isset($format['MediaBox'])) {
  1848. $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);
  1849. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  1850. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  1851. } else {
  1852. if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
  1853. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  1854. } else {
  1855. if (!isset($format['format'])) {
  1856. // default value
  1857. $format['format'] = 'A4';
  1858. }
  1859. $pf = TCPDF_STATIC::getPageSizeFromFormat($format['format']);
  1860. }
  1861. $this->fwPt = $pf[0];
  1862. $this->fhPt = $pf[1];
  1863. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1864. }
  1865. // the visible region of default user space
  1866. if (isset($format['CropBox'])) {
  1867. $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);
  1868. }
  1869. // the region to which the contents of the page shall be clipped when output in a production environment
  1870. if (isset($format['BleedBox'])) {
  1871. $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);
  1872. }
  1873. // the intended dimensions of the finished page after trimming
  1874. if (isset($format['TrimBox'])) {
  1875. $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);
  1876. }
  1877. // the page's meaningful content (including potential white space)
  1878. if (isset($format['ArtBox'])) {
  1879. $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);
  1880. }
  1881. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  1882. if (isset($format['BoxColorInfo'])) {
  1883. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  1884. }
  1885. if (isset($format['Rotate']) AND (($format['Rotate'] % 90) == 0)) {
  1886. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1887. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  1888. }
  1889. if (isset($format['PZ'])) {
  1890. // The page's preferred zoom (magnification) factor
  1891. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  1892. }
  1893. if (isset($format['trans'])) {
  1894. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  1895. if (isset($format['trans']['Dur'])) {
  1896. // The page's display duration
  1897. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  1898. }
  1899. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
  1900. if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
  1901. // The transition style that shall be used when moving to this page from another during a presentation
  1902. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  1903. $valid_effect = array('Split', 'Blinds');
  1904. $valid_vals = array('H', 'V');
  1905. if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
  1906. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  1907. }
  1908. $valid_effect = array('Split', 'Box', 'Fly');
  1909. $valid_vals = array('I', 'O');
  1910. if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
  1911. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  1912. }
  1913. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  1914. if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
  1915. if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
  1916. OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
  1917. OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
  1918. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  1919. }
  1920. }
  1921. if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
  1922. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  1923. }
  1924. if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
  1925. $this->pagedim[$this->page]['trans']['B'] = 'true';
  1926. }
  1927. } else {
  1928. $this->pagedim[$this->page]['trans']['S'] = 'R';
  1929. }
  1930. if (isset($format['trans']['D'])) {
  1931. // The duration of the transition effect, in seconds
  1932. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  1933. } else {
  1934. $this->pagedim[$this->page]['trans']['D'] = 1;
  1935. }
  1936. }
  1937. }
  1938. $this->setPageOrientation($orientation);
  1939. }
  1940. /**
  1941. * Set page orientation.
  1942. * @param $orientation (string) 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>
  1943. * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
  1944. * @param $bottommargin (float) bottom margin of the page.
  1945. * @public
  1946. * @since 3.0.015 (2008-06-06)
  1947. */
  1948. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  1949. if (!isset($this->pagedim[$this->page]['MediaBox'])) {
  1950. // the boundaries of the physical medium on which the page shall be displayed or printed
  1951. $this->pagedim = TCPDF_STATIC::setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true, $this->k, $this->pagedim);
  1952. }
  1953. if (!isset($this->pagedim[$this->page]['CropBox'])) {
  1954. // the visible region of default user space
  1955. $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);
  1956. }
  1957. if (!isset($this->pagedim[$this->page]['BleedBox'])) {
  1958. // the region to which the contents of the page shall be clipped when output in a production environment
  1959. $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);
  1960. }
  1961. if (!isset($this->pagedim[$this->page]['TrimBox'])) {
  1962. // the intended dimensions of the finished page after trimming
  1963. $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);
  1964. }
  1965. if (!isset($this->pagedim[$this->page]['ArtBox'])) {
  1966. // the page's meaningful content (including potential white space)
  1967. $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);
  1968. }
  1969. if (!isset($this->pagedim[$this->page]['Rotate'])) {
  1970. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  1971. $this->pagedim[$this->page]['Rotate'] = 0;
  1972. }
  1973. if (!isset($this->pagedim[$this->page]['PZ'])) {
  1974. // The page's preferred zoom (magnification) factor
  1975. $this->pagedim[$this->page]['PZ'] = 1;
  1976. }
  1977. if ($this->fwPt > $this->fhPt) {
  1978. // landscape
  1979. $default_orientation = 'L';
  1980. } else {
  1981. // portrait
  1982. $default_orientation = 'P';
  1983. }
  1984. $valid_orientations = array('P', 'L');
  1985. if (empty($orientation)) {
  1986. $orientation = $default_orientation;
  1987. } else {
  1988. $orientation = strtoupper($orientation{0});
  1989. }
  1990. if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
  1991. $this->CurOrientation = $orientation;
  1992. $this->wPt = $this->fhPt;
  1993. $this->hPt = $this->fwPt;
  1994. } else {
  1995. $this->CurOrientation = $default_orientation;
  1996. $this->wPt = $this->fwPt;
  1997. $this->hPt = $this->fhPt;
  1998. }
  1999. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) AND (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps)){
  2000. // swap X and Y coordinates (change page orientation)
  2001. $this->pagedim = TCPDF_STATIC::swapPageBoxCoordinates($this->page, $this->pagedim);
  2002. }
  2003. $this->w = ($this->wPt / $this->k);
  2004. $this->h = ($this->hPt / $this->k);
  2005. if (TCPDF_STATIC::empty_string($autopagebreak)) {
  2006. if (isset($this->AutoPageBreak)) {
  2007. $autopagebreak = $this->AutoPageBreak;
  2008. } else {
  2009. $autopagebreak = true;
  2010. }
  2011. }
  2012. if (TCPDF_STATIC::empty_string($bottommargin)) {
  2013. if (isset($this->bMargin)) {
  2014. $bottommargin = $this->bMargin;
  2015. } else {
  2016. // default value = 2 cm
  2017. $bottommargin = 2 * 28.35 / $this->k;
  2018. }
  2019. }
  2020. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  2021. // store page dimensions
  2022. $this->pagedim[$this->page]['w'] = $this->wPt;
  2023. $this->pagedim[$this->page]['h'] = $this->hPt;
  2024. $this->pagedim[$this->page]['wk'] = $this->w;
  2025. $this->pagedim[$this->page]['hk'] = $this->h;
  2026. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  2027. $this->pagedim[$this->page]['bm'] = $bottommargin;
  2028. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  2029. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  2030. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  2031. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  2032. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  2033. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  2034. }
  2035. /**
  2036. * Set regular expression to detect withespaces or word separators.
  2037. * The pattern delimiter must be the forward-slash character "/".
  2038. * Some example patterns are:
  2039. * <pre>
  2040. * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
  2041. * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
  2042. * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
  2043. * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
  2044. * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
  2045. * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  2046. * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
  2047. * </pre>
  2048. * @param $re (string) regular expression (leave empty for default).
  2049. * @public
  2050. * @since 4.6.016 (2009-06-15)
  2051. */
  2052. public function setSpacesRE($re='/[^\S\xa0]/') {
  2053. $this->re_spaces = $re;
  2054. $re_parts = explode('/', $re);
  2055. // get pattern parts
  2056. $this->re_space = array();
  2057. if (isset($re_parts[1]) AND !empty($re_parts[1])) {
  2058. $this->re_space['p'] = $re_parts[1];
  2059. } else {
  2060. $this->re_space['p'] = '[\s]';
  2061. }
  2062. // set pattern modifiers
  2063. if (isset($re_parts[2]) AND !empty($re_parts[2])) {
  2064. $this->re_space['m'] = $re_parts[2];
  2065. } else {
  2066. $this->re_space['m'] = '';
  2067. }
  2068. }
  2069. /**
  2070. * Enable or disable Right-To-Left language mode
  2071. * @param $enable (Boolean) if true enable Right-To-Left language mode.
  2072. * @param $resetx (Boolean) if true reset the X position on direction change.
  2073. * @public
  2074. * @since 2.0.000 (2008-01-03)
  2075. */
  2076. public function setRTL($enable, $resetx=true) {
  2077. $enable = $enable ? true : false;
  2078. $resetx = ($resetx AND ($enable != $this->rtl));
  2079. $this->rtl = $enable;
  2080. $this->tmprtl = false;
  2081. if ($resetx) {
  2082. $this->Ln(0);
  2083. }
  2084. }
  2085. /**
  2086. * Return the RTL status
  2087. * @return boolean
  2088. * @public
  2089. * @since 4.0.012 (2008-07-24)
  2090. */
  2091. public function getRTL() {
  2092. return $this->rtl;
  2093. }
  2094. /**
  2095. * Force temporary RTL language direction
  2096. * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
  2097. * @public
  2098. * @since 2.1.000 (2008-01-09)
  2099. */
  2100. public function setTempRTL($mode) {
  2101. $newmode = false;
  2102. switch (strtoupper($mode)) {
  2103. case 'LTR':
  2104. case 'L': {
  2105. if ($this->rtl) {
  2106. $newmode = 'L';
  2107. }
  2108. break;
  2109. }
  2110. case 'RTL':
  2111. case 'R': {
  2112. if (!$this->rtl) {
  2113. $newmode = 'R';
  2114. }
  2115. break;
  2116. }
  2117. case false:
  2118. default: {
  2119. $newmode = false;
  2120. break;
  2121. }
  2122. }
  2123. $this->tmprtl = $newmode;
  2124. }
  2125. /**
  2126. * Return the current temporary RTL status
  2127. * @return boolean
  2128. * @public
  2129. * @since 4.8.014 (2009-11-04)
  2130. */
  2131. public function isRTLTextDir() {
  2132. return ($this->rtl OR ($this->tmprtl == 'R'));
  2133. }
  2134. /**
  2135. * Set the last cell height.
  2136. * @param $h (float) cell height.
  2137. * @author Nicola Asuni
  2138. * @public
  2139. * @since 1.53.0.TC034
  2140. */
  2141. public function setLastH($h) {
  2142. $this->lasth = $h;
  2143. }
  2144. /**
  2145. * Reset the last cell height.
  2146. * @public
  2147. * @since 5.9.000 (2010-10-03)
  2148. */
  2149. public function resetLastH() {
  2150. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  2151. }
  2152. /**
  2153. * Get the last cell height.
  2154. * @return last cell height
  2155. * @public
  2156. * @since 4.0.017 (2008-08-05)
  2157. */
  2158. public function getLastH() {
  2159. return $this->lasth;
  2160. }
  2161. /**
  2162. * Set the adjusting factor to convert pixels to user units.
  2163. * @param $scale (float) adjusting factor to convert pixels to user units.
  2164. * @author Nicola Asuni
  2165. * @public
  2166. * @since 1.5.2
  2167. */
  2168. public function setImageScale($scale) {
  2169. $this->imgscale = $scale;
  2170. }
  2171. /**
  2172. * Returns the adjusting factor to convert pixels to user units.
  2173. * @return float adjusting factor to convert pixels to user units.
  2174. * @author Nicola Asuni
  2175. * @public
  2176. * @since 1.5.2
  2177. */
  2178. public function getImageScale() {
  2179. return $this->imgscale;
  2180. }
  2181. /**
  2182. * Returns an array of page dimensions:
  2183. * <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>
  2184. * @param $pagenum (int) page number (empty = current page)
  2185. * @return array of page dimensions.
  2186. * @author Nicola Asuni
  2187. * @public
  2188. * @since 4.5.027 (2009-03-16)
  2189. */
  2190. public function getPageDimensions($pagenum='') {
  2191. if (empty($pagenum)) {
  2192. $pagenum = $this->page;
  2193. }
  2194. return $this->pagedim[$pagenum];
  2195. }
  2196. /**
  2197. * Returns the page width in units.
  2198. * @param $pagenum (int) page number (empty = current page)
  2199. * @return int page width.
  2200. * @author Nicola Asuni
  2201. * @public
  2202. * @since 1.5.2
  2203. * @see getPageDimensions()
  2204. */
  2205. public function getPageWidth($pagenum='') {
  2206. if (empty($pagenum)) {
  2207. return $this->w;
  2208. }
  2209. return $this->pagedim[$pagenum]['w'];
  2210. }
  2211. /**
  2212. * Returns the page height in units.
  2213. * @param $pagenum (int) page number (empty = current page)
  2214. * @return int page height.
  2215. * @author Nicola Asuni
  2216. * @public
  2217. * @since 1.5.2
  2218. * @see getPageDimensions()
  2219. */
  2220. public function getPageHeight($pagenum='') {
  2221. if (empty($pagenum)) {
  2222. return $this->h;
  2223. }
  2224. return $this->pagedim[$pagenum]['h'];
  2225. }
  2226. /**
  2227. * Returns the page break margin.
  2228. * @param $pagenum (int) page number (empty = current page)
  2229. * @return int page break margin.
  2230. * @author Nicola Asuni
  2231. * @public
  2232. * @since 1.5.2
  2233. * @see getPageDimensions()
  2234. */
  2235. public function getBreakMargin($pagenum='') {
  2236. if (empty($pagenum)) {
  2237. return $this->bMargin;
  2238. }
  2239. return $this->pagedim[$pagenum]['bm'];
  2240. }
  2241. /**
  2242. * Returns the scale factor (number of points in user unit).
  2243. * @return int scale factor.
  2244. * @author Nicola Asuni
  2245. * @public
  2246. * @since 1.5.2
  2247. */
  2248. public function getScaleFactor() {
  2249. return $this->k;
  2250. }
  2251. /**
  2252. * Defines the left, top and right margins.
  2253. * @param $left (float) Left margin.
  2254. * @param $top (float) Top margin.
  2255. * @param $right (float) Right margin. Default value is the left one.
  2256. * @param $keepmargins (boolean) if true overwrites the default page margins
  2257. * @public
  2258. * @since 1.0
  2259. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  2260. */
  2261. public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
  2262. //Set left, top and right margins
  2263. $this->lMargin = $left;
  2264. $this->tMargin = $top;
  2265. if ($right == -1) {
  2266. $right = $left;
  2267. }
  2268. $this->rMargin = $right;
  2269. if ($keepmargins) {
  2270. // overwrite original values
  2271. $this->original_lMargin = $this->lMargin;
  2272. $this->original_rMargin = $this->rMargin;
  2273. }
  2274. }
  2275. /**
  2276. * 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.
  2277. * @param $margin (float) The margin.
  2278. * @public
  2279. * @since 1.4
  2280. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2281. */
  2282. public function SetLeftMargin($margin) {
  2283. //Set left margin
  2284. $this->lMargin = $margin;
  2285. if (($this->page > 0) AND ($this->x < $margin)) {
  2286. $this->x = $margin;
  2287. }
  2288. }
  2289. /**
  2290. * Defines the top margin. The method can be called before creating the first page.
  2291. * @param $margin (float) The margin.
  2292. * @public
  2293. * @since 1.5
  2294. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  2295. */
  2296. public function SetTopMargin($margin) {
  2297. //Set top margin
  2298. $this->tMargin = $margin;
  2299. if (($this->page > 0) AND ($this->y < $margin)) {
  2300. $this->y = $margin;
  2301. }
  2302. }
  2303. /**
  2304. * Defines the right margin. The method can be called before creating the first page.
  2305. * @param $margin (float) The margin.
  2306. * @public
  2307. * @since 1.5
  2308. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  2309. */
  2310. public function SetRightMargin($margin) {
  2311. $this->rMargin = $margin;
  2312. if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  2313. $this->x = $this->w - $margin;
  2314. }
  2315. }
  2316. /**
  2317. * Set the same internal Cell padding for top, right, bottom, left-
  2318. * @param $pad (float) internal padding.
  2319. * @public
  2320. * @since 2.1.000 (2008-01-09)
  2321. * @see getCellPaddings(), setCellPaddings()
  2322. */
  2323. public function SetCellPadding($pad) {
  2324. if ($pad >= 0) {
  2325. $this->cell_padding['L'] = $pad;
  2326. $this->cell_padding['T'] = $pad;
  2327. $this->cell_padding['R'] = $pad;
  2328. $this->cell_padding['B'] = $pad;
  2329. }
  2330. }
  2331. /**
  2332. * Set the internal Cell paddings.
  2333. * @param $left (float) left padding
  2334. * @param $top (float) top padding
  2335. * @param $right (float) right padding
  2336. * @param $bottom (float) bottom padding
  2337. * @public
  2338. * @since 5.9.000 (2010-10-03)
  2339. * @see getCellPaddings(), SetCellPadding()
  2340. */
  2341. public function setCellPaddings($left='', $top='', $right='', $bottom='') {
  2342. if (($left !== '') AND ($left >= 0)) {
  2343. $this->cell_padding['L'] = $left;
  2344. }
  2345. if (($top !== '') AND ($top >= 0)) {
  2346. $this->cell_padding['T'] = $top;
  2347. }
  2348. if (($right !== '') AND ($right >= 0)) {
  2349. $this->cell_padding['R'] = $right;
  2350. }
  2351. if (($bottom !== '') AND ($bottom >= 0)) {
  2352. $this->cell_padding['B'] = $bottom;
  2353. }
  2354. }
  2355. /**
  2356. * Get the internal Cell padding array.
  2357. * @return array of padding values
  2358. * @public
  2359. * @since 5.9.000 (2010-10-03)
  2360. * @see setCellPaddings(), SetCellPadding()
  2361. */
  2362. public function getCellPaddings() {
  2363. return $this->cell_padding;
  2364. }
  2365. /**
  2366. * Set the internal Cell margins.
  2367. * @param $left (float) left margin
  2368. * @param $top (float) top margin
  2369. * @param $right (float) right margin
  2370. * @param $bottom (float) bottom margin
  2371. * @public
  2372. * @since 5.9.000 (2010-10-03)
  2373. * @see getCellMargins()
  2374. */
  2375. public function setCellMargins($left='', $top='', $right='', $bottom='') {
  2376. if (($left !== '') AND ($left >= 0)) {
  2377. $this->cell_margin['L'] = $left;
  2378. }
  2379. if (($top !== '') AND ($top >= 0)) {
  2380. $this->cell_margin['T'] = $top;
  2381. }
  2382. if (($right !== '') AND ($right >= 0)) {
  2383. $this->cell_margin['R'] = $right;
  2384. }
  2385. if (($bottom !== '') AND ($bottom >= 0)) {
  2386. $this->cell_margin['B'] = $bottom;
  2387. }
  2388. }
  2389. /**
  2390. * Get the internal Cell margin array.
  2391. * @return array of margin values
  2392. * @public
  2393. * @since 5.9.000 (2010-10-03)
  2394. * @see setCellMargins()
  2395. */
  2396. public function getCellMargins() {
  2397. return $this->cell_margin;
  2398. }
  2399. /**
  2400. * Adjust the internal Cell padding array to take account of the line width.
  2401. * @param $brd (mixed) 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)))
  2402. * @return array of adjustments
  2403. * @public
  2404. * @since 5.9.000 (2010-10-03)
  2405. */
  2406. protected function adjustCellPadding($brd=0) {
  2407. if (empty($brd)) {
  2408. return;
  2409. }
  2410. if (is_string($brd)) {
  2411. // convert string to array
  2412. $slen = strlen($brd);
  2413. $newbrd = array();
  2414. for ($i = 0; $i < $slen; ++$i) {
  2415. $newbrd[$brd[$i]] = true;
  2416. }
  2417. $brd = $newbrd;
  2418. } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
  2419. $brd = array('LRTB' => true);
  2420. }
  2421. if (!is_array($brd)) {
  2422. return;
  2423. }
  2424. // store current cell padding
  2425. $cp = $this->cell_padding;
  2426. // select border mode
  2427. if (isset($brd['mode'])) {
  2428. $mode = $brd['mode'];
  2429. unset($brd['mode']);
  2430. } else {
  2431. $mode = 'normal';
  2432. }
  2433. // process borders
  2434. foreach ($brd as $border => $style) {
  2435. $line_width = $this->LineWidth;
  2436. if (is_array($style) AND isset($style['width'])) {
  2437. // get border width
  2438. $line_width = $style['width'];
  2439. }
  2440. $adj = 0; // line width inside the cell
  2441. switch ($mode) {
  2442. case 'ext': {
  2443. $adj = 0;
  2444. break;
  2445. }
  2446. case 'int': {
  2447. $adj = $line_width;
  2448. break;
  2449. }
  2450. case 'normal':
  2451. default: {
  2452. $adj = ($line_width / 2);
  2453. break;
  2454. }
  2455. }
  2456. // correct internal cell padding if required to avoid overlap between text and lines
  2457. if ((strpos($border,'T') !== false) AND ($this->cell_padding['T'] < $adj)) {
  2458. $this->cell_padding['T'] = $adj;
  2459. }
  2460. if ((strpos($border,'R') !== false) AND ($this->cell_padding['R'] < $adj)) {
  2461. $this->cell_padding['R'] = $adj;
  2462. }
  2463. if ((strpos($border,'B') !== false) AND ($this->cell_padding['B'] < $adj)) {
  2464. $this->cell_padding['B'] = $adj;
  2465. }
  2466. if ((strpos($border,'L') !== false) AND ($this->cell_padding['L'] < $adj)) {
  2467. $this->cell_padding['L'] = $adj;
  2468. }
  2469. }
  2470. return array('T' => ($this->cell_padding['T'] - $cp['T']), 'R' => ($this->cell_padding['R'] - $cp['R']), 'B' => ($this->cell_padding['B'] - $cp['B']), 'L' => ($this->cell_padding['L'] - $cp['L']));
  2471. }
  2472. /**
  2473. * 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.
  2474. * @param $auto (boolean) Boolean indicating if mode should be on or off.
  2475. * @param $margin (float) Distance from the bottom of the page.
  2476. * @public
  2477. * @since 1.0
  2478. * @see Cell(), MultiCell(), AcceptPageBreak()
  2479. */
  2480. public function SetAutoPageBreak($auto, $margin=0) {
  2481. $this->AutoPageBreak = $auto ? true : false;
  2482. $this->bMargin = $margin;
  2483. $this->PageBreakTrigger = $this->h - $margin;
  2484. }
  2485. /**
  2486. * Return the auto-page-break mode (true or false).
  2487. * @return boolean auto-page-break mode
  2488. * @public
  2489. * @since 5.9.088
  2490. */
  2491. public function getAutoPageBreak() {
  2492. return $this->AutoPageBreak;
  2493. }
  2494. /**
  2495. * Defines the way the document is to be displayed by the viewer.
  2496. * @param $zoom (mixed) 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>
  2497. * @param $layout (string) 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>
  2498. * @param $mode (string) 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>
  2499. * @public
  2500. * @since 1.2
  2501. */
  2502. public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
  2503. if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
  2504. $this->ZoomMode = $zoom;
  2505. } else {
  2506. $this->Error('Incorrect zoom display mode: '.$zoom);
  2507. }
  2508. $this->LayoutMode = TCPDF_STATIC::getPageLayoutMode($layout);
  2509. $this->PageMode = TCPDF_STATIC::getPageMode($mode);
  2510. }
  2511. /**
  2512. * 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.
  2513. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  2514. * @param $compress (boolean) Boolean indicating if compression must be enabled.
  2515. * @public
  2516. * @since 1.4
  2517. */
  2518. public function SetCompression($compress=true) {
  2519. if (function_exists('gzcompress')) {
  2520. $this->compress = $compress ? true : false;
  2521. } else {
  2522. $this->compress = false;
  2523. }
  2524. }
  2525. /**
  2526. * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
  2527. * @param $mode (boolean) If true force sRGB output intent.
  2528. * @public
  2529. * @since 5.9.121 (2011-09-28)
  2530. */
  2531. public function setSRGBmode($mode=false) {
  2532. $this->force_srgb = $mode ? true : false;
  2533. }
  2534. /**
  2535. * Turn on/off Unicode mode for document information dictionary (meta tags).
  2536. * This has effect only when unicode mode is set to false.
  2537. * @param $unicode (boolean) if true set the meta information in Unicode
  2538. * @since 5.9.027 (2010-12-01)
  2539. * @public
  2540. */
  2541. public function SetDocInfoUnicode($unicode=true) {
  2542. $this->docinfounicode = $unicode ? true : false;
  2543. }
  2544. /**
  2545. * Defines the title of the document.
  2546. * @param $title (string) The title.
  2547. * @public
  2548. * @since 1.2
  2549. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  2550. */
  2551. public function SetTitle($title) {
  2552. $this->title = $title;
  2553. }
  2554. /**
  2555. * Defines the subject of the document.
  2556. * @param $subject (string) The subject.
  2557. * @public
  2558. * @since 1.2
  2559. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  2560. */
  2561. public function SetSubject($subject) {
  2562. $this->subject = $subject;
  2563. }
  2564. /**
  2565. * Defines the author of the document.
  2566. * @param $author (string) The name of the author.
  2567. * @public
  2568. * @since 1.2
  2569. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  2570. */
  2571. public function SetAuthor($author) {
  2572. $this->author = $author;
  2573. }
  2574. /**
  2575. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  2576. * @param $keywords (string) The list of keywords.
  2577. * @public
  2578. * @since 1.2
  2579. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  2580. */
  2581. public function SetKeywords($keywords) {
  2582. $this->keywords = $keywords;
  2583. }
  2584. /**
  2585. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  2586. * @param $creator (string) The name of the creator.
  2587. * @public
  2588. * @since 1.2
  2589. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  2590. */
  2591. public function SetCreator($creator) {
  2592. $this->creator = $creator;
  2593. }
  2594. /**
  2595. * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
  2596. * @param $msg (string) The error message
  2597. * @public
  2598. * @since 1.0
  2599. */
  2600. public function Error($msg) {
  2601. // unset all class variables
  2602. $this->_destroy(true);
  2603. if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR) {
  2604. die('<strong>TCPDF ERROR: </strong>'.$msg);
  2605. } else {
  2606. throw new Exception('TCPDF ERROR: '.$msg);
  2607. }
  2608. }
  2609. /**
  2610. * This method begins the generation of the PDF document.
  2611. * It is not necessary to call it explicitly because AddPage() does it automatically.
  2612. * Note: no page is created by this method
  2613. * @public
  2614. * @since 1.0
  2615. * @see AddPage(), Close()
  2616. */
  2617. public function Open() {
  2618. $this->state = 1;
  2619. }
  2620. /**
  2621. * Terminates the PDF document.
  2622. * It is not necessary to call this method explicitly because Output() does it automatically.
  2623. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  2624. * @public
  2625. * @since 1.0
  2626. * @see Open(), Output()
  2627. */
  2628. public function Close() {
  2629. if ($this->state == 3) {
  2630. return;
  2631. }
  2632. if ($this->page == 0) {
  2633. $this->AddPage();
  2634. }
  2635. $this->endLayer();
  2636. if ($this->tcpdflink) {
  2637. // save current graphic settings
  2638. $gvars = $this->getGraphicVars();
  2639. $this->setEqualColumns();
  2640. $this->lastpage(true);
  2641. $this->SetAutoPageBreak(false);
  2642. $this->x = 0;
  2643. $this->y = $this->h - (1 / $this->k);
  2644. $this->lMargin = 0;
  2645. $this->_out('q');
  2646. $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN:'helvetica';
  2647. $this->SetFont($font, '', 1);
  2648. $this->setTextRenderingMode(0, false, false);
  2649. $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";
  2650. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  2651. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  2652. $this->_out('Q');
  2653. // restore graphic settings
  2654. $this->setGraphicVars($gvars);
  2655. }
  2656. // close page
  2657. $this->endPage();
  2658. // close document
  2659. $this->_enddoc();
  2660. // unset all class variables (except critical ones)
  2661. $this->_destroy(false);
  2662. }
  2663. /**
  2664. * Move pointer at the specified document page and update page dimensions.
  2665. * @param $pnum (int) page number (1 ... numpages)
  2666. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2667. * @public
  2668. * @since 2.1.000 (2008-01-07)
  2669. * @see getPage(), lastpage(), getNumPages()
  2670. */
  2671. public function setPage($pnum, $resetmargins=false) {
  2672. if (($pnum == $this->page) AND ($this->state == 2)) {
  2673. return;
  2674. }
  2675. if (($pnum > 0) AND ($pnum <= $this->numpages)) {
  2676. $this->state = 2;
  2677. // save current graphic settings
  2678. //$gvars = $this->getGraphicVars();
  2679. $oldpage = $this->page;
  2680. $this->page = $pnum;
  2681. $this->wPt = $this->pagedim[$this->page]['w'];
  2682. $this->hPt = $this->pagedim[$this->page]['h'];
  2683. $this->w = $this->pagedim[$this->page]['wk'];
  2684. $this->h = $this->pagedim[$this->page]['hk'];
  2685. $this->tMargin = $this->pagedim[$this->page]['tm'];
  2686. $this->bMargin = $this->pagedim[$this->page]['bm'];
  2687. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  2688. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  2689. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  2690. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  2691. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  2692. // restore graphic settings
  2693. //$this->setGraphicVars($gvars);
  2694. if ($resetmargins) {
  2695. $this->lMargin = $this->pagedim[$this->page]['olm'];
  2696. $this->rMargin = $this->pagedim[$this->page]['orm'];
  2697. $this->SetY($this->tMargin);
  2698. } else {
  2699. // account for booklet mode
  2700. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  2701. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  2702. $this->lMargin += $deltam;
  2703. $this->rMargin -= $deltam;
  2704. }
  2705. }
  2706. } else {
  2707. $this->Error('Wrong page number on setPage() function: '.$pnum);
  2708. }
  2709. }
  2710. /**
  2711. * Reset pointer to the last document page.
  2712. * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
  2713. * @public
  2714. * @since 2.0.000 (2008-01-04)
  2715. * @see setPage(), getPage(), getNumPages()
  2716. */
  2717. public function lastPage($resetmargins=false) {
  2718. $this->setPage($this->getNumPages(), $resetmargins);
  2719. }
  2720. /**
  2721. * Get current document page number.
  2722. * @return int page number
  2723. * @public
  2724. * @since 2.1.000 (2008-01-07)
  2725. * @see setPage(), lastpage(), getNumPages()
  2726. */
  2727. public function getPage() {
  2728. return $this->page;
  2729. }
  2730. /**
  2731. * Get the total number of insered pages.
  2732. * @return int number of pages
  2733. * @public
  2734. * @since 2.1.000 (2008-01-07)
  2735. * @see setPage(), getPage(), lastpage()
  2736. */
  2737. public function getNumPages() {
  2738. return $this->numpages;
  2739. }
  2740. /**
  2741. * Adds a new TOC (Table Of Content) page to the document.
  2742. * @param $orientation (string) page orientation.
  2743. * @param $format (mixed) 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().
  2744. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2745. * @public
  2746. * @since 5.0.001 (2010-05-06)
  2747. * @see AddPage(), startPage(), endPage(), endTOCPage()
  2748. */
  2749. public function addTOCPage($orientation='', $format='', $keepmargins=false) {
  2750. $this->AddPage($orientation, $format, $keepmargins, true);
  2751. }
  2752. /**
  2753. * Terminate the current TOC (Table Of Content) page
  2754. * @public
  2755. * @since 5.0.001 (2010-05-06)
  2756. * @see AddPage(), startPage(), endPage(), addTOCPage()
  2757. */
  2758. public function endTOCPage() {
  2759. $this->endPage(true);
  2760. }
  2761. /**
  2762. * 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).
  2763. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  2764. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2765. * @param $format (mixed) 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().
  2766. * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
  2767. * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
  2768. * @public
  2769. * @since 1.0
  2770. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2771. */
  2772. public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
  2773. if ($this->inxobj) {
  2774. // we are inside an XObject template
  2775. return;
  2776. }
  2777. if (!isset($this->original_lMargin) OR $keepmargins) {
  2778. $this->original_lMargin = $this->lMargin;
  2779. }
  2780. if (!isset($this->original_rMargin) OR $keepmargins) {
  2781. $this->original_rMargin = $this->rMargin;
  2782. }
  2783. // terminate previous page
  2784. $this->endPage();
  2785. // start new page
  2786. $this->startPage($orientation, $format, $tocpage);
  2787. }
  2788. /**
  2789. * Terminate the current page
  2790. * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
  2791. * @public
  2792. * @since 4.2.010 (2008-11-14)
  2793. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  2794. */
  2795. public function endPage($tocpage=false) {
  2796. // check if page is already closed
  2797. if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
  2798. return;
  2799. }
  2800. // print page footer
  2801. $this->setFooter();
  2802. // close page
  2803. $this->_endpage();
  2804. // mark page as closed
  2805. $this->pageopen[$this->page] = false;
  2806. if ($tocpage) {
  2807. $this->tocpage = false;
  2808. }
  2809. }
  2810. /**
  2811. * Starts a new page to the document. The page must be closed using the endPage() function.
  2812. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  2813. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  2814. * @param $format (mixed) 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().
  2815. * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
  2816. * @since 4.2.010 (2008-11-14)
  2817. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  2818. * @public
  2819. */
  2820. public function startPage($orientation='', $format='', $tocpage=false) {
  2821. if ($tocpage) {
  2822. $this->tocpage = true;
  2823. }
  2824. // move page numbers of documents to be attached
  2825. if ($this->tocpage) {
  2826. // move reference to unexistent pages (used for page attachments)
  2827. // adjust outlines
  2828. $tmpoutlines = $this->outlines;
  2829. foreach ($tmpoutlines as $key => $outline) {
  2830. if ($outline['p'] > $this->numpages) {
  2831. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  2832. }
  2833. }
  2834. // adjust dests
  2835. $tmpdests = $this->dests;
  2836. foreach ($tmpdests as $key => $dest) {
  2837. if ($dest['p'] > $this->numpages) {
  2838. $this->dests[$key]['p'] = ($dest['p'] + 1);
  2839. }
  2840. }
  2841. // adjust links
  2842. $tmplinks = $this->links;
  2843. foreach ($tmplinks as $key => $link) {
  2844. if ($link[0] > $this->numpages) {
  2845. $this->links[$key][0] = ($link[0] + 1);
  2846. }
  2847. }
  2848. }
  2849. if ($this->numpages > $this->page) {
  2850. // this page has been already added
  2851. $this->setPage($this->page + 1);
  2852. $this->SetY($this->tMargin);
  2853. return;
  2854. }
  2855. // start a new page
  2856. if ($this->state == 0) {
  2857. $this->Open();
  2858. }
  2859. ++$this->numpages;
  2860. $this->swapMargins($this->booklet);
  2861. // save current graphic settings
  2862. $gvars = $this->getGraphicVars();
  2863. // start new page
  2864. $this->_beginpage($orientation, $format);
  2865. // mark page as open
  2866. $this->pageopen[$this->page] = true;
  2867. // restore graphic settings
  2868. $this->setGraphicVars($gvars);
  2869. // mark this point
  2870. $this->setPageMark();
  2871. // print page header
  2872. $this->setHeader();
  2873. // restore graphic settings
  2874. $this->setGraphicVars($gvars);
  2875. // mark this point
  2876. $this->setPageMark();
  2877. // print table header (if any)
  2878. $this->setTableHeader();
  2879. // set mark for empty page check
  2880. $this->emptypagemrk[$this->page]= $this->pagelen[$this->page];
  2881. }
  2882. /**
  2883. * Set start-writing mark on current page stream used to put borders and fills.
  2884. * Borders and fills are always created after content and inserted on the position marked by this method.
  2885. * This function must be called after calling Image() function for a background image.
  2886. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  2887. * @public
  2888. * @since 4.0.016 (2008-07-30)
  2889. */
  2890. public function setPageMark() {
  2891. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  2892. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  2893. $this->setContentMark();
  2894. }
  2895. /**
  2896. * Set start-writing mark on selected page.
  2897. * Borders and fills are always created after content and inserted on the position marked by this method.
  2898. * @param $page (int) page number (default is the current page)
  2899. * @protected
  2900. * @since 4.6.021 (2009-07-20)
  2901. */
  2902. protected function setContentMark($page=0) {
  2903. if ($page <= 0) {
  2904. $page = $this->page;
  2905. }
  2906. if (isset($this->footerlen[$page])) {
  2907. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  2908. } else {
  2909. $this->cntmrk[$page] = $this->pagelen[$page];
  2910. }
  2911. }
  2912. /**
  2913. * Set header data.
  2914. * @param $ln (string) header image logo
  2915. * @param $lw (string) header image logo width in mm
  2916. * @param $ht (string) string to print as title on document header
  2917. * @param $hs (string) string to print on document header
  2918. * @param $tc (array) RGB array color for text.
  2919. * @param $lc (array) RGB array color for line.
  2920. * @public
  2921. */
  2922. public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
  2923. $this->header_logo = $ln;
  2924. $this->header_logo_width = $lw;
  2925. $this->header_title = $ht;
  2926. $this->header_string = $hs;
  2927. $this->header_text_color = $tc;
  2928. $this->header_line_color = $lc;
  2929. }
  2930. /**
  2931. * Set footer data.
  2932. * @param $tc (array) RGB array color for text.
  2933. * @param $lc (array) RGB array color for line.
  2934. * @public
  2935. */
  2936. public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
  2937. $this->footer_text_color = $tc;
  2938. $this->footer_line_color = $lc;
  2939. }
  2940. /**
  2941. * Returns header data:
  2942. * <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>
  2943. * @return array()
  2944. * @public
  2945. * @since 4.0.012 (2008-07-24)
  2946. */
  2947. public function getHeaderData() {
  2948. $ret = array();
  2949. $ret['logo'] = $this->header_logo;
  2950. $ret['logo_width'] = $this->header_logo_width;
  2951. $ret['title'] = $this->header_title;
  2952. $ret['string'] = $this->header_string;
  2953. $ret['text_color'] = $this->header_text_color;
  2954. $ret['line_color'] = $this->header_line_color;
  2955. return $ret;
  2956. }
  2957. /**
  2958. * Set header margin.
  2959. * (minimum distance between header and top page margin)
  2960. * @param $hm (int) distance in user units
  2961. * @public
  2962. */
  2963. public function setHeaderMargin($hm=10) {
  2964. $this->header_margin = $hm;
  2965. }
  2966. /**
  2967. * Returns header margin in user units.
  2968. * @return float
  2969. * @since 4.0.012 (2008-07-24)
  2970. * @public
  2971. */
  2972. public function getHeaderMargin() {
  2973. return $this->header_margin;
  2974. }
  2975. /**
  2976. * Set footer margin.
  2977. * (minimum distance between footer and bottom page margin)
  2978. * @param $fm (int) distance in user units
  2979. * @public
  2980. */
  2981. public function setFooterMargin($fm=10) {
  2982. $this->footer_margin = $fm;
  2983. }
  2984. /**
  2985. * Returns footer margin in user units.
  2986. * @return float
  2987. * @since 4.0.012 (2008-07-24)
  2988. * @public
  2989. */
  2990. public function getFooterMargin() {
  2991. return $this->footer_margin;
  2992. }
  2993. /**
  2994. * Set a flag to print page header.
  2995. * @param $val (boolean) set to true to print the page header (default), false otherwise.
  2996. * @public
  2997. */
  2998. public function setPrintHeader($val=true) {
  2999. $this->print_header = $val ? true : false;
  3000. }
  3001. /**
  3002. * Set a flag to print page footer.
  3003. * @param $val (boolean) set to true to print the page footer (default), false otherwise.
  3004. * @public
  3005. */
  3006. public function setPrintFooter($val=true) {
  3007. $this->print_footer = $val ? true : false;
  3008. }
  3009. /**
  3010. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  3011. * @return float
  3012. * @public
  3013. */
  3014. public function getImageRBX() {
  3015. return $this->img_rb_x;
  3016. }
  3017. /**
  3018. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  3019. * @return float
  3020. * @public
  3021. */
  3022. public function getImageRBY() {
  3023. return $this->img_rb_y;
  3024. }
  3025. /**
  3026. * Reset the xobject template used by Header() method.
  3027. * @public
  3028. */
  3029. public function resetHeaderTemplate() {
  3030. $this->header_xobjid = -1;
  3031. }
  3032. /**
  3033. * Set a flag to automatically reset the xobject template used by Header() method at each page.
  3034. * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
  3035. * @public
  3036. */
  3037. public function setHeaderTemplateAutoreset($val=true) {
  3038. $this->header_xobj_autoreset = $val ? true : false;
  3039. }
  3040. /**
  3041. * This method is used to render the page header.
  3042. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3043. * @public
  3044. */
  3045. public function Header() {
  3046. if ($this->header_xobjid < 0) {
  3047. // start a new XObject Template
  3048. $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
  3049. $headerfont = $this->getHeaderFont();
  3050. $headerdata = $this->getHeaderData();
  3051. $this->y = $this->header_margin;
  3052. if ($this->rtl) {
  3053. $this->x = $this->w - $this->original_rMargin;
  3054. } else {
  3055. $this->x = $this->original_lMargin;
  3056. }
  3057. if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
  3058. $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
  3059. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  3060. $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3061. } elseif ($imgtype == 'svg') {
  3062. $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3063. } else {
  3064. $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
  3065. }
  3066. $imgy = $this->getImageRBY();
  3067. } else {
  3068. $imgy = $this->y;
  3069. }
  3070. $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
  3071. // set starting margin for text data cell
  3072. if ($this->getRTL()) {
  3073. $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
  3074. } else {
  3075. $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
  3076. }
  3077. $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
  3078. $this->SetTextColorArray($this->header_text_color);
  3079. // header title
  3080. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  3081. $this->SetX($header_x);
  3082. $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  3083. // header string
  3084. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  3085. $this->SetX($header_x);
  3086. $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
  3087. // print an ending header line
  3088. $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
  3089. $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
  3090. if ($this->rtl) {
  3091. $this->SetX($this->original_rMargin);
  3092. } else {
  3093. $this->SetX($this->original_lMargin);
  3094. }
  3095. $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
  3096. $this->endTemplate();
  3097. }
  3098. // print header template
  3099. $x = 0;
  3100. $dx = 0;
  3101. if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) {
  3102. // adjust margins for booklet mode
  3103. $dx = ($this->original_lMargin - $this->original_rMargin);
  3104. }
  3105. if ($this->rtl) {
  3106. $x = $this->w + $dx;
  3107. } else {
  3108. $x = 0 + $dx;
  3109. }
  3110. $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
  3111. if ($this->header_xobj_autoreset) {
  3112. // reset header xobject template at each page
  3113. $this->header_xobjid = -1;
  3114. }
  3115. }
  3116. /**
  3117. * This method is used to render the page footer.
  3118. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  3119. * @public
  3120. */
  3121. public function Footer() {
  3122. $cur_y = $this->y;
  3123. $this->SetTextColorArray($this->footer_text_color);
  3124. //set style for cell border
  3125. $line_width = (0.85 / $this->k);
  3126. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color));
  3127. //print document barcode
  3128. $barcode = $this->getBarcode();
  3129. if (!empty($barcode)) {
  3130. $this->Ln($line_width);
  3131. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin) / 3);
  3132. $style = array(
  3133. 'position' => $this->rtl?'R':'L',
  3134. 'align' => $this->rtl?'R':'L',
  3135. 'stretch' => false,
  3136. 'fitwidth' => true,
  3137. 'cellfitalign' => '',
  3138. 'border' => false,
  3139. 'padding' => 0,
  3140. 'fgcolor' => array(0,0,0),
  3141. 'bgcolor' => false,
  3142. 'text' => false
  3143. );
  3144. $this->write1DBarcode($barcode, 'C128', '', $cur_y + $line_width, '', (($this->footer_margin / 3) - $line_width), 0.3, $style, '');
  3145. }
  3146. $w_page = isset($this->l['w_page']) ? $this->l['w_page'].' ' : '';
  3147. if (empty($this->pagegroups)) {
  3148. $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
  3149. } else {
  3150. $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
  3151. }
  3152. $this->SetY($cur_y);
  3153. //Print page number
  3154. if ($this->getRTL()) {
  3155. $this->SetX($this->original_rMargin);
  3156. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  3157. } else {
  3158. $this->SetX($this->original_lMargin);
  3159. $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
  3160. }
  3161. }
  3162. /**
  3163. * This method is used to render the page header.
  3164. * @protected
  3165. * @since 4.0.012 (2008-07-24)
  3166. */
  3167. protected function setHeader() {
  3168. if (!$this->print_header OR ($this->state != 2)) {
  3169. return;
  3170. }
  3171. $this->InHeader = true;
  3172. $this->setGraphicVars($this->default_graphic_vars);
  3173. $temp_thead = $this->thead;
  3174. $temp_theadMargins = $this->theadMargins;
  3175. $lasth = $this->lasth;
  3176. $this->_out('q');
  3177. $this->rMargin = $this->original_rMargin;
  3178. $this->lMargin = $this->original_lMargin;
  3179. $this->SetCellPadding(0);
  3180. //set current position
  3181. if ($this->rtl) {
  3182. $this->SetXY($this->original_rMargin, $this->header_margin);
  3183. } else {
  3184. $this->SetXY($this->original_lMargin, $this->header_margin);
  3185. }
  3186. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  3187. $this->Header();
  3188. //restore position
  3189. if ($this->rtl) {
  3190. $this->SetXY($this->original_rMargin, $this->tMargin);
  3191. } else {
  3192. $this->SetXY($this->original_lMargin, $this->tMargin);
  3193. }
  3194. $this->_out('Q');
  3195. $this->lasth = $lasth;
  3196. $this->thead = $temp_thead;
  3197. $this->theadMargins = $temp_theadMargins;
  3198. $this->newline = false;
  3199. $this->InHeader = false;
  3200. }
  3201. /**
  3202. * This method is used to render the page footer.
  3203. * @protected
  3204. * @since 4.0.012 (2008-07-24)
  3205. */
  3206. protected function setFooter() {
  3207. if ($this->state != 2) {
  3208. return;
  3209. }
  3210. $this->InFooter = true;
  3211. // save current graphic settings
  3212. $gvars = $this->getGraphicVars();
  3213. // mark this point
  3214. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  3215. $this->_out("\n");
  3216. if ($this->print_footer) {
  3217. $this->setGraphicVars($this->default_graphic_vars);
  3218. $this->current_column = 0;
  3219. $this->num_columns = 1;
  3220. $temp_thead = $this->thead;
  3221. $temp_theadMargins = $this->theadMargins;
  3222. $lasth = $this->lasth;
  3223. $this->_out('q');
  3224. $this->rMargin = $this->original_rMargin;
  3225. $this->lMargin = $this->original_lMargin;
  3226. $this->SetCellPadding(0);
  3227. //set current position
  3228. $footer_y = $this->h - $this->footer_margin;
  3229. if ($this->rtl) {
  3230. $this->SetXY($this->original_rMargin, $footer_y);
  3231. } else {
  3232. $this->SetXY($this->original_lMargin, $footer_y);
  3233. }
  3234. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  3235. $this->Footer();
  3236. //restore position
  3237. if ($this->rtl) {
  3238. $this->SetXY($this->original_rMargin, $this->tMargin);
  3239. } else {
  3240. $this->SetXY($this->original_lMargin, $this->tMargin);
  3241. }
  3242. $this->_out('Q');
  3243. $this->lasth = $lasth;
  3244. $this->thead = $temp_thead;
  3245. $this->theadMargins = $temp_theadMargins;
  3246. }
  3247. // restore graphic settings
  3248. $this->setGraphicVars($gvars);
  3249. $this->current_column = $gvars['current_column'];
  3250. $this->num_columns = $gvars['num_columns'];
  3251. // calculate footer length
  3252. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  3253. $this->InFooter = false;
  3254. }
  3255. /**
  3256. * Check if we are on the page body (excluding page header and footer).
  3257. * @return true if we are not in page header nor in page footer, false otherwise.
  3258. * @protected
  3259. * @since 5.9.091 (2011-06-15)
  3260. */
  3261. protected function inPageBody() {
  3262. return (($this->InHeader === false) AND ($this->InFooter === false));
  3263. }
  3264. /**
  3265. * This method is used to render the table header on new page (if any).
  3266. * @protected
  3267. * @since 4.5.030 (2009-03-25)
  3268. */
  3269. protected function setTableHeader() {
  3270. if ($this->num_columns > 1) {
  3271. // multi column mode
  3272. return;
  3273. }
  3274. if (isset($this->theadMargins['top'])) {
  3275. // restore the original top-margin
  3276. $this->tMargin = $this->theadMargins['top'];
  3277. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3278. $this->y = $this->tMargin;
  3279. }
  3280. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  3281. // set margins
  3282. $prev_lMargin = $this->lMargin;
  3283. $prev_rMargin = $this->rMargin;
  3284. $prev_cell_padding = $this->cell_padding;
  3285. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  3286. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  3287. $this->cell_padding = $this->theadMargins['cell_padding'];
  3288. if ($this->rtl) {
  3289. $this->x = $this->w - $this->rMargin;
  3290. } else {
  3291. $this->x = $this->lMargin;
  3292. }
  3293. // account for special "cell" mode
  3294. if ($this->theadMargins['cell']) {
  3295. if ($this->rtl) {
  3296. $this->x -= $this->cell_padding['R'];
  3297. } else {
  3298. $this->x += $this->cell_padding['L'];
  3299. }
  3300. }
  3301. // print table header
  3302. $this->writeHTML($this->thead, false, false, false, false, '');
  3303. // set new top margin to skip the table headers
  3304. if (!isset($this->theadMargins['top'])) {
  3305. $this->theadMargins['top'] = $this->tMargin;
  3306. }
  3307. // store end of header position
  3308. if (!isset($this->columns[0]['th'])) {
  3309. $this->columns[0]['th'] = array();
  3310. }
  3311. $this->columns[0]['th']['\''.$this->page.'\''] = $this->y;
  3312. $this->tMargin = $this->y;
  3313. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3314. $this->lasth = 0;
  3315. $this->lMargin = $prev_lMargin;
  3316. $this->rMargin = $prev_rMargin;
  3317. $this->cell_padding = $prev_cell_padding;
  3318. }
  3319. }
  3320. /**
  3321. * Returns the current page number.
  3322. * @return int page number
  3323. * @public
  3324. * @since 1.0
  3325. * @see getAliasNbPages()
  3326. */
  3327. public function PageNo() {
  3328. return $this->page;
  3329. }
  3330. /**
  3331. * Returns the array of spot colors.
  3332. * @return (array) Spot colors array.
  3333. * @public
  3334. * @since 6.0.038 (2013-09-30)
  3335. */
  3336. public function getAllSpotColors() {
  3337. return $this->spot_colors;
  3338. }
  3339. /**
  3340. * Defines a new spot color.
  3341. * It can be expressed in RGB components or gray scale.
  3342. * The method can be called before the first page is created and the value is retained from page to page.
  3343. * @param $name (string) Full name of the spot color.
  3344. * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
  3345. * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
  3346. * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
  3347. * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
  3348. * @public
  3349. * @since 4.0.024 (2008-09-12)
  3350. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3351. */
  3352. public function AddSpotColor($name, $c, $m, $y, $k) {
  3353. if (!isset($this->spot_colors[$name])) {
  3354. $i = (1 + count($this->spot_colors));
  3355. $this->spot_colors[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
  3356. }
  3357. }
  3358. /**
  3359. * Set the spot color for the specified type ('draw', 'fill', 'text').
  3360. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3361. * @param $name (string) Name of the spot color.
  3362. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3363. * @return (string) PDF color command.
  3364. * @public
  3365. * @since 5.9.125 (2011-10-03)
  3366. */
  3367. public function setSpotColor($type, $name, $tint=100) {
  3368. $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
  3369. if ($spotcolor === false) {
  3370. $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
  3371. }
  3372. $tint = (max(0, min(100, $tint)) / 100);
  3373. $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
  3374. switch ($type) {
  3375. case 'draw': {
  3376. $pdfcolor .= sprintf('CS %F SCN', $tint);
  3377. $this->DrawColor = $pdfcolor;
  3378. $this->strokecolor = $spotcolor;
  3379. break;
  3380. }
  3381. case 'fill': {
  3382. $pdfcolor .= sprintf('cs %F scn', $tint);
  3383. $this->FillColor = $pdfcolor;
  3384. $this->bgcolor = $spotcolor;
  3385. break;
  3386. }
  3387. case 'text': {
  3388. $pdfcolor .= sprintf('cs %F scn', $tint);
  3389. $this->TextColor = $pdfcolor;
  3390. $this->fgcolor = $spotcolor;
  3391. break;
  3392. }
  3393. }
  3394. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3395. if ($this->state == 2) {
  3396. $this->_out($pdfcolor);
  3397. }
  3398. if ($this->inxobj) {
  3399. // we are inside an XObject template
  3400. $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
  3401. }
  3402. return $pdfcolor;
  3403. }
  3404. /**
  3405. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  3406. * @param $name (string) Name of the spot color.
  3407. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3408. * @public
  3409. * @since 4.0.024 (2008-09-12)
  3410. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  3411. */
  3412. public function SetDrawSpotColor($name, $tint=100) {
  3413. $this->setSpotColor('draw', $name, $tint);
  3414. }
  3415. /**
  3416. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  3417. * @param $name (string) Name of the spot color.
  3418. * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3419. * @public
  3420. * @since 4.0.024 (2008-09-12)
  3421. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  3422. */
  3423. public function SetFillSpotColor($name, $tint=100) {
  3424. $this->setSpotColor('fill', $name, $tint);
  3425. }
  3426. /**
  3427. * Defines the spot color used for text.
  3428. * @param $name (string) Name of the spot color.
  3429. * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  3430. * @public
  3431. * @since 4.0.024 (2008-09-12)
  3432. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  3433. */
  3434. public function SetTextSpotColor($name, $tint=100) {
  3435. $this->setSpotColor('text', $name, $tint);
  3436. }
  3437. /**
  3438. * Set the color array for the specified type ('draw', 'fill', 'text').
  3439. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3440. * The method can be called before the first page is created and the value is retained from page to page.
  3441. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3442. * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
  3443. * @param $ret (boolean) If true do not send the PDF command.
  3444. * @return (string) The PDF command or empty string.
  3445. * @public
  3446. * @since 3.1.000 (2008-06-11)
  3447. */
  3448. public function setColorArray($type, $color, $ret=false) {
  3449. if (is_array($color)) {
  3450. $color = array_values($color);
  3451. // component: grey, RGB red or CMYK cyan
  3452. $c = isset($color[0]) ? $color[0] : -1;
  3453. // component: RGB green or CMYK magenta
  3454. $m = isset($color[1]) ? $color[1] : -1;
  3455. // component: RGB blue or CMYK yellow
  3456. $y = isset($color[2]) ? $color[2] : -1;
  3457. // component: CMYK black
  3458. $k = isset($color[3]) ? $color[3] : -1;
  3459. // color name
  3460. $name = isset($color[4]) ? $color[4] : '';
  3461. if ($c >= 0) {
  3462. return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
  3463. }
  3464. }
  3465. return '';
  3466. }
  3467. /**
  3468. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  3469. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3470. * The method can be called before the first page is created and the value is retained from page to page.
  3471. * @param $color (array) Array of colors (1, 3 or 4 values).
  3472. * @param $ret (boolean) If true do not send the PDF command.
  3473. * @return string the PDF command
  3474. * @public
  3475. * @since 3.1.000 (2008-06-11)
  3476. * @see SetDrawColor()
  3477. */
  3478. public function SetDrawColorArray($color, $ret=false) {
  3479. return $this->setColorArray('draw', $color, $ret);
  3480. }
  3481. /**
  3482. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  3483. * It can be expressed in RGB, CMYK or GRAY SCALE components.
  3484. * The method can be called before the first page is created and the value is retained from page to page.
  3485. * @param $color (array) Array of colors (1, 3 or 4 values).
  3486. * @param $ret (boolean) If true do not send the PDF command.
  3487. * @public
  3488. * @since 3.1.000 (2008-6-11)
  3489. * @see SetFillColor()
  3490. */
  3491. public function SetFillColorArray($color, $ret=false) {
  3492. return $this->setColorArray('fill', $color, $ret);
  3493. }
  3494. /**
  3495. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  3496. * The method can be called before the first page is created and the value is retained from page to page.
  3497. * @param $color (array) Array of colors (1, 3 or 4 values).
  3498. * @param $ret (boolean) If true do not send the PDF command.
  3499. * @public
  3500. * @since 3.1.000 (2008-6-11)
  3501. * @see SetFillColor()
  3502. */
  3503. public function SetTextColorArray($color, $ret=false) {
  3504. return $this->setColorArray('text', $color, $ret);
  3505. }
  3506. /**
  3507. * Defines the color used by the specified type ('draw', 'fill', 'text').
  3508. * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  3509. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3510. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3511. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3512. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3513. * @param $ret (boolean) If true do not send the command.
  3514. * @param $name (string) spot color name (if any)
  3515. * @return (string) The PDF command or empty string.
  3516. * @public
  3517. * @since 5.9.125 (2011-10-03)
  3518. */
  3519. public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3520. // set default values
  3521. if (!is_numeric($col1)) {
  3522. $col1 = 0;
  3523. }
  3524. if (!is_numeric($col2)) {
  3525. $col2 = -1;
  3526. }
  3527. if (!is_numeric($col3)) {
  3528. $col3 = -1;
  3529. }
  3530. if (!is_numeric($col4)) {
  3531. $col4 = -1;
  3532. }
  3533. // set color by case
  3534. $suffix = '';
  3535. if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
  3536. // Grey scale
  3537. $col1 = max(0, min(255, $col1));
  3538. $intcolor = array('G' => $col1);
  3539. $pdfcolor = sprintf('%F ', ($col1 / 255));
  3540. $suffix = 'g';
  3541. } elseif ($col4 == -1) {
  3542. // RGB
  3543. $col1 = max(0, min(255, $col1));
  3544. $col2 = max(0, min(255, $col2));
  3545. $col3 = max(0, min(255, $col3));
  3546. $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  3547. $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
  3548. $suffix = 'rg';
  3549. } else {
  3550. $col1 = max(0, min(100, $col1));
  3551. $col2 = max(0, min(100, $col2));
  3552. $col3 = max(0, min(100, $col3));
  3553. $col4 = max(0, min(100, $col4));
  3554. if (empty($name)) {
  3555. // CMYK
  3556. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  3557. $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
  3558. $suffix = 'k';
  3559. } else {
  3560. // SPOT COLOR
  3561. $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
  3562. $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
  3563. $pdfcolor = $this->setSpotColor($type, $name, 100);
  3564. }
  3565. }
  3566. switch ($type) {
  3567. case 'draw': {
  3568. $pdfcolor .= strtoupper($suffix);
  3569. $this->DrawColor = $pdfcolor;
  3570. $this->strokecolor = $intcolor;
  3571. break;
  3572. }
  3573. case 'fill': {
  3574. $pdfcolor .= $suffix;
  3575. $this->FillColor = $pdfcolor;
  3576. $this->bgcolor = $intcolor;
  3577. break;
  3578. }
  3579. case 'text': {
  3580. $pdfcolor .= $suffix;
  3581. $this->TextColor = $pdfcolor;
  3582. $this->fgcolor = $intcolor;
  3583. break;
  3584. }
  3585. }
  3586. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  3587. if (($type != 'text') AND ($this->state == 2)) {
  3588. if (!$ret) {
  3589. $this->_out($pdfcolor);
  3590. }
  3591. return $pdfcolor;
  3592. }
  3593. return '';
  3594. }
  3595. /**
  3596. * 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.
  3597. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3598. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3599. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3600. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3601. * @param $ret (boolean) If true do not send the command.
  3602. * @param $name (string) spot color name (if any)
  3603. * @return string the PDF command
  3604. * @public
  3605. * @since 1.3
  3606. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  3607. */
  3608. public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3609. return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
  3610. }
  3611. /**
  3612. * 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.
  3613. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3614. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3615. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3616. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3617. * @param $ret (boolean) If true do not send the command.
  3618. * @param $name (string) Spot color name (if any).
  3619. * @return (string) The PDF command.
  3620. * @public
  3621. * @since 1.3
  3622. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  3623. */
  3624. public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3625. return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
  3626. }
  3627. /**
  3628. * 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.
  3629. * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
  3630. * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
  3631. * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
  3632. * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
  3633. * @param $ret (boolean) If true do not send the command.
  3634. * @param $name (string) Spot color name (if any).
  3635. * @return (string) Empty string.
  3636. * @public
  3637. * @since 1.3
  3638. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  3639. */
  3640. public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
  3641. return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
  3642. }
  3643. /**
  3644. * Returns the length of a string in user unit. A font must be selected.<br>
  3645. * @param $s (string) The string whose length is to be computed
  3646. * @param $fontname (string) 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.
  3647. * @param $fontstyle (string) 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.
  3648. * @param $fontsize (float) Font size in points. The default value is the current size.
  3649. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3650. * @return mixed int total string length or array of characted widths
  3651. * @author Nicola Asuni
  3652. * @public
  3653. * @since 1.2
  3654. */
  3655. public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3656. 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);
  3657. }
  3658. /**
  3659. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  3660. * @param $sa (string) The array of chars whose total length is to be computed
  3661. * @param $fontname (string) 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.
  3662. * @param $fontstyle (string) 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.
  3663. * @param $fontsize (float) Font size in points. The default value is the current size.
  3664. * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
  3665. * @return mixed int total string length or array of characted widths
  3666. * @author Nicola Asuni
  3667. * @public
  3668. * @since 2.4.000 (2008-03-06)
  3669. */
  3670. public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
  3671. // store current values
  3672. if (!TCPDF_STATIC::empty_string($fontname)) {
  3673. $prev_FontFamily = $this->FontFamily;
  3674. $prev_FontStyle = $this->FontStyle;
  3675. $prev_FontSizePt = $this->FontSizePt;
  3676. $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
  3677. }
  3678. // convert UTF-8 array to Latin1 if required
  3679. if ($this->isunicode AND (!$this->isUnicodeFont())) {
  3680. $sa = TCPDF_FONTS::UTF8ArrToLatin1Arr($sa);
  3681. }
  3682. $w = 0; // total width
  3683. $wa = array(); // array of characters widths
  3684. foreach ($sa as $ck => $char) {
  3685. // character width
  3686. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  3687. $wa[] = $cw;
  3688. $w += $cw;
  3689. }
  3690. // restore previous values
  3691. if (!TCPDF_STATIC::empty_string($fontname)) {
  3692. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
  3693. }
  3694. if ($getarray) {
  3695. return $wa;
  3696. }
  3697. return $w;
  3698. }
  3699. /**
  3700. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
  3701. * @param $char (int) The char code whose length is to be returned
  3702. * @param $notlast (boolean) If false ignore the font-spacing.
  3703. * @return float char width
  3704. * @author Nicola Asuni
  3705. * @public
  3706. * @since 2.4.000 (2008-03-06)
  3707. */
  3708. public function GetCharWidth($char, $notlast=true) {
  3709. // get raw width
  3710. $chw = $this->getRawCharWidth($char);
  3711. if (($this->font_spacing < 0) OR (($this->font_spacing > 0) AND $notlast)) {
  3712. // increase/decrease font spacing
  3713. $chw += $this->font_spacing;
  3714. }
  3715. if ($this->font_stretching != 100) {
  3716. // fixed stretching mode
  3717. $chw *= ($this->font_stretching / 100);
  3718. }
  3719. return $chw;
  3720. }
  3721. /**
  3722. * Returns the length of the char in user unit for the current font.
  3723. * @param $char (int) The char code whose length is to be returned
  3724. * @return float char width
  3725. * @author Nicola Asuni
  3726. * @public
  3727. * @since 5.9.000 (2010-09-28)
  3728. */
  3729. public function getRawCharWidth($char) {
  3730. if ($char == 173) {
  3731. // SHY character will not be printed
  3732. return (0);
  3733. }
  3734. if (isset($this->CurrentFont['cw'][$char])) {
  3735. $w = $this->CurrentFont['cw'][$char];
  3736. } elseif (isset($this->CurrentFont['dw'])) {
  3737. // default width
  3738. $w = $this->CurrentFont['dw'];
  3739. } elseif (isset($this->CurrentFont['cw'][32])) {
  3740. // default width
  3741. $w = $this->CurrentFont['cw'][32];
  3742. } else {
  3743. $w = 600;
  3744. }
  3745. return $this->getAbsFontMeasure($w);
  3746. }
  3747. /**
  3748. * Returns the numbero of characters in a string.
  3749. * @param $s (string) The input string.
  3750. * @return int number of characters
  3751. * @public
  3752. * @since 2.0.0001 (2008-01-07)
  3753. */
  3754. public function GetNumChars($s) {
  3755. if ($this->isUnicodeFont()) {
  3756. return count(TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont));
  3757. }
  3758. return strlen($s);
  3759. }
  3760. /**
  3761. * Fill the list of available fonts ($this->fontlist).
  3762. * @protected
  3763. * @since 4.0.013 (2008-07-28)
  3764. */
  3765. protected function getFontsList() {
  3766. if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) {
  3767. while (($file = readdir($fontsdir)) !== false) {
  3768. if (substr($file, -4) == '.php') {
  3769. array_push($this->fontlist, strtolower(basename($file, '.php')));
  3770. }
  3771. }
  3772. closedir($fontsdir);
  3773. }
  3774. }
  3775. /**
  3776. * Returns the unicode caracter specified by the value
  3777. * @param $c (int) UTF-8 value
  3778. * @return Returns the specified character.
  3779. * @since 2.3.000 (2008-03-05)
  3780. * @public
  3781. * @deprecated
  3782. */
  3783. public function unichr($c) {
  3784. return TCPDF_FONTS::unichr($c, $this->isunicode);
  3785. }
  3786. /**
  3787. * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
  3788. * @param $fontfile (string) Font file (full path).
  3789. * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
  3790. * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
  3791. * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
  3792. * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
  3793. * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
  3794. * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
  3795. * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
  3796. * @return (string) TCPDF font name.
  3797. * @author Nicola Asuni
  3798. * @since 5.9.123 (2010-09-30)
  3799. * @public
  3800. * @deprecated
  3801. */
  3802. public function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false) {
  3803. return TCPDF_FONTS::addTTFfont($fontfile, $fonttype, $enc, $flags, $outpath, $platid, $encid, $addcbbox);
  3804. }
  3805. /**
  3806. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  3807. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  3808. * 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.
  3809. * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  3810. * @param $style (string) 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>
  3811. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  3812. * @return array containing the font data, or false in case of error.
  3813. * @param $subset (mixed) 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.
  3814. * @public
  3815. * @since 1.5
  3816. * @see SetFont(), setFontSubsetting()
  3817. */
  3818. public function AddFont($family, $style='', $fontfile='', $subset='default') {
  3819. if ($subset === 'default') {
  3820. $subset = $this->font_subsetting;
  3821. }
  3822. if ($this->pdfa_mode) {
  3823. $subset = false;
  3824. }
  3825. if (TCPDF_STATIC::empty_string($family)) {
  3826. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  3827. $family = $this->FontFamily;
  3828. } else {
  3829. $this->Error('Empty font family');
  3830. }
  3831. }
  3832. // move embedded styles on $style
  3833. if (substr($family, -1) == 'I') {
  3834. $style .= 'I';
  3835. $family = substr($family, 0, -1);
  3836. }
  3837. if (substr($family, -1) == 'B') {
  3838. $style .= 'B';
  3839. $family = substr($family, 0, -1);
  3840. }
  3841. // normalize family name
  3842. $family = strtolower($family);
  3843. if ((!$this->isunicode) AND ($family == 'arial')) {
  3844. $family = 'helvetica';
  3845. }
  3846. if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
  3847. $style = '';
  3848. }
  3849. if ($this->pdfa_mode AND (isset($this->CoreFonts[$family]))) {
  3850. // all fonts must be embedded
  3851. $family = 'pdfa'.$family;
  3852. }
  3853. $tempstyle = strtoupper($style);
  3854. $style = '';
  3855. // underline
  3856. if (strpos($tempstyle, 'U') !== false) {
  3857. $this->underline = true;
  3858. } else {
  3859. $this->underline = false;
  3860. }
  3861. // line-through (deleted)
  3862. if (strpos($tempstyle, 'D') !== false) {
  3863. $this->linethrough = true;
  3864. } else {
  3865. $this->linethrough = false;
  3866. }
  3867. // overline
  3868. if (strpos($tempstyle, 'O') !== false) {
  3869. $this->overline = true;
  3870. } else {
  3871. $this->overline = false;
  3872. }
  3873. // bold
  3874. if (strpos($tempstyle, 'B') !== false) {
  3875. $style .= 'B';
  3876. }
  3877. // oblique
  3878. if (strpos($tempstyle, 'I') !== false) {
  3879. $style .= 'I';
  3880. }
  3881. $bistyle = $style;
  3882. $fontkey = $family.$style;
  3883. $font_style = $style.($this->underline ? 'U' : '').($this->linethrough ? 'D' : '').($this->overline ? 'O' : '');
  3884. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  3885. // check if the font has been already added
  3886. $fb = $this->getFontBuffer($fontkey);
  3887. if ($fb !== false) {
  3888. if ($this->inxobj) {
  3889. // we are inside an XObject template
  3890. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  3891. }
  3892. return $fontdata;
  3893. }
  3894. // get specified font directory (if any)
  3895. $fontdir = false;
  3896. if (!TCPDF_STATIC::empty_string($fontfile)) {
  3897. $fontdir = dirname($fontfile);
  3898. if (TCPDF_STATIC::empty_string($fontdir) OR ($fontdir == '.')) {
  3899. $fontdir = '';
  3900. } else {
  3901. $fontdir .= '/';
  3902. }
  3903. }
  3904. // true when the font style variation is missing
  3905. $missing_style = false;
  3906. // search and include font file
  3907. if (TCPDF_STATIC::empty_string($fontfile) OR (!@file_exists($fontfile))) {
  3908. // build a standard filenames for specified font
  3909. $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
  3910. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3911. if (TCPDF_STATIC::empty_string($fontfile)) {
  3912. $missing_style = true;
  3913. // try to remove the style part
  3914. $tmp_fontfile = str_replace(' ', '', $family).'.php';
  3915. $fontfile = TCPDF_FONTS::getFontFullPath($tmp_fontfile, $fontdir);
  3916. }
  3917. }
  3918. // include font file
  3919. if (!TCPDF_STATIC::empty_string($fontfile) AND (@file_exists($fontfile))) {
  3920. include($fontfile);
  3921. } else {
  3922. $this->Error('Could not include font definition file: '.$family.'');
  3923. }
  3924. // check font parameters
  3925. if ((!isset($type)) OR (!isset($cw))) {
  3926. $this->Error('The font definition file has a bad format: '.$fontfile.'');
  3927. }
  3928. // SET default parameters
  3929. if (!isset($file) OR TCPDF_STATIC::empty_string($file)) {
  3930. $file = '';
  3931. }
  3932. if (!isset($enc) OR TCPDF_STATIC::empty_string($enc)) {
  3933. $enc = '';
  3934. }
  3935. if (!isset($cidinfo) OR TCPDF_STATIC::empty_string($cidinfo)) {
  3936. $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
  3937. $cidinfo['uni2cid'] = array();
  3938. }
  3939. if (!isset($ctg) OR TCPDF_STATIC::empty_string($ctg)) {
  3940. $ctg = '';
  3941. }
  3942. if (!isset($desc) OR TCPDF_STATIC::empty_string($desc)) {
  3943. $desc = array();
  3944. }
  3945. if (!isset($up) OR TCPDF_STATIC::empty_string($up)) {
  3946. $up = -100;
  3947. }
  3948. if (!isset($ut) OR TCPDF_STATIC::empty_string($ut)) {
  3949. $ut = 50;
  3950. }
  3951. if (!isset($cw) OR TCPDF_STATIC::empty_string($cw)) {
  3952. $cw = array();
  3953. }
  3954. if (!isset($dw) OR TCPDF_STATIC::empty_string($dw)) {
  3955. // set default width
  3956. if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
  3957. $dw = $desc['MissingWidth'];
  3958. } elseif (isset($cw[32])) {
  3959. $dw = $cw[32];
  3960. } else {
  3961. $dw = 600;
  3962. }
  3963. }
  3964. ++$this->numfonts;
  3965. if ($type == 'core') {
  3966. $name = $this->CoreFonts[$fontkey];
  3967. $subset = false;
  3968. } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
  3969. $subset = false;
  3970. } elseif ($type == 'TrueTypeUnicode') {
  3971. $enc = 'Identity-H';
  3972. } elseif ($type == 'cidfont0') {
  3973. if ($this->pdfa_mode) {
  3974. $this->Error('All fonts must be embedded in PDF/A mode!');
  3975. }
  3976. } else {
  3977. $this->Error('Unknow font type: '.$type.'');
  3978. }
  3979. // set name if unset
  3980. if (!isset($name) OR empty($name)) {
  3981. $name = $fontkey;
  3982. }
  3983. // create artificial font style variations if missing (only works with non-embedded fonts)
  3984. if (($type != 'core') AND $missing_style) {
  3985. // style variations
  3986. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  3987. $name .= $styles[$bistyle];
  3988. // artificial bold
  3989. if (strpos($bistyle, 'B') !== false) {
  3990. if (isset($desc['StemV'])) {
  3991. // from normal to bold
  3992. $desc['StemV'] = round($desc['StemV'] * 1.75);
  3993. } else {
  3994. // bold
  3995. $desc['StemV'] = 123;
  3996. }
  3997. }
  3998. // artificial italic
  3999. if (strpos($bistyle, 'I') !== false) {
  4000. if (isset($desc['ItalicAngle'])) {
  4001. $desc['ItalicAngle'] -= 11;
  4002. } else {
  4003. $desc['ItalicAngle'] = -11;
  4004. }
  4005. if (isset($desc['Flags'])) {
  4006. $desc['Flags'] |= 64; //bit 7
  4007. } else {
  4008. $desc['Flags'] = 64;
  4009. }
  4010. }
  4011. }
  4012. // check if the array of characters bounding boxes is defined
  4013. if (!isset($cbbox)) {
  4014. $cbbox = array();
  4015. }
  4016. // initialize subsetchars
  4017. $subsetchars = array_fill(0, 255, true);
  4018. $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));
  4019. if ($this->inxobj) {
  4020. // we are inside an XObject template
  4021. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  4022. }
  4023. if (isset($diff) AND (!empty($diff))) {
  4024. //Search existing encodings
  4025. $d = 0;
  4026. $nb = count($this->diffs);
  4027. for ($i=1; $i <= $nb; ++$i) {
  4028. if ($this->diffs[$i] == $diff) {
  4029. $d = $i;
  4030. break;
  4031. }
  4032. }
  4033. if ($d == 0) {
  4034. $d = $nb + 1;
  4035. $this->diffs[$d] = $diff;
  4036. }
  4037. $this->setFontSubBuffer($fontkey, 'diff', $d);
  4038. }
  4039. if (!TCPDF_STATIC::empty_string($file)) {
  4040. if (!isset($this->FontFiles[$file])) {
  4041. if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
  4042. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4043. } elseif ($type != 'core') {
  4044. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
  4045. }
  4046. } else {
  4047. // update fontkeys that are sharing this font file
  4048. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] AND $subset);
  4049. if (!in_array($fontkey, $this->FontFiles[$file]['fontkeys'])) {
  4050. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  4051. }
  4052. }
  4053. }
  4054. return $fontdata;
  4055. }
  4056. /**
  4057. * Sets the font used to print character strings.
  4058. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  4059. * The method can be called before the first page is created and the font is retained from page to page.
  4060. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  4061. * 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 />
  4062. * @param $family (string) 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.
  4063. * @param $style (string) 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.
  4064. * @param $size (float) 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
  4065. * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  4066. * @param $subset (mixed) 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.
  4067. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4068. * @author Nicola Asuni
  4069. * @public
  4070. * @since 1.0
  4071. * @see AddFont(), SetFontSize()
  4072. */
  4073. public function SetFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
  4074. //Select a font; size given in points
  4075. if ($size === null) {
  4076. $size = $this->FontSizePt;
  4077. }
  4078. if ($size < 0) {
  4079. $size = 0;
  4080. }
  4081. // try to add font (if not already added)
  4082. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  4083. $this->FontFamily = $fontdata['family'];
  4084. $this->FontStyle = $fontdata['style'];
  4085. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  4086. // save subset chars of the previous font
  4087. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4088. }
  4089. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  4090. $this->SetFontSize($size, $out);
  4091. }
  4092. /**
  4093. * Defines the size of the current font.
  4094. * @param $size (float) The font size in points.
  4095. * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
  4096. * @public
  4097. * @since 1.0
  4098. * @see SetFont()
  4099. */
  4100. public function SetFontSize($size, $out=true) {
  4101. // font size in points
  4102. $this->FontSizePt = $size;
  4103. // font size in user units
  4104. $this->FontSize = $size / $this->k;
  4105. // calculate some font metrics
  4106. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4107. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4108. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  4109. } else {
  4110. $font_height = $size * 1.219;
  4111. }
  4112. if (isset($this->CurrentFont['desc']['Ascent']) AND ($this->CurrentFont['desc']['Ascent'] > 0)) {
  4113. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  4114. }
  4115. if (isset($this->CurrentFont['desc']['Descent']) AND ($this->CurrentFont['desc']['Descent'] <= 0)) {
  4116. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  4117. }
  4118. if (!isset($font_ascent) AND !isset($font_descent)) {
  4119. // core font
  4120. $font_ascent = 0.76 * $font_height;
  4121. $font_descent = $font_height - $font_ascent;
  4122. } elseif (!isset($font_descent)) {
  4123. $font_descent = $font_height - $font_ascent;
  4124. } elseif (!isset($font_ascent)) {
  4125. $font_ascent = $font_height - $font_descent;
  4126. }
  4127. $this->FontAscent = ($font_ascent / $this->k);
  4128. $this->FontDescent = ($font_descent / $this->k);
  4129. if ($out AND ($this->page > 0) AND (isset($this->CurrentFont['i'])) AND ($this->state == 2)) {
  4130. $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  4131. }
  4132. }
  4133. /**
  4134. * Returns the bounding box of the current font in user units.
  4135. * @return array
  4136. * @public
  4137. * @since 5.9.152 (2012-03-23)
  4138. */
  4139. public function getFontBBox() {
  4140. $fbbox = array();
  4141. if (isset($this->CurrentFont['desc']['FontBBox'])) {
  4142. $tmpbbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, -1));
  4143. $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
  4144. } else {
  4145. // Find max width
  4146. if (isset($this->CurrentFont['desc']['MaxWidth'])) {
  4147. $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont['desc']['MaxWidth']));
  4148. } else {
  4149. $maxw = 0;
  4150. if (isset($this->CurrentFont['desc']['MissingWidth'])) {
  4151. $maxw = max($maxw, $this->CurrentFont['desc']['MissingWidth']);
  4152. }
  4153. if (isset($this->CurrentFont['desc']['AvgWidth'])) {
  4154. $maxw = max($maxw, $this->CurrentFont['desc']['AvgWidth']);
  4155. }
  4156. if (isset($this->CurrentFont['dw'])) {
  4157. $maxw = max($maxw, $this->CurrentFont['dw']);
  4158. }
  4159. foreach ($this->CurrentFont['cw'] as $char => $w) {
  4160. $maxw = max($maxw, $w);
  4161. }
  4162. if ($maxw == 0) {
  4163. $maxw = 600;
  4164. }
  4165. $maxw = $this->getAbsFontMeasure($maxw);
  4166. }
  4167. $fbbox = array(0, (0 - $this->FontDescent), $maxw, $this->FontAscent);
  4168. }
  4169. return $fbbox;
  4170. }
  4171. /**
  4172. * Convert a relative font measure into absolute value.
  4173. * @param $s (int) Font measure.
  4174. * @return float Absolute measure.
  4175. * @since 5.9.186 (2012-09-13)
  4176. */
  4177. public function getAbsFontMeasure($s) {
  4178. return ($s * $this->FontSize / 1000);
  4179. }
  4180. /**
  4181. * Returns the glyph bounding box of the specified character in the current font in user units.
  4182. * @param $char (int) Input character code.
  4183. * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
  4184. * @since 5.9.186 (2012-09-13)
  4185. */
  4186. public function getCharBBox($char) {
  4187. if (isset($this->CurrentFont['cbbox'][$char])) {
  4188. return array_map(array($this,'getAbsFontMeasure'), $this->CurrentFont['cbbox'][intval($char)]);
  4189. }
  4190. return false;
  4191. }
  4192. /**
  4193. * Return the font descent value
  4194. * @param $font (string) font name
  4195. * @param $style (string) font style
  4196. * @param $size (float) The size (in points)
  4197. * @return int font descent
  4198. * @public
  4199. * @author Nicola Asuni
  4200. * @since 4.9.003 (2010-03-30)
  4201. */
  4202. public function getFontDescent($font, $style='', $size=0) {
  4203. $fontdata = $this->AddFont($font, $style);
  4204. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4205. if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
  4206. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  4207. } else {
  4208. $descent = (1.219 * 0.24 * $size);
  4209. }
  4210. return ($descent / $this->k);
  4211. }
  4212. /**
  4213. * Return the font ascent value.
  4214. * @param $font (string) font name
  4215. * @param $style (string) font style
  4216. * @param $size (float) The size (in points)
  4217. * @return int font ascent
  4218. * @public
  4219. * @author Nicola Asuni
  4220. * @since 4.9.003 (2010-03-30)
  4221. */
  4222. public function getFontAscent($font, $style='', $size=0) {
  4223. $fontdata = $this->AddFont($font, $style);
  4224. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4225. if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
  4226. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  4227. } else {
  4228. $ascent = 1.219 * 0.76 * $size;
  4229. }
  4230. return ($ascent / $this->k);
  4231. }
  4232. /**
  4233. * Return true in the character is present in the specified font.
  4234. * @param $char (mixed) Character to check (integer value or string)
  4235. * @param $font (string) Font name (family name).
  4236. * @param $style (string) Font style.
  4237. * @return (boolean) true if the char is defined, false otherwise.
  4238. * @public
  4239. * @since 5.9.153 (2012-03-28)
  4240. */
  4241. public function isCharDefined($char, $font='', $style='') {
  4242. if (is_string($char)) {
  4243. // get character code
  4244. $char = TCPDF_FONTS::UTF8StringToArray($char, $this->isunicode, $this->CurrentFont);
  4245. $char = $char[0];
  4246. }
  4247. if (TCPDF_STATIC::empty_string($font)) {
  4248. if (TCPDF_STATIC::empty_string($style)) {
  4249. return (isset($this->CurrentFont['cw'][intval($char)]));
  4250. }
  4251. $font = $this->FontFamily;
  4252. }
  4253. $fontdata = $this->AddFont($font, $style);
  4254. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4255. return (isset($fontinfo['cw'][intval($char)]));
  4256. }
  4257. /**
  4258. * Replace missing font characters on selected font with specified substitutions.
  4259. * @param $text (string) Text to process.
  4260. * @param $font (string) Font name (family name).
  4261. * @param $style (string) Font style.
  4262. * @param $subs (array) 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.
  4263. * @return (string) Processed text.
  4264. * @public
  4265. * @since 5.9.153 (2012-03-28)
  4266. */
  4267. public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
  4268. if (empty($subs)) {
  4269. return $text;
  4270. }
  4271. if (TCPDF_STATIC::empty_string($font)) {
  4272. $font = $this->FontFamily;
  4273. }
  4274. $fontdata = $this->AddFont($font, $style);
  4275. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  4276. $uniarr = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  4277. foreach ($uniarr as $k => $chr) {
  4278. if (!isset($fontinfo['cw'][$chr])) {
  4279. // this character is missing on the selected font
  4280. if (isset($subs[$chr])) {
  4281. // we have available substitutions
  4282. if (is_array($subs[$chr])) {
  4283. foreach($subs[$chr] as $s) {
  4284. if (isset($fontinfo['cw'][$s])) {
  4285. $uniarr[$k] = $s;
  4286. break;
  4287. }
  4288. }
  4289. } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
  4290. $uniarr[$k] = $subs[$chr];
  4291. }
  4292. }
  4293. }
  4294. }
  4295. return TCPDF_FONTS::UniArrSubString(TCPDF_FONTS::UTF8ArrayToUniArray($uniarr, $this->isunicode));
  4296. }
  4297. /**
  4298. * Defines the default monospaced font.
  4299. * @param $font (string) Font name.
  4300. * @public
  4301. * @since 4.5.025
  4302. */
  4303. public function SetDefaultMonospacedFont($font) {
  4304. $this->default_monospaced_font = $font;
  4305. }
  4306. /**
  4307. * 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 />
  4308. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  4309. * @public
  4310. * @since 1.5
  4311. * @see Cell(), Write(), Image(), Link(), SetLink()
  4312. */
  4313. public function AddLink() {
  4314. //Create a new internal link
  4315. $n = count($this->links) + 1;
  4316. $this->links[$n] = array(0, 0);
  4317. return $n;
  4318. }
  4319. /**
  4320. * Defines the page and position a link points to.
  4321. * @param $link (int) The link identifier returned by AddLink()
  4322. * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  4323. * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
  4324. * @public
  4325. * @since 1.5
  4326. * @see AddLink()
  4327. */
  4328. public function SetLink($link, $y=0, $page=-1) {
  4329. if ($y == -1) {
  4330. $y = $this->y;
  4331. }
  4332. if ($page == -1) {
  4333. $page = $this->page;
  4334. }
  4335. $this->links[$link] = array($page, $y);
  4336. }
  4337. /**
  4338. * Puts a link on a rectangular area of the page.
  4339. * 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.
  4340. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4341. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4342. * @param $w (float) Width of the rectangle
  4343. * @param $h (float) Height of the rectangle
  4344. * @param $link (mixed) URL or identifier returned by AddLink()
  4345. * @param $spaces (int) number of spaces on the text to link
  4346. * @public
  4347. * @since 1.5
  4348. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  4349. */
  4350. public function Link($x, $y, $w, $h, $link, $spaces=0) {
  4351. $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
  4352. }
  4353. /**
  4354. * Puts a markup annotation on a rectangular area of the page.
  4355. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  4356. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  4357. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  4358. * @param $w (float) Width of the rectangle
  4359. * @param $h (float) Height of the rectangle
  4360. * @param $text (string) annotation text or alternate content
  4361. * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
  4362. * @param $spaces (int) number of spaces on the text to link
  4363. * @public
  4364. * @since 4.0.018 (2008-08-06)
  4365. */
  4366. public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
  4367. if ($this->inxobj) {
  4368. // store parameters for later use on template
  4369. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  4370. return;
  4371. }
  4372. if ($x === '') {
  4373. $x = $this->x;
  4374. }
  4375. if ($y === '') {
  4376. $y = $this->y;
  4377. }
  4378. // check page for no-write regions and adapt page margins if necessary
  4379. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  4380. // recalculate coordinates to account for graphic transformations
  4381. if (isset($this->transfmatrix) AND !empty($this->transfmatrix)) {
  4382. for ($i=$this->transfmatrix_key; $i > 0; --$i) {
  4383. $maxid = count($this->transfmatrix[$i]) - 1;
  4384. for ($j=$maxid; $j >= 0; --$j) {
  4385. $ctm = $this->transfmatrix[$i][$j];
  4386. if (isset($ctm['a'])) {
  4387. $x = $x * $this->k;
  4388. $y = ($this->h - $y) * $this->k;
  4389. $w = $w * $this->k;
  4390. $h = $h * $this->k;
  4391. // top left
  4392. $xt = $x;
  4393. $yt = $y;
  4394. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4395. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4396. // top right
  4397. $xt = $x + $w;
  4398. $yt = $y;
  4399. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4400. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4401. // bottom left
  4402. $xt = $x;
  4403. $yt = $y - $h;
  4404. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4405. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4406. // bottom right
  4407. $xt = $x + $w;
  4408. $yt = $y - $h;
  4409. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  4410. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  4411. // new coordinates (rectangle area)
  4412. $x = min($x1, $x2, $x3, $x4);
  4413. $y = max($y1, $y2, $y3, $y4);
  4414. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  4415. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  4416. $x = $x / $this->k;
  4417. $y = $this->h - ($y / $this->k);
  4418. }
  4419. }
  4420. }
  4421. }
  4422. if ($this->page <= 0) {
  4423. $page = 1;
  4424. } else {
  4425. $page = $this->page;
  4426. }
  4427. if (!isset($this->PageAnnots[$page])) {
  4428. $this->PageAnnots[$page] = array();
  4429. }
  4430. $this->PageAnnots[$page][] = array('n' => ++$this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
  4431. if (!$this->pdfa_mode) {
  4432. if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC::empty_string($opt['FS']))
  4433. AND (@file_exists($opt['FS']) OR TCPDF_STATIC::isValidURL($opt['FS']))
  4434. AND (!isset($this->embeddedfiles[basename($opt['FS'])]))) {
  4435. $this->embeddedfiles[basename($opt['FS'])] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $opt['FS']);
  4436. }
  4437. }
  4438. // Add widgets annotation's icons
  4439. if (isset($opt['mk']['i']) AND @file_exists($opt['mk']['i'])) {
  4440. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  4441. }
  4442. if (isset($opt['mk']['ri']) AND @file_exists($opt['mk']['ri'])) {
  4443. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4444. }
  4445. if (isset($opt['mk']['ix']) AND @file_exists($opt['mk']['ix'])) {
  4446. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  4447. }
  4448. }
  4449. /**
  4450. * Embedd the attached files.
  4451. * @since 4.4.000 (2008-12-07)
  4452. * @protected
  4453. * @see Annotation()
  4454. */
  4455. protected function _putEmbeddedFiles() {
  4456. if ($this->pdfa_mode) {
  4457. // embedded files are not allowed in PDF/A mode
  4458. return;
  4459. }
  4460. reset($this->embeddedfiles);
  4461. foreach ($this->embeddedfiles as $filename => $filedata) {
  4462. $data = TCPDF_STATIC::fileGetContents($filedata['file']);
  4463. if ($data !== FALSE) {
  4464. $rawsize = strlen($data);
  4465. if ($rawsize > 0) {
  4466. // update name tree
  4467. $this->efnames[$filename] = $filedata['f'].' 0 R';
  4468. // embedded file specification object
  4469. $out = $this->_getobj($filedata['f'])."\n";
  4470. $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']).' /EF <</F '.$filedata['n'].' 0 R>> >>';
  4471. $out .= "\n".'endobj';
  4472. $this->_out($out);
  4473. // embedded file object
  4474. $filter = '';
  4475. if ($this->compress) {
  4476. $data = gzcompress($data);
  4477. $filter = ' /Filter /FlateDecode';
  4478. }
  4479. $stream = $this->_getrawstream($data, $filedata['n']);
  4480. $out = $this->_getobj($filedata['n'])."\n";
  4481. $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
  4482. $out .= ' stream'."\n".$stream."\n".'endstream';
  4483. $out .= "\n".'endobj';
  4484. $this->_out($out);
  4485. }
  4486. }
  4487. }
  4488. }
  4489. /**
  4490. * Prints a text cell at the specified position.
  4491. * This method allows to place a string precisely on the page.
  4492. * @param $x (float) Abscissa of the cell origin
  4493. * @param $y (float) Ordinate of the cell origin
  4494. * @param $txt (string) String to print
  4495. * @param $fstroke (int) outline size in user units (false = disable)
  4496. * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  4497. * @param $ffill (boolean) if true fills the text
  4498. * @param $border (mixed) 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)))
  4499. * @param $ln (int) 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.
  4500. * @param $align (string) 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>
  4501. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4502. * @param $link (mixed) URL or identifier returned by AddLink().
  4503. * @param $stretch (int) 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.
  4504. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4505. * @param $calign (string) 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>
  4506. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4507. * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
  4508. * @public
  4509. * @since 1.0
  4510. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  4511. */
  4512. public function Text($x, $y, $txt, $fstroke=false, $fclip=false, $ffill=true, $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M', $rtloff=false) {
  4513. $textrendermode = $this->textrendermode;
  4514. $textstrokewidth = $this->textstrokewidth;
  4515. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  4516. $this->SetXY($x, $y, $rtloff);
  4517. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  4518. // restore previous rendering mode
  4519. $this->textrendermode = $textrendermode;
  4520. $this->textstrokewidth = $textstrokewidth;
  4521. }
  4522. /**
  4523. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  4524. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  4525. * This method is called automatically and should not be called directly by the application.
  4526. * @return boolean
  4527. * @public
  4528. * @since 1.4
  4529. * @see SetAutoPageBreak()
  4530. */
  4531. public function AcceptPageBreak() {
  4532. if ($this->num_columns > 1) {
  4533. // multi column mode
  4534. if ($this->current_column < ($this->num_columns - 1)) {
  4535. // go to next column
  4536. $this->selectColumn($this->current_column + 1);
  4537. } elseif ($this->AutoPageBreak) {
  4538. // add a new page
  4539. $this->AddPage();
  4540. // set first column
  4541. $this->selectColumn(0);
  4542. }
  4543. // avoid page breaking from checkPageBreak()
  4544. return false;
  4545. }
  4546. return $this->AutoPageBreak;
  4547. }
  4548. /**
  4549. * Add page if needed.
  4550. * @param $h (float) Cell height. Default value: 0.
  4551. * @param $y (mixed) starting y position, leave empty for current position.
  4552. * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
  4553. * @return boolean true in case of page break, false otherwise.
  4554. * @since 3.2.000 (2008-07-01)
  4555. * @protected
  4556. */
  4557. protected function checkPageBreak($h=0, $y='', $addpage=true) {
  4558. if (TCPDF_STATIC::empty_string($y)) {
  4559. $y = $this->y;
  4560. }
  4561. $current_page = $this->page;
  4562. if ((($y + $h) > $this->PageBreakTrigger) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
  4563. if ($addpage) {
  4564. //Automatic page break
  4565. $x = $this->x;
  4566. $this->AddPage($this->CurOrientation);
  4567. $this->y = $this->tMargin;
  4568. $oldpage = $this->page - 1;
  4569. if ($this->rtl) {
  4570. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm']) {
  4571. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  4572. } else {
  4573. $this->x = $x;
  4574. }
  4575. } else {
  4576. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm']) {
  4577. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  4578. } else {
  4579. $this->x = $x;
  4580. }
  4581. }
  4582. }
  4583. return true;
  4584. }
  4585. if ($current_page != $this->page) {
  4586. // account for columns mode
  4587. return true;
  4588. }
  4589. return false;
  4590. }
  4591. /**
  4592. * 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 />
  4593. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4594. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4595. * @param $h (float) Cell height. Default value: 0.
  4596. * @param $txt (string) String to print. Default value: empty string.
  4597. * @param $border (mixed) 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)))
  4598. * @param $ln (int) 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.
  4599. * @param $align (string) 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>
  4600. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4601. * @param $link (mixed) URL or identifier returned by AddLink().
  4602. * @param $stretch (int) 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.
  4603. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4604. * @param $calign (string) 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>
  4605. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  4606. * @public
  4607. * @since 1.0
  4608. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  4609. */
  4610. 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') {
  4611. $prev_cell_margin = $this->cell_margin;
  4612. $prev_cell_padding = $this->cell_padding;
  4613. $this->adjustCellPadding($border);
  4614. if (!$ignore_min_height) {
  4615. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  4616. if ($h < $min_cell_height) {
  4617. $h = $min_cell_height;
  4618. }
  4619. }
  4620. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  4621. // apply text shadow if enabled
  4622. if ($this->txtshadow['enabled']) {
  4623. // save data
  4624. $x = $this->x;
  4625. $y = $this->y;
  4626. $bc = $this->bgcolor;
  4627. $fc = $this->fgcolor;
  4628. $sc = $this->strokecolor;
  4629. $alpha = $this->alpha;
  4630. // print shadow
  4631. $this->x += $this->txtshadow['depth_w'];
  4632. $this->y += $this->txtshadow['depth_h'];
  4633. $this->SetFillColorArray($this->txtshadow['color']);
  4634. $this->SetTextColorArray($this->txtshadow['color']);
  4635. $this->SetDrawColorArray($this->txtshadow['color']);
  4636. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4637. $this->setAlpha($this->txtshadow['opacity'], $this->txtshadow['blend_mode']);
  4638. }
  4639. if ($this->state == 2) {
  4640. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4641. }
  4642. //restore data
  4643. $this->x = $x;
  4644. $this->y = $y;
  4645. $this->SetFillColorArray($bc);
  4646. $this->SetTextColorArray($fc);
  4647. $this->SetDrawColorArray($sc);
  4648. if ($this->txtshadow['opacity'] != $alpha['CA']) {
  4649. $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
  4650. }
  4651. }
  4652. if ($this->state == 2) {
  4653. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  4654. }
  4655. $this->cell_padding = $prev_cell_padding;
  4656. $this->cell_margin = $prev_cell_margin;
  4657. }
  4658. /**
  4659. * 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 />
  4660. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  4661. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  4662. * @param $h (float) Cell height. Default value: 0.
  4663. * @param $txt (string) String to print. Default value: empty string.
  4664. * @param $border (mixed) 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)))
  4665. * @param $ln (int) 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.
  4666. * @param $align (string) 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>
  4667. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  4668. * @param $link (mixed) URL or identifier returned by AddLink().
  4669. * @param $stretch (int) 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.
  4670. * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
  4671. * @param $calign (string) 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>
  4672. * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  4673. * @return string containing cell code
  4674. * @protected
  4675. * @since 1.0
  4676. * @see Cell()
  4677. */
  4678. 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') {
  4679. // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
  4680. $txt = str_replace(TCPDF_FONTS::unichr(160, $this->isunicode), ' ', $txt);
  4681. $prev_cell_margin = $this->cell_margin;
  4682. $prev_cell_padding = $this->cell_padding;
  4683. $txt = TCPDF_STATIC::removeSHY($txt, $this->isunicode);
  4684. $rs = ''; //string to be returned
  4685. $this->adjustCellPadding($border);
  4686. if (!$ignore_min_height) {
  4687. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  4688. if ($h < $min_cell_height) {
  4689. $h = $min_cell_height;
  4690. }
  4691. }
  4692. $k = $this->k;
  4693. // check page for no-write regions and adapt page margins if necessary
  4694. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  4695. if ($this->rtl) {
  4696. $x = $this->x - $this->cell_margin['R'];
  4697. } else {
  4698. $x = $this->x + $this->cell_margin['L'];
  4699. }
  4700. $y = $this->y + $this->cell_margin['T'];
  4701. $prev_font_stretching = $this->font_stretching;
  4702. $prev_font_spacing = $this->font_spacing;
  4703. // cell vertical alignment
  4704. switch ($calign) {
  4705. case 'A': {
  4706. // font top
  4707. switch ($valign) {
  4708. case 'T': {
  4709. // top
  4710. $y -= $this->cell_padding['T'];
  4711. break;
  4712. }
  4713. case 'B': {
  4714. // bottom
  4715. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  4716. break;
  4717. }
  4718. default:
  4719. case 'C':
  4720. case 'M': {
  4721. // center
  4722. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  4723. break;
  4724. }
  4725. }
  4726. break;
  4727. }
  4728. case 'L': {
  4729. // font baseline
  4730. switch ($valign) {
  4731. case 'T': {
  4732. // top
  4733. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  4734. break;
  4735. }
  4736. case 'B': {
  4737. // bottom
  4738. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  4739. break;
  4740. }
  4741. default:
  4742. case 'C':
  4743. case 'M': {
  4744. // center
  4745. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  4746. break;
  4747. }
  4748. }
  4749. break;
  4750. }
  4751. case 'D': {
  4752. // font bottom
  4753. switch ($valign) {
  4754. case 'T': {
  4755. // top
  4756. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  4757. break;
  4758. }
  4759. case 'B': {
  4760. // bottom
  4761. $y -= ($h - $this->cell_padding['B']);
  4762. break;
  4763. }
  4764. default:
  4765. case 'C':
  4766. case 'M': {
  4767. // center
  4768. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  4769. break;
  4770. }
  4771. }
  4772. break;
  4773. }
  4774. case 'B': {
  4775. // cell bottom
  4776. $y -= $h;
  4777. break;
  4778. }
  4779. case 'C':
  4780. case 'M': {
  4781. // cell center
  4782. $y -= ($h / 2);
  4783. break;
  4784. }
  4785. default:
  4786. case 'T': {
  4787. // cell top
  4788. break;
  4789. }
  4790. }
  4791. // text vertical alignment
  4792. switch ($valign) {
  4793. case 'T': {
  4794. // top
  4795. $yt = $y + $this->cell_padding['T'];
  4796. break;
  4797. }
  4798. case 'B': {
  4799. // bottom
  4800. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  4801. break;
  4802. }
  4803. default:
  4804. case 'C':
  4805. case 'M': {
  4806. // center
  4807. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  4808. break;
  4809. }
  4810. }
  4811. $basefonty = $yt + $this->FontAscent;
  4812. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  4813. if ($this->rtl) {
  4814. $w = $x - $this->lMargin;
  4815. } else {
  4816. $w = $this->w - $this->rMargin - $x;
  4817. }
  4818. }
  4819. $s = '';
  4820. // fill and borders
  4821. if (is_string($border) AND (strlen($border) == 4)) {
  4822. // full border
  4823. $border = 1;
  4824. }
  4825. if ($fill OR ($border == 1)) {
  4826. if ($fill) {
  4827. $op = ($border == 1) ? 'B' : 'f';
  4828. } else {
  4829. $op = 'S';
  4830. }
  4831. if ($this->rtl) {
  4832. $xk = (($x - $w) * $k);
  4833. } else {
  4834. $xk = ($x * $k);
  4835. }
  4836. $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (-$h * $k), $op);
  4837. }
  4838. // draw borders
  4839. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  4840. if ($txt != '') {
  4841. $txt2 = $txt;
  4842. if ($this->isunicode) {
  4843. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  4844. $txt2 = TCPDF_FONTS::UTF8ToLatin1($txt2, $this->isunicode, $this->CurrentFont);
  4845. } else {
  4846. $unicode = TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont); // array of UTF-8 unicode values
  4847. $unicode = TCPDF_FONTS::utf8Bidi($unicode, '', $this->tmprtl, $this->isunicode, $this->CurrentFont);
  4848. // replace thai chars (if any)
  4849. if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS == true)) {
  4850. // number of chars
  4851. $numchars = count($unicode);
  4852. // po pla, for far, for fan
  4853. $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
  4854. // do chada, to patak
  4855. $lowtail = array(0x0e0e, 0x0e0f);
  4856. // mai hun arkad, sara i, sara ii, sara ue, sara uee
  4857. $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
  4858. // mai ek, mai tho, mai tri, mai chattawa, karan
  4859. $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
  4860. // sara u, sara uu, pinthu
  4861. $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
  4862. $output = array();
  4863. for ($i = 0; $i < $numchars; $i++) {
  4864. if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
  4865. $ch0 = $unicode[$i];
  4866. $ch1 = ($i > 0) ? $unicode[($i - 1)] : 0;
  4867. $ch2 = ($i > 1) ? $unicode[($i - 2)] : 0;
  4868. $chn = ($i < ($numchars - 1)) ? $unicode[($i + 1)] : 0;
  4869. if (in_array($ch0, $tonemark)) {
  4870. if ($chn == 0x0e33) {
  4871. // sara um
  4872. if (in_array($ch1, $longtail)) {
  4873. // tonemark at upper left
  4874. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4875. } else {
  4876. // tonemark at upper right (normal position)
  4877. $output[] = $ch0;
  4878. }
  4879. } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
  4880. // tonemark at lower left
  4881. $output[] = $this->replaceChar($ch0, (0xf705 + $ch0 - 0x0e48));
  4882. } elseif (in_array($ch1, $upvowel)) {
  4883. if (in_array($ch2, $longtail)) {
  4884. // tonemark at upper left
  4885. $output[] = $this->replaceChar($ch0, (0xf713 + $ch0 - 0x0e48));
  4886. } else {
  4887. // tonemark at upper right (normal position)
  4888. $output[] = $ch0;
  4889. }
  4890. } else {
  4891. // tonemark at lower right
  4892. $output[] = $this->replaceChar($ch0, (0xf70a + $ch0 - 0x0e48));
  4893. }
  4894. } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
  4895. // add lower left nikhahit and sara aa
  4896. if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
  4897. $output[] = 0xf711;
  4898. $this->CurrentFont['subsetchars'][0xf711] = true;
  4899. $output[] = 0x0e32;
  4900. $this->CurrentFont['subsetchars'][0x0e32] = true;
  4901. } else {
  4902. $output[] = $ch0;
  4903. }
  4904. } elseif (in_array($ch1, $longtail)) {
  4905. if ($ch0 == 0x0e31) {
  4906. // lower left mai hun arkad
  4907. $output[] = $this->replaceChar($ch0, 0xf710);
  4908. } elseif (in_array($ch0, $upvowel)) {
  4909. // lower left
  4910. $output[] = $this->replaceChar($ch0, (0xf701 + $ch0 - 0x0e34));
  4911. } elseif ($ch0 == 0x0e47) {
  4912. // lower left mai tai koo
  4913. $output[] = $this->replaceChar($ch0, 0xf712);
  4914. } else {
  4915. // normal character
  4916. $output[] = $ch0;
  4917. }
  4918. } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
  4919. // lower vowel
  4920. $output[] = $this->replaceChar($ch0, (0xf718 + $ch0 - 0x0e38));
  4921. } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
  4922. // yo ying without lower part
  4923. $output[] = $this->replaceChar($ch0, 0xf70f);
  4924. } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
  4925. // tho santan without lower part
  4926. $output[] = $this->replaceChar($ch0, 0xf700);
  4927. } else {
  4928. $output[] = $ch0;
  4929. }
  4930. } else {
  4931. // non-thai character
  4932. $output[] = $unicode[$i];
  4933. }
  4934. }
  4935. $unicode = $output;
  4936. // update font subsetchars
  4937. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  4938. } // end of K_THAI_TOPCHARS
  4939. $txt2 = TCPDF_FONTS::arrUTF8ToUTF16BE($unicode, false);
  4940. }
  4941. }
  4942. $txt2 = TCPDF_STATIC::_escape($txt2);
  4943. // get current text width (considering general font stretching and spacing)
  4944. $txwidth = $this->GetStringWidth($txt);
  4945. $width = $txwidth;
  4946. // check for stretch mode
  4947. if ($stretch > 0) {
  4948. // calculate ratio between cell width and text width
  4949. if ($width <= 0) {
  4950. $ratio = 1;
  4951. } else {
  4952. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  4953. }
  4954. // check if stretching is required
  4955. if (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0))) {
  4956. // the text will be stretched to fit cell width
  4957. if ($stretch > 2) {
  4958. // set new character spacing
  4959. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  4960. } else {
  4961. // set new horizontal stretching
  4962. $this->font_stretching *= $ratio;
  4963. }
  4964. // recalculate text width (the text fills the entire cell)
  4965. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  4966. // reset alignment
  4967. $align = '';
  4968. }
  4969. }
  4970. if ($this->font_stretching != 100) {
  4971. // apply font stretching
  4972. $rs .= sprintf('BT %F Tz ET ', $this->font_stretching);
  4973. }
  4974. if ($this->font_spacing != 0) {
  4975. // increase/decrease font spacing
  4976. $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing * $this->k));
  4977. }
  4978. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  4979. $s .= 'q '.$this->TextColor.' ';
  4980. }
  4981. // rendering mode
  4982. $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode, ($this->textstrokewidth * $this->k));
  4983. // count number of spaces
  4984. $ns = substr_count($txt, chr(32));
  4985. // Justification
  4986. $spacewidth = 0;
  4987. if (($align == 'J') AND ($ns > 0)) {
  4988. if ($this->isUnicodeFont()) {
  4989. // get string width without spaces
  4990. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  4991. // calculate average space width
  4992. $spacewidth = -1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1) / ($this->FontSize?$this->FontSize:1);
  4993. if ($this->font_stretching != 100) {
  4994. // word spacing is affected by stretching
  4995. $spacewidth /= ($this->font_stretching / 100);
  4996. }
  4997. // set word position to be used with TJ operator
  4998. $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
  4999. $unicode_justification = true;
  5000. } else {
  5001. // get string width
  5002. $width = $txwidth;
  5003. // new space width
  5004. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1)) * $this->k;
  5005. if ($this->font_stretching != 100) {
  5006. // word spacing (Tw) is affected by stretching
  5007. $spacewidth /= ($this->font_stretching / 100);
  5008. }
  5009. // set word spacing
  5010. $rs .= sprintf('BT %F Tw ET ', $spacewidth);
  5011. }
  5012. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5013. }
  5014. // replace carriage return characters
  5015. $txt2 = str_replace("\r", ' ', $txt2);
  5016. switch ($align) {
  5017. case 'C': {
  5018. $dx = ($w - $width) / 2;
  5019. break;
  5020. }
  5021. case 'R': {
  5022. if ($this->rtl) {
  5023. $dx = $this->cell_padding['R'];
  5024. } else {
  5025. $dx = $w - $width - $this->cell_padding['R'];
  5026. }
  5027. break;
  5028. }
  5029. case 'L': {
  5030. if ($this->rtl) {
  5031. $dx = $w - $width - $this->cell_padding['L'];
  5032. } else {
  5033. $dx = $this->cell_padding['L'];
  5034. }
  5035. break;
  5036. }
  5037. case 'J':
  5038. default: {
  5039. if ($this->rtl) {
  5040. $dx = $this->cell_padding['R'];
  5041. } else {
  5042. $dx = $this->cell_padding['L'];
  5043. }
  5044. break;
  5045. }
  5046. }
  5047. if ($this->rtl) {
  5048. $xdx = $x - $dx - $width;
  5049. } else {
  5050. $xdx = $x + $dx;
  5051. }
  5052. $xdk = $xdx * $k;
  5053. // print text
  5054. $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  5055. if (isset($uniblock)) {
  5056. // print overlapping characters as separate string
  5057. $xshift = 0; // horizontal shift
  5058. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  5059. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
  5060. foreach ($uniblock as $uk => $uniarr) {
  5061. if (($uk % 2) == 0) {
  5062. // x space to skip
  5063. if ($spacewidth != 0) {
  5064. // justification shift
  5065. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  5066. }
  5067. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  5068. } else {
  5069. // character to print
  5070. $topchr = TCPDF_FONTS::arrUTF8ToUTF16BE($uniarr, false);
  5071. $topchr = TCPDF_STATIC::_escape($topchr);
  5072. $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  5073. }
  5074. }
  5075. }
  5076. if ($this->underline) {
  5077. $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
  5078. }
  5079. if ($this->linethrough) {
  5080. $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
  5081. }
  5082. if ($this->overline) {
  5083. $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
  5084. }
  5085. if ($this->ColorFlag AND ($this->textrendermode < 4)) {
  5086. $s .= ' Q';
  5087. }
  5088. if ($link) {
  5089. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  5090. }
  5091. }
  5092. // output cell
  5093. if ($s) {
  5094. // output cell
  5095. $rs .= $s;
  5096. if ($this->font_spacing != 0) {
  5097. // reset font spacing mode
  5098. $rs .= ' BT 0 Tc ET';
  5099. }
  5100. if ($this->font_stretching != 100) {
  5101. // reset font stretching mode
  5102. $rs .= ' BT 100 Tz ET';
  5103. }
  5104. }
  5105. // reset word spacing
  5106. if (!$this->isUnicodeFont() AND ($align == 'J')) {
  5107. $rs .= ' BT 0 Tw ET';
  5108. }
  5109. // reset stretching and spacing
  5110. $this->font_stretching = $prev_font_stretching;
  5111. $this->font_spacing = $prev_font_spacing;
  5112. $this->lasth = $h;
  5113. if ($ln > 0) {
  5114. //Go to the beginning of the next line
  5115. $this->y = $y + $h + $this->cell_margin['B'];
  5116. if ($ln == 1) {
  5117. if ($this->rtl) {
  5118. $this->x = $this->w - $this->rMargin;
  5119. } else {
  5120. $this->x = $this->lMargin;
  5121. }
  5122. }
  5123. } else {
  5124. // go left or right by case
  5125. if ($this->rtl) {
  5126. $this->x = $x - $w - $this->cell_margin['L'];
  5127. } else {
  5128. $this->x = $x + $w + $this->cell_margin['R'];
  5129. }
  5130. }
  5131. $gstyles = ''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor."\n";
  5132. $rs = $gstyles.$rs;
  5133. $this->cell_padding = $prev_cell_padding;
  5134. $this->cell_margin = $prev_cell_margin;
  5135. return $rs;
  5136. }
  5137. /**
  5138. * Replace a char if is defined on the current font.
  5139. * @param $oldchar (int) Integer code (unicode) of the character to replace.
  5140. * @param $newchar (int) Integer code (unicode) of the new character.
  5141. * @return int the replaced char or the old char in case the new char i not defined
  5142. * @protected
  5143. * @since 5.9.167 (2012-06-22)
  5144. */
  5145. protected function replaceChar($oldchar, $newchar) {
  5146. if ($this->isCharDefined($newchar)) {
  5147. // add the new char on the subset list
  5148. $this->CurrentFont['subsetchars'][$newchar] = true;
  5149. // return the new character
  5150. return $newchar;
  5151. }
  5152. // return the old char
  5153. return $oldchar;
  5154. }
  5155. /**
  5156. * Returns the code to draw the cell border
  5157. * @param $x (float) X coordinate.
  5158. * @param $y (float) Y coordinate.
  5159. * @param $w (float) Cell width.
  5160. * @param $h (float) Cell height.
  5161. * @param $brd (mixed) 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)))
  5162. * @return string containing cell border code
  5163. * @protected
  5164. * @see SetLineStyle()
  5165. * @since 5.7.000 (2010-08-02)
  5166. */
  5167. protected function getCellBorder($x, $y, $w, $h, $brd) {
  5168. $s = ''; // string to be returned
  5169. if (empty($brd)) {
  5170. return $s;
  5171. }
  5172. if ($brd == 1) {
  5173. $brd = array('LRTB' => true);
  5174. }
  5175. // calculate coordinates for border
  5176. $k = $this->k;
  5177. if ($this->rtl) {
  5178. $xeL = ($x - $w) * $k;
  5179. $xeR = $x * $k;
  5180. } else {
  5181. $xeL = $x * $k;
  5182. $xeR = ($x + $w) * $k;
  5183. }
  5184. $yeL = (($this->h - ($y + $h)) * $k);
  5185. $yeT = (($this->h - $y) * $k);
  5186. $xeT = $xeL;
  5187. $xeB = $xeR;
  5188. $yeR = $yeT;
  5189. $yeB = $yeL;
  5190. if (is_string($brd)) {
  5191. // convert string to array
  5192. $slen = strlen($brd);
  5193. $newbrd = array();
  5194. for ($i = 0; $i < $slen; ++$i) {
  5195. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  5196. }
  5197. $brd = $newbrd;
  5198. }
  5199. if (isset($brd['mode'])) {
  5200. $mode = $brd['mode'];
  5201. unset($brd['mode']);
  5202. } else {
  5203. $mode = 'normal';
  5204. }
  5205. foreach ($brd as $border => $style) {
  5206. if (is_array($style) AND !empty($style)) {
  5207. // apply border style
  5208. $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
  5209. $s .= $this->SetLineStyle($style, true)."\n";
  5210. }
  5211. switch ($mode) {
  5212. case 'ext': {
  5213. $off = (($this->LineWidth / 2) * $k);
  5214. $xL = $xeL - $off;
  5215. $xR = $xeR + $off;
  5216. $yT = $yeT + $off;
  5217. $yL = $yeL - $off;
  5218. $xT = $xL;
  5219. $xB = $xR;
  5220. $yR = $yT;
  5221. $yB = $yL;
  5222. $w += $this->LineWidth;
  5223. $h += $this->LineWidth;
  5224. break;
  5225. }
  5226. case 'int': {
  5227. $off = ($this->LineWidth / 2) * $k;
  5228. $xL = $xeL + $off;
  5229. $xR = $xeR - $off;
  5230. $yT = $yeT - $off;
  5231. $yL = $yeL + $off;
  5232. $xT = $xL;
  5233. $xB = $xR;
  5234. $yR = $yT;
  5235. $yB = $yL;
  5236. $w -= $this->LineWidth;
  5237. $h -= $this->LineWidth;
  5238. break;
  5239. }
  5240. case 'normal':
  5241. default: {
  5242. $xL = $xeL;
  5243. $xT = $xeT;
  5244. $xB = $xeB;
  5245. $xR = $xeR;
  5246. $yL = $yeL;
  5247. $yT = $yeT;
  5248. $yB = $yeB;
  5249. $yR = $yeR;
  5250. break;
  5251. }
  5252. }
  5253. // draw borders by case
  5254. if (strlen($border) == 4) {
  5255. $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
  5256. } elseif (strlen($border) == 3) {
  5257. if (strpos($border,'B') === false) { // LTR
  5258. $s .= sprintf('%F %F m ', $xL, $yL);
  5259. $s .= sprintf('%F %F l ', $xT, $yT);
  5260. $s .= sprintf('%F %F l ', $xR, $yR);
  5261. $s .= sprintf('%F %F l ', $xB, $yB);
  5262. $s .= 'S ';
  5263. } elseif (strpos($border,'L') === false) { // TRB
  5264. $s .= sprintf('%F %F m ', $xT, $yT);
  5265. $s .= sprintf('%F %F l ', $xR, $yR);
  5266. $s .= sprintf('%F %F l ', $xB, $yB);
  5267. $s .= sprintf('%F %F l ', $xL, $yL);
  5268. $s .= 'S ';
  5269. } elseif (strpos($border,'T') === false) { // RBL
  5270. $s .= sprintf('%F %F m ', $xR, $yR);
  5271. $s .= sprintf('%F %F l ', $xB, $yB);
  5272. $s .= sprintf('%F %F l ', $xL, $yL);
  5273. $s .= sprintf('%F %F l ', $xT, $yT);
  5274. $s .= 'S ';
  5275. } elseif (strpos($border,'R') === false) { // BLT
  5276. $s .= sprintf('%F %F m ', $xB, $yB);
  5277. $s .= sprintf('%F %F l ', $xL, $yL);
  5278. $s .= sprintf('%F %F l ', $xT, $yT);
  5279. $s .= sprintf('%F %F l ', $xR, $yR);
  5280. $s .= 'S ';
  5281. }
  5282. } elseif (strlen($border) == 2) {
  5283. if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
  5284. $s .= sprintf('%F %F m ', $xL, $yL);
  5285. $s .= sprintf('%F %F l ', $xT, $yT);
  5286. $s .= sprintf('%F %F l ', $xR, $yR);
  5287. $s .= 'S ';
  5288. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
  5289. $s .= sprintf('%F %F m ', $xT, $yT);
  5290. $s .= sprintf('%F %F l ', $xR, $yR);
  5291. $s .= sprintf('%F %F l ', $xB, $yB);
  5292. $s .= 'S ';
  5293. } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
  5294. $s .= sprintf('%F %F m ', $xR, $yR);
  5295. $s .= sprintf('%F %F l ', $xB, $yB);
  5296. $s .= sprintf('%F %F l ', $xL, $yL);
  5297. $s .= 'S ';
  5298. } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
  5299. $s .= sprintf('%F %F m ', $xB, $yB);
  5300. $s .= sprintf('%F %F l ', $xL, $yL);
  5301. $s .= sprintf('%F %F l ', $xT, $yT);
  5302. $s .= 'S ';
  5303. } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
  5304. $s .= sprintf('%F %F m ', $xL, $yL);
  5305. $s .= sprintf('%F %F l ', $xT, $yT);
  5306. $s .= 'S ';
  5307. $s .= sprintf('%F %F m ', $xR, $yR);
  5308. $s .= sprintf('%F %F l ', $xB, $yB);
  5309. $s .= 'S ';
  5310. } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
  5311. $s .= sprintf('%F %F m ', $xT, $yT);
  5312. $s .= sprintf('%F %F l ', $xR, $yR);
  5313. $s .= 'S ';
  5314. $s .= sprintf('%F %F m ', $xB, $yB);
  5315. $s .= sprintf('%F %F l ', $xL, $yL);
  5316. $s .= 'S ';
  5317. }
  5318. } else { // strlen($border) == 1
  5319. if (strpos($border,'L') !== false) { // L
  5320. $s .= sprintf('%F %F m ', $xL, $yL);
  5321. $s .= sprintf('%F %F l ', $xT, $yT);
  5322. $s .= 'S ';
  5323. } elseif (strpos($border,'T') !== false) { // T
  5324. $s .= sprintf('%F %F m ', $xT, $yT);
  5325. $s .= sprintf('%F %F l ', $xR, $yR);
  5326. $s .= 'S ';
  5327. } elseif (strpos($border,'R') !== false) { // R
  5328. $s .= sprintf('%F %F m ', $xR, $yR);
  5329. $s .= sprintf('%F %F l ', $xB, $yB);
  5330. $s .= 'S ';
  5331. } elseif (strpos($border,'B') !== false) { // B
  5332. $s .= sprintf('%F %F m ', $xB, $yB);
  5333. $s .= sprintf('%F %F l ', $xL, $yL);
  5334. $s .= 'S ';
  5335. }
  5336. }
  5337. if (is_array($style) AND !empty($style)) {
  5338. // reset border style to previous value
  5339. $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
  5340. }
  5341. }
  5342. return $s;
  5343. }
  5344. /**
  5345. * This method allows printing text with line breaks.
  5346. * 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 />
  5347. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  5348. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5349. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  5350. * @param $txt (string) String to print
  5351. * @param $border (mixed) 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)))
  5352. * @param $align (string) 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>
  5353. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5354. * @param $ln (int) 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>
  5355. * @param $x (float) x position in user units
  5356. * @param $y (float) y position in user units
  5357. * @param $reseth (boolean) if true reset the last cell height (default true).
  5358. * @param $stretch (int) 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.
  5359. * @param $ishtml (boolean) 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.
  5360. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  5361. * @param $maxh (float) 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.
  5362. * @param $valign (string) 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.
  5363. * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode).
  5364. * @return int Return the number of cells or 1 for html mode.
  5365. * @public
  5366. * @since 1.3
  5367. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  5368. */
  5369. public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false) {
  5370. $prev_cell_margin = $this->cell_margin;
  5371. $prev_cell_padding = $this->cell_padding;
  5372. // adjust internal padding
  5373. $this->adjustCellPadding($border);
  5374. $mc_padding = $this->cell_padding;
  5375. $mc_margin = $this->cell_margin;
  5376. $this->cell_padding['T'] = 0;
  5377. $this->cell_padding['B'] = 0;
  5378. $this->setCellMargins(0, 0, 0, 0);
  5379. if (TCPDF_STATIC::empty_string($this->lasth) OR $reseth) {
  5380. // reset row height
  5381. $this->resetLastH();
  5382. }
  5383. if (!TCPDF_STATIC::empty_string($y)) {
  5384. $this->SetY($y);
  5385. } else {
  5386. $y = $this->GetY();
  5387. }
  5388. $resth = 0;
  5389. if (($h > 0) AND $this->inPageBody() AND (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger)) {
  5390. // spit cell in more pages/columns
  5391. $newh = ($this->PageBreakTrigger - $y);
  5392. $resth = ($h - $newh); // cell to be printed on the next page/column
  5393. $h = $newh;
  5394. }
  5395. // get current page number
  5396. $startpage = $this->page;
  5397. // get current column
  5398. $startcolumn = $this->current_column;
  5399. if (!TCPDF_STATIC::empty_string($x)) {
  5400. $this->SetX($x);
  5401. } else {
  5402. $x = $this->GetX();
  5403. }
  5404. // check page for no-write regions and adapt page margins if necessary
  5405. list($x, $y) = $this->checkPageRegions(0, $x, $y);
  5406. // apply margins
  5407. $oy = $y + $mc_margin['T'];
  5408. if ($this->rtl) {
  5409. $ox = ($this->w - $x - $mc_margin['R']);
  5410. } else {
  5411. $ox = ($x + $mc_margin['L']);
  5412. }
  5413. $this->x = $ox;
  5414. $this->y = $oy;
  5415. // set width
  5416. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5417. if ($this->rtl) {
  5418. $w = ($this->x - $this->lMargin - $mc_margin['L']);
  5419. } else {
  5420. $w = ($this->w - $this->x - $this->rMargin - $mc_margin['R']);
  5421. }
  5422. }
  5423. // store original margin values
  5424. $lMargin = $this->lMargin;
  5425. $rMargin = $this->rMargin;
  5426. if ($this->rtl) {
  5427. $this->rMargin = ($this->w - $this->x);
  5428. $this->lMargin = ($this->x - $w);
  5429. } else {
  5430. $this->lMargin = ($this->x);
  5431. $this->rMargin = ($this->w - $this->x - $w);
  5432. }
  5433. $this->clMargin = $this->lMargin;
  5434. $this->crMargin = $this->rMargin;
  5435. if ($autopadding) {
  5436. // add top padding
  5437. $this->y += $mc_padding['T'];
  5438. }
  5439. if ($ishtml) { // ******* Write HTML text
  5440. $this->writeHTML($txt, true, false, $reseth, true, $align);
  5441. $nl = 1;
  5442. } else { // ******* Write simple text
  5443. $prev_FontSizePt = $this->FontSizePt;
  5444. // vertical alignment
  5445. if ($maxh > 0) {
  5446. // get text height
  5447. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5448. if ($fitcell) {
  5449. // try to reduce font size to fit text on cell (use a quick search algorithm)
  5450. $fmin = 1;
  5451. $fmax = $this->FontSizePt;
  5452. $prev_text_height = $text_height;
  5453. $maxit = 100; // max number of iterations
  5454. while ($maxit > 0) {
  5455. $fmid = (($fmax + $fmin) / 2);
  5456. $this->SetFontSize($fmid, false);
  5457. $this->resetLastH();
  5458. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  5459. if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
  5460. break;
  5461. } elseif ($text_height < $maxh) {
  5462. $fmin = $fmid;
  5463. } else {
  5464. $fmax = $fmid;
  5465. }
  5466. --$maxit;
  5467. }
  5468. $this->SetFontSize($this->FontSizePt);
  5469. }
  5470. if ($text_height < $maxh) {
  5471. if ($valign == 'M') {
  5472. // text vertically centered
  5473. $this->y += (($maxh - $text_height) / 2);
  5474. } elseif ($valign == 'B') {
  5475. // text vertically aligned on bottom
  5476. $this->y += ($maxh - $text_height);
  5477. }
  5478. }
  5479. }
  5480. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  5481. if ($fitcell) {
  5482. // restore font size
  5483. $this->SetFontSize($prev_FontSizePt);
  5484. }
  5485. }
  5486. if ($autopadding) {
  5487. // add bottom padding
  5488. $this->y += $mc_padding['B'];
  5489. }
  5490. // Get end-of-text Y position
  5491. $currentY = $this->y;
  5492. // get latest page number
  5493. $endpage = $this->page;
  5494. if ($resth > 0) {
  5495. $skip = ($endpage - $startpage);
  5496. $tmpresth = $resth;
  5497. while ($tmpresth > 0) {
  5498. if ($skip <= 0) {
  5499. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  5500. $this->checkPageBreak($this->PageBreakTrigger + 1);
  5501. }
  5502. if ($this->num_columns > 1) {
  5503. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  5504. } else {
  5505. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  5506. }
  5507. --$skip;
  5508. }
  5509. $currentY = $this->y;
  5510. $endpage = $this->page;
  5511. }
  5512. // get latest column
  5513. $endcolumn = $this->current_column;
  5514. if ($this->num_columns == 0) {
  5515. $this->num_columns = 1;
  5516. }
  5517. // disable page regions check
  5518. $check_page_regions = $this->check_page_regions;
  5519. $this->check_page_regions = false;
  5520. // get border modes
  5521. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  5522. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  5523. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  5524. // design borders around HTML cells.
  5525. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  5526. $ccode = '';
  5527. $this->setPage($page);
  5528. if ($this->num_columns < 2) {
  5529. // single-column mode
  5530. $this->SetX($x);
  5531. $this->y = $this->tMargin;
  5532. }
  5533. // account for margin changes
  5534. if ($page > $startpage) {
  5535. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  5536. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  5537. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  5538. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  5539. }
  5540. }
  5541. if ($startpage == $endpage) {
  5542. // single page
  5543. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  5544. $this->selectColumn($column);
  5545. if ($this->rtl) {
  5546. $this->x -= $mc_margin['R'];
  5547. } else {
  5548. $this->x += $mc_margin['L'];
  5549. }
  5550. if ($startcolumn == $endcolumn) { // single column
  5551. $cborder = $border;
  5552. $h = max($h, ($currentY - $oy));
  5553. $this->y = $oy;
  5554. } elseif ($column == $startcolumn) { // first column
  5555. $cborder = $border_start;
  5556. $this->y = $oy;
  5557. $h = $this->h - $this->y - $this->bMargin;
  5558. } elseif ($column == $endcolumn) { // end column
  5559. $cborder = $border_end;
  5560. $h = $currentY - $this->y;
  5561. if ($resth > $h) {
  5562. $h = $resth;
  5563. }
  5564. } else { // middle column
  5565. $cborder = $border_middle;
  5566. $h = $this->h - $this->y - $this->bMargin;
  5567. $resth -= $h;
  5568. }
  5569. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5570. } // end for each column
  5571. } elseif ($page == $startpage) { // first page
  5572. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  5573. $this->selectColumn($column);
  5574. if ($this->rtl) {
  5575. $this->x -= $mc_margin['R'];
  5576. } else {
  5577. $this->x += $mc_margin['L'];
  5578. }
  5579. if ($column == $startcolumn) { // first column
  5580. $cborder = $border_start;
  5581. $this->y = $oy;
  5582. $h = $this->h - $this->y - $this->bMargin;
  5583. } else { // middle column
  5584. $cborder = $border_middle;
  5585. $h = $this->h - $this->y - $this->bMargin;
  5586. $resth -= $h;
  5587. }
  5588. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5589. } // end for each column
  5590. } elseif ($page == $endpage) { // last page
  5591. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  5592. $this->selectColumn($column);
  5593. if ($this->rtl) {
  5594. $this->x -= $mc_margin['R'];
  5595. } else {
  5596. $this->x += $mc_margin['L'];
  5597. }
  5598. if ($column == $endcolumn) {
  5599. // end column
  5600. $cborder = $border_end;
  5601. $h = $currentY - $this->y;
  5602. if ($resth > $h) {
  5603. $h = $resth;
  5604. }
  5605. } else {
  5606. // middle column
  5607. $cborder = $border_middle;
  5608. $h = $this->h - $this->y - $this->bMargin;
  5609. $resth -= $h;
  5610. }
  5611. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5612. } // end for each column
  5613. } else { // middle page
  5614. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  5615. $this->selectColumn($column);
  5616. if ($this->rtl) {
  5617. $this->x -= $mc_margin['R'];
  5618. } else {
  5619. $this->x += $mc_margin['L'];
  5620. }
  5621. $cborder = $border_middle;
  5622. $h = $this->h - $this->y - $this->bMargin;
  5623. $resth -= $h;
  5624. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  5625. } // end for each column
  5626. }
  5627. if ($cborder OR $fill) {
  5628. $offsetlen = strlen($ccode);
  5629. // draw border and fill
  5630. if ($this->inxobj) {
  5631. // we are inside an XObject template
  5632. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  5633. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  5634. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  5635. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  5636. } else {
  5637. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  5638. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  5639. }
  5640. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  5641. $pstart = substr($pagebuff, 0, $pagemark);
  5642. $pend = substr($pagebuff, $pagemark);
  5643. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  5644. } else {
  5645. if (end($this->transfmrk[$this->page]) !== false) {
  5646. $pagemarkkey = key($this->transfmrk[$this->page]);
  5647. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  5648. $this->transfmrk[$this->page][$pagemarkkey] += $offsetlen;
  5649. } elseif ($this->InFooter) {
  5650. $pagemark = $this->footerpos[$this->page];
  5651. $this->footerpos[$this->page] += $offsetlen;
  5652. } else {
  5653. $pagemark = $this->intmrk[$this->page];
  5654. $this->intmrk[$this->page] += $offsetlen;
  5655. }
  5656. $pagebuff = $this->getPageBuffer($this->page);
  5657. $pstart = substr($pagebuff, 0, $pagemark);
  5658. $pend = substr($pagebuff, $pagemark);
  5659. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  5660. }
  5661. }
  5662. } // end for each page
  5663. // restore page regions check
  5664. $this->check_page_regions = $check_page_regions;
  5665. // Get end-of-cell Y position
  5666. $currentY = $this->GetY();
  5667. // restore previous values
  5668. if ($this->num_columns > 1) {
  5669. $this->selectColumn();
  5670. } else {
  5671. // restore original margins
  5672. $this->lMargin = $lMargin;
  5673. $this->rMargin = $rMargin;
  5674. if ($this->page > $startpage) {
  5675. // check for margin variations between pages (i.e. booklet mode)
  5676. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$startpage]['olm']);
  5677. $dr = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$startpage]['orm']);
  5678. if (($dl != 0) OR ($dr != 0)) {
  5679. $this->lMargin += $dl;
  5680. $this->rMargin += $dr;
  5681. }
  5682. }
  5683. }
  5684. if ($ln > 0) {
  5685. //Go to the beginning of the next line
  5686. $this->SetY($currentY + $mc_margin['B']);
  5687. if ($ln == 2) {
  5688. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5689. }
  5690. } else {
  5691. // go left or right by case
  5692. $this->setPage($startpage);
  5693. $this->y = $y;
  5694. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  5695. }
  5696. $this->setContentMark();
  5697. $this->cell_padding = $prev_cell_padding;
  5698. $this->cell_margin = $prev_cell_margin;
  5699. $this->clMargin = $this->lMargin;
  5700. $this->crMargin = $this->rMargin;
  5701. return $nl;
  5702. }
  5703. /**
  5704. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  5705. * @param $txt (string) String for calculating his height
  5706. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5707. * @param $reseth (boolean) if true reset the last cell height (default false).
  5708. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5709. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5710. * @param $border (mixed) 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)))
  5711. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5712. * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
  5713. * @public
  5714. * @since 4.5.011
  5715. */
  5716. public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  5717. if ($txt === '') {
  5718. // empty string
  5719. return 1;
  5720. }
  5721. // adjust internal padding
  5722. $prev_cell_padding = $this->cell_padding;
  5723. $prev_lasth = $this->lasth;
  5724. if (is_array($cellpadding)) {
  5725. $this->cell_padding = $cellpadding;
  5726. }
  5727. $this->adjustCellPadding($border);
  5728. if (TCPDF_STATIC::empty_string($w) OR ($w <= 0)) {
  5729. if ($this->rtl) {
  5730. $w = $this->x - $this->lMargin;
  5731. } else {
  5732. $w = $this->w - $this->rMargin - $this->x;
  5733. }
  5734. }
  5735. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  5736. if ($reseth) {
  5737. // reset row height
  5738. $this->resetLastH();
  5739. }
  5740. $lines = 1;
  5741. $sum = 0;
  5742. $chars = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($txt, $this->isunicode, $this->CurrentFont), $txt, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5743. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  5744. $length = count($chars);
  5745. $lastSeparator = -1;
  5746. for ($i = 0; $i < $length; ++$i) {
  5747. $charWidth = $charsWidth[$i];
  5748. if (preg_match($this->re_spaces, TCPDF_FONTS::unichr($chars[$i], $this->isunicode))) {
  5749. $lastSeparator = $i;
  5750. }
  5751. if ((($sum + $charWidth) > $wmax) OR ($chars[$i] == 10)) {
  5752. ++$lines;
  5753. if ($chars[$i] == 10) {
  5754. $lastSeparator = -1;
  5755. $sum = 0;
  5756. } elseif ($lastSeparator != -1) {
  5757. $i = $lastSeparator;
  5758. $lastSeparator = -1;
  5759. $sum = 0;
  5760. } else {
  5761. $sum = $charWidth;
  5762. }
  5763. } else {
  5764. $sum += $charWidth;
  5765. }
  5766. }
  5767. if ($chars[($length - 1)] == 10) {
  5768. --$lines;
  5769. }
  5770. $this->cell_padding = $prev_cell_padding;
  5771. $this->lasth = $prev_lasth;
  5772. return $lines;
  5773. }
  5774. /**
  5775. * This method return the estimated height needed for printing a simple text string using the Multicell() method.
  5776. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  5777. * @pre
  5778. * // store current object
  5779. * $pdf->startTransaction();
  5780. * // store starting values
  5781. * $start_y = $pdf->GetY();
  5782. * $start_page = $pdf->getPage();
  5783. * // call your printing functions with your parameters
  5784. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5785. * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
  5786. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5787. * // get the new Y
  5788. * $end_y = $pdf->GetY();
  5789. * $end_page = $pdf->getPage();
  5790. * // calculate height
  5791. * $height = 0;
  5792. * if ($end_page == $start_page) {
  5793. * $height = $end_y - $start_y;
  5794. * } else {
  5795. * for ($page=$start_page; $page <= $end_page; ++$page) {
  5796. * $this->setPage($page);
  5797. * if ($page == $start_page) {
  5798. * // first page
  5799. * $height = $this->h - $start_y - $this->bMargin;
  5800. * } elseif ($page == $end_page) {
  5801. * // last page
  5802. * $height = $end_y - $this->tMargin;
  5803. * } else {
  5804. * $height = $this->h - $this->tMargin - $this->bMargin;
  5805. * }
  5806. * }
  5807. * }
  5808. * // restore previous object
  5809. * $pdf = $pdf->rollbackTransaction();
  5810. *
  5811. * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
  5812. * @param $txt (string) String for calculating his height
  5813. * @param $reseth (boolean) if true reset the last cell height (default false).
  5814. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
  5815. * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
  5816. * @param $border (mixed) 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)))
  5817. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  5818. * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
  5819. * @public
  5820. */
  5821. public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
  5822. // adjust internal padding
  5823. $prev_cell_padding = $this->cell_padding;
  5824. $prev_lasth = $this->lasth;
  5825. if (is_array($cellpadding)) {
  5826. $this->cell_padding = $cellpadding;
  5827. }
  5828. $this->adjustCellPadding($border);
  5829. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  5830. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  5831. if ($autopadding) {
  5832. // add top and bottom padding
  5833. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  5834. }
  5835. $this->cell_padding = $prev_cell_padding;
  5836. $this->lasth = $prev_lasth;
  5837. return $height;
  5838. }
  5839. /**
  5840. * This method prints text from the current position.<br />
  5841. * @param $h (float) Line height
  5842. * @param $txt (string) String to print
  5843. * @param $link (mixed) URL or identifier returned by AddLink()
  5844. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  5845. * @param $align (string) 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>
  5846. * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  5847. * @param $stretch (int) 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.
  5848. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  5849. * @param $firstblock (boolean) if true the string is the starting of a line.
  5850. * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  5851. * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
  5852. * @param $margin (array) margin array of the parent container
  5853. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  5854. * @public
  5855. * @since 1.5
  5856. */
  5857. public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
  5858. // check page for no-write regions and adapt page margins if necessary
  5859. list($this->x, $this->y) = $this->checkPageRegions($h, $this->x, $this->y);
  5860. if (strlen($txt) == 0) {
  5861. // fix empty text
  5862. $txt = ' ';
  5863. }
  5864. if ($margin === '') {
  5865. // set default margins
  5866. $margin = $this->cell_margin;
  5867. }
  5868. // remove carriage returns
  5869. $s = str_replace("\r", '', $txt);
  5870. // check if string contains arabic text
  5871. if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $s)) {
  5872. $arabic = true;
  5873. } else {
  5874. $arabic = false;
  5875. }
  5876. // check if string contains RTL text
  5877. if ($arabic OR ($this->tmprtl == 'R') OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $s)) {
  5878. $rtlmode = true;
  5879. } else {
  5880. $rtlmode = false;
  5881. }
  5882. // get a char width
  5883. $chrwidth = $this->GetCharWidth(46); // dot character
  5884. // get array of unicode values
  5885. $chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);
  5886. // calculate maximum width for a single character on string
  5887. $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
  5888. array_walk($chrw, array($this, 'getRawCharWidth'));
  5889. $maxchwidth = max($chrw);
  5890. // get array of chars
  5891. $uchars = TCPDF_FONTS::UTF8ArrayToUniArray($chars, $this->isunicode);
  5892. // get the number of characters
  5893. $nb = count($chars);
  5894. // replacement for SHY character (minus symbol)
  5895. $shy_replacement = 45;
  5896. $shy_replacement_char = TCPDF_FONTS::unichr($shy_replacement, $this->isunicode);
  5897. // widht for SHY replacement
  5898. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  5899. // max Y
  5900. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  5901. // page width
  5902. $pw = $w = $this->w - $this->lMargin - $this->rMargin;
  5903. // calculate remaining line width ($w)
  5904. if ($this->rtl) {
  5905. $w = $this->x - $this->lMargin;
  5906. } else {
  5907. $w = $this->w - $this->rMargin - $this->x;
  5908. }
  5909. // max column width
  5910. $wmax = ($w - $wadj);
  5911. if (!$firstline) {
  5912. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  5913. }
  5914. if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
  5915. // the maximum width character do not fit on column
  5916. return '';
  5917. }
  5918. // minimum row height
  5919. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  5920. $start_page = $this->page;
  5921. $i = 0; // character position
  5922. $j = 0; // current starting position
  5923. $sep = -1; // position of the last blank space
  5924. $shy = false; // true if the last blank is a soft hypen (SHY)
  5925. $l = 0; // current string length
  5926. $nl = 0; //number of lines
  5927. $linebreak = false;
  5928. $pc = 0; // previous character
  5929. // for each character
  5930. while ($i < $nb) {
  5931. if (($maxh > 0) AND ($this->y >= $maxy) ) {
  5932. break;
  5933. }
  5934. //Get the current character
  5935. $c = $chars[$i];
  5936. if ($c == 10) { // 10 = "\n" = new line
  5937. //Explicit line break
  5938. if ($align == 'J') {
  5939. if ($this->rtl) {
  5940. $talign = 'R';
  5941. } else {
  5942. $talign = 'L';
  5943. }
  5944. } else {
  5945. $talign = $align;
  5946. }
  5947. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  5948. if ($firstline) {
  5949. $startx = $this->x;
  5950. $tmparr = array_slice($chars, $j, ($i - $j));
  5951. if ($rtlmode) {
  5952. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  5953. }
  5954. $linew = $this->GetArrStringWidth($tmparr);
  5955. unset($tmparr);
  5956. if ($this->rtl) {
  5957. $this->endlinex = $startx - $linew;
  5958. } else {
  5959. $this->endlinex = $startx + $linew;
  5960. }
  5961. $w = $linew;
  5962. $tmpcellpadding = $this->cell_padding;
  5963. if ($maxh == 0) {
  5964. $this->SetCellPadding(0);
  5965. }
  5966. }
  5967. if ($firstblock AND $this->isRTLTextDir()) {
  5968. $tmpstr = $this->stringRightTrim($tmpstr);
  5969. }
  5970. // Skip newlines at the begining of a page or column
  5971. if (!empty($tmpstr) OR ($this->y < ($this->PageBreakTrigger - $row_height))) {
  5972. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  5973. }
  5974. unset($tmpstr);
  5975. if ($firstline) {
  5976. $this->cell_padding = $tmpcellpadding;
  5977. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  5978. }
  5979. ++$nl;
  5980. $j = $i + 1;
  5981. $l = 0;
  5982. $sep = -1;
  5983. $shy = false;
  5984. // account for margin changes
  5985. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  5986. $this->AcceptPageBreak();
  5987. if ($this->rtl) {
  5988. $this->x -= $margin['R'];
  5989. } else {
  5990. $this->x += $margin['L'];
  5991. }
  5992. $this->lMargin += $margin['L'];
  5993. $this->rMargin += $margin['R'];
  5994. }
  5995. $w = $this->getRemainingWidth();
  5996. $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']);
  5997. } else {
  5998. // 160 is the non-breaking space.
  5999. // 173 is SHY (Soft Hypen).
  6000. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  6001. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  6002. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  6003. if (($c != 160)
  6004. AND (($c == 173)
  6005. OR preg_match($this->re_spaces, TCPDF_FONTS::unichr($c, $this->isunicode))
  6006. OR (($c == 45)
  6007. AND ($i < ($nb - 1))
  6008. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($pc, $this->isunicode))
  6009. AND @preg_match('/[\p{L}]/'.$this->re_space['m'], TCPDF_FONTS::unichr($chars[($i + 1)], $this->isunicode))
  6010. )
  6011. )
  6012. ) {
  6013. // update last blank space position
  6014. $sep = $i;
  6015. // check if is a SHY
  6016. if (($c == 173) OR ($c == 45)) {
  6017. $shy = true;
  6018. if ($pc == 45) {
  6019. $tmp_shy_replacement_width = 0;
  6020. $tmp_shy_replacement_char = '';
  6021. } else {
  6022. $tmp_shy_replacement_width = $shy_replacement_width;
  6023. $tmp_shy_replacement_char = $shy_replacement_char;
  6024. }
  6025. } else {
  6026. $shy = false;
  6027. }
  6028. }
  6029. // update string length
  6030. if ($this->isUnicodeFont() AND ($arabic)) {
  6031. // with bidirectional algorithm some chars may be changed affecting the line length
  6032. // *** very slow ***
  6033. $l = $this->GetArrStringWidth(TCPDF_FONTS::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl, $this->isunicode, $this->CurrentFont));
  6034. } else {
  6035. $l += $this->GetCharWidth($c);
  6036. }
  6037. if (($l > $wmax) OR (($c == 173) AND (($l + $tmp_shy_replacement_width) > $wmax)) ) {
  6038. // we have reached the end of column
  6039. if ($sep == -1) {
  6040. // check if the line was already started
  6041. if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $this->cell_padding['R'] - $margin['R'] - $chrwidth)))
  6042. OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $this->cell_padding['L'] + $margin['L'] + $chrwidth)))) {
  6043. // print a void cell and go to next line
  6044. $this->Cell($w, $h, '', 0, 1);
  6045. $linebreak = true;
  6046. if ($firstline) {
  6047. return (TCPDF_FONTS::UniArrSubString($uchars, $j));
  6048. }
  6049. } else {
  6050. // truncate the word because do not fit on column
  6051. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6052. if ($firstline) {
  6053. $startx = $this->x;
  6054. $tmparr = array_slice($chars, $j, ($i - $j));
  6055. if ($rtlmode) {
  6056. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6057. }
  6058. $linew = $this->GetArrStringWidth($tmparr);
  6059. unset($tmparr);
  6060. if ($this->rtl) {
  6061. $this->endlinex = $startx - $linew;
  6062. } else {
  6063. $this->endlinex = $startx + $linew;
  6064. }
  6065. $w = $linew;
  6066. $tmpcellpadding = $this->cell_padding;
  6067. if ($maxh == 0) {
  6068. $this->SetCellPadding(0);
  6069. }
  6070. }
  6071. if ($firstblock AND $this->isRTLTextDir()) {
  6072. $tmpstr = $this->stringRightTrim($tmpstr);
  6073. }
  6074. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6075. unset($tmpstr);
  6076. if ($firstline) {
  6077. $this->cell_padding = $tmpcellpadding;
  6078. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6079. }
  6080. $j = $i;
  6081. --$i;
  6082. }
  6083. } else {
  6084. // word wrapping
  6085. if ($this->rtl AND (!$firstblock) AND ($sep < $i)) {
  6086. $endspace = 1;
  6087. } else {
  6088. $endspace = 0;
  6089. }
  6090. // check the length of the next string
  6091. $strrest = TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace));
  6092. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $this->stringTrim($strrest));
  6093. if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
  6094. // truncate the word because do not fit on a full page width
  6095. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $i);
  6096. if ($firstline) {
  6097. $startx = $this->x;
  6098. $tmparr = array_slice($chars, $j, ($i - $j));
  6099. if ($rtlmode) {
  6100. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6101. }
  6102. $linew = $this->GetArrStringWidth($tmparr);
  6103. unset($tmparr);
  6104. if ($this->rtl) {
  6105. $this->endlinex = ($startx - $linew);
  6106. } else {
  6107. $this->endlinex = ($startx + $linew);
  6108. }
  6109. $w = $linew;
  6110. $tmpcellpadding = $this->cell_padding;
  6111. if ($maxh == 0) {
  6112. $this->SetCellPadding(0);
  6113. }
  6114. }
  6115. if ($firstblock AND $this->isRTLTextDir()) {
  6116. $tmpstr = $this->stringRightTrim($tmpstr);
  6117. }
  6118. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  6119. unset($tmpstr);
  6120. if ($firstline) {
  6121. $this->cell_padding = $tmpcellpadding;
  6122. return (TCPDF_FONTS::UniArrSubString($uchars, $i));
  6123. }
  6124. $j = $i;
  6125. --$i;
  6126. } else {
  6127. // word wrapping
  6128. if ($shy) {
  6129. // add hypen (minus symbol) at the end of the line
  6130. $shy_width = $tmp_shy_replacement_width;
  6131. if ($this->rtl) {
  6132. $shy_char_left = $tmp_shy_replacement_char;
  6133. $shy_char_right = '';
  6134. } else {
  6135. $shy_char_left = '';
  6136. $shy_char_right = $tmp_shy_replacement_char;
  6137. }
  6138. } else {
  6139. $shy_width = 0;
  6140. $shy_char_left = '';
  6141. $shy_char_right = '';
  6142. }
  6143. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, ($sep + $endspace));
  6144. if ($firstline) {
  6145. $startx = $this->x;
  6146. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  6147. if ($rtlmode) {
  6148. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6149. }
  6150. $linew = $this->GetArrStringWidth($tmparr);
  6151. unset($tmparr);
  6152. if ($this->rtl) {
  6153. $this->endlinex = $startx - $linew - $shy_width;
  6154. } else {
  6155. $this->endlinex = $startx + $linew + $shy_width;
  6156. }
  6157. $w = $linew;
  6158. $tmpcellpadding = $this->cell_padding;
  6159. if ($maxh == 0) {
  6160. $this->SetCellPadding(0);
  6161. }
  6162. }
  6163. // print the line
  6164. if ($firstblock AND $this->isRTLTextDir()) {
  6165. $tmpstr = $this->stringRightTrim($tmpstr);
  6166. }
  6167. $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  6168. unset($tmpstr);
  6169. if ($firstline) {
  6170. if ($chars[$sep] == 45) {
  6171. $endspace += 1;
  6172. }
  6173. // return the remaining text
  6174. $this->cell_padding = $tmpcellpadding;
  6175. return (TCPDF_FONTS::UniArrSubString($uchars, ($sep + $endspace)));
  6176. }
  6177. $i = $sep;
  6178. $sep = -1;
  6179. $shy = false;
  6180. $j = ($i + 1);
  6181. }
  6182. }
  6183. // account for margin changes
  6184. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) {
  6185. $this->AcceptPageBreak();
  6186. if ($this->rtl) {
  6187. $this->x -= $margin['R'];
  6188. } else {
  6189. $this->x += $margin['L'];
  6190. }
  6191. $this->lMargin += $margin['L'];
  6192. $this->rMargin += $margin['R'];
  6193. }
  6194. $w = $this->getRemainingWidth();
  6195. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6196. if ($linebreak) {
  6197. $linebreak = false;
  6198. } else {
  6199. ++$nl;
  6200. $l = 0;
  6201. }
  6202. }
  6203. }
  6204. // save last character
  6205. $pc = $c;
  6206. ++$i;
  6207. } // end while i < nb
  6208. // print last substring (if any)
  6209. if ($l > 0) {
  6210. switch ($align) {
  6211. case 'J':
  6212. case 'C': {
  6213. $w = $w;
  6214. break;
  6215. }
  6216. case 'L': {
  6217. if ($this->rtl) {
  6218. $w = $w;
  6219. } else {
  6220. $w = $l;
  6221. }
  6222. break;
  6223. }
  6224. case 'R': {
  6225. if ($this->rtl) {
  6226. $w = $l;
  6227. } else {
  6228. $w = $w;
  6229. }
  6230. break;
  6231. }
  6232. default: {
  6233. $w = $l;
  6234. break;
  6235. }
  6236. }
  6237. $tmpstr = TCPDF_FONTS::UniArrSubString($uchars, $j, $nb);
  6238. if ($firstline) {
  6239. $startx = $this->x;
  6240. $tmparr = array_slice($chars, $j, ($nb - $j));
  6241. if ($rtlmode) {
  6242. $tmparr = TCPDF_FONTS::utf8Bidi($tmparr, $tmpstr, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  6243. }
  6244. $linew = $this->GetArrStringWidth($tmparr);
  6245. unset($tmparr);
  6246. if ($this->rtl) {
  6247. $this->endlinex = $startx - $linew;
  6248. } else {
  6249. $this->endlinex = $startx + $linew;
  6250. }
  6251. $w = $linew;
  6252. $tmpcellpadding = $this->cell_padding;
  6253. if ($maxh == 0) {
  6254. $this->SetCellPadding(0);
  6255. }
  6256. }
  6257. if ($firstblock AND $this->isRTLTextDir()) {
  6258. $tmpstr = $this->stringRightTrim($tmpstr);
  6259. }
  6260. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  6261. unset($tmpstr);
  6262. if ($firstline) {
  6263. $this->cell_padding = $tmpcellpadding;
  6264. return (TCPDF_FONTS::UniArrSubString($uchars, $nb));
  6265. }
  6266. ++$nl;
  6267. }
  6268. if ($firstline) {
  6269. return '';
  6270. }
  6271. return $nl;
  6272. }
  6273. /**
  6274. * Returns the remaining width between the current position and margins.
  6275. * @return int Return the remaining width
  6276. * @protected
  6277. */
  6278. protected function getRemainingWidth() {
  6279. list($this->x, $this->y) = $this->checkPageRegions(0, $this->x, $this->y);
  6280. if ($this->rtl) {
  6281. return ($this->x - $this->lMargin);
  6282. } else {
  6283. return ($this->w - $this->rMargin - $this->x);
  6284. }
  6285. }
  6286. /**
  6287. * Set the block dimensions accounting for page breaks and page/column fitting
  6288. * @param $w (float) width
  6289. * @param $h (float) height
  6290. * @param $x (float) X coordinate
  6291. * @param $y (float) Y coodiante
  6292. * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
  6293. * @return array($w, $h, $x, $y)
  6294. * @protected
  6295. * @since 5.5.009 (2010-07-05)
  6296. */
  6297. protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
  6298. if ($w <= 0) {
  6299. // set maximum width
  6300. $w = ($this->w - $this->lMargin - $this->rMargin);
  6301. if ($w <= 0) {
  6302. $w = 1;
  6303. }
  6304. }
  6305. if ($h <= 0) {
  6306. // set maximum height
  6307. $h = ($this->PageBreakTrigger - $this->tMargin);
  6308. if ($h <= 0) {
  6309. $h = 1;
  6310. }
  6311. }
  6312. // resize the block to be vertically contained on a single page or single column
  6313. if ($fitonpage OR $this->AutoPageBreak) {
  6314. $ratio_wh = ($w / $h);
  6315. if ($h > ($this->PageBreakTrigger - $this->tMargin)) {
  6316. $h = $this->PageBreakTrigger - $this->tMargin;
  6317. $w = ($h * $ratio_wh);
  6318. }
  6319. // resize the block to be horizontally contained on a single page or single column
  6320. if ($fitonpage) {
  6321. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  6322. if ($w > $maxw) {
  6323. $w = $maxw;
  6324. $h = ($w / $ratio_wh);
  6325. }
  6326. }
  6327. }
  6328. // Check whether we need a new page or new column first as this does not fit
  6329. $prev_x = $this->x;
  6330. $prev_y = $this->y;
  6331. if ($this->checkPageBreak($h, $y) OR ($this->y < $prev_y)) {
  6332. $y = $this->y;
  6333. if ($this->rtl) {
  6334. $x += ($prev_x - $this->x);
  6335. } else {
  6336. $x += ($this->x - $prev_x);
  6337. }
  6338. $this->newline = true;
  6339. }
  6340. // resize the block to be contained on the remaining available page or column space
  6341. if ($fitonpage) {
  6342. $ratio_wh = ($w / $h);
  6343. if (($y + $h) > $this->PageBreakTrigger) {
  6344. $h = $this->PageBreakTrigger - $y;
  6345. $w = ($h * $ratio_wh);
  6346. }
  6347. if ((!$this->rtl) AND (($x + $w) > ($this->w - $this->rMargin))) {
  6348. $w = $this->w - $this->rMargin - $x;
  6349. $h = ($w / $ratio_wh);
  6350. } elseif (($this->rtl) AND (($x - $w) < ($this->lMargin))) {
  6351. $w = $x - $this->lMargin;
  6352. $h = ($w / $ratio_wh);
  6353. }
  6354. }
  6355. return array($w, $h, $x, $y);
  6356. }
  6357. /**
  6358. * Puts an image in the page.
  6359. * The upper-left corner must be given.
  6360. * The dimensions can be specified in different ways:<ul>
  6361. * <li>explicit width and height (expressed in user unit)</li>
  6362. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  6363. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  6364. * 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;
  6365. * The format can be specified explicitly or inferred from the file extension.<br />
  6366. * It is possible to put a link on the image.<br />
  6367. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  6368. * @param $file (string) 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').
  6369. * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  6370. * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  6371. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6372. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6373. * @param $type (string) 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.
  6374. * @param $link (mixed) URL or identifier returned by AddLink().
  6375. * @param $align (string) 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>
  6376. * @param $resize (mixed) 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).
  6377. * @param $dpi (int) dot-per-inch resolution used on resize
  6378. * @param $palign (string) 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>
  6379. * @param $ismask (boolean) true if this image is a mask, false otherwise
  6380. * @param $imgmask (mixed) image object returned by this function or false
  6381. * @param $border (mixed) 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)))
  6382. * @param $fitbox (mixed) 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).
  6383. * @param $hidden (boolean) If true do not display the image.
  6384. * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
  6385. * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
  6386. * @param $altimgs (array) 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.
  6387. * @return image information
  6388. * @public
  6389. * @since 1.1
  6390. */
  6391. public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array()) {
  6392. if ($this->state != 2) {
  6393. return;
  6394. }
  6395. if ($x === '') {
  6396. $x = $this->x;
  6397. }
  6398. if ($y === '') {
  6399. $y = $this->y;
  6400. }
  6401. // check page for no-write regions and adapt page margins if necessary
  6402. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  6403. $exurl = ''; // external streams
  6404. $imsize = FALSE;
  6405. // check if we are passing an image as file or string
  6406. if ($file[0] === '@') {
  6407. // image from string
  6408. $imgdata = substr($file, 1);
  6409. } else { // image file
  6410. if ($file{0} === '*') {
  6411. // image as external stream
  6412. $file = substr($file, 1);
  6413. $exurl = $file;
  6414. }
  6415. // check if is local file
  6416. if (!@file_exists($file)) {
  6417. // encode spaces on filename (file is probably an URL)
  6418. $file = str_replace(' ', '%20', $file);
  6419. }
  6420. if (@file_exists($file)) {
  6421. // get image dimensions
  6422. $imsize = @getimagesize($file);
  6423. }
  6424. if ($imsize === FALSE) {
  6425. $imgdata = TCPDF_STATIC::fileGetContents($file);
  6426. }
  6427. }
  6428. if (isset($imgdata) AND ($imgdata !== FALSE) AND (strpos($file, '__tcpdf_img') === FALSE)) {
  6429. // copy image to cache
  6430. $original_file = $file;
  6431. $file = TCPDF_STATIC::getObjFilename('img');
  6432. $fp = fopen($file, 'w');
  6433. fwrite($fp, $imgdata);
  6434. fclose($fp);
  6435. unset($imgdata);
  6436. $imsize = @getimagesize($file);
  6437. if ($imsize === FALSE) {
  6438. unlink($file);
  6439. $file = $original_file;
  6440. } else {
  6441. $this->cached_files[] = $file;
  6442. }
  6443. }
  6444. if ($imsize === FALSE) {
  6445. if (($w > 0) AND ($h > 0)) {
  6446. // get measures from specified data
  6447. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6448. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  6449. $imsize = array($pw, $ph);
  6450. } else {
  6451. $this->Error('[Image] Unable to get the size of the image: '.$file);
  6452. }
  6453. }
  6454. // file hash
  6455. $filehash = md5($this->file_id.$file);
  6456. // get original image width and height in pixels
  6457. list($pixw, $pixh) = $imsize;
  6458. // calculate image width and height on document
  6459. if (($w <= 0) AND ($h <= 0)) {
  6460. // convert image size to document unit
  6461. $w = $this->pixelsToUnits($pixw);
  6462. $h = $this->pixelsToUnits($pixh);
  6463. } elseif ($w <= 0) {
  6464. $w = $h * $pixw / $pixh;
  6465. } elseif ($h <= 0) {
  6466. $h = $w * $pixh / $pixw;
  6467. } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
  6468. if (strlen($fitbox) !== 2) {
  6469. // set default alignment
  6470. $fitbox = '--';
  6471. }
  6472. // scale image dimensions proportionally to fit within the ($w, $h) box
  6473. if ((($w * $pixh) / ($h * $pixw)) < 1) {
  6474. // store current height
  6475. $oldh = $h;
  6476. // calculate new height
  6477. $h = $w * $pixh / $pixw;
  6478. // height difference
  6479. $hdiff = ($oldh - $h);
  6480. // vertical alignment
  6481. switch (strtoupper($fitbox{1})) {
  6482. case 'T': {
  6483. break;
  6484. }
  6485. case 'M': {
  6486. $y += ($hdiff / 2);
  6487. break;
  6488. }
  6489. case 'B': {
  6490. $y += $hdiff;
  6491. break;
  6492. }
  6493. }
  6494. } else {
  6495. // store current width
  6496. $oldw = $w;
  6497. // calculate new width
  6498. $w = $h * $pixw / $pixh;
  6499. // width difference
  6500. $wdiff = ($oldw - $w);
  6501. // horizontal alignment
  6502. switch (strtoupper($fitbox{0})) {
  6503. case 'L': {
  6504. if ($this->rtl) {
  6505. $x -= $wdiff;
  6506. }
  6507. break;
  6508. }
  6509. case 'C': {
  6510. if ($this->rtl) {
  6511. $x -= ($wdiff / 2);
  6512. } else {
  6513. $x += ($wdiff / 2);
  6514. }
  6515. break;
  6516. }
  6517. case 'R': {
  6518. if (!$this->rtl) {
  6519. $x += $wdiff;
  6520. }
  6521. break;
  6522. }
  6523. }
  6524. }
  6525. }
  6526. // fit the image on available space
  6527. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  6528. // calculate new minimum dimensions in pixels
  6529. $neww = round($w * $this->k * $dpi / $this->dpi);
  6530. $newh = round($h * $this->k * $dpi / $this->dpi);
  6531. // check if resize is necessary (resize is used only to reduce the image)
  6532. $newsize = ($neww * $newh);
  6533. $pixsize = ($pixw * $pixh);
  6534. if (intval($resize) == 2) {
  6535. $resize = true;
  6536. } elseif ($newsize >= $pixsize) {
  6537. $resize = false;
  6538. }
  6539. // check if image has been already added on document
  6540. $newimage = true;
  6541. if (in_array($file, $this->imagekeys)) {
  6542. $newimage = false;
  6543. // get existing image data
  6544. $info = $this->getImageBuffer($file);
  6545. if (substr($file, 0, -34) != K_PATH_CACHE.'msk') {
  6546. // check if the newer image is larger
  6547. $oldsize = ($info['w'] * $info['h']);
  6548. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6549. $newimage = true;
  6550. }
  6551. }
  6552. } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_imgmask_') === FALSE)) {
  6553. // create temp image file (without alpha channel)
  6554. $tempfile_plain = K_PATH_CACHE.'__tcpdf_imgmask_plain_'.$filehash;
  6555. // create temp alpha file
  6556. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_imgmask_alpha_'.$filehash;
  6557. // check for cached images
  6558. if (in_array($tempfile_plain, $this->imagekeys)) {
  6559. // get existing image data
  6560. $info = $this->getImageBuffer($tempfile_plain);
  6561. // check if the newer image is larger
  6562. $oldsize = ($info['w'] * $info['h']);
  6563. if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
  6564. $newimage = true;
  6565. } else {
  6566. $newimage = false;
  6567. // embed mask image
  6568. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6569. // embed image, masked with previously embedded mask
  6570. return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6571. }
  6572. }
  6573. }
  6574. if ($newimage) {
  6575. //First use of image, get info
  6576. $type = strtolower($type);
  6577. if ($type == '') {
  6578. $type = TCPDF_IMAGES::getImageFileType($file, $imsize);
  6579. } elseif ($type == 'jpg') {
  6580. $type = 'jpeg';
  6581. }
  6582. $mqr = TCPDF_STATIC::get_mqr();
  6583. TCPDF_STATIC::set_mqr(false);
  6584. // Specific image handlers (defined on TCPDF_IMAGES CLASS)
  6585. $mtd = '_parse'.$type;
  6586. // GD image handler function
  6587. $gdfunction = 'imagecreatefrom'.$type;
  6588. $info = false;
  6589. if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
  6590. // TCPDF image functions
  6591. $info = TCPDF_IMAGES::$mtd($file);
  6592. if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_imgmask_') === FALSE)
  6593. AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
  6594. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
  6595. }
  6596. }
  6597. if (($info === false) AND function_exists($gdfunction)) {
  6598. try {
  6599. // GD library
  6600. $img = @$gdfunction($file);
  6601. if ($img !== false) {
  6602. if ($resize) {
  6603. $imgr = imagecreatetruecolor($neww, $newh);
  6604. if (($type == 'gif') OR ($type == 'png')) {
  6605. $imgr = TCPDF_IMAGES::setGDImageTransparency($imgr, $img);
  6606. }
  6607. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  6608. if (($type == 'gif') OR ($type == 'png')) {
  6609. $info = TCPDF_IMAGES::_toPNG($imgr);
  6610. } else {
  6611. $info = TCPDF_IMAGES::_toJPEG($imgr, $this->jpeg_quality);
  6612. }
  6613. } else {
  6614. if (($type == 'gif') OR ($type == 'png')) {
  6615. $info = TCPDF_IMAGES::_toPNG($img);
  6616. } else {
  6617. $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality);
  6618. }
  6619. }
  6620. }
  6621. } catch(Exception $e) {
  6622. $info = false;
  6623. }
  6624. }
  6625. if (($info === false) AND extension_loaded('imagick')) {
  6626. try {
  6627. // ImageMagick library
  6628. $img = new Imagick();
  6629. if ($type == 'SVG') {
  6630. // get SVG file content
  6631. $svgimg = TCPDF_STATIC::fileGetContents($file);
  6632. if ($svgimg !== FALSE) {
  6633. // get width and height
  6634. $regs = array();
  6635. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
  6636. $svgtag = $regs[1];
  6637. $tmp = array();
  6638. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6639. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6640. $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit;
  6641. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
  6642. } else {
  6643. $ow = $w;
  6644. }
  6645. $tmp = array();
  6646. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
  6647. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  6648. $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit;
  6649. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
  6650. } else {
  6651. $oh = $h;
  6652. }
  6653. $tmp = array();
  6654. if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
  6655. $vbw = ($ow * $this->imgscale * $this->k);
  6656. $vbh = ($oh * $this->imgscale * $this->k);
  6657. $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
  6658. $svgtag = $vbox.$svgtag;
  6659. }
  6660. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
  6661. }
  6662. $img->readImageBlob($svgimg);
  6663. }
  6664. } else {
  6665. $img->readImage($file);
  6666. }
  6667. if ($resize) {
  6668. $img->resizeImage($neww, $newh, 10, 1, false);
  6669. }
  6670. $img->setCompressionQuality($this->jpeg_quality);
  6671. $img->setImageFormat('jpeg');
  6672. $tempname = TCPDF_STATIC::getObjFilename('img');
  6673. $img->writeImage($tempname);
  6674. $info = TCPDF_IMAGES::_parsejpeg($tempname);
  6675. unlink($tempname);
  6676. $img->destroy();
  6677. } catch(Exception $e) {
  6678. $info = false;
  6679. }
  6680. }
  6681. if ($info === false) {
  6682. // unable to process image
  6683. return;
  6684. }
  6685. TCPDF_STATIC::set_mqr($mqr);
  6686. if(is_array($info)) {
  6687. if ($ismask) {
  6688. // force grayscale
  6689. $info['cs'] = 'DeviceGray';
  6690. }
  6691. if ($imgmask !== false) {
  6692. $info['masked'] = $imgmask;
  6693. }
  6694. if (!empty($exurl)) {
  6695. $info['exurl'] = $exurl;
  6696. }
  6697. // array of alternative images
  6698. $info['altimgs'] = $altimgs;
  6699. // add image to document
  6700. $info['i'] = $this->setImageBuffer($file, $info);
  6701. }
  6702. }
  6703. // set alignment
  6704. $this->img_rb_y = $y + $h;
  6705. // set alignment
  6706. if ($this->rtl) {
  6707. if ($palign == 'L') {
  6708. $ximg = $this->lMargin;
  6709. } elseif ($palign == 'C') {
  6710. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6711. } elseif ($palign == 'R') {
  6712. $ximg = $this->w - $this->rMargin - $w;
  6713. } else {
  6714. $ximg = $x - $w;
  6715. }
  6716. $this->img_rb_x = $ximg;
  6717. } else {
  6718. if ($palign == 'L') {
  6719. $ximg = $this->lMargin;
  6720. } elseif ($palign == 'C') {
  6721. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  6722. } elseif ($palign == 'R') {
  6723. $ximg = $this->w - $this->rMargin - $w;
  6724. } else {
  6725. $ximg = $x;
  6726. }
  6727. $this->img_rb_x = $ximg + $w;
  6728. }
  6729. if ($ismask OR $hidden) {
  6730. // image is not displayed
  6731. return $info['i'];
  6732. }
  6733. $xkimg = $ximg * $this->k;
  6734. if (!$alt) {
  6735. // only non-alternative immages will be set
  6736. $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']));
  6737. }
  6738. if (!empty($border)) {
  6739. $bx = $this->x;
  6740. $by = $this->y;
  6741. $this->x = $ximg;
  6742. if ($this->rtl) {
  6743. $this->x += $w;
  6744. }
  6745. $this->y = $y;
  6746. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  6747. $this->x = $bx;
  6748. $this->y = $by;
  6749. }
  6750. if ($link) {
  6751. $this->Link($ximg, $y, $w, $h, $link, 0);
  6752. }
  6753. // set pointer to align the next text/objects
  6754. switch($align) {
  6755. case 'T': {
  6756. $this->y = $y;
  6757. $this->x = $this->img_rb_x;
  6758. break;
  6759. }
  6760. case 'M': {
  6761. $this->y = $y + round($h/2);
  6762. $this->x = $this->img_rb_x;
  6763. break;
  6764. }
  6765. case 'B': {
  6766. $this->y = $this->img_rb_y;
  6767. $this->x = $this->img_rb_x;
  6768. break;
  6769. }
  6770. case 'N': {
  6771. $this->SetY($this->img_rb_y);
  6772. break;
  6773. }
  6774. default:{
  6775. break;
  6776. }
  6777. }
  6778. $this->endlinex = $this->img_rb_x;
  6779. if ($this->inxobj) {
  6780. // we are inside an XObject template
  6781. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  6782. }
  6783. return $info['i'];
  6784. }
  6785. /**
  6786. * Extract info from a PNG image with alpha channel using the Imagick or GD library.
  6787. * @param $file (string) Name of the file containing the image.
  6788. * @param $x (float) Abscissa of the upper-left corner.
  6789. * @param $y (float) Ordinate of the upper-left corner.
  6790. * @param $wpx (float) Original width of the image in pixels.
  6791. * @param $hpx (float) original height of the image in pixels.
  6792. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6793. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  6794. * @param $type (string) 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.
  6795. * @param $link (mixed) URL or identifier returned by AddLink().
  6796. * @param $align (string) 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>
  6797. * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
  6798. * @param $dpi (int) dot-per-inch resolution used on resize
  6799. * @param $palign (string) 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>
  6800. * @param $filehash (string) File hash used to build unique file names.
  6801. * @author Nicola Asuni
  6802. * @protected
  6803. * @since 4.3.007 (2008-12-04)
  6804. * @see Image()
  6805. */
  6806. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
  6807. // create temp images
  6808. if (empty($filehash)) {
  6809. $filehash = md5($this->file_id.$file);
  6810. }
  6811. // create temp image file (without alpha channel)
  6812. $tempfile_plain = K_PATH_CACHE.'__tcpdf_imgmask_plain_'.$filehash;
  6813. // create temp alpha file
  6814. $tempfile_alpha = K_PATH_CACHE.'__tcpdf_imgmask_alpha_'.$filehash;
  6815. $parsed = false;
  6816. $parse_error = '';
  6817. // ImageMagick extension
  6818. if (($parsed === false) AND extension_loaded('imagick')) {
  6819. try {
  6820. // ImageMagick library
  6821. $img = new Imagick();
  6822. $img->readImage($file);
  6823. // clone image object
  6824. $imga = TCPDF_STATIC::objclone($img);
  6825. // extract alpha channel
  6826. if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
  6827. $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
  6828. } else {
  6829. $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
  6830. $img->negateImage(true);
  6831. }
  6832. $img->setImageFormat('png');
  6833. $img->writeImage($tempfile_alpha);
  6834. // remove alpha channel
  6835. if (method_exists($imga, 'setImageMatte')) {
  6836. $imga->setImageMatte(false);
  6837. } else {
  6838. $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
  6839. }
  6840. $imga->setImageFormat('png');
  6841. $imga->writeImage($tempfile_plain);
  6842. $parsed = true;
  6843. } catch (Exception $e) {
  6844. // Imagemagick fails, try with GD
  6845. $parse_error = 'Imagick library error: '.$e->getMessage();
  6846. }
  6847. }
  6848. // GD extension
  6849. if (($parsed === false) AND function_exists('imagecreatefrompng')) {
  6850. try {
  6851. // generate images
  6852. $img = imagecreatefrompng($file);
  6853. $imgalpha = imagecreate($wpx, $hpx);
  6854. // generate gray scale palette (0 -> 255)
  6855. for ($c = 0; $c < 256; ++$c) {
  6856. ImageColorAllocate($imgalpha, $c, $c, $c);
  6857. }
  6858. // extract alpha channel
  6859. for ($xpx = 0; $xpx < $wpx; ++$xpx) {
  6860. for ($ypx = 0; $ypx < $hpx; ++$ypx) {
  6861. $color = imagecolorat($img, $xpx, $ypx);
  6862. // get and correct gamma color
  6863. $alpha = $this->getGDgamma($img, $color);
  6864. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  6865. }
  6866. }
  6867. imagepng($imgalpha, $tempfile_alpha);
  6868. imagedestroy($imgalpha);
  6869. // extract image without alpha channel
  6870. $imgplain = imagecreatetruecolor($wpx, $hpx);
  6871. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  6872. imagepng($imgplain, $tempfile_plain);
  6873. imagedestroy($imgplain);
  6874. $parsed = true;
  6875. } catch (Exception $e) {
  6876. // GD fails
  6877. $parse_error = 'GD library error: '.$e->getMessage();
  6878. }
  6879. }
  6880. if ($parsed === false) {
  6881. if (empty($parse_error)) {
  6882. $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
  6883. } else {
  6884. $this->Error($parse_error);
  6885. }
  6886. }
  6887. // embed mask image
  6888. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  6889. // embed image, masked with previously embedded mask
  6890. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  6891. // remove temp files
  6892. unlink($tempfile_alpha);
  6893. unlink($tempfile_plain);
  6894. }
  6895. /**
  6896. * Get the GD-corrected PNG gamma value from alpha color
  6897. * @param $img (int) GD image Resource ID.
  6898. * @param $c (int) alpha color
  6899. * @protected
  6900. * @since 4.3.007 (2008-12-04)
  6901. */
  6902. protected function getGDgamma($img, $c) {
  6903. if (!isset($this->gdgammacache['#'.$c])) {
  6904. $colors = imagecolorsforindex($img, $c);
  6905. // GD alpha is only 7 bit (0 -> 127)
  6906. $this->gdgammacache['#'.$c] = (((127 - $colors['alpha']) / 127) * 255);
  6907. // correct gamma
  6908. $this->gdgammacache['#'.$c] = (pow(($this->gdgammacache['#'.$c] / 255), 2.2) * 255);
  6909. // store the latest values on cache to improve performances
  6910. if (count($this->gdgammacache) > 8) {
  6911. // remove one element from the cache array
  6912. array_shift($this->gdgammacache);
  6913. }
  6914. }
  6915. return $this->gdgammacache['#'.$c];
  6916. }
  6917. /**
  6918. * Performs a line break.
  6919. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  6920. * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
  6921. * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
  6922. * @public
  6923. * @since 1.0
  6924. * @see Cell()
  6925. */
  6926. public function Ln($h='', $cell=false) {
  6927. 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'])) {
  6928. // revove vertical space from the top of the column
  6929. return;
  6930. }
  6931. if ($cell) {
  6932. if ($this->rtl) {
  6933. $cellpadding = $this->cell_padding['R'];
  6934. } else {
  6935. $cellpadding = $this->cell_padding['L'];
  6936. }
  6937. } else {
  6938. $cellpadding = 0;
  6939. }
  6940. if ($this->rtl) {
  6941. $this->x = $this->w - $this->rMargin - $cellpadding;
  6942. } else {
  6943. $this->x = $this->lMargin + $cellpadding;
  6944. }
  6945. if (is_string($h)) {
  6946. $this->y += $this->lasth;
  6947. } else {
  6948. $this->y += $h;
  6949. }
  6950. $this->newline = true;
  6951. }
  6952. /**
  6953. * Returns the relative X value of current position.
  6954. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  6955. * @return float
  6956. * @public
  6957. * @since 1.2
  6958. * @see SetX(), GetY(), SetY()
  6959. */
  6960. public function GetX() {
  6961. //Get x position
  6962. if ($this->rtl) {
  6963. return ($this->w - $this->x);
  6964. } else {
  6965. return $this->x;
  6966. }
  6967. }
  6968. /**
  6969. * Returns the absolute X value of current position.
  6970. * @return float
  6971. * @public
  6972. * @since 1.2
  6973. * @see SetX(), GetY(), SetY()
  6974. */
  6975. public function GetAbsX() {
  6976. return $this->x;
  6977. }
  6978. /**
  6979. * Returns the ordinate of the current position.
  6980. * @return float
  6981. * @public
  6982. * @since 1.0
  6983. * @see SetY(), GetX(), SetX()
  6984. */
  6985. public function GetY() {
  6986. return $this->y;
  6987. }
  6988. /**
  6989. * Defines the abscissa of the current position.
  6990. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  6991. * @param $x (float) The value of the abscissa in user units.
  6992. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  6993. * @public
  6994. * @since 1.2
  6995. * @see GetX(), GetY(), SetY(), SetXY()
  6996. */
  6997. public function SetX($x, $rtloff=false) {
  6998. $x = floatval($x);
  6999. if (!$rtloff AND $this->rtl) {
  7000. if ($x >= 0) {
  7001. $this->x = $this->w - $x;
  7002. } else {
  7003. $this->x = abs($x);
  7004. }
  7005. } else {
  7006. if ($x >= 0) {
  7007. $this->x = $x;
  7008. } else {
  7009. $this->x = $this->w + $x;
  7010. }
  7011. }
  7012. if ($this->x < 0) {
  7013. $this->x = 0;
  7014. }
  7015. if ($this->x > $this->w) {
  7016. $this->x = $this->w;
  7017. }
  7018. }
  7019. /**
  7020. * Moves the current abscissa back to the left margin and sets the ordinate.
  7021. * If the passed value is negative, it is relative to the bottom of the page.
  7022. * @param $y (float) The value of the ordinate in user units.
  7023. * @param $resetx (bool) if true (default) reset the X position.
  7024. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7025. * @public
  7026. * @since 1.0
  7027. * @see GetX(), GetY(), SetY(), SetXY()
  7028. */
  7029. public function SetY($y, $resetx=true, $rtloff=false) {
  7030. $y = floatval($y);
  7031. if ($resetx) {
  7032. //reset x
  7033. if (!$rtloff AND $this->rtl) {
  7034. $this->x = $this->w - $this->rMargin;
  7035. } else {
  7036. $this->x = $this->lMargin;
  7037. }
  7038. }
  7039. if ($y >= 0) {
  7040. $this->y = $y;
  7041. } else {
  7042. $this->y = $this->h + $y;
  7043. }
  7044. if ($this->y < 0) {
  7045. $this->y = 0;
  7046. }
  7047. if ($this->y > $this->h) {
  7048. $this->y = $this->h;
  7049. }
  7050. }
  7051. /**
  7052. * Defines the abscissa and ordinate of the current position.
  7053. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  7054. * @param $x (float) The value of the abscissa.
  7055. * @param $y (float) The value of the ordinate.
  7056. * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
  7057. * @public
  7058. * @since 1.2
  7059. * @see SetX(), SetY()
  7060. */
  7061. public function SetXY($x, $y, $rtloff=false) {
  7062. $this->SetY($y, false, $rtloff);
  7063. $this->SetX($x, $rtloff);
  7064. }
  7065. /**
  7066. * Set the absolute X coordinate of the current pointer.
  7067. * @param $x (float) The value of the abscissa in user units.
  7068. * @public
  7069. * @since 5.9.186 (2012-09-13)
  7070. * @see setAbsX(), setAbsY(), SetAbsXY()
  7071. */
  7072. public function SetAbsX($x) {
  7073. $this->x = floatval($x);
  7074. }
  7075. /**
  7076. * Set the absolute Y coordinate of the current pointer.
  7077. * @param $y (float) (float) The value of the ordinate in user units.
  7078. * @public
  7079. * @since 5.9.186 (2012-09-13)
  7080. * @see setAbsX(), setAbsY(), SetAbsXY()
  7081. */
  7082. public function SetAbsY($y) {
  7083. $this->y = floatval($y);
  7084. }
  7085. /**
  7086. * Set the absolute X and Y coordinates of the current pointer.
  7087. * @param $x (float) The value of the abscissa in user units.
  7088. * @param $y (float) (float) The value of the ordinate in user units.
  7089. * @public
  7090. * @since 5.9.186 (2012-09-13)
  7091. * @see setAbsX(), setAbsY(), SetAbsXY()
  7092. */
  7093. public function SetAbsXY($x, $y) {
  7094. $this->SetAbsX($x);
  7095. $this->SetAbsY($y);
  7096. }
  7097. /**
  7098. * Send the document to a given destination: string, local file or browser.
  7099. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  7100. * The method first calls Close() if necessary to terminate the document.
  7101. * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  7102. * @param $dest (string) 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>
  7103. * @public
  7104. * @since 1.0
  7105. * @see Close()
  7106. */
  7107. public function Output($name='doc.pdf', $dest='I') {
  7108. //Output PDF to some destination
  7109. //Finish document if necessary
  7110. if ($this->state < 3) {
  7111. $this->Close();
  7112. }
  7113. //Normalize parameters
  7114. if (is_bool($dest)) {
  7115. $dest = $dest ? 'D' : 'F';
  7116. }
  7117. $dest = strtoupper($dest);
  7118. if ($dest{0} != 'F') {
  7119. $name = preg_replace('/[\s]+/', '_', $name);
  7120. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  7121. }
  7122. if ($this->sign) {
  7123. // *** apply digital signature to the document ***
  7124. // get the document content
  7125. $pdfdoc = $this->getBuffer();
  7126. // remove last newline
  7127. $pdfdoc = substr($pdfdoc, 0, -1);
  7128. // Remove the original buffer
  7129. if (isset($this->diskcache) AND $this->diskcache) {
  7130. // remove buffer file from cache
  7131. unlink($this->buffer);
  7132. }
  7133. unset($this->buffer);
  7134. // remove filler space
  7135. $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string);
  7136. // define the ByteRange
  7137. $byte_range = array();
  7138. $byte_range[0] = 0;
  7139. $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10;
  7140. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  7141. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  7142. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
  7143. // replace the ByteRange
  7144. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  7145. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  7146. $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc);
  7147. // write the document to a temporary folder
  7148. $tempdoc = TCPDF_STATIC::getObjFilename('doc');
  7149. $f = fopen($tempdoc, 'wb');
  7150. if (!$f) {
  7151. $this->Error('Unable to create temporary file: '.$tempdoc);
  7152. }
  7153. $pdfdoc_length = strlen($pdfdoc);
  7154. fwrite($f, $pdfdoc, $pdfdoc_length);
  7155. fclose($f);
  7156. // get digital signature via openssl library
  7157. $tempsign = TCPDF_STATIC::getObjFilename('sig');
  7158. if (empty($this->signature_data['extracerts'])) {
  7159. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  7160. } else {
  7161. 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']);
  7162. }
  7163. unlink($tempdoc);
  7164. // read signature
  7165. $signature = file_get_contents($tempsign);
  7166. unlink($tempsign);
  7167. // extract signature
  7168. $signature = substr($signature, $pdfdoc_length);
  7169. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  7170. $tmparr = explode("\n\n", $signature);
  7171. $signature = $tmparr[1];
  7172. unset($tmparr);
  7173. // decode signature
  7174. $signature = base64_decode(trim($signature));
  7175. // convert signature to hex
  7176. $signature = current(unpack('H*', $signature));
  7177. $signature = str_pad($signature, $this->signature_max_length, '0');
  7178. // disable disk caching
  7179. $this->diskcache = false;
  7180. // Add signature to the document
  7181. $this->buffer = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
  7182. $this->bufferlen = strlen($this->buffer);
  7183. }
  7184. switch($dest) {
  7185. case 'I': {
  7186. // Send PDF to the standard output
  7187. if (ob_get_contents()) {
  7188. $this->Error('Some data has already been output, can\'t send PDF file');
  7189. }
  7190. if (php_sapi_name() != 'cli') {
  7191. // send output to a browser
  7192. header('Content-Type: application/pdf');
  7193. if (headers_sent()) {
  7194. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7195. }
  7196. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7197. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7198. header('Pragma: public');
  7199. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7200. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7201. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7202. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7203. } else {
  7204. echo $this->getBuffer();
  7205. }
  7206. break;
  7207. }
  7208. case 'D': {
  7209. // download PDF as file
  7210. if (ob_get_contents()) {
  7211. $this->Error('Some data has already been output, can\'t send PDF file');
  7212. }
  7213. header('Content-Description: File Transfer');
  7214. if (headers_sent()) {
  7215. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7216. }
  7217. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7218. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7219. header('Pragma: public');
  7220. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7221. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7222. // force download dialog
  7223. if (strpos(php_sapi_name(), 'cgi') === false) {
  7224. header('Content-Type: application/force-download');
  7225. header('Content-Type: application/octet-stream', false);
  7226. header('Content-Type: application/download', false);
  7227. header('Content-Type: application/pdf', false);
  7228. } else {
  7229. header('Content-Type: application/pdf');
  7230. }
  7231. // use the Content-Disposition header to supply a recommended filename
  7232. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7233. header('Content-Transfer-Encoding: binary');
  7234. TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
  7235. break;
  7236. }
  7237. case 'F':
  7238. case 'FI':
  7239. case 'FD': {
  7240. // save PDF to a local file
  7241. if ($this->diskcache) {
  7242. copy($this->buffer, $name);
  7243. } else {
  7244. $f = fopen($name, 'wb');
  7245. if (!$f) {
  7246. $this->Error('Unable to create output file: '.$name);
  7247. }
  7248. fwrite($f, $this->getBuffer(), $this->bufferlen);
  7249. fclose($f);
  7250. }
  7251. if ($dest == 'FI') {
  7252. // send headers to browser
  7253. header('Content-Type: application/pdf');
  7254. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7255. //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  7256. header('Pragma: public');
  7257. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7258. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7259. header('Content-Disposition: inline; filename="'.basename($name).'"');
  7260. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7261. } elseif ($dest == 'FD') {
  7262. // send headers to browser
  7263. if (ob_get_contents()) {
  7264. $this->Error('Some data has already been output, can\'t send PDF file');
  7265. }
  7266. header('Content-Description: File Transfer');
  7267. if (headers_sent()) {
  7268. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  7269. }
  7270. header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
  7271. header('Pragma: public');
  7272. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  7273. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  7274. // force download dialog
  7275. if (strpos(php_sapi_name(), 'cgi') === false) {
  7276. header('Content-Type: application/force-download');
  7277. header('Content-Type: application/octet-stream', false);
  7278. header('Content-Type: application/download', false);
  7279. header('Content-Type: application/pdf', false);
  7280. } else {
  7281. header('Content-Type: application/pdf');
  7282. }
  7283. // use the Content-Disposition header to supply a recommended filename
  7284. header('Content-Disposition: attachment; filename="'.basename($name).'"');
  7285. header('Content-Transfer-Encoding: binary');
  7286. TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name));
  7287. }
  7288. break;
  7289. }
  7290. case 'E': {
  7291. // return PDF as base64 mime multi-part email attachment (RFC 2045)
  7292. $retval = 'Content-Type: application/pdf;'."\r\n";
  7293. $retval .= ' name="'.$name.'"'."\r\n";
  7294. $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
  7295. $retval .= 'Content-Disposition: attachment;'."\r\n";
  7296. $retval .= ' filename="'.$name.'"'."\r\n\r\n";
  7297. $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
  7298. return $retval;
  7299. }
  7300. case 'S': {
  7301. // returns PDF as a string
  7302. return $this->getBuffer();
  7303. }
  7304. default: {
  7305. $this->Error('Incorrect output destination: '.$dest);
  7306. }
  7307. }
  7308. return '';
  7309. }
  7310. /**
  7311. * Unset all class variables except the following critical variables.
  7312. * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
  7313. * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
  7314. * @public
  7315. * @since 4.5.016 (2009-02-24)
  7316. */
  7317. public function _destroy($destroyall=false, $preserve_objcopy=false) {
  7318. if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!TCPDF_STATIC::empty_string($this->buffer))) {
  7319. // remove buffer file from cache
  7320. unlink($this->buffer);
  7321. }
  7322. if ($destroyall AND isset($this->cached_files) AND !empty($this->cached_files)) {
  7323. // remove cached files
  7324. foreach ($this->cached_files as $cachefile) {
  7325. if (is_file($cachefile)) {
  7326. unlink($cachefile);
  7327. }
  7328. }
  7329. unset($this->cached_files);
  7330. }
  7331. foreach (array_keys(get_object_vars($this)) as $val) {
  7332. if ($destroyall OR (
  7333. ($val != 'internal_encoding')
  7334. AND ($val != 'state')
  7335. AND ($val != 'bufferlen')
  7336. AND ($val != 'buffer')
  7337. AND ($val != 'diskcache')
  7338. AND ($val != 'cached_files')
  7339. AND ($val != 'sign')
  7340. AND ($val != 'signature_data')
  7341. AND ($val != 'signature_max_length')
  7342. AND ($val != 'byterange_string')
  7343. )) {
  7344. if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
  7345. unset($this->$val);
  7346. }
  7347. }
  7348. }
  7349. }
  7350. /**
  7351. * Check for locale-related bug
  7352. * @protected
  7353. */
  7354. protected function _dochecks() {
  7355. //Check for locale-related bug
  7356. if (1.1 == 1) {
  7357. $this->Error('Don\'t alter the locale before including class file');
  7358. }
  7359. //Check for decimal separator
  7360. if (sprintf('%.1F', 1.0) != '1.0') {
  7361. setlocale(LC_NUMERIC, 'C');
  7362. }
  7363. }
  7364. /**
  7365. * Return an array containing variations for the basic page number alias.
  7366. * @param $a (string) Base alias.
  7367. * @return array of page number aliases
  7368. * @protected
  7369. */
  7370. protected function getInternalPageNumberAliases($a= '') {
  7371. $alias = array();
  7372. // build array of Unicode + ASCII variants (the order is important)
  7373. $alias = array('u' => array(), 'a' => array());
  7374. $u = '{'.$a.'}';
  7375. $alias['u'][] = TCPDF_STATIC::_escape($u);
  7376. if ($this->isunicode) {
  7377. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($u, $this->isunicode, $this->CurrentFont));
  7378. $alias['u'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($u, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7379. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::UTF8ToLatin1($a, $this->isunicode, $this->CurrentFont));
  7380. $alias['a'][] = TCPDF_STATIC::_escape(TCPDF_FONTS::utf8StrRev($a, false, $this->tmprtl, $this->isunicode, $this->CurrentFont));
  7381. }
  7382. $alias['a'][] = TCPDF_STATIC::_escape($a);
  7383. return $alias;
  7384. }
  7385. /**
  7386. * Return an array containing all internal page aliases.
  7387. * @return array of page number aliases
  7388. * @protected
  7389. */
  7390. protected function getAllInternalPageNumberAliases() {
  7391. $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);
  7392. $pnalias = array();
  7393. foreach($basic_alias as $k => $a) {
  7394. $pnalias[$k] = $this->getInternalPageNumberAliases($a);
  7395. }
  7396. return $pnalias;
  7397. }
  7398. /**
  7399. * Replace right shift page number aliases with spaces to correct right alignment.
  7400. * This works perfectly only when using monospaced fonts.
  7401. * @param $page (string) Page content.
  7402. * @param $aliases (array) Array of page aliases.
  7403. * @param $diff (int) initial difference to add.
  7404. * @return replaced page content.
  7405. * @protected
  7406. */
  7407. protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
  7408. foreach ($aliases as $type => $alias) {
  7409. foreach ($alias as $a) {
  7410. // find position of compensation factor
  7411. $startnum = (strpos($a, ':') + 1);
  7412. $a = substr($a, 0, $startnum);
  7413. if (($pos = strpos($page, $a)) !== false) {
  7414. // end of alias
  7415. $endnum = strpos($page, '}', $pos);
  7416. // string to be replaced
  7417. $aa = substr($page, $pos, ($endnum - $pos + 1));
  7418. // get compensation factor
  7419. $ratio = substr($page, ($pos + $startnum), ($endnum - $pos - $startnum));
  7420. $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
  7421. $ratio = floatval($ratio);
  7422. if ($type == 'u') {
  7423. $chrdiff = floor(($diff + 12) * $ratio);
  7424. $shift = str_repeat(' ', $chrdiff);
  7425. $shift = TCPDF_FONTS::UTF8ToUTF16BE($shift, false, $this->isunicode, $this->CurrentFont);
  7426. } else {
  7427. $chrdiff = floor(($diff + 11) * $ratio);
  7428. $shift = str_repeat(' ', $chrdiff);
  7429. }
  7430. $page = str_replace($aa, $shift, $page);
  7431. }
  7432. }
  7433. }
  7434. return $page;
  7435. }
  7436. /**
  7437. * Set page boxes to be included on page descriptions.
  7438. * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
  7439. * @protected
  7440. */
  7441. protected function setPageBoxTypes($boxes) {
  7442. $this->page_boxes = array();
  7443. foreach ($boxes as $box) {
  7444. if (in_array($box, TCPDF_STATIC::$pageboxes)) {
  7445. $this->page_boxes[] = $box;
  7446. }
  7447. }
  7448. }
  7449. /**
  7450. * Output pages (and replace page number aliases).
  7451. * @protected
  7452. */
  7453. protected function _putpages() {
  7454. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  7455. // get internal aliases for page numbers
  7456. $pnalias = $this->getAllInternalPageNumberAliases();
  7457. $num_pages = $this->numpages;
  7458. $ptpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $num_pages - 1));
  7459. $ptpu = TCPDF_FONTS::UTF8ToUTF16BE($ptpa, false, $this->isunicode, $this->CurrentFont);
  7460. $ptp_num_chars = $this->GetNumChars($ptpa);
  7461. $pagegroupnum = 0;
  7462. $groupnum = 0;
  7463. $ptgu = 1;
  7464. $ptga = 1;
  7465. $ptg_num_chars = 1;
  7466. for ($n = 1; $n <= $num_pages; ++$n) {
  7467. // get current page
  7468. $temppage = $this->getPageBuffer($n);
  7469. $pagelen = strlen($temppage);
  7470. // set replacements for total pages number
  7471. $pnpa = TCPDF_STATIC::formatPageNumber(($this->starting_page_number + $n - 1));
  7472. $pnpu = TCPDF_FONTS::UTF8ToUTF16BE($pnpa, false, $this->isunicode, $this->CurrentFont);
  7473. $pnp_num_chars = $this->GetNumChars($pnpa);
  7474. $pdiff = 0; // difference used for right shift alignment of page numbers
  7475. $gdiff = 0; // difference used for right shift alignment of page group numbers
  7476. if (!empty($this->pagegroups)) {
  7477. if (isset($this->newpagegroup[$n])) {
  7478. $pagegroupnum = 0;
  7479. ++$groupnum;
  7480. $ptga = TCPDF_STATIC::formatPageNumber($this->pagegroups[$groupnum]);
  7481. $ptgu = TCPDF_FONTS::UTF8ToUTF16BE($ptga, false, $this->isunicode, $this->CurrentFont);
  7482. $ptg_num_chars = $this->GetNumChars($ptga);
  7483. }
  7484. ++$pagegroupnum;
  7485. $pnga = TCPDF_STATIC::formatPageNumber($pagegroupnum);
  7486. $pngu = TCPDF_FONTS::UTF8ToUTF16BE($pnga, false, $this->isunicode, $this->CurrentFont);
  7487. $png_num_chars = $this->GetNumChars($pnga);
  7488. // replace page numbers
  7489. $replace = array();
  7490. $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
  7491. $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
  7492. $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
  7493. $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
  7494. list($temppage, $gdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $gdiff);
  7495. }
  7496. // replace page numbers
  7497. $replace = array();
  7498. $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
  7499. $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
  7500. $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
  7501. $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
  7502. list($temppage, $pdiff) = TCPDF_STATIC::replacePageNumAliases($temppage, $replace, $pdiff);
  7503. // replace right shift alias
  7504. $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
  7505. // replace EPS marker
  7506. $temppage = str_replace($this->epsmarker, '', $temppage);
  7507. //Page
  7508. $this->page_obj_id[$n] = $this->_newobj();
  7509. $out = '<<';
  7510. $out .= ' /Type /Page';
  7511. $out .= ' /Parent 1 0 R';
  7512. $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp);
  7513. $out .= ' /Resources 2 0 R';
  7514. foreach ($this->page_boxes as $box) {
  7515. $out .= ' /'.$box;
  7516. $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']);
  7517. }
  7518. if (isset($this->pagedim[$n]['BoxColorInfo']) AND !empty($this->pagedim[$n]['BoxColorInfo'])) {
  7519. $out .= ' /BoxColorInfo <<';
  7520. foreach ($this->page_boxes as $box) {
  7521. if (isset($this->pagedim[$n]['BoxColorInfo'][$box])) {
  7522. $out .= ' /'.$box.' <<';
  7523. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C'])) {
  7524. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  7525. $out .= ' /C [';
  7526. $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  7527. $out .= ' ]';
  7528. }
  7529. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W'])) {
  7530. $out .= ' /W '.($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  7531. }
  7532. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S'])) {
  7533. $out .= ' /S /'.$this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  7534. }
  7535. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D'])) {
  7536. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  7537. $out .= ' /D [';
  7538. foreach ($dashes as $dash) {
  7539. $out .= sprintf(' %F', ($dash * $this->k));
  7540. }
  7541. $out .= ' ]';
  7542. }
  7543. $out .= ' >>';
  7544. }
  7545. }
  7546. $out .= ' >>';
  7547. }
  7548. $out .= ' /Contents '.($this->n + 1).' 0 R';
  7549. $out .= ' /Rotate '.$this->pagedim[$n]['Rotate'];
  7550. if (!$this->pdfa_mode) {
  7551. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  7552. }
  7553. if (isset($this->pagedim[$n]['trans']) AND !empty($this->pagedim[$n]['trans'])) {
  7554. // page transitions
  7555. if (isset($this->pagedim[$n]['trans']['Dur'])) {
  7556. $out .= ' /Dur '.$this->pagedim[$n]['trans']['Dur'];
  7557. }
  7558. $out .= ' /Trans <<';
  7559. $out .= ' /Type /Trans';
  7560. if (isset($this->pagedim[$n]['trans']['S'])) {
  7561. $out .= ' /S /'.$this->pagedim[$n]['trans']['S'];
  7562. }
  7563. if (isset($this->pagedim[$n]['trans']['D'])) {
  7564. $out .= ' /D '.$this->pagedim[$n]['trans']['D'];
  7565. }
  7566. if (isset($this->pagedim[$n]['trans']['Dm'])) {
  7567. $out .= ' /Dm /'.$this->pagedim[$n]['trans']['Dm'];
  7568. }
  7569. if (isset($this->pagedim[$n]['trans']['M'])) {
  7570. $out .= ' /M /'.$this->pagedim[$n]['trans']['M'];
  7571. }
  7572. if (isset($this->pagedim[$n]['trans']['Di'])) {
  7573. $out .= ' /Di '.$this->pagedim[$n]['trans']['Di'];
  7574. }
  7575. if (isset($this->pagedim[$n]['trans']['SS'])) {
  7576. $out .= ' /SS '.$this->pagedim[$n]['trans']['SS'];
  7577. }
  7578. if (isset($this->pagedim[$n]['trans']['B'])) {
  7579. $out .= ' /B '.$this->pagedim[$n]['trans']['B'];
  7580. }
  7581. $out .= ' >>';
  7582. }
  7583. $out .= $this->_getannotsrefs($n);
  7584. $out .= ' /PZ '.$this->pagedim[$n]['PZ'];
  7585. $out .= ' >>';
  7586. $out .= "\n".'endobj';
  7587. $this->_out($out);
  7588. //Page content
  7589. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  7590. $this->_newobj();
  7591. $p = $this->_getrawstream($p);
  7592. $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
  7593. if ($this->diskcache) {
  7594. // remove temporary files
  7595. unlink($this->pages[$n]);
  7596. }
  7597. }
  7598. //Pages root
  7599. $out = $this->_getobj(1)."\n";
  7600. $out .= '<< /Type /Pages /Kids [';
  7601. foreach($this->page_obj_id as $page_obj) {
  7602. $out .= ' '.$page_obj.' 0 R';
  7603. }
  7604. $out .= ' ] /Count '.$num_pages.' >>';
  7605. $out .= "\n".'endobj';
  7606. $this->_out($out);
  7607. }
  7608. /**
  7609. * Output references to page annotations
  7610. * @param $n (int) page number
  7611. * @protected
  7612. * @author Nicola Asuni
  7613. * @since 4.7.000 (2008-08-29)
  7614. * @deprecated
  7615. */
  7616. protected function _putannotsrefs($n) {
  7617. $this->_out($this->_getannotsrefs($n));
  7618. }
  7619. /**
  7620. * Get references to page annotations.
  7621. * @param $n (int) page number
  7622. * @return string
  7623. * @protected
  7624. * @author Nicola Asuni
  7625. * @since 5.0.010 (2010-05-17)
  7626. */
  7627. protected function _getannotsrefs($n) {
  7628. if (!(isset($this->PageAnnots[$n]) OR ($this->sign AND isset($this->signature_data['cert_type'])))) {
  7629. return '';
  7630. }
  7631. $out = ' /Annots [';
  7632. if (isset($this->PageAnnots[$n])) {
  7633. foreach ($this->PageAnnots[$n] as $key => $val) {
  7634. if (!in_array($val['n'], $this->radio_groups)) {
  7635. $out .= ' '.$val['n'].' 0 R';
  7636. }
  7637. }
  7638. // add radiobutton groups
  7639. if (isset($this->radiobutton_groups[$n])) {
  7640. foreach ($this->radiobutton_groups[$n] as $key => $data) {
  7641. if (isset($data['n'])) {
  7642. $out .= ' '.$data['n'].' 0 R';
  7643. }
  7644. }
  7645. }
  7646. }
  7647. if ($this->sign AND ($n == $this->signature_appearance['page']) AND isset($this->signature_data['cert_type'])) {
  7648. // set reference for signature object
  7649. $out .= ' '.$this->sig_obj_id.' 0 R';
  7650. }
  7651. if (!empty($this->empty_signature_appearance)) {
  7652. foreach ($this->empty_signature_appearance as $esa) {
  7653. if ($esa['page'] == $n) {
  7654. // set reference for empty signature objects
  7655. $out .= ' '.$esa['objid'].' 0 R';
  7656. }
  7657. }
  7658. }
  7659. $out .= ' ]';
  7660. return $out;
  7661. }
  7662. /**
  7663. * Output annotations objects for all pages.
  7664. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  7665. * See section 12.5 of PDF 32000_2008 reference.
  7666. * @protected
  7667. * @author Nicola Asuni
  7668. * @since 4.0.018 (2008-08-06)
  7669. */
  7670. protected function _putannotsobjs() {
  7671. // reset object counter
  7672. for ($n=1; $n <= $this->numpages; ++$n) {
  7673. if (isset($this->PageAnnots[$n])) {
  7674. // set page annotations
  7675. foreach ($this->PageAnnots[$n] as $key => $pl) {
  7676. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  7677. // create annotation object for grouping radiobuttons
  7678. if (isset($this->radiobutton_groups[$n][$pl['txt']]) AND is_array($this->radiobutton_groups[$n][$pl['txt']])) {
  7679. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  7680. $annots = '<<';
  7681. $annots .= ' /Type /Annot';
  7682. $annots .= ' /Subtype /Widget';
  7683. $annots .= ' /Rect [0 0 0 0]';
  7684. if ($this->radiobutton_groups[$n][$pl['txt']]['#readonly#']) {
  7685. // read only
  7686. $annots .= ' /F 68';
  7687. $annots .= ' /Ff 49153';
  7688. } else {
  7689. $annots .= ' /F 4'; // default print for PDF/A
  7690. $annots .= ' /Ff 49152';
  7691. }
  7692. $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
  7693. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  7694. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
  7695. }
  7696. $annots .= ' /FT /Btn';
  7697. $annots .= ' /Kids [';
  7698. $defval = '';
  7699. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data) {
  7700. if (isset($data['kid'])) {
  7701. $annots .= ' '.$data['kid'].' 0 R';
  7702. if ($data['def'] !== 'Off') {
  7703. $defval = $data['def'];
  7704. }
  7705. }
  7706. }
  7707. $annots .= ' ]';
  7708. if (!empty($defval)) {
  7709. $annots .= ' /V /'.$defval;
  7710. }
  7711. $annots .= ' >>';
  7712. $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
  7713. $this->form_obj_id[] = $radio_button_obj_id;
  7714. // store object id to be used on Parent entry of Kids
  7715. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  7716. }
  7717. $formfield = false;
  7718. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  7719. $a = $pl['x'] * $this->k;
  7720. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  7721. $c = $pl['w'] * $this->k;
  7722. $d = $pl['h'] * $this->k;
  7723. $rect = sprintf('%F %F %F %F', $a, $b, $a+$c, $b+$d);
  7724. // create new annotation object
  7725. $annots = '<</Type /Annot';
  7726. $annots .= ' /Subtype /'.$pl['opt']['subtype'];
  7727. $annots .= ' /Rect ['.$rect.']';
  7728. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  7729. if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
  7730. $annots .= ' /FT /'.$pl['opt']['ft'];
  7731. $formfield = true;
  7732. }
  7733. $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
  7734. $annots .= ' /P '.$this->page_obj_id[$n].' 0 R';
  7735. $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  7736. $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp);
  7737. if (isset($pl['opt']['f'])) {
  7738. $fval = 0;
  7739. if (is_array($pl['opt']['f'])) {
  7740. foreach ($pl['opt']['f'] as $f) {
  7741. switch (strtolower($f)) {
  7742. case 'invisible': {
  7743. $fval += 1 << 0;
  7744. break;
  7745. }
  7746. case 'hidden': {
  7747. $fval += 1 << 1;
  7748. break;
  7749. }
  7750. case 'print': {
  7751. $fval += 1 << 2;
  7752. break;
  7753. }
  7754. case 'nozoom': {
  7755. $fval += 1 << 3;
  7756. break;
  7757. }
  7758. case 'norotate': {
  7759. $fval += 1 << 4;
  7760. break;
  7761. }
  7762. case 'noview': {
  7763. $fval += 1 << 5;
  7764. break;
  7765. }
  7766. case 'readonly': {
  7767. $fval += 1 << 6;
  7768. break;
  7769. }
  7770. case 'locked': {
  7771. $fval += 1 << 8;
  7772. break;
  7773. }
  7774. case 'togglenoview': {
  7775. $fval += 1 << 9;
  7776. break;
  7777. }
  7778. case 'lockedcontents': {
  7779. $fval += 1 << 10;
  7780. break;
  7781. }
  7782. default: {
  7783. break;
  7784. }
  7785. }
  7786. }
  7787. } else {
  7788. $fval = intval($pl['opt']['f']);
  7789. }
  7790. } else {
  7791. $fval = 4;
  7792. }
  7793. if ($this->pdfa_mode) {
  7794. // force print flag for PDF/A mode
  7795. $fval |= 4;
  7796. }
  7797. $annots .= ' /F '.intval($fval);
  7798. if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
  7799. $annots .= ' /AS /'.$pl['opt']['as'];
  7800. }
  7801. if (isset($pl['opt']['ap'])) {
  7802. // appearance stream
  7803. $annots .= ' /AP <<';
  7804. if (is_array($pl['opt']['ap'])) {
  7805. foreach ($pl['opt']['ap'] as $apmode => $apdef) {
  7806. // $apmode can be: n = normal; r = rollover; d = down;
  7807. $annots .= ' /'.strtoupper($apmode);
  7808. if (is_array($apdef)) {
  7809. $annots .= ' <<';
  7810. foreach ($apdef as $apstate => $stream) {
  7811. // reference to XObject that define the appearance for this mode-state
  7812. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  7813. $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
  7814. }
  7815. $annots .= ' >>';
  7816. } else {
  7817. // reference to XObject that define the appearance for this mode
  7818. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  7819. $annots .= ' '.$apsobjid.' 0 R';
  7820. }
  7821. }
  7822. } else {
  7823. $annots .= $pl['opt']['ap'];
  7824. }
  7825. $annots .= ' >>';
  7826. }
  7827. if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
  7828. $annots .= ' /BS <<';
  7829. $annots .= ' /Type /Border';
  7830. if (isset($pl['opt']['bs']['w'])) {
  7831. $annots .= ' /W '.intval($pl['opt']['bs']['w']);
  7832. }
  7833. $bstyles = array('S', 'D', 'B', 'I', 'U');
  7834. if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
  7835. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7836. }
  7837. if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
  7838. $annots .= ' /D [';
  7839. foreach ($pl['opt']['bs']['d'] as $cord) {
  7840. $annots .= ' '.intval($cord);
  7841. }
  7842. $annots .= ']';
  7843. }
  7844. $annots .= ' >>';
  7845. } else {
  7846. $annots .= ' /Border [';
  7847. if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
  7848. $annots .= intval($pl['opt']['border'][0]).' ';
  7849. $annots .= intval($pl['opt']['border'][1]).' ';
  7850. $annots .= intval($pl['opt']['border'][2]);
  7851. if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
  7852. $annots .= ' [';
  7853. foreach ($pl['opt']['border'][3] as $dash) {
  7854. $annots .= intval($dash).' ';
  7855. }
  7856. $annots .= ']';
  7857. }
  7858. } else {
  7859. $annots .= '0 0 0';
  7860. }
  7861. $annots .= ']';
  7862. }
  7863. if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
  7864. $annots .= ' /BE <<';
  7865. $bstyles = array('S', 'C');
  7866. if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
  7867. $annots .= ' /S /'.$pl['opt']['bs']['s'];
  7868. } else {
  7869. $annots .= ' /S /S';
  7870. }
  7871. if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
  7872. $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
  7873. }
  7874. $annots .= '>>';
  7875. }
  7876. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
  7877. $annots .= ' /C '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['c']);
  7878. }
  7879. //$annots .= ' /StructParent ';
  7880. //$annots .= ' /OC ';
  7881. $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
  7882. if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
  7883. // this is a markup type
  7884. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  7885. $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
  7886. }
  7887. //$annots .= ' /Popup ';
  7888. if (isset($pl['opt']['ca'])) {
  7889. $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
  7890. }
  7891. if (isset($pl['opt']['rc'])) {
  7892. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  7893. }
  7894. $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp);
  7895. //$annots .= ' /IRT ';
  7896. if (isset($pl['opt']['subj'])) {
  7897. $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
  7898. }
  7899. //$annots .= ' /RT ';
  7900. //$annots .= ' /IT ';
  7901. //$annots .= ' /ExData ';
  7902. }
  7903. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
  7904. // Annotation types
  7905. switch (strtolower($pl['opt']['subtype'])) {
  7906. case 'text': {
  7907. if (isset($pl['opt']['open'])) {
  7908. $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  7909. }
  7910. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  7911. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  7912. $annots .= ' /Name /'.$pl['opt']['name'];
  7913. } else {
  7914. $annots .= ' /Name /Note';
  7915. }
  7916. $statemodels = array('Marked', 'Review');
  7917. if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
  7918. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  7919. } else {
  7920. $pl['opt']['statemodel'] = 'Marked';
  7921. $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
  7922. }
  7923. if ($pl['opt']['statemodel'] == 'Marked') {
  7924. $states = array('Accepted', 'Unmarked');
  7925. } else {
  7926. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  7927. }
  7928. if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
  7929. $annots .= ' /State /'.$pl['opt']['state'];
  7930. } else {
  7931. if ($pl['opt']['statemodel'] == 'Marked') {
  7932. $annots .= ' /State /Unmarked';
  7933. } else {
  7934. $annots .= ' /State /None';
  7935. }
  7936. }
  7937. break;
  7938. }
  7939. case 'link': {
  7940. if (is_string($pl['txt'])) {
  7941. if ($pl['txt'][0] == '#') {
  7942. // internal destination
  7943. $annots .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($pl['txt'], 1));
  7944. } elseif ($pl['txt'][0] == '%') {
  7945. // embedded PDF file
  7946. $filename = basename(substr($pl['txt'], 1));
  7947. $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  7948. } elseif ($pl['txt'][0] == '*') {
  7949. // embedded generic file
  7950. $filename = basename(substr($pl['txt'], 1));
  7951. $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});';
  7952. $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
  7953. } else {
  7954. // external URI link
  7955. $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
  7956. }
  7957. } elseif (isset($this->links[$pl['txt']])) {
  7958. // internal link ID
  7959. $l = $this->links[$pl['txt']];
  7960. if (isset($this->page_obj_id[($l[0])])) {
  7961. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  7962. }
  7963. }
  7964. $hmodes = array('N', 'I', 'O', 'P');
  7965. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
  7966. $annots .= ' /H /'.$pl['opt']['h'];
  7967. } else {
  7968. $annots .= ' /H /I';
  7969. }
  7970. //$annots .= ' /PA ';
  7971. //$annots .= ' /Quadpoints ';
  7972. break;
  7973. }
  7974. case 'freetext': {
  7975. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  7976. $annots .= ' /DA ('.$pl['opt']['da'].')';
  7977. }
  7978. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  7979. $annots .= ' /Q '.intval($pl['opt']['q']);
  7980. }
  7981. if (isset($pl['opt']['rc'])) {
  7982. $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
  7983. }
  7984. if (isset($pl['opt']['ds'])) {
  7985. $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
  7986. }
  7987. if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
  7988. $annots .= ' /CL [';
  7989. foreach ($pl['opt']['cl'] as $cl) {
  7990. $annots .= sprintf('%F ', $cl * $this->k);
  7991. }
  7992. $annots .= ']';
  7993. }
  7994. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  7995. if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
  7996. $annots .= ' /IT /'.$pl['opt']['it'];
  7997. }
  7998. if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
  7999. $l = $pl['opt']['rd'][0] * $this->k;
  8000. $r = $pl['opt']['rd'][1] * $this->k;
  8001. $t = $pl['opt']['rd'][2] * $this->k;
  8002. $b = $pl['opt']['rd'][3] * $this->k;
  8003. $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
  8004. }
  8005. if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
  8006. $annots .= ' /LE /'.$pl['opt']['le'];
  8007. }
  8008. break;
  8009. }
  8010. case 'line': {
  8011. break;
  8012. }
  8013. case 'square': {
  8014. break;
  8015. }
  8016. case 'circle': {
  8017. break;
  8018. }
  8019. case 'polygon': {
  8020. break;
  8021. }
  8022. case 'polyline': {
  8023. break;
  8024. }
  8025. case 'highlight': {
  8026. break;
  8027. }
  8028. case 'underline': {
  8029. break;
  8030. }
  8031. case 'squiggly': {
  8032. break;
  8033. }
  8034. case 'strikeout': {
  8035. break;
  8036. }
  8037. case 'stamp': {
  8038. break;
  8039. }
  8040. case 'caret': {
  8041. break;
  8042. }
  8043. case 'ink': {
  8044. break;
  8045. }
  8046. case 'popup': {
  8047. break;
  8048. }
  8049. case 'fileattachment': {
  8050. if ($this->pdfa_mode) {
  8051. // embedded files are not allowed in PDF/A mode
  8052. break;
  8053. }
  8054. if (!isset($pl['opt']['fs'])) {
  8055. break;
  8056. }
  8057. $filename = basename($pl['opt']['fs']);
  8058. if (isset($this->embeddedfiles[$filename]['f'])) {
  8059. $annots .= ' /FS '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8060. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  8061. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8062. $annots .= ' /Name /'.$pl['opt']['name'];
  8063. } else {
  8064. $annots .= ' /Name /PushPin';
  8065. }
  8066. // index (zero-based) of the annotation in the Annots array of this page
  8067. $this->embeddedfiles[$filename]['a'] = $key;
  8068. }
  8069. break;
  8070. }
  8071. case 'sound': {
  8072. if (!isset($pl['opt']['fs'])) {
  8073. break;
  8074. }
  8075. $filename = basename($pl['opt']['fs']);
  8076. if (isset($this->embeddedfiles[$filename]['f'])) {
  8077. // ... TO BE COMPLETED ...
  8078. // /R /C /B /E /CO /CP
  8079. $annots .= ' /Sound '.$this->embeddedfiles[$filename]['f'].' 0 R';
  8080. $iconsapp = array('Speaker', 'Mic');
  8081. if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
  8082. $annots .= ' /Name /'.$pl['opt']['name'];
  8083. } else {
  8084. $annots .= ' /Name /Speaker';
  8085. }
  8086. }
  8087. break;
  8088. }
  8089. case 'movie': {
  8090. break;
  8091. }
  8092. case 'widget': {
  8093. $hmode = array('N', 'I', 'O', 'P', 'T');
  8094. if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
  8095. $annots .= ' /H /'.$pl['opt']['h'];
  8096. }
  8097. if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
  8098. $annots .= ' /MK <<';
  8099. if (isset($pl['opt']['mk']['r'])) {
  8100. $annots .= ' /R '.$pl['opt']['mk']['r'];
  8101. }
  8102. if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
  8103. $annots .= ' /BC '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bc']);
  8104. }
  8105. if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
  8106. $annots .= ' /BG '.TCPDF_COLORS::getColorStringFromArray($pl['opt']['mk']['bg']);
  8107. }
  8108. if (isset($pl['opt']['mk']['ca'])) {
  8109. $annots .= ' /CA '.$pl['opt']['mk']['ca'];
  8110. }
  8111. if (isset($pl['opt']['mk']['rc'])) {
  8112. $annots .= ' /RC '.$pl['opt']['mk']['rc'];
  8113. }
  8114. if (isset($pl['opt']['mk']['ac'])) {
  8115. $annots .= ' /AC '.$pl['opt']['mk']['ac'];
  8116. }
  8117. if (isset($pl['opt']['mk']['i'])) {
  8118. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  8119. if ($info !== false) {
  8120. $annots .= ' /I '.$info['n'].' 0 R';
  8121. }
  8122. }
  8123. if (isset($pl['opt']['mk']['ri'])) {
  8124. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  8125. if ($info !== false) {
  8126. $annots .= ' /RI '.$info['n'].' 0 R';
  8127. }
  8128. }
  8129. if (isset($pl['opt']['mk']['ix'])) {
  8130. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  8131. if ($info !== false) {
  8132. $annots .= ' /IX '.$info['n'].' 0 R';
  8133. }
  8134. }
  8135. if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
  8136. $annots .= ' /IF <<';
  8137. $if_sw = array('A', 'B', 'S', 'N');
  8138. if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
  8139. $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
  8140. }
  8141. $if_s = array('A', 'P');
  8142. if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
  8143. $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
  8144. }
  8145. if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
  8146. $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  8147. }
  8148. if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
  8149. $annots .= ' /FB true';
  8150. }
  8151. $annots .= '>>';
  8152. }
  8153. if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
  8154. $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
  8155. }
  8156. $annots .= '>>';
  8157. } // end MK
  8158. // --- Entries for field dictionaries ---
  8159. if (isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8160. // set parent
  8161. $annots .= ' /Parent '.$this->radiobutton_groups[$n][$pl['txt']].' 0 R';
  8162. }
  8163. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  8164. $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
  8165. }
  8166. if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
  8167. $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
  8168. }
  8169. if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
  8170. $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
  8171. }
  8172. if (isset($pl['opt']['ff'])) {
  8173. if (is_array($pl['opt']['ff'])) {
  8174. // array of bit settings
  8175. $flag = 0;
  8176. foreach($pl['opt']['ff'] as $val) {
  8177. $flag += 1 << ($val - 1);
  8178. }
  8179. } else {
  8180. $flag = intval($pl['opt']['ff']);
  8181. }
  8182. $annots .= ' /Ff '.$flag;
  8183. }
  8184. if (isset($pl['opt']['maxlen'])) {
  8185. $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
  8186. }
  8187. if (isset($pl['opt']['v'])) {
  8188. $annots .= ' /V';
  8189. if (is_array($pl['opt']['v'])) {
  8190. foreach ($pl['opt']['v'] AS $optval) {
  8191. if (is_float($optval)) {
  8192. $optval = sprintf('%F', $optval);
  8193. }
  8194. $annots .= ' '.$optval;
  8195. }
  8196. } else {
  8197. $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
  8198. }
  8199. }
  8200. if (isset($pl['opt']['dv'])) {
  8201. $annots .= ' /DV';
  8202. if (is_array($pl['opt']['dv'])) {
  8203. foreach ($pl['opt']['dv'] AS $optval) {
  8204. if (is_float($optval)) {
  8205. $optval = sprintf('%F', $optval);
  8206. }
  8207. $annots .= ' '.$optval;
  8208. }
  8209. } else {
  8210. $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
  8211. }
  8212. }
  8213. if (isset($pl['opt']['rv'])) {
  8214. $annots .= ' /RV';
  8215. if (is_array($pl['opt']['rv'])) {
  8216. foreach ($pl['opt']['rv'] AS $optval) {
  8217. if (is_float($optval)) {
  8218. $optval = sprintf('%F', $optval);
  8219. }
  8220. $annots .= ' '.$optval;
  8221. }
  8222. } else {
  8223. $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
  8224. }
  8225. }
  8226. if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
  8227. $annots .= ' /A << '.$pl['opt']['a'].' >>';
  8228. }
  8229. if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
  8230. $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
  8231. }
  8232. if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
  8233. $annots .= ' /DA ('.$pl['opt']['da'].')';
  8234. }
  8235. if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
  8236. $annots .= ' /Q '.intval($pl['opt']['q']);
  8237. }
  8238. if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
  8239. $annots .= ' /Opt [';
  8240. foreach($pl['opt']['opt'] AS $copt) {
  8241. if (is_array($copt)) {
  8242. $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
  8243. } else {
  8244. $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
  8245. }
  8246. }
  8247. $annots .= ']';
  8248. }
  8249. if (isset($pl['opt']['ti'])) {
  8250. $annots .= ' /TI '.intval($pl['opt']['ti']);
  8251. }
  8252. if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
  8253. $annots .= ' /I [';
  8254. foreach($pl['opt']['i'] AS $copt) {
  8255. $annots .= intval($copt).' ';
  8256. }
  8257. $annots .= ']';
  8258. }
  8259. break;
  8260. }
  8261. case 'screen': {
  8262. break;
  8263. }
  8264. case 'printermark': {
  8265. break;
  8266. }
  8267. case 'trapnet': {
  8268. break;
  8269. }
  8270. case 'watermark': {
  8271. break;
  8272. }
  8273. case '3d': {
  8274. break;
  8275. }
  8276. default: {
  8277. break;
  8278. }
  8279. }
  8280. $annots .= '>>';
  8281. // create new annotation object
  8282. $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
  8283. if ($formfield AND !isset($this->radiobutton_groups[$n][$pl['txt']])) {
  8284. // store reference of form object
  8285. $this->form_obj_id[] = $annot_obj_id;
  8286. }
  8287. }
  8288. }
  8289. } // end for each page
  8290. }
  8291. /**
  8292. * Put appearance streams XObject used to define annotation's appearance states.
  8293. * @param $w (int) annotation width
  8294. * @param $h (int) annotation height
  8295. * @param $stream (string) appearance stream
  8296. * @return int object ID
  8297. * @protected
  8298. * @since 4.8.001 (2009-09-09)
  8299. */
  8300. protected function _putAPXObject($w=0, $h=0, $stream='') {
  8301. $stream = trim($stream);
  8302. $out = $this->_getobj()."\n";
  8303. $this->xobjects['AX'.$this->n] = array('n' => $this->n);
  8304. $out .= '<<';
  8305. $out .= ' /Type /XObject';
  8306. $out .= ' /Subtype /Form';
  8307. $out .= ' /FormType 1';
  8308. if ($this->compress) {
  8309. $stream = gzcompress($stream);
  8310. $out .= ' /Filter /FlateDecode';
  8311. }
  8312. $rect = sprintf('%F %F', $w, $h);
  8313. $out .= ' /BBox [0 0 '.$rect.']';
  8314. $out .= ' /Matrix [1 0 0 1 0 0]';
  8315. $out .= ' /Resources 2 0 R';
  8316. $stream = $this->_getrawstream($stream);
  8317. $out .= ' /Length '.strlen($stream);
  8318. $out .= ' >>';
  8319. $out .= ' stream'."\n".$stream."\n".'endstream';
  8320. $out .= "\n".'endobj';
  8321. $this->_out($out);
  8322. return $this->n;
  8323. }
  8324. /**
  8325. * Output fonts.
  8326. * @author Nicola Asuni
  8327. * @protected
  8328. */
  8329. protected function _putfonts() {
  8330. $nf = $this->n;
  8331. foreach ($this->diffs as $diff) {
  8332. //Encodings
  8333. $this->_newobj();
  8334. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
  8335. }
  8336. $mqr = TCPDF_STATIC::get_mqr();
  8337. TCPDF_STATIC::set_mqr(false);
  8338. foreach ($this->FontFiles as $file => $info) {
  8339. // search and get font file to embedd
  8340. $fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
  8341. if (!TCPDF_STATIC::empty_string($fontfile)) {
  8342. $font = file_get_contents($fontfile);
  8343. $compressed = (substr($file, -2) == '.z');
  8344. if ((!$compressed) AND (isset($info['length2']))) {
  8345. $header = (ord($font{0}) == 128);
  8346. if ($header) {
  8347. // strip first binary header
  8348. $font = substr($font, 6);
  8349. }
  8350. if ($header AND (ord($font[$info['length1']]) == 128)) {
  8351. // strip second binary header
  8352. $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] + 6));
  8353. }
  8354. } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
  8355. if ($compressed) {
  8356. // uncompress font
  8357. $font = gzuncompress($font);
  8358. }
  8359. // merge subset characters
  8360. $subsetchars = array(); // used chars
  8361. foreach ($info['fontkeys'] as $fontkey) {
  8362. $fontinfo = $this->getFontBuffer($fontkey);
  8363. $subsetchars += $fontinfo['subsetchars'];
  8364. }
  8365. // rebuild a font subset
  8366. $font = TCPDF_FONTS::_getTrueTypeFontSubset($font, $subsetchars);
  8367. // calculate new font length
  8368. $info['length1'] = strlen($font);
  8369. if ($compressed) {
  8370. // recompress font
  8371. $font = gzcompress($font);
  8372. }
  8373. }
  8374. $this->_newobj();
  8375. $this->FontFiles[$file]['n'] = $this->n;
  8376. $stream = $this->_getrawstream($font);
  8377. $out = '<< /Length '.strlen($stream);
  8378. if ($compressed) {
  8379. $out .= ' /Filter /FlateDecode';
  8380. }
  8381. $out .= ' /Length1 '.$info['length1'];
  8382. if (isset($info['length2'])) {
  8383. $out .= ' /Length2 '.$info['length2'].' /Length3 0';
  8384. }
  8385. $out .= ' >>';
  8386. $out .= ' stream'."\n".$stream."\n".'endstream';
  8387. $out .= "\n".'endobj';
  8388. $this->_out($out);
  8389. }
  8390. }
  8391. TCPDF_STATIC::set_mqr($mqr);
  8392. foreach ($this->fontkeys as $k) {
  8393. //Font objects
  8394. $font = $this->getFontBuffer($k);
  8395. $type = $font['type'];
  8396. $name = $font['name'];
  8397. if ($type == 'core') {
  8398. // standard core font
  8399. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8400. $out .= '<</Type /Font';
  8401. $out .= ' /Subtype /Type1';
  8402. $out .= ' /BaseFont /'.$name;
  8403. $out .= ' /Name /F'.$font['i'];
  8404. if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
  8405. $out .= ' /Encoding /WinAnsiEncoding';
  8406. }
  8407. if ($k == 'helvetica') {
  8408. // add default font for annotations
  8409. $this->annotation_fonts[$k] = $font['i'];
  8410. }
  8411. $out .= ' >>';
  8412. $out .= "\n".'endobj';
  8413. $this->_out($out);
  8414. } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
  8415. // additional Type1 or TrueType font
  8416. $out = $this->_getobj($this->font_obj_ids[$k])."\n";
  8417. $out .= '<</Type /Font';
  8418. $out .= ' /Subtype /'.$type;
  8419. $out .= ' /BaseFont /'.$name;
  8420. $out .= ' /Name /F'.$font['i'];
  8421. $out .= ' /FirstChar 32 /LastChar 255';
  8422. $out .= ' /Widths '.($this->n + 1).' 0 R';
  8423. $out .= ' /FontDescriptor '.($this->n + 2).' 0 R';
  8424. if ($font['enc']) {
  8425. if (isset($font['diff'])) {
  8426. $out .= ' /Encoding '.($nf + $font['diff']).' 0 R';
  8427. } else {
  8428. $out .= ' /Encoding /WinAnsiEncoding';
  8429. }
  8430. }
  8431. $out .= ' >>';
  8432. $out .= "\n".'endobj';
  8433. $this->_out($out);
  8434. // Widths
  8435. $this->_newobj();
  8436. $s = '[';
  8437. for ($i = 32; $i < 256; ++$i) {
  8438. if (isset($font['cw'][$i])) {
  8439. $s .= $font['cw'][$i].' ';
  8440. } else {
  8441. $s .= $font['dw'].' ';
  8442. }
  8443. }
  8444. $s .= ']';
  8445. $s .= "\n".'endobj';
  8446. $this->_out($s);
  8447. //Descriptor
  8448. $this->_newobj();
  8449. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8450. foreach ($font['desc'] as $fdk => $fdv) {
  8451. if (is_float($fdv)) {
  8452. $fdv = sprintf('%F', $fdv);
  8453. }
  8454. $s .= ' /'.$fdk.' '.$fdv.'';
  8455. }
  8456. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8457. $s .= ' /FontFile'.($type == 'Type1' ? '' : '2').' '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8458. }
  8459. $s .= '>>';
  8460. $s .= "\n".'endobj';
  8461. $this->_out($s);
  8462. } else {
  8463. // additional types
  8464. $mtd = '_put'.strtolower($type);
  8465. if (!method_exists($this, $mtd)) {
  8466. $this->Error('Unsupported font type: '.$type);
  8467. }
  8468. $this->$mtd($font);
  8469. }
  8470. }
  8471. }
  8472. /**
  8473. * Adds unicode fonts.<br>
  8474. * Based on PDF Reference 1.3 (section 5)
  8475. * @param $font (array) font data
  8476. * @protected
  8477. * @author Nicola Asuni
  8478. * @since 1.52.0.TC005 (2005-01-05)
  8479. */
  8480. protected function _puttruetypeunicode($font) {
  8481. $fontname = '';
  8482. if ($font['subset']) {
  8483. // change name for font subsetting
  8484. $subtag = sprintf('%06u', $font['i']);
  8485. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  8486. $fontname .= $subtag.'+';
  8487. }
  8488. $fontname .= $font['name'];
  8489. // Type0 Font
  8490. // A composite font composed of other fonts, organized hierarchically
  8491. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8492. $out .= '<< /Type /Font';
  8493. $out .= ' /Subtype /Type0';
  8494. $out .= ' /BaseFont /'.$fontname;
  8495. $out .= ' /Name /F'.$font['i'];
  8496. $out .= ' /Encoding /'.$font['enc'];
  8497. $out .= ' /ToUnicode '.($this->n + 1).' 0 R';
  8498. $out .= ' /DescendantFonts ['.($this->n + 2).' 0 R]';
  8499. $out .= ' >>';
  8500. $out .= "\n".'endobj';
  8501. $this->_out($out);
  8502. // ToUnicode map for Identity-H
  8503. $stream = TCPDF_FONT_DATA::$uni_identity_h;
  8504. // ToUnicode Object
  8505. $this->_newobj();
  8506. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  8507. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8508. $stream = $this->_getrawstream($stream);
  8509. $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
  8510. // CIDFontType2
  8511. // A CIDFont whose glyph descriptions are based on TrueType font technology
  8512. $oid = $this->_newobj();
  8513. $out = '<< /Type /Font';
  8514. $out .= ' /Subtype /CIDFontType2';
  8515. $out .= ' /BaseFont /'.$fontname;
  8516. // A dictionary containing entries that define the character collection of the CIDFont.
  8517. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8518. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8519. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8520. $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
  8521. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8522. $out .= ' /DW '.$font['dw']; // default width
  8523. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, 0);
  8524. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8525. $out .= "\n".'/CIDToGIDMap '.($this->n + 2).' 0 R';
  8526. }
  8527. $out .= ' >>';
  8528. $out .= "\n".'endobj';
  8529. $this->_out($out);
  8530. // Font descriptor
  8531. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  8532. $this->_newobj();
  8533. $out = '<< /Type /FontDescriptor';
  8534. $out .= ' /FontName /'.$fontname;
  8535. foreach ($font['desc'] as $key => $value) {
  8536. if (is_float($value)) {
  8537. $value = sprintf('%F', $value);
  8538. }
  8539. $out .= ' /'.$key.' '.$value;
  8540. }
  8541. $fontdir = false;
  8542. if (!TCPDF_STATIC::empty_string($font['file'])) {
  8543. // A stream containing a TrueType font
  8544. $out .= ' /FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R';
  8545. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  8546. }
  8547. $out .= ' >>';
  8548. $out .= "\n".'endobj';
  8549. $this->_out($out);
  8550. if (isset($font['ctg']) AND (!TCPDF_STATIC::empty_string($font['ctg']))) {
  8551. $this->_newobj();
  8552. // Embed CIDToGIDMap
  8553. // A specification of the mapping from CIDs to glyph indices
  8554. // search and get CTG font file to embedd
  8555. $ctgfile = strtolower($font['ctg']);
  8556. // search and get ctg font file to embedd
  8557. $fontfile = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
  8558. if (TCPDF_STATIC::empty_string($fontfile)) {
  8559. $this->Error('Font file not found: '.$ctgfile);
  8560. }
  8561. $stream = $this->_getrawstream(file_get_contents($fontfile));
  8562. $out = '<< /Length '.strlen($stream).'';
  8563. if (substr($fontfile, -2) == '.z') { // check file extension
  8564. // Decompresses data encoded using the public-domain
  8565. // zlib/deflate compression method, reproducing the
  8566. // original text or binary data
  8567. $out .= ' /Filter /FlateDecode';
  8568. }
  8569. $out .= ' >>';
  8570. $out .= ' stream'."\n".$stream."\n".'endstream';
  8571. $out .= "\n".'endobj';
  8572. $this->_out($out);
  8573. }
  8574. }
  8575. /**
  8576. * Output CID-0 fonts.
  8577. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  8578. * @param $font (array) font data
  8579. * @protected
  8580. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  8581. * @since 3.2.000 (2008-06-23)
  8582. */
  8583. protected function _putcidfont0($font) {
  8584. $cidoffset = 0;
  8585. if (!isset($font['cw'][1])) {
  8586. $cidoffset = 31;
  8587. }
  8588. if (isset($font['cidinfo']['uni2cid'])) {
  8589. // convert unicode to cid.
  8590. $uni2cid = $font['cidinfo']['uni2cid'];
  8591. $cw = array();
  8592. foreach ($font['cw'] as $uni => $width) {
  8593. if (isset($uni2cid[$uni])) {
  8594. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  8595. } elseif ($uni < 256) {
  8596. $cw[$uni] = $width;
  8597. } // else unknown character
  8598. }
  8599. $font = array_merge($font, array('cw' => $cw));
  8600. }
  8601. $name = $font['name'];
  8602. $enc = $font['enc'];
  8603. if ($enc) {
  8604. $longname = $name.'-'.$enc;
  8605. } else {
  8606. $longname = $name;
  8607. }
  8608. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']])."\n";
  8609. $out .= '<</Type /Font';
  8610. $out .= ' /Subtype /Type0';
  8611. $out .= ' /BaseFont /'.$longname;
  8612. $out .= ' /Name /F'.$font['i'];
  8613. if ($enc) {
  8614. $out .= ' /Encoding /'.$enc;
  8615. }
  8616. $out .= ' /DescendantFonts ['.($this->n + 1).' 0 R]';
  8617. $out .= ' >>';
  8618. $out .= "\n".'endobj';
  8619. $this->_out($out);
  8620. $oid = $this->_newobj();
  8621. $out = '<</Type /Font';
  8622. $out .= ' /Subtype /CIDFontType0';
  8623. $out .= ' /BaseFont /'.$name;
  8624. $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
  8625. $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
  8626. $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
  8627. $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
  8628. $out .= ' /FontDescriptor '.($this->n + 1).' 0 R';
  8629. $out .= ' /DW '.$font['dw'];
  8630. $out .= "\n".TCPDF_FONTS::_putfontwidths($font, $cidoffset);
  8631. $out .= ' >>';
  8632. $out .= "\n".'endobj';
  8633. $this->_out($out);
  8634. $this->_newobj();
  8635. $s = '<</Type /FontDescriptor /FontName /'.$name;
  8636. foreach ($font['desc'] as $k => $v) {
  8637. if ($k != 'Style') {
  8638. if (is_float($v)) {
  8639. $v = sprintf('%F', $v);
  8640. }
  8641. $s .= ' /'.$k.' '.$v.'';
  8642. }
  8643. }
  8644. $s .= '>>';
  8645. $s .= "\n".'endobj';
  8646. $this->_out($s);
  8647. }
  8648. /**
  8649. * Output images.
  8650. * @protected
  8651. */
  8652. protected function _putimages() {
  8653. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  8654. foreach ($this->imagekeys as $file) {
  8655. $info = $this->getImageBuffer($file);
  8656. // set object for alternate images array
  8657. if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
  8658. $altoid = $this->_newobj();
  8659. $out = '[';
  8660. foreach ($info['altimgs'] as $altimage) {
  8661. if (isset($this->xobjects['I'.$altimage[0]]['n'])) {
  8662. $out .= ' << /Image '.$this->xobjects['I'.$altimage[0]]['n'].' 0 R';
  8663. $out .= ' /DefaultForPrinting';
  8664. if ($altimage[1] === true) {
  8665. $out .= ' true';
  8666. } else {
  8667. $out .= ' false';
  8668. }
  8669. $out .= ' >>';
  8670. }
  8671. }
  8672. $out .= ' ]';
  8673. $out .= "\n".'endobj';
  8674. $this->_out($out);
  8675. }
  8676. // set image object
  8677. $oid = $this->_newobj();
  8678. $this->xobjects['I'.$info['i']] = array('n' => $oid);
  8679. $this->setImageSubBuffer($file, 'n', $this->n);
  8680. $out = '<</Type /XObject';
  8681. $out .= ' /Subtype /Image';
  8682. $out .= ' /Width '.$info['w'];
  8683. $out .= ' /Height '.$info['h'];
  8684. if (array_key_exists('masked', $info)) {
  8685. $out .= ' /SMask '.($this->n - 1).' 0 R';
  8686. }
  8687. // set color space
  8688. $icc = false;
  8689. if (isset($info['icc']) AND ($info['icc'] !== false)) {
  8690. // ICC Colour Space
  8691. $icc = true;
  8692. $out .= ' /ColorSpace [/ICCBased '.($this->n + 1).' 0 R]';
  8693. } elseif ($info['cs'] == 'Indexed') {
  8694. // Indexed Colour Space
  8695. $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n + 1).' 0 R]';
  8696. } else {
  8697. // Device Colour Space
  8698. $out .= ' /ColorSpace /'.$info['cs'];
  8699. }
  8700. if ($info['cs'] == 'DeviceCMYK') {
  8701. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  8702. }
  8703. $out .= ' /BitsPerComponent '.$info['bpc'];
  8704. if (isset($altoid) AND ($altoid > 0)) {
  8705. // reference to alternate images dictionary
  8706. $out .= ' /Alternates '.$altoid.' 0 R';
  8707. }
  8708. if (isset($info['exurl']) AND !empty($info['exurl'])) {
  8709. // external stream
  8710. $out .= ' /Length 0';
  8711. $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
  8712. if (isset($info['f'])) {
  8713. $out .= ' /FFilter /'.$info['f'];
  8714. }
  8715. $out .= ' >>';
  8716. $out .= ' stream'."\n".'endstream';
  8717. } else {
  8718. if (isset($info['f'])) {
  8719. $out .= ' /Filter /'.$info['f'];
  8720. }
  8721. if (isset($info['parms'])) {
  8722. $out .= ' '.$info['parms'];
  8723. }
  8724. if (isset($info['trns']) AND is_array($info['trns'])) {
  8725. $trns = '';
  8726. $count_info = count($info['trns']);
  8727. for ($i=0; $i < $count_info; ++$i) {
  8728. $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
  8729. }
  8730. $out .= ' /Mask ['.$trns.']';
  8731. }
  8732. $stream = $this->_getrawstream($info['data']);
  8733. $out .= ' /Length '.strlen($stream).' >>';
  8734. $out .= ' stream'."\n".$stream."\n".'endstream';
  8735. }
  8736. $out .= "\n".'endobj';
  8737. $this->_out($out);
  8738. if ($icc) {
  8739. // ICC colour profile
  8740. $this->_newobj();
  8741. $icc = ($this->compress) ? gzcompress($info['icc']) : $info['icc'];
  8742. $icc = $this->_getrawstream($icc);
  8743. $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  8744. } elseif ($info['cs'] == 'Indexed') {
  8745. // colour palette
  8746. $this->_newobj();
  8747. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  8748. $pal = $this->_getrawstream($pal);
  8749. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
  8750. }
  8751. }
  8752. }
  8753. /**
  8754. * Output Form XObjects Templates.
  8755. * @author Nicola Asuni
  8756. * @since 5.8.017 (2010-08-24)
  8757. * @protected
  8758. * @see startTemplate(), endTemplate(), printTemplate()
  8759. */
  8760. protected function _putxobjects() {
  8761. foreach ($this->xobjects as $key => $data) {
  8762. if (isset($data['outdata'])) {
  8763. $stream = str_replace($this->epsmarker, '', trim($data['outdata']));
  8764. $out = $this->_getobj($data['n'])."\n";
  8765. $out .= '<<';
  8766. $out .= ' /Type /XObject';
  8767. $out .= ' /Subtype /Form';
  8768. $out .= ' /FormType 1';
  8769. if ($this->compress) {
  8770. $stream = gzcompress($stream);
  8771. $out .= ' /Filter /FlateDecode';
  8772. }
  8773. $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));
  8774. $out .= ' /Matrix [1 0 0 1 0 0]';
  8775. $out .= ' /Resources <<';
  8776. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8777. if (!$this->pdfa_mode) {
  8778. // transparency
  8779. if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
  8780. $out .= ' /ExtGState <<';
  8781. foreach ($data['extgstates'] as $k => $extgstate) {
  8782. if (isset($this->extgstates[$k]['name'])) {
  8783. $out .= ' /'.$this->extgstates[$k]['name'];
  8784. } else {
  8785. $out .= ' /GS'.$k;
  8786. }
  8787. $out .= ' '.$this->extgstates[$k]['n'].' 0 R';
  8788. }
  8789. $out .= ' >>';
  8790. }
  8791. if (isset($data['gradients']) AND !empty($data['gradients'])) {
  8792. $gp = '';
  8793. $gs = '';
  8794. foreach ($data['gradients'] as $id => $grad) {
  8795. // gradient patterns
  8796. $gp .= ' /p'.$id.' '.$this->gradients[$id]['pattern'].' 0 R';
  8797. // gradient shadings
  8798. $gs .= ' /Sh'.$id.' '.$this->gradients[$id]['id'].' 0 R';
  8799. }
  8800. $out .= ' /Pattern <<'.$gp.' >>';
  8801. $out .= ' /Shading <<'.$gs.' >>';
  8802. }
  8803. }
  8804. // spot colors
  8805. if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
  8806. $out .= ' /ColorSpace <<';
  8807. foreach ($data['spot_colors'] as $name => $color) {
  8808. $out .= ' /CS'.$color['i'].' '.$this->spot_colors[$name]['n'].' 0 R';
  8809. }
  8810. $out .= ' >>';
  8811. }
  8812. // fonts
  8813. if (!empty($data['fonts'])) {
  8814. $out .= ' /Font <<';
  8815. foreach ($data['fonts'] as $fontkey => $fontid) {
  8816. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  8817. }
  8818. $out .= ' >>';
  8819. }
  8820. // images or nested xobjects
  8821. if (!empty($data['images']) OR !empty($data['xobjects'])) {
  8822. $out .= ' /XObject <<';
  8823. foreach ($data['images'] as $imgid) {
  8824. $out .= ' /I'.$imgid.' '.$this->xobjects['I'.$imgid]['n'].' 0 R';
  8825. }
  8826. foreach ($data['xobjects'] as $sub_id => $sub_objid) {
  8827. $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
  8828. }
  8829. $out .= ' >>';
  8830. }
  8831. $out .= ' >>'; //end resources
  8832. if (isset($data['group']) AND ($data['group'] !== false)) {
  8833. // set transparency group
  8834. $out .= ' /Group << /Type /Group /S /Transparency';
  8835. if (is_array($data['group'])) {
  8836. if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
  8837. $out .= ' /CS /'.$data['group']['CS'];
  8838. }
  8839. if (isset($data['group']['I'])) {
  8840. $out .= ' /I /'.($data['group']['I']===true?'true':'false');
  8841. }
  8842. if (isset($data['group']['K'])) {
  8843. $out .= ' /K /'.($data['group']['K']===true?'true':'false');
  8844. }
  8845. }
  8846. $out .= ' >>';
  8847. }
  8848. $stream = $this->_getrawstream($stream, $data['n']);
  8849. $out .= ' /Length '.strlen($stream);
  8850. $out .= ' >>';
  8851. $out .= ' stream'."\n".$stream."\n".'endstream';
  8852. $out .= "\n".'endobj';
  8853. $this->_out($out);
  8854. }
  8855. }
  8856. }
  8857. /**
  8858. * Output Spot Colors Resources.
  8859. * @protected
  8860. * @since 4.0.024 (2008-09-12)
  8861. */
  8862. protected function _putspotcolors() {
  8863. foreach ($this->spot_colors as $name => $color) {
  8864. $this->_newobj();
  8865. $this->spot_colors[$name]['n'] = $this->n;
  8866. $out = '[/Separation /'.str_replace(' ', '#20', $name);
  8867. $out .= ' /DeviceCMYK <<';
  8868. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  8869. $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
  8870. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  8871. $out .= "\n".'endobj';
  8872. $this->_out($out);
  8873. }
  8874. }
  8875. /**
  8876. * Return XObjects Dictionary.
  8877. * @return string XObjects dictionary
  8878. * @protected
  8879. * @since 5.8.014 (2010-08-23)
  8880. */
  8881. protected function _getxobjectdict() {
  8882. $out = '';
  8883. foreach ($this->xobjects as $id => $objid) {
  8884. $out .= ' /'.$id.' '.$objid['n'].' 0 R';
  8885. }
  8886. return $out;
  8887. }
  8888. /**
  8889. * Output Resources Dictionary.
  8890. * @protected
  8891. */
  8892. protected function _putresourcedict() {
  8893. $out = $this->_getobj(2)."\n";
  8894. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  8895. $out .= ' /Font <<';
  8896. foreach ($this->fontkeys as $fontkey) {
  8897. $font = $this->getFontBuffer($fontkey);
  8898. $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
  8899. }
  8900. $out .= ' >>';
  8901. $out .= ' /XObject <<';
  8902. $out .= $this->_getxobjectdict();
  8903. $out .= ' >>';
  8904. // layers
  8905. if (!empty($this->pdflayers)) {
  8906. $out .= ' /Properties <<';
  8907. foreach ($this->pdflayers as $layer) {
  8908. $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
  8909. }
  8910. $out .= ' >>';
  8911. }
  8912. if (!$this->pdfa_mode) {
  8913. // transparency
  8914. if (isset($this->extgstates) AND !empty($this->extgstates)) {
  8915. $out .= ' /ExtGState <<';
  8916. foreach ($this->extgstates as $k => $extgstate) {
  8917. if (isset($extgstate['name'])) {
  8918. $out .= ' /'.$extgstate['name'];
  8919. } else {
  8920. $out .= ' /GS'.$k;
  8921. }
  8922. $out .= ' '.$extgstate['n'].' 0 R';
  8923. }
  8924. $out .= ' >>';
  8925. }
  8926. if (isset($this->gradients) AND !empty($this->gradients)) {
  8927. $gp = '';
  8928. $gs = '';
  8929. foreach ($this->gradients as $id => $grad) {
  8930. // gradient patterns
  8931. $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
  8932. // gradient shadings
  8933. $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
  8934. }
  8935. $out .= ' /Pattern <<'.$gp.' >>';
  8936. $out .= ' /Shading <<'.$gs.' >>';
  8937. }
  8938. }
  8939. // spot colors
  8940. if (isset($this->spot_colors) AND !empty($this->spot_colors)) {
  8941. $out .= ' /ColorSpace <<';
  8942. foreach ($this->spot_colors as $color) {
  8943. $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
  8944. }
  8945. $out .= ' >>';
  8946. }
  8947. $out .= ' >>';
  8948. $out .= "\n".'endobj';
  8949. $this->_out($out);
  8950. }
  8951. /**
  8952. * Output Resources.
  8953. * @protected
  8954. */
  8955. protected function _putresources() {
  8956. $this->_putextgstates();
  8957. $this->_putocg();
  8958. $this->_putfonts();
  8959. $this->_putimages();
  8960. $this->_putspotcolors();
  8961. $this->_putshaders();
  8962. $this->_putxobjects();
  8963. $this->_putresourcedict();
  8964. $this->_putdests();
  8965. $this->_putEmbeddedFiles();
  8966. $this->_putannotsobjs();
  8967. $this->_putjavascript();
  8968. $this->_putbookmarks();
  8969. $this->_putencryption();
  8970. }
  8971. /**
  8972. * Adds some Metadata information (Document Information Dictionary)
  8973. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  8974. * @return int object id
  8975. * @protected
  8976. */
  8977. protected function _putinfo() {
  8978. $oid = $this->_newobj();
  8979. $out = '<<';
  8980. // store current isunicode value
  8981. $prev_isunicode = $this->isunicode;
  8982. if ($this->docinfounicode) {
  8983. $this->isunicode = true;
  8984. }
  8985. if (!TCPDF_STATIC::empty_string($this->title)) {
  8986. // The document's title.
  8987. $out .= ' /Title '.$this->_textstring($this->title, $oid);
  8988. }
  8989. if (!TCPDF_STATIC::empty_string($this->author)) {
  8990. // The name of the person who created the document.
  8991. $out .= ' /Author '.$this->_textstring($this->author, $oid);
  8992. }
  8993. if (!TCPDF_STATIC::empty_string($this->subject)) {
  8994. // The subject of the document.
  8995. $out .= ' /Subject '.$this->_textstring($this->subject, $oid);
  8996. }
  8997. if (!TCPDF_STATIC::empty_string($this->keywords)) {
  8998. // Keywords associated with the document.
  8999. $out .= ' /Keywords '.$this->_textstring($this->keywords, $oid);
  9000. }
  9001. if (!TCPDF_STATIC::empty_string($this->creator)) {
  9002. // 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.
  9003. $out .= ' /Creator '.$this->_textstring($this->creator, $oid);
  9004. }
  9005. // restore previous isunicode value
  9006. $this->isunicode = $prev_isunicode;
  9007. // default producer
  9008. $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid);
  9009. // The date and time the document was created, in human-readable form
  9010. $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp);
  9011. // The date and time the document was most recently modified, in human-readable form
  9012. $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp);
  9013. // A name object indicating whether the document has been modified to include trapping information
  9014. $out .= ' /Trapped /False';
  9015. $out .= ' >>';
  9016. $out .= "\n".'endobj';
  9017. $this->_out($out);
  9018. return $oid;
  9019. }
  9020. /**
  9021. * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
  9022. * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
  9023. * @param $xmp (string) Custom XMP data.
  9024. * @since 5.9.128 (2011-10-06)
  9025. * @public
  9026. */
  9027. public function setExtraXMP($xmp) {
  9028. $this->custom_xmp = $xmp;
  9029. }
  9030. /**
  9031. * Put XMP data object and return ID.
  9032. * @return (int) The object ID.
  9033. * @since 5.9.121 (2011-09-28)
  9034. * @protected
  9035. */
  9036. protected function _putXMP() {
  9037. $oid = $this->_newobj();
  9038. // store current isunicode value
  9039. $prev_isunicode = $this->isunicode;
  9040. $this->isunicode = true;
  9041. $prev_encrypted = $this->encrypted;
  9042. $this->encrypted = false;
  9043. // set XMP data
  9044. $xmp = '<?xpacket begin="'.TCPDF_FONTS::unichr(0xfeff, $this->isunicode).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
  9045. $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";
  9046. $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  9047. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  9048. $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
  9049. $xmp .= "\t\t\t".'<dc:title>'."\n";
  9050. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9051. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->title).'</rdf:li>'."\n";
  9052. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9053. $xmp .= "\t\t\t".'</dc:title>'."\n";
  9054. $xmp .= "\t\t\t".'<dc:creator>'."\n";
  9055. $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
  9056. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->author).'</rdf:li>'."\n";
  9057. $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
  9058. $xmp .= "\t\t\t".'</dc:creator>'."\n";
  9059. $xmp .= "\t\t\t".'<dc:description>'."\n";
  9060. $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
  9061. $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC::_escapeXML($this->subject).'</rdf:li>'."\n";
  9062. $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
  9063. $xmp .= "\t\t\t".'</dc:description>'."\n";
  9064. $xmp .= "\t\t\t".'<dc:subject>'."\n";
  9065. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9066. $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC::_escapeXML($this->keywords).'</rdf:li>'."\n";
  9067. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9068. $xmp .= "\t\t\t".'</dc:subject>'."\n";
  9069. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9070. // convert doc creation date format
  9071. $dcdate = TCPDF_STATIC::getFormattedDate($this->doc_creation_timestamp);
  9072. $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
  9073. $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
  9074. $doccreationdate .= '+'.substr($dcdate, 15, 2).':'.substr($dcdate, 18, 2);
  9075. $doccreationdate = TCPDF_STATIC::_escapeXML($doccreationdate);
  9076. // convert doc modification date format
  9077. $dmdate = TCPDF_STATIC::getFormattedDate($this->doc_modification_timestamp);
  9078. $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
  9079. $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
  9080. $docmoddate .= '+'.substr($dmdate, 15, 2).':'.substr($dmdate, 18, 2);
  9081. $docmoddate = TCPDF_STATIC::_escapeXML($docmoddate);
  9082. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  9083. $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
  9084. $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  9085. $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
  9086. $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
  9087. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9088. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  9089. $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC::_escapeXML($this->keywords).'</pdf:Keywords>'."\n";
  9090. $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).'</pdf:Producer>'."\n";
  9091. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9092. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  9093. $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);
  9094. $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
  9095. $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
  9096. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9097. if ($this->pdfa_mode) {
  9098. $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
  9099. $xmp .= "\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n";
  9100. $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
  9101. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9102. }
  9103. // XMP extension schemas
  9104. $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";
  9105. $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
  9106. $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
  9107. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9108. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
  9109. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
  9110. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
  9111. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9112. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9113. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
  9114. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
  9115. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
  9116. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9117. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9118. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9119. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9120. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
  9121. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
  9122. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
  9123. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9124. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9125. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9126. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9127. $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9128. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
  9129. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
  9130. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
  9131. $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
  9132. $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
  9133. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9134. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9135. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
  9136. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
  9137. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
  9138. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9139. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9140. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9141. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
  9142. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
  9143. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9144. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9145. $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
  9146. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
  9147. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
  9148. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
  9149. $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
  9150. $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
  9151. $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
  9152. $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
  9153. $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
  9154. $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
  9155. $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
  9156. $xmp .= "\t\t".'</rdf:Description>'."\n";
  9157. $xmp .= "\t".'</rdf:RDF>'."\n";
  9158. $xmp .= $this->custom_xmp;
  9159. $xmp .= '</x:xmpmeta>'."\n";
  9160. $xmp .= '<?xpacket end="w"?>';
  9161. $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
  9162. // restore previous isunicode value
  9163. $this->isunicode = $prev_isunicode;
  9164. $this->encrypted = $prev_encrypted;
  9165. $this->_out($out);
  9166. return $oid;
  9167. }
  9168. /**
  9169. * Output Catalog.
  9170. * @return int object id
  9171. * @protected
  9172. */
  9173. protected function _putcatalog() {
  9174. // put XMP
  9175. $xmpobj = $this->_putXMP();
  9176. // if required, add standard sRGB_IEC61966-2.1 blackscaled ICC colour profile
  9177. if ($this->pdfa_mode OR $this->force_srgb) {
  9178. $iccobj = $this->_newobj();
  9179. $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc');
  9180. $filter = '';
  9181. if ($this->compress) {
  9182. $filter = ' /Filter /FlateDecode';
  9183. $icc = gzcompress($icc);
  9184. }
  9185. $icc = $this->_getrawstream($icc);
  9186. $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
  9187. }
  9188. // start catalog
  9189. $oid = $this->_newobj();
  9190. $out = '<< /Type /Catalog';
  9191. $out .= ' /Version /'.$this->PDFVersion;
  9192. //$out .= ' /Extensions <<>>';
  9193. $out .= ' /Pages 1 0 R';
  9194. //$out .= ' /PageLabels ' //...;
  9195. $out .= ' /Names <<';
  9196. if ((!$this->pdfa_mode) AND !empty($this->n_js)) {
  9197. $out .= ' /JavaScript '.$this->n_js;
  9198. }
  9199. if (!empty($this->efnames)) {
  9200. $out .= ' /EmbeddedFiles <</Names [';
  9201. foreach ($this->efnames AS $fn => $fref) {
  9202. $out .= ' '.$this->_datastring($fn).' '.$fref;
  9203. }
  9204. $out .= ' ]>>';
  9205. }
  9206. $out .= ' >>';
  9207. if (!empty($this->dests)) {
  9208. $out .= ' /Dests '.($this->n_dests).' 0 R';
  9209. }
  9210. $out .= $this->_putviewerpreferences();
  9211. if (isset($this->LayoutMode) AND (!TCPDF_STATIC::empty_string($this->LayoutMode))) {
  9212. $out .= ' /PageLayout /'.$this->LayoutMode;
  9213. }
  9214. if (isset($this->PageMode) AND (!TCPDF_STATIC::empty_string($this->PageMode))) {
  9215. $out .= ' /PageMode /'.$this->PageMode;
  9216. }
  9217. if (count($this->outlines) > 0) {
  9218. $out .= ' /Outlines '.$this->OutlineRoot.' 0 R';
  9219. $out .= ' /PageMode /UseOutlines';
  9220. }
  9221. //$out .= ' /Threads []';
  9222. if ($this->ZoomMode == 'fullpage') {
  9223. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /Fit]';
  9224. } elseif ($this->ZoomMode == 'fullwidth') {
  9225. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /FitH null]';
  9226. } elseif ($this->ZoomMode == 'real') {
  9227. $out .= ' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null 1]';
  9228. } elseif (!is_string($this->ZoomMode)) {
  9229. $out .= sprintf(' /OpenAction ['.$this->page_obj_id[1].' 0 R /XYZ null null %F]', ($this->ZoomMode / 100));
  9230. }
  9231. //$out .= ' /AA <<>>';
  9232. //$out .= ' /URI <<>>';
  9233. $out .= ' /Metadata '.$xmpobj.' 0 R';
  9234. //$out .= ' /StructTreeRoot <<>>';
  9235. //$out .= ' /MarkInfo <<>>';
  9236. if (isset($this->l['a_meta_language'])) {
  9237. $out .= ' /Lang '.$this->_textstring($this->l['a_meta_language'], $oid);
  9238. }
  9239. //$out .= ' /SpiderInfo <<>>';
  9240. // set OutputIntent to sRGB IEC61966-2.1 if required
  9241. if ($this->pdfa_mode OR $this->force_srgb) {
  9242. $out .= ' /OutputIntents [<<';
  9243. $out .= ' /Type /OutputIntent';
  9244. $out .= ' /S /GTS_PDFA1';
  9245. $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9246. $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9247. $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
  9248. $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
  9249. $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
  9250. $out .= ' >>]';
  9251. }
  9252. //$out .= ' /PieceInfo <<>>';
  9253. if (!empty($this->pdflayers)) {
  9254. $lyrobjs = '';
  9255. $lyrobjs_print = '';
  9256. $lyrobjs_view = '';
  9257. foreach ($this->pdflayers as $layer) {
  9258. $lyrobjs .= ' '.$layer['objid'].' 0 R';
  9259. if ($layer['print']) {
  9260. $lyrobjs_print .= ' '.$layer['objid'].' 0 R';
  9261. }
  9262. if ($layer['view']) {
  9263. $lyrobjs_view .= ' '.$layer['objid'].' 0 R';
  9264. }
  9265. }
  9266. $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
  9267. $out .= ' /D <<';
  9268. $out .= ' /Name '.$this->_textstring('Layers', $oid);
  9269. $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
  9270. $out .= ' /BaseState /ON';
  9271. $out .= ' /ON ['.$lyrobjs_print.']';
  9272. $out .= ' /OFF ['.$lyrobjs_view.']';
  9273. $out .= ' /Intent /View';
  9274. $out .= ' /AS [';
  9275. $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
  9276. $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
  9277. $out .= ' ]';
  9278. $out .= ' /Order ['.$lyrobjs.']';
  9279. $out .= ' /ListMode /AllPages';
  9280. //$out .= ' /RBGroups ['..']';
  9281. //$out .= ' /Locked ['..']';
  9282. $out .= ' >>';
  9283. $out .= ' >>';
  9284. }
  9285. // AcroForm
  9286. if (!empty($this->form_obj_id)
  9287. OR ($this->sign AND isset($this->signature_data['cert_type']))
  9288. OR !empty($this->empty_signature_appearance)) {
  9289. $out .= ' /AcroForm <<';
  9290. $objrefs = '';
  9291. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9292. // set reference for signature object
  9293. $objrefs .= $this->sig_obj_id.' 0 R';
  9294. }
  9295. if (!empty($this->empty_signature_appearance)) {
  9296. foreach ($this->empty_signature_appearance as $esa) {
  9297. // set reference for empty signature objects
  9298. $objrefs .= ' '.$esa['objid'].' 0 R';
  9299. }
  9300. }
  9301. if (!empty($this->form_obj_id)) {
  9302. foreach($this->form_obj_id as $objid) {
  9303. $objrefs .= ' '.$objid.' 0 R';
  9304. }
  9305. }
  9306. $out .= ' /Fields ['.$objrefs.']';
  9307. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  9308. $out .= ' /NeedAppearances false';
  9309. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9310. if ($this->signature_data['cert_type'] > 0) {
  9311. $out .= ' /SigFlags 3';
  9312. } else {
  9313. $out .= ' /SigFlags 1';
  9314. }
  9315. }
  9316. //$out .= ' /CO ';
  9317. if (isset($this->annotation_fonts) AND !empty($this->annotation_fonts)) {
  9318. $out .= ' /DR <<';
  9319. $out .= ' /Font <<';
  9320. foreach ($this->annotation_fonts as $fontkey => $fontid) {
  9321. $out .= ' /F'.$fontid.' '.$this->font_obj_ids[$fontkey].' 0 R';
  9322. }
  9323. $out .= ' >> >>';
  9324. }
  9325. $font = $this->getFontBuffer('helvetica');
  9326. $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
  9327. $out .= ' /Q '.(($this->rtl)?'2':'0');
  9328. //$out .= ' /XFA ';
  9329. $out .= ' >>';
  9330. // signatures
  9331. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9332. if ($this->signature_data['cert_type'] > 0) {
  9333. $out .= ' /Perms << /DocMDP '.($this->sig_obj_id + 1).' 0 R >>';
  9334. } else {
  9335. $out .= ' /Perms << /UR3 '.($this->sig_obj_id + 1).' 0 R >>';
  9336. }
  9337. }
  9338. }
  9339. //$out .= ' /Legal <<>>';
  9340. //$out .= ' /Requirements []';
  9341. //$out .= ' /Collection <<>>';
  9342. //$out .= ' /NeedsRendering true';
  9343. $out .= ' >>';
  9344. $out .= "\n".'endobj';
  9345. $this->_out($out);
  9346. return $oid;
  9347. }
  9348. /**
  9349. * Output viewer preferences.
  9350. * @return string for viewer preferences
  9351. * @author Nicola asuni
  9352. * @since 3.1.000 (2008-06-09)
  9353. * @protected
  9354. */
  9355. protected function _putviewerpreferences() {
  9356. $vp = $this->viewer_preferences;
  9357. $out = ' /ViewerPreferences <<';
  9358. if ($this->rtl) {
  9359. $out .= ' /Direction /R2L';
  9360. } else {
  9361. $out .= ' /Direction /L2R';
  9362. }
  9363. if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
  9364. $out .= ' /HideToolbar true';
  9365. }
  9366. if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
  9367. $out .= ' /HideMenubar true';
  9368. }
  9369. if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
  9370. $out .= ' /HideWindowUI true';
  9371. }
  9372. if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
  9373. $out .= ' /FitWindow true';
  9374. }
  9375. if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
  9376. $out .= ' /CenterWindow true';
  9377. }
  9378. if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
  9379. $out .= ' /DisplayDocTitle true';
  9380. }
  9381. if (isset($vp['NonFullScreenPageMode'])) {
  9382. $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
  9383. }
  9384. if (isset($vp['ViewArea'])) {
  9385. $out .= ' /ViewArea /'.$vp['ViewArea'];
  9386. }
  9387. if (isset($vp['ViewClip'])) {
  9388. $out .= ' /ViewClip /'.$vp['ViewClip'];
  9389. }
  9390. if (isset($vp['PrintArea'])) {
  9391. $out .= ' /PrintArea /'.$vp['PrintArea'];
  9392. }
  9393. if (isset($vp['PrintClip'])) {
  9394. $out .= ' /PrintClip /'.$vp['PrintClip'];
  9395. }
  9396. if (isset($vp['PrintScaling'])) {
  9397. $out .= ' /PrintScaling /'.$vp['PrintScaling'];
  9398. }
  9399. if (isset($vp['Duplex']) AND (!TCPDF_STATIC::empty_string($vp['Duplex']))) {
  9400. $out .= ' /Duplex /'.$vp['Duplex'];
  9401. }
  9402. if (isset($vp['PickTrayByPDFSize'])) {
  9403. if ($vp['PickTrayByPDFSize']) {
  9404. $out .= ' /PickTrayByPDFSize true';
  9405. } else {
  9406. $out .= ' /PickTrayByPDFSize false';
  9407. }
  9408. }
  9409. if (isset($vp['PrintPageRange'])) {
  9410. $PrintPageRangeNum = '';
  9411. foreach ($vp['PrintPageRange'] as $k => $v) {
  9412. $PrintPageRangeNum .= ' '.($v - 1).'';
  9413. }
  9414. $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
  9415. }
  9416. if (isset($vp['NumCopies'])) {
  9417. $out .= ' /NumCopies '.intval($vp['NumCopies']);
  9418. }
  9419. $out .= ' >>';
  9420. return $out;
  9421. }
  9422. /**
  9423. * Output PDF File Header (7.5.2).
  9424. * @protected
  9425. */
  9426. protected function _putheader() {
  9427. $this->_out('%PDF-'.$this->PDFVersion);
  9428. $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
  9429. }
  9430. /**
  9431. * Output end of document (EOF).
  9432. * @protected
  9433. */
  9434. protected function _enddoc() {
  9435. if (isset($this->CurrentFont['fontkey']) AND isset($this->CurrentFont['subsetchars'])) {
  9436. // save subset chars of the previous font
  9437. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  9438. }
  9439. $this->state = 1;
  9440. $this->_putheader();
  9441. $this->_putpages();
  9442. $this->_putresources();
  9443. // empty signature fields
  9444. if (!empty($this->empty_signature_appearance)) {
  9445. foreach ($this->empty_signature_appearance as $key => $esa) {
  9446. // widget annotation for empty signature
  9447. $out = $this->_getobj($esa['objid'])."\n";
  9448. $out .= '<< /Type /Annot';
  9449. $out .= ' /Subtype /Widget';
  9450. $out .= ' /Rect ['.$esa['rect'].']';
  9451. $out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
  9452. $out .= ' /F 4';
  9453. $out .= ' /FT /Sig';
  9454. $signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
  9455. $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
  9456. $out .= ' /Ff 0';
  9457. $out .= ' >>';
  9458. $out .= "\n".'endobj';
  9459. $this->_out($out);
  9460. }
  9461. }
  9462. // Signature
  9463. if ($this->sign AND isset($this->signature_data['cert_type'])) {
  9464. // widget annotation for signature
  9465. $out = $this->_getobj($this->sig_obj_id)."\n";
  9466. $out .= '<< /Type /Annot';
  9467. $out .= ' /Subtype /Widget';
  9468. $out .= ' /Rect ['.$this->signature_appearance['rect'].']';
  9469. $out .= ' /P '.$this->page_obj_id[($this->signature_appearance['page'])].' 0 R'; // link to signature appearance page
  9470. $out .= ' /F 4';
  9471. $out .= ' /FT /Sig';
  9472. $out .= ' /T '.$this->_textstring($this->signature_appearance['name'], $this->sig_obj_id);
  9473. $out .= ' /Ff 0';
  9474. $out .= ' /V '.($this->sig_obj_id + 1).' 0 R';
  9475. $out .= ' >>';
  9476. $out .= "\n".'endobj';
  9477. $this->_out($out);
  9478. // signature
  9479. $this->_putsignature();
  9480. }
  9481. // Info
  9482. $objid_info = $this->_putinfo();
  9483. // Catalog
  9484. $objid_catalog = $this->_putcatalog();
  9485. // Cross-ref
  9486. $o = $this->bufferlen;
  9487. // XREF section
  9488. $this->_out('xref');
  9489. $this->_out('0 '.($this->n + 1));
  9490. $this->_out('0000000000 65535 f ');
  9491. $freegen = ($this->n + 2);
  9492. for ($i=1; $i <= $this->n; ++$i) {
  9493. if (!isset($this->offsets[$i]) AND ($i > 1)) {
  9494. $this->_out(sprintf('0000000000 %05d f ', $freegen));
  9495. ++$freegen;
  9496. } else {
  9497. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  9498. }
  9499. }
  9500. // TRAILER
  9501. $out = 'trailer'."\n";
  9502. $out .= '<<';
  9503. $out .= ' /Size '.($this->n + 1);
  9504. $out .= ' /Root '.$objid_catalog.' 0 R';
  9505. $out .= ' /Info '.$objid_info.' 0 R';
  9506. if ($this->encrypted) {
  9507. $out .= ' /Encrypt '.$this->encryptdata['objid'].' 0 R';
  9508. }
  9509. $out .= ' /ID [ <'.$this->file_id.'> <'.$this->file_id.'> ]';
  9510. $out .= ' >>';
  9511. $this->_out($out);
  9512. $this->_out('startxref');
  9513. $this->_out($o);
  9514. $this->_out('%%EOF');
  9515. $this->state = 3; // end-of-doc
  9516. if ($this->diskcache) {
  9517. // remove temporary files used for images
  9518. foreach ($this->imagekeys as $key) {
  9519. // remove temporary files
  9520. unlink($this->images[$key]);
  9521. }
  9522. foreach ($this->fontkeys as $key) {
  9523. // remove temporary files
  9524. unlink($this->fonts[$key]);
  9525. }
  9526. }
  9527. }
  9528. /**
  9529. * Initialize a new page.
  9530. * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  9531. * @param $format (mixed) 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().
  9532. * @protected
  9533. * @see getPageSizeFromFormat(), setPageFormat()
  9534. */
  9535. protected function _beginpage($orientation='', $format='') {
  9536. ++$this->page;
  9537. $this->pageobjects[$this->page] = array();
  9538. $this->setPageBuffer($this->page, '');
  9539. // initialize array for graphics tranformation positions inside a page buffer
  9540. $this->transfmrk[$this->page] = array();
  9541. $this->state = 2;
  9542. if (TCPDF_STATIC::empty_string($orientation)) {
  9543. if (isset($this->CurOrientation)) {
  9544. $orientation = $this->CurOrientation;
  9545. } elseif ($this->fwPt > $this->fhPt) {
  9546. // landscape
  9547. $orientation = 'L';
  9548. } else {
  9549. // portrait
  9550. $orientation = 'P';
  9551. }
  9552. }
  9553. if (TCPDF_STATIC::empty_string($format)) {
  9554. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  9555. $this->setPageOrientation($orientation);
  9556. } else {
  9557. $this->setPageFormat($format, $orientation);
  9558. }
  9559. if ($this->rtl) {
  9560. $this->x = $this->w - $this->rMargin;
  9561. } else {
  9562. $this->x = $this->lMargin;
  9563. }
  9564. $this->y = $this->tMargin;
  9565. if (isset($this->newpagegroup[$this->page])) {
  9566. // start a new group
  9567. $this->currpagegroup = $this->newpagegroup[$this->page];
  9568. $this->pagegroups[$this->currpagegroup] = 1;
  9569. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  9570. ++$this->pagegroups[$this->currpagegroup];
  9571. }
  9572. }
  9573. /**
  9574. * Mark end of page.
  9575. * @protected
  9576. */
  9577. protected function _endpage() {
  9578. $this->setVisibility('all');
  9579. $this->state = 1;
  9580. }
  9581. /**
  9582. * Begin a new object and return the object number.
  9583. * @return int object number
  9584. * @protected
  9585. */
  9586. protected function _newobj() {
  9587. $this->_out($this->_getobj());
  9588. return $this->n;
  9589. }
  9590. /**
  9591. * Return the starting object string for the selected object ID.
  9592. * @param $objid (int) Object ID (leave empty to get a new ID).
  9593. * @return string the starting object string
  9594. * @protected
  9595. * @since 5.8.009 (2010-08-20)
  9596. */
  9597. protected function _getobj($objid='') {
  9598. if ($objid === '') {
  9599. ++$this->n;
  9600. $objid = $this->n;
  9601. }
  9602. $this->offsets[$objid] = $this->bufferlen;
  9603. $this->pageobjects[$this->page][] = $objid;
  9604. return $objid.' 0 obj';
  9605. }
  9606. /**
  9607. * Underline text.
  9608. * @param $x (int) X coordinate
  9609. * @param $y (int) Y coordinate
  9610. * @param $txt (string) text to underline
  9611. * @protected
  9612. */
  9613. protected function _dounderline($x, $y, $txt) {
  9614. $w = $this->GetStringWidth($txt);
  9615. return $this->_dounderlinew($x, $y, $w);
  9616. }
  9617. /**
  9618. * Underline for rectangular text area.
  9619. * @param $x (int) X coordinate
  9620. * @param $y (int) Y coordinate
  9621. * @param $w (int) width to underline
  9622. * @protected
  9623. * @since 4.8.008 (2009-09-29)
  9624. */
  9625. protected function _dounderlinew($x, $y, $w) {
  9626. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9627. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  9628. }
  9629. /**
  9630. * Line through text.
  9631. * @param $x (int) X coordinate
  9632. * @param $y (int) Y coordinate
  9633. * @param $txt (string) text to linethrough
  9634. * @protected
  9635. */
  9636. protected function _dolinethrough($x, $y, $txt) {
  9637. $w = $this->GetStringWidth($txt);
  9638. return $this->_dolinethroughw($x, $y, $w);
  9639. }
  9640. /**
  9641. * Line through for rectangular text area.
  9642. * @param $x (int) X coordinate
  9643. * @param $y (int) Y coordinate
  9644. * @param $w (int) line length (width)
  9645. * @protected
  9646. * @since 4.9.008 (2009-09-29)
  9647. */
  9648. protected function _dolinethroughw($x, $y, $w) {
  9649. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9650. return sprintf('%F %F %F %F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  9651. }
  9652. /**
  9653. * Overline text.
  9654. * @param $x (int) X coordinate
  9655. * @param $y (int) Y coordinate
  9656. * @param $txt (string) text to overline
  9657. * @protected
  9658. * @since 4.9.015 (2010-04-19)
  9659. */
  9660. protected function _dooverline($x, $y, $txt) {
  9661. $w = $this->GetStringWidth($txt);
  9662. return $this->_dooverlinew($x, $y, $w);
  9663. }
  9664. /**
  9665. * Overline for rectangular text area.
  9666. * @param $x (int) X coordinate
  9667. * @param $y (int) Y coordinate
  9668. * @param $w (int) width to overline
  9669. * @protected
  9670. * @since 4.9.015 (2010-04-19)
  9671. */
  9672. protected function _dooverlinew($x, $y, $w) {
  9673. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  9674. return sprintf('%F %F %F %F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  9675. }
  9676. /**
  9677. * Format a data string for meta information
  9678. * @param $s (string) data string to escape.
  9679. * @param $n (int) object ID
  9680. * @return string escaped string.
  9681. * @protected
  9682. */
  9683. protected function _datastring($s, $n=0) {
  9684. if ($n == 0) {
  9685. $n = $this->n;
  9686. }
  9687. $s = $this->_encrypt_data($n, $s);
  9688. return '('. TCPDF_STATIC::_escape($s).')';
  9689. }
  9690. /**
  9691. * Set the document creation timestamp
  9692. * @param $time (mixed) Document creation timestamp in seconds or date-time string.
  9693. * @public
  9694. * @since 5.9.152 (2012-03-23)
  9695. */
  9696. public function setDocCreationTimestamp($time) {
  9697. if (is_string($time)) {
  9698. $time = TCPDF_STATIC::getTimestamp($time);
  9699. }
  9700. $this->doc_creation_timestamp = intval($time);
  9701. }
  9702. /**
  9703. * Set the document modification timestamp
  9704. * @param $time (mixed) Document modification timestamp in seconds or date-time string.
  9705. * @public
  9706. * @since 5.9.152 (2012-03-23)
  9707. */
  9708. public function setDocModificationTimestamp($time) {
  9709. if (is_string($time)) {
  9710. $time = TCPDF_STATIC::getTimestamp($time);
  9711. }
  9712. $this->doc_modification_timestamp = intval($time);
  9713. }
  9714. /**
  9715. * Returns document creation timestamp in seconds.
  9716. * @return (int) Creation timestamp in seconds.
  9717. * @public
  9718. * @since 5.9.152 (2012-03-23)
  9719. */
  9720. public function getDocCreationTimestamp() {
  9721. return $this->doc_creation_timestamp;
  9722. }
  9723. /**
  9724. * Returns document modification timestamp in seconds.
  9725. * @return (int) Modfication timestamp in seconds.
  9726. * @public
  9727. * @since 5.9.152 (2012-03-23)
  9728. */
  9729. public function getDocModificationTimestamp() {
  9730. return $this->doc_modification_timestamp;
  9731. }
  9732. /**
  9733. * Returns a formatted date for meta information
  9734. * @param $n (int) Object ID.
  9735. * @param $timestamp (int) Timestamp to convert.
  9736. * @return string escaped date string.
  9737. * @protected
  9738. * @since 4.6.028 (2009-08-25)
  9739. */
  9740. protected function _datestring($n=0, $timestamp=0) {
  9741. if ((empty($timestamp)) OR ($timestamp < 0)) {
  9742. $timestamp = $this->doc_creation_timestamp;
  9743. }
  9744. return $this->_datastring('D:'.TCPDF_STATIC::getFormattedDate($timestamp), $n);
  9745. }
  9746. /**
  9747. * Format a text string for meta information
  9748. * @param $s (string) string to escape.
  9749. * @param $n (int) object ID
  9750. * @return string escaped string.
  9751. * @protected
  9752. */
  9753. protected function _textstring($s, $n=0) {
  9754. if ($this->isunicode) {
  9755. //Convert string to UTF-16BE
  9756. $s = TCPDF_FONTS::UTF8ToUTF16BE($s, true, $this->isunicode, $this->CurrentFont);
  9757. }
  9758. return $this->_datastring($s, $n);
  9759. }
  9760. /**
  9761. * THIS METHOD IS DEPRECATED
  9762. * Format a text string
  9763. * @param $s (string) string to escape.
  9764. * @return string escaped string.
  9765. * @protected
  9766. * @deprecated
  9767. */
  9768. protected function _escapetext($s) {
  9769. if ($this->isunicode) {
  9770. if (($this->CurrentFont['type'] == 'core') OR ($this->CurrentFont['type'] == 'TrueType') OR ($this->CurrentFont['type'] == 'Type1')) {
  9771. $s = TCPDF_FONTS::UTF8ToLatin1($s, $this->isunicode, $this->CurrentFont);
  9772. } else {
  9773. //Convert string to UTF-16BE and reverse RTL language
  9774. $s = TCPDF_FONTS::utf8StrRev($s, false, $this->tmprtl, $this->isunicode, $this->CurrentFont);
  9775. }
  9776. }
  9777. return TCPDF_STATIC::_escape($s);
  9778. }
  9779. /**
  9780. * get raw output stream.
  9781. * @param $s (string) string to output.
  9782. * @param $n (int) object reference for encryption mode
  9783. * @protected
  9784. * @author Nicola Asuni
  9785. * @since 5.5.000 (2010-06-22)
  9786. */
  9787. protected function _getrawstream($s, $n=0) {
  9788. if ($n <= 0) {
  9789. // default to current object
  9790. $n = $this->n;
  9791. }
  9792. return $this->_encrypt_data($n, $s);
  9793. }
  9794. /**
  9795. * Format output stream (DEPRECATED).
  9796. * @param $s (string) string to output.
  9797. * @param $n (int) object reference for encryption mode
  9798. * @protected
  9799. * @deprecated
  9800. */
  9801. protected function _getstream($s, $n=0) {
  9802. return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
  9803. }
  9804. /**
  9805. * Output a stream (DEPRECATED).
  9806. * @param $s (string) string to output.
  9807. * @param $n (int) object reference for encryption mode
  9808. * @protected
  9809. * @deprecated
  9810. */
  9811. protected function _putstream($s, $n=0) {
  9812. $this->_out($this->_getstream($s, $n));
  9813. }
  9814. /**
  9815. * Output a string to the document.
  9816. * @param $s (string) string to output.
  9817. * @protected
  9818. */
  9819. protected function _out($s) {
  9820. if ($this->state == 2) {
  9821. if ($this->inxobj) {
  9822. // we are inside an XObject template
  9823. $this->xobjects[$this->xobjid]['outdata'] .= $s."\n";
  9824. } elseif ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
  9825. // puts data before page footer
  9826. $pagebuff = $this->getPageBuffer($this->page);
  9827. $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
  9828. $footer = substr($pagebuff, -$this->footerlen[$this->page]);
  9829. $this->setPageBuffer($this->page, $page.$s."\n".$footer);
  9830. // update footer position
  9831. $this->footerpos[$this->page] += strlen($s."\n");
  9832. } else {
  9833. // set page data
  9834. $this->setPageBuffer($this->page, $s."\n", true);
  9835. }
  9836. } elseif ($this->state > 0) {
  9837. // set general data
  9838. $this->setBuffer($s."\n");
  9839. }
  9840. }
  9841. /**
  9842. * Set header font.
  9843. * @param $font (array) font
  9844. * @public
  9845. * @since 1.1
  9846. */
  9847. public function setHeaderFont($font) {
  9848. $this->header_font = $font;
  9849. }
  9850. /**
  9851. * Get header font.
  9852. * @return array()
  9853. * @public
  9854. * @since 4.0.012 (2008-07-24)
  9855. */
  9856. public function getHeaderFont() {
  9857. return $this->header_font;
  9858. }
  9859. /**
  9860. * Set footer font.
  9861. * @param $font (array) font
  9862. * @public
  9863. * @since 1.1
  9864. */
  9865. public function setFooterFont($font) {
  9866. $this->footer_font = $font;
  9867. }
  9868. /**
  9869. * Get Footer font.
  9870. * @return array()
  9871. * @public
  9872. * @since 4.0.012 (2008-07-24)
  9873. */
  9874. public function getFooterFont() {
  9875. return $this->footer_font;
  9876. }
  9877. /**
  9878. * Set language array.
  9879. * @param $language (array)
  9880. * @public
  9881. * @since 1.1
  9882. */
  9883. public function setLanguageArray($language) {
  9884. $this->l = $language;
  9885. if (isset($this->l['a_meta_dir'])) {
  9886. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  9887. } else {
  9888. $this->rtl = false;
  9889. }
  9890. }
  9891. /**
  9892. * Returns the PDF data.
  9893. * @public
  9894. */
  9895. public function getPDFData() {
  9896. if ($this->state < 3) {
  9897. $this->Close();
  9898. }
  9899. return $this->buffer;
  9900. }
  9901. /**
  9902. * Output anchor link.
  9903. * @param $url (string) 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;)
  9904. * @param $name (string) link name
  9905. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  9906. * @param $firstline (boolean) if true prints only the first line and return the remaining string.
  9907. * @param $color (array) array of RGB text color
  9908. * @param $style (string) font style (U, D, B, I)
  9909. * @param $firstblock (boolean) if true the string is the starting of a line.
  9910. * @return the number of cells used or the remaining text if $firstline = true;
  9911. * @public
  9912. */
  9913. public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
  9914. if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
  9915. // convert url to internal link
  9916. $lnkdata = explode(',', $url);
  9917. if (isset($lnkdata[0])) {
  9918. $page = intval(substr($lnkdata[0], 1));
  9919. if (empty($page) OR ($page <= 0)) {
  9920. $page = $this->page;
  9921. }
  9922. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  9923. $lnky = floatval($lnkdata[1]);
  9924. } else {
  9925. $lnky = 0;
  9926. }
  9927. $url = $this->AddLink();
  9928. $this->SetLink($url, $lnky, $page);
  9929. }
  9930. }
  9931. // store current settings
  9932. $prevcolor = $this->fgcolor;
  9933. $prevstyle = $this->FontStyle;
  9934. if (empty($color)) {
  9935. $this->SetTextColorArray($this->htmlLinkColorArray);
  9936. } else {
  9937. $this->SetTextColorArray($color);
  9938. }
  9939. if ($style == -1) {
  9940. $this->SetFont('', $this->FontStyle.$this->htmlLinkFontStyle);
  9941. } else {
  9942. $this->SetFont('', $this->FontStyle.$style);
  9943. }
  9944. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  9945. // restore settings
  9946. $this->SetFont('', $prevstyle);
  9947. $this->SetTextColorArray($prevcolor);
  9948. return $ret;
  9949. }
  9950. /**
  9951. * Converts pixels to User's Units.
  9952. * @param $px (int) pixels
  9953. * @return float value in user's unit
  9954. * @public
  9955. * @see setImageScale(), getImageScale()
  9956. */
  9957. public function pixelsToUnits($px) {
  9958. return ($px / ($this->imgscale * $this->k));
  9959. }
  9960. /**
  9961. * Reverse function for htmlentities.
  9962. * Convert entities in UTF-8.
  9963. * @param $text_to_convert (string) Text to convert.
  9964. * @return string converted text string
  9965. * @public
  9966. */
  9967. public function unhtmlentities($text_to_convert) {
  9968. return @html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  9969. }
  9970. // ENCRYPTION METHODS ----------------------------------
  9971. /**
  9972. * Compute encryption key depending on object number where the encrypted data is stored.
  9973. * This is used for all strings and streams without crypt filter specifier.
  9974. * @param $n (int) object number
  9975. * @return int object key
  9976. * @protected
  9977. * @author Nicola Asuni
  9978. * @since 2.0.000 (2008-01-02)
  9979. */
  9980. protected function _objectkey($n) {
  9981. $objkey = $this->encryptdata['key'].pack('VXxx', $n);
  9982. if ($this->encryptdata['mode'] == 2) { // AES-128
  9983. // AES padding
  9984. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  9985. }
  9986. $objkey = substr(TCPDF_STATIC::_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  9987. $objkey = substr($objkey, 0, 16);
  9988. return $objkey;
  9989. }
  9990. /**
  9991. * Encrypt the input string.
  9992. * @param $n (int) object number
  9993. * @param $s (string) data string to encrypt
  9994. * @return encrypted string
  9995. * @protected
  9996. * @author Nicola Asuni
  9997. * @since 5.0.005 (2010-05-11)
  9998. */
  9999. protected function _encrypt_data($n, $s) {
  10000. if (!$this->encrypted) {
  10001. return $s;
  10002. }
  10003. switch ($this->encryptdata['mode']) {
  10004. case 0: // RC4-40
  10005. case 1: { // RC4-128
  10006. $s = TCPDF_STATIC::_RC4($this->_objectkey($n), $s, $this->last_enc_key, $this->last_enc_key_c);
  10007. break;
  10008. }
  10009. case 2: { // AES-128
  10010. $s = TCPDF_STATIC::_AES($this->_objectkey($n), $s);
  10011. break;
  10012. }
  10013. case 3: { // AES-256
  10014. $s = TCPDF_STATIC::_AES($this->encryptdata['key'], $s);
  10015. break;
  10016. }
  10017. }
  10018. return $s;
  10019. }
  10020. /**
  10021. * Put encryption on PDF document.
  10022. * @protected
  10023. * @author Nicola Asuni
  10024. * @since 2.0.000 (2008-01-02)
  10025. */
  10026. protected function _putencryption() {
  10027. if (!$this->encrypted) {
  10028. return;
  10029. }
  10030. $this->encryptdata['objid'] = $this->_newobj();
  10031. $out = '<<';
  10032. if (!isset($this->encryptdata['Filter']) OR empty($this->encryptdata['Filter'])) {
  10033. $this->encryptdata['Filter'] = 'Standard';
  10034. }
  10035. $out .= ' /Filter /'.$this->encryptdata['Filter'];
  10036. if (isset($this->encryptdata['SubFilter']) AND !empty($this->encryptdata['SubFilter'])) {
  10037. $out .= ' /SubFilter /'.$this->encryptdata['SubFilter'];
  10038. }
  10039. if (!isset($this->encryptdata['V']) OR empty($this->encryptdata['V'])) {
  10040. $this->encryptdata['V'] = 1;
  10041. }
  10042. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  10043. $out .= ' /V '.$this->encryptdata['V'];
  10044. if (isset($this->encryptdata['Length']) AND !empty($this->encryptdata['Length'])) {
  10045. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  10046. $out .= ' /Length '.$this->encryptdata['Length'];
  10047. } else {
  10048. $out .= ' /Length 40';
  10049. }
  10050. if ($this->encryptdata['V'] >= 4) {
  10051. if (!isset($this->encryptdata['StmF']) OR empty($this->encryptdata['StmF'])) {
  10052. $this->encryptdata['StmF'] = 'Identity';
  10053. }
  10054. if (!isset($this->encryptdata['StrF']) OR empty($this->encryptdata['StrF'])) {
  10055. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10056. $this->encryptdata['StrF'] = 'Identity';
  10057. }
  10058. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  10059. if (isset($this->encryptdata['CF']) AND !empty($this->encryptdata['CF'])) {
  10060. $out .= ' /CF <<';
  10061. $out .= ' /'.$this->encryptdata['StmF'].' <<';
  10062. $out .= ' /Type /CryptFilter';
  10063. if (isset($this->encryptdata['CF']['CFM']) AND !empty($this->encryptdata['CF']['CFM'])) {
  10064. // The method used
  10065. $out .= ' /CFM /'.$this->encryptdata['CF']['CFM'];
  10066. if ($this->encryptdata['pubkey']) {
  10067. $out .= ' /Recipients [';
  10068. foreach ($this->encryptdata['Recipients'] as $rec) {
  10069. $out .= ' <'.$rec.'>';
  10070. }
  10071. $out .= ' ]';
  10072. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) {
  10073. $out .= ' /EncryptMetadata false';
  10074. } else {
  10075. $out .= ' /EncryptMetadata true';
  10076. }
  10077. }
  10078. } else {
  10079. $out .= ' /CFM /None';
  10080. }
  10081. if (isset($this->encryptdata['CF']['AuthEvent']) AND !empty($this->encryptdata['CF']['AuthEvent'])) {
  10082. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  10083. $out .= ' /AuthEvent /'.$this->encryptdata['CF']['AuthEvent'];
  10084. } else {
  10085. $out .= ' /AuthEvent /DocOpen';
  10086. }
  10087. if (isset($this->encryptdata['CF']['Length']) AND !empty($this->encryptdata['CF']['Length'])) {
  10088. // The bit length of the encryption key.
  10089. $out .= ' /Length '.$this->encryptdata['CF']['Length'];
  10090. }
  10091. $out .= ' >> >>';
  10092. }
  10093. // The name of the crypt filter that shall be used by default when decrypting streams.
  10094. $out .= ' /StmF /'.$this->encryptdata['StmF'];
  10095. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  10096. $out .= ' /StrF /'.$this->encryptdata['StrF'];
  10097. if (isset($this->encryptdata['EFF']) AND !empty($this->encryptdata['EFF'])) {
  10098. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  10099. $out .= ' /EFF /'.$this->encryptdata[''];
  10100. }
  10101. }
  10102. // Additional encryption dictionary entries for the standard security handler
  10103. if ($this->encryptdata['pubkey']) {
  10104. if (($this->encryptdata['V'] < 4) AND isset($this->encryptdata['Recipients']) AND !empty($this->encryptdata['Recipients'])) {
  10105. $out .= ' /Recipients [';
  10106. foreach ($this->encryptdata['Recipients'] as $rec) {
  10107. $out .= ' <'.$rec.'>';
  10108. }
  10109. $out .= ' ]';
  10110. }
  10111. } else {
  10112. $out .= ' /R';
  10113. if ($this->encryptdata['V'] == 5) { // AES-256
  10114. $out .= ' 5';
  10115. $out .= ' /OE ('.TCPDF_STATIC::_escape($this->encryptdata['OE']).')';
  10116. $out .= ' /UE ('.TCPDF_STATIC::_escape($this->encryptdata['UE']).')';
  10117. $out .= ' /Perms ('.TCPDF_STATIC::_escape($this->encryptdata['perms']).')';
  10118. } elseif ($this->encryptdata['V'] == 4) { // AES-128
  10119. $out .= ' 4';
  10120. } elseif ($this->encryptdata['V'] < 2) { // RC-40
  10121. $out .= ' 2';
  10122. } else { // RC-128
  10123. $out .= ' 3';
  10124. }
  10125. $out .= ' /O ('.TCPDF_STATIC::_escape($this->encryptdata['O']).')';
  10126. $out .= ' /U ('.TCPDF_STATIC::_escape($this->encryptdata['U']).')';
  10127. $out .= ' /P '.$this->encryptdata['P'];
  10128. if (isset($this->encryptdata['EncryptMetadata']) AND (!$this->encryptdata['EncryptMetadata'])) {
  10129. $out .= ' /EncryptMetadata false';
  10130. } else {
  10131. $out .= ' /EncryptMetadata true';
  10132. }
  10133. }
  10134. $out .= ' >>';
  10135. $out .= "\n".'endobj';
  10136. $this->_out($out);
  10137. }
  10138. /**
  10139. * Compute U value (used for encryption)
  10140. * @return string U value
  10141. * @protected
  10142. * @since 2.0.000 (2008-01-02)
  10143. * @author Nicola Asuni
  10144. */
  10145. protected function _Uvalue() {
  10146. if ($this->encryptdata['mode'] == 0) { // RC4-40
  10147. return TCPDF_STATIC::_RC4($this->encryptdata['key'], TCPDF_STATIC::$enc_padding, $this->last_enc_key, $this->last_enc_key_c);
  10148. } elseif ($this->encryptdata['mode'] < 3) { // RC4-128, AES-128
  10149. $tmp = TCPDF_STATIC::_md5_16(TCPDF_STATIC::$enc_padding.$this->encryptdata['fileid']);
  10150. $enc = TCPDF_STATIC::_RC4($this->encryptdata['key'], $tmp, $this->last_enc_key, $this->last_enc_key_c);
  10151. $len = strlen($tmp);
  10152. for ($i = 1; $i <= 19; ++$i) {
  10153. $ek = '';
  10154. for ($j = 0; $j < $len; ++$j) {
  10155. $ek .= chr(ord($this->encryptdata['key'][$j]) ^ $i);
  10156. }
  10157. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10158. }
  10159. $enc .= str_repeat("\x00", 16);
  10160. return substr($enc, 0, 32);
  10161. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10162. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10163. // User Validation Salt
  10164. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  10165. // User Key Salt
  10166. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  10167. return hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UVS'], true).$this->encryptdata['UVS'].$this->encryptdata['UKS'];
  10168. }
  10169. }
  10170. /**
  10171. * Compute UE value (used for encryption)
  10172. * @return string UE value
  10173. * @protected
  10174. * @since 5.9.006 (2010-10-19)
  10175. * @author Nicola Asuni
  10176. */
  10177. protected function _UEvalue() {
  10178. $hashkey = hash('sha256', $this->encryptdata['user_password'].$this->encryptdata['UKS'], true);
  10179. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  10180. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  10181. }
  10182. /**
  10183. * Compute O value (used for encryption)
  10184. * @return string O value
  10185. * @protected
  10186. * @since 2.0.000 (2008-01-02)
  10187. * @author Nicola Asuni
  10188. */
  10189. protected function _Ovalue() {
  10190. if ($this->encryptdata['mode'] < 3) { // RC4-40, RC4-128, AES-128
  10191. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['owner_password']);
  10192. if ($this->encryptdata['mode'] > 0) {
  10193. for ($i = 0; $i < 50; ++$i) {
  10194. $tmp = TCPDF_STATIC::_md5_16($tmp);
  10195. }
  10196. }
  10197. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  10198. $enc = TCPDF_STATIC::_RC4($owner_key, $this->encryptdata['user_password'], $this->last_enc_key, $this->last_enc_key_c);
  10199. if ($this->encryptdata['mode'] > 0) {
  10200. $len = strlen($owner_key);
  10201. for ($i = 1; $i <= 19; ++$i) {
  10202. $ek = '';
  10203. for ($j = 0; $j < $len; ++$j) {
  10204. $ek .= chr(ord($owner_key[$j]) ^ $i);
  10205. }
  10206. $enc = TCPDF_STATIC::_RC4($ek, $enc, $this->last_enc_key, $this->last_enc_key_c);
  10207. }
  10208. }
  10209. return $enc;
  10210. } elseif ($this->encryptdata['mode'] == 3) { // AES-256
  10211. $seed = TCPDF_STATIC::_md5_16(TCPDF_STATIC::getRandomSeed());
  10212. // Owner Validation Salt
  10213. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  10214. // Owner Key Salt
  10215. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  10216. return hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OVS'].$this->encryptdata['U'], true).$this->encryptdata['OVS'].$this->encryptdata['OKS'];
  10217. }
  10218. }
  10219. /**
  10220. * Compute OE value (used for encryption)
  10221. * @return string OE value
  10222. * @protected
  10223. * @since 5.9.006 (2010-10-19)
  10224. * @author Nicola Asuni
  10225. */
  10226. protected function _OEvalue() {
  10227. $hashkey = hash('sha256', $this->encryptdata['owner_password'].$this->encryptdata['OKS'].$this->encryptdata['U'], true);
  10228. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  10229. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  10230. }
  10231. /**
  10232. * Convert password for AES-256 encryption mode
  10233. * @param $password (string) password
  10234. * @return string password
  10235. * @protected
  10236. * @since 5.9.006 (2010-10-19)
  10237. * @author Nicola Asuni
  10238. */
  10239. protected function _fixAES256Password($password) {
  10240. $psw = ''; // password to be returned
  10241. $psw_array = TCPDF_FONTS::utf8Bidi(TCPDF_FONTS::UTF8StringToArray($password, $this->isunicode, $this->CurrentFont), $password, $this->rtl, $this->isunicode, $this->CurrentFont);
  10242. foreach ($psw_array as $c) {
  10243. $psw .= TCPDF_FONTS::unichr($c, $this->isunicode);
  10244. }
  10245. return substr($psw, 0, 127);
  10246. }
  10247. /**
  10248. * Compute encryption key
  10249. * @protected
  10250. * @since 2.0.000 (2008-01-02)
  10251. * @author Nicola Asuni
  10252. */
  10253. protected function _generateencryptionkey() {
  10254. $keybytelen = ($this->encryptdata['Length'] / 8);
  10255. if (!$this->encryptdata['pubkey']) { // standard mode
  10256. if ($this->encryptdata['mode'] == 3) { // AES-256
  10257. // generate 256 bit random key
  10258. $this->encryptdata['key'] = substr(hash('sha256', TCPDF_STATIC::getRandomSeed(), true), 0, $keybytelen);
  10259. // truncate passwords
  10260. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  10261. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  10262. // Compute U value
  10263. $this->encryptdata['U'] = $this->_Uvalue();
  10264. // Compute UE value
  10265. $this->encryptdata['UE'] = $this->_UEvalue();
  10266. // Compute O value
  10267. $this->encryptdata['O'] = $this->_Ovalue();
  10268. // Compute OE value
  10269. $this->encryptdata['OE'] = $this->_OEvalue();
  10270. // Compute P value
  10271. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10272. // Computing the encryption dictionary's Perms (permissions) value
  10273. $perms = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  10274. $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
  10275. if (isset($this->encryptdata['CF']['EncryptMetadata']) AND (!$this->encryptdata['CF']['EncryptMetadata'])) { // byte 8
  10276. $perms .= 'F';
  10277. } else {
  10278. $perms .= 'T';
  10279. }
  10280. $perms .= 'adb'; // bytes 9-11
  10281. $perms .= 'nick'; // bytes 12-15
  10282. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
  10283. $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
  10284. } else { // RC4-40, RC4-128, AES-128
  10285. // Pad passwords
  10286. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10287. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'].TCPDF_STATIC::$enc_padding, 0, 32);
  10288. // Compute O value
  10289. $this->encryptdata['O'] = $this->_Ovalue();
  10290. // get default permissions (reverse byte order)
  10291. $permissions = TCPDF_STATIC::getEncPermissionsString($this->encryptdata['protection']);
  10292. // Compute encryption key
  10293. $tmp = TCPDF_STATIC::_md5_16($this->encryptdata['user_password'].$this->encryptdata['O'].$permissions.$this->encryptdata['fileid']);
  10294. if ($this->encryptdata['mode'] > 0) {
  10295. for ($i = 0; $i < 50; ++$i) {
  10296. $tmp = TCPDF_STATIC::_md5_16(substr($tmp, 0, $keybytelen));
  10297. }
  10298. }
  10299. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  10300. // Compute U value
  10301. $this->encryptdata['U'] = $this->_Uvalue();
  10302. // Compute P value
  10303. $this->encryptdata['P'] = $this->encryptdata['protection'];
  10304. }
  10305. } else { // Public-Key mode
  10306. // random 20-byte seed
  10307. $seed = sha1(TCPDF_STATIC::getRandomSeed(), true);
  10308. $recipient_bytes = '';
  10309. foreach ($this->encryptdata['pubkeys'] as $pubkey) {
  10310. // for each public certificate
  10311. if (isset($pubkey['p'])) {
  10312. $pkprotection = TCPDF_STATIC::getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  10313. } else {
  10314. $pkprotection = $this->encryptdata['protection'];
  10315. }
  10316. // get default permissions (reverse byte order)
  10317. $pkpermissions = TCPDF_STATIC::getEncPermissionsString($pkprotection);
  10318. // envelope data
  10319. $envelope = $seed.$pkpermissions;
  10320. // write the envelope data to a temporary file
  10321. $tempkeyfile = TCPDF_STATIC::getObjFilename('key');
  10322. $f = fopen($tempkeyfile, 'wb');
  10323. if (!$f) {
  10324. $this->Error('Unable to create temporary key file: '.$tempkeyfile);
  10325. }
  10326. $envelope_length = strlen($envelope);
  10327. fwrite($f, $envelope, $envelope_length);
  10328. fclose($f);
  10329. $tempencfile = TCPDF_STATIC::getObjFilename('enc');
  10330. if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED)) {
  10331. $this->Error('Unable to encrypt the file: '.$tempkeyfile);
  10332. }
  10333. unlink($tempkeyfile);
  10334. // read encryption signature
  10335. $signature = file_get_contents($tempencfile, false, null, $envelope_length);
  10336. unlink($tempencfile);
  10337. // extract signature
  10338. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  10339. $tmparr = explode("\n\n", $signature);
  10340. $signature = trim($tmparr[1]);
  10341. unset($tmparr);
  10342. // decode signature
  10343. $signature = base64_decode($signature);
  10344. // convert signature to hex
  10345. $hexsignature = current(unpack('H*', $signature));
  10346. // store signature on recipients array
  10347. $this->encryptdata['Recipients'][] = $hexsignature;
  10348. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  10349. $recipient_bytes .= $signature;
  10350. }
  10351. // calculate encryption key
  10352. if ($this->encryptdata['mode'] == 3) { // AES-256
  10353. $this->encryptdata['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
  10354. } else { // RC4-40, RC4-128, AES-128
  10355. $this->encryptdata['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
  10356. }
  10357. }
  10358. }
  10359. /**
  10360. * Set document protection
  10361. * Remark: the protection against modification is for people who have the full Acrobat product.
  10362. * 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.
  10363. * 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.
  10364. * @param $permissions (Array) 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>
  10365. * @param $user_pass (String) user password. Empty by default.
  10366. * @param $owner_pass (String) owner password. If not specified, a random value is used.
  10367. * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  10368. * @param $pubkeys (String) 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')))
  10369. * @public
  10370. * @since 2.0.000 (2008-01-02)
  10371. * @author Nicola Asuni
  10372. */
  10373. 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) {
  10374. if ($this->pdfa_mode) {
  10375. // encryption is not allowed in PDF/A mode
  10376. return;
  10377. }
  10378. $this->encryptdata['protection'] = TCPDF_STATIC::getUserPermissionCode($permissions, $mode);
  10379. if (($pubkeys !== null) AND (is_array($pubkeys))) {
  10380. // public-key mode
  10381. $this->encryptdata['pubkeys'] = $pubkeys;
  10382. if ($mode == 0) {
  10383. // public-Key Security requires at least 128 bit
  10384. $mode = 1;
  10385. }
  10386. if (!function_exists('openssl_pkcs7_encrypt')) {
  10387. $this->Error('Public-Key Security requires openssl library.');
  10388. }
  10389. // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  10390. $this->encryptdata['pubkey'] = true;
  10391. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  10392. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  10393. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  10394. } else {
  10395. // standard mode (password mode)
  10396. $this->encryptdata['pubkey'] = false;
  10397. $this->encryptdata['Filter'] = 'Standard';
  10398. $this->encryptdata['StmF'] = 'StdCF';
  10399. $this->encryptdata['StrF'] = 'StdCF';
  10400. }
  10401. if ($mode > 1) { // AES
  10402. if (!extension_loaded('mcrypt')) {
  10403. $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
  10404. }
  10405. if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false) {
  10406. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  10407. }
  10408. if (($mode == 3) AND !function_exists('hash')) {
  10409. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  10410. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  10411. }
  10412. }
  10413. if ($owner_pass === null) {
  10414. $owner_pass = md5(TCPDF_STATIC::getRandomSeed());
  10415. }
  10416. $this->encryptdata['user_password'] = $user_pass;
  10417. $this->encryptdata['owner_password'] = $owner_pass;
  10418. $this->encryptdata['mode'] = $mode;
  10419. switch ($mode) {
  10420. case 0: { // RC4 40 bit
  10421. $this->encryptdata['V'] = 1;
  10422. $this->encryptdata['Length'] = 40;
  10423. $this->encryptdata['CF']['CFM'] = 'V2';
  10424. break;
  10425. }
  10426. case 1: { // RC4 128 bit
  10427. $this->encryptdata['V'] = 2;
  10428. $this->encryptdata['Length'] = 128;
  10429. $this->encryptdata['CF']['CFM'] = 'V2';
  10430. if ($this->encryptdata['pubkey']) {
  10431. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  10432. $this->encryptdata['Recipients'] = array();
  10433. }
  10434. break;
  10435. }
  10436. case 2: { // AES 128 bit
  10437. $this->encryptdata['V'] = 4;
  10438. $this->encryptdata['Length'] = 128;
  10439. $this->encryptdata['CF']['CFM'] = 'AESV2';
  10440. $this->encryptdata['CF']['Length'] = 128;
  10441. if ($this->encryptdata['pubkey']) {
  10442. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10443. $this->encryptdata['Recipients'] = array();
  10444. }
  10445. break;
  10446. }
  10447. case 3: { // AES 256 bit
  10448. $this->encryptdata['V'] = 5;
  10449. $this->encryptdata['Length'] = 256;
  10450. $this->encryptdata['CF']['CFM'] = 'AESV3';
  10451. $this->encryptdata['CF']['Length'] = 256;
  10452. if ($this->encryptdata['pubkey']) {
  10453. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  10454. $this->encryptdata['Recipients'] = array();
  10455. }
  10456. break;
  10457. }
  10458. }
  10459. $this->encrypted = true;
  10460. $this->encryptdata['fileid'] = TCPDF_STATIC::convertHexStringToString($this->file_id);
  10461. $this->_generateencryptionkey();
  10462. }
  10463. // END OF ENCRYPTION FUNCTIONS -------------------------
  10464. // START TRANSFORMATIONS SECTION -----------------------
  10465. /**
  10466. * Starts a 2D tranformation saving current graphic state.
  10467. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  10468. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10469. * @public
  10470. * @since 2.1.000 (2008-01-07)
  10471. * @see StartTransform(), StopTransform()
  10472. */
  10473. public function StartTransform() {
  10474. if ($this->state != 2) {
  10475. return;
  10476. }
  10477. $this->_out('q');
  10478. if ($this->inxobj) {
  10479. // we are inside an XObject template
  10480. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10481. } else {
  10482. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  10483. }
  10484. ++$this->transfmatrix_key;
  10485. $this->transfmatrix[$this->transfmatrix_key] = array();
  10486. }
  10487. /**
  10488. * Stops a 2D tranformation restoring previous graphic state.
  10489. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  10490. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  10491. * @public
  10492. * @since 2.1.000 (2008-01-07)
  10493. * @see StartTransform(), StopTransform()
  10494. */
  10495. public function StopTransform() {
  10496. if ($this->state != 2) {
  10497. return;
  10498. }
  10499. $this->_out('Q');
  10500. if (isset($this->transfmatrix[$this->transfmatrix_key])) {
  10501. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  10502. --$this->transfmatrix_key;
  10503. }
  10504. if ($this->inxobj) {
  10505. // we are inside an XObject template
  10506. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  10507. } else {
  10508. array_pop($this->transfmrk[$this->page]);
  10509. }
  10510. }
  10511. /**
  10512. * Horizontal Scaling.
  10513. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10514. * @param $x (int) abscissa of the scaling center. Default is current x position
  10515. * @param $y (int) ordinate of the scaling center. Default is current y position
  10516. * @public
  10517. * @since 2.1.000 (2008-01-07)
  10518. * @see StartTransform(), StopTransform()
  10519. */
  10520. public function ScaleX($s_x, $x='', $y='') {
  10521. $this->Scale($s_x, 100, $x, $y);
  10522. }
  10523. /**
  10524. * Vertical Scaling.
  10525. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10526. * @param $x (int) abscissa of the scaling center. Default is current x position
  10527. * @param $y (int) ordinate of the scaling center. Default is current y position
  10528. * @public
  10529. * @since 2.1.000 (2008-01-07)
  10530. * @see StartTransform(), StopTransform()
  10531. */
  10532. public function ScaleY($s_y, $x='', $y='') {
  10533. $this->Scale(100, $s_y, $x, $y);
  10534. }
  10535. /**
  10536. * Vertical and horizontal proportional Scaling.
  10537. * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
  10538. * @param $x (int) abscissa of the scaling center. Default is current x position
  10539. * @param $y (int) ordinate of the scaling center. Default is current y position
  10540. * @public
  10541. * @since 2.1.000 (2008-01-07)
  10542. * @see StartTransform(), StopTransform()
  10543. */
  10544. public function ScaleXY($s, $x='', $y='') {
  10545. $this->Scale($s, $s, $x, $y);
  10546. }
  10547. /**
  10548. * Vertical and horizontal non-proportional Scaling.
  10549. * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
  10550. * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
  10551. * @param $x (int) abscissa of the scaling center. Default is current x position
  10552. * @param $y (int) ordinate of the scaling center. Default is current y position
  10553. * @public
  10554. * @since 2.1.000 (2008-01-07)
  10555. * @see StartTransform(), StopTransform()
  10556. */
  10557. public function Scale($s_x, $s_y, $x='', $y='') {
  10558. if ($x === '') {
  10559. $x = $this->x;
  10560. }
  10561. if ($y === '') {
  10562. $y = $this->y;
  10563. }
  10564. if (($s_x == 0) OR ($s_y == 0)) {
  10565. $this->Error('Please do not use values equal to zero for scaling');
  10566. }
  10567. $y = ($this->h - $y) * $this->k;
  10568. $x *= $this->k;
  10569. //calculate elements of transformation matrix
  10570. $s_x /= 100;
  10571. $s_y /= 100;
  10572. $tm = array();
  10573. $tm[0] = $s_x;
  10574. $tm[1] = 0;
  10575. $tm[2] = 0;
  10576. $tm[3] = $s_y;
  10577. $tm[4] = $x * (1 - $s_x);
  10578. $tm[5] = $y * (1 - $s_y);
  10579. //scale the coordinate system
  10580. $this->Transform($tm);
  10581. }
  10582. /**
  10583. * Horizontal Mirroring.
  10584. * @param $x (int) abscissa of the point. Default is current x position
  10585. * @public
  10586. * @since 2.1.000 (2008-01-07)
  10587. * @see StartTransform(), StopTransform()
  10588. */
  10589. public function MirrorH($x='') {
  10590. $this->Scale(-100, 100, $x);
  10591. }
  10592. /**
  10593. * Verical Mirroring.
  10594. * @param $y (int) ordinate of the point. Default is current y position
  10595. * @public
  10596. * @since 2.1.000 (2008-01-07)
  10597. * @see StartTransform(), StopTransform()
  10598. */
  10599. public function MirrorV($y='') {
  10600. $this->Scale(100, -100, '', $y);
  10601. }
  10602. /**
  10603. * Point reflection mirroring.
  10604. * @param $x (int) abscissa of the point. Default is current x position
  10605. * @param $y (int) ordinate of the point. Default is current y position
  10606. * @public
  10607. * @since 2.1.000 (2008-01-07)
  10608. * @see StartTransform(), StopTransform()
  10609. */
  10610. public function MirrorP($x='',$y='') {
  10611. $this->Scale(-100, -100, $x, $y);
  10612. }
  10613. /**
  10614. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  10615. * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
  10616. * @param $x (int) abscissa of the point. Default is current x position
  10617. * @param $y (int) ordinate of the point. Default is current y position
  10618. * @public
  10619. * @since 2.1.000 (2008-01-07)
  10620. * @see StartTransform(), StopTransform()
  10621. */
  10622. public function MirrorL($angle=0, $x='',$y='') {
  10623. $this->Scale(-100, 100, $x, $y);
  10624. $this->Rotate(-2*($angle-90), $x, $y);
  10625. }
  10626. /**
  10627. * Translate graphic object horizontally.
  10628. * @param $t_x (int) movement to the right (or left for RTL)
  10629. * @public
  10630. * @since 2.1.000 (2008-01-07)
  10631. * @see StartTransform(), StopTransform()
  10632. */
  10633. public function TranslateX($t_x) {
  10634. $this->Translate($t_x, 0);
  10635. }
  10636. /**
  10637. * Translate graphic object vertically.
  10638. * @param $t_y (int) movement to the bottom
  10639. * @public
  10640. * @since 2.1.000 (2008-01-07)
  10641. * @see StartTransform(), StopTransform()
  10642. */
  10643. public function TranslateY($t_y) {
  10644. $this->Translate(0, $t_y);
  10645. }
  10646. /**
  10647. * Translate graphic object horizontally and vertically.
  10648. * @param $t_x (int) movement to the right
  10649. * @param $t_y (int) movement to the bottom
  10650. * @public
  10651. * @since 2.1.000 (2008-01-07)
  10652. * @see StartTransform(), StopTransform()
  10653. */
  10654. public function Translate($t_x, $t_y) {
  10655. //calculate elements of transformation matrix
  10656. $tm = array();
  10657. $tm[0] = 1;
  10658. $tm[1] = 0;
  10659. $tm[2] = 0;
  10660. $tm[3] = 1;
  10661. $tm[4] = $t_x * $this->k;
  10662. $tm[5] = -$t_y * $this->k;
  10663. //translate the coordinate system
  10664. $this->Transform($tm);
  10665. }
  10666. /**
  10667. * Rotate object.
  10668. * @param $angle (float) angle in degrees for counter-clockwise rotation
  10669. * @param $x (int) abscissa of the rotation center. Default is current x position
  10670. * @param $y (int) ordinate of the rotation center. Default is current y position
  10671. * @public
  10672. * @since 2.1.000 (2008-01-07)
  10673. * @see StartTransform(), StopTransform()
  10674. */
  10675. public function Rotate($angle, $x='', $y='') {
  10676. if ($x === '') {
  10677. $x = $this->x;
  10678. }
  10679. if ($y === '') {
  10680. $y = $this->y;
  10681. }
  10682. $y = ($this->h - $y) * $this->k;
  10683. $x *= $this->k;
  10684. //calculate elements of transformation matrix
  10685. $tm = array();
  10686. $tm[0] = cos(deg2rad($angle));
  10687. $tm[1] = sin(deg2rad($angle));
  10688. $tm[2] = -$tm[1];
  10689. $tm[3] = $tm[0];
  10690. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  10691. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  10692. //rotate the coordinate system around ($x,$y)
  10693. $this->Transform($tm);
  10694. }
  10695. /**
  10696. * Skew horizontally.
  10697. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10698. * @param $x (int) abscissa of the skewing center. default is current x position
  10699. * @param $y (int) ordinate of the skewing center. default is current y position
  10700. * @public
  10701. * @since 2.1.000 (2008-01-07)
  10702. * @see StartTransform(), StopTransform()
  10703. */
  10704. public function SkewX($angle_x, $x='', $y='') {
  10705. $this->Skew($angle_x, 0, $x, $y);
  10706. }
  10707. /**
  10708. * Skew vertically.
  10709. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10710. * @param $x (int) abscissa of the skewing center. default is current x position
  10711. * @param $y (int) ordinate of the skewing center. default is current y position
  10712. * @public
  10713. * @since 2.1.000 (2008-01-07)
  10714. * @see StartTransform(), StopTransform()
  10715. */
  10716. public function SkewY($angle_y, $x='', $y='') {
  10717. $this->Skew(0, $angle_y, $x, $y);
  10718. }
  10719. /**
  10720. * Skew.
  10721. * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  10722. * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  10723. * @param $x (int) abscissa of the skewing center. default is current x position
  10724. * @param $y (int) ordinate of the skewing center. default is current y position
  10725. * @public
  10726. * @since 2.1.000 (2008-01-07)
  10727. * @see StartTransform(), StopTransform()
  10728. */
  10729. public function Skew($angle_x, $angle_y, $x='', $y='') {
  10730. if ($x === '') {
  10731. $x = $this->x;
  10732. }
  10733. if ($y === '') {
  10734. $y = $this->y;
  10735. }
  10736. if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
  10737. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  10738. }
  10739. $x *= $this->k;
  10740. $y = ($this->h - $y) * $this->k;
  10741. //calculate elements of transformation matrix
  10742. $tm = array();
  10743. $tm[0] = 1;
  10744. $tm[1] = tan(deg2rad($angle_y));
  10745. $tm[2] = tan(deg2rad($angle_x));
  10746. $tm[3] = 1;
  10747. $tm[4] = -$tm[2] * $y;
  10748. $tm[5] = -$tm[1] * $x;
  10749. //skew the coordinate system
  10750. $this->Transform($tm);
  10751. }
  10752. /**
  10753. * Apply graphic transformations.
  10754. * @param $tm (array) transformation matrix
  10755. * @protected
  10756. * @since 2.1.000 (2008-01-07)
  10757. * @see StartTransform(), StopTransform()
  10758. */
  10759. protected function Transform($tm) {
  10760. if ($this->state != 2) {
  10761. return;
  10762. }
  10763. $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  10764. // add tranformation matrix
  10765. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  10766. // update transformation mark
  10767. if ($this->inxobj) {
  10768. // we are inside an XObject template
  10769. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  10770. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  10771. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  10772. }
  10773. } elseif (end($this->transfmrk[$this->page]) !== false) {
  10774. $key = key($this->transfmrk[$this->page]);
  10775. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  10776. }
  10777. }
  10778. // END TRANSFORMATIONS SECTION -------------------------
  10779. // START GRAPHIC FUNCTIONS SECTION ---------------------
  10780. // The following section is based on the code provided by David Hernandez Sanz
  10781. /**
  10782. * 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.
  10783. * @param $width (float) The width.
  10784. * @public
  10785. * @since 1.0
  10786. * @see Line(), Rect(), Cell(), MultiCell()
  10787. */
  10788. public function SetLineWidth($width) {
  10789. //Set line width
  10790. $this->LineWidth = $width;
  10791. $this->linestyleWidth = sprintf('%F w', ($width * $this->k));
  10792. if ($this->state == 2) {
  10793. $this->_out($this->linestyleWidth);
  10794. }
  10795. }
  10796. /**
  10797. * Returns the current the line width.
  10798. * @return int Line width
  10799. * @public
  10800. * @since 2.1.000 (2008-01-07)
  10801. * @see Line(), SetLineWidth()
  10802. */
  10803. public function GetLineWidth() {
  10804. return $this->LineWidth;
  10805. }
  10806. /**
  10807. * Set line style.
  10808. * @param $style (array) Line style. Array with keys among the following:
  10809. * <ul>
  10810. * <li>width (float): Width of the line in user units.</li>
  10811. * <li>cap (string): Type of cap to put on the line. Possible values are:
  10812. * butt, round, square. The difference between "square" and "butt" is that
  10813. * "square" projects a flat end past the end of the line.</li>
  10814. * <li>join (string): Type of join. Possible values are: miter, round,
  10815. * bevel.</li>
  10816. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  10817. * series of length values, which are the lengths of the on and off dashes.
  10818. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  10819. * 1 off, 2 on, 1 off, ...</li>
  10820. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  10821. * the point at which the pattern starts.</li>
  10822. * <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>
  10823. * </ul>
  10824. * @param $ret (boolean) if true do not send the command.
  10825. * @return string the PDF command
  10826. * @public
  10827. * @since 2.1.000 (2008-01-08)
  10828. */
  10829. public function SetLineStyle($style, $ret=false) {
  10830. $s = ''; // string to be returned
  10831. if (!is_array($style)) {
  10832. return;
  10833. }
  10834. if (isset($style['width'])) {
  10835. $this->LineWidth = $style['width'];
  10836. $this->linestyleWidth = sprintf('%F w', ($style['width'] * $this->k));
  10837. $s .= $this->linestyleWidth.' ';
  10838. }
  10839. if (isset($style['cap'])) {
  10840. $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
  10841. if (isset($ca[$style['cap']])) {
  10842. $this->linestyleCap = $ca[$style['cap']].' J';
  10843. $s .= $this->linestyleCap.' ';
  10844. }
  10845. }
  10846. if (isset($style['join'])) {
  10847. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  10848. if (isset($ja[$style['join']])) {
  10849. $this->linestyleJoin = $ja[$style['join']].' j';
  10850. $s .= $this->linestyleJoin.' ';
  10851. }
  10852. }
  10853. if (isset($style['dash'])) {
  10854. $dash_string = '';
  10855. if ($style['dash']) {
  10856. if (preg_match('/^.+,/', $style['dash']) > 0) {
  10857. $tab = explode(',', $style['dash']);
  10858. } else {
  10859. $tab = array($style['dash']);
  10860. }
  10861. $dash_string = '';
  10862. foreach ($tab as $i => $v) {
  10863. if ($i) {
  10864. $dash_string .= ' ';
  10865. }
  10866. $dash_string .= sprintf('%F', $v);
  10867. }
  10868. }
  10869. if (!isset($style['phase']) OR !$style['dash']) {
  10870. $style['phase'] = 0;
  10871. }
  10872. $this->linestyleDash = sprintf('[%s] %F d', $dash_string, $style['phase']);
  10873. $s .= $this->linestyleDash.' ';
  10874. }
  10875. if (isset($style['color'])) {
  10876. $s .= $this->SetDrawColorArray($style['color'], true).' ';
  10877. }
  10878. if (!$ret AND ($this->state == 2)) {
  10879. $this->_out($s);
  10880. }
  10881. return $s;
  10882. }
  10883. /**
  10884. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  10885. * @param $x (float) Abscissa of point.
  10886. * @param $y (float) Ordinate of point.
  10887. * @protected
  10888. * @since 2.1.000 (2008-01-08)
  10889. */
  10890. protected function _outPoint($x, $y) {
  10891. if ($this->state == 2) {
  10892. $this->_out(sprintf('%F %F m', ($x * $this->k), (($this->h - $y) * $this->k)));
  10893. }
  10894. }
  10895. /**
  10896. * Append a straight line segment from the current point to the point (x, y).
  10897. * The new current point shall be (x, y).
  10898. * @param $x (float) Abscissa of end point.
  10899. * @param $y (float) Ordinate of end point.
  10900. * @protected
  10901. * @since 2.1.000 (2008-01-08)
  10902. */
  10903. protected function _outLine($x, $y) {
  10904. if ($this->state == 2) {
  10905. $this->_out(sprintf('%F %F l', ($x * $this->k), (($this->h - $y) * $this->k)));
  10906. }
  10907. }
  10908. /**
  10909. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  10910. * @param $x (float) Abscissa of upper-left corner.
  10911. * @param $y (float) Ordinate of upper-left corner.
  10912. * @param $w (float) Width.
  10913. * @param $h (float) Height.
  10914. * @param $op (string) options
  10915. * @protected
  10916. * @since 2.1.000 (2008-01-08)
  10917. */
  10918. protected function _outRect($x, $y, $w, $h, $op) {
  10919. if ($this->state == 2) {
  10920. $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k), (($this->h - $y) * $this->k), ($w * $this->k), (-$h * $this->k), $op));
  10921. }
  10922. }
  10923. /**
  10924. * Append a cubic B\E9zier 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 B\E9zier control points.
  10925. * The new current point shall be (x3, y3).
  10926. * @param $x1 (float) Abscissa of control point 1.
  10927. * @param $y1 (float) Ordinate of control point 1.
  10928. * @param $x2 (float) Abscissa of control point 2.
  10929. * @param $y2 (float) Ordinate of control point 2.
  10930. * @param $x3 (float) Abscissa of end point.
  10931. * @param $y3 (float) Ordinate of end point.
  10932. * @protected
  10933. * @since 2.1.000 (2008-01-08)
  10934. */
  10935. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
  10936. if ($this->state == 2) {
  10937. $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)));
  10938. }
  10939. }
  10940. /**
  10941. * Append a cubic B\E9zier 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 B\E9zier control points.
  10942. * The new current point shall be (x3, y3).
  10943. * @param $x2 (float) Abscissa of control point 2.
  10944. * @param $y2 (float) Ordinate of control point 2.
  10945. * @param $x3 (float) Abscissa of end point.
  10946. * @param $y3 (float) Ordinate of end point.
  10947. * @protected
  10948. * @since 4.9.019 (2010-04-26)
  10949. */
  10950. protected function _outCurveV($x2, $y2, $x3, $y3) {
  10951. if ($this->state == 2) {
  10952. $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k), (($this->h - $y2) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  10953. }
  10954. }
  10955. /**
  10956. * Append a cubic B\E9zier 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 B\E9zier control points.
  10957. * The new current point shall be (x3, y3).
  10958. * @param $x1 (float) Abscissa of control point 1.
  10959. * @param $y1 (float) Ordinate of control point 1.
  10960. * @param $x3 (float) Abscissa of end point.
  10961. * @param $y3 (float) Ordinate of end point.
  10962. * @protected
  10963. * @since 2.1.000 (2008-01-08)
  10964. */
  10965. protected function _outCurveY($x1, $y1, $x3, $y3) {
  10966. if ($this->state == 2) {
  10967. $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k), (($this->h - $y1) * $this->k), ($x3 * $this->k), (($this->h - $y3) * $this->k)));
  10968. }
  10969. }
  10970. /**
  10971. * Draws a line between two points.
  10972. * @param $x1 (float) Abscissa of first point.
  10973. * @param $y1 (float) Ordinate of first point.
  10974. * @param $x2 (float) Abscissa of second point.
  10975. * @param $y2 (float) Ordinate of second point.
  10976. * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
  10977. * @public
  10978. * @since 1.0
  10979. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  10980. */
  10981. public function Line($x1, $y1, $x2, $y2, $style=array()) {
  10982. if ($this->state != 2) {
  10983. return;
  10984. }
  10985. if (is_array($style)) {
  10986. $this->SetLineStyle($style);
  10987. }
  10988. $this->_outPoint($x1, $y1);
  10989. $this->_outLine($x2, $y2);
  10990. $this->_out('S');
  10991. }
  10992. /**
  10993. * Draws a rectangle.
  10994. * @param $x (float) Abscissa of upper-left corner.
  10995. * @param $y (float) Ordinate of upper-left corner.
  10996. * @param $w (float) Width.
  10997. * @param $h (float) Height.
  10998. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  10999. * @param $border_style (array) Border style of rectangle. Array with keys among the following:
  11000. * <ul>
  11001. * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
  11002. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
  11003. * </ul>
  11004. * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
  11005. * @param $fill_color (array) 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).
  11006. * @public
  11007. * @since 1.0
  11008. * @see SetLineStyle()
  11009. */
  11010. public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
  11011. if ($this->state != 2) {
  11012. return;
  11013. }
  11014. if (empty($style)) {
  11015. $style = 'S';
  11016. }
  11017. if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
  11018. // set background color
  11019. $this->SetFillColorArray($fill_color);
  11020. }
  11021. if (!empty($border_style)) {
  11022. if (isset($border_style['all']) AND !empty($border_style['all'])) {
  11023. //set global style for border
  11024. $this->SetLineStyle($border_style['all']);
  11025. $border_style = array();
  11026. } else {
  11027. // remove stroke operator from style
  11028. $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*' );
  11029. if (isset($opnostroke[$style])) {
  11030. $style = $opnostroke[$style];
  11031. }
  11032. }
  11033. }
  11034. if (!empty($style)) {
  11035. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11036. $this->_outRect($x, $y, $w, $h, $op);
  11037. }
  11038. if (!empty($border_style)) {
  11039. $border_style2 = array();
  11040. foreach ($border_style as $line => $value) {
  11041. $length = strlen($line);
  11042. for ($i = 0; $i < $length; ++$i) {
  11043. $border_style2[$line[$i]] = $value;
  11044. }
  11045. }
  11046. $border_style = $border_style2;
  11047. if (isset($border_style['L']) AND $border_style['L']) {
  11048. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  11049. }
  11050. if (isset($border_style['T']) AND $border_style['T']) {
  11051. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  11052. }
  11053. if (isset($border_style['R']) AND $border_style['R']) {
  11054. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  11055. }
  11056. if (isset($border_style['B']) AND $border_style['B']) {
  11057. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  11058. }
  11059. }
  11060. }
  11061. /**
  11062. * Draws a Bezier curve.
  11063. * The Bezier curve is a tangent to the line between the control points at
  11064. * either end of the curve.
  11065. * @param $x0 (float) Abscissa of start point.
  11066. * @param $y0 (float) Ordinate of start point.
  11067. * @param $x1 (float) Abscissa of control point 1.
  11068. * @param $y1 (float) Ordinate of control point 1.
  11069. * @param $x2 (float) Abscissa of control point 2.
  11070. * @param $y2 (float) Ordinate of control point 2.
  11071. * @param $x3 (float) Abscissa of end point.
  11072. * @param $y3 (float) Ordinate of end point.
  11073. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11074. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11075. * @param $fill_color (array) 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).
  11076. * @public
  11077. * @see SetLineStyle()
  11078. * @since 2.1.000 (2008-01-08)
  11079. */
  11080. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
  11081. if ($this->state != 2) {
  11082. return;
  11083. }
  11084. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11085. $this->SetFillColorArray($fill_color);
  11086. }
  11087. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11088. if ($line_style) {
  11089. $this->SetLineStyle($line_style);
  11090. }
  11091. $this->_outPoint($x0, $y0);
  11092. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11093. $this->_out($op);
  11094. }
  11095. /**
  11096. * Draws a poly-Bezier curve.
  11097. * Each Bezier curve segment is a tangent to the line between the control points at
  11098. * either end of the curve.
  11099. * @param $x0 (float) Abscissa of start point.
  11100. * @param $y0 (float) Ordinate of start point.
  11101. * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  11102. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11103. * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
  11104. * @param $fill_color (array) 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).
  11105. * @public
  11106. * @see SetLineStyle()
  11107. * @since 3.0008 (2008-05-12)
  11108. */
  11109. public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
  11110. if ($this->state != 2) {
  11111. return;
  11112. }
  11113. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11114. $this->SetFillColorArray($fill_color);
  11115. }
  11116. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11117. if ($op == 'f') {
  11118. $line_style = array();
  11119. }
  11120. if ($line_style) {
  11121. $this->SetLineStyle($line_style);
  11122. }
  11123. $this->_outPoint($x0, $y0);
  11124. foreach ($segments as $segment) {
  11125. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  11126. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  11127. }
  11128. $this->_out($op);
  11129. }
  11130. /**
  11131. * Draws an ellipse.
  11132. * An ellipse is formed from n Bezier curves.
  11133. * @param $x0 (float) Abscissa of center point.
  11134. * @param $y0 (float) Ordinate of center point.
  11135. * @param $rx (float) Horizontal radius.
  11136. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11137. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11138. * @param $astart: (float) Angle start of draw line. Default value: 0.
  11139. * @param $afinish: (float) Angle finish of draw line. Default value: 360.
  11140. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11141. * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
  11142. * @param $fill_color (array) 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).
  11143. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11144. * @author Nicola Asuni
  11145. * @public
  11146. * @since 2.1.000 (2008-01-08)
  11147. */
  11148. public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11149. if ($this->state != 2) {
  11150. return;
  11151. }
  11152. if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
  11153. $ry = $rx;
  11154. }
  11155. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11156. $this->SetFillColorArray($fill_color);
  11157. }
  11158. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11159. if ($op == 'f') {
  11160. $line_style = array();
  11161. }
  11162. if ($line_style) {
  11163. $this->SetLineStyle($line_style);
  11164. }
  11165. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
  11166. $this->_out($op);
  11167. }
  11168. /**
  11169. * Append an elliptical arc to the current path.
  11170. * An ellipse is formed from n Bezier curves.
  11171. * @param $xc (float) Abscissa of center point.
  11172. * @param $yc (float) Ordinate of center point.
  11173. * @param $rx (float) Horizontal radius.
  11174. * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
  11175. * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  11176. * @param $angs: (float) Angle start of draw line. Default value: 0.
  11177. * @param $angf: (float) Angle finish of draw line. Default value: 360.
  11178. * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
  11179. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
  11180. * @param $startpoint (boolean) if true output a starting point.
  11181. * @param $ccw (boolean) if true draws in counter-clockwise.
  11182. * @param $svg (boolean) if true the angles are in svg mode (already calculated).
  11183. * @return array bounding box coordinates (x min, y min, x max, y max)
  11184. * @author Nicola Asuni
  11185. * @protected
  11186. * @since 4.9.019 (2010-04-26)
  11187. */
  11188. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
  11189. if (($rx <= 0) OR ($ry < 0)) {
  11190. return;
  11191. }
  11192. $k = $this->k;
  11193. if ($nc < 2) {
  11194. $nc = 2;
  11195. }
  11196. $xmin = 2147483647;
  11197. $ymin = 2147483647;
  11198. $xmax = 0;
  11199. $ymax = 0;
  11200. if ($pie) {
  11201. // center of the arc
  11202. $this->_outPoint($xc, $yc);
  11203. }
  11204. $xang = deg2rad((float) $xang);
  11205. $angs = deg2rad((float) $angs);
  11206. $angf = deg2rad((float) $angf);
  11207. if ($svg) {
  11208. $as = $angs;
  11209. $af = $angf;
  11210. } else {
  11211. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  11212. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  11213. }
  11214. if ($as < 0) {
  11215. $as += (2 * M_PI);
  11216. }
  11217. if ($af < 0) {
  11218. $af += (2 * M_PI);
  11219. }
  11220. if ($ccw AND ($as > $af)) {
  11221. // reverse rotation
  11222. $as -= (2 * M_PI);
  11223. } elseif (!$ccw AND ($as < $af)) {
  11224. // reverse rotation
  11225. $af -= (2 * M_PI);
  11226. }
  11227. $total_angle = ($af - $as);
  11228. if ($nc < 2) {
  11229. $nc = 2;
  11230. }
  11231. // total arcs to draw
  11232. $nc *= (2 * abs($total_angle) / M_PI);
  11233. $nc = round($nc) + 1;
  11234. // angle of each arc
  11235. $arcang = ($total_angle / $nc);
  11236. // center point in PDF coordinates
  11237. $x0 = $xc;
  11238. $y0 = ($this->h - $yc);
  11239. // starting angle
  11240. $ang = $as;
  11241. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  11242. $cos_xang = cos($xang);
  11243. $sin_xang = sin($xang);
  11244. $cos_ang = cos($ang);
  11245. $sin_ang = sin($ang);
  11246. // first arc point
  11247. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11248. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11249. // first Bezier control point
  11250. $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11251. $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11252. if ($pie) {
  11253. // line from center to arc starting point
  11254. $this->_outLine($px1, $this->h - $py1);
  11255. } elseif ($startpoint) {
  11256. // arc starting point
  11257. $this->_outPoint($px1, $this->h - $py1);
  11258. }
  11259. // draw arcs
  11260. for ($i = 1; $i <= $nc; ++$i) {
  11261. // starting angle
  11262. $ang = $as + ($i * $arcang);
  11263. if ($i == $nc) {
  11264. $ang = $af;
  11265. }
  11266. $cos_ang = cos($ang);
  11267. $sin_ang = sin($ang);
  11268. // second arc point
  11269. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  11270. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  11271. // second Bezier control point
  11272. $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  11273. $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  11274. // draw arc
  11275. $cx1 = ($px1 + $qx1);
  11276. $cy1 = ($this->h - ($py1 + $qy1));
  11277. $cx2 = ($px2 - $qx2);
  11278. $cy2 = ($this->h - ($py2 - $qy2));
  11279. $cx3 = $px2;
  11280. $cy3 = ($this->h - $py2);
  11281. $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
  11282. // get bounding box coordinates
  11283. $xmin = min($xmin, $cx1, $cx2, $cx3);
  11284. $ymin = min($ymin, $cy1, $cy2, $cy3);
  11285. $xmax = max($xmax, $cx1, $cx2, $cx3);
  11286. $ymax = max($ymax, $cy1, $cy2, $cy3);
  11287. // move to next point
  11288. $px1 = $px2;
  11289. $py1 = $py2;
  11290. $qx1 = $qx2;
  11291. $qy1 = $qy2;
  11292. }
  11293. if ($pie) {
  11294. $this->_outLine($xc, $yc);
  11295. // get bounding box coordinates
  11296. $xmin = min($xmin, $xc);
  11297. $ymin = min($ymin, $yc);
  11298. $xmax = max($xmax, $xc);
  11299. $ymax = max($ymax, $yc);
  11300. }
  11301. return array($xmin, $ymin, $xmax, $ymax);
  11302. }
  11303. /**
  11304. * Draws a circle.
  11305. * A circle is formed from n Bezier curves.
  11306. * @param $x0 (float) Abscissa of center point.
  11307. * @param $y0 (float) Ordinate of center point.
  11308. * @param $r (float) Radius.
  11309. * @param $angstr: (float) Angle start of draw line. Default value: 0.
  11310. * @param $angend: (float) Angle finish of draw line. Default value: 360.
  11311. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11312. * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11313. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11314. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
  11315. * @public
  11316. * @since 2.1.000 (2008-01-08)
  11317. */
  11318. public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
  11319. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  11320. }
  11321. /**
  11322. * Draws a polygonal line
  11323. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11324. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11325. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11326. * <ul>
  11327. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11328. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11329. * </ul>
  11330. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11331. * @param $fill_color (array) 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).
  11332. * @since 4.8.003 (2009-09-15)
  11333. * @public
  11334. */
  11335. public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
  11336. $this->Polygon($p, $style, $line_style, $fill_color, false);
  11337. }
  11338. /**
  11339. * Draws a polygon.
  11340. * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  11341. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11342. * @param $line_style (array) Line style of polygon. Array with keys among the following:
  11343. * <ul>
  11344. * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
  11345. * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
  11346. * </ul>
  11347. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  11348. * @param $fill_color (array) 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).
  11349. * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
  11350. * @public
  11351. * @since 2.1.000 (2008-01-08)
  11352. */
  11353. public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
  11354. if ($this->state != 2) {
  11355. return;
  11356. }
  11357. $nc = count($p); // number of coordinates
  11358. $np = $nc / 2; // number of points
  11359. if ($closed) {
  11360. // close polygon by adding the first 2 points at the end (one line)
  11361. for ($i = 0; $i < 4; ++$i) {
  11362. $p[$nc + $i] = $p[$i];
  11363. }
  11364. // copy style for the last added line
  11365. if (isset($line_style[0])) {
  11366. $line_style[$np] = $line_style[0];
  11367. }
  11368. $nc += 4;
  11369. }
  11370. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11371. $this->SetFillColorArray($fill_color);
  11372. }
  11373. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11374. if ($op == 'f') {
  11375. $line_style = array();
  11376. }
  11377. $draw = true;
  11378. if ($line_style) {
  11379. if (isset($line_style['all'])) {
  11380. $this->SetLineStyle($line_style['all']);
  11381. } else {
  11382. $draw = false;
  11383. if ($op == 'B') {
  11384. // draw fill
  11385. $op = 'f';
  11386. $this->_outPoint($p[0], $p[1]);
  11387. for ($i = 2; $i < $nc; $i = $i + 2) {
  11388. $this->_outLine($p[$i], $p[$i + 1]);
  11389. }
  11390. $this->_out($op);
  11391. }
  11392. // draw outline
  11393. $this->_outPoint($p[0], $p[1]);
  11394. for ($i = 2; $i < $nc; $i = $i + 2) {
  11395. $line_num = ($i / 2) - 1;
  11396. if (isset($line_style[$line_num])) {
  11397. if ($line_style[$line_num] != 0) {
  11398. if (is_array($line_style[$line_num])) {
  11399. $this->_out('S');
  11400. $this->SetLineStyle($line_style[$line_num]);
  11401. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  11402. $this->_outLine($p[$i], $p[$i + 1]);
  11403. $this->_out('S');
  11404. $this->_outPoint($p[$i], $p[$i + 1]);
  11405. } else {
  11406. $this->_outLine($p[$i], $p[$i + 1]);
  11407. }
  11408. }
  11409. } else {
  11410. $this->_outLine($p[$i], $p[$i + 1]);
  11411. }
  11412. }
  11413. $this->_out($op);
  11414. }
  11415. }
  11416. if ($draw) {
  11417. $this->_outPoint($p[0], $p[1]);
  11418. for ($i = 2; $i < $nc; $i = $i + 2) {
  11419. $this->_outLine($p[$i], $p[$i + 1]);
  11420. }
  11421. $this->_out($op);
  11422. }
  11423. }
  11424. /**
  11425. * Draws a regular polygon.
  11426. * @param $x0 (float) Abscissa of center point.
  11427. * @param $y0 (float) Ordinate of center point.
  11428. * @param $r: (float) Radius of inscribed circle.
  11429. * @param $ns (integer) Number of sides.
  11430. * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
  11431. * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
  11432. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11433. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11434. * <ul>
  11435. * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
  11436. * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
  11437. * </ul>
  11438. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11439. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11440. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11441. * <ul>
  11442. * <li>D or empty string: Draw (default).</li>
  11443. * <li>F: Fill.</li>
  11444. * <li>DF or FD: Draw and fill.</li>
  11445. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11446. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11447. * </ul>
  11448. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11449. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11450. * @public
  11451. * @since 2.1.000 (2008-01-08)
  11452. */
  11453. 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()) {
  11454. if (3 > $ns) {
  11455. $ns = 3;
  11456. }
  11457. if ($draw_circle) {
  11458. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11459. }
  11460. $p = array();
  11461. for ($i = 0; $i < $ns; ++$i) {
  11462. $a = $angle + ($i * 360 / $ns);
  11463. $a_rad = deg2rad((float) $a);
  11464. $p[] = $x0 + ($r * sin($a_rad));
  11465. $p[] = $y0 + ($r * cos($a_rad));
  11466. }
  11467. $this->Polygon($p, $style, $line_style, $fill_color);
  11468. }
  11469. /**
  11470. * Draws a star polygon
  11471. * @param $x0 (float) Abscissa of center point.
  11472. * @param $y0 (float) Ordinate of center point.
  11473. * @param $r (float) Radius of inscribed circle.
  11474. * @param $nv (integer) Number of vertices.
  11475. * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  11476. * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
  11477. * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
  11478. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11479. * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
  11480. * <ul>
  11481. * <li>all: Line style of all sides. Array like for
  11482. * SetLineStyle().</li>
  11483. * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
  11484. * </ul>
  11485. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  11486. * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  11487. * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
  11488. * <ul>
  11489. * <li>D or empty string: Draw (default).</li>
  11490. * <li>F: Fill.</li>
  11491. * <li>DF or FD: Draw and fill.</li>
  11492. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  11493. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  11494. * </ul>
  11495. * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
  11496. * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  11497. * @public
  11498. * @since 2.1.000 (2008-01-08)
  11499. */
  11500. 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()) {
  11501. if ($nv < 2) {
  11502. $nv = 2;
  11503. }
  11504. if ($draw_circle) {
  11505. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  11506. }
  11507. $p2 = array();
  11508. $visited = array();
  11509. for ($i = 0; $i < $nv; ++$i) {
  11510. $a = $angle + ($i * 360 / $nv);
  11511. $a_rad = deg2rad((float) $a);
  11512. $p2[] = $x0 + ($r * sin($a_rad));
  11513. $p2[] = $y0 + ($r * cos($a_rad));
  11514. $visited[] = false;
  11515. }
  11516. $p = array();
  11517. $i = 0;
  11518. do {
  11519. $p[] = $p2[$i * 2];
  11520. $p[] = $p2[($i * 2) + 1];
  11521. $visited[$i] = true;
  11522. $i += $ng;
  11523. $i %= $nv;
  11524. } while (!$visited[$i]);
  11525. $this->Polygon($p, $style, $line_style, $fill_color);
  11526. }
  11527. /**
  11528. * Draws a rounded rectangle.
  11529. * @param $x (float) Abscissa of upper-left corner.
  11530. * @param $y (float) Ordinate of upper-left corner.
  11531. * @param $w (float) Width.
  11532. * @param $h (float) Height.
  11533. * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
  11534. * @param $round_corner (string) 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").
  11535. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11536. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11537. * @param $fill_color (array) 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).
  11538. * @public
  11539. * @since 2.1.000 (2008-01-08)
  11540. */
  11541. public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11542. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  11543. }
  11544. /**
  11545. * Draws a rounded rectangle.
  11546. * @param $x (float) Abscissa of upper-left corner.
  11547. * @param $y (float) Ordinate of upper-left corner.
  11548. * @param $w (float) Width.
  11549. * @param $h (float) Height.
  11550. * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
  11551. * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
  11552. * @param $round_corner (string) 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").
  11553. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  11554. * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
  11555. * @param $fill_color (array) 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).
  11556. * @public
  11557. * @since 4.9.019 (2010-04-22)
  11558. */
  11559. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
  11560. if ($this->state != 2) {
  11561. return;
  11562. }
  11563. if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
  11564. // Not rounded
  11565. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  11566. return;
  11567. }
  11568. // Rounded
  11569. if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
  11570. $this->SetFillColorArray($fill_color);
  11571. }
  11572. $op = TCPDF_STATIC::getPathPaintOperator($style);
  11573. if ($op == 'f') {
  11574. $border_style = array();
  11575. }
  11576. if ($border_style) {
  11577. $this->SetLineStyle($border_style);
  11578. }
  11579. $MyArc = 4 / 3 * (sqrt(2) - 1);
  11580. $this->_outPoint($x + $rx, $y);
  11581. $xc = $x + $w - $rx;
  11582. $yc = $y + $ry;
  11583. $this->_outLine($xc, $y);
  11584. if ($round_corner[0]) {
  11585. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  11586. } else {
  11587. $this->_outLine($x + $w, $y);
  11588. }
  11589. $xc = $x + $w - $rx;
  11590. $yc = $y + $h - $ry;
  11591. $this->_outLine($x + $w, $yc);
  11592. if ($round_corner[1]) {
  11593. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  11594. } else {
  11595. $this->_outLine($x + $w, $y + $h);
  11596. }
  11597. $xc = $x + $rx;
  11598. $yc = $y + $h - $ry;
  11599. $this->_outLine($xc, $y + $h);
  11600. if ($round_corner[2]) {
  11601. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  11602. } else {
  11603. $this->_outLine($x, $y + $h);
  11604. }
  11605. $xc = $x + $rx;
  11606. $yc = $y + $ry;
  11607. $this->_outLine($x, $yc);
  11608. if ($round_corner[3]) {
  11609. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  11610. } else {
  11611. $this->_outLine($x, $y);
  11612. $this->_outLine($x + $rx, $y);
  11613. }
  11614. $this->_out($op);
  11615. }
  11616. /**
  11617. * Draws a grahic arrow.
  11618. * @param $x0 (float) Abscissa of first point.
  11619. * @param $y0 (float) Ordinate of first point.
  11620. * @param $x1 (float) Abscissa of second point.
  11621. * @param $y1 (float) Ordinate of second point.
  11622. * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  11623. * @param $arm_size (float) length of arrowhead arms
  11624. * @param $arm_angle (int) angle between an arm and the shaft
  11625. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  11626. * @since 4.6.018 (2009-07-10)
  11627. */
  11628. public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
  11629. // getting arrow direction angle
  11630. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  11631. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  11632. if ($dir_angle < 0) {
  11633. $dir_angle += (2 * M_PI);
  11634. }
  11635. $arm_angle = deg2rad($arm_angle);
  11636. $sx1 = $x1;
  11637. $sy1 = $y1;
  11638. if ($head_style > 0) {
  11639. // calculate the stopping point for the arrow shaft
  11640. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  11641. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  11642. }
  11643. // main arrow line / shaft
  11644. $this->Line($x0, $y0, $sx1, $sy1);
  11645. // left arrowhead arm tip
  11646. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  11647. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  11648. // right arrowhead arm tip
  11649. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  11650. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  11651. $mode = 'D';
  11652. $style = array();
  11653. switch ($head_style) {
  11654. case 0: {
  11655. // draw only arrowhead arms
  11656. $mode = 'D';
  11657. $style = array(1, 1, 0);
  11658. break;
  11659. }
  11660. case 1: {
  11661. // draw closed arrowhead, but no fill
  11662. $mode = 'D';
  11663. break;
  11664. }
  11665. case 2: {
  11666. // closed and filled arrowhead
  11667. $mode = 'DF';
  11668. break;
  11669. }
  11670. case 3: {
  11671. // filled arrowhead
  11672. $mode = 'F';
  11673. break;
  11674. }
  11675. }
  11676. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  11677. }
  11678. // END GRAPHIC FUNCTIONS SECTION -----------------------
  11679. /**
  11680. * Add a Named Destination.
  11681. * NOTE: destination names are unique, so only last entry will be saved.
  11682. * @param $name (string) Destination name.
  11683. * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
  11684. * @param $page (int) Target page number (leave empty for current page).
  11685. * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;).
  11686. * @return (string) Stripped named destination identifier or false in case of error.
  11687. * @public
  11688. * @author Christian Deligant, Nicola Asuni
  11689. * @since 5.9.097 (2011-06-23)
  11690. */
  11691. public function setDestination($name, $y=-1, $page='', $x=-1) {
  11692. // remove unsupported characters
  11693. $name = TCPDF_STATIC::encodeNameObject($name);
  11694. if (TCPDF_STATIC::empty_string($name)) {
  11695. return false;
  11696. }
  11697. if ($y == -1) {
  11698. $y = $this->GetY();
  11699. } elseif ($y < 0) {
  11700. $y = 0;
  11701. } elseif ($y > $this->h) {
  11702. $y = $this->h;
  11703. }
  11704. if ($x == -1) {
  11705. $x = $this->GetX();
  11706. } elseif ($x < 0) {
  11707. $x = 0;
  11708. } elseif ($x > $this->w) {
  11709. $x = $this->w;
  11710. }
  11711. if (empty($page)) {
  11712. $page = $this->PageNo();
  11713. if (empty($page)) {
  11714. return;
  11715. }
  11716. }
  11717. $this->dests[$name] = array('x' => $x, 'y' => $y, 'p' => $page);
  11718. return $name;
  11719. }
  11720. /**
  11721. * Return the Named Destination array.
  11722. * @return (array) Named Destination array.
  11723. * @public
  11724. * @author Nicola Asuni
  11725. * @since 5.9.097 (2011-06-23)
  11726. */
  11727. public function getDestination() {
  11728. return $this->dests;
  11729. }
  11730. /**
  11731. * Insert Named Destinations.
  11732. * @protected
  11733. * @author Johannes G\FCntert, Nicola Asuni
  11734. * @since 5.9.098 (2011-06-23)
  11735. */
  11736. protected function _putdests() {
  11737. if (empty($this->dests)) {
  11738. return;
  11739. }
  11740. $this->n_dests = $this->_newobj();
  11741. $out = ' <<';
  11742. foreach($this->dests as $name => $o) {
  11743. $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)));
  11744. }
  11745. $out .= ' >>';
  11746. $out .= "\n".'endobj';
  11747. $this->_out($out);
  11748. }
  11749. /**
  11750. * Adds a bookmark - alias for Bookmark().
  11751. * @param $txt (string) Bookmark description.
  11752. * @param $level (int) Bookmark level (minimum value is 0).
  11753. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11754. * @param $page (int) Target page number (leave empty for current page).
  11755. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11756. * @param $color (array) RGB color array (values from 0 to 255).
  11757. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11758. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11759. * @public
  11760. */
  11761. public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11762. $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
  11763. }
  11764. /**
  11765. * Adds a bookmark.
  11766. * @param $txt (string) Bookmark description.
  11767. * @param $level (int) Bookmark level (minimum value is 0).
  11768. * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  11769. * @param $page (int) Target page number (leave empty for current page).
  11770. * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
  11771. * @param $color (array) RGB color array (values from 0 to 255).
  11772. * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
  11773. * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
  11774. * @public
  11775. * @since 2.1.002 (2008-02-12)
  11776. */
  11777. public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
  11778. if ($level < 0) {
  11779. $level = 0;
  11780. }
  11781. if (isset($this->outlines[0])) {
  11782. $lastoutline = end($this->outlines);
  11783. $maxlevel = $lastoutline['l'] + 1;
  11784. } else {
  11785. $maxlevel = 0;
  11786. }
  11787. if ($level > $maxlevel) {
  11788. $level = $maxlevel;
  11789. }
  11790. if ($y == -1) {
  11791. $y = $this->GetY();
  11792. } elseif ($y < 0) {
  11793. $y = 0;
  11794. } elseif ($y > $this->h) {
  11795. $y = $this->h;
  11796. }
  11797. if ($x == -1) {
  11798. $x = $this->GetX();
  11799. } elseif ($x < 0) {
  11800. $x = 0;
  11801. } elseif ($x > $this->w) {
  11802. $x = $this->w;
  11803. }
  11804. if (empty($page)) {
  11805. $page = $this->PageNo();
  11806. if (empty($page)) {
  11807. return;
  11808. }
  11809. }
  11810. $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
  11811. }
  11812. /**
  11813. * Sort bookmarks for page and key.
  11814. * @protected
  11815. * @since 5.9.119 (2011-09-19)
  11816. */
  11817. protected function sortBookmarks() {
  11818. // get sorting columns
  11819. $outline_p = array();
  11820. $outline_y = array();
  11821. foreach ($this->outlines as $key => $row) {
  11822. $outline_p[$key] = $row['p'];
  11823. $outline_k[$key] = $key;
  11824. }
  11825. // sort outlines by page and original position
  11826. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  11827. }
  11828. /**
  11829. * Create a bookmark PDF string.
  11830. * @protected
  11831. * @author Olivier Plathey, Nicola Asuni
  11832. * @since 2.1.002 (2008-02-12)
  11833. */
  11834. protected function _putbookmarks() {
  11835. $nb = count($this->outlines);
  11836. if ($nb == 0) {
  11837. return;
  11838. }
  11839. // sort bookmarks
  11840. $this->sortBookmarks();
  11841. $lru = array();
  11842. $level = 0;
  11843. foreach ($this->outlines as $i => $o) {
  11844. if ($o['l'] > 0) {
  11845. $parent = $lru[($o['l'] - 1)];
  11846. //Set parent and last pointers
  11847. $this->outlines[$i]['parent'] = $parent;
  11848. $this->outlines[$parent]['last'] = $i;
  11849. if ($o['l'] > $level) {
  11850. //Level increasing: set first pointer
  11851. $this->outlines[$parent]['first'] = $i;
  11852. }
  11853. } else {
  11854. $this->outlines[$i]['parent'] = $nb;
  11855. }
  11856. if (($o['l'] <= $level) AND ($i > 0)) {
  11857. //Set prev and next pointers
  11858. $prev = $lru[$o['l']];
  11859. $this->outlines[$prev]['next'] = $i;
  11860. $this->outlines[$i]['prev'] = $prev;
  11861. }
  11862. $lru[$o['l']] = $i;
  11863. $level = $o['l'];
  11864. }
  11865. //Outline items
  11866. $n = $this->n + 1;
  11867. $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';
  11868. foreach ($this->outlines as $i => $o) {
  11869. $oid = $this->_newobj();
  11870. // covert HTML title to string
  11871. $title = preg_replace($nltags, "\n", $o['t']);
  11872. $title = preg_replace("/[\r]+/si", '', $title);
  11873. $title = preg_replace("/[\n]+/si", "\n", $title);
  11874. $title = strip_tags($title);
  11875. $title = $this->stringTrim($title);
  11876. $out = '<</Title '.$this->_textstring($title, $oid);
  11877. $out .= ' /Parent '.($n + $o['parent']).' 0 R';
  11878. if (isset($o['prev'])) {
  11879. $out .= ' /Prev '.($n + $o['prev']).' 0 R';
  11880. }
  11881. if (isset($o['next'])) {
  11882. $out .= ' /Next '.($n + $o['next']).' 0 R';
  11883. }
  11884. if (isset($o['first'])) {
  11885. $out .= ' /First '.($n + $o['first']).' 0 R';
  11886. }
  11887. if (isset($o['last'])) {
  11888. $out .= ' /Last '.($n + $o['last']).' 0 R';
  11889. }
  11890. if (isset($o['u']) AND !empty($o['u'])) {
  11891. // link
  11892. if (is_string($o['u'])) {
  11893. if ($o['u'][0] == '#') {
  11894. // internal destination
  11895. $out .= ' /Dest /'.TCPDF_STATIC::encodeNameObject(substr($o['u'], 1));
  11896. } elseif ($o['u'][0] == '%') {
  11897. // embedded PDF file
  11898. $filename = basename(substr($o['u'], 1));
  11899. $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles[$filename]['a'].' >> >>';
  11900. } elseif ($o['u'][0] == '*') {
  11901. // embedded generic file
  11902. $filename = basename(substr($o['u'], 1));
  11903. $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});';
  11904. $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
  11905. } else {
  11906. // external URI link
  11907. $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
  11908. }
  11909. } elseif (isset($this->links[$o['u']])) {
  11910. // internal link ID
  11911. $l = $this->links[$o['u']];
  11912. if (isset($this->page_obj_id[($l[0])])) {
  11913. $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  11914. }
  11915. }
  11916. } elseif (isset($this->page_obj_id[($o['p'])])) {
  11917. // link to a page
  11918. $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)));
  11919. }
  11920. // set font style
  11921. $style = 0;
  11922. if (!empty($o['s'])) {
  11923. // bold
  11924. if (strpos($o['s'], 'B') !== false) {
  11925. $style |= 2;
  11926. }
  11927. // oblique
  11928. if (strpos($o['s'], 'I') !== false) {
  11929. $style |= 1;
  11930. }
  11931. }
  11932. $out .= sprintf(' /F %d', $style);
  11933. // set bookmark color
  11934. if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
  11935. $color = array_values($o['c']);
  11936. $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
  11937. } else {
  11938. // black
  11939. $out .= ' /C [0.0 0.0 0.0]';
  11940. }
  11941. $out .= ' /Count 0'; // normally closed item
  11942. $out .= ' >>';
  11943. $out .= "\n".'endobj';
  11944. $this->_out($out);
  11945. }
  11946. //Outline root
  11947. $this->OutlineRoot = $this->_newobj();
  11948. $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n + $lru[0]).' 0 R >>'."\n".'endobj');
  11949. }
  11950. // --- JAVASCRIPT ------------------------------------------------------
  11951. /**
  11952. * Adds a javascript
  11953. * @param $script (string) Javascript code
  11954. * @public
  11955. * @author Johannes G\FCntert, Nicola Asuni
  11956. * @since 2.1.002 (2008-02-12)
  11957. */
  11958. public function IncludeJS($script) {
  11959. $this->javascript .= $script;
  11960. }
  11961. /**
  11962. * Adds a javascript object and return object ID
  11963. * @param $script (string) Javascript code
  11964. * @param $onload (boolean) if true executes this object when opening the document
  11965. * @return int internal object ID
  11966. * @public
  11967. * @author Nicola Asuni
  11968. * @since 4.8.000 (2009-09-07)
  11969. */
  11970. public function addJavascriptObject($script, $onload=false) {
  11971. if ($this->pdfa_mode) {
  11972. // javascript is not allowed in PDF/A mode
  11973. return false;
  11974. }
  11975. ++$this->n;
  11976. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  11977. return $this->n;
  11978. }
  11979. /**
  11980. * Create a javascript PDF string.
  11981. * @protected
  11982. * @author Johannes G\FCntert, Nicola Asuni
  11983. * @since 2.1.002 (2008-02-12)
  11984. */
  11985. protected function _putjavascript() {
  11986. if ($this->pdfa_mode OR (empty($this->javascript) AND empty($this->js_objects))) {
  11987. return;
  11988. }
  11989. if (strpos($this->javascript, 'this.addField') > 0) {
  11990. if (!$this->ur['enabled']) {
  11991. //$this->setUserRights();
  11992. }
  11993. // the following two lines are used to avoid form fields duplication after saving
  11994. // The addField method only works when releasing user rights (UR3)
  11995. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  11996. $jsb = "getField('tcpdfdocsaved').value='saved';";
  11997. $this->javascript = $jsa."\n".$this->javascript."\n".$jsb;
  11998. }
  11999. // name tree for javascript
  12000. $this->n_js = '<< /Names [';
  12001. if (!empty($this->javascript)) {
  12002. $this->n_js .= ' (EmbeddedJS) '.($this->n + 1).' 0 R';
  12003. }
  12004. if (!empty($this->js_objects)) {
  12005. foreach ($this->js_objects as $key => $val) {
  12006. if ($val['onload']) {
  12007. $this->n_js .= ' (JS'.$key.') '.$key.' 0 R';
  12008. }
  12009. }
  12010. }
  12011. $this->n_js .= ' ] >>';
  12012. // default Javascript object
  12013. if (!empty($this->javascript)) {
  12014. $obj_id = $this->_newobj();
  12015. $out = '<< /S /JavaScript';
  12016. $out .= ' /JS '.$this->_textstring($this->javascript, $obj_id);
  12017. $out .= ' >>';
  12018. $out .= "\n".'endobj';
  12019. $this->_out($out);
  12020. }
  12021. // additional Javascript objects
  12022. if (!empty($this->js_objects)) {
  12023. foreach ($this->js_objects as $key => $val) {
  12024. $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
  12025. $this->_out($out);
  12026. }
  12027. }
  12028. }
  12029. /**
  12030. * Adds a javascript form field.
  12031. * @param $type (string) field type
  12032. * @param $name (string) field name
  12033. * @param $x (int) horizontal position
  12034. * @param $y (int) vertical position
  12035. * @param $w (int) width
  12036. * @param $h (int) height
  12037. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12038. * @protected
  12039. * @author Denis Van Nuffelen, Nicola Asuni
  12040. * @since 2.1.002 (2008-02-12)
  12041. */
  12042. protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
  12043. if ($this->rtl) {
  12044. $x = $x - $w;
  12045. }
  12046. // the followind avoid fields duplication after saving the document
  12047. $this->javascript .= "if (getField('tcpdfdocsaved').value != 'saved') {";
  12048. $k = $this->k;
  12049. $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";
  12050. $this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
  12051. while (list($key, $val) = each($prop)) {
  12052. if (strcmp(substr($key, -5), 'Color') == 0) {
  12053. $val = TCPDF_COLORS::_JScolor($val);
  12054. } else {
  12055. $val = "'".$val."'";
  12056. }
  12057. $this->javascript .= 'f'.$name.'.'.$key.'='.$val.";\n";
  12058. }
  12059. if ($this->rtl) {
  12060. $this->x -= $w;
  12061. } else {
  12062. $this->x += $w;
  12063. }
  12064. $this->javascript .= '}';
  12065. }
  12066. // --- FORM FIELDS -----------------------------------------------------
  12067. /**
  12068. * Set default properties for form fields.
  12069. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12070. * @public
  12071. * @author Nicola Asuni
  12072. * @since 4.8.000 (2009-09-06)
  12073. */
  12074. public function setFormDefaultProp($prop=array()) {
  12075. $this->default_form_prop = $prop;
  12076. }
  12077. /**
  12078. * Return the default properties for form fields.
  12079. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12080. * @public
  12081. * @author Nicola Asuni
  12082. * @since 4.8.000 (2009-09-06)
  12083. */
  12084. public function getFormDefaultProp() {
  12085. return $this->default_form_prop;
  12086. }
  12087. /**
  12088. * Creates a text field
  12089. * @param $name (string) field name
  12090. * @param $w (float) Width of the rectangle
  12091. * @param $h (float) Height of the rectangle
  12092. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12093. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12094. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12095. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12096. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12097. * @public
  12098. * @author Nicola Asuni
  12099. * @since 4.8.000 (2009-09-07)
  12100. */
  12101. public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12102. if ($x === '') {
  12103. $x = $this->x;
  12104. }
  12105. if ($y === '') {
  12106. $y = $this->y;
  12107. }
  12108. // check page for no-write regions and adapt page margins if necessary
  12109. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12110. if ($js) {
  12111. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  12112. return;
  12113. }
  12114. // get default style
  12115. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12116. // get annotation data
  12117. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12118. // set default appearance stream
  12119. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12120. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12121. $popt['da'] = $fontstyle;
  12122. // build appearance stream
  12123. $popt['ap'] = array();
  12124. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12125. $text = '';
  12126. if (isset($prop['value']) AND !empty($prop['value'])) {
  12127. $text = $prop['value'];
  12128. } elseif (isset($opt['v']) AND !empty($opt['v'])) {
  12129. $text = $opt['v'];
  12130. }
  12131. $tmpid = $this->startTemplate($w, $h, false);
  12132. $align = '';
  12133. if (isset($popt['q'])) {
  12134. switch ($popt['q']) {
  12135. case 0: {
  12136. $align = 'L';
  12137. break;
  12138. }
  12139. case 1: {
  12140. $align = 'C';
  12141. break;
  12142. }
  12143. case 2: {
  12144. $align = 'R';
  12145. break;
  12146. }
  12147. default: {
  12148. $align = '';
  12149. break;
  12150. }
  12151. }
  12152. }
  12153. $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12154. $this->endTemplate();
  12155. --$this->n;
  12156. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12157. unset($this->xobjects[$tmpid]);
  12158. $popt['ap']['n'] .= 'Q EMC';
  12159. // merge options
  12160. $opt = array_merge($popt, $opt);
  12161. // remove some conflicting options
  12162. unset($opt['bs']);
  12163. // set remaining annotation data
  12164. $opt['Subtype'] = 'Widget';
  12165. $opt['ft'] = 'Tx';
  12166. $opt['t'] = $name;
  12167. // Additional annotation's parameters (check _putannotsobj() method):
  12168. //$opt['f']
  12169. //$opt['as']
  12170. //$opt['bs']
  12171. //$opt['be']
  12172. //$opt['c']
  12173. //$opt['border']
  12174. //$opt['h']
  12175. //$opt['mk'];
  12176. //$opt['mk']['r']
  12177. //$opt['mk']['bc'];
  12178. //$opt['mk']['bg'];
  12179. unset($opt['mk']['ca']);
  12180. unset($opt['mk']['rc']);
  12181. unset($opt['mk']['ac']);
  12182. unset($opt['mk']['i']);
  12183. unset($opt['mk']['ri']);
  12184. unset($opt['mk']['ix']);
  12185. unset($opt['mk']['if']);
  12186. //$opt['mk']['if']['sw'];
  12187. //$opt['mk']['if']['s'];
  12188. //$opt['mk']['if']['a'];
  12189. //$opt['mk']['if']['fb'];
  12190. unset($opt['mk']['tp']);
  12191. //$opt['tu']
  12192. //$opt['tm']
  12193. //$opt['ff']
  12194. //$opt['v']
  12195. //$opt['dv']
  12196. //$opt['a']
  12197. //$opt['aa']
  12198. //$opt['q']
  12199. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12200. if ($this->rtl) {
  12201. $this->x -= $w;
  12202. } else {
  12203. $this->x += $w;
  12204. }
  12205. }
  12206. /**
  12207. * Creates a RadioButton field.
  12208. * @param $name (string) Field name.
  12209. * @param $w (int) Width of the radio button.
  12210. * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12211. * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12212. * @param $onvalue (string) Value to be returned if selected.
  12213. * @param $checked (boolean) Define the initial state.
  12214. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12215. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12216. * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12217. * @public
  12218. * @author Nicola Asuni
  12219. * @since 4.8.000 (2009-09-07)
  12220. */
  12221. public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
  12222. if ($x === '') {
  12223. $x = $this->x;
  12224. }
  12225. if ($y === '') {
  12226. $y = $this->y;
  12227. }
  12228. // check page for no-write regions and adapt page margins if necessary
  12229. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12230. if ($js) {
  12231. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  12232. return;
  12233. }
  12234. if (TCPDF_STATIC::empty_string($onvalue)) {
  12235. $onvalue = 'On';
  12236. }
  12237. if ($checked) {
  12238. $defval = $onvalue;
  12239. } else {
  12240. $defval = 'Off';
  12241. }
  12242. // set font
  12243. $font = 'zapfdingbats';
  12244. if ($this->pdfa_mode) {
  12245. // all fonts must be embedded
  12246. $font = 'pdfa'.$font;
  12247. }
  12248. $this->AddFont($font);
  12249. $tmpfont = $this->getFontBuffer($font);
  12250. // set data for parent group
  12251. if (!isset($this->radiobutton_groups[$this->page])) {
  12252. $this->radiobutton_groups[$this->page] = array();
  12253. }
  12254. if (!isset($this->radiobutton_groups[$this->page][$name])) {
  12255. $this->radiobutton_groups[$this->page][$name] = array();
  12256. ++$this->n;
  12257. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  12258. $this->radio_groups[] = $this->n;
  12259. }
  12260. $kid = ($this->n + 1);
  12261. // save object ID to be added on Kids entry on parent object
  12262. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  12263. // get default style
  12264. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12265. $prop['NoToggleToOff'] = 'true';
  12266. $prop['Radio'] = 'true';
  12267. $prop['borderStyle'] = 'inset';
  12268. // get annotation data
  12269. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12270. // set additional default options
  12271. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12272. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12273. $popt['da'] = $fontstyle;
  12274. // build appearance stream
  12275. $popt['ap'] = array();
  12276. $popt['ap']['n'] = array();
  12277. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k);
  12278. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12279. $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);
  12280. $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);
  12281. if (!isset($popt['mk'])) {
  12282. $popt['mk'] = array();
  12283. }
  12284. $popt['mk']['ca'] = '(l)';
  12285. // merge options
  12286. $opt = array_merge($popt, $opt);
  12287. // set remaining annotation data
  12288. $opt['Subtype'] = 'Widget';
  12289. $opt['ft'] = 'Btn';
  12290. if ($checked) {
  12291. $opt['v'] = array('/'.$onvalue);
  12292. $opt['as'] = $onvalue;
  12293. } else {
  12294. $opt['as'] = 'Off';
  12295. }
  12296. // store readonly flag
  12297. if (!isset($this->radiobutton_groups[$this->page][$name]['#readonly#'])) {
  12298. $this->radiobutton_groups[$this->page][$name]['#readonly#'] = false;
  12299. }
  12300. $this->radiobutton_groups[$this->page][$name]['#readonly#'] |= ($opt['f'] & 64);
  12301. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12302. if ($this->rtl) {
  12303. $this->x -= $w;
  12304. } else {
  12305. $this->x += $w;
  12306. }
  12307. }
  12308. /**
  12309. * Creates a List-box field
  12310. * @param $name (string) field name
  12311. * @param $w (int) width
  12312. * @param $h (int) height
  12313. * @param $values (array) array containing the list of values.
  12314. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12315. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12316. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12317. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12318. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12319. * @public
  12320. * @author Nicola Asuni
  12321. * @since 4.8.000 (2009-09-07)
  12322. */
  12323. public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12324. if ($x === '') {
  12325. $x = $this->x;
  12326. }
  12327. if ($y === '') {
  12328. $y = $this->y;
  12329. }
  12330. // check page for no-write regions and adapt page margins if necessary
  12331. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12332. if ($js) {
  12333. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  12334. $s = '';
  12335. foreach ($values as $value) {
  12336. if (is_array($value)) {
  12337. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12338. } else {
  12339. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12340. }
  12341. }
  12342. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12343. return;
  12344. }
  12345. // get default style
  12346. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12347. // get annotation data
  12348. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12349. // set additional default values
  12350. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12351. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12352. $popt['da'] = $fontstyle;
  12353. // build appearance stream
  12354. $popt['ap'] = array();
  12355. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12356. $text = '';
  12357. foreach($values as $item) {
  12358. if (is_array($item)) {
  12359. $text .= $item[1]."\n";
  12360. } else {
  12361. $text .= $item."\n";
  12362. }
  12363. }
  12364. $tmpid = $this->startTemplate($w, $h, false);
  12365. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12366. $this->endTemplate();
  12367. --$this->n;
  12368. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12369. unset($this->xobjects[$tmpid]);
  12370. $popt['ap']['n'] .= 'Q EMC';
  12371. // merge options
  12372. $opt = array_merge($popt, $opt);
  12373. // set remaining annotation data
  12374. $opt['Subtype'] = 'Widget';
  12375. $opt['ft'] = 'Ch';
  12376. $opt['t'] = $name;
  12377. $opt['opt'] = $values;
  12378. unset($opt['mk']['ca']);
  12379. unset($opt['mk']['rc']);
  12380. unset($opt['mk']['ac']);
  12381. unset($opt['mk']['i']);
  12382. unset($opt['mk']['ri']);
  12383. unset($opt['mk']['ix']);
  12384. unset($opt['mk']['if']);
  12385. unset($opt['mk']['tp']);
  12386. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12387. if ($this->rtl) {
  12388. $this->x -= $w;
  12389. } else {
  12390. $this->x += $w;
  12391. }
  12392. }
  12393. /**
  12394. * Creates a Combo-box field
  12395. * @param $name (string) field name
  12396. * @param $w (int) width
  12397. * @param $h (int) height
  12398. * @param $values (array) array containing the list of values.
  12399. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12400. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12401. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12402. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12403. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12404. * @public
  12405. * @author Nicola Asuni
  12406. * @since 4.8.000 (2009-09-07)
  12407. */
  12408. public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12409. if ($x === '') {
  12410. $x = $this->x;
  12411. }
  12412. if ($y === '') {
  12413. $y = $this->y;
  12414. }
  12415. // check page for no-write regions and adapt page margins if necessary
  12416. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12417. if ($js) {
  12418. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  12419. $s = '';
  12420. foreach ($values as $value) {
  12421. if (is_array($value)) {
  12422. $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
  12423. } else {
  12424. $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
  12425. }
  12426. }
  12427. $this->javascript .= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
  12428. return;
  12429. }
  12430. // get default style
  12431. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12432. $prop['Combo'] = true;
  12433. // get annotation data
  12434. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12435. // set additional default options
  12436. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12437. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12438. $popt['da'] = $fontstyle;
  12439. // build appearance stream
  12440. $popt['ap'] = array();
  12441. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12442. $text = '';
  12443. foreach($values as $item) {
  12444. if (is_array($item)) {
  12445. $text .= $item[1]."\n";
  12446. } else {
  12447. $text .= $item."\n";
  12448. }
  12449. }
  12450. $tmpid = $this->startTemplate($w, $h, false);
  12451. $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
  12452. $this->endTemplate();
  12453. --$this->n;
  12454. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12455. unset($this->xobjects[$tmpid]);
  12456. $popt['ap']['n'] .= 'Q EMC';
  12457. // merge options
  12458. $opt = array_merge($popt, $opt);
  12459. // set remaining annotation data
  12460. $opt['Subtype'] = 'Widget';
  12461. $opt['ft'] = 'Ch';
  12462. $opt['t'] = $name;
  12463. $opt['opt'] = $values;
  12464. unset($opt['mk']['ca']);
  12465. unset($opt['mk']['rc']);
  12466. unset($opt['mk']['ac']);
  12467. unset($opt['mk']['i']);
  12468. unset($opt['mk']['ri']);
  12469. unset($opt['mk']['ix']);
  12470. unset($opt['mk']['if']);
  12471. unset($opt['mk']['tp']);
  12472. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12473. if ($this->rtl) {
  12474. $this->x -= $w;
  12475. } else {
  12476. $this->x += $w;
  12477. }
  12478. }
  12479. /**
  12480. * Creates a CheckBox field
  12481. * @param $name (string) field name
  12482. * @param $w (int) width
  12483. * @param $checked (boolean) define the initial state.
  12484. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12485. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12486. * @param $onvalue (string) value to be returned if selected.
  12487. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12488. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12489. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12490. * @public
  12491. * @author Nicola Asuni
  12492. * @since 4.8.000 (2009-09-07)
  12493. */
  12494. public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
  12495. if ($x === '') {
  12496. $x = $this->x;
  12497. }
  12498. if ($y === '') {
  12499. $y = $this->y;
  12500. }
  12501. // check page for no-write regions and adapt page margins if necessary
  12502. list($x, $y) = $this->checkPageRegions($w, $x, $y);
  12503. if ($js) {
  12504. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  12505. return;
  12506. }
  12507. if (!isset($prop['value'])) {
  12508. $prop['value'] = array('Yes');
  12509. }
  12510. // get default style
  12511. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12512. $prop['borderStyle'] = 'inset';
  12513. // get annotation data
  12514. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12515. // set additional default options
  12516. $font = 'zapfdingbats';
  12517. if ($this->pdfa_mode) {
  12518. // all fonts must be embedded
  12519. $font = 'pdfa'.$font;
  12520. }
  12521. $this->AddFont($font);
  12522. $tmpfont = $this->getFontBuffer($font);
  12523. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  12524. $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  12525. $popt['da'] = $fontstyle;
  12526. // build appearance stream
  12527. $popt['ap'] = array();
  12528. $popt['ap']['n'] = array();
  12529. $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k);
  12530. $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt / 1000) / $this->k)) * $this->k);
  12531. $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);
  12532. $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);
  12533. // merge options
  12534. $opt = array_merge($popt, $opt);
  12535. // set remaining annotation data
  12536. $opt['Subtype'] = 'Widget';
  12537. $opt['ft'] = 'Btn';
  12538. $opt['t'] = $name;
  12539. if (TCPDF_STATIC::empty_string($onvalue)) {
  12540. $onvalue = 'Yes';
  12541. }
  12542. $opt['opt'] = array($onvalue);
  12543. if ($checked) {
  12544. $opt['v'] = array('/Yes');
  12545. $opt['as'] = 'Yes';
  12546. } else {
  12547. $opt['v'] = array('/Off');
  12548. $opt['as'] = 'Off';
  12549. }
  12550. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  12551. if ($this->rtl) {
  12552. $this->x -= $w;
  12553. } else {
  12554. $this->x += $w;
  12555. }
  12556. }
  12557. /**
  12558. * Creates a button field
  12559. * @param $name (string) field name
  12560. * @param $w (int) width
  12561. * @param $h (int) height
  12562. * @param $caption (string) caption.
  12563. * @param $action (mixed) 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.
  12564. * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  12565. * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
  12566. * @param $x (float) Abscissa of the upper-left corner of the rectangle
  12567. * @param $y (float) Ordinate of the upper-left corner of the rectangle
  12568. * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  12569. * @public
  12570. * @author Nicola Asuni
  12571. * @since 4.8.000 (2009-09-07)
  12572. */
  12573. public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
  12574. if ($x === '') {
  12575. $x = $this->x;
  12576. }
  12577. if ($y === '') {
  12578. $y = $this->y;
  12579. }
  12580. // check page for no-write regions and adapt page margins if necessary
  12581. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  12582. if ($js) {
  12583. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  12584. $this->javascript .= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
  12585. $this->javascript .= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
  12586. $this->javascript .= 'f'.$name.".highlight='push';\n";
  12587. $this->javascript .= 'f'.$name.".print=false;\n";
  12588. return;
  12589. }
  12590. // get default style
  12591. $prop = array_merge($this->getFormDefaultProp(), $prop);
  12592. $prop['Pushbutton'] = 'true';
  12593. $prop['highlight'] = 'push';
  12594. $prop['display'] = 'display.noPrint';
  12595. // get annotation data
  12596. $popt = TCPDF_STATIC::getAnnotOptFromJSProp($prop, $this->spot_colors, $this->rtl);
  12597. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  12598. $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  12599. $popt['da'] = $fontstyle;
  12600. // build appearance stream
  12601. $popt['ap'] = array();
  12602. $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
  12603. $tmpid = $this->startTemplate($w, $h, false);
  12604. $bw = (2 / $this->k); // border width
  12605. $border = array(
  12606. 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12607. 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
  12608. 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
  12609. 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
  12610. $this->SetFillColor(204);
  12611. $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
  12612. $this->endTemplate();
  12613. --$this->n;
  12614. $popt['ap']['n'] .= $this->xobjects[$tmpid]['outdata'];
  12615. unset($this->xobjects[$tmpid]);
  12616. $popt['ap']['n'] .= 'Q EMC';
  12617. // set additional default options
  12618. if (!isset($popt['mk'])) {
  12619. $popt['mk'] = array();
  12620. }
  12621. $ann_obj_id = ($this->n + 1);
  12622. if (!empty($action) AND !is_array($action)) {
  12623. $ann_obj_id = ($this->n + 2);
  12624. }
  12625. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  12626. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  12627. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  12628. // merge options
  12629. $opt = array_merge($popt, $opt);
  12630. // set remaining annotation data
  12631. $opt['Subtype'] = 'Widget';
  12632. $opt['ft'] = 'Btn';
  12633. $opt['t'] = $caption;
  12634. $opt['v'] = $name;
  12635. if (!empty($action)) {
  12636. if (is_array($action)) {
  12637. // form action options as on section 12.7.5 of PDF32000_2008.
  12638. $opt['aa'] = '/D <<';
  12639. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  12640. foreach ($action AS $key => $val) {
  12641. if (($key == 'S') AND in_array($val, $bmode)) {
  12642. $opt['aa'] .= ' /S /'.$val;
  12643. } elseif (($key == 'F') AND (!empty($val))) {
  12644. $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
  12645. } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
  12646. $opt['aa'] .= ' /Fields [';
  12647. foreach ($val AS $field) {
  12648. $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
  12649. }
  12650. $opt['aa'] .= ']';
  12651. } elseif (($key == 'Flags')) {
  12652. $ff = 0;
  12653. if (is_array($val)) {
  12654. foreach ($val AS $flag) {
  12655. switch ($flag) {
  12656. case 'Include/Exclude': {
  12657. $ff += 1 << 0;
  12658. break;
  12659. }
  12660. case 'IncludeNoValueFields': {
  12661. $ff += 1 << 1;
  12662. break;
  12663. }
  12664. case 'ExportFormat': {
  12665. $ff += 1 << 2;
  12666. break;
  12667. }
  12668. case 'GetMethod': {
  12669. $ff += 1 << 3;
  12670. break;
  12671. }
  12672. case 'SubmitCoordinates': {
  12673. $ff += 1 << 4;
  12674. break;
  12675. }
  12676. case 'XFDF': {
  12677. $ff += 1 << 5;
  12678. break;
  12679. }
  12680. case 'IncludeAppendSaves': {
  12681. $ff += 1 << 6;
  12682. break;
  12683. }
  12684. case 'IncludeAnnotations': {
  12685. $ff += 1 << 7;
  12686. break;
  12687. }
  12688. case 'SubmitPDF': {
  12689. $ff += 1 << 8;
  12690. break;
  12691. }
  12692. case 'CanonicalFormat': {
  12693. $ff += 1 << 9;
  12694. break;
  12695. }
  12696. case 'ExclNonUserAnnots': {
  12697. $ff += 1 << 10;
  12698. break;
  12699. }
  12700. case 'ExclFKey': {
  12701. $ff += 1 << 11;
  12702. break;
  12703. }
  12704. case 'EmbedForm': {
  12705. $ff += 1 << 13;
  12706. break;
  12707. }
  12708. }
  12709. }
  12710. } else {
  12711. $ff = intval($val);
  12712. }
  12713. $opt['aa'] .= ' /Flags '.$ff;
  12714. }
  12715. }
  12716. $opt['aa'] .= ' >>';
  12717. } else {
  12718. // Javascript action or raw action command
  12719. $js_obj_id = $this->addJavascriptObject($action);
  12720. $opt['aa'] = '/D '.$js_obj_id.' 0 R';
  12721. }
  12722. }
  12723. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  12724. if ($this->rtl) {
  12725. $this->x -= $w;
  12726. } else {
  12727. $this->x += $w;
  12728. }
  12729. }
  12730. // --- END FORMS FIELDS ------------------------------------------------
  12731. /**
  12732. * Add certification signature (DocMDP or UR3)
  12733. * You can set only one signature type
  12734. * @protected
  12735. * @author Nicola Asuni
  12736. * @since 4.6.008 (2009-05-07)
  12737. */
  12738. protected function _putsignature() {
  12739. if ((!$this->sign) OR (!isset($this->signature_data['cert_type']))) {
  12740. return;
  12741. }
  12742. $sigobjid = ($this->sig_obj_id + 1);
  12743. $out = $this->_getobj($sigobjid)."\n";
  12744. $out .= '<< /Type /Sig';
  12745. $out .= ' /Filter /Adobe.PPKLite';
  12746. $out .= ' /SubFilter /adbe.pkcs7.detached';
  12747. $out .= ' '.TCPDF_STATIC::$byterange_string;
  12748. $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length).'>';
  12749. $out .= ' /Reference ['; // array of signature reference dictionaries
  12750. $out .= ' << /Type /SigRef';
  12751. if ($this->signature_data['cert_type'] > 0) {
  12752. $out .= ' /TransformMethod /DocMDP';
  12753. $out .= ' /TransformParams <<';
  12754. $out .= ' /Type /TransformParams';
  12755. $out .= ' /P '.$this->signature_data['cert_type'];
  12756. $out .= ' /V /1.2';
  12757. } else {
  12758. $out .= ' /TransformMethod /UR3';
  12759. $out .= ' /TransformParams <<';
  12760. $out .= ' /Type /TransformParams';
  12761. $out .= ' /V /2.2';
  12762. if (!TCPDF_STATIC::empty_string($this->ur['document'])) {
  12763. $out .= ' /Document['.$this->ur['document'].']';
  12764. }
  12765. if (!TCPDF_STATIC::empty_string($this->ur['form'])) {
  12766. $out .= ' /Form['.$this->ur['form'].']';
  12767. }
  12768. if (!TCPDF_STATIC::empty_string($this->ur['signature'])) {
  12769. $out .= ' /Signature['.$this->ur['signature'].']';
  12770. }
  12771. if (!TCPDF_STATIC::empty_string($this->ur['annots'])) {
  12772. $out .= ' /Annots['.$this->ur['annots'].']';
  12773. }
  12774. if (!TCPDF_STATIC::empty_string($this->ur['ef'])) {
  12775. $out .= ' /EF['.$this->ur['ef'].']';
  12776. }
  12777. if (!TCPDF_STATIC::empty_string($this->ur['formex'])) {
  12778. $out .= ' /FormEX['.$this->ur['formex'].']';
  12779. }
  12780. }
  12781. $out .= ' >>'; // close TransformParams
  12782. // optional digest data (values must be calculated and replaced later)
  12783. //$out .= ' /Data ********** 0 R';
  12784. //$out .= ' /DigestMethod/MD5';
  12785. //$out .= ' /DigestLocation[********** 34]';
  12786. //$out .= ' /DigestValue<********************************>';
  12787. $out .= ' >>';
  12788. $out .= ' ]'; // end of reference
  12789. if (isset($this->signature_data['info']['Name']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Name'])) {
  12790. $out .= ' /Name '.$this->_textstring($this->signature_data['info']['Name'], $sigobjid);
  12791. }
  12792. if (isset($this->signature_data['info']['Location']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Location'])) {
  12793. $out .= ' /Location '.$this->_textstring($this->signature_data['info']['Location'], $sigobjid);
  12794. }
  12795. if (isset($this->signature_data['info']['Reason']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['Reason'])) {
  12796. $out .= ' /Reason '.$this->_textstring($this->signature_data['info']['Reason'], $sigobjid);
  12797. }
  12798. if (isset($this->signature_data['info']['ContactInfo']) AND !TCPDF_STATIC::empty_string($this->signature_data['info']['ContactInfo'])) {
  12799. $out .= ' /ContactInfo '.$this->_textstring($this->signature_data['info']['ContactInfo'], $sigobjid);
  12800. }
  12801. $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp);
  12802. $out .= ' >>';
  12803. $out .= "\n".'endobj';
  12804. $this->_out($out);
  12805. }
  12806. /**
  12807. * Set User's Rights for PDF Reader
  12808. * WARNING: This is experimental and currently do not work.
  12809. * Check the PDF Reference 8.7.1 Transform Methods,
  12810. * Table 8.105 Entries in the UR transform parameters dictionary
  12811. * @param $enable (boolean) if true enable user's rights on PDF reader
  12812. * @param $document (string) 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.
  12813. * @param $annots (string) 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.
  12814. * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  12815. * @param $signature (string) 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.
  12816. * @param $ef (string) 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
  12817. Names specifying additional embedded-files-related usage rights for the document.
  12818. * @param $formex (string) 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.
  12819. * @public
  12820. * @author Nicola Asuni
  12821. * @since 2.9.000 (2008-03-26)
  12822. */
  12823. public function setUserRights(
  12824. $enable=true,
  12825. $document='/FullSave',
  12826. $annots='/Create/Delete/Modify/Copy/Import/Export',
  12827. $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
  12828. $signature='/Modify',
  12829. $ef='/Create/Delete/Modify/Import',
  12830. $formex='') {
  12831. $this->ur['enabled'] = $enable;
  12832. $this->ur['document'] = $document;
  12833. $this->ur['annots'] = $annots;
  12834. $this->ur['form'] = $form;
  12835. $this->ur['signature'] = $signature;
  12836. $this->ur['ef'] = $ef;
  12837. $this->ur['formex'] = $formex;
  12838. if (!$this->sign) {
  12839. $this->setSignature('', '', '', '', 0, array());
  12840. }
  12841. }
  12842. /**
  12843. * Enable document signature (requires the OpenSSL Library).
  12844. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  12845. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12846. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12847. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  12848. * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
  12849. * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
  12850. * @param $private_key_password (string) password
  12851. * @param $extracerts (string) 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.
  12852. * @param $cert_type (int) 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.
  12853. * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
  12854. * @public
  12855. * @author Nicola Asuni
  12856. * @since 4.6.005 (2009-04-24)
  12857. */
  12858. public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
  12859. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  12860. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  12861. // to convert pfx certificate to pem: openssl
  12862. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  12863. $this->sign = true;
  12864. ++$this->n;
  12865. $this->sig_obj_id = $this->n; // signature widget
  12866. ++$this->n; // signature object ($this->sig_obj_id + 1)
  12867. $this->signature_data = array();
  12868. if (strlen($signing_cert) == 0) {
  12869. $this->Error('Please provide a certificate file and password!');
  12870. }
  12871. if (strlen($private_key) == 0) {
  12872. $private_key = $signing_cert;
  12873. }
  12874. $this->signature_data['signcert'] = $signing_cert;
  12875. $this->signature_data['privkey'] = $private_key;
  12876. $this->signature_data['password'] = $private_key_password;
  12877. $this->signature_data['extracerts'] = $extracerts;
  12878. $this->signature_data['cert_type'] = $cert_type;
  12879. $this->signature_data['info'] = $info;
  12880. }
  12881. /**
  12882. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  12883. * @param $x (float) Abscissa of the upper-left corner.
  12884. * @param $y (float) Ordinate of the upper-left corner.
  12885. * @param $w (float) Width of the signature area.
  12886. * @param $h (float) Height of the signature area.
  12887. * @param $page (int) option page number (if < 0 the current page is used).
  12888. * @param $name (string) Name of the signature.
  12889. * @public
  12890. * @author Nicola Asuni
  12891. * @since 5.3.011 (2010-06-17)
  12892. */
  12893. public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12894. $this->signature_appearance = $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  12895. }
  12896. /**
  12897. * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
  12898. * @param $x (float) Abscissa of the upper-left corner.
  12899. * @param $y (float) Ordinate of the upper-left corner.
  12900. * @param $w (float) Width of the signature area.
  12901. * @param $h (float) Height of the signature area.
  12902. * @param $page (int) option page number (if < 0 the current page is used).
  12903. * @param $name (string) Name of the signature.
  12904. * @public
  12905. * @author Nicola Asuni
  12906. * @since 5.9.101 (2011-07-06)
  12907. */
  12908. public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12909. ++$this->n;
  12910. $this->empty_signature_appearance[] = array('objid' => $this->n) + $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
  12911. }
  12912. /**
  12913. * Get the array that defines the signature appearance (page and rectangle coordinates).
  12914. * @param $x (float) Abscissa of the upper-left corner.
  12915. * @param $y (float) Ordinate of the upper-left corner.
  12916. * @param $w (float) Width of the signature area.
  12917. * @param $h (float) Height of the signature area.
  12918. * @param $page (int) option page number (if < 0 the current page is used).
  12919. * @param $name (string) Name of the signature.
  12920. * @return (array) Array defining page and rectangle coordinates of signature appearance.
  12921. * @protected
  12922. * @author Nicola Asuni
  12923. * @since 5.9.101 (2011-07-06)
  12924. */
  12925. protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
  12926. $sigapp = array();
  12927. if (($page < 1) OR ($page > $this->numpages)) {
  12928. $sigapp['page'] = $this->page;
  12929. } else {
  12930. $sigapp['page'] = intval($page);
  12931. }
  12932. if (empty($name)) {
  12933. $sigapp['name'] = 'Signature';
  12934. } else {
  12935. $sigapp['name'] = $name;
  12936. }
  12937. $a = $x * $this->k;
  12938. $b = $this->pagedim[($sigapp['page'])]['h'] - (($y + $h) * $this->k);
  12939. $c = $w * $this->k;
  12940. $d = $h * $this->k;
  12941. $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a + $c), ($b + $d));
  12942. return $sigapp;
  12943. }
  12944. /**
  12945. * Create a new page group.
  12946. * NOTE: call this function before calling AddPage()
  12947. * @param $page (int) starting group page (leave empty for next page).
  12948. * @public
  12949. * @since 3.0.000 (2008-03-27)
  12950. */
  12951. public function startPageGroup($page='') {
  12952. if (empty($page)) {
  12953. $page = $this->page + 1;
  12954. }
  12955. $this->newpagegroup[$page] = sizeof($this->newpagegroup) + 1;
  12956. }
  12957. /**
  12958. * Set the starting page number.
  12959. * @param $num (int) Starting page number.
  12960. * @since 5.9.093 (2011-06-16)
  12961. * @public
  12962. */
  12963. public function setStartingPageNumber($num=1) {
  12964. $this->starting_page_number = max(0, intval($num));
  12965. }
  12966. /**
  12967. * Returns the string alias used right align page numbers.
  12968. * If the current font is unicode type, the returned string wil contain an additional open curly brace.
  12969. * @return string
  12970. * @since 5.9.099 (2011-06-27)
  12971. * @public
  12972. */
  12973. public function getAliasRightShift() {
  12974. // calculate aproximatively the ratio between widths of aliases and replacements.
  12975. $ref = '{'.TCPDF_STATIC::$alias_right_shift.'}{'.TCPDF_STATIC::$alias_tot_pages.'}{'.TCPDF_STATIC::$alias_num_page.'}';
  12976. $rep = str_repeat(' ', $this->GetNumChars($ref));
  12977. $wrep = $this->GetStringWidth($rep);
  12978. if ($wrep > 0) {
  12979. $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
  12980. } else {
  12981. $wdiff = 1;
  12982. }
  12983. $sdiff = sprintf('%F', $wdiff);
  12984. $alias = TCPDF_STATIC::$alias_right_shift.$sdiff.'}';
  12985. if ($this->isUnicodeFont()) {
  12986. $alias = '{'.$alias;
  12987. }
  12988. return $alias;
  12989. }
  12990. /**
  12991. * Returns the string alias used for the total number of pages.
  12992. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  12993. * This alias will be replaced by the total number of pages in the document.
  12994. * @return string
  12995. * @since 4.0.018 (2008-08-08)
  12996. * @public
  12997. */
  12998. public function getAliasNbPages() {
  12999. if ($this->isUnicodeFont()) {
  13000. return '{'.TCPDF_STATIC::$alias_tot_pages.'}';
  13001. }
  13002. return TCPDF_STATIC::$alias_tot_pages;
  13003. }
  13004. /**
  13005. * Returns the string alias used for the page number.
  13006. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13007. * This alias will be replaced by the page number.
  13008. * @return string
  13009. * @since 4.5.000 (2009-01-02)
  13010. * @public
  13011. */
  13012. public function getAliasNumPage() {
  13013. if ($this->isUnicodeFont()) {
  13014. return '{'.TCPDF_STATIC::$alias_num_page.'}';
  13015. }
  13016. return TCPDF_STATIC::$alias_num_page;
  13017. }
  13018. /**
  13019. * Return the alias for the total number of pages in the current page group.
  13020. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13021. * This alias will be replaced by the total number of pages in this group.
  13022. * @return alias of the current page group
  13023. * @public
  13024. * @since 3.0.000 (2008-03-27)
  13025. */
  13026. public function getPageGroupAlias() {
  13027. if ($this->isUnicodeFont()) {
  13028. return '{'.TCPDF_STATIC::$alias_group_tot_pages.'}';
  13029. }
  13030. return TCPDF_STATIC::$alias_group_tot_pages;
  13031. }
  13032. /**
  13033. * Return the alias for the page number on the current page group.
  13034. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  13035. * This alias will be replaced by the page number (relative to the belonging group).
  13036. * @return alias of the current page group
  13037. * @public
  13038. * @since 4.5.000 (2009-01-02)
  13039. */
  13040. public function getPageNumGroupAlias() {
  13041. if ($this->isUnicodeFont()) {
  13042. return '{'.TCPDF_STATIC::$alias_group_num_page.'}';
  13043. }
  13044. return TCPDF_STATIC::$alias_group_num_page;
  13045. }
  13046. /**
  13047. * Return the current page in the group.
  13048. * @return current page in the group
  13049. * @public
  13050. * @since 3.0.000 (2008-03-27)
  13051. */
  13052. public function getGroupPageNo() {
  13053. return $this->pagegroups[$this->currpagegroup];
  13054. }
  13055. /**
  13056. * Returns the current group page number formatted as a string.
  13057. * @public
  13058. * @since 4.3.003 (2008-11-18)
  13059. * @see PaneNo(), formatPageNumber()
  13060. */
  13061. public function getGroupPageNoFormatted() {
  13062. return TCPDF_STATIC::formatPageNumber($this->getGroupPageNo());
  13063. }
  13064. /**
  13065. * Returns the current page number formatted as a string.
  13066. * @public
  13067. * @since 4.2.005 (2008-11-06)
  13068. * @see PaneNo(), formatPageNumber()
  13069. */
  13070. public function PageNoFormatted() {
  13071. return TCPDF_STATIC::formatPageNumber($this->PageNo());
  13072. }
  13073. /**
  13074. * Put pdf layers.
  13075. * @protected
  13076. * @since 3.0.000 (2008-03-27)
  13077. */
  13078. protected function _putocg() {
  13079. if (empty($this->pdflayers)) {
  13080. return;
  13081. }
  13082. foreach ($this->pdflayers as $key => $layer) {
  13083. $this->pdflayers[$key]['objid'] = $this->_newobj();
  13084. $out = '<< /Type /OCG';
  13085. $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers[$key]['objid']);
  13086. $out .= ' /Usage <<';
  13087. $out .= ' /Print <</PrintState /'.($layer['print']?'ON':'OFF').'>>';
  13088. $out .= ' /View <</ViewState /'.($layer['view']?'ON':'OFF').'>>';
  13089. $out .= ' >> >>';
  13090. $out .= "\n".'endobj';
  13091. $this->_out($out);
  13092. }
  13093. }
  13094. /**
  13095. * Start a new pdf layer.
  13096. * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name.
  13097. * @param $print (boolean) Set to true to print this layer.
  13098. * @param $view (boolean) Set to true to view this layer.
  13099. * @public
  13100. * @since 5.9.102 (2011-07-13)
  13101. */
  13102. public function startLayer($name='', $print=true, $view=true) {
  13103. if ($this->state != 2) {
  13104. return;
  13105. }
  13106. $layer = sprintf('LYR%03d', (count($this->pdflayers) + 1));
  13107. if (empty($name)) {
  13108. $name = $layer;
  13109. } else {
  13110. $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
  13111. }
  13112. $this->pdflayers[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view);
  13113. $this->openMarkedContent = true;
  13114. $this->_out('/OC /'.$layer.' BDC');
  13115. }
  13116. /**
  13117. * End the current PDF layer.
  13118. * @public
  13119. * @since 5.9.102 (2011-07-13)
  13120. */
  13121. public function endLayer() {
  13122. if ($this->state != 2) {
  13123. return;
  13124. }
  13125. if ($this->openMarkedContent) {
  13126. // close existing open marked-content layer
  13127. $this->_out('EMC');
  13128. $this->openMarkedContent = false;
  13129. }
  13130. }
  13131. /**
  13132. * Set the visibility of the successive elements.
  13133. * This can be useful, for instance, to put a background
  13134. * image or color that will show on screen but won't print.
  13135. * @param $v (string) visibility mode. Legal values are: all, print, screen or view.
  13136. * @public
  13137. * @since 3.0.000 (2008-03-27)
  13138. */
  13139. public function setVisibility($v) {
  13140. if ($this->state != 2) {
  13141. return;
  13142. }
  13143. $this->endLayer();
  13144. switch($v) {
  13145. case 'print': {
  13146. $this->startLayer('Print', true, false);
  13147. break;
  13148. }
  13149. case 'view':
  13150. case 'screen': {
  13151. $this->startLayer('View', false, true);
  13152. break;
  13153. }
  13154. case 'all': {
  13155. $this->_out('');
  13156. break;
  13157. }
  13158. default: {
  13159. $this->Error('Incorrect visibility: '.$v);
  13160. break;
  13161. }
  13162. }
  13163. }
  13164. /**
  13165. * Add transparency parameters to the current extgstate
  13166. * @param $parms (array) parameters
  13167. * @return the number of extgstates
  13168. * @protected
  13169. * @since 3.0.000 (2008-03-27)
  13170. */
  13171. protected function addExtGState($parms) {
  13172. if ($this->pdfa_mode) {
  13173. // transparencies are not allowed in PDF/A mode
  13174. return;
  13175. }
  13176. // check if this ExtGState already exist
  13177. foreach ($this->extgstates as $i => $ext) {
  13178. if ($ext['parms'] == $parms) {
  13179. if ($this->inxobj) {
  13180. // we are inside an XObject template
  13181. $this->xobjects[$this->xobjid]['extgstates'][$i] = $ext;
  13182. }
  13183. // return reference to existing ExtGState
  13184. return $i;
  13185. }
  13186. }
  13187. $n = (count($this->extgstates) + 1);
  13188. $this->extgstates[$n] = array('parms' => $parms);
  13189. if ($this->inxobj) {
  13190. // we are inside an XObject template
  13191. $this->xobjects[$this->xobjid]['extgstates'][$n] = $this->extgstates[$n];
  13192. }
  13193. return $n;
  13194. }
  13195. /**
  13196. * Add an extgstate
  13197. * @param $gs (array) extgstate
  13198. * @protected
  13199. * @since 3.0.000 (2008-03-27)
  13200. */
  13201. protected function setExtGState($gs) {
  13202. if ($this->pdfa_mode OR ($this->state != 2)) {
  13203. // transparency is not allowed in PDF/A mode
  13204. return;
  13205. }
  13206. $this->_out(sprintf('/GS%d gs', $gs));
  13207. }
  13208. /**
  13209. * Put extgstates for object transparency
  13210. * @protected
  13211. * @since 3.0.000 (2008-03-27)
  13212. */
  13213. protected function _putextgstates() {
  13214. foreach ($this->extgstates as $i => $ext) {
  13215. $this->extgstates[$i]['n'] = $this->_newobj();
  13216. $out = '<< /Type /ExtGState';
  13217. foreach ($ext['parms'] as $k => $v) {
  13218. if (is_float($v)) {
  13219. $v = sprintf('%F', $v);
  13220. } elseif ($v === true) {
  13221. $v = 'true';
  13222. } elseif ($v === false) {
  13223. $v = 'false';
  13224. }
  13225. $out .= ' /'.$k.' '.$v;
  13226. }
  13227. $out .= ' >>';
  13228. $out .= "\n".'endobj';
  13229. $this->_out($out);
  13230. }
  13231. }
  13232. /**
  13233. * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
  13234. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13235. * @param $stroking (boolean) If true apply overprint for stroking operations.
  13236. * @param $nonstroking (boolean) If true apply overprint for painting operations other than stroking.
  13237. * @param $mode (integer) 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).
  13238. * @public
  13239. * @since 5.9.152 (2012-03-23)
  13240. */
  13241. public function setOverprint($stroking=true, $nonstroking='', $mode=0) {
  13242. if ($this->state != 2) {
  13243. return;
  13244. }
  13245. $stroking = $stroking ? true : false;
  13246. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13247. // default value if not set
  13248. $nonstroking = $stroking;
  13249. } else {
  13250. $nonstroking = $nonstroking ? true : false;
  13251. }
  13252. if (($mode != 0) AND ($mode != 1)) {
  13253. $mode = 0;
  13254. }
  13255. $this->overprint = array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
  13256. $gs = $this->addExtGState($this->overprint);
  13257. $this->setExtGState($gs);
  13258. }
  13259. /**
  13260. * Get the overprint mode array (OP, op, OPM).
  13261. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13262. * @return array.
  13263. * @public
  13264. * @since 5.9.152 (2012-03-23)
  13265. */
  13266. public function getOverprint() {
  13267. return $this->overprint;
  13268. }
  13269. /**
  13270. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  13271. * @param $stroking (float) Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
  13272. * @param $bm (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  13273. * @param $nonstroking (float) Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
  13274. * @param $ais (boolean)
  13275. * @public
  13276. * @since 3.0.000 (2008-03-27)
  13277. */
  13278. public function setAlpha($stroking=1, $bm='Normal', $nonstroking='', $ais=false) {
  13279. if ($this->pdfa_mode) {
  13280. // transparency is not allowed in PDF/A mode
  13281. return;
  13282. }
  13283. $stroking = floatval($stroking);
  13284. if (TCPDF_STATIC::empty_string($nonstroking)) {
  13285. // default value if not set
  13286. $nonstroking = $stroking;
  13287. } else {
  13288. $nonstroking = floatval($nonstroking);
  13289. }
  13290. if ($bm[0] == '/') {
  13291. // remove trailing slash
  13292. $bm = substr($bm, 1);
  13293. }
  13294. if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
  13295. $bm = 'Normal';
  13296. }
  13297. $ais = $ais ? true : false;
  13298. $this->alpha = array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
  13299. $gs = $this->addExtGState($this->alpha);
  13300. $this->setExtGState($gs);
  13301. }
  13302. /**
  13303. * Get the alpha mode array (CA, ca, BM, AIS).
  13304. * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
  13305. * @return array.
  13306. * @public
  13307. * @since 5.9.152 (2012-03-23)
  13308. */
  13309. public function getAlpha() {
  13310. return $this->alpha;
  13311. }
  13312. /**
  13313. * Set the default JPEG compression quality (1-100)
  13314. * @param $quality (int) JPEG quality, integer between 1 and 100
  13315. * @public
  13316. * @since 3.0.000 (2008-03-27)
  13317. */
  13318. public function setJPEGQuality($quality) {
  13319. if (($quality < 1) OR ($quality > 100)) {
  13320. $quality = 75;
  13321. }
  13322. $this->jpeg_quality = intval($quality);
  13323. }
  13324. /**
  13325. * Set the default number of columns in a row for HTML tables.
  13326. * @param $cols (int) number of columns
  13327. * @public
  13328. * @since 3.0.014 (2008-06-04)
  13329. */
  13330. public function setDefaultTableColumns($cols=4) {
  13331. $this->default_table_columns = intval($cols);
  13332. }
  13333. /**
  13334. * Set the height of the cell (line height) respect the font height.
  13335. * @param $h (int) cell proportion respect font height (typical value = 1.25).
  13336. * @public
  13337. * @since 3.0.014 (2008-06-04)
  13338. */
  13339. public function setCellHeightRatio($h) {
  13340. $this->cell_height_ratio = $h;
  13341. }
  13342. /**
  13343. * return the height of cell repect font height.
  13344. * @public
  13345. * @since 4.0.012 (2008-07-24)
  13346. */
  13347. public function getCellHeightRatio() {
  13348. return $this->cell_height_ratio;
  13349. }
  13350. /**
  13351. * Set the PDF version (check PDF reference for valid values).
  13352. * @param $version (string) PDF document version.
  13353. * @public
  13354. * @since 3.1.000 (2008-06-09)
  13355. */
  13356. public function setPDFVersion($version='1.7') {
  13357. if ($this->pdfa_mode) {
  13358. // PDF/A mode
  13359. $this->PDFVersion = '1.4';
  13360. } else {
  13361. $this->PDFVersion = $version;
  13362. }
  13363. }
  13364. /**
  13365. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  13366. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  13367. * <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>
  13368. * @param $preferences (array) array of options.
  13369. * @author Nicola Asuni
  13370. * @public
  13371. * @since 3.1.000 (2008-06-09)
  13372. */
  13373. public function setViewerPreferences($preferences) {
  13374. $this->viewer_preferences = $preferences;
  13375. }
  13376. /**
  13377. * Paints color transition registration bars
  13378. * @param $x (float) abscissa of the top left corner of the rectangle.
  13379. * @param $y (float) ordinate of the top left corner of the rectangle.
  13380. * @param $w (float) width of the rectangle.
  13381. * @param $h (float) height of the rectangle.
  13382. * @param $transition (boolean) if true prints tcolor transitions to white.
  13383. * @param $vertical (boolean) if true prints bar vertically.
  13384. * @param $colors (string) 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.
  13385. * @author Nicola Asuni
  13386. * @since 4.9.000 (2010-03-26)
  13387. * @public
  13388. */
  13389. public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
  13390. if (strpos($colors, 'ALLSPOT') !== false) {
  13391. // expand spot colors
  13392. $spot_colors = '';
  13393. foreach ($this->spot_colors as $spot_color_name => $v) {
  13394. $spot_colors .= ','.$spot_color_name;
  13395. }
  13396. if (!empty($spot_colors)) {
  13397. $spot_colors = substr($spot_colors, 1);
  13398. $colors = str_replace('ALLSPOT', $spot_colors, $colors);
  13399. } else {
  13400. $colors = str_replace('ALLSPOT', 'NONE', $colors);
  13401. }
  13402. }
  13403. $bars = explode(',', $colors);
  13404. $numbars = count($bars); // number of bars to print
  13405. if ($numbars <= 0) {
  13406. return;
  13407. }
  13408. // set bar measures
  13409. if ($vertical) {
  13410. $coords = array(0, 0, 0, 1);
  13411. $wb = $w / $numbars; // bar width
  13412. $hb = $h; // bar height
  13413. $xd = $wb; // delta x
  13414. $yd = 0; // delta y
  13415. } else {
  13416. $coords = array(1, 0, 0, 0);
  13417. $wb = $w; // bar width
  13418. $hb = $h / $numbars; // bar height
  13419. $xd = 0; // delta x
  13420. $yd = $hb; // delta y
  13421. }
  13422. $xb = $x;
  13423. $yb = $y;
  13424. foreach ($bars as $col) {
  13425. switch ($col) {
  13426. // set transition colors
  13427. case 'A': { // BLACK (GRAYSCALE)
  13428. $col_a = array(255);
  13429. $col_b = array(0);
  13430. break;
  13431. }
  13432. case 'W': { // WHITE (GRAYSCALE)
  13433. $col_a = array(0);
  13434. $col_b = array(255);
  13435. break;
  13436. }
  13437. case 'R': { // RED (RGB)
  13438. $col_a = array(255,255,255);
  13439. $col_b = array(255,0,0);
  13440. break;
  13441. }
  13442. case 'G': { // GREEN (RGB)
  13443. $col_a = array(255,255,255);
  13444. $col_b = array(0,255,0);
  13445. break;
  13446. }
  13447. case 'B': { // BLUE (RGB)
  13448. $col_a = array(255,255,255);
  13449. $col_b = array(0,0,255);
  13450. break;
  13451. }
  13452. case 'C': { // CYAN (CMYK)
  13453. $col_a = array(0,0,0,0);
  13454. $col_b = array(100,0,0,0);
  13455. break;
  13456. }
  13457. case 'M': { // MAGENTA (CMYK)
  13458. $col_a = array(0,0,0,0);
  13459. $col_b = array(0,100,0,0);
  13460. break;
  13461. }
  13462. case 'Y': { // YELLOW (CMYK)
  13463. $col_a = array(0,0,0,0);
  13464. $col_b = array(0,0,100,0);
  13465. break;
  13466. }
  13467. case 'K': { // KEY - BLACK (CMYK)
  13468. $col_a = array(0,0,0,0);
  13469. $col_b = array(0,0,0,100);
  13470. break;
  13471. }
  13472. case 'RGB': { // BLACK REGISTRATION (RGB)
  13473. $col_a = array(255,255,255);
  13474. $col_b = array(0,0,0);
  13475. break;
  13476. }
  13477. case 'CMYK': { // BLACK REGISTRATION (CMYK)
  13478. $col_a = array(0,0,0,0);
  13479. $col_b = array(100,100,100,100);
  13480. break;
  13481. }
  13482. case 'ALL': { // SPOT COLOR REGISTRATION
  13483. $col_a = array(0,0,0,0,'None');
  13484. $col_b = array(100,100,100,100,'All');
  13485. break;
  13486. }
  13487. case 'NONE': { // SKIP THIS COLOR
  13488. $col_a = array(0,0,0,0,'None');
  13489. $col_b = array(0,0,0,0,'None');
  13490. break;
  13491. }
  13492. default: { // SPECIFIC SPOT COLOR NAME
  13493. $col_a = array(0,0,0,0,'None');
  13494. $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
  13495. if ($col_b === false) {
  13496. // in case of error defaults to the registration color
  13497. $col_b = array(100,100,100,100,'All');
  13498. }
  13499. break;
  13500. }
  13501. }
  13502. if ($col != 'NONE') {
  13503. if ($transition) {
  13504. // color gradient
  13505. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  13506. } else {
  13507. $this->SetFillColorArray($col_b);
  13508. // colored rectangle
  13509. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  13510. }
  13511. $xb += $xd;
  13512. $yb += $yd;
  13513. }
  13514. }
  13515. }
  13516. /**
  13517. * Paints crop marks.
  13518. * @param $x (float) abscissa of the crop mark center.
  13519. * @param $y (float) ordinate of the crop mark center.
  13520. * @param $w (float) width of the crop mark.
  13521. * @param $h (float) height of the crop mark.
  13522. * @param $type (string) 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.
  13523. * @param $color (array) crop mark color (default spot registration color).
  13524. * @author Nicola Asuni
  13525. * @since 4.9.000 (2010-03-26)
  13526. * @public
  13527. */
  13528. public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
  13529. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
  13530. $type = strtoupper($type);
  13531. $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
  13532. // split type in single components
  13533. $type = str_replace('-', ',', $type);
  13534. $type = str_replace('TL', 'T,L', $type);
  13535. $type = str_replace('TR', 'T,R', $type);
  13536. $type = str_replace('BL', 'F,L', $type);
  13537. $type = str_replace('BR', 'F,R', $type);
  13538. $type = str_replace('A', 'T,L', $type);
  13539. $type = str_replace('B', 'T,R', $type);
  13540. $type = str_replace('T,RO', 'BO', $type);
  13541. $type = str_replace('C', 'F,L', $type);
  13542. $type = str_replace('D', 'F,R', $type);
  13543. $crops = explode(',', strtoupper($type));
  13544. // remove duplicates
  13545. $crops = array_unique($crops);
  13546. $dw = ($w / 4); // horizontal space to leave before the intersection point
  13547. $dh = ($h / 4); // vertical space to leave before the intersection point
  13548. foreach ($crops as $crop) {
  13549. switch ($crop) {
  13550. case 'T':
  13551. case 'TOP': {
  13552. $x1 = $x;
  13553. $y1 = ($y - $h);
  13554. $x2 = $x;
  13555. $y2 = ($y - $dh);
  13556. break;
  13557. }
  13558. case 'F':
  13559. case 'BOTTOM': {
  13560. $x1 = $x;
  13561. $y1 = ($y + $dh);
  13562. $x2 = $x;
  13563. $y2 = ($y + $h);
  13564. break;
  13565. }
  13566. case 'L':
  13567. case 'LEFT': {
  13568. $x1 = ($x - $w);
  13569. $y1 = $y;
  13570. $x2 = ($x - $dw);
  13571. $y2 = $y;
  13572. break;
  13573. }
  13574. case 'R':
  13575. case 'RIGHT': {
  13576. $x1 = ($x + $dw);
  13577. $y1 = $y;
  13578. $x2 = ($x + $w);
  13579. $y2 = $y;
  13580. break;
  13581. }
  13582. }
  13583. $this->Line($x1, $y1, $x2, $y2);
  13584. }
  13585. }
  13586. /**
  13587. * Paints a registration mark
  13588. * @param $x (float) abscissa of the registration mark center.
  13589. * @param $y (float) ordinate of the registration mark center.
  13590. * @param $r (float) radius of the crop mark.
  13591. * @param $double (boolean) if true print two concentric crop marks.
  13592. * @param $cola (array) crop mark color (default spot registration color 'All').
  13593. * @param $colb (array) second crop mark color (default spot registration color 'None').
  13594. * @author Nicola Asuni
  13595. * @since 4.9.000 (2010-03-26)
  13596. * @public
  13597. */
  13598. public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
  13599. $line_style = array('width' => max((0.5 / $this->k),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
  13600. $this->SetFillColorArray($cola);
  13601. $this->PieSector($x, $y, $r, 90, 180, 'F');
  13602. $this->PieSector($x, $y, $r, 270, 360, 'F');
  13603. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13604. if ($double) {
  13605. $ri = $r * 0.5;
  13606. $this->SetFillColorArray($colb);
  13607. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13608. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13609. $this->SetFillColorArray($cola);
  13610. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13611. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13612. $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
  13613. }
  13614. }
  13615. /**
  13616. * Paints a CMYK registration mark
  13617. * @param $x (float) abscissa of the registration mark center.
  13618. * @param $y (float) ordinate of the registration mark center.
  13619. * @param $r (float) radius of the crop mark.
  13620. * @author Nicola Asuni
  13621. * @since 6.0.038 (2013-09-30)
  13622. * @public
  13623. */
  13624. public function registrationMarkCMYK($x, $y, $r) {
  13625. // line width
  13626. $lw = max((0.5 / $this->k),($r / 8));
  13627. // internal radius
  13628. $ri = ($r * 0.6);
  13629. // external radius
  13630. $re = ($r * 1.3);
  13631. // Cyan
  13632. $this->SetFillColorArray(array(100,0,0,0));
  13633. $this->PieSector($x, $y, $ri, 270, 360, 'F');
  13634. // Magenta
  13635. $this->SetFillColorArray(array(0,100,0,0));
  13636. $this->PieSector($x, $y, $ri, 0, 90, 'F');
  13637. // Yellow
  13638. $this->SetFillColorArray(array(0,0,100,0));
  13639. $this->PieSector($x, $y, $ri, 90, 180, 'F');
  13640. // Key - black
  13641. $this->SetFillColorArray(array(0,0,0,100));
  13642. $this->PieSector($x, $y, $ri, 180, 270, 'F');
  13643. // registration color
  13644. $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
  13645. $this->SetFillColorArray(array(100,100,100,100,'All'));
  13646. // external circle
  13647. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  13648. // cross lines
  13649. $this->Line($x, ($y - $re), $x, ($y - $ri));
  13650. $this->Line($x, ($y + $ri), $x, ($y + $re));
  13651. $this->Line(($x - $re), $y, ($x - $ri), $y);
  13652. $this->Line(($x + $ri), $y, ($x + $re), $y);
  13653. }
  13654. /**
  13655. * Paints a linear colour gradient.
  13656. * @param $x (float) abscissa of the top left corner of the rectangle.
  13657. * @param $y (float) ordinate of the top left corner of the rectangle.
  13658. * @param $w (float) width of the rectangle.
  13659. * @param $h (float) height of the rectangle.
  13660. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  13661. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  13662. * @param $coords (array) 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).
  13663. * @author Andreas W\FCrmser, Nicola Asuni
  13664. * @since 3.1.000 (2008-06-09)
  13665. * @public
  13666. */
  13667. public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
  13668. $this->Clip($x, $y, $w, $h);
  13669. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13670. }
  13671. /**
  13672. * Paints a radial colour gradient.
  13673. * @param $x (float) abscissa of the top left corner of the rectangle.
  13674. * @param $y (float) ordinate of the top left corner of the rectangle.
  13675. * @param $w (float) width of the rectangle.
  13676. * @param $h (float) height of the rectangle.
  13677. * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
  13678. * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
  13679. * @param $coords (array) 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.
  13680. * @author Andreas W\FCrmser, Nicola Asuni
  13681. * @since 3.1.000 (2008-06-09)
  13682. * @public
  13683. */
  13684. public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
  13685. $this->Clip($x, $y, $w, $h);
  13686. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  13687. }
  13688. /**
  13689. * Paints a coons patch mesh.
  13690. * @param $x (float) abscissa of the top left corner of the rectangle.
  13691. * @param $y (float) ordinate of the top left corner of the rectangle.
  13692. * @param $w (float) width of the rectangle.
  13693. * @param $h (float) height of the rectangle.
  13694. * @param $col1 (array) first color (lower left corner) (RGB components).
  13695. * @param $col2 (array) second color (lower right corner) (RGB components).
  13696. * @param $col3 (array) third color (upper right corner) (RGB components).
  13697. * @param $col4 (array) fourth color (upper left corner) (RGB components).
  13698. * @param $coords (array) <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>
  13699. * @param $coords_min (array) minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  13700. * @param $coords_max (array) maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  13701. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13702. * @author Andreas W\FCrmser, Nicola Asuni
  13703. * @since 3.1.000 (2008-06-09)
  13704. * @public
  13705. */
  13706. 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) {
  13707. if ($this->pdfa_mode OR ($this->state != 2)) {
  13708. return;
  13709. }
  13710. $this->Clip($x, $y, $w, $h);
  13711. $n = count($this->gradients) + 1;
  13712. $this->gradients[$n] = array();
  13713. $this->gradients[$n]['type'] = 6; //coons patch mesh
  13714. $this->gradients[$n]['coords'] = array();
  13715. $this->gradients[$n]['antialias'] = $antialias;
  13716. $this->gradients[$n]['colors'] = array();
  13717. $this->gradients[$n]['transparency'] = false;
  13718. //check the coords array if it is the simple array or the multi patch array
  13719. if (!isset($coords[0]['f'])) {
  13720. //simple array -> convert to multi patch array
  13721. if (!isset($col1[1])) {
  13722. $col1[1] = $col1[2] = $col1[0];
  13723. }
  13724. if (!isset($col2[1])) {
  13725. $col2[1] = $col2[2] = $col2[0];
  13726. }
  13727. if (!isset($col3[1])) {
  13728. $col3[1] = $col3[2] = $col3[0];
  13729. }
  13730. if (!isset($col4[1])) {
  13731. $col4[1] = $col4[2] = $col4[0];
  13732. }
  13733. $patch_array[0]['f'] = 0;
  13734. $patch_array[0]['points'] = $coords;
  13735. $patch_array[0]['colors'][0]['r'] = $col1[0];
  13736. $patch_array[0]['colors'][0]['g'] = $col1[1];
  13737. $patch_array[0]['colors'][0]['b'] = $col1[2];
  13738. $patch_array[0]['colors'][1]['r'] = $col2[0];
  13739. $patch_array[0]['colors'][1]['g'] = $col2[1];
  13740. $patch_array[0]['colors'][1]['b'] = $col2[2];
  13741. $patch_array[0]['colors'][2]['r'] = $col3[0];
  13742. $patch_array[0]['colors'][2]['g'] = $col3[1];
  13743. $patch_array[0]['colors'][2]['b'] = $col3[2];
  13744. $patch_array[0]['colors'][3]['r'] = $col4[0];
  13745. $patch_array[0]['colors'][3]['g'] = $col4[1];
  13746. $patch_array[0]['colors'][3]['b'] = $col4[2];
  13747. } else {
  13748. //multi patch array
  13749. $patch_array = $coords;
  13750. }
  13751. $bpcd = 65535; //16 bits per coordinate
  13752. //build the data stream
  13753. $this->gradients[$n]['stream'] = '';
  13754. $count_patch = count($patch_array);
  13755. for ($i=0; $i < $count_patch; ++$i) {
  13756. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  13757. $count_points = count($patch_array[$i]['points']);
  13758. for ($j=0; $j < $count_points; ++$j) {
  13759. //each point as 16 bit
  13760. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  13761. if ($patch_array[$i]['points'][$j] < 0) {
  13762. $patch_array[$i]['points'][$j] = 0;
  13763. }
  13764. if ($patch_array[$i]['points'][$j] > $bpcd) {
  13765. $patch_array[$i]['points'][$j] = $bpcd;
  13766. }
  13767. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  13768. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  13769. }
  13770. $count_cols = count($patch_array[$i]['colors']);
  13771. for ($j=0; $j < $count_cols; ++$j) {
  13772. //each color component as 8 bit
  13773. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  13774. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  13775. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  13776. }
  13777. }
  13778. //paint the gradient
  13779. $this->_out('/Sh'.$n.' sh');
  13780. //restore previous Graphic State
  13781. $this->_out('Q');
  13782. if ($this->inxobj) {
  13783. // we are inside an XObject template
  13784. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13785. }
  13786. }
  13787. /**
  13788. * Set a rectangular clipping area.
  13789. * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  13790. * @param $y (float) ordinate of the top left corner of the rectangle.
  13791. * @param $w (float) width of the rectangle.
  13792. * @param $h (float) height of the rectangle.
  13793. * @author Andreas W\FCrmser, Nicola Asuni
  13794. * @since 3.1.000 (2008-06-09)
  13795. * @protected
  13796. */
  13797. protected function Clip($x, $y, $w, $h) {
  13798. if ($this->state != 2) {
  13799. return;
  13800. }
  13801. if ($this->rtl) {
  13802. $x = $this->w - $x - $w;
  13803. }
  13804. //save current Graphic State
  13805. $s = 'q';
  13806. //set clipping area
  13807. $s .= sprintf(' %F %F %F %F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k);
  13808. //set up transformation matrix for gradient
  13809. $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k);
  13810. $this->_out($s);
  13811. }
  13812. /**
  13813. * Output gradient.
  13814. * @param $type (int) 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)
  13815. * @param $coords (array) array of coordinates.
  13816. * @param $stops (array) 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).
  13817. * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
  13818. * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  13819. * @author Nicola Asuni
  13820. * @since 3.1.000 (2008-06-09)
  13821. * @public
  13822. */
  13823. public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
  13824. if ($this->pdfa_mode OR ($this->state != 2)) {
  13825. return;
  13826. }
  13827. $n = count($this->gradients) + 1;
  13828. $this->gradients[$n] = array();
  13829. $this->gradients[$n]['type'] = $type;
  13830. $this->gradients[$n]['coords'] = $coords;
  13831. $this->gradients[$n]['antialias'] = $antialias;
  13832. $this->gradients[$n]['colors'] = array();
  13833. $this->gradients[$n]['transparency'] = false;
  13834. // color space
  13835. $numcolspace = count($stops[0]['color']);
  13836. $bcolor = array_values($background);
  13837. switch($numcolspace) {
  13838. case 5: // SPOT
  13839. case 4: { // CMYK
  13840. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  13841. if (!empty($background)) {
  13842. $this->gradients[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
  13843. }
  13844. break;
  13845. }
  13846. case 3: { // RGB
  13847. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  13848. if (!empty($background)) {
  13849. $this->gradients[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
  13850. }
  13851. break;
  13852. }
  13853. case 1: { // GRAY SCALE
  13854. $this->gradients[$n]['colspace'] = 'DeviceGray';
  13855. if (!empty($background)) {
  13856. $this->gradients[$n]['background'] = sprintf('%F', $bcolor[0]/255);
  13857. }
  13858. break;
  13859. }
  13860. }
  13861. $num_stops = count($stops);
  13862. $last_stop_id = $num_stops - 1;
  13863. foreach ($stops as $key => $stop) {
  13864. $this->gradients[$n]['colors'][$key] = array();
  13865. // offset represents a location along the gradient vector
  13866. if (isset($stop['offset'])) {
  13867. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  13868. } else {
  13869. if ($key == 0) {
  13870. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  13871. } elseif ($key == $last_stop_id) {
  13872. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  13873. } else {
  13874. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  13875. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  13876. }
  13877. }
  13878. if (isset($stop['opacity'])) {
  13879. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  13880. if ((!$this->pdfa_mode) AND ($stop['opacity'] < 1)) {
  13881. $this->gradients[$n]['transparency'] = true;
  13882. }
  13883. } else {
  13884. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  13885. }
  13886. // exponent for the exponential interpolation function
  13887. if (isset($stop['exponent'])) {
  13888. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  13889. } else {
  13890. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  13891. }
  13892. // set colors
  13893. $color = array_values($stop['color']);
  13894. switch($numcolspace) {
  13895. case 5: // SPOT
  13896. case 4: { // CMYK
  13897. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
  13898. break;
  13899. }
  13900. case 3: { // RGB
  13901. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
  13902. break;
  13903. }
  13904. case 1: { // GRAY SCALE
  13905. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
  13906. break;
  13907. }
  13908. }
  13909. }
  13910. if ($this->gradients[$n]['transparency']) {
  13911. // paint luminosity gradient
  13912. $this->_out('/TGS'.$n.' gs');
  13913. }
  13914. //paint the gradient
  13915. $this->_out('/Sh'.$n.' sh');
  13916. //restore previous Graphic State
  13917. $this->_out('Q');
  13918. if ($this->inxobj) {
  13919. // we are inside an XObject template
  13920. $this->xobjects[$this->xobjid]['gradients'][$n] = $this->gradients[$n];
  13921. }
  13922. }
  13923. /**
  13924. * Output gradient shaders.
  13925. * @author Nicola Asuni
  13926. * @since 3.1.000 (2008-06-09)
  13927. * @protected
  13928. */
  13929. function _putshaders() {
  13930. if ($this->pdfa_mode) {
  13931. return;
  13932. }
  13933. $idt = count($this->gradients); //index for transparency gradients
  13934. foreach ($this->gradients as $id => $grad) {
  13935. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  13936. $fc = $this->_newobj();
  13937. $out = '<<';
  13938. $out .= ' /FunctionType 3';
  13939. $out .= ' /Domain [0 1]';
  13940. $functions = '';
  13941. $bounds = '';
  13942. $encode = '';
  13943. $i = 1;
  13944. $num_cols = count($grad['colors']);
  13945. $lastcols = $num_cols - 1;
  13946. for ($i = 1; $i < $num_cols; ++$i) {
  13947. $functions .= ($fc + $i).' 0 R ';
  13948. if ($i < $lastcols) {
  13949. $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
  13950. }
  13951. $encode .= '0 1 ';
  13952. }
  13953. $out .= ' /Functions ['.trim($functions).']';
  13954. $out .= ' /Bounds ['.trim($bounds).']';
  13955. $out .= ' /Encode ['.trim($encode).']';
  13956. $out .= ' >>';
  13957. $out .= "\n".'endobj';
  13958. $this->_out($out);
  13959. for ($i = 1; $i < $num_cols; ++$i) {
  13960. $this->_newobj();
  13961. $out = '<<';
  13962. $out .= ' /FunctionType 2';
  13963. $out .= ' /Domain [0 1]';
  13964. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
  13965. $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
  13966. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  13967. $out .= ' >>';
  13968. $out .= "\n".'endobj';
  13969. $this->_out($out);
  13970. }
  13971. // set transparency fuctions
  13972. if ($grad['transparency']) {
  13973. $ft = $this->_newobj();
  13974. $out = '<<';
  13975. $out .= ' /FunctionType 3';
  13976. $out .= ' /Domain [0 1]';
  13977. $functions = '';
  13978. $i = 1;
  13979. $num_cols = count($grad['colors']);
  13980. for ($i = 1; $i < $num_cols; ++$i) {
  13981. $functions .= ($ft + $i).' 0 R ';
  13982. }
  13983. $out .= ' /Functions ['.trim($functions).']';
  13984. $out .= ' /Bounds ['.trim($bounds).']';
  13985. $out .= ' /Encode ['.trim($encode).']';
  13986. $out .= ' >>';
  13987. $out .= "\n".'endobj';
  13988. $this->_out($out);
  13989. for ($i = 1; $i < $num_cols; ++$i) {
  13990. $this->_newobj();
  13991. $out = '<<';
  13992. $out .= ' /FunctionType 2';
  13993. $out .= ' /Domain [0 1]';
  13994. $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
  13995. $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
  13996. $out .= ' /N '.$grad['colors'][$i]['exponent'];
  13997. $out .= ' >>';
  13998. $out .= "\n".'endobj';
  13999. $this->_out($out);
  14000. }
  14001. }
  14002. }
  14003. // set shading object
  14004. $this->_newobj();
  14005. $out = '<< /ShadingType '.$grad['type'];
  14006. if (isset($grad['colspace'])) {
  14007. $out .= ' /ColorSpace /'.$grad['colspace'];
  14008. } else {
  14009. $out .= ' /ColorSpace /DeviceRGB';
  14010. }
  14011. if (isset($grad['background']) AND !empty($grad['background'])) {
  14012. $out .= ' /Background ['.$grad['background'].']';
  14013. }
  14014. if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
  14015. $out .= ' /AntiAlias true';
  14016. }
  14017. if ($grad['type'] == 2) {
  14018. $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  14019. $out .= ' /Domain [0 1]';
  14020. $out .= ' /Function '.$fc.' 0 R';
  14021. $out .= ' /Extend [true true]';
  14022. $out .= ' >>';
  14023. } elseif ($grad['type'] == 3) {
  14024. //x0, y0, r0, x1, y1, r1
  14025. //at this this time radius of inner circle is 0
  14026. $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  14027. $out .= ' /Domain [0 1]';
  14028. $out .= ' /Function '.$fc.' 0 R';
  14029. $out .= ' /Extend [true true]';
  14030. $out .= ' >>';
  14031. } elseif ($grad['type'] == 6) {
  14032. $out .= ' /BitsPerCoordinate 16';
  14033. $out .= ' /BitsPerComponent 8';
  14034. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  14035. $out .= ' /BitsPerFlag 8';
  14036. $stream = $this->_getrawstream($grad['stream']);
  14037. $out .= ' /Length '.strlen($stream);
  14038. $out .= ' >>';
  14039. $out .= ' stream'."\n".$stream."\n".'endstream';
  14040. }
  14041. $out .= "\n".'endobj';
  14042. $this->_out($out);
  14043. if ($grad['transparency']) {
  14044. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  14045. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
  14046. }
  14047. $this->gradients[$id]['id'] = $this->n;
  14048. // set pattern object
  14049. $this->_newobj();
  14050. $out = '<< /Type /Pattern /PatternType 2';
  14051. $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R';
  14052. $out .= ' >>';
  14053. $out .= "\n".'endobj';
  14054. $this->_out($out);
  14055. $this->gradients[$id]['pattern'] = $this->n;
  14056. // set shading and pattern for transparency mask
  14057. if ($grad['transparency']) {
  14058. // luminosity pattern
  14059. $idgs = $id + $idt;
  14060. $this->_newobj();
  14061. $this->_out($shading_transparency);
  14062. $this->gradients[$idgs]['id'] = $this->n;
  14063. $this->_newobj();
  14064. $out = '<< /Type /Pattern /PatternType 2';
  14065. $out .= ' /Shading '.$this->gradients[$idgs]['id'].' 0 R';
  14066. $out .= ' >>';
  14067. $out .= "\n".'endobj';
  14068. $this->_out($out);
  14069. $this->gradients[$idgs]['pattern'] = $this->n;
  14070. // luminosity XObject
  14071. $oid = $this->_newobj();
  14072. $this->xobjects['LX'.$oid] = array('n' => $oid);
  14073. $filter = '';
  14074. $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt.' '.$this->hPt.' re f Q';
  14075. if ($this->compress) {
  14076. $filter = ' /Filter /FlateDecode';
  14077. $stream = gzcompress($stream);
  14078. }
  14079. $stream = $this->_getrawstream($stream);
  14080. $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
  14081. $out .= ' /Length '.strlen($stream);
  14082. $rect = sprintf('%F %F', $this->wPt, $this->hPt);
  14083. $out .= ' /BBox [0 0 '.$rect.']';
  14084. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  14085. $out .= ' /Resources <<';
  14086. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  14087. $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients[$idgs]['pattern'].' 0 R >>';
  14088. $out .= ' >>';
  14089. $out .= ' >> ';
  14090. $out .= ' stream'."\n".$stream."\n".'endstream';
  14091. $out .= "\n".'endobj';
  14092. $this->_out($out);
  14093. // SMask
  14094. $this->_newobj();
  14095. $out = '<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj';
  14096. $this->_out($out);
  14097. // ExtGState
  14098. $this->_newobj();
  14099. $out = '<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj';
  14100. $this->_out($out);
  14101. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS'.$id);
  14102. }
  14103. }
  14104. }
  14105. /**
  14106. * Draw the sector of a circle.
  14107. * It can be used for instance to render pie charts.
  14108. * @param $xc (float) abscissa of the center.
  14109. * @param $yc (float) ordinate of the center.
  14110. * @param $r (float) radius.
  14111. * @param $a (float) start angle (in degrees).
  14112. * @param $b (float) end angle (in degrees).
  14113. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14114. * @param $cw: (float) indicates whether to go clockwise (default: true).
  14115. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  14116. * @author Maxime Delorme, Nicola Asuni
  14117. * @since 3.1.000 (2008-06-09)
  14118. * @public
  14119. */
  14120. public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
  14121. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  14122. }
  14123. /**
  14124. * Draw the sector of an ellipse.
  14125. * It can be used for instance to render pie charts.
  14126. * @param $xc (float) abscissa of the center.
  14127. * @param $yc (float) ordinate of the center.
  14128. * @param $rx (float) the x-axis radius.
  14129. * @param $ry (float) the y-axis radius.
  14130. * @param $a (float) start angle (in degrees).
  14131. * @param $b (float) end angle (in degrees).
  14132. * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
  14133. * @param $cw: (float) indicates whether to go clockwise.
  14134. * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  14135. * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
  14136. * @author Maxime Delorme, Nicola Asuni
  14137. * @since 3.1.000 (2008-06-09)
  14138. * @public
  14139. */
  14140. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
  14141. if ($this->state != 2) {
  14142. return;
  14143. }
  14144. if ($this->rtl) {
  14145. $xc = ($this->w - $xc);
  14146. }
  14147. $op = TCPDF_STATIC::getPathPaintOperator($style);
  14148. if ($op == 'f') {
  14149. $line_style = array();
  14150. }
  14151. if ($cw) {
  14152. $d = $b;
  14153. $b = (360 - $a + $o);
  14154. $a = (360 - $d + $o);
  14155. } else {
  14156. $b += $o;
  14157. $a += $o;
  14158. }
  14159. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  14160. $this->_out($op);
  14161. }
  14162. /**
  14163. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  14164. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  14165. * Only vector drawing is supported, not text or bitmap.
  14166. * 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).
  14167. * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
  14168. * @param $x (float) Abscissa of the upper-left corner.
  14169. * @param $y (float) Ordinate of the upper-left corner.
  14170. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14171. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  14172. * @param $link (mixed) URL or identifier returned by AddLink().
  14173. * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  14174. * @param $align (string) 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>
  14175. * @param $palign (string) 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>
  14176. * @param $border (mixed) 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)))
  14177. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  14178. * @param $fixoutvals (boolean) if true remove values outside the bounding box.
  14179. * @author Valentin Schmidt, Nicola Asuni
  14180. * @since 3.1.000 (2008-06-09)
  14181. * @public
  14182. */
  14183. public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
  14184. if ($this->state != 2) {
  14185. return;
  14186. }
  14187. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  14188. // convert EPS to raster image using GD or ImageMagick libraries
  14189. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14190. }
  14191. if ($x === '') {
  14192. $x = $this->x;
  14193. }
  14194. if ($y === '') {
  14195. $y = $this->y;
  14196. }
  14197. // check page for no-write regions and adapt page margins if necessary
  14198. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14199. $k = $this->k;
  14200. if ($file{0} === '@') { // image from string
  14201. $data = substr($file, 1);
  14202. } else { // EPS/AI file
  14203. $data = TCPDF_STATIC::fileGetContents($file);
  14204. }
  14205. if ($data === FALSE) {
  14206. $this->Error('EPS file not found: '.$file);
  14207. }
  14208. $regs = array();
  14209. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  14210. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  14211. if (count($regs) > 1) {
  14212. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  14213. if (strpos($version_str, 'Adobe Illustrator') !== false) {
  14214. $versexp = explode(' ', $version_str);
  14215. $version = (float)array_pop($versexp);
  14216. if ($version >= 9) {
  14217. $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
  14218. }
  14219. }
  14220. }
  14221. // strip binary bytes in front of PS-header
  14222. $start = strpos($data, '%!PS-Adobe');
  14223. if ($start > 0) {
  14224. $data = substr($data, $start);
  14225. }
  14226. // find BoundingBox params
  14227. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  14228. if (count($regs) > 1) {
  14229. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  14230. } else {
  14231. $this->Error('No BoundingBox found in EPS/AI file: '.$file);
  14232. }
  14233. $start = strpos($data, '%%EndSetup');
  14234. if ($start === false) {
  14235. $start = strpos($data, '%%EndProlog');
  14236. }
  14237. if ($start === false) {
  14238. $start = strpos($data, '%%BoundingBox');
  14239. }
  14240. $data = substr($data, $start);
  14241. $end = strpos($data, '%%PageTrailer');
  14242. if ($end===false) {
  14243. $end = strpos($data, 'showpage');
  14244. }
  14245. if ($end) {
  14246. $data = substr($data, 0, $end);
  14247. }
  14248. // calculate image width and height on document
  14249. if (($w <= 0) AND ($h <= 0)) {
  14250. $w = ($x2 - $x1) / $k;
  14251. $h = ($y2 - $y1) / $k;
  14252. } elseif ($w <= 0) {
  14253. $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
  14254. } elseif ($h <= 0) {
  14255. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  14256. }
  14257. // fit the image on available space
  14258. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  14259. if ($this->rasterize_vector_images) {
  14260. // convert EPS to raster image using GD or ImageMagick libraries
  14261. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  14262. }
  14263. // set scaling factors
  14264. $scale_x = $w / (($x2 - $x1) / $k);
  14265. $scale_y = $h / (($y2 - $y1) / $k);
  14266. // set alignment
  14267. $this->img_rb_y = $y + $h;
  14268. // set alignment
  14269. if ($this->rtl) {
  14270. if ($palign == 'L') {
  14271. $ximg = $this->lMargin;
  14272. } elseif ($palign == 'C') {
  14273. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14274. } elseif ($palign == 'R') {
  14275. $ximg = $this->w - $this->rMargin - $w;
  14276. } else {
  14277. $ximg = $x - $w;
  14278. }
  14279. $this->img_rb_x = $ximg;
  14280. } else {
  14281. if ($palign == 'L') {
  14282. $ximg = $this->lMargin;
  14283. } elseif ($palign == 'C') {
  14284. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14285. } elseif ($palign == 'R') {
  14286. $ximg = $this->w - $this->rMargin - $w;
  14287. } else {
  14288. $ximg = $x;
  14289. }
  14290. $this->img_rb_x = $ximg + $w;
  14291. }
  14292. if ($useBoundingBox) {
  14293. $dx = $ximg * $k - $x1;
  14294. $dy = $y * $k - $y1;
  14295. } else {
  14296. $dx = $ximg * $k;
  14297. $dy = $y * $k;
  14298. }
  14299. // save the current graphic state
  14300. $this->_out('q'.$this->epsmarker);
  14301. // translate
  14302. $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  14303. // scale
  14304. if (isset($scale_x)) {
  14305. $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  14306. }
  14307. // handle pc/unix/mac line endings
  14308. $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
  14309. $u=0;
  14310. $cnt = count($lines);
  14311. for ($i=0; $i < $cnt; ++$i) {
  14312. $line = $lines[$i];
  14313. if (($line == '') OR ($line{0} == '%')) {
  14314. continue;
  14315. }
  14316. $len = strlen($line);
  14317. // check for spot color names
  14318. $color_name = '';
  14319. if (strcasecmp('x', substr(trim($line), -1)) == 0) {
  14320. if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
  14321. // extract spot color name
  14322. $color_name = $matches[0];
  14323. // remove color name from string
  14324. $line = str_replace(' '.$color_name, '', $line);
  14325. // remove pharentesis from color name
  14326. $color_name = substr($color_name, 1, -1);
  14327. }
  14328. }
  14329. $chunks = explode(' ', $line);
  14330. $cmd = trim(array_pop($chunks));
  14331. // RGB
  14332. if (($cmd == 'Xa') OR ($cmd == 'XA')) {
  14333. $b = array_pop($chunks);
  14334. $g = array_pop($chunks);
  14335. $r = array_pop($chunks);
  14336. $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!
  14337. continue;
  14338. }
  14339. $skip = false;
  14340. if ($fixoutvals) {
  14341. // check for values outside the bounding box
  14342. switch ($cmd) {
  14343. case 'm':
  14344. case 'l':
  14345. case 'L': {
  14346. // skip values outside bounding box
  14347. foreach ($chunks as $key => $val) {
  14348. if ((($key % 2) == 0) AND (($val < $x1) OR ($val > $x2))) {
  14349. $skip = true;
  14350. } elseif ((($key % 2) != 0) AND (($val < $y1) OR ($val > $y2))) {
  14351. $skip = true;
  14352. }
  14353. }
  14354. }
  14355. }
  14356. }
  14357. switch ($cmd) {
  14358. case 'm':
  14359. case 'l':
  14360. case 'v':
  14361. case 'y':
  14362. case 'c':
  14363. case 'k':
  14364. case 'K':
  14365. case 'g':
  14366. case 'G':
  14367. case 's':
  14368. case 'S':
  14369. case 'J':
  14370. case 'j':
  14371. case 'w':
  14372. case 'M':
  14373. case 'd':
  14374. case 'n': {
  14375. if ($skip) {
  14376. break;
  14377. }
  14378. $this->_out($line);
  14379. break;
  14380. }
  14381. case 'x': {// custom fill color
  14382. if (empty($color_name)) {
  14383. // CMYK color
  14384. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14385. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
  14386. } else {
  14387. // Spot Color (CMYK + tint)
  14388. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14389. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14390. $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14391. $this->_out($color_cmd);
  14392. }
  14393. break;
  14394. }
  14395. case 'X': { // custom stroke color
  14396. if (empty($color_name)) {
  14397. // CMYK color
  14398. list($col_c, $col_m, $col_y, $col_k) = $chunks;
  14399. $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
  14400. } else {
  14401. // Spot Color (CMYK + tint)
  14402. list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
  14403. $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
  14404. $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors[$color_name]['i'], (1 - $col_t));
  14405. $this->_out($color_cmd);
  14406. }
  14407. break;
  14408. }
  14409. case 'Y':
  14410. case 'N':
  14411. case 'V':
  14412. case 'L':
  14413. case 'C': {
  14414. if ($skip) {
  14415. break;
  14416. }
  14417. $line[($len - 1)] = strtolower($cmd);
  14418. $this->_out($line);
  14419. break;
  14420. }
  14421. case 'b':
  14422. case 'B': {
  14423. $this->_out($cmd . '*');
  14424. break;
  14425. }
  14426. case 'f':
  14427. case 'F': {
  14428. if ($u > 0) {
  14429. $isU = false;
  14430. $max = min(($i + 5), $cnt);
  14431. for ($j = ($i + 1); $j < $max; ++$j) {
  14432. $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
  14433. }
  14434. if ($isU) {
  14435. $this->_out('f*');
  14436. }
  14437. } else {
  14438. $this->_out('f*');
  14439. }
  14440. break;
  14441. }
  14442. case '*u': {
  14443. ++$u;
  14444. break;
  14445. }
  14446. case '*U': {
  14447. --$u;
  14448. break;
  14449. }
  14450. }
  14451. }
  14452. // restore previous graphic state
  14453. $this->_out($this->epsmarker.'Q');
  14454. if (!empty($border)) {
  14455. $bx = $this->x;
  14456. $by = $this->y;
  14457. $this->x = $ximg;
  14458. if ($this->rtl) {
  14459. $this->x += $w;
  14460. }
  14461. $this->y = $y;
  14462. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  14463. $this->x = $bx;
  14464. $this->y = $by;
  14465. }
  14466. if ($link) {
  14467. $this->Link($ximg, $y, $w, $h, $link, 0);
  14468. }
  14469. // set pointer to align the next text/objects
  14470. switch($align) {
  14471. case 'T':{
  14472. $this->y = $y;
  14473. $this->x = $this->img_rb_x;
  14474. break;
  14475. }
  14476. case 'M':{
  14477. $this->y = $y + round($h/2);
  14478. $this->x = $this->img_rb_x;
  14479. break;
  14480. }
  14481. case 'B':{
  14482. $this->y = $this->img_rb_y;
  14483. $this->x = $this->img_rb_x;
  14484. break;
  14485. }
  14486. case 'N':{
  14487. $this->SetY($this->img_rb_y);
  14488. break;
  14489. }
  14490. default:{
  14491. break;
  14492. }
  14493. }
  14494. $this->endlinex = $this->img_rb_x;
  14495. }
  14496. /**
  14497. * Set document barcode.
  14498. * @param $bc (string) barcode
  14499. * @public
  14500. */
  14501. public function setBarcode($bc='') {
  14502. $this->barcode = $bc;
  14503. }
  14504. /**
  14505. * Get current barcode.
  14506. * @return string
  14507. * @public
  14508. * @since 4.0.012 (2008-07-24)
  14509. */
  14510. public function getBarcode() {
  14511. return $this->barcode;
  14512. }
  14513. /**
  14514. * Print a Linear Barcode.
  14515. * @param $code (string) code to print
  14516. * @param $type (string) type of barcode (see tcpdf_barcodes_1d.php for supported formats).
  14517. * @param $x (int) x position in user units (empty string = current x position)
  14518. * @param $y (int) y position in user units (empty string = current y position)
  14519. * @param $w (int) width in user units (empty string = remaining page width)
  14520. * @param $h (int) height in user units (empty string = remaining page height)
  14521. * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
  14522. * @param $style (array) array of options:<ul>
  14523. * <li>boolean $style['border'] if true prints a border</li>
  14524. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  14525. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  14526. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  14527. * <li>array $style['fgcolor'] color array for bars and text</li>
  14528. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  14529. * <li>boolean $style['text'] if true prints text below the barcode</li>
  14530. * <li>string $style['label'] override default label</li>
  14531. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  14532. * <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>
  14533. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  14534. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  14535. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  14536. * <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>
  14537. * <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>
  14538. * @param $align (string) 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>
  14539. * @author Nicola Asuni
  14540. * @since 3.1.000 (2008-06-09)
  14541. * @public
  14542. */
  14543. public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') {
  14544. if (TCPDF_STATIC::empty_string(trim($code))) {
  14545. return;
  14546. }
  14547. require_once(dirname(__FILE__).'/tcpdf_barcodes_1d.php');
  14548. // save current graphic settings
  14549. $gvars = $this->getGraphicVars();
  14550. // create new barcode object
  14551. $barcodeobj = new TCPDFBarcode($code, $type);
  14552. $arrcode = $barcodeobj->getBarcodeArray();
  14553. if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
  14554. $this->Error('Error in 1D barcode string');
  14555. }
  14556. if ($arrcode['maxh'] <= 0) {
  14557. $arrcode['maxh'] = 1;
  14558. }
  14559. // set default values
  14560. if (!isset($style['position'])) {
  14561. $style['position'] = '';
  14562. } elseif ($style['position'] == 'S') {
  14563. // keep this for backward compatibility
  14564. $style['position'] = '';
  14565. $style['stretch'] = true;
  14566. }
  14567. if (!isset($style['fitwidth'])) {
  14568. if (!isset($style['stretch'])) {
  14569. $style['fitwidth'] = true;
  14570. } else {
  14571. $style['fitwidth'] = false;
  14572. }
  14573. }
  14574. if ($style['fitwidth']) {
  14575. // disable stretch
  14576. $style['stretch'] = false;
  14577. }
  14578. if (!isset($style['stretch'])) {
  14579. if (($w === '') OR ($w <= 0)) {
  14580. $style['stretch'] = false;
  14581. } else {
  14582. $style['stretch'] = true;
  14583. }
  14584. }
  14585. if (!isset($style['fgcolor'])) {
  14586. $style['fgcolor'] = array(0,0,0); // default black
  14587. }
  14588. if (!isset($style['bgcolor'])) {
  14589. $style['bgcolor'] = false; // default transparent
  14590. }
  14591. if (!isset($style['border'])) {
  14592. $style['border'] = false;
  14593. }
  14594. $fontsize = 0;
  14595. if (!isset($style['text'])) {
  14596. $style['text'] = false;
  14597. }
  14598. if ($style['text'] AND isset($style['font'])) {
  14599. if (isset($style['fontsize'])) {
  14600. $fontsize = $style['fontsize'];
  14601. }
  14602. $this->SetFont($style['font'], '', $fontsize);
  14603. }
  14604. if (!isset($style['stretchtext'])) {
  14605. $style['stretchtext'] = 4;
  14606. }
  14607. if ($x === '') {
  14608. $x = $this->x;
  14609. }
  14610. if ($y === '') {
  14611. $y = $this->y;
  14612. }
  14613. // check page for no-write regions and adapt page margins if necessary
  14614. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14615. if (($w === '') OR ($w <= 0)) {
  14616. if ($this->rtl) {
  14617. $w = $x - $this->lMargin;
  14618. } else {
  14619. $w = $this->w - $this->rMargin - $x;
  14620. }
  14621. }
  14622. // padding
  14623. if (!isset($style['padding'])) {
  14624. $padding = 0;
  14625. } elseif ($style['padding'] === 'auto') {
  14626. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  14627. } else {
  14628. $padding = floatval($style['padding']);
  14629. }
  14630. // horizontal padding
  14631. if (!isset($style['hpadding'])) {
  14632. $hpadding = $padding;
  14633. } elseif ($style['hpadding'] === 'auto') {
  14634. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  14635. } else {
  14636. $hpadding = floatval($style['hpadding']);
  14637. }
  14638. // vertical padding
  14639. if (!isset($style['vpadding'])) {
  14640. $vpadding = $padding;
  14641. } elseif ($style['vpadding'] === 'auto') {
  14642. $vpadding = ($hpadding / 2);
  14643. } else {
  14644. $vpadding = floatval($style['vpadding']);
  14645. }
  14646. // calculate xres (single bar width)
  14647. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  14648. if ($style['stretch']) {
  14649. $xres = $max_xres;
  14650. } else {
  14651. if (TCPDF_STATIC::empty_string($xres)) {
  14652. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  14653. }
  14654. if ($xres > $max_xres) {
  14655. // correct xres to fit on $w
  14656. $xres = $max_xres;
  14657. }
  14658. if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
  14659. OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
  14660. $hpadding = 10 * $xres;
  14661. if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
  14662. $vpadding = ($hpadding / 2);
  14663. }
  14664. }
  14665. }
  14666. if ($style['fitwidth']) {
  14667. $wold = $w;
  14668. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  14669. if (isset($style['cellfitalign'])) {
  14670. switch ($style['cellfitalign']) {
  14671. case 'L': {
  14672. if ($this->rtl) {
  14673. $x -= ($wold - $w);
  14674. }
  14675. break;
  14676. }
  14677. case 'R': {
  14678. if (!$this->rtl) {
  14679. $x += ($wold - $w);
  14680. }
  14681. break;
  14682. }
  14683. case 'C': {
  14684. if ($this->rtl) {
  14685. $x -= (($wold - $w) / 2);
  14686. } else {
  14687. $x += (($wold - $w) / 2);
  14688. }
  14689. break;
  14690. }
  14691. default : {
  14692. break;
  14693. }
  14694. }
  14695. }
  14696. }
  14697. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  14698. // height
  14699. if (($h === '') OR ($h <= 0)) {
  14700. // set default height
  14701. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  14702. }
  14703. $barh = $h - $text_height - (2 * $vpadding);
  14704. if ($barh <=0) {
  14705. // try to reduce font or padding to fit barcode on available height
  14706. if ($text_height > $h) {
  14707. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  14708. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  14709. $this->SetFont($style['font'], '', $fontsize);
  14710. }
  14711. if ($vpadding > 0) {
  14712. $vpadding = (($h - $text_height) / 4);
  14713. }
  14714. $barh = $h - $text_height - (2 * $vpadding);
  14715. }
  14716. // fit the barcode on available space
  14717. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  14718. // set alignment
  14719. $this->img_rb_y = $y + $h;
  14720. // set alignment
  14721. if ($this->rtl) {
  14722. if ($style['position'] == 'L') {
  14723. $xpos = $this->lMargin;
  14724. } elseif ($style['position'] == 'C') {
  14725. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14726. } elseif ($style['position'] == 'R') {
  14727. $xpos = $this->w - $this->rMargin - $w;
  14728. } else {
  14729. $xpos = $x - $w;
  14730. }
  14731. $this->img_rb_x = $xpos;
  14732. } else {
  14733. if ($style['position'] == 'L') {
  14734. $xpos = $this->lMargin;
  14735. } elseif ($style['position'] == 'C') {
  14736. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14737. } elseif ($style['position'] == 'R') {
  14738. $xpos = $this->w - $this->rMargin - $w;
  14739. } else {
  14740. $xpos = $x;
  14741. }
  14742. $this->img_rb_x = $xpos + $w;
  14743. }
  14744. $xpos_rect = $xpos;
  14745. if (!isset($style['align'])) {
  14746. $style['align'] = 'C';
  14747. }
  14748. switch ($style['align']) {
  14749. case 'L': {
  14750. $xpos = $xpos_rect + $hpadding;
  14751. break;
  14752. }
  14753. case 'R': {
  14754. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  14755. break;
  14756. }
  14757. case 'C':
  14758. default : {
  14759. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  14760. break;
  14761. }
  14762. }
  14763. $xpos_text = $xpos;
  14764. // barcode is always printed in LTR direction
  14765. $tempRTL = $this->rtl;
  14766. $this->rtl = false;
  14767. // print background color
  14768. if ($style['bgcolor']) {
  14769. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  14770. } elseif ($style['border']) {
  14771. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  14772. }
  14773. // set foreground color
  14774. $this->SetDrawColorArray($style['fgcolor']);
  14775. $this->SetTextColorArray($style['fgcolor']);
  14776. // print bars
  14777. foreach ($arrcode['bcode'] as $k => $v) {
  14778. $bw = ($v['w'] * $xres);
  14779. if ($v['t']) {
  14780. // draw a vertical bar
  14781. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  14782. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  14783. }
  14784. $xpos += $bw;
  14785. }
  14786. // print text
  14787. if ($style['text']) {
  14788. if (isset($style['label']) AND !TCPDF_STATIC::empty_string($style['label'])) {
  14789. $label = $style['label'];
  14790. } else {
  14791. $label = $code;
  14792. }
  14793. $txtwidth = ($arrcode['maxw'] * $xres);
  14794. if ($this->GetStringWidth($label) > $txtwidth) {
  14795. $style['stretchtext'] = 2;
  14796. }
  14797. // print text
  14798. $this->x = $xpos_text;
  14799. $this->y = $y + $vpadding + $barh;
  14800. $cellpadding = $this->cell_padding;
  14801. $this->SetCellPadding(0);
  14802. $this->Cell($txtwidth, '', $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
  14803. $this->cell_padding = $cellpadding;
  14804. }
  14805. // restore original direction
  14806. $this->rtl = $tempRTL;
  14807. // restore previous settings
  14808. $this->setGraphicVars($gvars);
  14809. // set pointer to align the next text/objects
  14810. switch($align) {
  14811. case 'T':{
  14812. $this->y = $y;
  14813. $this->x = $this->img_rb_x;
  14814. break;
  14815. }
  14816. case 'M':{
  14817. $this->y = $y + round($h / 2);
  14818. $this->x = $this->img_rb_x;
  14819. break;
  14820. }
  14821. case 'B':{
  14822. $this->y = $this->img_rb_y;
  14823. $this->x = $this->img_rb_x;
  14824. break;
  14825. }
  14826. case 'N':{
  14827. $this->SetY($this->img_rb_y);
  14828. break;
  14829. }
  14830. default:{
  14831. break;
  14832. }
  14833. }
  14834. $this->endlinex = $this->img_rb_x;
  14835. }
  14836. /**
  14837. * Print 2D Barcode.
  14838. * @param $code (string) code to print
  14839. * @param $type (string) type of barcode (see tcpdf_barcodes_2d.php for supported formats).
  14840. * @param $x (int) x position in user units
  14841. * @param $y (int) y position in user units
  14842. * @param $w (int) width in user units
  14843. * @param $h (int) height in user units
  14844. * @param $style (array) array of options:<ul>
  14845. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  14846. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  14847. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  14848. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  14849. * <li>int $style['module_width'] width of a single module in points</li>
  14850. * <li>int $style['module_height'] height of a single module in points</li>
  14851. * <li>array $style['fgcolor'] color array for bars and text</li>
  14852. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  14853. * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li><li>$style['module_width'] width of a single module in points</li>
  14854. * <li>$style['module_height'] height of a single module in points</li></ul>
  14855. * @param $align (string) 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>
  14856. * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  14857. * @author Nicola Asuni
  14858. * @since 4.5.037 (2009-04-07)
  14859. * @public
  14860. */
  14861. public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) {
  14862. if (TCPDF_STATIC::empty_string(trim($code))) {
  14863. return;
  14864. }
  14865. require_once(dirname(__FILE__).'/tcpdf_barcodes_2d.php');
  14866. // save current graphic settings
  14867. $gvars = $this->getGraphicVars();
  14868. // create new barcode object
  14869. $barcodeobj = new TCPDF2DBarcode($code, $type);
  14870. $arrcode = $barcodeobj->getBarcodeArray();
  14871. if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
  14872. $this->Error('Error in 2D barcode string');
  14873. }
  14874. // set default values
  14875. if (!isset($style['position'])) {
  14876. $style['position'] = '';
  14877. }
  14878. if (!isset($style['fgcolor'])) {
  14879. $style['fgcolor'] = array(0,0,0); // default black
  14880. }
  14881. if (!isset($style['bgcolor'])) {
  14882. $style['bgcolor'] = false; // default transparent
  14883. }
  14884. if (!isset($style['border'])) {
  14885. $style['border'] = false;
  14886. }
  14887. // padding
  14888. if (!isset($style['padding'])) {
  14889. $style['padding'] = 0;
  14890. } elseif ($style['padding'] === 'auto') {
  14891. $style['padding'] = 4;
  14892. }
  14893. if (!isset($style['hpadding'])) {
  14894. $style['hpadding'] = $style['padding'];
  14895. } elseif ($style['hpadding'] === 'auto') {
  14896. $style['hpadding'] = 4;
  14897. }
  14898. if (!isset($style['vpadding'])) {
  14899. $style['vpadding'] = $style['padding'];
  14900. } elseif ($style['vpadding'] === 'auto') {
  14901. $style['vpadding'] = 4;
  14902. }
  14903. $hpad = (2 * $style['hpadding']);
  14904. $vpad = (2 * $style['vpadding']);
  14905. // cell (module) dimension
  14906. if (!isset($style['module_width'])) {
  14907. $style['module_width'] = 1; // width of a single module in points
  14908. }
  14909. if (!isset($style['module_height'])) {
  14910. $style['module_height'] = 1; // height of a single module in points
  14911. }
  14912. if ($x === '') {
  14913. $x = $this->x;
  14914. }
  14915. if ($y === '') {
  14916. $y = $this->y;
  14917. }
  14918. // check page for no-write regions and adapt page margins if necessary
  14919. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  14920. // number of barcode columns and rows
  14921. $rows = $arrcode['num_rows'];
  14922. $cols = $arrcode['num_cols'];
  14923. if (($rows <= 0) || ($cols <= 0)){
  14924. $this->Error('Error in 2D barcode string');
  14925. }
  14926. // module width and height
  14927. $mw = $style['module_width'];
  14928. $mh = $style['module_height'];
  14929. if (($mw <= 0) OR ($mh <= 0)) {
  14930. $this->Error('Error in 2D barcode string');
  14931. }
  14932. // get max dimensions
  14933. if ($this->rtl) {
  14934. $maxw = $x - $this->lMargin;
  14935. } else {
  14936. $maxw = $this->w - $this->rMargin - $x;
  14937. }
  14938. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  14939. $ratioHW = ((($rows * $mh) + $hpad) / (($cols * $mw) + $vpad));
  14940. $ratioWH = ((($cols * $mw) + $vpad) / (($rows * $mh) + $hpad));
  14941. if (!$distort) {
  14942. if (($maxw * $ratioHW) > $maxh) {
  14943. $maxw = $maxh * $ratioWH;
  14944. }
  14945. if (($maxh * $ratioWH) > $maxw) {
  14946. $maxh = $maxw * $ratioHW;
  14947. }
  14948. }
  14949. // set maximum dimesions
  14950. if ($w > $maxw) {
  14951. $w = $maxw;
  14952. }
  14953. if ($h > $maxh) {
  14954. $h = $maxh;
  14955. }
  14956. // set dimensions
  14957. if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
  14958. $w = ($cols + $hpad) * ($mw / $this->k);
  14959. $h = ($rows + $vpad) * ($mh / $this->k);
  14960. } elseif (($w === '') OR ($w <= 0)) {
  14961. $w = $h * $ratioWH;
  14962. } elseif (($h === '') OR ($h <= 0)) {
  14963. $h = $w * $ratioHW;
  14964. }
  14965. // barcode size (excluding padding)
  14966. $bw = ($w * $cols) / ($cols + $hpad);
  14967. $bh = ($h * $rows) / ($rows + $vpad);
  14968. // dimension of single barcode cell unit
  14969. $cw = $bw / $cols;
  14970. $ch = $bh / $rows;
  14971. if (!$distort) {
  14972. if (($cw / $ch) > ($mw / $mh)) {
  14973. // correct horizontal distortion
  14974. $cw = $ch * $mw / $mh;
  14975. $bw = $cw * $cols;
  14976. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  14977. } else {
  14978. // correct vertical distortion
  14979. $ch = $cw * $mh / $mw;
  14980. $bh = $ch * $rows;
  14981. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  14982. }
  14983. }
  14984. // fit the barcode on available space
  14985. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
  14986. // set alignment
  14987. $this->img_rb_y = $y + $h;
  14988. // set alignment
  14989. if ($this->rtl) {
  14990. if ($style['position'] == 'L') {
  14991. $xpos = $this->lMargin;
  14992. } elseif ($style['position'] == 'C') {
  14993. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  14994. } elseif ($style['position'] == 'R') {
  14995. $xpos = $this->w - $this->rMargin - $w;
  14996. } else {
  14997. $xpos = $x - $w;
  14998. }
  14999. $this->img_rb_x = $xpos;
  15000. } else {
  15001. if ($style['position'] == 'L') {
  15002. $xpos = $this->lMargin;
  15003. } elseif ($style['position'] == 'C') {
  15004. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  15005. } elseif ($style['position'] == 'R') {
  15006. $xpos = $this->w - $this->rMargin - $w;
  15007. } else {
  15008. $xpos = $x;
  15009. }
  15010. $this->img_rb_x = $xpos + $w;
  15011. }
  15012. $xstart = $xpos + ($style['hpadding'] * $cw);
  15013. $ystart = $y + ($style['vpadding'] * $ch);
  15014. // barcode is always printed in LTR direction
  15015. $tempRTL = $this->rtl;
  15016. $this->rtl = false;
  15017. // print background color
  15018. if ($style['bgcolor']) {
  15019. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  15020. } elseif ($style['border']) {
  15021. $this->Rect($xpos, $y, $w, $h, 'D');
  15022. }
  15023. // set foreground color
  15024. $this->SetDrawColorArray($style['fgcolor']);
  15025. // print barcode cells
  15026. // for each row
  15027. for ($r = 0; $r < $rows; ++$r) {
  15028. $xr = $xstart;
  15029. // for each column
  15030. for ($c = 0; $c < $cols; ++$c) {
  15031. if ($arrcode['bcode'][$r][$c] == 1) {
  15032. // draw a single barcode cell
  15033. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  15034. }
  15035. $xr += $cw;
  15036. }
  15037. $ystart += $ch;
  15038. }
  15039. // restore original direction
  15040. $this->rtl = $tempRTL;
  15041. // restore previous settings
  15042. $this->setGraphicVars($gvars);
  15043. // set pointer to align the next text/objects
  15044. switch($align) {
  15045. case 'T':{
  15046. $this->y = $y;
  15047. $this->x = $this->img_rb_x;
  15048. break;
  15049. }
  15050. case 'M':{
  15051. $this->y = $y + round($h/2);
  15052. $this->x = $this->img_rb_x;
  15053. break;
  15054. }
  15055. case 'B':{
  15056. $this->y = $this->img_rb_y;
  15057. $this->x = $this->img_rb_x;
  15058. break;
  15059. }
  15060. case 'N':{
  15061. $this->SetY($this->img_rb_y);
  15062. break;
  15063. }
  15064. default:{
  15065. break;
  15066. }
  15067. }
  15068. $this->endlinex = $this->img_rb_x;
  15069. }
  15070. /**
  15071. * Returns an array containing current margins:
  15072. * <ul>
  15073. <li>$ret['left'] = left margin</li>
  15074. <li>$ret['right'] = right margin</li>
  15075. <li>$ret['top'] = top margin</li>
  15076. <li>$ret['bottom'] = bottom margin</li>
  15077. <li>$ret['header'] = header margin</li>
  15078. <li>$ret['footer'] = footer margin</li>
  15079. <li>$ret['cell'] = cell padding array</li>
  15080. <li>$ret['padding_left'] = cell left padding</li>
  15081. <li>$ret['padding_top'] = cell top padding</li>
  15082. <li>$ret['padding_right'] = cell right padding</li>
  15083. <li>$ret['padding_bottom'] = cell bottom padding</li>
  15084. * </ul>
  15085. * @return array containing all margins measures
  15086. * @public
  15087. * @since 3.2.000 (2008-06-23)
  15088. */
  15089. public function getMargins() {
  15090. $ret = array(
  15091. 'left' => $this->lMargin,
  15092. 'right' => $this->rMargin,
  15093. 'top' => $this->tMargin,
  15094. 'bottom' => $this->bMargin,
  15095. 'header' => $this->header_margin,
  15096. 'footer' => $this->footer_margin,
  15097. 'cell' => $this->cell_padding,
  15098. 'padding_left' => $this->cell_padding['L'],
  15099. 'padding_top' => $this->cell_padding['T'],
  15100. 'padding_right' => $this->cell_padding['R'],
  15101. 'padding_bottom' => $this->cell_padding['B']
  15102. );
  15103. return $ret;
  15104. }
  15105. /**
  15106. * Returns an array containing original margins:
  15107. * <ul>
  15108. <li>$ret['left'] = left margin</li>
  15109. <li>$ret['right'] = right margin</li>
  15110. * </ul>
  15111. * @return array containing all margins measures
  15112. * @public
  15113. * @since 4.0.012 (2008-07-24)
  15114. */
  15115. public function getOriginalMargins() {
  15116. $ret = array(
  15117. 'left' => $this->original_lMargin,
  15118. 'right' => $this->original_rMargin
  15119. );
  15120. return $ret;
  15121. }
  15122. /**
  15123. * Returns the current font size.
  15124. * @return current font size
  15125. * @public
  15126. * @since 3.2.000 (2008-06-23)
  15127. */
  15128. public function getFontSize() {
  15129. return $this->FontSize;
  15130. }
  15131. /**
  15132. * Returns the current font size in points unit.
  15133. * @return current font size in points unit
  15134. * @public
  15135. * @since 3.2.000 (2008-06-23)
  15136. */
  15137. public function getFontSizePt() {
  15138. return $this->FontSizePt;
  15139. }
  15140. /**
  15141. * Returns the current font family name.
  15142. * @return string current font family name
  15143. * @public
  15144. * @since 4.3.008 (2008-12-05)
  15145. */
  15146. public function getFontFamily() {
  15147. return $this->FontFamily;
  15148. }
  15149. /**
  15150. * Returns the current font style.
  15151. * @return string current font style
  15152. * @public
  15153. * @since 4.3.008 (2008-12-05)
  15154. */
  15155. public function getFontStyle() {
  15156. return $this->FontStyle;
  15157. }
  15158. /**
  15159. * Cleanup HTML code (requires HTML Tidy library).
  15160. * @param $html (string) htmlcode to fix
  15161. * @param $default_css (string) CSS commands to add
  15162. * @param $tagvs (array) parameters for setHtmlVSpace method
  15163. * @param $tidy_options (array) options for tidy_parse_string function
  15164. * @return string XHTML code cleaned up
  15165. * @author Nicola Asuni
  15166. * @public
  15167. * @since 5.9.017 (2010-11-16)
  15168. * @see setHtmlVSpace()
  15169. */
  15170. public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
  15171. return TCPDF_STATIC::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces);
  15172. }
  15173. /**
  15174. * Returns the border width from CSS property
  15175. * @param $width (string) border width
  15176. * @return int with in user units
  15177. * @protected
  15178. * @since 5.7.000 (2010-08-02)
  15179. */
  15180. protected function getCSSBorderWidth($width) {
  15181. if ($width == 'thin') {
  15182. $width = (2 / $this->k);
  15183. } elseif ($width == 'medium') {
  15184. $width = (4 / $this->k);
  15185. } elseif ($width == 'thick') {
  15186. $width = (6 / $this->k);
  15187. } else {
  15188. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  15189. }
  15190. return $width;
  15191. }
  15192. /**
  15193. * Returns the border dash style from CSS property
  15194. * @param $style (string) border style to convert
  15195. * @return int sash style (return -1 in case of none or hidden border)
  15196. * @protected
  15197. * @since 5.7.000 (2010-08-02)
  15198. */
  15199. protected function getCSSBorderDashStyle($style) {
  15200. switch (strtolower($style)) {
  15201. case 'none':
  15202. case 'hidden': {
  15203. $dash = -1;
  15204. break;
  15205. }
  15206. case 'dotted': {
  15207. $dash = 1;
  15208. break;
  15209. }
  15210. case 'dashed': {
  15211. $dash = 3;
  15212. break;
  15213. }
  15214. case 'double':
  15215. case 'groove':
  15216. case 'ridge':
  15217. case 'inset':
  15218. case 'outset':
  15219. case 'solid':
  15220. default: {
  15221. $dash = 0;
  15222. break;
  15223. }
  15224. }
  15225. return $dash;
  15226. }
  15227. /**
  15228. * Returns the border style array from CSS border properties
  15229. * @param $cssborder (string) border properties
  15230. * @return array containing border properties
  15231. * @protected
  15232. * @since 5.7.000 (2010-08-02)
  15233. */
  15234. protected function getCSSBorderStyle($cssborder) {
  15235. $bprop = preg_split('/[\s]+/', trim($cssborder));
  15236. $border = array(); // value to be returned
  15237. switch (count($bprop)) {
  15238. case 3: {
  15239. $width = $bprop[0];
  15240. $style = $bprop[1];
  15241. $color = $bprop[2];
  15242. break;
  15243. }
  15244. case 2: {
  15245. $width = 'medium';
  15246. $style = $bprop[0];
  15247. $color = $bprop[1];
  15248. break;
  15249. }
  15250. case 1: {
  15251. $width = 'medium';
  15252. $style = $bprop[0];
  15253. $color = 'black';
  15254. break;
  15255. }
  15256. default: {
  15257. $width = 'medium';
  15258. $style = 'solid';
  15259. $color = 'black';
  15260. break;
  15261. }
  15262. }
  15263. if ($style == 'none') {
  15264. return array();
  15265. }
  15266. $border['cap'] = 'square';
  15267. $border['join'] = 'miter';
  15268. $border['dash'] = $this->getCSSBorderDashStyle($style);
  15269. if ($border['dash'] < 0) {
  15270. return array();
  15271. }
  15272. $border['width'] = $this->getCSSBorderWidth($width);
  15273. $border['color'] = TCPDF_COLORS::convertHTMLColorToDec($color, $this->spot_colors);
  15274. return $border;
  15275. }
  15276. /**
  15277. * Get the internal Cell padding from CSS attribute.
  15278. * @param $csspadding (string) padding properties
  15279. * @param $width (float) width of the containing element
  15280. * @return array of cell paddings
  15281. * @public
  15282. * @since 5.9.000 (2010-10-04)
  15283. */
  15284. public function getCSSPadding($csspadding, $width=0) {
  15285. $padding = preg_split('/[\s]+/', trim($csspadding));
  15286. $cell_padding = array(); // value to be returned
  15287. switch (count($padding)) {
  15288. case 4: {
  15289. $cell_padding['T'] = $padding[0];
  15290. $cell_padding['R'] = $padding[1];
  15291. $cell_padding['B'] = $padding[2];
  15292. $cell_padding['L'] = $padding[3];
  15293. break;
  15294. }
  15295. case 3: {
  15296. $cell_padding['T'] = $padding[0];
  15297. $cell_padding['R'] = $padding[1];
  15298. $cell_padding['B'] = $padding[2];
  15299. $cell_padding['L'] = $padding[1];
  15300. break;
  15301. }
  15302. case 2: {
  15303. $cell_padding['T'] = $padding[0];
  15304. $cell_padding['R'] = $padding[1];
  15305. $cell_padding['B'] = $padding[0];
  15306. $cell_padding['L'] = $padding[1];
  15307. break;
  15308. }
  15309. case 1: {
  15310. $cell_padding['T'] = $padding[0];
  15311. $cell_padding['R'] = $padding[0];
  15312. $cell_padding['B'] = $padding[0];
  15313. $cell_padding['L'] = $padding[0];
  15314. break;
  15315. }
  15316. default: {
  15317. return $this->cell_padding;
  15318. }
  15319. }
  15320. if ($width == 0) {
  15321. $width = $this->w - $this->lMargin - $this->rMargin;
  15322. }
  15323. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  15324. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  15325. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  15326. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  15327. return $cell_padding;
  15328. }
  15329. /**
  15330. * Get the internal Cell margin from CSS attribute.
  15331. * @param $cssmargin (string) margin properties
  15332. * @param $width (float) width of the containing element
  15333. * @return array of cell margins
  15334. * @public
  15335. * @since 5.9.000 (2010-10-04)
  15336. */
  15337. public function getCSSMargin($cssmargin, $width=0) {
  15338. $margin = preg_split('/[\s]+/', trim($cssmargin));
  15339. $cell_margin = array(); // value to be returned
  15340. switch (count($margin)) {
  15341. case 4: {
  15342. $cell_margin['T'] = $margin[0];
  15343. $cell_margin['R'] = $margin[1];
  15344. $cell_margin['B'] = $margin[2];
  15345. $cell_margin['L'] = $margin[3];
  15346. break;
  15347. }
  15348. case 3: {
  15349. $cell_margin['T'] = $margin[0];
  15350. $cell_margin['R'] = $margin[1];
  15351. $cell_margin['B'] = $margin[2];
  15352. $cell_margin['L'] = $margin[1];
  15353. break;
  15354. }
  15355. case 2: {
  15356. $cell_margin['T'] = $margin[0];
  15357. $cell_margin['R'] = $margin[1];
  15358. $cell_margin['B'] = $margin[0];
  15359. $cell_margin['L'] = $margin[1];
  15360. break;
  15361. }
  15362. case 1: {
  15363. $cell_margin['T'] = $margin[0];
  15364. $cell_margin['R'] = $margin[0];
  15365. $cell_margin['B'] = $margin[0];
  15366. $cell_margin['L'] = $margin[0];
  15367. break;
  15368. }
  15369. default: {
  15370. return $this->cell_margin;
  15371. }
  15372. }
  15373. if ($width == 0) {
  15374. $width = $this->w - $this->lMargin - $this->rMargin;
  15375. }
  15376. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  15377. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  15378. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  15379. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  15380. return $cell_margin;
  15381. }
  15382. /**
  15383. * Get the border-spacing from CSS attribute.
  15384. * @param $cssbspace (string) border-spacing CSS properties
  15385. * @param $width (float) width of the containing element
  15386. * @return array of border spacings
  15387. * @public
  15388. * @since 5.9.010 (2010-10-27)
  15389. */
  15390. public function getCSSBorderMargin($cssbspace, $width=0) {
  15391. $space = preg_split('/[\s]+/', trim($cssbspace));
  15392. $border_spacing = array(); // value to be returned
  15393. switch (count($space)) {
  15394. case 2: {
  15395. $border_spacing['H'] = $space[0];
  15396. $border_spacing['V'] = $space[1];
  15397. break;
  15398. }
  15399. case 1: {
  15400. $border_spacing['H'] = $space[0];
  15401. $border_spacing['V'] = $space[0];
  15402. break;
  15403. }
  15404. default: {
  15405. return array('H' => 0, 'V' => 0);
  15406. }
  15407. }
  15408. if ($width == 0) {
  15409. $width = $this->w - $this->lMargin - $this->rMargin;
  15410. }
  15411. $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
  15412. $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
  15413. return $border_spacing;
  15414. }
  15415. /**
  15416. * Returns the letter-spacing value from CSS value
  15417. * @param $spacing (string) letter-spacing value
  15418. * @param $parent (float) font spacing (tracking) value of the parent element
  15419. * @return float quantity to increases or decreases the space between characters in a text.
  15420. * @protected
  15421. * @since 5.9.000 (2010-10-02)
  15422. */
  15423. protected function getCSSFontSpacing($spacing, $parent=0) {
  15424. $val = 0; // value to be returned
  15425. $spacing = trim($spacing);
  15426. switch ($spacing) {
  15427. case 'normal': {
  15428. $val = 0;
  15429. break;
  15430. }
  15431. case 'inherit': {
  15432. if ($parent == 'normal') {
  15433. $val = 0;
  15434. } else {
  15435. $val = $parent;
  15436. }
  15437. break;
  15438. }
  15439. default: {
  15440. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  15441. }
  15442. }
  15443. return $val;
  15444. }
  15445. /**
  15446. * Returns the percentage of font stretching from CSS value
  15447. * @param $stretch (string) stretch mode
  15448. * @param $parent (float) stretch value of the parent element
  15449. * @return float font stretching percentage
  15450. * @protected
  15451. * @since 5.9.000 (2010-10-02)
  15452. */
  15453. protected function getCSSFontStretching($stretch, $parent=100) {
  15454. $val = 100; // value to be returned
  15455. $stretch = trim($stretch);
  15456. switch ($stretch) {
  15457. case 'ultra-condensed': {
  15458. $val = 40;
  15459. break;
  15460. }
  15461. case 'extra-condensed': {
  15462. $val = 55;
  15463. break;
  15464. }
  15465. case 'condensed': {
  15466. $val = 70;
  15467. break;
  15468. }
  15469. case 'semi-condensed': {
  15470. $val = 85;
  15471. break;
  15472. }
  15473. case 'normal': {
  15474. $val = 100;
  15475. break;
  15476. }
  15477. case 'semi-expanded': {
  15478. $val = 115;
  15479. break;
  15480. }
  15481. case 'expanded': {
  15482. $val = 130;
  15483. break;
  15484. }
  15485. case 'extra-expanded': {
  15486. $val = 145;
  15487. break;
  15488. }
  15489. case 'ultra-expanded': {
  15490. $val = 160;
  15491. break;
  15492. }
  15493. case 'wider': {
  15494. $val = ($parent + 10);
  15495. break;
  15496. }
  15497. case 'narrower': {
  15498. $val = ($parent - 10);
  15499. break;
  15500. }
  15501. case 'inherit': {
  15502. if ($parent == 'normal') {
  15503. $val = 100;
  15504. } else {
  15505. $val = $parent;
  15506. }
  15507. break;
  15508. }
  15509. default: {
  15510. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  15511. }
  15512. }
  15513. return $val;
  15514. }
  15515. /**
  15516. * Convert HTML string containing font size value to points
  15517. * @param $val (string) String containing font size value and unit.
  15518. * @param $refsize (float) Reference font size in points.
  15519. * @param $parent_size (float) Parent font size in points.
  15520. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  15521. * @return float value in points
  15522. * @public
  15523. */
  15524. public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
  15525. $refsize = TCPDF_FONTS::getFontRefSize($refsize);
  15526. $parent_size = TCPDF_FONTS::getFontRefSize($parent_size, $refsize);
  15527. switch ($val) {
  15528. case 'xx-small': {
  15529. $size = ($refsize - 4);
  15530. break;
  15531. }
  15532. case 'x-small': {
  15533. $size = ($refsize - 3);
  15534. break;
  15535. }
  15536. case 'small': {
  15537. $size = ($refsize - 2);
  15538. break;
  15539. }
  15540. case 'medium': {
  15541. $size = $refsize;
  15542. break;
  15543. }
  15544. case 'large': {
  15545. $size = ($refsize + 2);
  15546. break;
  15547. }
  15548. case 'x-large': {
  15549. $size = ($refsize + 4);
  15550. break;
  15551. }
  15552. case 'xx-large': {
  15553. $size = ($refsize + 6);
  15554. break;
  15555. }
  15556. case 'smaller': {
  15557. $size = ($parent_size - 3);
  15558. break;
  15559. }
  15560. case 'larger': {
  15561. $size = ($parent_size + 3);
  15562. break;
  15563. }
  15564. default: {
  15565. $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
  15566. }
  15567. }
  15568. return $size;
  15569. }
  15570. /**
  15571. * Returns the HTML DOM array.
  15572. * @param $html (string) html code
  15573. * @return array
  15574. * @protected
  15575. * @since 3.2.000 (2008-06-20)
  15576. */
  15577. protected function getHtmlDomArray($html) {
  15578. // array of CSS styles ( selector => properties).
  15579. $css = array();
  15580. // get CSS array defined at previous call
  15581. $matches = array();
  15582. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
  15583. if (isset($matches[1][0])) {
  15584. $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
  15585. }
  15586. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  15587. }
  15588. // extract external CSS files
  15589. $matches = array();
  15590. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
  15591. foreach ($matches[1] as $key => $link) {
  15592. $type = array();
  15593. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
  15594. $type = array();
  15595. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  15596. // get 'all' and 'print' media, other media types are discarded
  15597. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15598. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15599. $type = array();
  15600. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
  15601. // read CSS data file
  15602. $cssdata = TCPDF_STATIC::fileGetContents(trim($type[1]));
  15603. if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
  15604. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15605. }
  15606. }
  15607. }
  15608. }
  15609. }
  15610. }
  15611. // extract style tags
  15612. $matches = array();
  15613. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
  15614. foreach ($matches[1] as $key => $media) {
  15615. $type = array();
  15616. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  15617. // get 'all' and 'print' media, other media types are discarded
  15618. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  15619. if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
  15620. $cssdata = $matches[2][$key];
  15621. $css = array_merge($css, TCPDF_STATIC::extractCSSproperties($cssdata));
  15622. }
  15623. }
  15624. }
  15625. // create a special tag to contain the CSS array (used for table content)
  15626. $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
  15627. // remove head and style blocks
  15628. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  15629. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  15630. // define block tags
  15631. $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
  15632. // define self-closing tags
  15633. $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
  15634. // remove all unsupported tags (the line below lists all supported tags)
  15635. $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>');
  15636. //replace some blank characters
  15637. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  15638. $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);
  15639. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  15640. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  15641. $html = strtr($html, $repTable);
  15642. $offset = 0;
  15643. while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
  15644. $html_a = substr($html, 0, $offset);
  15645. $html_b = substr($html, $offset, ($pos - $offset + 6));
  15646. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
  15647. // preserve newlines on <pre> tag
  15648. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  15649. }
  15650. while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], $html_b)) {
  15651. // preserve spaces on <pre> tag
  15652. $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space['p']."(.*?)</pre>'".$this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  15653. }
  15654. $html = $html_a.$html_b.substr($html, $pos + 6);
  15655. $offset = strlen($html_a.$html_b);
  15656. }
  15657. $offset = 0;
  15658. while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
  15659. $html_a = substr($html, 0, $offset);
  15660. $html_b = substr($html, $offset, ($pos - $offset + 11));
  15661. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
  15662. // preserve newlines on <textarea> tag
  15663. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  15664. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  15665. }
  15666. $html = $html_a.$html_b.substr($html, $pos + 11);
  15667. $offset = strlen($html_a.$html_b);
  15668. }
  15669. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  15670. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  15671. $offset = 0;
  15672. while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
  15673. $html_a = substr($html, 0, $offset);
  15674. $html_b = substr($html, $offset, ($pos - $offset + 9));
  15675. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
  15676. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  15677. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  15678. }
  15679. $html = $html_a.$html_b.substr($html, $pos + 9);
  15680. $offset = strlen($html_a.$html_b);
  15681. }
  15682. if (preg_match("'</select'si", $html)) {
  15683. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  15684. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  15685. }
  15686. $html = str_replace("\n", ' ', $html);
  15687. // restore textarea newlines
  15688. $html = str_replace('<TBR>', "\n", $html);
  15689. // remove extra spaces from code
  15690. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  15691. $html = preg_replace('/'.$this->re_space['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space['m'], '</\\1>', $html);
  15692. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  15693. $html = preg_replace('/'.$this->re_space['p'].'+<(ul|ol|dl|br)/'.$this->re_space['m'], '<\\1', $html);
  15694. $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);
  15695. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  15696. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  15697. $html = preg_replace('/'.$this->re_space['p'].'+<img/'.$this->re_space['m'], chr(32).'<img', $html);
  15698. $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1>&nbsp;\\2', $html);
  15699. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  15700. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  15701. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  15702. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  15703. $html = preg_replace('/<li([^\>]*)>'.$this->re_space['p'].'*<img/'.$this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  15704. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  15705. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  15706. $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
  15707. $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
  15708. $html = preg_replace('/'.$this->re_space['p'].'+/'.$this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  15709. // trim string
  15710. $html = $this->stringTrim($html);
  15711. // fix br tag after li
  15712. $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
  15713. // fix first image tag alignment
  15714. $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
  15715. // pattern for generic tag
  15716. $tagpattern = '/(<[^>]+>)/';
  15717. // explodes the string
  15718. $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  15719. // count elements
  15720. $maxel = count($a);
  15721. $elkey = 0;
  15722. $key = 0;
  15723. // create an array of elements
  15724. $dom = array();
  15725. $dom[$key] = array();
  15726. // set inheritable properties fot the first void element
  15727. // 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
  15728. $dom[$key]['tag'] = false;
  15729. $dom[$key]['block'] = false;
  15730. $dom[$key]['value'] = '';
  15731. $dom[$key]['parent'] = 0;
  15732. $dom[$key]['hide'] = false;
  15733. $dom[$key]['fontname'] = $this->FontFamily;
  15734. $dom[$key]['fontstyle'] = $this->FontStyle;
  15735. $dom[$key]['fontsize'] = $this->FontSizePt;
  15736. $dom[$key]['font-stretch'] = $this->font_stretching;
  15737. $dom[$key]['letter-spacing'] = $this->font_spacing;
  15738. $dom[$key]['stroke'] = $this->textstrokewidth;
  15739. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  15740. $dom[$key]['clip'] = ($this->textrendermode > 3);
  15741. $dom[$key]['line-height'] = $this->cell_height_ratio;
  15742. $dom[$key]['bgcolor'] = false;
  15743. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  15744. $dom[$key]['strokecolor'] = $this->strokecolor;
  15745. $dom[$key]['align'] = '';
  15746. $dom[$key]['listtype'] = '';
  15747. $dom[$key]['text-indent'] = 0;
  15748. $dom[$key]['border'] = array();
  15749. $dom[$key]['dir'] = $this->rtl?'rtl':'ltr';
  15750. $thead = false; // true when we are inside the THEAD tag
  15751. ++$key;
  15752. $level = array();
  15753. array_push($level, 0); // root
  15754. while ($elkey < $maxel) {
  15755. $dom[$key] = array();
  15756. $element = $a[$elkey];
  15757. $dom[$key]['elkey'] = $elkey;
  15758. if (preg_match($tagpattern, $element)) {
  15759. // html tag
  15760. $element = substr($element, 1, -1);
  15761. // get tag name
  15762. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  15763. $tagname = strtolower($tag[1]);
  15764. // check if we are inside a table header
  15765. if ($tagname == 'thead') {
  15766. if ($element{0} == '/') {
  15767. $thead = false;
  15768. } else {
  15769. $thead = true;
  15770. }
  15771. ++$elkey;
  15772. continue;
  15773. }
  15774. $dom[$key]['tag'] = true;
  15775. $dom[$key]['value'] = $tagname;
  15776. if (in_array($dom[$key]['value'], $blocktags)) {
  15777. $dom[$key]['block'] = true;
  15778. } else {
  15779. $dom[$key]['block'] = false;
  15780. }
  15781. if ($element{0} == '/') {
  15782. // *** closing html tag
  15783. $dom[$key]['opening'] = false;
  15784. $dom[$key]['parent'] = end($level);
  15785. array_pop($level);
  15786. $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
  15787. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  15788. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  15789. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  15790. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  15791. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  15792. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  15793. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  15794. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  15795. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  15796. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  15797. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  15798. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  15799. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  15800. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  15801. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
  15802. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  15803. }
  15804. // set the number of columns in table tag
  15805. if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
  15806. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  15807. }
  15808. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  15809. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  15810. for ($i = ($dom[$key]['parent'] + 1); $i < $key; ++$i) {
  15811. $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
  15812. }
  15813. $key = $i;
  15814. // mark nested tables
  15815. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
  15816. // remove thead sections from nested tables
  15817. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  15818. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  15819. }
  15820. // store header rows on a new table
  15821. if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
  15822. if (TCPDF_STATIC::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
  15823. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  15824. }
  15825. for ($i = $dom[$key]['parent']; $i <= $key; ++$i) {
  15826. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  15827. }
  15828. if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
  15829. $dom[($dom[$key]['parent'])]['attribute'] = array();
  15830. }
  15831. // header elements must be always contained in a single page
  15832. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  15833. }
  15834. if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
  15835. // remove the nobr attributes from the table header
  15836. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  15837. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  15838. }
  15839. } else {
  15840. // *** opening or self-closing html tag
  15841. $dom[$key]['opening'] = true;
  15842. $dom[$key]['parent'] = end($level);
  15843. if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
  15844. // self-closing tag
  15845. $dom[$key]['self'] = true;
  15846. } else {
  15847. // opening tag
  15848. array_push($level, $key);
  15849. $dom[$key]['self'] = false;
  15850. }
  15851. // copy some values from parent
  15852. $parentkey = 0;
  15853. if ($key > 0) {
  15854. $parentkey = $dom[$key]['parent'];
  15855. $dom[$key]['hide'] = $dom[$parentkey]['hide'];
  15856. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  15857. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  15858. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  15859. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  15860. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  15861. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  15862. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  15863. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  15864. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  15865. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  15866. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  15867. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  15868. $dom[$key]['align'] = $dom[$parentkey]['align'];
  15869. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  15870. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  15871. $dom[$key]['border'] = array();
  15872. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  15873. }
  15874. // get attributes
  15875. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  15876. $dom[$key]['attribute'] = array(); // reset attribute array
  15877. while (list($id, $name) = each($attr_array[1])) {
  15878. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  15879. }
  15880. if (!empty($css)) {
  15881. // merge CSS style to current style
  15882. list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC::getCSSdataArray($dom, $key, $css);
  15883. $dom[$key]['attribute']['style'] = TCPDF_STATIC::getTagStyleFromCSSarray($dom[$key]['cssdata']);
  15884. }
  15885. // split style attributes
  15886. if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
  15887. // get style attributes
  15888. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  15889. $dom[$key]['style'] = array(); // reset style attribute array
  15890. while (list($id, $name) = each($style_array[1])) {
  15891. // in case of duplicate attribute the last replace the previous
  15892. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  15893. }
  15894. // --- get some style attributes ---
  15895. // text direction
  15896. if (isset($dom[$key]['style']['direction'])) {
  15897. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  15898. }
  15899. // display
  15900. if (isset($dom[$key]['style']['display'])) {
  15901. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
  15902. }
  15903. // font family
  15904. if (isset($dom[$key]['style']['font-family'])) {
  15905. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  15906. }
  15907. // list-style-type
  15908. if (isset($dom[$key]['style']['list-style-type'])) {
  15909. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  15910. if ($dom[$key]['listtype'] == 'inherit') {
  15911. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  15912. }
  15913. }
  15914. // text-indent
  15915. if (isset($dom[$key]['style']['text-indent'])) {
  15916. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  15917. if ($dom[$key]['text-indent'] == 'inherit') {
  15918. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  15919. }
  15920. }
  15921. // font size
  15922. if (isset($dom[$key]['style']['font-size'])) {
  15923. $fsize = trim($dom[$key]['style']['font-size']);
  15924. $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
  15925. }
  15926. // font-stretch
  15927. if (isset($dom[$key]['style']['font-stretch'])) {
  15928. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  15929. }
  15930. // letter-spacing
  15931. if (isset($dom[$key]['style']['letter-spacing'])) {
  15932. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  15933. }
  15934. // line-height
  15935. if (isset($dom[$key]['style']['line-height'])) {
  15936. $lineheight = trim($dom[$key]['style']['line-height']);
  15937. switch ($lineheight) {
  15938. // A normal line height. This is default
  15939. case 'normal': {
  15940. $dom[$key]['line-height'] = $dom[0]['line-height'];
  15941. break;
  15942. }
  15943. default: {
  15944. if (is_numeric($lineheight)) {
  15945. $lineheight = $lineheight * 100;
  15946. }
  15947. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  15948. }
  15949. }
  15950. }
  15951. // font style
  15952. if (isset($dom[$key]['style']['font-weight'])) {
  15953. if (strtolower($dom[$key]['style']['font-weight']{0}) == 'n') {
  15954. if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
  15955. $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
  15956. }
  15957. } elseif (strtolower($dom[$key]['style']['font-weight']{0}) == 'b') {
  15958. $dom[$key]['fontstyle'] .= 'B';
  15959. }
  15960. }
  15961. if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
  15962. $dom[$key]['fontstyle'] .= 'I';
  15963. }
  15964. // font color
  15965. if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['color']))) {
  15966. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors);
  15967. } elseif ($dom[$key]['value'] == 'a') {
  15968. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  15969. }
  15970. // background color
  15971. if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['style']['background-color']))) {
  15972. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors);
  15973. }
  15974. // text-decoration
  15975. if (isset($dom[$key]['style']['text-decoration'])) {
  15976. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  15977. foreach ($decors as $dec) {
  15978. $dec = trim($dec);
  15979. if (!TCPDF_STATIC::empty_string($dec)) {
  15980. if ($dec{0} == 'u') {
  15981. // underline
  15982. $dom[$key]['fontstyle'] .= 'U';
  15983. } elseif ($dec{0} == 'l') {
  15984. // line-through
  15985. $dom[$key]['fontstyle'] .= 'D';
  15986. } elseif ($dec{0} == 'o') {
  15987. // overline
  15988. $dom[$key]['fontstyle'] .= 'O';
  15989. }
  15990. }
  15991. }
  15992. } elseif ($dom[$key]['value'] == 'a') {
  15993. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  15994. }
  15995. // check for width attribute
  15996. if (isset($dom[$key]['style']['width'])) {
  15997. $dom[$key]['width'] = $dom[$key]['style']['width'];
  15998. }
  15999. // check for height attribute
  16000. if (isset($dom[$key]['style']['height'])) {
  16001. $dom[$key]['height'] = $dom[$key]['style']['height'];
  16002. }
  16003. // check for text alignment
  16004. if (isset($dom[$key]['style']['text-align'])) {
  16005. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
  16006. }
  16007. // check for CSS border properties
  16008. if (isset($dom[$key]['style']['border'])) {
  16009. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  16010. if (!empty($borderstyle)) {
  16011. $dom[$key]['border']['LTRB'] = $borderstyle;
  16012. }
  16013. }
  16014. if (isset($dom[$key]['style']['border-color'])) {
  16015. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  16016. if (isset($brd_colors[3])) {
  16017. $dom[$key]['border']['L']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[3], $this->spot_colors);
  16018. }
  16019. if (isset($brd_colors[1])) {
  16020. $dom[$key]['border']['R']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[1], $this->spot_colors);
  16021. }
  16022. if (isset($brd_colors[0])) {
  16023. $dom[$key]['border']['T']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[0], $this->spot_colors);
  16024. }
  16025. if (isset($brd_colors[2])) {
  16026. $dom[$key]['border']['B']['color'] = TCPDF_COLORS::convertHTMLColorToDec($brd_colors[2], $this->spot_colors);
  16027. }
  16028. }
  16029. if (isset($dom[$key]['style']['border-width'])) {
  16030. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  16031. if (isset($brd_widths[3])) {
  16032. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  16033. }
  16034. if (isset($brd_widths[1])) {
  16035. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  16036. }
  16037. if (isset($brd_widths[0])) {
  16038. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  16039. }
  16040. if (isset($brd_widths[2])) {
  16041. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  16042. }
  16043. }
  16044. if (isset($dom[$key]['style']['border-style'])) {
  16045. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  16046. if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
  16047. $dom[$key]['border']['L']['cap'] = 'square';
  16048. $dom[$key]['border']['L']['join'] = 'miter';
  16049. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  16050. if ($dom[$key]['border']['L']['dash'] < 0) {
  16051. $dom[$key]['border']['L'] = array();
  16052. }
  16053. }
  16054. if (isset($brd_styles[1])) {
  16055. $dom[$key]['border']['R']['cap'] = 'square';
  16056. $dom[$key]['border']['R']['join'] = 'miter';
  16057. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  16058. if ($dom[$key]['border']['R']['dash'] < 0) {
  16059. $dom[$key]['border']['R'] = array();
  16060. }
  16061. }
  16062. if (isset($brd_styles[0])) {
  16063. $dom[$key]['border']['T']['cap'] = 'square';
  16064. $dom[$key]['border']['T']['join'] = 'miter';
  16065. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  16066. if ($dom[$key]['border']['T']['dash'] < 0) {
  16067. $dom[$key]['border']['T'] = array();
  16068. }
  16069. }
  16070. if (isset($brd_styles[2])) {
  16071. $dom[$key]['border']['B']['cap'] = 'square';
  16072. $dom[$key]['border']['B']['join'] = 'miter';
  16073. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  16074. if ($dom[$key]['border']['B']['dash'] < 0) {
  16075. $dom[$key]['border']['B'] = array();
  16076. }
  16077. }
  16078. }
  16079. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  16080. foreach ($cellside as $bsk => $bsv) {
  16081. if (isset($dom[$key]['style']['border-'.$bsv])) {
  16082. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
  16083. if (!empty($borderstyle)) {
  16084. $dom[$key]['border'][$bsk] = $borderstyle;
  16085. }
  16086. }
  16087. if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
  16088. $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors);
  16089. }
  16090. if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
  16091. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
  16092. }
  16093. if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
  16094. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
  16095. if ($dom[$key]['border'][$bsk]['dash'] < 0) {
  16096. $dom[$key]['border'][$bsk] = array();
  16097. }
  16098. }
  16099. }
  16100. // check for CSS padding properties
  16101. if (isset($dom[$key]['style']['padding'])) {
  16102. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  16103. } else {
  16104. $dom[$key]['padding'] = $this->cell_padding;
  16105. }
  16106. foreach ($cellside as $psk => $psv) {
  16107. if (isset($dom[$key]['style']['padding-'.$psv])) {
  16108. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
  16109. }
  16110. }
  16111. // check for CSS margin properties
  16112. if (isset($dom[$key]['style']['margin'])) {
  16113. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  16114. } else {
  16115. $dom[$key]['margin'] = $this->cell_margin;
  16116. }
  16117. foreach ($cellside as $psk => $psv) {
  16118. if (isset($dom[$key]['style']['margin-'.$psv])) {
  16119. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
  16120. }
  16121. }
  16122. // check for CSS border-spacing properties
  16123. if (isset($dom[$key]['style']['border-spacing'])) {
  16124. $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
  16125. }
  16126. // page-break-inside
  16127. if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
  16128. $dom[$key]['attribute']['nobr'] = 'true';
  16129. }
  16130. // page-break-before
  16131. if (isset($dom[$key]['style']['page-break-before'])) {
  16132. if ($dom[$key]['style']['page-break-before'] == 'always') {
  16133. $dom[$key]['attribute']['pagebreak'] = 'true';
  16134. } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
  16135. $dom[$key]['attribute']['pagebreak'] = 'left';
  16136. } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
  16137. $dom[$key]['attribute']['pagebreak'] = 'right';
  16138. }
  16139. }
  16140. // page-break-after
  16141. if (isset($dom[$key]['style']['page-break-after'])) {
  16142. if ($dom[$key]['style']['page-break-after'] == 'always') {
  16143. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  16144. } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
  16145. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  16146. } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
  16147. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  16148. }
  16149. }
  16150. }
  16151. if (isset($dom[$key]['attribute']['display'])) {
  16152. $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
  16153. }
  16154. if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
  16155. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
  16156. if (!empty($borderstyle)) {
  16157. $dom[$key]['border']['LTRB'] = $borderstyle;
  16158. }
  16159. }
  16160. // check for font tag
  16161. if ($dom[$key]['value'] == 'font') {
  16162. // font family
  16163. if (isset($dom[$key]['attribute']['face'])) {
  16164. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  16165. }
  16166. // font size
  16167. if (isset($dom[$key]['attribute']['size'])) {
  16168. if ($key > 0) {
  16169. if ($dom[$key]['attribute']['size']{0} == '+') {
  16170. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  16171. } elseif ($dom[$key]['attribute']['size']{0} == '-') {
  16172. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  16173. } else {
  16174. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16175. }
  16176. } else {
  16177. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  16178. }
  16179. }
  16180. }
  16181. // force natural alignment for lists
  16182. if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
  16183. AND (!isset($dom[$key]['align']) OR TCPDF_STATIC::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
  16184. if ($this->rtl) {
  16185. $dom[$key]['align'] = 'R';
  16186. } else {
  16187. $dom[$key]['align'] = 'L';
  16188. }
  16189. }
  16190. if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
  16191. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16192. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  16193. }
  16194. }
  16195. if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
  16196. $dom[$key]['fontstyle'] .= 'B';
  16197. }
  16198. if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
  16199. $dom[$key]['fontstyle'] .= 'I';
  16200. }
  16201. if ($dom[$key]['value'] == 'u') {
  16202. $dom[$key]['fontstyle'] .= 'U';
  16203. }
  16204. if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
  16205. $dom[$key]['fontstyle'] .= 'D';
  16206. }
  16207. if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
  16208. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  16209. }
  16210. if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
  16211. $dom[$key]['fontname'] = $this->default_monospaced_font;
  16212. }
  16213. if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
  16214. // headings h1, h2, h3, h4, h5, h6
  16215. if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
  16216. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  16217. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  16218. }
  16219. if (!isset($dom[$key]['style']['font-weight'])) {
  16220. $dom[$key]['fontstyle'] .= 'B';
  16221. }
  16222. }
  16223. if (($dom[$key]['value'] == 'table')) {
  16224. $dom[$key]['rows'] = 0; // number of rows
  16225. $dom[$key]['trids'] = array(); // IDs of TR elements
  16226. $dom[$key]['thead'] = ''; // table header rows
  16227. }
  16228. if (($dom[$key]['value'] == 'tr')) {
  16229. $dom[$key]['cols'] = 0;
  16230. if ($thead) {
  16231. $dom[$key]['thead'] = true;
  16232. // rows on thead block are printed as a separate table
  16233. } else {
  16234. $dom[$key]['thead'] = false;
  16235. // store the number of rows on table element
  16236. ++$dom[($dom[$key]['parent'])]['rows'];
  16237. // store the TR elements IDs on table element
  16238. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  16239. }
  16240. }
  16241. if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
  16242. if (isset($dom[$key]['attribute']['colspan'])) {
  16243. $colspan = intval($dom[$key]['attribute']['colspan']);
  16244. } else {
  16245. $colspan = 1;
  16246. }
  16247. $dom[$key]['attribute']['colspan'] = $colspan;
  16248. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  16249. }
  16250. // text direction
  16251. if (isset($dom[$key]['attribute']['dir'])) {
  16252. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  16253. }
  16254. // set foreground color attribute
  16255. if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['color']))) {
  16256. $dom[$key]['fgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors);
  16257. } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
  16258. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  16259. }
  16260. // set background color attribute
  16261. if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['bgcolor']))) {
  16262. $dom[$key]['bgcolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors);
  16263. }
  16264. // set stroke color attribute
  16265. if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['strokecolor']))) {
  16266. $dom[$key]['strokecolor'] = TCPDF_COLORS::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors);
  16267. }
  16268. // check for width attribute
  16269. if (isset($dom[$key]['attribute']['width'])) {
  16270. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  16271. }
  16272. // check for height attribute
  16273. if (isset($dom[$key]['attribute']['height'])) {
  16274. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  16275. }
  16276. // check for text alignment
  16277. if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
  16278. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
  16279. }
  16280. // check for text rendering mode (the following attributes do not exist in HTML)
  16281. if (isset($dom[$key]['attribute']['stroke'])) {
  16282. // font stroke width
  16283. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  16284. }
  16285. if (isset($dom[$key]['attribute']['fill'])) {
  16286. // font fill
  16287. if ($dom[$key]['attribute']['fill'] == 'true') {
  16288. $dom[$key]['fill'] = true;
  16289. } else {
  16290. $dom[$key]['fill'] = false;
  16291. }
  16292. }
  16293. if (isset($dom[$key]['attribute']['clip'])) {
  16294. // clipping mode
  16295. if ($dom[$key]['attribute']['clip'] == 'true') {
  16296. $dom[$key]['clip'] = true;
  16297. } else {
  16298. $dom[$key]['clip'] = false;
  16299. }
  16300. }
  16301. } // end opening tag
  16302. } else {
  16303. // text
  16304. $dom[$key]['tag'] = false;
  16305. $dom[$key]['block'] = false;
  16306. //$element = str_replace('&nbsp;', TCPDF_FONTS::unichr(160, $this->isunicode), $element);
  16307. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  16308. $dom[$key]['parent'] = end($level);
  16309. $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
  16310. }
  16311. ++$elkey;
  16312. ++$key;
  16313. }
  16314. return $dom;
  16315. }
  16316. /**
  16317. * Returns the string used to find spaces
  16318. * @return string
  16319. * @protected
  16320. * @author Nicola Asuni
  16321. * @since 4.8.024 (2010-01-15)
  16322. */
  16323. protected function getSpaceString() {
  16324. $spacestr = chr(32);
  16325. if ($this->isUnicodeFont()) {
  16326. $spacestr = chr(0).chr(32);
  16327. }
  16328. return $spacestr;
  16329. }
  16330. /**
  16331. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  16332. * @param $pararray (array) parameters array
  16333. * @return sting containing serialized data
  16334. * @since 4.9.006 (2010-04-02)
  16335. * @public
  16336. * @deprecated
  16337. */
  16338. public function serializeTCPDFtagParameters($pararray) {
  16339. return TCPDF_STATIC::serializeTCPDFtagParameters($pararray);
  16340. }
  16341. /**
  16342. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  16343. * 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 />
  16344. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  16345. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16346. * 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
  16347. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16348. * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
  16349. * @param $h (float) Cell minimum height. The cell extends automatically if needed.
  16350. * @param $x (float) upper-left corner X coordinate
  16351. * @param $y (float) upper-left corner Y coordinate
  16352. * @param $html (string) html text to print. Default value: empty string.
  16353. * @param $border (mixed) 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)))
  16354. * @param $ln (int) 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>
  16355. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  16356. * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
  16357. * @param $reseth (boolean) if true reset the last cell height (default true).
  16358. * @param $align (string) 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>
  16359. * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
  16360. * @see Multicell(), writeHTML()
  16361. * @public
  16362. */
  16363. public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
  16364. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
  16365. }
  16366. /**
  16367. * Allows to preserve some HTML formatting (limited support).<br />
  16368. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  16369. * 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
  16370. * NOTE: all the HTML attributes must be enclosed in double-quote.
  16371. * @param $html (string) text to display
  16372. * @param $ln (boolean) if true add a new line after text (default = true)
  16373. * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
  16374. * @param $reseth (boolean) if true reset the last cell height (default false).
  16375. * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
  16376. * @param $align (string) 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>
  16377. * @public
  16378. */
  16379. public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
  16380. $gvars = $this->getGraphicVars();
  16381. // store current values
  16382. $prev_cell_margin = $this->cell_margin;
  16383. $prev_cell_padding = $this->cell_padding;
  16384. $prevPage = $this->page;
  16385. $prevlMargin = $this->lMargin;
  16386. $prevrMargin = $this->rMargin;
  16387. $curfontname = $this->FontFamily;
  16388. $curfontstyle = $this->FontStyle;
  16389. $curfontsize = $this->FontSizePt;
  16390. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  16391. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  16392. $curfontstretcing = $this->font_stretching;
  16393. $curfonttracking = $this->font_spacing;
  16394. $this->newline = true;
  16395. $newline = true;
  16396. $startlinepage = $this->page;
  16397. $minstartliney = $this->y;
  16398. $maxbottomliney = 0;
  16399. $startlinex = $this->x;
  16400. $startliney = $this->y;
  16401. $yshift = 0;
  16402. $loop = 0;
  16403. $curpos = 0;
  16404. $this_method_vars = array();
  16405. $undo = false;
  16406. $fontaligned = false;
  16407. $reverse_dir = false; // true when the text direction is reversed
  16408. $this->premode = false;
  16409. if ($this->inxobj) {
  16410. // we are inside an XObject template
  16411. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  16412. } elseif (isset($this->PageAnnots[$this->page])) {
  16413. $pask = count($this->PageAnnots[$this->page]);
  16414. } else {
  16415. $pask = 0;
  16416. }
  16417. if ($this->inxobj) {
  16418. // we are inside an XObject template
  16419. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  16420. } elseif (!$this->InFooter) {
  16421. if (isset($this->footerlen[$this->page])) {
  16422. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  16423. } else {
  16424. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  16425. }
  16426. $startlinepos = $this->footerpos[$this->page];
  16427. } else {
  16428. // we are inside the footer
  16429. $startlinepos = $this->pagelen[$this->page];
  16430. }
  16431. $lalign = $align;
  16432. $plalign = $align;
  16433. if ($this->rtl) {
  16434. $w = $this->x - $this->lMargin;
  16435. } else {
  16436. $w = $this->w - $this->rMargin - $this->x;
  16437. }
  16438. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  16439. if ($cell) {
  16440. if ($this->rtl) {
  16441. $this->x -= $this->cell_padding['R'];
  16442. $this->lMargin += $this->cell_padding['R'];
  16443. } else {
  16444. $this->x += $this->cell_padding['L'];
  16445. $this->rMargin += $this->cell_padding['L'];
  16446. }
  16447. }
  16448. if ($this->customlistindent >= 0) {
  16449. $this->listindent = $this->customlistindent;
  16450. } else {
  16451. $this->listindent = $this->GetStringWidth('000000');
  16452. }
  16453. $this->listindentlevel = 0;
  16454. // save previous states
  16455. $prev_cell_height_ratio = $this->cell_height_ratio;
  16456. $prev_listnum = $this->listnum;
  16457. $prev_listordered = $this->listordered;
  16458. $prev_listcount = $this->listcount;
  16459. $prev_lispacer = $this->lispacer;
  16460. $this->listnum = 0;
  16461. $this->listordered = array();
  16462. $this->listcount = array();
  16463. $this->lispacer = '';
  16464. if ((TCPDF_STATIC::empty_string($this->lasth)) OR ($reseth)) {
  16465. // reset row height
  16466. $this->resetLastH();
  16467. }
  16468. $dom = $this->getHtmlDomArray($html);
  16469. $maxel = count($dom);
  16470. $key = 0;
  16471. while ($key < $maxel) {
  16472. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
  16473. // store the node key
  16474. $hidden_node_key = $key;
  16475. if ($dom[$key]['self']) {
  16476. // skip just this self-closing tag
  16477. ++$key;
  16478. } else {
  16479. // skip this and all children tags
  16480. while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
  16481. // skip hidden objects
  16482. ++$key;
  16483. }
  16484. ++$key;
  16485. }
  16486. }
  16487. if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
  16488. // check for pagebreak
  16489. if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
  16490. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16491. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16492. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16493. }
  16494. if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  16495. OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  16496. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16497. $this->checkPageBreak($this->PageBreakTrigger + 1);
  16498. $this->htmlvspace = ($this->PageBreakTrigger + 1);
  16499. }
  16500. }
  16501. if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
  16502. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
  16503. $dom[$key]['attribute']['nobr'] = false;
  16504. } else {
  16505. // store current object
  16506. $this->startTransaction();
  16507. // save this method vars
  16508. $this_method_vars['html'] = $html;
  16509. $this_method_vars['ln'] = $ln;
  16510. $this_method_vars['fill'] = $fill;
  16511. $this_method_vars['reseth'] = $reseth;
  16512. $this_method_vars['cell'] = $cell;
  16513. $this_method_vars['align'] = $align;
  16514. $this_method_vars['gvars'] = $gvars;
  16515. $this_method_vars['prevPage'] = $prevPage;
  16516. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  16517. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  16518. $this_method_vars['prevlMargin'] = $prevlMargin;
  16519. $this_method_vars['prevrMargin'] = $prevrMargin;
  16520. $this_method_vars['curfontname'] = $curfontname;
  16521. $this_method_vars['curfontstyle'] = $curfontstyle;
  16522. $this_method_vars['curfontsize'] = $curfontsize;
  16523. $this_method_vars['curfontascent'] = $curfontascent;
  16524. $this_method_vars['curfontdescent'] = $curfontdescent;
  16525. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  16526. $this_method_vars['curfonttracking'] = $curfonttracking;
  16527. $this_method_vars['minstartliney'] = $minstartliney;
  16528. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  16529. $this_method_vars['yshift'] = $yshift;
  16530. $this_method_vars['startlinepage'] = $startlinepage;
  16531. $this_method_vars['startlinepos'] = $startlinepos;
  16532. $this_method_vars['startlinex'] = $startlinex;
  16533. $this_method_vars['startliney'] = $startliney;
  16534. $this_method_vars['newline'] = $newline;
  16535. $this_method_vars['loop'] = $loop;
  16536. $this_method_vars['curpos'] = $curpos;
  16537. $this_method_vars['pask'] = $pask;
  16538. $this_method_vars['lalign'] = $lalign;
  16539. $this_method_vars['plalign'] = $plalign;
  16540. $this_method_vars['w'] = $w;
  16541. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  16542. $this_method_vars['prev_listnum'] = $prev_listnum;
  16543. $this_method_vars['prev_listordered'] = $prev_listordered;
  16544. $this_method_vars['prev_listcount'] = $prev_listcount;
  16545. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  16546. $this_method_vars['fontaligned'] = $fontaligned;
  16547. $this_method_vars['key'] = $key;
  16548. $this_method_vars['dom'] = $dom;
  16549. }
  16550. }
  16551. // print THEAD block
  16552. if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
  16553. if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC::empty_string($dom[$dom[$key]['parent']]['thead'])) {
  16554. $this->inthead = true;
  16555. // print table header (thead)
  16556. $this->writeHTML($this->thead, false, false, false, false, '');
  16557. // check if we are on a new page or on a new column
  16558. if (($this->y < $this->start_transaction_y) OR ($this->checkPageBreak($this->lasth, '', false))) {
  16559. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  16560. // restore previous object
  16561. $this->rollbackTransaction(true);
  16562. // restore previous values
  16563. foreach ($this_method_vars as $vkey => $vval) {
  16564. $$vkey = $vval;
  16565. }
  16566. // disable table header
  16567. $tmp_thead = $this->thead;
  16568. $this->thead = '';
  16569. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  16570. $pre_y = $this->y;
  16571. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  16572. // fix for multicolumn mode
  16573. $startliney = $this->y;
  16574. }
  16575. $this->start_transaction_page = $this->page;
  16576. $this->start_transaction_y = $this->y;
  16577. // restore table header
  16578. $this->thead = $tmp_thead;
  16579. // fix table border properties
  16580. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
  16581. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  16582. } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
  16583. $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
  16584. } else {
  16585. $tmp_cellspacing = 0;
  16586. }
  16587. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  16588. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  16589. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  16590. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  16591. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  16592. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  16593. // print table header (thead)
  16594. $this->writeHTML($this->thead, false, false, false, false, '');
  16595. }
  16596. }
  16597. // move $key index forward to skip THEAD block
  16598. while ( ($key < $maxel) AND (!(
  16599. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
  16600. OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
  16601. ++$key;
  16602. }
  16603. }
  16604. if ($dom[$key]['tag'] OR ($key == 0)) {
  16605. if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
  16606. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  16607. }
  16608. // vertically align image in line
  16609. if ((!$this->newline) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
  16610. // get image height
  16611. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px');
  16612. $autolinebreak = false;
  16613. if (isset($dom[$key]['width']) AND ($dom[$key]['width'] > 0)) {
  16614. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
  16615. if (($imgw <= ($this->w - $this->lMargin - $this->rMargin - $this->cell_padding['L'] - $this->cell_padding['R']))
  16616. AND ((($this->rtl) AND (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L'])))
  16617. OR ((!$this->rtl) AND (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))) {
  16618. // add automatic line break
  16619. $autolinebreak = true;
  16620. $this->Ln('', $cell);
  16621. if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
  16622. // go back to evaluate this line break
  16623. --$key;
  16624. }
  16625. }
  16626. }
  16627. if (!$autolinebreak) {
  16628. if ($this->inPageBody()) {
  16629. $pre_y = $this->y;
  16630. // check for page break
  16631. if ((!$this->checkPageBreak($imgh)) AND ($this->y < $pre_y)) {
  16632. // fix for multicolumn mode
  16633. $startliney = $this->y;
  16634. }
  16635. }
  16636. if ($this->page > $startlinepage) {
  16637. // fix line splitted over two pages
  16638. if (isset($this->footerlen[$startlinepage])) {
  16639. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16640. }
  16641. // line to be moved one page forward
  16642. $pagebuff = $this->getPageBuffer($startlinepage);
  16643. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16644. $tstart = substr($pagebuff, 0, $startlinepos);
  16645. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16646. // remove line from previous page
  16647. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16648. $pagebuff = $this->getPageBuffer($this->page);
  16649. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16650. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16651. // add line start to current page
  16652. $yshift = ($minstartliney - $this->y);
  16653. if ($fontaligned) {
  16654. $yshift += ($curfontsize / $this->k);
  16655. }
  16656. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16657. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16658. // shift the annotations and links
  16659. if (isset($this->PageAnnots[$this->page])) {
  16660. $next_pask = count($this->PageAnnots[$this->page]);
  16661. } else {
  16662. $next_pask = 0;
  16663. }
  16664. if (isset($this->PageAnnots[$startlinepage])) {
  16665. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16666. if ($pak >= $pask) {
  16667. $this->PageAnnots[$this->page][] = $pac;
  16668. unset($this->PageAnnots[$startlinepage][$pak]);
  16669. $npak = count($this->PageAnnots[$this->page]) - 1;
  16670. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16671. }
  16672. }
  16673. }
  16674. $pask = $next_pask;
  16675. $startlinepos = $this->cntmrk[$this->page];
  16676. $startlinepage = $this->page;
  16677. $startliney = $this->y;
  16678. $this->newline = false;
  16679. }
  16680. $this->y += ((($curfontsize * $this->cell_height_ratio / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh;
  16681. $minstartliney = min($this->y, $minstartliney);
  16682. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  16683. }
  16684. } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
  16685. // account for different font size
  16686. $pfontname = $curfontname;
  16687. $pfontstyle = $curfontstyle;
  16688. $pfontsize = $curfontsize;
  16689. $fontname = (isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname);
  16690. $fontstyle = (isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle);
  16691. $fontsize = (isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize);
  16692. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  16693. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  16694. if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
  16695. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16696. OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
  16697. if (($key < ($maxel - 1)) AND (
  16698. ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
  16699. OR ($this->cell_height_ratio != $dom[$key]['line-height'])
  16700. OR (!$this->newline AND is_numeric($fontsize) AND is_numeric($curfontsize) AND ($fontsize >= 0) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
  16701. )) {
  16702. if ($this->page > $startlinepage) {
  16703. // fix lines splitted over two pages
  16704. if (isset($this->footerlen[$startlinepage])) {
  16705. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16706. }
  16707. // line to be moved one page forward
  16708. $pagebuff = $this->getPageBuffer($startlinepage);
  16709. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  16710. $tstart = substr($pagebuff, 0, $startlinepos);
  16711. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  16712. // remove line start from previous page
  16713. $this->setPageBuffer($startlinepage, $tstart.''.$tend);
  16714. $pagebuff = $this->getPageBuffer($this->page);
  16715. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  16716. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  16717. // add line start to current page
  16718. $yshift = ($minstartliney - $this->y);
  16719. $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k));
  16720. $this->setPageBuffer($this->page, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
  16721. // shift the annotations and links
  16722. if (isset($this->PageAnnots[$this->page])) {
  16723. $next_pask = count($this->PageAnnots[$this->page]);
  16724. } else {
  16725. $next_pask = 0;
  16726. }
  16727. if (isset($this->PageAnnots[$startlinepage])) {
  16728. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
  16729. if ($pak >= $pask) {
  16730. $this->PageAnnots[$this->page][] = $pac;
  16731. unset($this->PageAnnots[$startlinepage][$pak]);
  16732. $npak = count($this->PageAnnots[$this->page]) - 1;
  16733. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  16734. }
  16735. }
  16736. }
  16737. $pask = $next_pask;
  16738. $startlinepos = $this->cntmrk[$this->page];
  16739. $startlinepage = $this->page;
  16740. $startliney = $this->y;
  16741. }
  16742. if (!isset($dom[$key]['line-height'])) {
  16743. $dom[$key]['line-height'] = $this->cell_height_ratio;
  16744. }
  16745. if (!$dom[$key]['block']) {
  16746. 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']))) {
  16747. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  16748. }
  16749. if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
  16750. $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
  16751. 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)))) {
  16752. $minstartliney = min($this->y, $line_align_data[1]);
  16753. $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $line_align_data[2]);
  16754. } else {
  16755. $minstartliney = min($this->y, $minstartliney);
  16756. $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  16757. }
  16758. $line_align_data = $current_line_align_data;
  16759. }
  16760. }
  16761. $this->cell_height_ratio = $dom[$key]['line-height'];
  16762. $fontaligned = true;
  16763. }
  16764. $this->SetFont($fontname, $fontstyle, $fontsize);
  16765. // reset row height
  16766. $this->resetLastH();
  16767. $curfontname = $fontname;
  16768. $curfontstyle = $fontstyle;
  16769. $curfontsize = $fontsize;
  16770. $curfontascent = $fontascent;
  16771. $curfontdescent = $fontdescent;
  16772. }
  16773. }
  16774. // set text rendering mode
  16775. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  16776. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  16777. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  16778. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  16779. if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
  16780. $this->setFontStretching($dom[$key]['font-stretch']);
  16781. }
  16782. if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
  16783. $this->setFontSpacing($dom[$key]['letter-spacing']);
  16784. }
  16785. if (($plalign == 'J') AND $dom[$key]['block']) {
  16786. $plalign = '';
  16787. }
  16788. // get current position on page buffer
  16789. $curpos = $this->pagelen[$startlinepage];
  16790. if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
  16791. $this->SetFillColorArray($dom[$key]['bgcolor']);
  16792. $wfill = true;
  16793. } else {
  16794. $wfill = $fill | false;
  16795. }
  16796. if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
  16797. $this->SetTextColorArray($dom[$key]['fgcolor']);
  16798. }
  16799. if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
  16800. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  16801. }
  16802. if (isset($dom[$key]['align'])) {
  16803. $lalign = $dom[$key]['align'];
  16804. }
  16805. if (TCPDF_STATIC::empty_string($lalign)) {
  16806. $lalign = $align;
  16807. }
  16808. }
  16809. // align lines
  16810. if ($this->newline AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
  16811. $newline = true;
  16812. $fontaligned = false;
  16813. // we are at the beginning of a new line
  16814. if (isset($startlinex)) {
  16815. $yshift = ($minstartliney - $startliney);
  16816. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  16817. $yshift = 0;
  16818. }
  16819. $t_x = 0;
  16820. // the last line must be shifted to be aligned as requested
  16821. $linew = abs($this->endlinex - $startlinex);
  16822. if ($this->inxobj) {
  16823. // we are inside an XObject template
  16824. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  16825. if (isset($opentagpos)) {
  16826. $midpos = $opentagpos;
  16827. } else {
  16828. $midpos = 0;
  16829. }
  16830. if ($midpos > 0) {
  16831. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  16832. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  16833. } else {
  16834. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  16835. $pend = '';
  16836. }
  16837. } else {
  16838. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  16839. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  16840. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16841. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  16842. } elseif (isset($opentagpos)) {
  16843. $midpos = $opentagpos;
  16844. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  16845. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  16846. $midpos = $this->footerpos[$startlinepage];
  16847. } else {
  16848. $midpos = 0;
  16849. }
  16850. if ($midpos > 0) {
  16851. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  16852. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  16853. } else {
  16854. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  16855. $pend = '';
  16856. }
  16857. }
  16858. if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  16859. // calculate shifting amount
  16860. $tw = $w;
  16861. if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
  16862. $tw += $this->cell_padding['R'];
  16863. }
  16864. if ($this->lMargin != $prevlMargin) {
  16865. $tw += ($prevlMargin - $this->lMargin);
  16866. }
  16867. if ($this->rMargin != $prevrMargin) {
  16868. $tw += ($prevrMargin - $this->rMargin);
  16869. }
  16870. $one_space_width = $this->GetStringWidth(chr(32));
  16871. $no = 0; // number of spaces on a line contained on a single block
  16872. if ($this->isRTLTextDir()) { // RTL
  16873. // remove left space if exist
  16874. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  16875. if ($pos1 > 0) {
  16876. $pos1 = intval($pos1);
  16877. if ($this->isUnicodeFont()) {
  16878. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  16879. $spacelen = 2;
  16880. } else {
  16881. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  16882. $spacelen = 1;
  16883. }
  16884. if ($pos1 == $pos2) {
  16885. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  16886. if (substr($pmid, $pos1, 4) == '[()]') {
  16887. $linew -= $one_space_width;
  16888. } elseif ($pos1 == strpos($pmid, '[(')) {
  16889. $no = 1;
  16890. }
  16891. }
  16892. }
  16893. } else { // LTR
  16894. // remove right space if exist
  16895. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  16896. if ($pos1 > 0) {
  16897. $pos1 = intval($pos1);
  16898. if ($this->isUnicodeFont()) {
  16899. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  16900. $spacelen = 2;
  16901. } else {
  16902. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  16903. $spacelen = 1;
  16904. }
  16905. if ($pos1 == $pos2) {
  16906. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  16907. $linew -= $one_space_width;
  16908. }
  16909. }
  16910. }
  16911. $mdiff = ($tw - $linew);
  16912. if ($plalign == 'C') {
  16913. if ($this->rtl) {
  16914. $t_x = -($mdiff / 2);
  16915. } else {
  16916. $t_x = ($mdiff / 2);
  16917. }
  16918. } elseif ($plalign == 'R') {
  16919. // right alignment on LTR document
  16920. $t_x = $mdiff;
  16921. } elseif ($plalign == 'L') {
  16922. // left alignment on RTL document
  16923. $t_x = -$mdiff;
  16924. } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
  16925. // Justification
  16926. if ($this->isRTLTextDir()) {
  16927. // align text on the left
  16928. $t_x = -$mdiff;
  16929. }
  16930. $ns = 0; // number of spaces
  16931. $pmidtemp = $pmid;
  16932. // escape special characters
  16933. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  16934. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  16935. // search spaces
  16936. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
  16937. $spacestr = $this->getSpaceString();
  16938. $maxkk = count($lnstring[1]) - 1;
  16939. for ($kk=0; $kk <= $maxkk; ++$kk) {
  16940. // restore special characters
  16941. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  16942. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  16943. // store number of spaces on the strings
  16944. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  16945. // count total spaces on line
  16946. $ns += $lnstring[2][$kk];
  16947. $lnstring[3][$kk] = $ns;
  16948. }
  16949. if ($ns == 0) {
  16950. $ns = 1;
  16951. }
  16952. // calculate additional space to add to each existing space
  16953. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  16954. if ($this->FontSize <= 0) {
  16955. $this->FontSize = 1;
  16956. }
  16957. $spacewidthu = -1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  16958. if ($this->font_spacing != 0) {
  16959. // fixed spacing mode
  16960. $osw = -1000 * $this->font_spacing / $this->FontSize;
  16961. $spacewidthu += $osw;
  16962. }
  16963. $nsmax = $ns;
  16964. $ns = 0;
  16965. reset($lnstring);
  16966. $offset = 0;
  16967. $strcount = 0;
  16968. $prev_epsposbeg = 0;
  16969. $textpos = 0;
  16970. if ($this->isRTLTextDir()) {
  16971. $textpos = $this->wPt;
  16972. }
  16973. global $spacew;
  16974. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
  16975. // check if we are inside a string section '[( ... )]'
  16976. $stroffset = strpos($pmid, '[(', $offset);
  16977. if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
  16978. // set offset to the end of string section
  16979. $offset = strpos($pmid, ')]', $stroffset);
  16980. while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
  16981. $offset = strpos($pmid, ')]', ($offset + 1));
  16982. }
  16983. if ($offset === false) {
  16984. $this->Error('HTML Justification: malformed PDF code.');
  16985. }
  16986. continue;
  16987. }
  16988. if ($this->isRTLTextDir()) {
  16989. $spacew = ($spacewidth * ($nsmax - $ns));
  16990. } else {
  16991. $spacew = ($spacewidth * $ns);
  16992. }
  16993. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  16994. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, $offset);
  16995. $epsposend = strpos($pmid, $this->epsmarker.'Q', $offset) + strlen($this->epsmarker.'Q');
  16996. if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
  16997. OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
  16998. // shift EPS images
  16999. $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
  17000. $epsposbeg = strpos($pmid, 'q'.$this->epsmarker, ($prev_epsposbeg - 6));
  17001. $pmid_b = substr($pmid, 0, $epsposbeg);
  17002. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  17003. $pmid_e = substr($pmid, $epsposend);
  17004. $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
  17005. $offset = $epsposend;
  17006. continue;
  17007. }
  17008. $prev_epsposbeg = $epsposbeg;
  17009. $currentxpos = 0;
  17010. // shift blocks of code
  17011. switch ($strpiece[2][0]) {
  17012. case 'Td':
  17013. case 'cm':
  17014. case 'm':
  17015. case 'l': {
  17016. // get current X position
  17017. preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
  17018. if (!isset($xmatches[1])) {
  17019. break;
  17020. }
  17021. $currentxpos = $xmatches[1];
  17022. $textpos = $currentxpos;
  17023. if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
  17024. $ns = $lnstring[3][$strcount];
  17025. if ($this->isRTLTextDir()) {
  17026. $spacew = ($spacewidth * ($nsmax - $ns));
  17027. }
  17028. ++$strcount;
  17029. }
  17030. // justify block
  17031. $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
  17032. create_function('$matches', 'global $spacew;
  17033. $newx = sprintf("%F",(floatval($matches[1]) + $spacew));
  17034. return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
  17035. break;
  17036. }
  17037. case 're': {
  17038. // justify block
  17039. if (!TCPDF_STATIC::empty_string($this->lispacer)) {
  17040. $this->lispacer = '';
  17041. continue;
  17042. }
  17043. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
  17044. if (!isset($xmatches[1])) {
  17045. break;
  17046. }
  17047. $currentxpos = $xmatches[1];
  17048. global $x_diff, $w_diff;
  17049. $x_diff = 0;
  17050. $w_diff = 0;
  17051. if ($this->isRTLTextDir()) { // RTL
  17052. if ($currentxpos < $textpos) {
  17053. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  17054. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17055. } else {
  17056. if ($strcount > 0) {
  17057. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  17058. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17059. }
  17060. }
  17061. } else { // LTR
  17062. if ($currentxpos > $textpos) {
  17063. if ($strcount > 0) {
  17064. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  17065. }
  17066. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  17067. } else {
  17068. if ($strcount > 1) {
  17069. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  17070. }
  17071. if ($strcount > 0) {
  17072. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  17073. }
  17074. }
  17075. }
  17076. $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x',
  17077. create_function('$matches', 'global $x_diff, $w_diff;
  17078. $newx = sprintf("%F",(floatval($matches[1]) + $x_diff));
  17079. $neww = sprintf("%F",(floatval($matches[3]) + $w_diff));
  17080. return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
  17081. break;
  17082. }
  17083. case 'c': {
  17084. // get current X position
  17085. 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);
  17086. if (!isset($xmatches[1])) {
  17087. break;
  17088. }
  17089. $currentxpos = $xmatches[1];
  17090. // justify block
  17091. $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x',
  17092. create_function('$matches', 'global $spacew;
  17093. $newx1 = sprintf("%F",(floatval($matches[1]) + $spacew));
  17094. $newx2 = sprintf("%F",(floatval($matches[3]) + $spacew));
  17095. $newx3 = sprintf("%F",(floatval($matches[5]) + $spacew));
  17096. return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
  17097. break;
  17098. }
  17099. }
  17100. // shift the annotations and links
  17101. $cxpos = ($currentxpos / $this->k);
  17102. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  17103. if ($this->inxobj) {
  17104. // we are inside an XObject template
  17105. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17106. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17107. if ($cxpos > $lmpos) {
  17108. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  17109. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17110. } else {
  17111. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17112. }
  17113. break;
  17114. }
  17115. }
  17116. } elseif (isset($this->PageAnnots[$this->page])) {
  17117. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17118. if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac['x'] * $this->k) <= ($currentxpos + $this->feps))) {
  17119. if ($cxpos > $lmpos) {
  17120. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  17121. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17122. } else {
  17123. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  17124. }
  17125. break;
  17126. }
  17127. }
  17128. }
  17129. } // end of while
  17130. // remove markers
  17131. $pmid = str_replace('x*#!#*x', '', $pmid);
  17132. if ($this->isUnicodeFont()) {
  17133. // multibyte characters
  17134. $spacew = $spacewidthu;
  17135. if ($this->font_stretching != 100) {
  17136. // word spacing is affected by stretching
  17137. $spacew /= ($this->font_stretching / 100);
  17138. }
  17139. $pmidtemp = $pmid;
  17140. // escape special characters
  17141. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  17142. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  17143. $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x",
  17144. create_function('$matches', 'global $spacew;
  17145. $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  17146. $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  17147. return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%F", $spacew)." (", $matches[1]).")]";'), $pmidtemp);
  17148. if ($this->inxobj) {
  17149. // we are inside an XObject template
  17150. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\n".$pend;
  17151. } else {
  17152. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
  17153. }
  17154. $endlinepos = strlen($pstart."\n".$pmid."\n");
  17155. } else {
  17156. // non-unicode (single-byte characters)
  17157. if ($this->font_stretching != 100) {
  17158. // word spacing (Tw) is affected by stretching
  17159. $spacewidth /= ($this->font_stretching / 100);
  17160. }
  17161. $rs = sprintf('%F Tw', $spacewidth);
  17162. $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
  17163. if ($this->inxobj) {
  17164. // we are inside an XObject template
  17165. $this->xobjects[$this->xobjid]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
  17166. } else {
  17167. $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
  17168. }
  17169. $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
  17170. }
  17171. }
  17172. } // end of J
  17173. } // end if $startlinex
  17174. if (($t_x != 0) OR ($yshift < 0)) {
  17175. // shift the line
  17176. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17177. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17178. $endlinepos = strlen($pstart);
  17179. if ($this->inxobj) {
  17180. // we are inside an XObject template
  17181. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17182. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17183. if ($pak >= $pask) {
  17184. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17185. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17186. }
  17187. }
  17188. } else {
  17189. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17190. // shift the annotations and links
  17191. if (isset($this->PageAnnots[$this->page])) {
  17192. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17193. if ($pak >= $pask) {
  17194. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17195. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17196. }
  17197. }
  17198. }
  17199. }
  17200. $this->y -= $yshift;
  17201. }
  17202. }
  17203. $pbrk = $this->checkPageBreak($this->lasth);
  17204. $this->newline = false;
  17205. $startlinex = $this->x;
  17206. $startliney = $this->y;
  17207. if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
  17208. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  17209. } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
  17210. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  17211. } else {
  17212. $minstartliney = $startliney;
  17213. $maxbottomliney = ($this->y + (($fontsize * $this->cell_height_ratio) / $this->k));
  17214. }
  17215. $startlinepage = $this->page;
  17216. if (isset($endlinepos) AND (!$pbrk)) {
  17217. $startlinepos = $endlinepos;
  17218. } else {
  17219. if ($this->inxobj) {
  17220. // we are inside an XObject template
  17221. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17222. } elseif (!$this->InFooter) {
  17223. if (isset($this->footerlen[$this->page])) {
  17224. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17225. } else {
  17226. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17227. }
  17228. $startlinepos = $this->footerpos[$this->page];
  17229. } else {
  17230. $startlinepos = $this->pagelen[$this->page];
  17231. }
  17232. }
  17233. unset($endlinepos);
  17234. $plalign = $lalign;
  17235. if (isset($this->PageAnnots[$this->page])) {
  17236. $pask = count($this->PageAnnots[$this->page]);
  17237. } else {
  17238. $pask = 0;
  17239. }
  17240. if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
  17241. AND (isset($this->emptypagemrk[$this->page]))
  17242. AND ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page]))) {
  17243. $this->SetFont($fontname, $fontstyle, $fontsize);
  17244. if ($wfill) {
  17245. $this->SetFillColorArray($this->bgcolor);
  17246. }
  17247. }
  17248. } // end newline
  17249. if (isset($opentagpos)) {
  17250. unset($opentagpos);
  17251. }
  17252. if ($dom[$key]['tag']) {
  17253. if ($dom[$key]['opening']) {
  17254. // get text indentation (if any)
  17255. if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
  17256. $this->textindent = $dom[$key]['text-indent'];
  17257. $this->newline = true;
  17258. }
  17259. // table
  17260. if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
  17261. // available page width
  17262. if ($this->rtl) {
  17263. $wtmp = $this->x - $this->lMargin;
  17264. } else {
  17265. $wtmp = $this->w - $this->rMargin - $this->x;
  17266. }
  17267. // get cell spacing
  17268. if (isset($dom[$key]['attribute']['cellspacing'])) {
  17269. $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  17270. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  17271. } elseif (isset($dom[$key]['border-spacing'])) {
  17272. $cellspacing = $dom[$key]['border-spacing'];
  17273. } else {
  17274. $cellspacing = array('H' => 0, 'V' => 0);
  17275. }
  17276. // table width
  17277. if (isset($dom[$key]['width'])) {
  17278. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  17279. } else {
  17280. $table_width = $wtmp;
  17281. }
  17282. $table_width -= (2 * $cellspacing['H']);
  17283. if (!$this->inthead) {
  17284. $this->y += $cellspacing['V'];
  17285. }
  17286. if ($this->rtl) {
  17287. $cellspacingx = -$cellspacing['H'];
  17288. } else {
  17289. $cellspacingx = $cellspacing['H'];
  17290. }
  17291. // total table width without cellspaces
  17292. $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
  17293. // minimum column width
  17294. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  17295. // array of custom column widths
  17296. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  17297. }
  17298. // table row
  17299. if ($dom[$key]['value'] == 'tr') {
  17300. // reset column counter
  17301. $colid = 0;
  17302. }
  17303. // table cell
  17304. if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
  17305. $trid = $dom[$key]['parent'];
  17306. $table_el = $dom[$trid]['parent'];
  17307. if (!isset($dom[$table_el]['cols'])) {
  17308. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  17309. }
  17310. // store border info
  17311. $tdborder = 0;
  17312. if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
  17313. $tdborder = $dom[$key]['border'];
  17314. }
  17315. $colspan = intval($dom[$key]['attribute']['colspan']);
  17316. if ($colspan <= 0) {
  17317. $colspan = 1;
  17318. }
  17319. $old_cell_padding = $this->cell_padding;
  17320. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
  17321. $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  17322. $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
  17323. } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
  17324. $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
  17325. } else {
  17326. $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
  17327. }
  17328. $this->cell_padding = $current_cell_padding;
  17329. if (isset($dom[$key]['height'])) {
  17330. // minimum cell height
  17331. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  17332. } else {
  17333. $cellh = 0;
  17334. }
  17335. if (isset($dom[$key]['content'])) {
  17336. $cell_content = stripslashes($dom[$key]['content']);
  17337. } else {
  17338. $cell_content = '&nbsp;';
  17339. }
  17340. $tagtype = $dom[$key]['value'];
  17341. $parentid = $key;
  17342. while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
  17343. // move $key index forward
  17344. ++$key;
  17345. }
  17346. if (!isset($dom[$trid]['startpage'])) {
  17347. $dom[$trid]['startpage'] = $this->page;
  17348. } else {
  17349. $this->setPage($dom[$trid]['startpage']);
  17350. }
  17351. if (!isset($dom[$trid]['startcolumn'])) {
  17352. $dom[$trid]['startcolumn'] = $this->current_column;
  17353. } elseif ($this->current_column != $dom[$trid]['startcolumn']) {
  17354. $tmpx = $this->x;
  17355. $this->selectColumn($dom[$trid]['startcolumn']);
  17356. $this->x = $tmpx;
  17357. }
  17358. if (!isset($dom[$trid]['starty'])) {
  17359. $dom[$trid]['starty'] = $this->y;
  17360. } else {
  17361. $this->y = $dom[$trid]['starty'];
  17362. }
  17363. if (!isset($dom[$trid]['startx'])) {
  17364. $dom[$trid]['startx'] = $this->x;
  17365. $this->x += $cellspacingx;
  17366. } else {
  17367. $this->x += ($cellspacingx / 2);
  17368. }
  17369. if (isset($dom[$parentid]['attribute']['rowspan'])) {
  17370. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  17371. } else {
  17372. $rowspan = 1;
  17373. }
  17374. // skip row-spanned cells started on the previous rows
  17375. if (isset($dom[$table_el]['rowspans'])) {
  17376. $rsk = 0;
  17377. $rskmax = count($dom[$table_el]['rowspans']);
  17378. while ($rsk < $rskmax) {
  17379. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  17380. $rsstartx = $trwsp['startx'];
  17381. $rsendx = $trwsp['endx'];
  17382. // account for margin changes
  17383. if ($trwsp['startpage'] < $this->page) {
  17384. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm'])) {
  17385. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  17386. $rsstartx -= $dl;
  17387. $rsendx -= $dl;
  17388. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm'])) {
  17389. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  17390. $rsstartx += $dl;
  17391. $rsendx += $dl;
  17392. }
  17393. }
  17394. if (($trwsp['rowspan'] > 0)
  17395. AND ($rsstartx > ($this->x - $cellspacing['H'] - $current_cell_padding['L'] - $this->feps))
  17396. AND ($rsstartx < ($this->x + $cellspacing['H'] + $current_cell_padding['R'] + $this->feps))
  17397. AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page) OR ($trwsp['startcolumn'] < $this->current_column))) {
  17398. // set the starting X position of the current cell
  17399. $this->x = $rsendx + $cellspacingx;
  17400. // increment column indicator
  17401. $colid += $trwsp['colspan'];
  17402. if (($trwsp['rowspan'] == 1)
  17403. AND (isset($dom[$trid]['endy']))
  17404. AND (isset($dom[$trid]['endpage']))
  17405. AND (isset($dom[$trid]['endcolumn']))
  17406. AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
  17407. AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17408. // set ending Y position for row
  17409. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17410. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  17411. }
  17412. $rsk = 0;
  17413. } else {
  17414. ++$rsk;
  17415. }
  17416. }
  17417. }
  17418. if (isset($dom[$parentid]['width'])) {
  17419. // user specified width
  17420. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  17421. $tmpcw = ($cellw / $colspan);
  17422. for ($i = 0; $i < $colspan; ++$i) {
  17423. $table_colwidths[($colid + $i)] = $tmpcw;
  17424. }
  17425. } else {
  17426. // inherit column width
  17427. $cellw = 0;
  17428. for ($i = 0; $i < $colspan; ++$i) {
  17429. $cellw += $table_colwidths[($colid + $i)];
  17430. }
  17431. }
  17432. $cellw += (($colspan - 1) * $cellspacing['H']);
  17433. // increment column indicator
  17434. $colid += $colspan;
  17435. // add rowspan information to table element
  17436. if ($rowspan > 1) {
  17437. $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));
  17438. }
  17439. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  17440. if ($rowspan > 1) {
  17441. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  17442. }
  17443. // push background colors
  17444. if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
  17445. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  17446. }
  17447. // store border info
  17448. if (isset($tdborder) AND !empty($tdborder)) {
  17449. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  17450. }
  17451. $prevLastH = $this->lasth;
  17452. // store some info for multicolumn mode
  17453. if ($this->rtl) {
  17454. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  17455. } else {
  17456. $this->colxshift['x'] = $this->x - $this->lMargin;
  17457. }
  17458. $this->colxshift['s'] = $cellspacing;
  17459. $this->colxshift['p'] = $current_cell_padding;
  17460. // ****** write the cell content ******
  17461. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
  17462. // restore some values
  17463. $this->colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  17464. $this->lasth = $prevLastH;
  17465. $this->cell_padding = $old_cell_padding;
  17466. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  17467. // update the end of row position
  17468. if ($rowspan <= 1) {
  17469. if (isset($dom[$trid]['endy'])) {
  17470. if (($this->page == $dom[$trid]['endpage']) AND ($this->current_column == $dom[$trid]['endcolumn'])) {
  17471. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  17472. } elseif (($this->page > $dom[$trid]['endpage']) OR ($this->current_column > $dom[$trid]['endcolumn'])) {
  17473. $dom[$trid]['endy'] = $this->y;
  17474. }
  17475. } else {
  17476. $dom[$trid]['endy'] = $this->y;
  17477. }
  17478. if (isset($dom[$trid]['endpage'])) {
  17479. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  17480. } else {
  17481. $dom[$trid]['endpage'] = $this->page;
  17482. }
  17483. if (isset($dom[$trid]['endcolumn'])) {
  17484. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  17485. } else {
  17486. $dom[$trid]['endcolumn'] = $this->current_column;
  17487. }
  17488. } else {
  17489. // account for row-spanned cells
  17490. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  17491. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  17492. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  17493. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  17494. }
  17495. if (isset($dom[$table_el]['rowspans'])) {
  17496. // update endy and endpage on rowspanned cells
  17497. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  17498. if ($trwsp['rowspan'] > 0) {
  17499. if (isset($dom[$trid]['endpage'])) {
  17500. if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
  17501. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  17502. } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
  17503. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  17504. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  17505. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  17506. } else {
  17507. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  17508. }
  17509. }
  17510. }
  17511. }
  17512. }
  17513. $this->x += ($cellspacingx / 2);
  17514. } else {
  17515. // opening tag (or self-closing tag)
  17516. if (!isset($opentagpos)) {
  17517. if ($this->inxobj) {
  17518. // we are inside an XObject template
  17519. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  17520. } elseif (!$this->InFooter) {
  17521. if (isset($this->footerlen[$this->page])) {
  17522. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  17523. } else {
  17524. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  17525. }
  17526. $opentagpos = $this->footerpos[$this->page];
  17527. }
  17528. }
  17529. $dom = $this->openHTMLTagHandler($dom, $key, $cell);
  17530. }
  17531. } else { // closing tag
  17532. $prev_numpages = $this->numpages;
  17533. $old_bordermrk = $this->bordermrk[$this->page];
  17534. $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  17535. if ($this->bordermrk[$this->page] > $old_bordermrk) {
  17536. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  17537. }
  17538. if ($prev_numpages > $this->numpages) {
  17539. $startlinepage = $this->page;
  17540. }
  17541. }
  17542. } elseif (strlen($dom[$key]['value']) > 0) {
  17543. // print list-item
  17544. if (!TCPDF_STATIC::empty_string($this->lispacer) AND ($this->lispacer != '^')) {
  17545. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  17546. $this->resetLastH();
  17547. $minstartliney = $this->y;
  17548. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  17549. if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
  17550. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  17551. }
  17552. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  17553. $this->resetLastH();
  17554. if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
  17555. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  17556. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  17557. $this->y += ((($pfontsize - $curfontsize) * $this->cell_height_ratio / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  17558. $minstartliney = min($this->y, $minstartliney);
  17559. $maxbottomliney = max(($this->y + (($pfontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  17560. }
  17561. }
  17562. // text
  17563. $this->htmlvspace = 0;
  17564. if ((!$this->premode) AND $this->isRTLTextDir()) {
  17565. // reverse spaces order
  17566. $lsp = ''; // left spaces
  17567. $rsp = ''; // right spaces
  17568. if (preg_match('/^('.$this->re_space['p'].'+)/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17569. $lsp = $matches[1];
  17570. }
  17571. if (preg_match('/('.$this->re_space['p'].'+)$/'.$this->re_space['m'], $dom[$key]['value'], $matches)) {
  17572. $rsp = $matches[1];
  17573. }
  17574. $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
  17575. }
  17576. if ($newline) {
  17577. if (!$this->premode) {
  17578. $prelen = strlen($dom[$key]['value']);
  17579. if ($this->isRTLTextDir()) {
  17580. // right trim except non-breaking space
  17581. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  17582. } else {
  17583. // left trim except non-breaking space
  17584. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  17585. }
  17586. $postlen = strlen($dom[$key]['value']);
  17587. if (($postlen == 0) AND ($prelen > 0)) {
  17588. $dom[$key]['trimmed_space'] = true;
  17589. }
  17590. }
  17591. $newline = false;
  17592. $firstblock = true;
  17593. } else {
  17594. $firstblock = false;
  17595. // replace empty multiple spaces string with a single space
  17596. $dom[$key]['value'] = preg_replace('/^'.$this->re_space['p'].'+$/'.$this->re_space['m'], chr(32), $dom[$key]['value']);
  17597. }
  17598. $strrest = '';
  17599. if ($this->rtl) {
  17600. $this->x -= $this->textindent;
  17601. } else {
  17602. $this->x += $this->textindent;
  17603. }
  17604. if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
  17605. $strlinelen = $this->GetStringWidth($dom[$key]['value']);
  17606. if (!empty($this->HREF) AND (isset($this->HREF['url']))) {
  17607. // HTML <a> Link
  17608. $hrefcolor = '';
  17609. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
  17610. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  17611. }
  17612. $hrefstyle = -1;
  17613. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
  17614. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  17615. }
  17616. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  17617. } else {
  17618. $wadj = 0; // space to leave for block continuity
  17619. if ($this->rtl) {
  17620. $cwa = ($this->x - $this->lMargin);
  17621. } else {
  17622. $cwa = ($this->w - $this->rMargin - $this->x);
  17623. }
  17624. if (($strlinelen < $cwa) AND (isset($dom[($key + 1)])) AND ($dom[($key + 1)]['tag']) AND (!$dom[($key + 1)]['block'])) {
  17625. // check the next text blocks for continuity
  17626. $nkey = ($key + 1);
  17627. $write_block = true;
  17628. $same_textdir = true;
  17629. $tmp_fontname = $this->FontFamily;
  17630. $tmp_fontstyle = $this->FontStyle;
  17631. $tmp_fontsize = $this->FontSizePt;
  17632. while ($write_block AND isset($dom[$nkey])) {
  17633. if ($dom[$nkey]['tag']) {
  17634. if ($dom[$nkey]['block']) {
  17635. // end of block
  17636. $write_block = false;
  17637. }
  17638. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  17639. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  17640. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  17641. $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
  17642. } else {
  17643. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'+/', $this->re_space['m'], $dom[$nkey]['value']);
  17644. if (isset($nextstr[0]) AND $same_textdir) {
  17645. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  17646. if (isset($nextstr[1])) {
  17647. $write_block = false;
  17648. }
  17649. }
  17650. }
  17651. ++$nkey;
  17652. }
  17653. }
  17654. if (($wadj > 0) AND (($strlinelen + $wadj) >= $cwa)) {
  17655. $wadj = 0;
  17656. $nextstr = TCPDF_STATIC::pregSplit('/'.$this->re_space['p'].'/', $this->re_space['m'], $dom[$key]['value']);
  17657. $numblks = count($nextstr);
  17658. if ($numblks > 1) {
  17659. // try to split on blank spaces
  17660. $wadj = ($cwa - $strlinelen + $this->GetStringWidth($nextstr[($numblks - 1)]));
  17661. } else {
  17662. // set the entire block on new line
  17663. $wadj = $this->GetStringWidth($nextstr[0]);
  17664. }
  17665. }
  17666. // check for reversed text direction
  17667. if (($wadj > 0) AND (($this->rtl AND ($this->tmprtl === 'L')) OR (!$this->rtl AND ($this->tmprtl === 'R')))) {
  17668. // LTR text on RTL direction or RTL text on LTR direction
  17669. $reverse_dir = true;
  17670. $this->rtl = !$this->rtl;
  17671. $revshift = ($strlinelen + $wadj + 0.000001); // add little quantity for rounding problems
  17672. if ($this->rtl) {
  17673. $this->x += $revshift;
  17674. } else {
  17675. $this->x -= $revshift;
  17676. }
  17677. $xws = $this->x;
  17678. }
  17679. // ****** write only until the end of the line and get the rest ******
  17680. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  17681. // restore default direction
  17682. if ($reverse_dir AND ($wadj == 0)) {
  17683. $this->x = $xws;
  17684. $this->rtl = !$this->rtl;
  17685. $reverse_dir = false;
  17686. }
  17687. }
  17688. }
  17689. $this->textindent = 0;
  17690. if (strlen($strrest) > 0) {
  17691. // store the remaining string on the previous $key position
  17692. $this->newline = true;
  17693. if ($strrest == $dom[$key]['value']) {
  17694. // used to avoid infinite loop
  17695. ++$loop;
  17696. } else {
  17697. $loop = 0;
  17698. }
  17699. $dom[$key]['value'] = $strrest;
  17700. if ($cell) {
  17701. if ($this->rtl) {
  17702. $this->x -= $this->cell_padding['R'];
  17703. } else {
  17704. $this->x += $this->cell_padding['L'];
  17705. }
  17706. }
  17707. if ($loop < 3) {
  17708. --$key;
  17709. }
  17710. } else {
  17711. $loop = 0;
  17712. // add the positive font spacing of the last character (if any)
  17713. if ($this->font_spacing > 0) {
  17714. if ($this->rtl) {
  17715. $this->x -= $this->font_spacing;
  17716. } else {
  17717. $this->x += $this->font_spacing;
  17718. }
  17719. }
  17720. }
  17721. }
  17722. ++$key;
  17723. 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')) {
  17724. // check if we are on a new page or on a new column
  17725. if ((!$undo) AND (($this->y < $this->start_transaction_y) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y)))) {
  17726. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  17727. // restore previous object
  17728. $this->rollbackTransaction(true);
  17729. // restore previous values
  17730. foreach ($this_method_vars as $vkey => $vval) {
  17731. $$vkey = $vval;
  17732. }
  17733. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17734. $pre_y = $this->y;
  17735. if ((!$this->checkPageBreak($this->PageBreakTrigger + 1)) AND ($this->y < $pre_y)) {
  17736. $startliney = $this->y;
  17737. }
  17738. $undo = true; // avoid infinite loop
  17739. } else {
  17740. $undo = false;
  17741. }
  17742. }
  17743. } // end for each $key
  17744. // align the last line
  17745. if (isset($startlinex)) {
  17746. $yshift = ($minstartliney - $startliney);
  17747. if (($yshift > 0) OR ($this->page > $startlinepage)) {
  17748. $yshift = 0;
  17749. }
  17750. $t_x = 0;
  17751. // the last line must be shifted to be aligned as requested
  17752. $linew = abs($this->endlinex - $startlinex);
  17753. if ($this->inxobj) {
  17754. // we are inside an XObject template
  17755. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  17756. if (isset($opentagpos)) {
  17757. $midpos = $opentagpos;
  17758. } else {
  17759. $midpos = 0;
  17760. }
  17761. if ($midpos > 0) {
  17762. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  17763. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  17764. } else {
  17765. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  17766. $pend = '';
  17767. }
  17768. } else {
  17769. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  17770. if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17771. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17772. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  17773. } elseif (isset($opentagpos)) {
  17774. $midpos = $opentagpos;
  17775. } elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
  17776. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  17777. $midpos = $this->footerpos[$startlinepage];
  17778. } else {
  17779. $midpos = 0;
  17780. }
  17781. if ($midpos > 0) {
  17782. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  17783. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  17784. } else {
  17785. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  17786. $pend = '';
  17787. }
  17788. }
  17789. if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
  17790. // calculate shifting amount
  17791. $tw = $w;
  17792. if ($this->lMargin != $prevlMargin) {
  17793. $tw += ($prevlMargin - $this->lMargin);
  17794. }
  17795. if ($this->rMargin != $prevrMargin) {
  17796. $tw += ($prevrMargin - $this->rMargin);
  17797. }
  17798. $one_space_width = $this->GetStringWidth(chr(32));
  17799. $no = 0; // number of spaces on a line contained on a single block
  17800. if ($this->isRTLTextDir()) { // RTL
  17801. // remove left space if exist
  17802. $pos1 = TCPDF_STATIC::revstrpos($pmid, '[(');
  17803. if ($pos1 > 0) {
  17804. $pos1 = intval($pos1);
  17805. if ($this->isUnicodeFont()) {
  17806. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(0).chr(32)));
  17807. $spacelen = 2;
  17808. } else {
  17809. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, '[('.chr(32)));
  17810. $spacelen = 1;
  17811. }
  17812. if ($pos1 == $pos2) {
  17813. $pmid = substr($pmid, 0, ($pos1 + 2)).substr($pmid, ($pos1 + 2 + $spacelen));
  17814. if (substr($pmid, $pos1, 4) == '[()]') {
  17815. $linew -= $one_space_width;
  17816. } elseif ($pos1 == strpos($pmid, '[(')) {
  17817. $no = 1;
  17818. }
  17819. }
  17820. }
  17821. } else { // LTR
  17822. // remove right space if exist
  17823. $pos1 = TCPDF_STATIC::revstrpos($pmid, ')]');
  17824. if ($pos1 > 0) {
  17825. $pos1 = intval($pos1);
  17826. if ($this->isUnicodeFont()) {
  17827. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(0).chr(32).')]')) + 2;
  17828. $spacelen = 2;
  17829. } else {
  17830. $pos2 = intval(TCPDF_STATIC::revstrpos($pmid, chr(32).')]')) + 1;
  17831. $spacelen = 1;
  17832. }
  17833. if ($pos1 == $pos2) {
  17834. $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
  17835. $linew -= $one_space_width;
  17836. }
  17837. }
  17838. }
  17839. $mdiff = ($tw - $linew);
  17840. if ($plalign == 'C') {
  17841. if ($this->rtl) {
  17842. $t_x = -($mdiff / 2);
  17843. } else {
  17844. $t_x = ($mdiff / 2);
  17845. }
  17846. } elseif ($plalign == 'R') {
  17847. // right alignment on LTR document
  17848. $t_x = $mdiff;
  17849. } elseif ($plalign == 'L') {
  17850. // left alignment on RTL document
  17851. $t_x = -$mdiff;
  17852. }
  17853. } // end if startlinex
  17854. if (($t_x != 0) OR ($yshift < 0)) {
  17855. // shift the line
  17856. $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k), ($yshift * $this->k));
  17857. $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
  17858. $endlinepos = strlen($pstart);
  17859. if ($this->inxobj) {
  17860. // we are inside an XObject template
  17861. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$pend;
  17862. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac) {
  17863. if ($pak >= $pask) {
  17864. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  17865. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  17866. }
  17867. }
  17868. } else {
  17869. $this->setPageBuffer($startlinepage, $pstart.$pend);
  17870. // shift the annotations and links
  17871. if (isset($this->PageAnnots[$this->page])) {
  17872. foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
  17873. if ($pak >= $pask) {
  17874. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  17875. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  17876. }
  17877. }
  17878. }
  17879. }
  17880. $this->y -= $yshift;
  17881. $yshift = 0;
  17882. }
  17883. }
  17884. // restore previous values
  17885. $this->setGraphicVars($gvars);
  17886. if ($this->num_columns > 1) {
  17887. $this->selectColumn();
  17888. } elseif ($this->page > $prevPage) {
  17889. $this->lMargin = $this->pagedim[$this->page]['olm'];
  17890. $this->rMargin = $this->pagedim[$this->page]['orm'];
  17891. }
  17892. // restore previous list state
  17893. $this->cell_height_ratio = $prev_cell_height_ratio;
  17894. $this->listnum = $prev_listnum;
  17895. $this->listordered = $prev_listordered;
  17896. $this->listcount = $prev_listcount;
  17897. $this->lispacer = $prev_lispacer;
  17898. if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
  17899. $this->Ln($this->lasth);
  17900. if ($this->y < $maxbottomliney) {
  17901. $this->y = $maxbottomliney;
  17902. }
  17903. }
  17904. unset($dom);
  17905. }
  17906. /**
  17907. * Process opening tags.
  17908. * @param $dom (array) html dom array
  17909. * @param $key (int) current element id
  17910. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  17911. * @return $dom array
  17912. * @protected
  17913. */
  17914. protected function openHTMLTagHandler($dom, $key, $cell) {
  17915. $tag = $dom[$key];
  17916. $parent = $dom[($dom[$key]['parent'])];
  17917. $firsttag = ($key == 1);
  17918. // check for text direction attribute
  17919. if (isset($tag['dir'])) {
  17920. $this->setTempRTL($tag['dir']);
  17921. } else {
  17922. $this->tmprtl = false;
  17923. }
  17924. if ($tag['block']) {
  17925. $hbz = 0; // distance from y to line bottom
  17926. $hb = 0; // vertical space between block tags
  17927. // calculate vertical space for block tags
  17928. if (isset($this->tagvspaces[$tag['value']][0]['h']) AND ($this->tagvspaces[$tag['value']][0]['h'] >= 0)) {
  17929. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  17930. } elseif (isset($tag['fontsize'])) {
  17931. $cur_h = ($tag['fontsize'] / $this->k) * $this->cell_height_ratio;
  17932. } else {
  17933. $cur_h = $this->FontSize * $this->cell_height_ratio;
  17934. }
  17935. if (isset($this->tagvspaces[$tag['value']][0]['n'])) {
  17936. $n = $this->tagvspaces[$tag['value']][0]['n'];
  17937. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  17938. $n = 0.6;
  17939. } else {
  17940. $n = 1;
  17941. }
  17942. if ((!isset($this->tagvspaces[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br')))) {
  17943. $hb = 0;
  17944. } else {
  17945. $hb = ($n * $cur_h);
  17946. }
  17947. if (($this->htmlvspace <= 0) AND ($n > 0)) {
  17948. if (isset($parent['fontsize'])) {
  17949. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  17950. } else {
  17951. $hbz = $this->FontSize * $this->cell_height_ratio;
  17952. }
  17953. }
  17954. if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
  17955. // fix vertical space after table
  17956. $hbz = 0;
  17957. }
  17958. }
  17959. // Opening tag
  17960. switch($tag['value']) {
  17961. case 'table': {
  17962. $cp = 0;
  17963. $cs = 0;
  17964. $dom[$key]['rowspans'] = array();
  17965. if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
  17966. $this->htmlvspace = 0;
  17967. // set table header
  17968. if (!TCPDF_STATIC::empty_string($dom[$key]['thead'])) {
  17969. // set table header
  17970. $this->thead = $dom[$key]['thead'];
  17971. if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
  17972. $this->theadMargins = array();
  17973. $this->theadMargins['cell_padding'] = $this->cell_padding;
  17974. $this->theadMargins['lmargin'] = $this->lMargin;
  17975. $this->theadMargins['rmargin'] = $this->rMargin;
  17976. $this->theadMargins['page'] = $this->page;
  17977. $this->theadMargins['cell'] = $cell;
  17978. }
  17979. }
  17980. }
  17981. // store current margins and page
  17982. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  17983. if (isset($tag['attribute']['cellpadding'])) {
  17984. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  17985. $this->SetCellPadding($pad);
  17986. } elseif (isset($tag['padding'])) {
  17987. $this->cell_padding = $tag['padding'];
  17988. }
  17989. if (isset($tag['attribute']['cellspacing'])) {
  17990. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  17991. } elseif (isset($tag['border-spacing'])) {
  17992. $cs = $tag['border-spacing']['V'];
  17993. }
  17994. $prev_y = $this->y;
  17995. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) OR ($this->y < $prev_y)) {
  17996. $this->inthead = true;
  17997. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  17998. $this->checkPageBreak($this->PageBreakTrigger + 1);
  17999. }
  18000. break;
  18001. }
  18002. case 'tr': {
  18003. // array of columns positions
  18004. $dom[$key]['cellpos'] = array();
  18005. break;
  18006. }
  18007. case 'hr': {
  18008. if ((isset($tag['height'])) AND ($tag['height'] != '')) {
  18009. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  18010. } else {
  18011. $hrHeight = $this->GetLineWidth();
  18012. }
  18013. $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
  18014. $x = $this->GetX();
  18015. $y = $this->GetY();
  18016. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  18017. if ($cell) {
  18018. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  18019. }
  18020. if ((isset($tag['width'])) AND ($tag['width'] != '')) {
  18021. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  18022. } else {
  18023. $hrWidth = $wtmp;
  18024. }
  18025. $prevlinewidth = $this->GetLineWidth();
  18026. $this->SetLineWidth($hrHeight);
  18027. $this->Line($x, $y, $x + $hrWidth, $y);
  18028. $this->SetLineWidth($prevlinewidth);
  18029. $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key + 1)]));
  18030. break;
  18031. }
  18032. case 'a': {
  18033. if (array_key_exists('href', $tag['attribute'])) {
  18034. $this->HREF['url'] = $tag['attribute']['href'];
  18035. }
  18036. break;
  18037. }
  18038. case 'img': {
  18039. if (isset($tag['attribute']['src'])) {
  18040. if ($tag['attribute']['src']{0} === '@') {
  18041. // data stream
  18042. $tag['attribute']['src'] = '@'.base64_decode(substr($tag['attribute']['src'], 1));
  18043. $type = '';
  18044. } else {
  18045. // get image type
  18046. $type = TCPDF_IMAGES::getImageFileType($tag['attribute']['src']);
  18047. }
  18048. if (!isset($tag['width'])) {
  18049. $tag['width'] = 0;
  18050. }
  18051. if (!isset($tag['height'])) {
  18052. $tag['height'] = 0;
  18053. }
  18054. //if (!isset($tag['attribute']['align'])) {
  18055. // the only alignment supported is "bottom"
  18056. // further development is required for other modes.
  18057. $tag['attribute']['align'] = 'bottom';
  18058. //}
  18059. switch($tag['attribute']['align']) {
  18060. case 'top': {
  18061. $align = 'T';
  18062. break;
  18063. }
  18064. case 'middle': {
  18065. $align = 'M';
  18066. break;
  18067. }
  18068. case 'bottom': {
  18069. $align = 'B';
  18070. break;
  18071. }
  18072. default: {
  18073. $align = 'B';
  18074. break;
  18075. }
  18076. }
  18077. $prevy = $this->y;
  18078. $xpos = $this->x;
  18079. $imglink = '';
  18080. if (isset($this->HREF['url']) AND !TCPDF_STATIC::empty_string($this->HREF['url'])) {
  18081. $imglink = $this->HREF['url'];
  18082. if ($imglink{0} == '#') {
  18083. // convert url to internal link
  18084. $lnkdata = explode(',', $imglink);
  18085. if (isset($lnkdata[0])) {
  18086. $page = intval(substr($lnkdata[0], 1));
  18087. if (empty($page) OR ($page <= 0)) {
  18088. $page = $this->page;
  18089. }
  18090. if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
  18091. $lnky = floatval($lnkdata[1]);
  18092. } else {
  18093. $lnky = 0;
  18094. }
  18095. $imglink = $this->AddLink();
  18096. $this->SetLink($imglink, $lnky, $page);
  18097. }
  18098. }
  18099. }
  18100. $border = 0;
  18101. if (isset($tag['border']) AND !empty($tag['border'])) {
  18102. // currently only support 1 (frame) or a combination of 'LTRB'
  18103. $border = $tag['border'];
  18104. }
  18105. $iw = '';
  18106. if (isset($tag['width'])) {
  18107. $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
  18108. }
  18109. $ih = '';
  18110. if (isset($tag['height'])) {
  18111. $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
  18112. }
  18113. if (($type == 'eps') OR ($type == 'ai')) {
  18114. $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  18115. } elseif ($type == 'svg') {
  18116. $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  18117. } else {
  18118. $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  18119. }
  18120. switch($align) {
  18121. case 'T': {
  18122. $this->y = $prevy;
  18123. break;
  18124. }
  18125. case 'M': {
  18126. $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2) ;
  18127. break;
  18128. }
  18129. case 'B': {
  18130. $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k);
  18131. break;
  18132. }
  18133. }
  18134. }
  18135. break;
  18136. }
  18137. case 'dl': {
  18138. ++$this->listnum;
  18139. if ($this->listnum == 1) {
  18140. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18141. } else {
  18142. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18143. }
  18144. break;
  18145. }
  18146. case 'dt': {
  18147. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18148. break;
  18149. }
  18150. case 'dd': {
  18151. if ($this->rtl) {
  18152. $this->rMargin += $this->listindent;
  18153. } else {
  18154. $this->lMargin += $this->listindent;
  18155. }
  18156. ++$this->listindentlevel;
  18157. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18158. break;
  18159. }
  18160. case 'ul':
  18161. case 'ol': {
  18162. ++$this->listnum;
  18163. if ($tag['value'] == 'ol') {
  18164. $this->listordered[$this->listnum] = true;
  18165. } else {
  18166. $this->listordered[$this->listnum] = false;
  18167. }
  18168. if (isset($tag['attribute']['start'])) {
  18169. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  18170. } else {
  18171. $this->listcount[$this->listnum] = 0;
  18172. }
  18173. if ($this->rtl) {
  18174. $this->rMargin += $this->listindent;
  18175. $this->x -= $this->listindent;
  18176. } else {
  18177. $this->lMargin += $this->listindent;
  18178. $this->x += $this->listindent;
  18179. }
  18180. ++$this->listindentlevel;
  18181. if ($this->listnum == 1) {
  18182. if ($key > 1) {
  18183. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18184. }
  18185. } else {
  18186. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  18187. }
  18188. break;
  18189. }
  18190. case 'li': {
  18191. if ($key > 2) {
  18192. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18193. }
  18194. if ($this->listordered[$this->listnum]) {
  18195. // ordered item
  18196. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18197. $this->lispacer = $parent['attribute']['type'];
  18198. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18199. $this->lispacer = $parent['listtype'];
  18200. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18201. $this->lispacer = $this->lisymbol;
  18202. } else {
  18203. $this->lispacer = '#';
  18204. }
  18205. ++$this->listcount[$this->listnum];
  18206. if (isset($tag['attribute']['value'])) {
  18207. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  18208. }
  18209. } else {
  18210. // unordered item
  18211. if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
  18212. $this->lispacer = $parent['attribute']['type'];
  18213. } elseif (isset($parent['listtype']) AND !TCPDF_STATIC::empty_string($parent['listtype'])) {
  18214. $this->lispacer = $parent['listtype'];
  18215. } elseif (isset($this->lisymbol) AND !TCPDF_STATIC::empty_string($this->lisymbol)) {
  18216. $this->lispacer = $this->lisymbol;
  18217. } else {
  18218. $this->lispacer = '!';
  18219. }
  18220. }
  18221. break;
  18222. }
  18223. case 'blockquote': {
  18224. if ($this->rtl) {
  18225. $this->rMargin += $this->listindent;
  18226. } else {
  18227. $this->lMargin += $this->listindent;
  18228. }
  18229. ++$this->listindentlevel;
  18230. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18231. break;
  18232. }
  18233. case 'br': {
  18234. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18235. break;
  18236. }
  18237. case 'div': {
  18238. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18239. break;
  18240. }
  18241. case 'p': {
  18242. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18243. break;
  18244. }
  18245. case 'pre': {
  18246. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18247. $this->premode = true;
  18248. break;
  18249. }
  18250. case 'sup': {
  18251. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  18252. break;
  18253. }
  18254. case 'sub': {
  18255. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  18256. break;
  18257. }
  18258. case 'h1':
  18259. case 'h2':
  18260. case 'h3':
  18261. case 'h4':
  18262. case 'h5':
  18263. case 'h6': {
  18264. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  18265. break;
  18266. }
  18267. // Form fields (since 4.8.000 - 2009-09-07)
  18268. case 'form': {
  18269. if (isset($tag['attribute']['action'])) {
  18270. $this->form_action = $tag['attribute']['action'];
  18271. } else {
  18272. $this->Error('Please explicitly set action attribute path!');
  18273. }
  18274. if (isset($tag['attribute']['enctype'])) {
  18275. $this->form_enctype = $tag['attribute']['enctype'];
  18276. } else {
  18277. $this->form_enctype = 'application/x-www-form-urlencoded';
  18278. }
  18279. if (isset($tag['attribute']['method'])) {
  18280. $this->form_mode = $tag['attribute']['method'];
  18281. } else {
  18282. $this->form_mode = 'post';
  18283. }
  18284. break;
  18285. }
  18286. case 'input': {
  18287. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18288. $name = $tag['attribute']['name'];
  18289. } else {
  18290. break;
  18291. }
  18292. $prop = array();
  18293. $opt = array();
  18294. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18295. $prop['readonly'] = true;
  18296. }
  18297. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18298. $value = $tag['attribute']['value'];
  18299. }
  18300. if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC::empty_string($tag['attribute']['maxlength'])) {
  18301. $opt['maxlen'] = intval($tag['attribute']['maxlength']);
  18302. }
  18303. $h = $this->FontSize * $this->cell_height_ratio;
  18304. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18305. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  18306. } else {
  18307. $w = $h;
  18308. }
  18309. if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
  18310. $checked = true;
  18311. } else {
  18312. $checked = false;
  18313. }
  18314. if (isset($tag['align'])) {
  18315. switch ($tag['align']) {
  18316. case 'C': {
  18317. $opt['q'] = 1;
  18318. break;
  18319. }
  18320. case 'R': {
  18321. $opt['q'] = 2;
  18322. break;
  18323. }
  18324. case 'L':
  18325. default: {
  18326. break;
  18327. }
  18328. }
  18329. }
  18330. switch ($tag['attribute']['type']) {
  18331. case 'text': {
  18332. if (isset($value)) {
  18333. $opt['v'] = $value;
  18334. }
  18335. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18336. break;
  18337. }
  18338. case 'password': {
  18339. if (isset($value)) {
  18340. $opt['v'] = $value;
  18341. }
  18342. $prop['password'] = 'true';
  18343. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18344. break;
  18345. }
  18346. case 'checkbox': {
  18347. if (!isset($value)) {
  18348. break;
  18349. }
  18350. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  18351. break;
  18352. }
  18353. case 'radio': {
  18354. if (!isset($value)) {
  18355. break;
  18356. }
  18357. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  18358. break;
  18359. }
  18360. case 'submit': {
  18361. if (!isset($value)) {
  18362. $value = 'submit';
  18363. }
  18364. $w = $this->GetStringWidth($value) * 1.5;
  18365. $h *= 1.6;
  18366. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18367. $action = array();
  18368. $action['S'] = 'SubmitForm';
  18369. $action['F'] = $this->form_action;
  18370. if ($this->form_enctype != 'FDF') {
  18371. $action['Flags'] = array('ExportFormat');
  18372. }
  18373. if ($this->form_mode == 'get') {
  18374. $action['Flags'] = array('GetMethod');
  18375. }
  18376. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  18377. break;
  18378. }
  18379. case 'reset': {
  18380. if (!isset($value)) {
  18381. $value = 'reset';
  18382. }
  18383. $w = $this->GetStringWidth($value) * 1.5;
  18384. $h *= 1.6;
  18385. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18386. $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
  18387. break;
  18388. }
  18389. case 'file': {
  18390. $prop['fileSelect'] = 'true';
  18391. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18392. if (!isset($value)) {
  18393. $value = '*';
  18394. }
  18395. $w = $this->GetStringWidth($value) * 2;
  18396. $h *= 1.2;
  18397. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18398. $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
  18399. $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18400. break;
  18401. }
  18402. case 'hidden': {
  18403. if (isset($value)) {
  18404. $opt['v'] = $value;
  18405. }
  18406. $opt['f'] = array('invisible', 'hidden');
  18407. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  18408. break;
  18409. }
  18410. case 'image': {
  18411. // THIS TYPE MUST BE FIXED
  18412. if (isset($tag['attribute']['src']) AND !TCPDF_STATIC::empty_string($tag['attribute']['src'])) {
  18413. $img = $tag['attribute']['src'];
  18414. } else {
  18415. break;
  18416. }
  18417. $value = 'img';
  18418. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  18419. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18420. $jsaction = $tag['attribute']['onclick'];
  18421. } else {
  18422. $jsaction = '';
  18423. }
  18424. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18425. break;
  18426. }
  18427. case 'button': {
  18428. if (!isset($value)) {
  18429. $value = ' ';
  18430. }
  18431. $w = $this->GetStringWidth($value) * 1.5;
  18432. $h *= 1.6;
  18433. $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
  18434. if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
  18435. $jsaction = $tag['attribute']['onclick'];
  18436. } else {
  18437. $jsaction = '';
  18438. }
  18439. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  18440. break;
  18441. }
  18442. }
  18443. break;
  18444. }
  18445. case 'textarea': {
  18446. $prop = array();
  18447. $opt = array();
  18448. if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC::empty_string($tag['attribute']['readonly'])) {
  18449. $prop['readonly'] = true;
  18450. }
  18451. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18452. $name = $tag['attribute']['name'];
  18453. } else {
  18454. break;
  18455. }
  18456. if (isset($tag['attribute']['value']) AND !TCPDF_STATIC::empty_string($tag['attribute']['value'])) {
  18457. $opt['v'] = $tag['attribute']['value'];
  18458. }
  18459. if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC::empty_string($tag['attribute']['cols'])) {
  18460. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  18461. } else {
  18462. $w = 40;
  18463. }
  18464. if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC::empty_string($tag['attribute']['rows'])) {
  18465. $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio;
  18466. } else {
  18467. $h = 10;
  18468. }
  18469. $prop['multiline'] = 'true';
  18470. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  18471. break;
  18472. }
  18473. case 'select': {
  18474. $h = $this->FontSize * $this->cell_height_ratio;
  18475. if (isset($tag['attribute']['size']) AND !TCPDF_STATIC::empty_string($tag['attribute']['size'])) {
  18476. $h *= ($tag['attribute']['size'] + 1);
  18477. }
  18478. $prop = array();
  18479. $opt = array();
  18480. if (isset($tag['attribute']['name']) AND !TCPDF_STATIC::empty_string($tag['attribute']['name'])) {
  18481. $name = $tag['attribute']['name'];
  18482. } else {
  18483. break;
  18484. }
  18485. $w = 0;
  18486. if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC::empty_string($tag['attribute']['opt'])) {
  18487. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  18488. $values = array();
  18489. foreach ($options as $val) {
  18490. if (strpos($val, '#!TaB!#') !== false) {
  18491. $opts = explode('#!TaB!#', $val);
  18492. $values[] = $opts;
  18493. $w = max($w, $this->GetStringWidth($opts[1]));
  18494. } else {
  18495. $values[] = $val;
  18496. $w = max($w, $this->GetStringWidth($val));
  18497. }
  18498. }
  18499. } else {
  18500. break;
  18501. }
  18502. $w *= 2;
  18503. if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
  18504. $prop['multipleSelection'] = 'true';
  18505. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18506. } else {
  18507. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  18508. }
  18509. break;
  18510. }
  18511. case 'tcpdf': {
  18512. if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML === true)) {
  18513. // Special tag used to call TCPDF methods
  18514. if (isset($tag['attribute']['method'])) {
  18515. $tcpdf_method = $tag['attribute']['method'];
  18516. if (method_exists($this, $tcpdf_method)) {
  18517. if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
  18518. $params = unserialize(urldecode($tag['attribute']['params']));
  18519. call_user_func_array(array($this, $tcpdf_method), $params);
  18520. } else {
  18521. $this->$tcpdf_method();
  18522. }
  18523. $this->newline = true;
  18524. }
  18525. }
  18526. }
  18527. break;
  18528. }
  18529. default: {
  18530. break;
  18531. }
  18532. }
  18533. // define tags that support borders and background colors
  18534. $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
  18535. if (in_array($tag['value'], $bordertags)) {
  18536. // set border
  18537. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  18538. }
  18539. if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
  18540. $pba = $dom[$key]['attribute']['pagebreakafter'];
  18541. // check for pagebreak
  18542. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  18543. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18544. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18545. }
  18546. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  18547. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  18548. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  18549. $this->checkPageBreak($this->PageBreakTrigger + 1);
  18550. }
  18551. }
  18552. return $dom;
  18553. }
  18554. /**
  18555. * Process closing tags.
  18556. * @param $dom (array) html dom array
  18557. * @param $key (int) current element id
  18558. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  18559. * @param $maxbottomliney (int) maximum y value of current line
  18560. * @return $dom array
  18561. * @protected
  18562. */
  18563. protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
  18564. $tag = $dom[$key];
  18565. $parent = $dom[($dom[$key]['parent'])];
  18566. $lasttag = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)]['value'] == 'marker')));
  18567. $in_table_head = false;
  18568. // maximum x position (used to draw borders)
  18569. if ($this->rtl) {
  18570. $xmax = $this->w;
  18571. } else {
  18572. $xmax = 0;
  18573. }
  18574. if ($tag['block']) {
  18575. $hbz = 0; // distance from y to line bottom
  18576. $hb = 0; // vertical space between block tags
  18577. // calculate vertical space for block tags
  18578. if (isset($this->tagvspaces[$tag['value']][1]['h']) AND ($this->tagvspaces[$tag['value']][1]['h'] >= 0)) {
  18579. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  18580. } elseif (isset($parent['fontsize'])) {
  18581. $pre_h = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  18582. } else {
  18583. $pre_h = $this->FontSize * $this->cell_height_ratio;
  18584. }
  18585. if (isset($this->tagvspaces[$tag['value']][1]['n'])) {
  18586. $n = $this->tagvspaces[$tag['value']][1]['n'];
  18587. } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
  18588. $n = 0.6;
  18589. } else {
  18590. $n = 1;
  18591. }
  18592. if ((!isset($this->tagvspaces[$tag['value']])) AND ($tag['value'] == 'div')) {
  18593. $hb = 0;
  18594. } else {
  18595. $hb = ($n * $pre_h);
  18596. }
  18597. if ($maxbottomliney > $this->PageBreakTrigger) {
  18598. $hbz = ($this->FontSize * $this->cell_height_ratio);
  18599. } elseif ($this->y < $maxbottomliney) {
  18600. $hbz = ($maxbottomliney - $this->y);
  18601. }
  18602. }
  18603. // Closing tag
  18604. switch($tag['value']) {
  18605. case 'tr': {
  18606. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  18607. if (!isset($parent['endy'])) {
  18608. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  18609. $parent['endy'] = $this->y;
  18610. }
  18611. if (!isset($parent['endpage'])) {
  18612. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  18613. $parent['endpage'] = $this->page;
  18614. }
  18615. if (!isset($parent['endcolumn'])) {
  18616. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  18617. $parent['endcolumn'] = $this->current_column;
  18618. }
  18619. // update row-spanned cells
  18620. if (isset($dom[$table_el]['rowspans'])) {
  18621. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18622. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  18623. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18624. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
  18625. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  18626. } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
  18627. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18628. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18629. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18630. }
  18631. }
  18632. }
  18633. // report new endy and endpage to the rowspanned cells
  18634. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18635. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18636. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  18637. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  18638. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  18639. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  18640. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  18641. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  18642. }
  18643. }
  18644. // update remaining rowspanned cells
  18645. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
  18646. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
  18647. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  18648. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  18649. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  18650. }
  18651. }
  18652. }
  18653. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  18654. if ($this->num_columns > 1) {
  18655. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  18656. }
  18657. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  18658. if (isset($dom[$table_el]['attribute']['cellspacing'])) {
  18659. $this->y += $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  18660. } elseif (isset($dom[$table_el]['border-spacing'])) {
  18661. $this->y += $dom[$table_el]['border-spacing']['V'];
  18662. }
  18663. $this->Ln(0, $cell);
  18664. if ($this->current_column == $parent['startcolumn']) {
  18665. $this->x = $parent['startx'];
  18666. }
  18667. // account for booklet mode
  18668. if ($this->page > $parent['startpage']) {
  18669. if (($this->rtl) AND ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm'])) {
  18670. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  18671. } elseif ((!$this->rtl) AND ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm'])) {
  18672. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  18673. }
  18674. }
  18675. break;
  18676. }
  18677. case 'tablehead':
  18678. // closing tag used for the thead part
  18679. $in_table_head = true;
  18680. $this->inthead = false;
  18681. case 'table': {
  18682. $table_el = $parent;
  18683. // set default border
  18684. if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
  18685. // set default border
  18686. $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
  18687. } else {
  18688. $border = 0;
  18689. }
  18690. $default_border = $border;
  18691. // fix bottom line alignment of last line before page break
  18692. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
  18693. // update row-spanned cells
  18694. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  18695. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  18696. if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
  18697. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  18698. }
  18699. if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
  18700. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  18701. }
  18702. }
  18703. }
  18704. if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
  18705. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  18706. $dom[$prevtrkey]['endy'] = $pgendy;
  18707. // update row-spanned cells
  18708. if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
  18709. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
  18710. if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] > 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
  18711. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  18712. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
  18713. }
  18714. }
  18715. }
  18716. }
  18717. $prevtrkey = $trkey;
  18718. $table_el = $dom[($dom[$key]['parent'])];
  18719. }
  18720. // for each row
  18721. if (count($table_el['trids']) > 0) {
  18722. unset($xmax);
  18723. }
  18724. foreach ($table_el['trids'] as $j => $trkey) {
  18725. $parent = $dom[$trkey];
  18726. if (!isset($xmax)) {
  18727. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  18728. }
  18729. // for each cell on the row
  18730. foreach ($parent['cellpos'] as $k => $cellpos) {
  18731. if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
  18732. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  18733. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  18734. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  18735. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  18736. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  18737. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  18738. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  18739. } else {
  18740. $endy = $parent['endy'];
  18741. $startpage = $parent['startpage'];
  18742. $endpage = $parent['endpage'];
  18743. $startcolumn = $parent['startcolumn'];
  18744. $endcolumn = $parent['endcolumn'];
  18745. }
  18746. if ($this->num_columns == 0) {
  18747. $this->num_columns = 1;
  18748. }
  18749. if (isset($cellpos['border'])) {
  18750. $border = $cellpos['border'];
  18751. }
  18752. if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
  18753. $this->SetFillColorArray($cellpos['bgcolor']);
  18754. $fill = true;
  18755. } else {
  18756. $fill = false;
  18757. }
  18758. $x = $cellpos['startx'];
  18759. $y = $parent['starty'];
  18760. $starty = $y;
  18761. $w = abs($cellpos['endx'] - $cellpos['startx']);
  18762. // get border modes
  18763. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  18764. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  18765. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  18766. // design borders around HTML cells.
  18767. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  18768. $ccode = '';
  18769. $this->setPage($page);
  18770. if ($this->num_columns < 2) {
  18771. // single-column mode
  18772. $this->x = $x;
  18773. $this->y = $this->tMargin;
  18774. }
  18775. // account for margin changes
  18776. if ($page > $startpage) {
  18777. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  18778. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  18779. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  18780. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  18781. }
  18782. }
  18783. if ($startpage == $endpage) { // single page
  18784. $deltacol = 0;
  18785. $deltath = 0;
  18786. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  18787. $this->selectColumn($column);
  18788. if ($startcolumn == $endcolumn) { // single column
  18789. $cborder = $border;
  18790. $h = $endy - $parent['starty'];
  18791. $this->y = $y;
  18792. $this->x = $x;
  18793. } elseif ($column == $startcolumn) { // first column
  18794. $cborder = $border_start;
  18795. $this->y = $starty;
  18796. $this->x = $x;
  18797. $h = $this->h - $this->y - $this->bMargin;
  18798. if ($this->rtl) {
  18799. $deltacol = $this->x + $this->rMargin - $this->w;
  18800. } else {
  18801. $deltacol = $this->x - $this->lMargin;
  18802. }
  18803. } elseif ($column == $endcolumn) { // end column
  18804. $cborder = $border_end;
  18805. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18806. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18807. }
  18808. $this->x += $deltacol;
  18809. $h = $endy - $this->y;
  18810. } else { // middle column
  18811. $cborder = $border_middle;
  18812. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18813. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18814. }
  18815. $this->x += $deltacol;
  18816. $h = $this->h - $this->y - $this->bMargin;
  18817. }
  18818. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18819. } // end for each column
  18820. } elseif ($page == $startpage) { // first page
  18821. $deltacol = 0;
  18822. $deltath = 0;
  18823. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  18824. $this->selectColumn($column);
  18825. if ($column == $startcolumn) { // first column
  18826. $cborder = $border_start;
  18827. $this->y = $starty;
  18828. $this->x = $x;
  18829. $h = $this->h - $this->y - $this->bMargin;
  18830. if ($this->rtl) {
  18831. $deltacol = $this->x + $this->rMargin - $this->w;
  18832. } else {
  18833. $deltacol = $this->x - $this->lMargin;
  18834. }
  18835. } else { // middle column
  18836. $cborder = $border_middle;
  18837. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18838. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18839. }
  18840. $this->x += $deltacol;
  18841. $h = $this->h - $this->y - $this->bMargin;
  18842. }
  18843. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18844. } // end for each column
  18845. } elseif ($page == $endpage) { // last page
  18846. $deltacol = 0;
  18847. $deltath = 0;
  18848. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  18849. $this->selectColumn($column);
  18850. if ($column == $endcolumn) { // end column
  18851. $cborder = $border_end;
  18852. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18853. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18854. }
  18855. $this->x += $deltacol;
  18856. $h = $endy - $this->y;
  18857. } else { // middle column
  18858. $cborder = $border_middle;
  18859. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18860. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18861. }
  18862. $this->x += $deltacol;
  18863. $h = $this->h - $this->y - $this->bMargin;
  18864. }
  18865. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18866. } // end for each column
  18867. } else { // middle page
  18868. $deltacol = 0;
  18869. $deltath = 0;
  18870. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  18871. $this->selectColumn($column);
  18872. $cborder = $border_middle;
  18873. if (isset($this->columns[$column]['th']['\''.$page.'\''])) {
  18874. $this->y = $this->columns[$column]['th']['\''.$page.'\''];
  18875. }
  18876. $this->x += $deltacol;
  18877. $h = $this->h - $this->y - $this->bMargin;
  18878. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  18879. } // end for each column
  18880. }
  18881. if ($cborder OR $fill) {
  18882. $offsetlen = strlen($ccode);
  18883. // draw border and fill
  18884. if ($this->inxobj) {
  18885. // we are inside an XObject template
  18886. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  18887. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  18888. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  18889. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  18890. } else {
  18891. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  18892. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  18893. }
  18894. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  18895. $pstart = substr($pagebuff, 0, $pagemark);
  18896. $pend = substr($pagebuff, $pagemark);
  18897. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  18898. } else {
  18899. // draw border and fill
  18900. if (end($this->transfmrk[$this->page]) !== false) {
  18901. $pagemarkkey = key($this->transfmrk[$this->page]);
  18902. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  18903. } elseif ($this->InFooter) {
  18904. $pagemark = $this->footerpos[$this->page];
  18905. } else {
  18906. $pagemark = $this->intmrk[$this->page];
  18907. }
  18908. $pagebuff = $this->getPageBuffer($this->page);
  18909. $pstart = substr($pagebuff, 0, $pagemark);
  18910. $pend = substr($pagebuff, $pagemark);
  18911. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  18912. }
  18913. }
  18914. } // end for each page
  18915. // restore default border
  18916. $border = $default_border;
  18917. } // end for each cell on the row
  18918. if (isset($table_el['attribute']['cellspacing'])) {
  18919. $this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  18920. } elseif (isset($table_el['border-spacing'])) {
  18921. $this->y += $table_el['border-spacing']['V'];
  18922. }
  18923. $this->Ln(0, $cell);
  18924. $this->x = $parent['startx'];
  18925. if ($endpage > $startpage) {
  18926. if (($this->rtl) AND ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm'])) {
  18927. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  18928. } elseif ((!$this->rtl) AND ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm'])) {
  18929. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  18930. }
  18931. }
  18932. }
  18933. if (!$in_table_head) { // we are not inside a thead section
  18934. $this->cell_padding = $table_el['old_cell_padding'];
  18935. // reset row height
  18936. $this->resetLastH();
  18937. if (($this->page == ($this->numpages - 1)) AND ($this->pageopen[$this->numpages])) {
  18938. $plendiff = ($this->pagelen[$this->numpages] - $this->emptypagemrk[$this->numpages]);
  18939. if (($plendiff > 0) AND ($plendiff < 60)) {
  18940. $pagediff = substr($this->getPageBuffer($this->numpages), $this->emptypagemrk[$this->numpages], $plendiff);
  18941. if (substr($pagediff, 0, 5) == 'BT /F') {
  18942. // the difference is only a font setting
  18943. $plendiff = 0;
  18944. }
  18945. }
  18946. if ($plendiff == 0) {
  18947. // remove last blank page
  18948. $this->deletePage($this->numpages);
  18949. }
  18950. }
  18951. if (isset($this->theadMargins['top'])) {
  18952. // restore top margin
  18953. $this->tMargin = $this->theadMargins['top'];
  18954. }
  18955. if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
  18956. // reset main table header
  18957. $this->thead = '';
  18958. $this->theadMargins = array();
  18959. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  18960. }
  18961. }
  18962. $parent = $table_el;
  18963. break;
  18964. }
  18965. case 'a': {
  18966. $this->HREF = '';
  18967. break;
  18968. }
  18969. case 'sup': {
  18970. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  18971. break;
  18972. }
  18973. case 'sub': {
  18974. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  18975. break;
  18976. }
  18977. case 'div': {
  18978. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  18979. break;
  18980. }
  18981. case 'blockquote': {
  18982. if ($this->rtl) {
  18983. $this->rMargin -= $this->listindent;
  18984. } else {
  18985. $this->lMargin -= $this->listindent;
  18986. }
  18987. --$this->listindentlevel;
  18988. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  18989. break;
  18990. }
  18991. case 'p': {
  18992. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  18993. break;
  18994. }
  18995. case 'pre': {
  18996. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  18997. $this->premode = false;
  18998. break;
  18999. }
  19000. case 'dl': {
  19001. --$this->listnum;
  19002. if ($this->listnum <= 0) {
  19003. $this->listnum = 0;
  19004. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19005. } else {
  19006. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19007. }
  19008. $this->resetLastH();
  19009. break;
  19010. }
  19011. case 'dt': {
  19012. $this->lispacer = '';
  19013. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19014. break;
  19015. }
  19016. case 'dd': {
  19017. $this->lispacer = '';
  19018. if ($this->rtl) {
  19019. $this->rMargin -= $this->listindent;
  19020. } else {
  19021. $this->lMargin -= $this->listindent;
  19022. }
  19023. --$this->listindentlevel;
  19024. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19025. break;
  19026. }
  19027. case 'ul':
  19028. case 'ol': {
  19029. --$this->listnum;
  19030. $this->lispacer = '';
  19031. if ($this->rtl) {
  19032. $this->rMargin -= $this->listindent;
  19033. } else {
  19034. $this->lMargin -= $this->listindent;
  19035. }
  19036. --$this->listindentlevel;
  19037. if ($this->listnum <= 0) {
  19038. $this->listnum = 0;
  19039. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19040. } else {
  19041. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19042. }
  19043. $this->resetLastH();
  19044. break;
  19045. }
  19046. case 'li': {
  19047. $this->lispacer = '';
  19048. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  19049. break;
  19050. }
  19051. case 'h1':
  19052. case 'h2':
  19053. case 'h3':
  19054. case 'h4':
  19055. case 'h5':
  19056. case 'h6': {
  19057. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  19058. break;
  19059. }
  19060. // Form fields (since 4.8.000 - 2009-09-07)
  19061. case 'form': {
  19062. $this->form_action = '';
  19063. $this->form_enctype = 'application/x-www-form-urlencoded';
  19064. break;
  19065. }
  19066. default : {
  19067. break;
  19068. }
  19069. }
  19070. // draw border and background (if any)
  19071. $this->drawHTMLTagBorder($parent, $xmax);
  19072. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
  19073. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  19074. // check for pagebreak
  19075. if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
  19076. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19077. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19078. }
  19079. if ((($pba == 'left') AND (((!$this->rtl) AND (($this->page % 2) == 0)) OR (($this->rtl) AND (($this->page % 2) != 0))))
  19080. OR (($pba == 'right') AND (((!$this->rtl) AND (($this->page % 2) != 0)) OR (($this->rtl) AND (($this->page % 2) == 0))))) {
  19081. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  19082. $this->checkPageBreak($this->PageBreakTrigger + 1);
  19083. }
  19084. }
  19085. $this->tmprtl = false;
  19086. return $dom;
  19087. }
  19088. /**
  19089. * Add vertical spaces if needed.
  19090. * @param $hbz (string) Distance between current y and line bottom.
  19091. * @param $hb (string) The height of the break.
  19092. * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
  19093. * @param $firsttag (boolean) set to true when the tag is the first.
  19094. * @param $lasttag (boolean) set to true when the tag is the last.
  19095. * @protected
  19096. */
  19097. protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
  19098. if ($firsttag) {
  19099. $this->Ln(0, $cell);
  19100. $this->htmlvspace = 0;
  19101. return;
  19102. }
  19103. if ($lasttag) {
  19104. $this->Ln($hbz, $cell);
  19105. $this->htmlvspace = 0;
  19106. return;
  19107. }
  19108. if ($hb < $this->htmlvspace) {
  19109. $hd = 0;
  19110. } else {
  19111. $hd = $hb - $this->htmlvspace;
  19112. $this->htmlvspace = $hb;
  19113. }
  19114. $this->Ln(($hbz + $hd), $cell);
  19115. }
  19116. /**
  19117. * Return the starting coordinates to draw an html border
  19118. * @return array containing top-left border coordinates
  19119. * @protected
  19120. * @since 5.7.000 (2010-08-03)
  19121. */
  19122. protected function getBorderStartPosition() {
  19123. if ($this->rtl) {
  19124. $xmax = $this->lMargin;
  19125. } else {
  19126. $xmax = $this->w - $this->rMargin;
  19127. }
  19128. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y, 'xmax' => $xmax);
  19129. }
  19130. /**
  19131. * Draw an HTML block border and fill
  19132. * @param $tag (array) array of tag properties.
  19133. * @param $xmax (int) end X coordinate for border.
  19134. * @protected
  19135. * @since 5.7.000 (2010-08-03)
  19136. */
  19137. protected function drawHTMLTagBorder($tag, $xmax) {
  19138. if (!isset($tag['borderposition'])) {
  19139. // nothing to draw
  19140. return;
  19141. }
  19142. $prev_x = $this->x;
  19143. $prev_y = $this->y;
  19144. $prev_lasth = $this->lasth;
  19145. $border = 0;
  19146. $fill = false;
  19147. $this->lasth = 0;
  19148. if (isset($tag['border']) AND !empty($tag['border'])) {
  19149. // get border style
  19150. $border = $tag['border'];
  19151. if (!TCPDF_STATIC::empty_string($this->thead) AND (!$this->inthead)) {
  19152. // border for table header
  19153. $border = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19154. }
  19155. }
  19156. if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
  19157. // get background color
  19158. $old_bgcolor = $this->bgcolor;
  19159. $this->SetFillColorArray($tag['bgcolor']);
  19160. $fill = true;
  19161. }
  19162. if (!$border AND !$fill) {
  19163. // nothing to draw
  19164. return;
  19165. }
  19166. if (isset($tag['attribute']['cellspacing'])) {
  19167. $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  19168. $cellspacing = array('H' => $clsp, 'V' => $clsp);
  19169. } elseif (isset($tag['border-spacing'])) {
  19170. $cellspacing = $tag['border-spacing'];
  19171. } else {
  19172. $cellspacing = array('H' => 0, 'V' => 0);
  19173. }
  19174. if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
  19175. // draw the border externally respect the sqare edge.
  19176. $border['mode'] = 'ext';
  19177. }
  19178. if ($this->rtl) {
  19179. if ($xmax >= $tag['borderposition']['x']) {
  19180. $xmax = $tag['borderposition']['xmax'];
  19181. }
  19182. $w = ($tag['borderposition']['x'] - $xmax);
  19183. } else {
  19184. if ($xmax <= $tag['borderposition']['x']) {
  19185. $xmax = $tag['borderposition']['xmax'];
  19186. }
  19187. $w = ($xmax - $tag['borderposition']['x']);
  19188. }
  19189. if ($w <= 0) {
  19190. return;
  19191. }
  19192. $w += $cellspacing['H'];
  19193. $startpage = $tag['borderposition']['page'];
  19194. $startcolumn = $tag['borderposition']['column'];
  19195. $x = $tag['borderposition']['x'];
  19196. $y = $tag['borderposition']['y'];
  19197. $endpage = $this->page;
  19198. $starty = $tag['borderposition']['y'] - $cellspacing['V'];
  19199. $currentY = $this->y;
  19200. $this->x = $x;
  19201. // get latest column
  19202. $endcolumn = $this->current_column;
  19203. if ($this->num_columns == 0) {
  19204. $this->num_columns = 1;
  19205. }
  19206. // get border modes
  19207. $border_start = TCPDF_STATIC::getBorderMode($border, $position='start', $this->opencell);
  19208. $border_end = TCPDF_STATIC::getBorderMode($border, $position='end', $this->opencell);
  19209. $border_middle = TCPDF_STATIC::getBorderMode($border, $position='middle', $this->opencell);
  19210. // temporary disable page regions
  19211. $temp_page_regions = $this->page_regions;
  19212. $this->page_regions = array();
  19213. // design borders around HTML cells.
  19214. for ($page = $startpage; $page <= $endpage; ++$page) { // for each page
  19215. $ccode = '';
  19216. $this->setPage($page);
  19217. if ($this->num_columns < 2) {
  19218. // single-column mode
  19219. $this->x = $x;
  19220. $this->y = $this->tMargin;
  19221. }
  19222. // account for margin changes
  19223. if ($page > $startpage) {
  19224. if (($this->rtl) AND ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm'])) {
  19225. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  19226. } elseif ((!$this->rtl) AND ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm'])) {
  19227. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  19228. }
  19229. }
  19230. if ($startpage == $endpage) {
  19231. // single page
  19232. for ($column = $startcolumn; $column <= $endcolumn; ++$column) { // for each column
  19233. $this->selectColumn($column);
  19234. if ($startcolumn == $endcolumn) { // single column
  19235. $cborder = $border;
  19236. $h = ($currentY - $y) + $cellspacing['V'];
  19237. $this->y = $starty;
  19238. } elseif ($column == $startcolumn) { // first column
  19239. $cborder = $border_start;
  19240. $this->y = $starty;
  19241. $h = $this->h - $this->y - $this->bMargin;
  19242. } elseif ($column == $endcolumn) { // end column
  19243. $cborder = $border_end;
  19244. $h = $currentY - $this->y;
  19245. } else { // middle column
  19246. $cborder = $border_middle;
  19247. $h = $this->h - $this->y - $this->bMargin;
  19248. }
  19249. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19250. } // end for each column
  19251. } elseif ($page == $startpage) { // first page
  19252. for ($column = $startcolumn; $column < $this->num_columns; ++$column) { // for each column
  19253. $this->selectColumn($column);
  19254. if ($column == $startcolumn) { // first column
  19255. $cborder = $border_start;
  19256. $this->y = $starty;
  19257. $h = $this->h - $this->y - $this->bMargin;
  19258. } else { // middle column
  19259. $cborder = $border_middle;
  19260. $h = $this->h - $this->y - $this->bMargin;
  19261. }
  19262. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19263. } // end for each column
  19264. } elseif ($page == $endpage) { // last page
  19265. for ($column = 0; $column <= $endcolumn; ++$column) { // for each column
  19266. $this->selectColumn($column);
  19267. if ($column == $endcolumn) {
  19268. // end column
  19269. $cborder = $border_end;
  19270. $h = $currentY - $this->y;
  19271. } else {
  19272. // middle column
  19273. $cborder = $border_middle;
  19274. $h = $this->h - $this->y - $this->bMargin;
  19275. }
  19276. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19277. } // end for each column
  19278. } else { // middle page
  19279. for ($column = 0; $column < $this->num_columns; ++$column) { // for each column
  19280. $this->selectColumn($column);
  19281. $cborder = $border_middle;
  19282. $h = $this->h - $this->y - $this->bMargin;
  19283. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
  19284. } // end for each column
  19285. }
  19286. if ($cborder OR $fill) {
  19287. $offsetlen = strlen($ccode);
  19288. // draw border and fill
  19289. if ($this->inxobj) {
  19290. // we are inside an XObject template
  19291. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false) {
  19292. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  19293. $pagemark = $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  19294. $this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey] += $offsetlen;
  19295. } else {
  19296. $pagemark = $this->xobjects[$this->xobjid]['intmrk'];
  19297. $this->xobjects[$this->xobjid]['intmrk'] += $offsetlen;
  19298. }
  19299. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  19300. $pstart = substr($pagebuff, 0, $pagemark);
  19301. $pend = substr($pagebuff, $pagemark);
  19302. $this->xobjects[$this->xobjid]['outdata'] = $pstart.$ccode.$pend;
  19303. } else {
  19304. if (end($this->transfmrk[$this->page]) !== false) {
  19305. $pagemarkkey = key($this->transfmrk[$this->page]);
  19306. $pagemark = $this->transfmrk[$this->page][$pagemarkkey];
  19307. } elseif ($this->InFooter) {
  19308. $pagemark = $this->footerpos[$this->page];
  19309. } else {
  19310. $pagemark = $this->intmrk[$this->page];
  19311. }
  19312. $pagebuff = $this->getPageBuffer($this->page);
  19313. $pstart = substr($pagebuff, 0, $pagemark);
  19314. $pend = substr($pagebuff, $pagemark);
  19315. $this->setPageBuffer($this->page, $pstart.$ccode.$pend);
  19316. $this->bordermrk[$this->page] += $offsetlen;
  19317. $this->cntmrk[$this->page] += $offsetlen;
  19318. }
  19319. }
  19320. } // end for each page
  19321. // restore page regions
  19322. $this->page_regions = $temp_page_regions;
  19323. if (isset($old_bgcolor)) {
  19324. // restore background color
  19325. $this->SetFillColorArray($old_bgcolor);
  19326. }
  19327. // restore pointer position
  19328. $this->x = $prev_x;
  19329. $this->y = $prev_y;
  19330. $this->lasth = $prev_lasth;
  19331. }
  19332. /**
  19333. * Set the default bullet to be used as LI bullet symbol
  19334. * @param $symbol (string) 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')
  19335. * @public
  19336. * @since 4.0.028 (2008-09-26)
  19337. */
  19338. public function setLIsymbol($symbol='!') {
  19339. // check for custom image symbol
  19340. if (substr($symbol, 0, 4) == 'img|') {
  19341. $this->lisymbol = $symbol;
  19342. return;
  19343. }
  19344. $symbol = strtolower($symbol);
  19345. $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');
  19346. if (in_array($symbol, $valid_symbols)) {
  19347. $this->lisymbol = $symbol;
  19348. } else {
  19349. $this->lisymbol = '';
  19350. }
  19351. }
  19352. /**
  19353. * Set the booklet mode for double-sided pages.
  19354. * @param $booklet (boolean) true set the booklet mode on, false otherwise.
  19355. * @param $inner (float) Inner page margin.
  19356. * @param $outer (float) Outer page margin.
  19357. * @public
  19358. * @since 4.2.000 (2008-10-29)
  19359. */
  19360. public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
  19361. $this->booklet = $booklet;
  19362. if ($inner >= 0) {
  19363. $this->lMargin = $inner;
  19364. }
  19365. if ($outer >= 0) {
  19366. $this->rMargin = $outer;
  19367. }
  19368. }
  19369. /**
  19370. * Swap the left and right margins.
  19371. * @param $reverse (boolean) if true swap left and right margins.
  19372. * @protected
  19373. * @since 4.2.000 (2008-10-29)
  19374. */
  19375. protected function swapMargins($reverse=true) {
  19376. if ($reverse) {
  19377. // swap left and right margins
  19378. $mtemp = $this->original_lMargin;
  19379. $this->original_lMargin = $this->original_rMargin;
  19380. $this->original_rMargin = $mtemp;
  19381. $deltam = $this->original_lMargin - $this->original_rMargin;
  19382. $this->lMargin += $deltam;
  19383. $this->rMargin -= $deltam;
  19384. }
  19385. }
  19386. /**
  19387. * Set the vertical spaces for HTML tags.
  19388. * The array must have the following structure (example):
  19389. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  19390. * The first array level contains the tag names,
  19391. * the second level contains 0 for opening tags or 1 for closing tags,
  19392. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  19393. * If the h parameter is not specified, default values are used.
  19394. * @param $tagvs (array) array of tags and relative vertical spaces.
  19395. * @public
  19396. * @since 4.2.001 (2008-10-30)
  19397. */
  19398. public function setHtmlVSpace($tagvs) {
  19399. $this->tagvspaces = $tagvs;
  19400. }
  19401. /**
  19402. * Set custom width for list indentation.
  19403. * @param $width (float) width of the indentation. Use negative value to disable it.
  19404. * @public
  19405. * @since 4.2.007 (2008-11-12)
  19406. */
  19407. public function setListIndentWidth($width) {
  19408. return $this->customlistindent = floatval($width);
  19409. }
  19410. /**
  19411. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  19412. * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
  19413. * @public
  19414. * @since 4.2.010 (2008-11-14)
  19415. */
  19416. public function setOpenCell($isopen) {
  19417. $this->opencell = $isopen;
  19418. }
  19419. /**
  19420. * Set the color and font style for HTML links.
  19421. * @param $color (array) RGB array of colors
  19422. * @param $fontstyle (string) additional font styles to add
  19423. * @public
  19424. * @since 4.4.003 (2008-12-09)
  19425. */
  19426. public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
  19427. $this->htmlLinkColorArray = $color;
  19428. $this->htmlLinkFontStyle = $fontstyle;
  19429. }
  19430. /**
  19431. * Convert HTML string containing value and unit of measure to user's units or points.
  19432. * @param $htmlval (string) String containing values and unit.
  19433. * @param $refsize (string) Reference value in points.
  19434. * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  19435. * @param $points (boolean) If true returns points, otherwise returns value in user's units.
  19436. * @return float value in user's unit or point if $points=true
  19437. * @public
  19438. * @since 4.4.004 (2008-12-10)
  19439. */
  19440. public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
  19441. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  19442. $retval = 0;
  19443. $value = 0;
  19444. $unit = 'px';
  19445. if ($points) {
  19446. $k = 1;
  19447. } else {
  19448. $k = $this->k;
  19449. }
  19450. if (in_array($defaultunit, $supportedunits)) {
  19451. $unit = $defaultunit;
  19452. }
  19453. if (is_numeric($htmlval)) {
  19454. $value = floatval($htmlval);
  19455. } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
  19456. $value = floatval($mnum[1]);
  19457. if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
  19458. if (in_array($munit[1], $supportedunits)) {
  19459. $unit = $munit[1];
  19460. }
  19461. }
  19462. }
  19463. switch ($unit) {
  19464. // percentage
  19465. case '%': {
  19466. $retval = (($value * $refsize) / 100);
  19467. break;
  19468. }
  19469. // relative-size
  19470. case 'em': {
  19471. $retval = ($value * $refsize);
  19472. break;
  19473. }
  19474. // height of lower case 'x' (about half the font-size)
  19475. case 'ex': {
  19476. $retval = ($value * ($refsize / 2));
  19477. break;
  19478. }
  19479. // absolute-size
  19480. case 'in': {
  19481. $retval = (($value * $this->dpi) / $k);
  19482. break;
  19483. }
  19484. // centimeters
  19485. case 'cm': {
  19486. $retval = (($value / 2.54 * $this->dpi) / $k);
  19487. break;
  19488. }
  19489. // millimeters
  19490. case 'mm': {
  19491. $retval = (($value / 25.4 * $this->dpi) / $k);
  19492. break;
  19493. }
  19494. // one pica is 12 points
  19495. case 'pc': {
  19496. $retval = (($value * 12) / $k);
  19497. break;
  19498. }
  19499. // points
  19500. case 'pt': {
  19501. $retval = ($value / $k);
  19502. break;
  19503. }
  19504. // pixels
  19505. case 'px': {
  19506. $retval = $this->pixelsToUnits($value);
  19507. if ($points) {
  19508. $retval *= $this->k;
  19509. }
  19510. break;
  19511. }
  19512. }
  19513. return $retval;
  19514. }
  19515. /**
  19516. * Output an HTML list bullet or ordered item symbol
  19517. * @param $listdepth (int) list nesting level
  19518. * @param $listtype (string) type of list
  19519. * @param $size (float) current font size
  19520. * @protected
  19521. * @since 4.4.004 (2008-12-10)
  19522. */
  19523. protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
  19524. if ($this->state != 2) {
  19525. return;
  19526. }
  19527. $size /= $this->k;
  19528. $fill = '';
  19529. $bgcolor = $this->bgcolor;
  19530. $color = $this->fgcolor;
  19531. $strokecolor = $this->strokecolor;
  19532. $width = 0;
  19533. $textitem = '';
  19534. $tmpx = $this->x;
  19535. $lspace = $this->GetStringWidth(' ');
  19536. if ($listtype == '^') {
  19537. // special symbol used for avoid justification of rect bullet
  19538. $this->lispacer = '';
  19539. return;
  19540. } elseif ($listtype == '!') {
  19541. // set default list type for unordered list
  19542. $deftypes = array('disc', 'circle', 'square');
  19543. $listtype = $deftypes[($listdepth - 1) % 3];
  19544. } elseif ($listtype == '#') {
  19545. // set default list type for ordered list
  19546. $listtype = 'decimal';
  19547. } elseif (substr($listtype, 0, 4) == 'img|') {
  19548. // custom image type ('img|type|width|height|image.ext')
  19549. $img = explode('|', $listtype);
  19550. $listtype = 'img';
  19551. }
  19552. switch ($listtype) {
  19553. // unordered types
  19554. case 'none': {
  19555. break;
  19556. }
  19557. case 'disc': {
  19558. $r = $size / 6;
  19559. $lspace += (2 * $r);
  19560. if ($this->rtl) {
  19561. $this->x += $lspace;
  19562. } else {
  19563. $this->x -= $lspace;
  19564. }
  19565. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, 'F', array(), $color, 8);
  19566. break;
  19567. }
  19568. case 'circle': {
  19569. $r = $size / 6;
  19570. $lspace += (2 * $r);
  19571. if ($this->rtl) {
  19572. $this->x += $lspace;
  19573. } else {
  19574. $this->x -= $lspace;
  19575. }
  19576. $prev_line_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor;
  19577. $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
  19578. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
  19579. $this->_out($prev_line_style); // restore line settings
  19580. break;
  19581. }
  19582. case 'square': {
  19583. $l = $size / 3;
  19584. $lspace += $l;
  19585. if ($this->rtl) {;
  19586. $this->x += $lspace;
  19587. } else {
  19588. $this->x -= $lspace;
  19589. }
  19590. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  19591. break;
  19592. }
  19593. case 'img': {
  19594. // 1=>type, 2=>width, 3=>height, 4=>image.ext
  19595. $lspace += $img[2];
  19596. if ($this->rtl) {;
  19597. $this->x += $lspace;
  19598. } else {
  19599. $this->x -= $lspace;
  19600. }
  19601. $imgtype = strtolower($img[1]);
  19602. $prev_y = $this->y;
  19603. switch ($imgtype) {
  19604. case 'svg': {
  19605. $this->ImageSVG($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
  19606. break;
  19607. }
  19608. case 'ai':
  19609. case 'eps': {
  19610. $this->ImageEps($img[4], $this->x, ($this->y + (($this->lasth - $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
  19611. break;
  19612. }
  19613. default: {
  19614. $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);
  19615. break;
  19616. }
  19617. }
  19618. $this->y = $prev_y;
  19619. break;
  19620. }
  19621. // ordered types
  19622. // $this->listcount[$this->listnum];
  19623. // $textitem
  19624. case '1':
  19625. case 'decimal': {
  19626. $textitem = $this->listcount[$this->listnum];
  19627. break;
  19628. }
  19629. case 'decimal-leading-zero': {
  19630. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  19631. break;
  19632. }
  19633. case 'i':
  19634. case 'lower-roman': {
  19635. $textitem = strtolower(TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]));
  19636. break;
  19637. }
  19638. case 'I':
  19639. case 'upper-roman': {
  19640. $textitem = TCPDF_STATIC::intToRoman($this->listcount[$this->listnum]);
  19641. break;
  19642. }
  19643. case 'a':
  19644. case 'lower-alpha':
  19645. case 'lower-latin': {
  19646. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  19647. break;
  19648. }
  19649. case 'A':
  19650. case 'upper-alpha':
  19651. case 'upper-latin': {
  19652. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  19653. break;
  19654. }
  19655. case 'lower-greek': {
  19656. $textitem = TCPDF_FONTS::unichr((945 + $this->listcount[$this->listnum] - 1), $this->isunicode);
  19657. break;
  19658. }
  19659. /*
  19660. // Types to be implemented (special handling)
  19661. case 'hebrew': {
  19662. break;
  19663. }
  19664. case 'armenian': {
  19665. break;
  19666. }
  19667. case 'georgian': {
  19668. break;
  19669. }
  19670. case 'cjk-ideographic': {
  19671. break;
  19672. }
  19673. case 'hiragana': {
  19674. break;
  19675. }
  19676. case 'katakana': {
  19677. break;
  19678. }
  19679. case 'hiragana-iroha': {
  19680. break;
  19681. }
  19682. case 'katakana-iroha': {
  19683. break;
  19684. }
  19685. */
  19686. default: {
  19687. $textitem = $this->listcount[$this->listnum];
  19688. }
  19689. }
  19690. if (!TCPDF_STATIC::empty_string($textitem)) {
  19691. // Check whether we need a new page or new column
  19692. $prev_y = $this->y;
  19693. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  19694. if ($this->checkPageBreak($h) OR ($this->y < $prev_y)) {
  19695. $tmpx = $this->x;
  19696. }
  19697. // print ordered item
  19698. if ($this->rtl) {
  19699. $textitem = '.'.$textitem;
  19700. } else {
  19701. $textitem = $textitem.'.';
  19702. }
  19703. $lspace += $this->GetStringWidth($textitem);
  19704. if ($this->rtl) {
  19705. $this->x += $lspace;
  19706. } else {
  19707. $this->x -= $lspace;
  19708. }
  19709. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  19710. }
  19711. $this->x = $tmpx;
  19712. $this->lispacer = '^';
  19713. // restore colors
  19714. $this->SetFillColorArray($bgcolor);
  19715. $this->SetDrawColorArray($strokecolor);
  19716. $this->SettextColorArray($color);
  19717. }
  19718. /**
  19719. * Returns current graphic variables as array.
  19720. * @return array of graphic variables
  19721. * @protected
  19722. * @since 4.2.010 (2008-11-14)
  19723. */
  19724. protected function getGraphicVars() {
  19725. $grapvars = array(
  19726. 'FontFamily' => $this->FontFamily,
  19727. 'FontStyle' => $this->FontStyle,
  19728. 'FontSizePt' => $this->FontSizePt,
  19729. 'rMargin' => $this->rMargin,
  19730. 'lMargin' => $this->lMargin,
  19731. 'cell_padding' => $this->cell_padding,
  19732. 'cell_margin' => $this->cell_margin,
  19733. 'LineWidth' => $this->LineWidth,
  19734. 'linestyleWidth' => $this->linestyleWidth,
  19735. 'linestyleCap' => $this->linestyleCap,
  19736. 'linestyleJoin' => $this->linestyleJoin,
  19737. 'linestyleDash' => $this->linestyleDash,
  19738. 'textrendermode' => $this->textrendermode,
  19739. 'textstrokewidth' => $this->textstrokewidth,
  19740. 'DrawColor' => $this->DrawColor,
  19741. 'FillColor' => $this->FillColor,
  19742. 'TextColor' => $this->TextColor,
  19743. 'ColorFlag' => $this->ColorFlag,
  19744. 'bgcolor' => $this->bgcolor,
  19745. 'fgcolor' => $this->fgcolor,
  19746. 'htmlvspace' => $this->htmlvspace,
  19747. 'listindent' => $this->listindent,
  19748. 'listindentlevel' => $this->listindentlevel,
  19749. 'listnum' => $this->listnum,
  19750. 'listordered' => $this->listordered,
  19751. 'listcount' => $this->listcount,
  19752. 'lispacer' => $this->lispacer,
  19753. 'cell_height_ratio' => $this->cell_height_ratio,
  19754. 'font_stretching' => $this->font_stretching,
  19755. 'font_spacing' => $this->font_spacing,
  19756. 'alpha' => $this->alpha,
  19757. // extended
  19758. 'lasth' => $this->lasth,
  19759. 'tMargin' => $this->tMargin,
  19760. 'bMargin' => $this->bMargin,
  19761. 'AutoPageBreak' => $this->AutoPageBreak,
  19762. 'PageBreakTrigger' => $this->PageBreakTrigger,
  19763. 'x' => $this->x,
  19764. 'y' => $this->y,
  19765. 'w' => $this->w,
  19766. 'h' => $this->h,
  19767. 'wPt' => $this->wPt,
  19768. 'hPt' => $this->hPt,
  19769. 'fwPt' => $this->fwPt,
  19770. 'fhPt' => $this->fhPt,
  19771. 'page' => $this->page,
  19772. 'current_column' => $this->current_column,
  19773. 'num_columns' => $this->num_columns
  19774. );
  19775. return $grapvars;
  19776. }
  19777. /**
  19778. * Set graphic variables.
  19779. * @param $gvars (array) array of graphic variablesto restore
  19780. * @param $extended (boolean) if true restore extended graphic variables
  19781. * @protected
  19782. * @since 4.2.010 (2008-11-14)
  19783. */
  19784. protected function setGraphicVars($gvars, $extended=false) {
  19785. if ($this->state != 2) {
  19786. return;
  19787. }
  19788. $this->FontFamily = $gvars['FontFamily'];
  19789. $this->FontStyle = $gvars['FontStyle'];
  19790. $this->FontSizePt = $gvars['FontSizePt'];
  19791. $this->rMargin = $gvars['rMargin'];
  19792. $this->lMargin = $gvars['lMargin'];
  19793. $this->cell_padding = $gvars['cell_padding'];
  19794. $this->cell_margin = $gvars['cell_margin'];
  19795. $this->LineWidth = $gvars['LineWidth'];
  19796. $this->linestyleWidth = $gvars['linestyleWidth'];
  19797. $this->linestyleCap = $gvars['linestyleCap'];
  19798. $this->linestyleJoin = $gvars['linestyleJoin'];
  19799. $this->linestyleDash = $gvars['linestyleDash'];
  19800. $this->textrendermode = $gvars['textrendermode'];
  19801. $this->textstrokewidth = $gvars['textstrokewidth'];
  19802. $this->DrawColor = $gvars['DrawColor'];
  19803. $this->FillColor = $gvars['FillColor'];
  19804. $this->TextColor = $gvars['TextColor'];
  19805. $this->ColorFlag = $gvars['ColorFlag'];
  19806. $this->bgcolor = $gvars['bgcolor'];
  19807. $this->fgcolor = $gvars['fgcolor'];
  19808. $this->htmlvspace = $gvars['htmlvspace'];
  19809. $this->listindent = $gvars['listindent'];
  19810. $this->listindentlevel = $gvars['listindentlevel'];
  19811. $this->listnum = $gvars['listnum'];
  19812. $this->listordered = $gvars['listordered'];
  19813. $this->listcount = $gvars['listcount'];
  19814. $this->lispacer = $gvars['lispacer'];
  19815. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  19816. $this->font_stretching = $gvars['font_stretching'];
  19817. $this->font_spacing = $gvars['font_spacing'];
  19818. $this->alpha = $gvars['alpha'];
  19819. if ($extended) {
  19820. // restore extended values
  19821. $this->lasth = $gvars['lasth'];
  19822. $this->tMargin = $gvars['tMargin'];
  19823. $this->bMargin = $gvars['bMargin'];
  19824. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  19825. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  19826. $this->x = $gvars['x'];
  19827. $this->y = $gvars['y'];
  19828. $this->w = $gvars['w'];
  19829. $this->h = $gvars['h'];
  19830. $this->wPt = $gvars['wPt'];
  19831. $this->hPt = $gvars['hPt'];
  19832. $this->fwPt = $gvars['fwPt'];
  19833. $this->fhPt = $gvars['fhPt'];
  19834. $this->page = $gvars['page'];
  19835. $this->current_column = $gvars['current_column'];
  19836. $this->num_columns = $gvars['num_columns'];
  19837. }
  19838. $this->_out(''.$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' '.$this->FillColor.'');
  19839. if (!TCPDF_STATIC::empty_string($this->FontFamily)) {
  19840. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  19841. }
  19842. }
  19843. /**
  19844. * Writes data to a temporary file on filesystem.
  19845. * @param $filename (string) file name
  19846. * @param $data (mixed) data to write on file
  19847. * @param $append (boolean) if true append data, false replace.
  19848. * @since 4.5.000 (2008-12-31)
  19849. * @protected
  19850. */
  19851. protected function writeDiskCache($filename, $data, $append=false) {
  19852. if ($append) {
  19853. $fmode = 'ab+';
  19854. } else {
  19855. $fmode = 'wb+';
  19856. }
  19857. $f = @fopen($filename, $fmode);
  19858. if (!$f) {
  19859. $this->Error('Unable to write cache file: '.$filename);
  19860. } else {
  19861. fwrite($f, $data);
  19862. fclose($f);
  19863. }
  19864. // update file length (needed for transactions)
  19865. if (!isset($this->cache_file_length['_'.$filename])) {
  19866. $this->cache_file_length['_'.$filename] = strlen($data);
  19867. } else {
  19868. $this->cache_file_length['_'.$filename] += strlen($data);
  19869. }
  19870. }
  19871. /**
  19872. * Read data from a temporary file on filesystem.
  19873. * @param $filename (string) file name
  19874. * @return mixed retrieved data
  19875. * @since 4.5.000 (2008-12-31)
  19876. * @protected
  19877. */
  19878. protected function readDiskCache($filename) {
  19879. return file_get_contents($filename);
  19880. }
  19881. /**
  19882. * Set buffer content (always append data).
  19883. * @param $data (string) data
  19884. * @protected
  19885. * @since 4.5.000 (2009-01-02)
  19886. */
  19887. protected function setBuffer($data) {
  19888. $this->bufferlen += strlen($data);
  19889. if ($this->diskcache) {
  19890. if (!isset($this->buffer) OR TCPDF_STATIC::empty_string($this->buffer)) {
  19891. $this->buffer = TCPDF_STATIC::getObjFilename('buf');
  19892. }
  19893. $this->writeDiskCache($this->buffer, $data, true);
  19894. } else {
  19895. $this->buffer .= $data;
  19896. }
  19897. }
  19898. /**
  19899. * Replace the buffer content
  19900. * @param $data (string) data
  19901. * @protected
  19902. * @since 5.5.000 (2010-06-22)
  19903. */
  19904. protected function replaceBuffer($data) {
  19905. $this->bufferlen = strlen($data);
  19906. if ($this->diskcache) {
  19907. if (!isset($this->buffer) OR TCPDF_STATIC::empty_string($this->buffer)) {
  19908. $this->buffer = TCPDF_STATIC::getObjFilename('buf');
  19909. }
  19910. $this->writeDiskCache($this->buffer, $data, false);
  19911. } else {
  19912. $this->buffer = $data;
  19913. }
  19914. }
  19915. /**
  19916. * Get buffer content.
  19917. * @return string buffer content
  19918. * @protected
  19919. * @since 4.5.000 (2009-01-02)
  19920. */
  19921. protected function getBuffer() {
  19922. if ($this->diskcache) {
  19923. return $this->readDiskCache($this->buffer);
  19924. } else {
  19925. return $this->buffer;
  19926. }
  19927. }
  19928. /**
  19929. * Set page buffer content.
  19930. * @param $page (int) page number
  19931. * @param $data (string) page data
  19932. * @param $append (boolean) if true append data, false replace.
  19933. * @protected
  19934. * @since 4.5.000 (2008-12-31)
  19935. */
  19936. protected function setPageBuffer($page, $data, $append=false) {
  19937. if ($this->diskcache) {
  19938. if (!isset($this->pages[$page])) {
  19939. $this->pages[$page] = TCPDF_STATIC::getObjFilename('page');
  19940. }
  19941. $this->writeDiskCache($this->pages[$page], $data, $append);
  19942. } else {
  19943. if ($append) {
  19944. $this->pages[$page] .= $data;
  19945. } else {
  19946. $this->pages[$page] = $data;
  19947. }
  19948. }
  19949. if ($append AND isset($this->pagelen[$page])) {
  19950. $this->pagelen[$page] += strlen($data);
  19951. } else {
  19952. $this->pagelen[$page] = strlen($data);
  19953. }
  19954. }
  19955. /**
  19956. * Get page buffer content.
  19957. * @param $page (int) page number
  19958. * @return string page buffer content or false in case of error
  19959. * @protected
  19960. * @since 4.5.000 (2008-12-31)
  19961. */
  19962. protected function getPageBuffer($page) {
  19963. if ($this->diskcache) {
  19964. return $this->readDiskCache($this->pages[$page]);
  19965. } elseif (isset($this->pages[$page])) {
  19966. return $this->pages[$page];
  19967. }
  19968. return false;
  19969. }
  19970. /**
  19971. * Set image buffer content.
  19972. * @param $image (string) image key
  19973. * @param $data (array) image data
  19974. * @return int image index number
  19975. * @protected
  19976. * @since 4.5.000 (2008-12-31)
  19977. */
  19978. protected function setImageBuffer($image, $data) {
  19979. if (($data['i'] = array_search($image, $this->imagekeys)) === FALSE) {
  19980. $this->imagekeys[$this->numimages] = $image;
  19981. $data['i'] = $this->numimages;
  19982. ++$this->numimages;
  19983. }
  19984. if ($this->diskcache) {
  19985. if (!isset($this->images[$image])) {
  19986. $this->images[$image] = TCPDF_STATIC::getObjFilename('img');
  19987. }
  19988. $this->writeDiskCache($this->images[$image], serialize($data));
  19989. } else {
  19990. $this->images[$image] = $data;
  19991. }
  19992. return $data['i'];
  19993. }
  19994. /**
  19995. * Set image buffer content for a specified sub-key.
  19996. * @param $image (string) image key
  19997. * @param $key (string) image sub-key
  19998. * @param $data (array) image data
  19999. * @protected
  20000. * @since 4.5.000 (2008-12-31)
  20001. */
  20002. protected function setImageSubBuffer($image, $key, $data) {
  20003. if (!isset($this->images[$image])) {
  20004. $this->setImageBuffer($image, array());
  20005. }
  20006. if ($this->diskcache) {
  20007. $tmpimg = $this->getImageBuffer($image);
  20008. $tmpimg[$key] = $data;
  20009. $this->writeDiskCache($this->images[$image], serialize($tmpimg));
  20010. } else {
  20011. $this->images[$image][$key] = $data;
  20012. }
  20013. }
  20014. /**
  20015. * Get image buffer content.
  20016. * @param $image (string) image key
  20017. * @return string image buffer content or false in case of error
  20018. * @protected
  20019. * @since 4.5.000 (2008-12-31)
  20020. */
  20021. protected function getImageBuffer($image) {
  20022. if ($this->diskcache AND isset($this->images[$image])) {
  20023. return unserialize($this->readDiskCache($this->images[$image]));
  20024. } elseif (isset($this->images[$image])) {
  20025. return $this->images[$image];
  20026. }
  20027. return false;
  20028. }
  20029. /**
  20030. * Set font buffer content.
  20031. * @param $font (string) font key
  20032. * @param $data (array) font data
  20033. * @protected
  20034. * @since 4.5.000 (2009-01-02)
  20035. */
  20036. protected function setFontBuffer($font, $data) {
  20037. if ($this->diskcache) {
  20038. if (!isset($this->fonts[$font])) {
  20039. $this->fonts[$font] = TCPDF_STATIC::getObjFilename('font');
  20040. }
  20041. $this->writeDiskCache($this->fonts[$font], serialize($data));
  20042. } else {
  20043. $this->fonts[$font] = $data;
  20044. }
  20045. if (!in_array($font, $this->fontkeys)) {
  20046. $this->fontkeys[] = $font;
  20047. // store object ID for current font
  20048. ++$this->n;
  20049. $this->font_obj_ids[$font] = $this->n;
  20050. $this->setFontSubBuffer($font, 'n', $this->n);
  20051. }
  20052. }
  20053. /**
  20054. * Set font buffer content.
  20055. * @param $font (string) font key
  20056. * @param $key (string) font sub-key
  20057. * @param $data (array) font data
  20058. * @protected
  20059. * @since 4.5.000 (2009-01-02)
  20060. */
  20061. protected function setFontSubBuffer($font, $key, $data) {
  20062. if (!isset($this->fonts[$font])) {
  20063. $this->setFontBuffer($font, array());
  20064. }
  20065. if ($this->diskcache) {
  20066. $tmpfont = $this->getFontBuffer($font);
  20067. $tmpfont[$key] = $data;
  20068. $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
  20069. } else {
  20070. $this->fonts[$font][$key] = $data;
  20071. }
  20072. }
  20073. /**
  20074. * Get font buffer content.
  20075. * @param $font (string) font key
  20076. * @return string font buffer content or false in case of error
  20077. * @protected
  20078. * @since 4.5.000 (2009-01-02)
  20079. */
  20080. protected function getFontBuffer($font) {
  20081. if ($this->diskcache AND isset($this->fonts[$font])) {
  20082. return unserialize($this->readDiskCache($this->fonts[$font]));
  20083. } elseif (isset($this->fonts[$font])) {
  20084. return $this->fonts[$font];
  20085. }
  20086. return false;
  20087. }
  20088. /**
  20089. * Move a page to a previous position.
  20090. * @param $frompage (int) number of the source page
  20091. * @param $topage (int) number of the destination page (must be less than $frompage)
  20092. * @return true in case of success, false in case of error.
  20093. * @public
  20094. * @since 4.5.000 (2009-01-02)
  20095. */
  20096. public function movePage($frompage, $topage) {
  20097. if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
  20098. return false;
  20099. }
  20100. if ($frompage == $this->page) {
  20101. // close the page before moving it
  20102. $this->endPage();
  20103. }
  20104. // move all page-related states
  20105. $tmppage = $this->getPageBuffer($frompage);
  20106. $tmppagedim = $this->pagedim[$frompage];
  20107. $tmppagelen = $this->pagelen[$frompage];
  20108. $tmpintmrk = $this->intmrk[$frompage];
  20109. $tmpbordermrk = $this->bordermrk[$frompage];
  20110. $tmpcntmrk = $this->cntmrk[$frompage];
  20111. $tmppageobjects = $this->pageobjects[$frompage];
  20112. if (isset($this->footerpos[$frompage])) {
  20113. $tmpfooterpos = $this->footerpos[$frompage];
  20114. }
  20115. if (isset($this->footerlen[$frompage])) {
  20116. $tmpfooterlen = $this->footerlen[$frompage];
  20117. }
  20118. if (isset($this->transfmrk[$frompage])) {
  20119. $tmptransfmrk = $this->transfmrk[$frompage];
  20120. }
  20121. if (isset($this->PageAnnots[$frompage])) {
  20122. $tmpannots = $this->PageAnnots[$frompage];
  20123. }
  20124. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20125. for ($i = $frompage; $i > $topage; --$i) {
  20126. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $frompage)) {
  20127. --$this->pagegroups[$this->newpagegroup[$i]];
  20128. break;
  20129. }
  20130. }
  20131. for ($i = $topage; $i > 0; --$i) {
  20132. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $topage)) {
  20133. ++$this->pagegroups[$this->newpagegroup[$i]];
  20134. break;
  20135. }
  20136. }
  20137. }
  20138. for ($i = $frompage; $i > $topage; --$i) {
  20139. $j = $i - 1;
  20140. // shift pages down
  20141. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20142. $this->pagedim[$i] = $this->pagedim[$j];
  20143. $this->pagelen[$i] = $this->pagelen[$j];
  20144. $this->intmrk[$i] = $this->intmrk[$j];
  20145. $this->bordermrk[$i] = $this->bordermrk[$j];
  20146. $this->cntmrk[$i] = $this->cntmrk[$j];
  20147. $this->pageobjects[$i] = $this->pageobjects[$j];
  20148. if (isset($this->footerpos[$j])) {
  20149. $this->footerpos[$i] = $this->footerpos[$j];
  20150. } elseif (isset($this->footerpos[$i])) {
  20151. unset($this->footerpos[$i]);
  20152. }
  20153. if (isset($this->footerlen[$j])) {
  20154. $this->footerlen[$i] = $this->footerlen[$j];
  20155. } elseif (isset($this->footerlen[$i])) {
  20156. unset($this->footerlen[$i]);
  20157. }
  20158. if (isset($this->transfmrk[$j])) {
  20159. $this->transfmrk[$i] = $this->transfmrk[$j];
  20160. } elseif (isset($this->transfmrk[$i])) {
  20161. unset($this->transfmrk[$i]);
  20162. }
  20163. if (isset($this->PageAnnots[$j])) {
  20164. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20165. } elseif (isset($this->PageAnnots[$i])) {
  20166. unset($this->PageAnnots[$i]);
  20167. }
  20168. if (isset($this->newpagegroup[$j])) {
  20169. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20170. unset($this->newpagegroup[$j]);
  20171. }
  20172. if ($this->currpagegroup == $j) {
  20173. $this->currpagegroup = $i;
  20174. }
  20175. }
  20176. $this->setPageBuffer($topage, $tmppage);
  20177. $this->pagedim[$topage] = $tmppagedim;
  20178. $this->pagelen[$topage] = $tmppagelen;
  20179. $this->intmrk[$topage] = $tmpintmrk;
  20180. $this->bordermrk[$topage] = $tmpbordermrk;
  20181. $this->cntmrk[$topage] = $tmpcntmrk;
  20182. $this->pageobjects[$topage] = $tmppageobjects;
  20183. if (isset($tmpfooterpos)) {
  20184. $this->footerpos[$topage] = $tmpfooterpos;
  20185. } elseif (isset($this->footerpos[$topage])) {
  20186. unset($this->footerpos[$topage]);
  20187. }
  20188. if (isset($tmpfooterlen)) {
  20189. $this->footerlen[$topage] = $tmpfooterlen;
  20190. } elseif (isset($this->footerlen[$topage])) {
  20191. unset($this->footerlen[$topage]);
  20192. }
  20193. if (isset($tmptransfmrk)) {
  20194. $this->transfmrk[$topage] = $tmptransfmrk;
  20195. } elseif (isset($this->transfmrk[$topage])) {
  20196. unset($this->transfmrk[$topage]);
  20197. }
  20198. if (isset($tmpannots)) {
  20199. $this->PageAnnots[$topage] = $tmpannots;
  20200. } elseif (isset($this->PageAnnots[$topage])) {
  20201. unset($this->PageAnnots[$topage]);
  20202. }
  20203. // adjust outlines
  20204. $tmpoutlines = $this->outlines;
  20205. foreach ($tmpoutlines as $key => $outline) {
  20206. if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
  20207. $this->outlines[$key]['p'] = ($outline['p'] + 1);
  20208. } elseif ($outline['p'] == $frompage) {
  20209. $this->outlines[$key]['p'] = $topage;
  20210. }
  20211. }
  20212. // adjust dests
  20213. $tmpdests = $this->dests;
  20214. foreach ($tmpdests as $key => $dest) {
  20215. if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
  20216. $this->dests[$key]['p'] = ($dest['p'] + 1);
  20217. } elseif ($dest['p'] == $frompage) {
  20218. $this->dests[$key]['p'] = $topage;
  20219. }
  20220. }
  20221. // adjust links
  20222. $tmplinks = $this->links;
  20223. foreach ($tmplinks as $key => $link) {
  20224. if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
  20225. $this->links[$key][0] = ($link[0] + 1);
  20226. } elseif ($link[0] == $frompage) {
  20227. $this->links[$key][0] = $topage;
  20228. }
  20229. }
  20230. // adjust javascript
  20231. $tmpjavascript = $this->javascript;
  20232. global $jfrompage, $jtopage;
  20233. $jfrompage = $frompage;
  20234. $jtopage = $topage;
  20235. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  20236. create_function('$matches', 'global $jfrompage, $jtopage;
  20237. $pagenum = intval($matches[3]) + 1;
  20238. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  20239. $newpage = ($pagenum + 1);
  20240. } elseif ($pagenum == $jfrompage) {
  20241. $newpage = $jtopage;
  20242. } else {
  20243. $newpage = $pagenum;
  20244. }
  20245. --$newpage;
  20246. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  20247. // return to last page
  20248. $this->lastPage(true);
  20249. return true;
  20250. }
  20251. /**
  20252. * Remove the specified page.
  20253. * @param $page (int) page to remove
  20254. * @return true in case of success, false in case of error.
  20255. * @public
  20256. * @since 4.6.004 (2009-04-23)
  20257. */
  20258. public function deletePage($page) {
  20259. if (($page < 1) OR ($page > $this->numpages)) {
  20260. return false;
  20261. }
  20262. // delete current page
  20263. unset($this->pages[$page]);
  20264. unset($this->pagedim[$page]);
  20265. unset($this->pagelen[$page]);
  20266. unset($this->intmrk[$page]);
  20267. unset($this->bordermrk[$page]);
  20268. unset($this->cntmrk[$page]);
  20269. foreach ($this->pageobjects[$page] as $oid) {
  20270. if (isset($this->offsets[$oid])){
  20271. unset($this->offsets[$oid]);
  20272. }
  20273. }
  20274. unset($this->pageobjects[$page]);
  20275. if (isset($this->footerpos[$page])) {
  20276. unset($this->footerpos[$page]);
  20277. }
  20278. if (isset($this->footerlen[$page])) {
  20279. unset($this->footerlen[$page]);
  20280. }
  20281. if (isset($this->transfmrk[$page])) {
  20282. unset($this->transfmrk[$page]);
  20283. }
  20284. if (isset($this->PageAnnots[$page])) {
  20285. unset($this->PageAnnots[$page]);
  20286. }
  20287. if (isset($this->newpagegroup) AND !empty($this->newpagegroup)) {
  20288. for ($i = $page; $i > 0; --$i) {
  20289. if (isset($this->newpagegroup[$i]) AND (($i + $this->pagegroups[$this->newpagegroup[$i]]) > $page)) {
  20290. --$this->pagegroups[$this->newpagegroup[$i]];
  20291. break;
  20292. }
  20293. }
  20294. }
  20295. if (isset($this->pageopen[$page])) {
  20296. unset($this->pageopen[$page]);
  20297. }
  20298. if ($page < $this->numpages) {
  20299. // update remaining pages
  20300. for ($i = $page; $i < $this->numpages; ++$i) {
  20301. $j = $i + 1;
  20302. // shift pages
  20303. $this->setPageBuffer($i, $this->getPageBuffer($j));
  20304. $this->pagedim[$i] = $this->pagedim[$j];
  20305. $this->pagelen[$i] = $this->pagelen[$j];
  20306. $this->intmrk[$i] = $this->intmrk[$j];
  20307. $this->bordermrk[$i] = $this->bordermrk[$j];
  20308. $this->cntmrk[$i] = $this->cntmrk[$j];
  20309. $this->pageobjects[$i] = $this->pageobjects[$j];
  20310. if (isset($this->footerpos[$j])) {
  20311. $this->footerpos[$i] = $this->footerpos[$j];
  20312. } elseif (isset($this->footerpos[$i])) {
  20313. unset($this->footerpos[$i]);
  20314. }
  20315. if (isset($this->footerlen[$j])) {
  20316. $this->footerlen[$i] = $this->footerlen[$j];
  20317. } elseif (isset($this->footerlen[$i])) {
  20318. unset($this->footerlen[$i]);
  20319. }
  20320. if (isset($this->transfmrk[$j])) {
  20321. $this->transfmrk[$i] = $this->transfmrk[$j];
  20322. } elseif (isset($this->transfmrk[$i])) {
  20323. unset($this->transfmrk[$i]);
  20324. }
  20325. if (isset($this->PageAnnots[$j])) {
  20326. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  20327. } elseif (isset($this->PageAnnots[$i])) {
  20328. unset($this->PageAnnots[$i]);
  20329. }
  20330. if (isset($this->newpagegroup[$j])) {
  20331. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  20332. unset($this->newpagegroup[$j]);
  20333. }
  20334. if ($this->currpagegroup == $j) {
  20335. $this->currpagegroup = $i;
  20336. }
  20337. if (isset($this->pageopen[$j])) {
  20338. $this->pageopen[$i] = $this->pageopen[$j];
  20339. } elseif (isset($this->pageopen[$i])) {
  20340. unset($this->pageopen[$i]);
  20341. }
  20342. }
  20343. // remove last page
  20344. unset($this->pages[$this->numpages]);
  20345. unset($this->pagedim[$this->numpages]);
  20346. unset($this->pagelen[$this->numpages]);
  20347. unset($this->intmrk[$this->numpages]);
  20348. unset($this->bordermrk[$this->numpages]);
  20349. unset($this->cntmrk[$this->numpages]);
  20350. foreach ($this->pageobjects[$this->numpages] as $oid) {
  20351. if (isset($this->offsets[$oid])){
  20352. unset($this->offsets[$oid]);
  20353. }
  20354. }
  20355. unset($this->pageobjects[$this->numpages]);
  20356. if (isset($this->footerpos[$this->numpages])) {
  20357. unset($this->footerpos[$this->numpages]);
  20358. }
  20359. if (isset($this->footerlen[$this->numpages])) {
  20360. unset($this->footerlen[$this->numpages]);
  20361. }
  20362. if (isset($this->transfmrk[$this->numpages])) {
  20363. unset($this->transfmrk[$this->numpages]);
  20364. }
  20365. if (isset($this->PageAnnots[$this->numpages])) {
  20366. unset($this->PageAnnots[$this->numpages]);
  20367. }
  20368. if (isset($this->newpagegroup[$this->numpages])) {
  20369. unset($this->newpagegroup[$this->numpages]);
  20370. }
  20371. if ($this->currpagegroup == $this->numpages) {
  20372. $this->currpagegroup = ($this->numpages - 1);
  20373. }
  20374. if (isset($this->pagegroups[$this->numpages])) {
  20375. unset($this->pagegroups[$this->numpages]);
  20376. }
  20377. if (isset($this->pageopen[$this->numpages])) {
  20378. unset($this->pageopen[$this->numpages]);
  20379. }
  20380. }
  20381. --$this->numpages;
  20382. $this->page = $this->numpages;
  20383. // adjust outlines
  20384. $tmpoutlines = $this->outlines;
  20385. foreach ($tmpoutlines as $key => $outline) {
  20386. if ($outline['p'] > $page) {
  20387. $this->outlines[$key]['p'] = $outline['p'] - 1;
  20388. } elseif ($outline['p'] == $page) {
  20389. unset($this->outlines[$key]);
  20390. }
  20391. }
  20392. // adjust dests
  20393. $tmpdests = $this->dests;
  20394. foreach ($tmpdests as $key => $dest) {
  20395. if ($dest['p'] > $page) {
  20396. $this->dests[$key]['p'] = $dest['p'] - 1;
  20397. } elseif ($dest['p'] == $page) {
  20398. unset($this->dests[$key]);
  20399. }
  20400. }
  20401. // adjust links
  20402. $tmplinks = $this->links;
  20403. foreach ($tmplinks as $key => $link) {
  20404. if ($link[0] > $page) {
  20405. $this->links[$key][0] = $link[0] - 1;
  20406. } elseif ($link[0] == $page) {
  20407. unset($this->links[$key]);
  20408. }
  20409. }
  20410. // adjust javascript
  20411. $tmpjavascript = $this->javascript;
  20412. global $jpage;
  20413. $jpage = $page;
  20414. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
  20415. create_function('$matches', 'global $jpage;
  20416. $pagenum = intval($matches[3]) + 1;
  20417. if ($pagenum >= $jpage) {
  20418. $newpage = ($pagenum - 1);
  20419. } elseif ($pagenum == $jpage) {
  20420. $newpage = 1;
  20421. } else {
  20422. $newpage = $pagenum;
  20423. }
  20424. --$newpage;
  20425. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  20426. // return to last page
  20427. if ($this->numpages > 0) {
  20428. $this->lastPage(true);
  20429. }
  20430. return true;
  20431. }
  20432. /**
  20433. * Clone the specified page to a new page.
  20434. * @param $page (int) number of page to copy (0 = current page)
  20435. * @return true in case of success, false in case of error.
  20436. * @public
  20437. * @since 4.9.015 (2010-04-20)
  20438. */
  20439. public function copyPage($page=0) {
  20440. if ($page == 0) {
  20441. // default value
  20442. $page = $this->page;
  20443. }
  20444. if (($page < 1) OR ($page > $this->numpages)) {
  20445. return false;
  20446. }
  20447. // close the last page
  20448. $this->endPage();
  20449. // copy all page-related states
  20450. ++$this->numpages;
  20451. $this->page = $this->numpages;
  20452. $this->setPageBuffer($this->page, $this->getPageBuffer($page));
  20453. $this->pagedim[$this->page] = $this->pagedim[$page];
  20454. $this->pagelen[$this->page] = $this->pagelen[$page];
  20455. $this->intmrk[$this->page] = $this->intmrk[$page];
  20456. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  20457. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  20458. $this->pageobjects[$this->page] = $this->pageobjects[$page];
  20459. $this->pageopen[$this->page] = false;
  20460. if (isset($this->footerpos[$page])) {
  20461. $this->footerpos[$this->page] = $this->footerpos[$page];
  20462. }
  20463. if (isset($this->footerlen[$page])) {
  20464. $this->footerlen[$this->page] = $this->footerlen[$page];
  20465. }
  20466. if (isset($this->transfmrk[$page])) {
  20467. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  20468. }
  20469. if (isset($this->PageAnnots[$page])) {
  20470. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  20471. }
  20472. if (isset($this->newpagegroup[$page])) {
  20473. // start a new group
  20474. $this->newpagegroup[$this->page] = sizeof($this->newpagegroup) + 1;
  20475. $this->currpagegroup = $this->newpagegroup[$this->page];
  20476. $this->pagegroups[$this->currpagegroup] = 1;
  20477. } elseif (isset($this->currpagegroup) AND ($this->currpagegroup > 0)) {
  20478. ++$this->pagegroups[$this->currpagegroup];
  20479. }
  20480. // copy outlines
  20481. $tmpoutlines = $this->outlines;
  20482. foreach ($tmpoutlines as $key => $outline) {
  20483. if ($outline['p'] == $page) {
  20484. $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page, 's' => $outline['s'], 'c' => $outline['c']);
  20485. }
  20486. }
  20487. // copy links
  20488. $tmplinks = $this->links;
  20489. foreach ($tmplinks as $key => $link) {
  20490. if ($link[0] == $page) {
  20491. $this->links[] = array($this->page, $link[1]);
  20492. }
  20493. }
  20494. // return to last page
  20495. $this->lastPage(true);
  20496. return true;
  20497. }
  20498. /**
  20499. * Output a Table of Content Index (TOC).
  20500. * This method must be called after all Bookmarks were set.
  20501. * Before calling this method you have to open the page using the addTOCPage() method.
  20502. * After calling this method you have to call endTOCPage() to close the TOC page.
  20503. * You can override this method to achieve different styles.
  20504. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  20505. * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
  20506. * @param $filler (string) string used to fill the space between text and page number.
  20507. * @param $toc_name (string) name to use for TOC bookmark.
  20508. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20509. * @param $color (array) RGB color array for bookmark title (values from 0 to 255).
  20510. * @public
  20511. * @author Nicola Asuni
  20512. * @since 4.5.000 (2009-01-02)
  20513. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  20514. */
  20515. public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
  20516. $fontsize = $this->FontSizePt;
  20517. $fontfamily = $this->FontFamily;
  20518. $fontstyle = $this->FontStyle;
  20519. $w = $this->w - $this->lMargin - $this->rMargin;
  20520. $spacer = $this->GetStringWidth(chr(32)) * 4;
  20521. $lmargin = $this->lMargin;
  20522. $rmargin = $this->rMargin;
  20523. $x_start = $this->GetX();
  20524. $page_first = $this->page;
  20525. $current_page = $this->page;
  20526. $page_fill_start = false;
  20527. $page_fill_end = false;
  20528. $current_column = $this->current_column;
  20529. if (TCPDF_STATIC::empty_string($numbersfont)) {
  20530. $numbersfont = $this->default_monospaced_font;
  20531. }
  20532. if (TCPDF_STATIC::empty_string($filler)) {
  20533. $filler = ' ';
  20534. }
  20535. if (TCPDF_STATIC::empty_string($page)) {
  20536. $gap = ' ';
  20537. } else {
  20538. $gap = '';
  20539. if ($page < 1) {
  20540. $page = 1;
  20541. }
  20542. }
  20543. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  20544. $numwidth = $this->GetStringWidth('00000');
  20545. $maxpage = 0; //used for pages on attached documents
  20546. foreach ($this->outlines as $key => $outline) {
  20547. // check for extra pages (used for attachments)
  20548. if (($this->page > $page_first) AND ($outline['p'] >= $this->numpages)) {
  20549. $outline['p'] += ($this->page - $page_first);
  20550. }
  20551. if ($this->rtl) {
  20552. $aligntext = 'R';
  20553. $alignnum = 'L';
  20554. } else {
  20555. $aligntext = 'L';
  20556. $alignnum = 'R';
  20557. }
  20558. if ($outline['l'] == 0) {
  20559. $this->SetFont($fontfamily, $outline['s'].'B', $fontsize);
  20560. } else {
  20561. $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
  20562. }
  20563. $this->SetTextColorArray($outline['c']);
  20564. // check for page break
  20565. $this->checkPageBreak((2 * $this->FontSize * $this->cell_height_ratio));
  20566. // set margins and X position
  20567. if (($this->page == $current_page) AND ($this->current_column == $current_column)) {
  20568. $this->lMargin = $lmargin;
  20569. $this->rMargin = $rmargin;
  20570. } else {
  20571. if ($this->current_column != $current_column) {
  20572. if ($this->rtl) {
  20573. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  20574. } else {
  20575. $x_start = $this->columns[$this->current_column]['x'];
  20576. }
  20577. }
  20578. $lmargin = $this->lMargin;
  20579. $rmargin = $this->rMargin;
  20580. $current_page = $this->page;
  20581. $current_column = $this->current_column;
  20582. }
  20583. $this->SetX($x_start);
  20584. $indent = ($spacer * $outline['l']);
  20585. if ($this->rtl) {
  20586. $this->x -= $indent;
  20587. $this->rMargin = $this->w - $this->x;
  20588. } else {
  20589. $this->x += $indent;
  20590. $this->lMargin = $this->x;
  20591. }
  20592. $link = $this->AddLink();
  20593. $this->SetLink($link, $outline['y'], $outline['p']);
  20594. // write the text
  20595. if ($this->rtl) {
  20596. $txt = ' '.$outline['t'];
  20597. } else {
  20598. $txt = $outline['t'].' ';
  20599. }
  20600. $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
  20601. if ($this->rtl) {
  20602. $tw = $this->x - $this->lMargin;
  20603. } else {
  20604. $tw = $this->w - $this->rMargin - $this->x;
  20605. }
  20606. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  20607. if (TCPDF_STATIC::empty_string($page)) {
  20608. $pagenum = $outline['p'];
  20609. } else {
  20610. // placemark to be replaced with the correct number
  20611. $pagenum = '{#'.($outline['p']).'}';
  20612. if ($this->isUnicodeFont()) {
  20613. $pagenum = '{'.$pagenum.'}';
  20614. }
  20615. $maxpage = max($maxpage, $outline['p']);
  20616. }
  20617. $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
  20618. $wfiller = $this->GetStringWidth($filler);
  20619. if ($wfiller > 0) {
  20620. $numfills = floor($fw / $wfiller);
  20621. } else {
  20622. $numfills = 0;
  20623. }
  20624. if ($numfills > 0) {
  20625. $rowfill = str_repeat($filler, $numfills);
  20626. } else {
  20627. $rowfill = '';
  20628. }
  20629. if ($this->rtl) {
  20630. $pagenum = $pagenum.$gap.$rowfill;
  20631. } else {
  20632. $pagenum = $rowfill.$gap.$pagenum;
  20633. }
  20634. // write the number
  20635. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  20636. }
  20637. $page_last = $this->getPage();
  20638. $numpages = ($page_last - $page_first + 1);
  20639. // account for booklet mode
  20640. if ($this->booklet) {
  20641. // check if a blank page is required before TOC
  20642. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20643. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20644. if ($page_fill_start) {
  20645. // add a page at the end (to be moved before TOC)
  20646. $this->addPage();
  20647. ++$page_last;
  20648. ++$numpages;
  20649. }
  20650. if ($page_fill_end) {
  20651. // add a page at the end
  20652. $this->addPage();
  20653. ++$page_last;
  20654. ++$numpages;
  20655. }
  20656. }
  20657. $maxpage = max($maxpage, $page_last);
  20658. if (!TCPDF_STATIC::empty_string($page)) {
  20659. for ($p = $page_first; $p <= $page_last; ++$p) {
  20660. // get page data
  20661. $temppage = $this->getPageBuffer($p);
  20662. for ($n = 1; $n <= $maxpage; ++$n) {
  20663. // update page numbers
  20664. $a = '{#'.$n.'}';
  20665. // get page number aliases
  20666. $pnalias = $this->getInternalPageNumberAliases($a);
  20667. // calculate replacement number
  20668. if (($n >= $page) AND ($n <= $this->numpages)) {
  20669. $np = $n + $numpages;
  20670. } else {
  20671. $np = $n;
  20672. }
  20673. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20674. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20675. // replace aliases with numbers
  20676. foreach ($pnalias['u'] as $u) {
  20677. $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
  20678. if ($this->rtl) {
  20679. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20680. } else {
  20681. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20682. }
  20683. $temppage = str_replace($u, $nr, $temppage);
  20684. }
  20685. foreach ($pnalias['a'] as $a) {
  20686. $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
  20687. if ($this->rtl) {
  20688. $nr = $na.' '.$sfill;
  20689. } else {
  20690. $nr = $sfill.' '.$na;
  20691. }
  20692. $temppage = str_replace($a, $nr, $temppage);
  20693. }
  20694. }
  20695. // save changes
  20696. $this->setPageBuffer($p, $temppage);
  20697. }
  20698. // move pages
  20699. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  20700. if ($page_fill_start) {
  20701. $this->movePage($page_last, $page_first);
  20702. }
  20703. for ($i = 0; $i < $numpages; ++$i) {
  20704. $this->movePage($page_last, $page);
  20705. }
  20706. }
  20707. }
  20708. /**
  20709. * Output a Table Of Content Index (TOC) using HTML templates.
  20710. * This method must be called after all Bookmarks were set.
  20711. * Before calling this method you have to open the page using the addTOCPage() method.
  20712. * After calling this method you have to call endTOCPage() to close the TOC page.
  20713. * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
  20714. * @param $toc_name (string) name to use for TOC bookmark.
  20715. * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
  20716. * @param $correct_align (boolean) if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
  20717. * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
  20718. * @param $color (array) RGB color array for title (values from 0 to 255).
  20719. * @public
  20720. * @author Nicola Asuni
  20721. * @since 5.0.001 (2010-05-06)
  20722. * @see addTOCPage(), endTOCPage(), addTOC()
  20723. */
  20724. public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
  20725. $filler = ' ';
  20726. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  20727. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  20728. // set new style for link
  20729. $this->htmlLinkColorArray = array();
  20730. $this->htmlLinkFontStyle = '';
  20731. $page_first = $this->getPage();
  20732. $page_fill_start = false;
  20733. $page_fill_end = false;
  20734. // get the font type used for numbers in each template
  20735. $current_font = $this->FontFamily;
  20736. foreach ($templates as $level => $html) {
  20737. $dom = $this->getHtmlDomArray($html);
  20738. foreach ($dom as $key => $value) {
  20739. if ($value['value'] == '#TOC_PAGE_NUMBER#') {
  20740. $this->SetFont($dom[($key - 1)]['fontname']);
  20741. $templates['F'.$level] = $this->isUnicodeFont();
  20742. }
  20743. }
  20744. }
  20745. $this->SetFont($current_font);
  20746. $maxpage = 0; //used for pages on attached documents
  20747. foreach ($this->outlines as $key => $outline) {
  20748. // get HTML template
  20749. $row = $templates[$outline['l']];
  20750. if (TCPDF_STATIC::empty_string($page)) {
  20751. $pagenum = $outline['p'];
  20752. } else {
  20753. // placemark to be replaced with the correct number
  20754. $pagenum = '{#'.($outline['p']).'}';
  20755. if ($templates['F'.$outline['l']]) {
  20756. $pagenum = '{'.$pagenum.'}';
  20757. }
  20758. $maxpage = max($maxpage, $outline['p']);
  20759. }
  20760. // replace templates with current values
  20761. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  20762. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  20763. // add link to page
  20764. $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
  20765. // write bookmark entry
  20766. $this->writeHTML($row, false, false, true, false, '');
  20767. }
  20768. // restore link styles
  20769. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  20770. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  20771. // move TOC page and replace numbers
  20772. $page_last = $this->getPage();
  20773. $numpages = ($page_last - $page_first + 1);
  20774. // account for booklet mode
  20775. if ($this->booklet) {
  20776. // check if a blank page is required before TOC
  20777. $page_fill_start = ((($page_first % 2) == 0) XOR (($page % 2) == 0));
  20778. $page_fill_end = (!((($numpages % 2) == 0) XOR ($page_fill_start)));
  20779. if ($page_fill_start) {
  20780. // add a page at the end (to be moved before TOC)
  20781. $this->addPage();
  20782. ++$page_last;
  20783. ++$numpages;
  20784. }
  20785. if ($page_fill_end) {
  20786. // add a page at the end
  20787. $this->addPage();
  20788. ++$page_last;
  20789. ++$numpages;
  20790. }
  20791. }
  20792. $maxpage = max($maxpage, $page_last);
  20793. if (!TCPDF_STATIC::empty_string($page)) {
  20794. for ($p = $page_first; $p <= $page_last; ++$p) {
  20795. // get page data
  20796. $temppage = $this->getPageBuffer($p);
  20797. for ($n = 1; $n <= $maxpage; ++$n) {
  20798. // update page numbers
  20799. $a = '{#'.$n.'}';
  20800. // get page number aliases
  20801. $pnalias = $this->getInternalPageNumberAliases($a);
  20802. // calculate replacement number
  20803. if ($n >= $page) {
  20804. $np = $n + $numpages;
  20805. } else {
  20806. $np = $n;
  20807. }
  20808. $na = TCPDF_STATIC::formatTOCPageNumber(($this->starting_page_number + $np - 1));
  20809. $nu = TCPDF_FONTS::UTF8ToUTF16BE($na, false, $this->isunicode, $this->CurrentFont);
  20810. // replace aliases with numbers
  20811. foreach ($pnalias['u'] as $u) {
  20812. if ($correct_align) {
  20813. $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
  20814. if ($this->rtl) {
  20815. $nr = $nu.TCPDF_FONTS::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode, $this->CurrentFont);
  20816. } else {
  20817. $nr = TCPDF_FONTS::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode, $this->CurrentFont).$nu;
  20818. }
  20819. } else {
  20820. $nr = $nu;
  20821. }
  20822. $temppage = str_replace($u, $nr, $temppage);
  20823. }
  20824. foreach ($pnalias['a'] as $a) {
  20825. if ($correct_align) {
  20826. $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
  20827. if ($this->rtl) {
  20828. $nr = $na.' '.$sfill;
  20829. } else {
  20830. $nr = $sfill.' '.$na;
  20831. }
  20832. } else {
  20833. $nr = $na;
  20834. }
  20835. $temppage = str_replace($a, $nr, $temppage);
  20836. }
  20837. }
  20838. // save changes
  20839. $this->setPageBuffer($p, $temppage);
  20840. }
  20841. // move pages
  20842. $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
  20843. if ($page_fill_start) {
  20844. $this->movePage($page_last, $page_first);
  20845. }
  20846. for ($i = 0; $i < $numpages; ++$i) {
  20847. $this->movePage($page_last, $page);
  20848. }
  20849. }
  20850. }
  20851. /**
  20852. * Stores a copy of the current TCPDF object used for undo operation.
  20853. * @public
  20854. * @since 4.5.029 (2009-03-19)
  20855. */
  20856. public function startTransaction() {
  20857. if (isset($this->objcopy)) {
  20858. // remove previous copy
  20859. $this->commitTransaction();
  20860. }
  20861. // record current page number and Y position
  20862. $this->start_transaction_page = $this->page;
  20863. $this->start_transaction_y = $this->y;
  20864. // clone current object
  20865. $this->objcopy = TCPDF_STATIC::objclone($this);
  20866. }
  20867. /**
  20868. * Delete the copy of the current TCPDF object used for undo operation.
  20869. * @public
  20870. * @since 4.5.029 (2009-03-19)
  20871. */
  20872. public function commitTransaction() {
  20873. if (isset($this->objcopy)) {
  20874. $this->objcopy->_destroy(true, true);
  20875. unset($this->objcopy);
  20876. }
  20877. }
  20878. /**
  20879. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  20880. * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
  20881. * @return TCPDF object.
  20882. * @public
  20883. * @since 4.5.029 (2009-03-19)
  20884. */
  20885. public function rollbackTransaction($self=false) {
  20886. if (isset($this->objcopy)) {
  20887. if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) {
  20888. // truncate files to previous values
  20889. foreach ($this->objcopy->cache_file_length as $file => $length) {
  20890. $file = substr($file, 1);
  20891. $handle = fopen($file, 'r+');
  20892. ftruncate($handle, $length);
  20893. }
  20894. }
  20895. $this->_destroy(true, true);
  20896. if ($self) {
  20897. $objvars = get_object_vars($this->objcopy);
  20898. foreach ($objvars as $key => $value) {
  20899. $this->$key = $value;
  20900. }
  20901. }
  20902. return $this->objcopy;
  20903. }
  20904. return $this;
  20905. }
  20906. // --- MULTI COLUMNS METHODS -----------------------
  20907. /**
  20908. * Set multiple columns of the same size
  20909. * @param $numcols (int) number of columns (set to zero to disable columns mode)
  20910. * @param $width (int) column width
  20911. * @param $y (int) column starting Y position (leave empty for current Y position)
  20912. * @public
  20913. * @since 4.9.001 (2010-03-28)
  20914. */
  20915. public function setEqualColumns($numcols=0, $width=0, $y='') {
  20916. $this->columns = array();
  20917. if ($numcols < 2) {
  20918. $numcols = 0;
  20919. $this->columns = array();
  20920. } else {
  20921. // maximum column width
  20922. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  20923. if (($width == 0) OR ($width > $maxwidth)) {
  20924. $width = $maxwidth;
  20925. }
  20926. if (TCPDF_STATIC::empty_string($y)) {
  20927. $y = $this->y;
  20928. }
  20929. // space between columns
  20930. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  20931. // fill the columns array (with, space, starting Y position)
  20932. for ($i = 0; $i < $numcols; ++$i) {
  20933. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  20934. }
  20935. }
  20936. $this->num_columns = $numcols;
  20937. $this->current_column = 0;
  20938. $this->column_start_page = $this->page;
  20939. $this->selectColumn(0);
  20940. }
  20941. /**
  20942. * Remove columns and reset page margins.
  20943. * @public
  20944. * @since 5.9.072 (2011-04-26)
  20945. */
  20946. public function resetColumns() {
  20947. $this->lMargin = $this->original_lMargin;
  20948. $this->rMargin = $this->original_rMargin;
  20949. $this->setEqualColumns();
  20950. }
  20951. /**
  20952. * Set columns array.
  20953. * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
  20954. * @param $columns (array)
  20955. * @public
  20956. * @since 4.9.001 (2010-03-28)
  20957. */
  20958. public function setColumnsArray($columns) {
  20959. $this->columns = $columns;
  20960. $this->num_columns = count($columns);
  20961. $this->current_column = 0;
  20962. $this->column_start_page = $this->page;
  20963. $this->selectColumn(0);
  20964. }
  20965. /**
  20966. * Set position at a given column
  20967. * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  20968. * @public
  20969. * @since 4.9.001 (2010-03-28)
  20970. */
  20971. public function selectColumn($col='') {
  20972. if (is_string($col)) {
  20973. $col = $this->current_column;
  20974. } elseif ($col >= $this->num_columns) {
  20975. $col = 0;
  20976. }
  20977. $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
  20978. $enable_thead = false;
  20979. if ($this->num_columns > 1) {
  20980. if ($col != $this->current_column) {
  20981. // move Y pointer at the top of the column
  20982. if ($this->column_start_page == $this->page) {
  20983. $this->y = $this->columns[$col]['y'];
  20984. } else {
  20985. $this->y = $this->tMargin;
  20986. }
  20987. // Avoid to write table headers more than once
  20988. if (($this->page > $this->maxselcol['page']) OR (($this->page == $this->maxselcol['page']) AND ($col > $this->maxselcol['column']))) {
  20989. $enable_thead = true;
  20990. $this->maxselcol['page'] = $this->page;
  20991. $this->maxselcol['column'] = $col;
  20992. }
  20993. }
  20994. $xshift = $this->colxshift;
  20995. // set X position of the current column by case
  20996. $listindent = ($this->listindentlevel * $this->listindent);
  20997. // calculate column X position
  20998. $colpos = 0;
  20999. for ($i = 0; $i < $col; ++$i) {
  21000. $colpos += ($this->columns[$i]['w'] + $this->columns[$i]['s']);
  21001. }
  21002. if ($this->rtl) {
  21003. $x = $this->w - $this->original_rMargin - $colpos;
  21004. $this->rMargin = ($this->w - $x + $listindent);
  21005. $this->lMargin = ($x - $this->columns[$col]['w']);
  21006. $this->x = $x - $listindent;
  21007. } else {
  21008. $x = $this->original_lMargin + $colpos;
  21009. $this->lMargin = ($x + $listindent);
  21010. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  21011. $this->x = $x + $listindent;
  21012. }
  21013. $this->columns[$col]['x'] = $x;
  21014. }
  21015. $this->current_column = $col;
  21016. // fix for HTML mode
  21017. $this->newline = true;
  21018. // print HTML table header (if any)
  21019. if ((!TCPDF_STATIC::empty_string($this->thead)) AND (!$this->inthead)) {
  21020. if ($enable_thead) {
  21021. // print table header
  21022. $this->writeHTML($this->thead, false, false, false, false, '');
  21023. $this->y += $xshift['s']['V'];
  21024. // store end of header position
  21025. if (!isset($this->columns[$col]['th'])) {
  21026. $this->columns[$col]['th'] = array();
  21027. }
  21028. $this->columns[$col]['th']['\''.$this->page.'\''] = $this->y;
  21029. $this->lasth = 0;
  21030. } elseif (isset($this->columns[$col]['th']['\''.$this->page.'\''])) {
  21031. $this->y = $this->columns[$col]['th']['\''.$this->page.'\''];
  21032. }
  21033. }
  21034. // account for an html table cell over multiple columns
  21035. if ($this->rtl) {
  21036. $this->rMargin += $xshift['x'];
  21037. $this->x -= ($xshift['x'] + $xshift['p']['R']);
  21038. } else {
  21039. $this->lMargin += $xshift['x'];
  21040. $this->x += $xshift['x'] + $xshift['p']['L'];
  21041. }
  21042. }
  21043. /**
  21044. * Return the current column number
  21045. * @return int current column number
  21046. * @public
  21047. * @since 5.5.011 (2010-07-08)
  21048. */
  21049. public function getColumn() {
  21050. return $this->current_column;
  21051. }
  21052. /**
  21053. * Return the current number of columns.
  21054. * @return int number of columns
  21055. * @public
  21056. * @since 5.8.018 (2010-08-25)
  21057. */
  21058. public function getNumberOfColumns() {
  21059. return $this->num_columns;
  21060. }
  21061. /**
  21062. * Set Text rendering mode.
  21063. * @param $stroke (int) outline size in user units (0 = disable).
  21064. * @param $fill (boolean) if true fills the text (default).
  21065. * @param $clip (boolean) if true activate clipping mode
  21066. * @public
  21067. * @since 4.9.008 (2009-04-02)
  21068. */
  21069. public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
  21070. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  21071. // convert text rendering parameters
  21072. if ($stroke < 0) {
  21073. $stroke = 0;
  21074. }
  21075. if ($fill === true) {
  21076. if ($stroke > 0) {
  21077. if ($clip === true) {
  21078. // Fill, then stroke text and add to path for clipping
  21079. $textrendermode = 6;
  21080. } else {
  21081. // Fill, then stroke text
  21082. $textrendermode = 2;
  21083. }
  21084. $textstrokewidth = $stroke;
  21085. } else {
  21086. if ($clip === true) {
  21087. // Fill text and add to path for clipping
  21088. $textrendermode = 4;
  21089. } else {
  21090. // Fill text
  21091. $textrendermode = 0;
  21092. }
  21093. }
  21094. } else {
  21095. if ($stroke > 0) {
  21096. if ($clip === true) {
  21097. // Stroke text and add to path for clipping
  21098. $textrendermode = 5;
  21099. } else {
  21100. // Stroke text
  21101. $textrendermode = 1;
  21102. }
  21103. $textstrokewidth = $stroke;
  21104. } else {
  21105. if ($clip === true) {
  21106. // Add text to path for clipping
  21107. $textrendermode = 7;
  21108. } else {
  21109. // Neither fill nor stroke text (invisible)
  21110. $textrendermode = 3;
  21111. }
  21112. }
  21113. }
  21114. $this->textrendermode = $textrendermode;
  21115. $this->textstrokewidth = $stroke;
  21116. }
  21117. /**
  21118. * Set parameters for drop shadow effect for text.
  21119. * @param $params (array) 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.
  21120. * @since 5.9.174 (2012-07-25)
  21121. * @public
  21122. */
  21123. public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
  21124. if (isset($params['enabled'])) {
  21125. $this->txtshadow['enabled'] = $params['enabled']?true:false;
  21126. } else {
  21127. $this->txtshadow['enabled'] = false;
  21128. }
  21129. if (isset($params['depth_w'])) {
  21130. $this->txtshadow['depth_w'] = floatval($params['depth_w']);
  21131. } else {
  21132. $this->txtshadow['depth_w'] = 0;
  21133. }
  21134. if (isset($params['depth_h'])) {
  21135. $this->txtshadow['depth_h'] = floatval($params['depth_h']);
  21136. } else {
  21137. $this->txtshadow['depth_h'] = 0;
  21138. }
  21139. if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
  21140. $this->txtshadow['color'] = $params['color'];
  21141. } else {
  21142. $this->txtshadow['color'] = $this->strokecolor;
  21143. }
  21144. if (isset($params['opacity'])) {
  21145. $this->txtshadow['opacity'] = min(1, max(0, floatval($params['opacity'])));
  21146. } else {
  21147. $this->txtshadow['opacity'] = 1;
  21148. }
  21149. 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'))) {
  21150. $this->txtshadow['blend_mode'] = $params['blend_mode'];
  21151. } else {
  21152. $this->txtshadow['blend_mode'] = 'Normal';
  21153. }
  21154. if ((($this->txtshadow['depth_w'] == 0) AND ($this->txtshadow['depth_h'] == 0)) OR ($this->txtshadow['opacity'] == 0)) {
  21155. $this->txtshadow['enabled'] = false;
  21156. }
  21157. }
  21158. /**
  21159. * Return the text shadow parameters array.
  21160. * @return Array of parameters.
  21161. * @since 5.9.174 (2012-07-25)
  21162. * @public
  21163. */
  21164. public function getTextShadow() {
  21165. return $this->txtshadow;
  21166. }
  21167. /**
  21168. * Returns an array of chars containing soft hyphens.
  21169. * @param $word (array) array of chars
  21170. * @param $patterns (array) Array of hypenation patterns.
  21171. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  21172. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21173. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21174. * @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
  21175. * @param $charmax (int) Maximum length of broken piece of word.
  21176. * @return array text with soft hyphens
  21177. * @author Nicola Asuni
  21178. * @since 4.9.012 (2010-04-12)
  21179. * @protected
  21180. */
  21181. protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21182. $hyphenword = array(); // hyphens positions
  21183. $numchars = count($word);
  21184. if ($numchars <= $charmin) {
  21185. return $word;
  21186. }
  21187. $word_string = TCPDF_FONTS::UTF8ArrSubString($word, '', '', $this->isunicode);
  21188. // some words will be returned as-is
  21189. $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})(\]?)$/';
  21190. if (preg_match($pattern, $word_string) > 0) {
  21191. // email
  21192. return $word;
  21193. }
  21194. $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})(\]?)$/';
  21195. if (preg_match($pattern, $word_string) > 0) {
  21196. // URL
  21197. return $word;
  21198. }
  21199. if (isset($dictionary[$word_string])) {
  21200. return TCPDF_FONTS::UTF8StringToArray($dictionary[$word_string], $this->isunicode, $this->CurrentFont);
  21201. }
  21202. // suround word with '_' characters
  21203. $tmpword = array_merge(array(95), $word, array(95));
  21204. $tmpnumchars = $numchars + 2;
  21205. $maxpos = $tmpnumchars - $charmin;
  21206. for ($pos = 0; $pos < $maxpos; ++$pos) {
  21207. $imax = min(($tmpnumchars - $pos), $charmax);
  21208. for ($i = $charmin; $i <= $imax; ++$i) {
  21209. $subword = strtolower(TCPDF_FONTS::UTF8ArrSubString($tmpword, $pos, ($pos + $i), $this->isunicode));
  21210. if (isset($patterns[$subword])) {
  21211. $pattern = TCPDF_FONTS::UTF8StringToArray($patterns[$subword], $this->isunicode, $this->CurrentFont);
  21212. $pattern_length = count($pattern);
  21213. $digits = 1;
  21214. for ($j = 0; $j < $pattern_length; ++$j) {
  21215. // check if $pattern[$j] is a number
  21216. if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
  21217. if ($j == 0) {
  21218. $zero = $pos - 1;
  21219. } else {
  21220. $zero = $pos + $j - $digits;
  21221. }
  21222. if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) {
  21223. $hyphenword[$zero] = TCPDF_FONTS::unichr($pattern[$j], $this->isunicode);
  21224. }
  21225. ++$digits;
  21226. }
  21227. }
  21228. }
  21229. }
  21230. }
  21231. $inserted = 0;
  21232. $maxpos = $numchars - $rightmin;
  21233. for ($i = $leftmin; $i <= $maxpos; ++$i) {
  21234. if (isset($hyphenword[$i]) AND (($hyphenword[$i] % 2) != 0)) {
  21235. // 173 = soft hyphen character
  21236. array_splice($word, $i + $inserted, 0, 173);
  21237. ++$inserted;
  21238. }
  21239. }
  21240. return $word;
  21241. }
  21242. /**
  21243. * Returns text with soft hyphens.
  21244. * @param $text (string) text to process
  21245. * @param $patterns (mixed) 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/
  21246. * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
  21247. * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
  21248. * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
  21249. * @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
  21250. * @param $charmax (int) Maximum length of broken piece of word.
  21251. * @return array text with soft hyphens
  21252. * @author Nicola Asuni
  21253. * @since 4.9.012 (2010-04-12)
  21254. * @public
  21255. */
  21256. public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
  21257. $text = $this->unhtmlentities($text);
  21258. $word = array(); // last word
  21259. $txtarr = array(); // text to be returned
  21260. $intag = false; // true if we are inside an HTML tag
  21261. if (!is_array($patterns)) {
  21262. $patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
  21263. }
  21264. // get array of characters
  21265. $unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
  21266. // for each char
  21267. foreach ($unichars as $char) {
  21268. if ((!$intag) AND TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
  21269. // letter character
  21270. $word[] = $char;
  21271. } else {
  21272. // other type of character
  21273. if (!TCPDF_STATIC::empty_string($word)) {
  21274. // hypenate the word
  21275. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21276. $word = array();
  21277. }
  21278. $txtarr[] = $char;
  21279. if (chr($char) == '<') {
  21280. // we are inside an HTML tag
  21281. $intag = true;
  21282. } elseif ($intag AND (chr($char) == '>')) {
  21283. // end of HTML tag
  21284. $intag = false;
  21285. }
  21286. }
  21287. }
  21288. if (!TCPDF_STATIC::empty_string($word)) {
  21289. // hypenate the word
  21290. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  21291. }
  21292. // convert char array to string and return
  21293. return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
  21294. }
  21295. /**
  21296. * Enable/disable rasterization of vector images using ImageMagick library.
  21297. * @param $mode (boolean) if true enable rasterization, false otherwise.
  21298. * @public
  21299. * @since 5.0.000 (2010-04-27)
  21300. */
  21301. public function setRasterizeVectorImages($mode) {
  21302. $this->rasterize_vector_images = $mode;
  21303. }
  21304. /**
  21305. * Enable or disable default option for font subsetting.
  21306. * @param $enable (boolean) if true enable font subsetting by default.
  21307. * @author Nicola Asuni
  21308. * @public
  21309. * @since 5.3.002 (2010-06-07)
  21310. */
  21311. public function setFontSubsetting($enable=true) {
  21312. if ($this->pdfa_mode) {
  21313. $this->font_subsetting = false;
  21314. } else {
  21315. $this->font_subsetting = $enable ? true : false;
  21316. }
  21317. }
  21318. /**
  21319. * Return the default option for font subsetting.
  21320. * @return boolean default font subsetting state.
  21321. * @author Nicola Asuni
  21322. * @public
  21323. * @since 5.3.002 (2010-06-07)
  21324. */
  21325. public function getFontSubsetting() {
  21326. return $this->font_subsetting;
  21327. }
  21328. /**
  21329. * Left trim the input string
  21330. * @param $str (string) string to trim
  21331. * @param $replace (string) string that replace spaces.
  21332. * @return left trimmed string
  21333. * @author Nicola Asuni
  21334. * @public
  21335. * @since 5.8.000 (2010-08-11)
  21336. */
  21337. public function stringLeftTrim($str, $replace='') {
  21338. return preg_replace('/^'.$this->re_space['p'].'+/'.$this->re_space['m'], $replace, $str);
  21339. }
  21340. /**
  21341. * Right trim the input string
  21342. * @param $str (string) string to trim
  21343. * @param $replace (string) string that replace spaces.
  21344. * @return right trimmed string
  21345. * @author Nicola Asuni
  21346. * @public
  21347. * @since 5.8.000 (2010-08-11)
  21348. */
  21349. public function stringRightTrim($str, $replace='') {
  21350. return preg_replace('/'.$this->re_space['p'].'+$/'.$this->re_space['m'], $replace, $str);
  21351. }
  21352. /**
  21353. * Trim the input string
  21354. * @param $str (string) string to trim
  21355. * @param $replace (string) string that replace spaces.
  21356. * @return trimmed string
  21357. * @author Nicola Asuni
  21358. * @public
  21359. * @since 5.8.000 (2010-08-11)
  21360. */
  21361. public function stringTrim($str, $replace='') {
  21362. $str = $this->stringLeftTrim($str, $replace);
  21363. $str = $this->stringRightTrim($str, $replace);
  21364. return $str;
  21365. }
  21366. /**
  21367. * Return true if the current font is unicode type.
  21368. * @return true for unicode font, false otherwise.
  21369. * @author Nicola Asuni
  21370. * @public
  21371. * @since 5.8.002 (2010-08-14)
  21372. */
  21373. public function isUnicodeFont() {
  21374. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont['type'] == 'cidfont0'));
  21375. }
  21376. /**
  21377. * Return normalized font name
  21378. * @param $fontfamily (string) property string containing font family names
  21379. * @return string normalized font name
  21380. * @author Nicola Asuni
  21381. * @public
  21382. * @since 5.8.004 (2010-08-17)
  21383. */
  21384. public function getFontFamilyName($fontfamily) {
  21385. // remove spaces and symbols
  21386. $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
  21387. // extract all font names
  21388. $fontslist = preg_split('/[,]/', $fontfamily);
  21389. // find first valid font name
  21390. foreach ($fontslist as $font) {
  21391. // replace font variations
  21392. $font = preg_replace('/italic$/', 'I', $font);
  21393. $font = preg_replace('/oblique$/', 'I', $font);
  21394. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  21395. // replace common family names and core fonts
  21396. $pattern = array();
  21397. $replacement = array();
  21398. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  21399. $replacement[] = 'times';
  21400. $pattern[] = '/^sansserif/';
  21401. $replacement[] = 'helvetica';
  21402. $pattern[] = '/^monospace/';
  21403. $replacement[] = 'courier';
  21404. $font = preg_replace($pattern, $replacement, $font);
  21405. if (in_array(strtolower($font), $this->fontlist) OR in_array($font, $this->fontkeys)) {
  21406. return $font;
  21407. }
  21408. }
  21409. // return current font as default
  21410. return $this->CurrentFont['fontkey'];
  21411. }
  21412. /**
  21413. * Start a new XObject Template.
  21414. * 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).
  21415. * 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.
  21416. * Note: X,Y coordinates will be reset to 0,0.
  21417. * @param $w (int) Template width in user units (empty string or zero = page width less margins).
  21418. * @param $h (int) Template height in user units (empty string or zero = page height less margins).
  21419. * @param $group (mixed) 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).
  21420. * @return int the XObject Template ID in case of success or false in case of error.
  21421. * @author Nicola Asuni
  21422. * @public
  21423. * @since 5.8.017 (2010-08-24)
  21424. * @see endTemplate(), printTemplate()
  21425. */
  21426. public function startTemplate($w=0, $h=0, $group=false) {
  21427. if ($this->inxobj) {
  21428. // we are already inside an XObject template
  21429. return false;
  21430. }
  21431. $this->inxobj = true;
  21432. ++$this->n;
  21433. // XObject ID
  21434. $this->xobjid = 'XT'.$this->n;
  21435. // object ID
  21436. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  21437. // store current graphic state
  21438. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  21439. // initialize data
  21440. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  21441. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  21442. $this->xobjects[$this->xobjid]['outdata'] = '';
  21443. $this->xobjects[$this->xobjid]['xobjects'] = array();
  21444. $this->xobjects[$this->xobjid]['images'] = array();
  21445. $this->xobjects[$this->xobjid]['fonts'] = array();
  21446. $this->xobjects[$this->xobjid]['annotations'] = array();
  21447. $this->xobjects[$this->xobjid]['extgstates'] = array();
  21448. $this->xobjects[$this->xobjid]['gradients'] = array();
  21449. $this->xobjects[$this->xobjid]['spot_colors'] = array();
  21450. // set new environment
  21451. $this->num_columns = 1;
  21452. $this->current_column = 0;
  21453. $this->SetAutoPageBreak(false);
  21454. if (($w === '') OR ($w <= 0)) {
  21455. $w = $this->w - $this->lMargin - $this->rMargin;
  21456. }
  21457. if (($h === '') OR ($h <= 0)) {
  21458. $h = $this->h - $this->tMargin - $this->bMargin;
  21459. }
  21460. $this->xobjects[$this->xobjid]['x'] = 0;
  21461. $this->xobjects[$this->xobjid]['y'] = 0;
  21462. $this->xobjects[$this->xobjid]['w'] = $w;
  21463. $this->xobjects[$this->xobjid]['h'] = $h;
  21464. $this->w = $w;
  21465. $this->h = $h;
  21466. $this->wPt = $this->w * $this->k;
  21467. $this->hPt = $this->h * $this->k;
  21468. $this->fwPt = $this->wPt;
  21469. $this->fhPt = $this->hPt;
  21470. $this->x = 0;
  21471. $this->y = 0;
  21472. $this->lMargin = 0;
  21473. $this->rMargin = 0;
  21474. $this->tMargin = 0;
  21475. $this->bMargin = 0;
  21476. // set group mode
  21477. $this->xobjects[$this->xobjid]['group'] = $group;
  21478. return $this->xobjid;
  21479. }
  21480. /**
  21481. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  21482. * 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).
  21483. * 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.
  21484. * @return int the XObject Template ID in case of success or false in case of error.
  21485. * @author Nicola Asuni
  21486. * @public
  21487. * @since 5.8.017 (2010-08-24)
  21488. * @see startTemplate(), printTemplate()
  21489. */
  21490. public function endTemplate() {
  21491. if (!$this->inxobj) {
  21492. // we are not inside a template
  21493. return false;
  21494. }
  21495. $this->inxobj = false;
  21496. // restore previous graphic state
  21497. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  21498. return $this->xobjid;
  21499. }
  21500. /**
  21501. * Print an XObject Template.
  21502. * You can print an XObject Template inside the currently opened Template.
  21503. * 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).
  21504. * 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.
  21505. * @param $id (string) The ID of XObject Template to print.
  21506. * @param $x (int) X position in user units (empty string = current x position)
  21507. * @param $y (int) Y position in user units (empty string = current y position)
  21508. * @param $w (int) Width in user units (zero = remaining page width)
  21509. * @param $h (int) Height in user units (zero = remaining page height)
  21510. * @param $align (string) 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>
  21511. * @param $palign (string) 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>
  21512. * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions.
  21513. * @author Nicola Asuni
  21514. * @public
  21515. * @since 5.8.017 (2010-08-24)
  21516. * @see startTemplate(), endTemplate()
  21517. */
  21518. public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
  21519. if ($this->state != 2) {
  21520. return;
  21521. }
  21522. if (!isset($this->xobjects[$id])) {
  21523. $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
  21524. }
  21525. if ($this->inxobj) {
  21526. if ($id == $this->xobjid) {
  21527. // close current template
  21528. $this->endTemplate();
  21529. } else {
  21530. // use the template as resource for the template currently opened
  21531. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  21532. }
  21533. }
  21534. // set default values
  21535. if ($x === '') {
  21536. $x = $this->x;
  21537. }
  21538. if ($y === '') {
  21539. $y = $this->y;
  21540. }
  21541. // check page for no-write regions and adapt page margins if necessary
  21542. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21543. $ow = $this->xobjects[$id]['w'];
  21544. if ($ow <= 0) {
  21545. $ow = 1;
  21546. }
  21547. $oh = $this->xobjects[$id]['h'];
  21548. if ($oh <= 0) {
  21549. $oh = 1;
  21550. }
  21551. // calculate template width and height on document
  21552. if (($w <= 0) AND ($h <= 0)) {
  21553. $w = $ow;
  21554. $h = $oh;
  21555. } elseif ($w <= 0) {
  21556. $w = $h * $ow / $oh;
  21557. } elseif ($h <= 0) {
  21558. $h = $w * $oh / $ow;
  21559. }
  21560. // fit the template on available space
  21561. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  21562. // set page alignment
  21563. $rb_y = $y + $h;
  21564. // set alignment
  21565. if ($this->rtl) {
  21566. if ($palign == 'L') {
  21567. $xt = $this->lMargin;
  21568. } elseif ($palign == 'C') {
  21569. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21570. } elseif ($palign == 'R') {
  21571. $xt = $this->w - $this->rMargin - $w;
  21572. } else {
  21573. $xt = $x - $w;
  21574. }
  21575. $rb_x = $xt;
  21576. } else {
  21577. if ($palign == 'L') {
  21578. $xt = $this->lMargin;
  21579. } elseif ($palign == 'C') {
  21580. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21581. } elseif ($palign == 'R') {
  21582. $xt = $this->w - $this->rMargin - $w;
  21583. } else {
  21584. $xt = $x;
  21585. }
  21586. $rb_x = $xt + $w;
  21587. }
  21588. // print XObject Template + Transformation matrix
  21589. $this->StartTransform();
  21590. // translate and scale
  21591. $sx = ($w / $ow);
  21592. $sy = ($h / $oh);
  21593. $tm = array();
  21594. $tm[0] = $sx;
  21595. $tm[1] = 0;
  21596. $tm[2] = 0;
  21597. $tm[3] = $sy;
  21598. $tm[4] = $xt * $this->k;
  21599. $tm[5] = ($this->h - $h - $y) * $this->k;
  21600. $this->Transform($tm);
  21601. // set object
  21602. $this->_out('/'.$id.' Do');
  21603. $this->StopTransform();
  21604. // add annotations
  21605. if (!empty($this->xobjects[$id]['annotations'])) {
  21606. foreach ($this->xobjects[$id]['annotations'] as $annot) {
  21607. // transform original coordinates
  21608. $coordlt = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k), (-$annot['y'] * $this->k)));
  21609. $ax = ($coordlt[4] / $this->k);
  21610. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  21611. $coordrb = TCPDF_STATIC::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] + $annot['w']) * $this->k), ((-$annot['y'] - $annot['h']) * $this->k)));
  21612. $aw = ($coordrb[4] / $this->k) - $ax;
  21613. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  21614. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  21615. }
  21616. }
  21617. // set pointer to align the next text/objects
  21618. switch($align) {
  21619. case 'T': {
  21620. $this->y = $y;
  21621. $this->x = $rb_x;
  21622. break;
  21623. }
  21624. case 'M': {
  21625. $this->y = $y + round($h/2);
  21626. $this->x = $rb_x;
  21627. break;
  21628. }
  21629. case 'B': {
  21630. $this->y = $rb_y;
  21631. $this->x = $rb_x;
  21632. break;
  21633. }
  21634. case 'N': {
  21635. $this->SetY($rb_y);
  21636. break;
  21637. }
  21638. default:{
  21639. break;
  21640. }
  21641. }
  21642. }
  21643. /**
  21644. * Set the percentage of character stretching.
  21645. * @param $perc (int) percentage of stretching (100 = no stretching)
  21646. * @author Nicola Asuni
  21647. * @public
  21648. * @since 5.9.000 (2010-09-29)
  21649. */
  21650. public function setFontStretching($perc=100) {
  21651. $this->font_stretching = $perc;
  21652. }
  21653. /**
  21654. * Get the percentage of character stretching.
  21655. * @return float stretching value
  21656. * @author Nicola Asuni
  21657. * @public
  21658. * @since 5.9.000 (2010-09-29)
  21659. */
  21660. public function getFontStretching() {
  21661. return $this->font_stretching;
  21662. }
  21663. /**
  21664. * Set the amount to increase or decrease the space between characters in a text.
  21665. * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
  21666. * @author Nicola Asuni
  21667. * @public
  21668. * @since 5.9.000 (2010-09-29)
  21669. */
  21670. public function setFontSpacing($spacing=0) {
  21671. $this->font_spacing = $spacing;
  21672. }
  21673. /**
  21674. * Get the amount to increase or decrease the space between characters in a text.
  21675. * @return int font spacing (tracking) value
  21676. * @author Nicola Asuni
  21677. * @public
  21678. * @since 5.9.000 (2010-09-29)
  21679. */
  21680. public function getFontSpacing() {
  21681. return $this->font_spacing;
  21682. }
  21683. /**
  21684. * Return an array of no-write page regions
  21685. * @return array of no-write page regions
  21686. * @author Nicola Asuni
  21687. * @public
  21688. * @since 5.9.003 (2010-10-13)
  21689. * @see setPageRegions(), addPageRegion()
  21690. */
  21691. public function getPageRegions() {
  21692. return $this->page_regions;
  21693. }
  21694. /**
  21695. * Set no-write regions on page.
  21696. * 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.
  21697. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21698. * You can set multiple regions for the same page.
  21699. * @param $regions (array) 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.
  21700. * @author Nicola Asuni
  21701. * @public
  21702. * @since 5.9.003 (2010-10-13)
  21703. * @see addPageRegion(), getPageRegions()
  21704. */
  21705. public function setPageRegions($regions=array()) {
  21706. // empty current regions array
  21707. $this->page_regions = array();
  21708. // add regions
  21709. foreach ($regions as $data) {
  21710. $this->addPageRegion($data);
  21711. }
  21712. }
  21713. /**
  21714. * Add a single no-write region on selected page.
  21715. * 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.
  21716. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21717. * You can set multiple regions for the same page.
  21718. * @param $region (array) 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).
  21719. * @author Nicola Asuni
  21720. * @public
  21721. * @since 5.9.003 (2010-10-13)
  21722. * @see setPageRegions(), getPageRegions()
  21723. */
  21724. public function addPageRegion($region) {
  21725. if (!isset($region['page']) OR empty($region['page'])) {
  21726. $region['page'] = $this->page;
  21727. }
  21728. if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
  21729. AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
  21730. AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
  21731. $this->page_regions[] = $region;
  21732. }
  21733. }
  21734. /**
  21735. * Remove a single no-write region.
  21736. * @param $key (int) region key
  21737. * @author Nicola Asuni
  21738. * @public
  21739. * @since 5.9.003 (2010-10-13)
  21740. * @see setPageRegions(), getPageRegions()
  21741. */
  21742. public function removePageRegion($key) {
  21743. if (isset($this->page_regions[$key])) {
  21744. unset($this->page_regions[$key]);
  21745. }
  21746. }
  21747. /**
  21748. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  21749. * 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.
  21750. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  21751. * @param $h (float) height of the text/image/object to print in user units
  21752. * @param $x (float) current X coordinate in user units
  21753. * @param $y (float) current Y coordinate in user units
  21754. * @return array($x, $y)
  21755. * @author Nicola Asuni
  21756. * @protected
  21757. * @since 5.9.003 (2010-10-13)
  21758. */
  21759. protected function checkPageRegions($h, $x, $y) {
  21760. // set default values
  21761. if ($x === '') {
  21762. $x = $this->x;
  21763. }
  21764. if ($y === '') {
  21765. $y = $this->y;
  21766. }
  21767. if (!$this->check_page_regions OR empty($this->page_regions)) {
  21768. // no page regions defined
  21769. return array($x, $y);
  21770. }
  21771. if (empty($h)) {
  21772. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  21773. }
  21774. // check for page break
  21775. if ($this->checkPageBreak($h, $y)) {
  21776. // the content will be printed on a new page
  21777. $x = $this->x;
  21778. $y = $this->y;
  21779. }
  21780. if ($this->num_columns > 1) {
  21781. if ($this->rtl) {
  21782. $this->lMargin = ($this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  21783. } else {
  21784. $this->rMargin = ($this->w - $this->columns[$this->current_column]['x'] - $this->columns[$this->current_column]['w']);
  21785. }
  21786. } else {
  21787. if ($this->rtl) {
  21788. $this->lMargin = max($this->clMargin, $this->original_lMargin);
  21789. } else {
  21790. $this->rMargin = max($this->crMargin, $this->original_rMargin);
  21791. }
  21792. }
  21793. // adjust coordinates and page margins
  21794. foreach ($this->page_regions as $regid => $regdata) {
  21795. if ($regdata['page'] == $this->page) {
  21796. // check region boundaries
  21797. if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
  21798. // Y is inside the region
  21799. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  21800. $yt = max($y, $regdata['yt']);
  21801. $yb = min(($yt + $h), $regdata['yb']);
  21802. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  21803. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  21804. if ($regdata['side'] == 'L') { // left side
  21805. $new_margin = max($xt, $xb);
  21806. if ($this->lMargin < $new_margin) {
  21807. if ($this->rtl) {
  21808. // adjust left page margin
  21809. $this->lMargin = max(0, $new_margin);
  21810. }
  21811. if ($x < $new_margin) {
  21812. // adjust x position
  21813. $x = $new_margin;
  21814. if ($new_margin > ($this->w - $this->rMargin)) {
  21815. // adjust y position
  21816. $y = $regdata['yb'] - $h;
  21817. }
  21818. }
  21819. }
  21820. } elseif ($regdata['side'] == 'R') { // right side
  21821. $new_margin = min($xt, $xb);
  21822. if (($this->w - $this->rMargin) > $new_margin) {
  21823. if (!$this->rtl) {
  21824. // adjust right page margin
  21825. $this->rMargin = max(0, ($this->w - $new_margin));
  21826. }
  21827. if ($x > $new_margin) {
  21828. // adjust x position
  21829. $x = $new_margin;
  21830. if ($new_margin > $this->lMargin) {
  21831. // adjust y position
  21832. $y = $regdata['yb'] - $h;
  21833. }
  21834. }
  21835. }
  21836. }
  21837. }
  21838. }
  21839. }
  21840. return array($x, $y);
  21841. }
  21842. // --- SVG METHODS ---------------------------------------------------------
  21843. /**
  21844. * Embedd a Scalable Vector Graphics (SVG) image.
  21845. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  21846. * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
  21847. * @param $x (float) Abscissa of the upper-left corner.
  21848. * @param $y (float) Ordinate of the upper-left corner.
  21849. * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  21850. * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  21851. * @param $link (mixed) URL or identifier returned by AddLink().
  21852. * @param $align (string) 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.
  21853. * @param $palign (string) 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>
  21854. * @param $border (mixed) 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)))
  21855. * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
  21856. * @author Nicola Asuni
  21857. * @since 5.0.000 (2010-05-02)
  21858. * @public
  21859. */
  21860. public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
  21861. if ($this->state != 2) {
  21862. return;
  21863. }
  21864. if ($this->rasterize_vector_images AND ($w > 0) AND ($h > 0)) {
  21865. // convert SVG to raster image using GD or ImageMagick libraries
  21866. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  21867. }
  21868. if ($file{0} === '@') { // image from string
  21869. $this->svgdir = '';
  21870. $svgdata = substr($file, 1);
  21871. } else { // SVG file
  21872. $this->svgdir = dirname($file);
  21873. $svgdata = TCPDF_STATIC::fileGetContents($file);
  21874. }
  21875. if ($svgdata === FALSE) {
  21876. $this->Error('SVG file not found: '.$file);
  21877. }
  21878. if ($x === '') {
  21879. $x = $this->x;
  21880. }
  21881. if ($y === '') {
  21882. $y = $this->y;
  21883. }
  21884. // check page for no-write regions and adapt page margins if necessary
  21885. list($x, $y) = $this->checkPageRegions($h, $x, $y);
  21886. $k = $this->k;
  21887. $ox = 0;
  21888. $oy = 0;
  21889. $ow = $w;
  21890. $oh = $h;
  21891. $aspect_ratio_align = 'xMidYMid';
  21892. $aspect_ratio_ms = 'meet';
  21893. $regs = array();
  21894. // get original image width and height
  21895. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  21896. if (isset($regs[1]) AND !empty($regs[1])) {
  21897. $tmp = array();
  21898. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21899. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  21900. }
  21901. $tmp = array();
  21902. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21903. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  21904. }
  21905. $tmp = array();
  21906. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21907. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  21908. }
  21909. $tmp = array();
  21910. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21911. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  21912. }
  21913. $tmp = array();
  21914. $view_box = array();
  21915. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
  21916. if (count($tmp) == 5) {
  21917. array_shift($tmp);
  21918. foreach ($tmp as $key => $val) {
  21919. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  21920. }
  21921. $ox = $view_box[0];
  21922. $oy = $view_box[1];
  21923. }
  21924. // get aspect ratio
  21925. $tmp = array();
  21926. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
  21927. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  21928. switch (count($aspect_ratio)) {
  21929. case 3: {
  21930. $aspect_ratio_align = $aspect_ratio[1];
  21931. $aspect_ratio_ms = $aspect_ratio[2];
  21932. break;
  21933. }
  21934. case 2: {
  21935. $aspect_ratio_align = $aspect_ratio[0];
  21936. $aspect_ratio_ms = $aspect_ratio[1];
  21937. break;
  21938. }
  21939. case 1: {
  21940. $aspect_ratio_align = $aspect_ratio[0];
  21941. $aspect_ratio_ms = 'meet';
  21942. break;
  21943. }
  21944. }
  21945. }
  21946. }
  21947. }
  21948. if ($ow <= 0) {
  21949. $ow = 1;
  21950. }
  21951. if ($oh <= 0) {
  21952. $oh = 1;
  21953. }
  21954. // calculate image width and height on document
  21955. if (($w <= 0) AND ($h <= 0)) {
  21956. // convert image size to document unit
  21957. $w = $ow;
  21958. $h = $oh;
  21959. } elseif ($w <= 0) {
  21960. $w = $h * $ow / $oh;
  21961. } elseif ($h <= 0) {
  21962. $h = $w * $oh / $ow;
  21963. }
  21964. // fit the image on available space
  21965. list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
  21966. if ($this->rasterize_vector_images) {
  21967. // convert SVG to raster image using GD or ImageMagick libraries
  21968. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  21969. }
  21970. // set alignment
  21971. $this->img_rb_y = $y + $h;
  21972. // set alignment
  21973. if ($this->rtl) {
  21974. if ($palign == 'L') {
  21975. $ximg = $this->lMargin;
  21976. } elseif ($palign == 'C') {
  21977. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21978. } elseif ($palign == 'R') {
  21979. $ximg = $this->w - $this->rMargin - $w;
  21980. } else {
  21981. $ximg = $x - $w;
  21982. }
  21983. $this->img_rb_x = $ximg;
  21984. } else {
  21985. if ($palign == 'L') {
  21986. $ximg = $this->lMargin;
  21987. } elseif ($palign == 'C') {
  21988. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  21989. } elseif ($palign == 'R') {
  21990. $ximg = $this->w - $this->rMargin - $w;
  21991. } else {
  21992. $ximg = $x;
  21993. }
  21994. $this->img_rb_x = $ximg + $w;
  21995. }
  21996. // store current graphic vars
  21997. $gvars = $this->getGraphicVars();
  21998. // store SVG position and scale factors
  21999. $svgoffset_x = ($ximg - $ox) * $this->k;
  22000. $svgoffset_y = -($y - $oy) * $this->k;
  22001. if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
  22002. $ow = $view_box[2];
  22003. $oh = $view_box[3];
  22004. } else {
  22005. if ($ow <= 0) {
  22006. $ow = $w;
  22007. }
  22008. if ($oh <= 0) {
  22009. $oh = $h;
  22010. }
  22011. }
  22012. $svgscale_x = $w / $ow;
  22013. $svgscale_y = $h / $oh;
  22014. // scaling and alignment
  22015. if ($aspect_ratio_align != 'none') {
  22016. // store current scaling values
  22017. $svgscale_old_x = $svgscale_x;
  22018. $svgscale_old_y = $svgscale_y;
  22019. // force uniform scaling
  22020. if ($aspect_ratio_ms == 'slice') {
  22021. // the entire viewport is covered by the viewBox
  22022. if ($svgscale_x > $svgscale_y) {
  22023. $svgscale_y = $svgscale_x;
  22024. } elseif ($svgscale_x < $svgscale_y) {
  22025. $svgscale_x = $svgscale_y;
  22026. }
  22027. } else { // meet
  22028. // the entire viewBox is visible within the viewport
  22029. if ($svgscale_x < $svgscale_y) {
  22030. $svgscale_y = $svgscale_x;
  22031. } elseif ($svgscale_x > $svgscale_y) {
  22032. $svgscale_x = $svgscale_y;
  22033. }
  22034. }
  22035. // correct X alignment
  22036. switch (substr($aspect_ratio_align, 1, 3)) {
  22037. case 'Min': {
  22038. // do nothing
  22039. break;
  22040. }
  22041. case 'Max': {
  22042. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  22043. break;
  22044. }
  22045. default:
  22046. case 'Mid': {
  22047. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  22048. break;
  22049. }
  22050. }
  22051. // correct Y alignment
  22052. switch (substr($aspect_ratio_align, 5)) {
  22053. case 'Min': {
  22054. // do nothing
  22055. break;
  22056. }
  22057. case 'Max': {
  22058. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  22059. break;
  22060. }
  22061. default:
  22062. case 'Mid': {
  22063. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  22064. break;
  22065. }
  22066. }
  22067. }
  22068. // store current page break mode
  22069. $page_break_mode = $this->AutoPageBreak;
  22070. $page_break_margin = $this->getBreakMargin();
  22071. $cell_padding = $this->cell_padding;
  22072. $this->SetCellPadding(0);
  22073. $this->SetAutoPageBreak(false);
  22074. // save the current graphic state
  22075. $this->_out('q'.$this->epsmarker);
  22076. // set initial clipping mask
  22077. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  22078. // scale and translate
  22079. $e = $ox * $this->k * (1 - $svgscale_x);
  22080. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  22081. $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e + $svgoffset_x), ($f + $svgoffset_y)));
  22082. // creates a new XML parser to be used by the other XML functions
  22083. $this->parser = xml_parser_create('UTF-8');
  22084. // the following function allows to use parser inside object
  22085. xml_set_object($this->parser, $this);
  22086. // disable case-folding for this XML parser
  22087. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  22088. // sets the element handler functions for the XML parser
  22089. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  22090. // sets the character data handler function for the XML parser
  22091. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  22092. // start parsing an XML document
  22093. if (!xml_parse($this->parser, $svgdata)) {
  22094. $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
  22095. $this->Error($error_message);
  22096. }
  22097. // free this XML parser
  22098. xml_parser_free($this->parser);
  22099. // restore previous graphic state
  22100. $this->_out($this->epsmarker.'Q');
  22101. // restore graphic vars
  22102. $this->setGraphicVars($gvars);
  22103. $this->lasth = $gvars['lasth'];
  22104. if (!empty($border)) {
  22105. $bx = $this->x;
  22106. $by = $this->y;
  22107. $this->x = $ximg;
  22108. if ($this->rtl) {
  22109. $this->x += $w;
  22110. }
  22111. $this->y = $y;
  22112. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  22113. $this->x = $bx;
  22114. $this->y = $by;
  22115. }
  22116. if ($link) {
  22117. $this->Link($ximg, $y, $w, $h, $link, 0);
  22118. }
  22119. // set pointer to align the next text/objects
  22120. switch($align) {
  22121. case 'T':{
  22122. $this->y = $y;
  22123. $this->x = $this->img_rb_x;
  22124. break;
  22125. }
  22126. case 'M':{
  22127. $this->y = $y + round($h/2);
  22128. $this->x = $this->img_rb_x;
  22129. break;
  22130. }
  22131. case 'B':{
  22132. $this->y = $this->img_rb_y;
  22133. $this->x = $this->img_rb_x;
  22134. break;
  22135. }
  22136. case 'N':{
  22137. $this->SetY($this->img_rb_y);
  22138. break;
  22139. }
  22140. default:{
  22141. // restore pointer to starting position
  22142. $this->x = $gvars['x'];
  22143. $this->y = $gvars['y'];
  22144. $this->page = $gvars['page'];
  22145. $this->current_column = $gvars['current_column'];
  22146. $this->tMargin = $gvars['tMargin'];
  22147. $this->bMargin = $gvars['bMargin'];
  22148. $this->w = $gvars['w'];
  22149. $this->h = $gvars['h'];
  22150. $this->wPt = $gvars['wPt'];
  22151. $this->hPt = $gvars['hPt'];
  22152. $this->fwPt = $gvars['fwPt'];
  22153. $this->fhPt = $gvars['fhPt'];
  22154. break;
  22155. }
  22156. }
  22157. $this->endlinex = $this->img_rb_x;
  22158. // restore page break
  22159. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  22160. $this->cell_padding = $cell_padding;
  22161. }
  22162. /**
  22163. * Convert SVG transformation matrix to PDF.
  22164. * @param $tm (array) original SVG transformation matrix
  22165. * @return array transformation matrix
  22166. * @protected
  22167. * @since 5.0.000 (2010-05-02)
  22168. */
  22169. protected function convertSVGtMatrix($tm) {
  22170. $a = $tm[0];
  22171. $b = -$tm[1];
  22172. $c = -$tm[2];
  22173. $d = $tm[3];
  22174. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  22175. $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  22176. $x = 0;
  22177. $y = $this->h * $this->k;
  22178. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  22179. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  22180. return array($a, $b, $c, $d, $e, $f);
  22181. }
  22182. /**
  22183. * Apply SVG graphic transformation matrix.
  22184. * @param $tm (array) original SVG transformation matrix
  22185. * @protected
  22186. * @since 5.0.000 (2010-05-02)
  22187. */
  22188. protected function SVGTransform($tm) {
  22189. $this->Transform($this->convertSVGtMatrix($tm));
  22190. }
  22191. /**
  22192. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  22193. * @param $svgstyle (array) array of SVG styles to apply
  22194. * @param $prevsvgstyle (array) array of previous SVG style
  22195. * @param $x (int) X origin of the bounding box
  22196. * @param $y (int) Y origin of the bounding box
  22197. * @param $w (int) width of the bounding box
  22198. * @param $h (int) height of the bounding box
  22199. * @param $clip_function (string) clip function
  22200. * @param $clip_params (array) array of parameters for clipping function
  22201. * @return object style
  22202. * @author Nicola Asuni
  22203. * @since 5.0.000 (2010-05-02)
  22204. * @protected
  22205. */
  22206. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
  22207. if ($this->state != 2) {
  22208. return;
  22209. }
  22210. $objstyle = '';
  22211. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22212. if (!isset($svgstyle['opacity'])) {
  22213. return $objstyle;
  22214. }
  22215. // clip-path
  22216. $regs = array();
  22217. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
  22218. $clip_path = $this->svgclippaths[$regs[1]];
  22219. foreach ($clip_path as $cp) {
  22220. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  22221. }
  22222. }
  22223. // opacity
  22224. if ($svgstyle['opacity'] != 1) {
  22225. $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
  22226. }
  22227. // color
  22228. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors);
  22229. $this->SetFillColorArray($fill_color);
  22230. // text color
  22231. $text_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors);
  22232. $this->SetTextColorArray($text_color);
  22233. // clip
  22234. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
  22235. $top = (isset($regs[1])?$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false):0);
  22236. $right = (isset($regs[2])?$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false):0);
  22237. $bottom = (isset($regs[3])?$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false):0);
  22238. $left = (isset($regs[4])?$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false):0);
  22239. $cx = $x + $left;
  22240. $cy = $y + $top;
  22241. $cw = $w - $left - $right;
  22242. $ch = $h - $top - $bottom;
  22243. if ($svgstyle['clip-rule'] == 'evenodd') {
  22244. $clip_rule = 'CNZ';
  22245. } else {
  22246. $clip_rule = 'CEO';
  22247. }
  22248. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  22249. }
  22250. // fill
  22251. $regs = array();
  22252. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
  22253. // gradient
  22254. $gradient = $this->svggradients[$regs[1]];
  22255. if (isset($gradient['xref'])) {
  22256. // reference to another gradient definition
  22257. $newgradient = $this->svggradients[$gradient['xref']];
  22258. $newgradient['coords'] = $gradient['coords'];
  22259. $newgradient['mode'] = $gradient['mode'];
  22260. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  22261. if (isset($gradient['gradientTransform'])) {
  22262. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  22263. }
  22264. $gradient = $newgradient;
  22265. }
  22266. //save current Graphic State
  22267. $this->_out('q');
  22268. //set clipping area
  22269. if (!empty($clip_function) AND method_exists($this, $clip_function)) {
  22270. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  22271. if (is_array($bbox) AND (count($bbox) == 4)) {
  22272. list($x, $y, $w, $h) = $bbox;
  22273. }
  22274. }
  22275. if ($gradient['mode'] == 'measure') {
  22276. if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
  22277. $gtm = $gradient['gradientTransform'];
  22278. // apply transformation matrix
  22279. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  22280. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  22281. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  22282. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  22283. if (isset($gradient['coords'][4])) {
  22284. $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  22285. }
  22286. $gradient['coords'][0] = $xa;
  22287. $gradient['coords'][1] = $ya;
  22288. $gradient['coords'][2] = $xb;
  22289. $gradient['coords'][3] = $yb;
  22290. }
  22291. // convert SVG coordinates to user units
  22292. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  22293. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  22294. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  22295. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  22296. if (isset($gradient['coords'][4])) {
  22297. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  22298. }
  22299. if ($w <= $minlen) {
  22300. $w = $minlen;
  22301. }
  22302. if ($h <= $minlen) {
  22303. $h = $minlen;
  22304. }
  22305. // shift units
  22306. if ($gradient['gradientUnits'] == 'objectBoundingBox') {
  22307. // convert to SVG coordinate system
  22308. $gradient['coords'][0] += $x;
  22309. $gradient['coords'][1] += $y;
  22310. $gradient['coords'][2] += $x;
  22311. $gradient['coords'][3] += $y;
  22312. }
  22313. // calculate percentages
  22314. $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
  22315. $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
  22316. $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
  22317. $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
  22318. if (isset($gradient['coords'][4])) {
  22319. $gradient['coords'][4] /= $w;
  22320. }
  22321. } elseif ($gradient['mode'] == 'percentage') {
  22322. foreach($gradient['coords'] as $key => $val) {
  22323. $gradient['coords'][$key] = (intval($val) / 100);
  22324. if ($val < 0) {
  22325. $gradient['coords'][$key] = 0;
  22326. } elseif ($val > 1) {
  22327. $gradient['coords'][$key] = 1;
  22328. }
  22329. }
  22330. }
  22331. if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
  22332. // single color (no shading)
  22333. $gradient['coords'][0] = 1;
  22334. $gradient['coords'][1] = 0;
  22335. $gradient['coords'][2] = 0.999;
  22336. $gradient['coords'][3] = 0;
  22337. }
  22338. // swap Y coordinates
  22339. $tmp = $gradient['coords'][1];
  22340. $gradient['coords'][1] = $gradient['coords'][3];
  22341. $gradient['coords'][3] = $tmp;
  22342. // set transformation map for gradient
  22343. if ($gradient['type'] == 3) {
  22344. // circular gradient
  22345. $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h));
  22346. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($w * $this->k), ($x * $this->k), ($cy * $this->k)));
  22347. } else {
  22348. $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k), ($h * $this->k), ($x * $this->k), (($this->h - ($y + $h)) * $this->k)));
  22349. }
  22350. if (count($gradient['stops']) > 1) {
  22351. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  22352. }
  22353. } elseif ($svgstyle['fill'] != 'none') {
  22354. $fill_color = TCPDF_COLORS::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors);
  22355. if ($svgstyle['fill-opacity'] != 1) {
  22356. $this->setAlpha($this->alpha['CA'], 'Normal', $svgstyle['fill-opacity'], false);
  22357. }
  22358. $this->SetFillColorArray($fill_color);
  22359. if ($svgstyle['fill-rule'] == 'evenodd') {
  22360. $objstyle .= 'F*';
  22361. } else {
  22362. $objstyle .= 'F';
  22363. }
  22364. }
  22365. // stroke
  22366. if ($svgstyle['stroke'] != 'none') {
  22367. if ($svgstyle['stroke-opacity'] != 1) {
  22368. $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha['ca'], false);
  22369. }
  22370. $stroke_style = array(
  22371. 'color' => TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors),
  22372. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  22373. 'cap' => $svgstyle['stroke-linecap'],
  22374. 'join' => $svgstyle['stroke-linejoin']
  22375. );
  22376. if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
  22377. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  22378. }
  22379. $this->SetLineStyle($stroke_style);
  22380. $objstyle .= 'D';
  22381. }
  22382. // font
  22383. $regs = array();
  22384. if (!empty($svgstyle['font'])) {
  22385. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
  22386. $font_family = $this->getFontFamilyName($regs[1]);
  22387. } else {
  22388. $font_family = $svgstyle['font-family'];
  22389. }
  22390. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22391. $font_size = trim($regs[1]);
  22392. } else {
  22393. $font_size = $svgstyle['font-size'];
  22394. }
  22395. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22396. $font_style = trim($regs[1]);
  22397. } else {
  22398. $font_style = $svgstyle['font-style'];
  22399. }
  22400. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22401. $font_weight = trim($regs[1]);
  22402. } else {
  22403. $font_weight = $svgstyle['font-weight'];
  22404. }
  22405. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22406. $font_stretch = trim($regs[1]);
  22407. } else {
  22408. $font_stretch = $svgstyle['font-stretch'];
  22409. }
  22410. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
  22411. $font_spacing = trim($regs[1]);
  22412. } else {
  22413. $font_spacing = $svgstyle['letter-spacing'];
  22414. }
  22415. } else {
  22416. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  22417. $font_size = $svgstyle['font-size'];
  22418. $font_style = $svgstyle['font-style'];
  22419. $font_weight = $svgstyle['font-weight'];
  22420. $font_stretch = $svgstyle['font-stretch'];
  22421. $font_spacing = $svgstyle['letter-spacing'];
  22422. }
  22423. $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit);
  22424. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  22425. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  22426. switch ($font_style) {
  22427. case 'italic': {
  22428. $font_style = 'I';
  22429. break;
  22430. }
  22431. case 'oblique': {
  22432. $font_style = 'I';
  22433. break;
  22434. }
  22435. default:
  22436. case 'normal': {
  22437. $font_style = '';
  22438. break;
  22439. }
  22440. }
  22441. switch ($font_weight) {
  22442. case 'bold':
  22443. case 'bolder': {
  22444. $font_style .= 'B';
  22445. break;
  22446. }
  22447. }
  22448. switch ($svgstyle['text-decoration']) {
  22449. case 'underline': {
  22450. $font_style .= 'U';
  22451. break;
  22452. }
  22453. case 'overline': {
  22454. $font_style .= 'O';
  22455. break;
  22456. }
  22457. case 'line-through': {
  22458. $font_style .= 'D';
  22459. break;
  22460. }
  22461. default:
  22462. case 'none': {
  22463. break;
  22464. }
  22465. }
  22466. $this->SetFont($font_family, $font_style, $font_size);
  22467. $this->setFontStretching($font_stretch);
  22468. $this->setFontSpacing($font_spacing);
  22469. return $objstyle;
  22470. }
  22471. /**
  22472. * Draws an SVG path
  22473. * @param $d (string) attribute d of the path SVG element
  22474. * @param $style (string) Style of rendering. Possible values are:
  22475. * <ul>
  22476. * <li>D or empty string: Draw (default).</li>
  22477. * <li>F: Fill.</li>
  22478. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22479. * <li>DF or FD: Draw and fill.</li>
  22480. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  22481. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  22482. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  22483. * </ul>
  22484. * @return array of container box measures (x, y, w, h)
  22485. * @author Nicola Asuni
  22486. * @since 5.0.000 (2010-05-02)
  22487. * @protected
  22488. */
  22489. protected function SVGPath($d, $style='') {
  22490. if ($this->state != 2) {
  22491. return;
  22492. }
  22493. // set fill/stroke style
  22494. $op = TCPDF_STATIC::getPathPaintOperator($style, '');
  22495. if (empty($op)) {
  22496. return;
  22497. }
  22498. $paths = array();
  22499. $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
  22500. preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER);
  22501. $x = 0;
  22502. $y = 0;
  22503. $x1 = 0;
  22504. $y1 = 0;
  22505. $x2 = 0;
  22506. $y2 = 0;
  22507. $xmin = 2147483647;
  22508. $xmax = 0;
  22509. $ymin = 2147483647;
  22510. $ymax = 0;
  22511. $relcoord = false;
  22512. $minlen = (0.01 / $this->k); // minimum acceptable length (3 point)
  22513. $firstcmd = true; // used to print first point
  22514. // draw curve pieces
  22515. foreach ($paths as $key => $val) {
  22516. // get curve type
  22517. $cmd = trim($val[1]);
  22518. if (strtolower($cmd) == $cmd) {
  22519. // use relative coordinated instead of absolute
  22520. $relcoord = true;
  22521. $xoffset = $x;
  22522. $yoffset = $y;
  22523. } else {
  22524. $relcoord = false;
  22525. $xoffset = 0;
  22526. $yoffset = 0;
  22527. }
  22528. $params = array();
  22529. if (isset($val[2])) {
  22530. // get curve parameters
  22531. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  22532. $params = array();
  22533. foreach ($rawparams as $ck => $cp) {
  22534. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  22535. if (abs($params[$ck]) < $minlen) {
  22536. // aproximate little values to zero
  22537. $params[$ck] = 0;
  22538. }
  22539. }
  22540. }
  22541. // store current origin point
  22542. $x0 = $x;
  22543. $y0 = $y;
  22544. switch (strtoupper($cmd)) {
  22545. case 'M': { // moveto
  22546. foreach ($params as $ck => $cp) {
  22547. if (($ck % 2) == 0) {
  22548. $x = $cp + $xoffset;
  22549. } else {
  22550. $y = $cp + $yoffset;
  22551. if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22552. if ($ck == 1) {
  22553. $this->_outPoint($x, $y);
  22554. $firstcmd = false;
  22555. } else {
  22556. $this->_outLine($x, $y);
  22557. }
  22558. $x0 = $x;
  22559. $y0 = $y;
  22560. }
  22561. $xmin = min($xmin, $x);
  22562. $ymin = min($ymin, $y);
  22563. $xmax = max($xmax, $x);
  22564. $ymax = max($ymax, $y);
  22565. if ($relcoord) {
  22566. $xoffset = $x;
  22567. $yoffset = $y;
  22568. }
  22569. }
  22570. }
  22571. break;
  22572. }
  22573. case 'L': { // lineto
  22574. foreach ($params as $ck => $cp) {
  22575. if (($ck % 2) == 0) {
  22576. $x = $cp + $xoffset;
  22577. } else {
  22578. $y = $cp + $yoffset;
  22579. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22580. $this->_outLine($x, $y);
  22581. $x0 = $x;
  22582. $y0 = $y;
  22583. }
  22584. $xmin = min($xmin, $x);
  22585. $ymin = min($ymin, $y);
  22586. $xmax = max($xmax, $x);
  22587. $ymax = max($ymax, $y);
  22588. if ($relcoord) {
  22589. $xoffset = $x;
  22590. $yoffset = $y;
  22591. }
  22592. }
  22593. }
  22594. break;
  22595. }
  22596. case 'H': { // horizontal lineto
  22597. foreach ($params as $ck => $cp) {
  22598. $x = $cp + $xoffset;
  22599. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22600. $this->_outLine($x, $y);
  22601. $x0 = $x;
  22602. $y0 = $y;
  22603. }
  22604. $xmin = min($xmin, $x);
  22605. $xmax = max($xmax, $x);
  22606. if ($relcoord) {
  22607. $xoffset = $x;
  22608. }
  22609. }
  22610. break;
  22611. }
  22612. case 'V': { // vertical lineto
  22613. foreach ($params as $ck => $cp) {
  22614. $y = $cp + $yoffset;
  22615. if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
  22616. $this->_outLine($x, $y);
  22617. $x0 = $x;
  22618. $y0 = $y;
  22619. }
  22620. $ymin = min($ymin, $y);
  22621. $ymax = max($ymax, $y);
  22622. if ($relcoord) {
  22623. $yoffset = $y;
  22624. }
  22625. }
  22626. break;
  22627. }
  22628. case 'C': { // curveto
  22629. foreach ($params as $ck => $cp) {
  22630. $params[$ck] = $cp;
  22631. if ((($ck + 1) % 6) == 0) {
  22632. $x1 = $params[($ck - 5)] + $xoffset;
  22633. $y1 = $params[($ck - 4)] + $yoffset;
  22634. $x2 = $params[($ck - 3)] + $xoffset;
  22635. $y2 = $params[($ck - 2)] + $yoffset;
  22636. $x = $params[($ck - 1)] + $xoffset;
  22637. $y = $params[($ck)] + $yoffset;
  22638. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22639. $xmin = min($xmin, $x, $x1, $x2);
  22640. $ymin = min($ymin, $y, $y1, $y2);
  22641. $xmax = max($xmax, $x, $x1, $x2);
  22642. $ymax = max($ymax, $y, $y1, $y2);
  22643. if ($relcoord) {
  22644. $xoffset = $x;
  22645. $yoffset = $y;
  22646. }
  22647. }
  22648. }
  22649. break;
  22650. }
  22651. case 'S': { // shorthand/smooth curveto
  22652. foreach ($params as $ck => $cp) {
  22653. $params[$ck] = $cp;
  22654. if ((($ck + 1) % 4) == 0) {
  22655. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
  22656. $x1 = (2 * $x) - $x2;
  22657. $y1 = (2 * $y) - $y2;
  22658. } else {
  22659. $x1 = $x;
  22660. $y1 = $y;
  22661. }
  22662. $x2 = $params[($ck - 3)] + $xoffset;
  22663. $y2 = $params[($ck - 2)] + $yoffset;
  22664. $x = $params[($ck - 1)] + $xoffset;
  22665. $y = $params[($ck)] + $yoffset;
  22666. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  22667. $xmin = min($xmin, $x, $x1, $x2);
  22668. $ymin = min($ymin, $y, $y1, $y2);
  22669. $xmax = max($xmax, $x, $x1, $x2);
  22670. $ymax = max($ymax, $y, $y1, $y2);
  22671. if ($relcoord) {
  22672. $xoffset = $x;
  22673. $yoffset = $y;
  22674. }
  22675. }
  22676. }
  22677. break;
  22678. }
  22679. case 'Q': { // quadratic B\E9zier curveto
  22680. foreach ($params as $ck => $cp) {
  22681. $params[$ck] = $cp;
  22682. if ((($ck + 1) % 4) == 0) {
  22683. // convert quadratic points to cubic points
  22684. $x1 = $params[($ck - 3)] + $xoffset;
  22685. $y1 = $params[($ck - 2)] + $yoffset;
  22686. $xa = ($x + (2 * $x1)) / 3;
  22687. $ya = ($y + (2 * $y1)) / 3;
  22688. $x = $params[($ck - 1)] + $xoffset;
  22689. $y = $params[($ck)] + $yoffset;
  22690. $xb = ($x + (2 * $x1)) / 3;
  22691. $yb = ($y + (2 * $y1)) / 3;
  22692. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  22693. $xmin = min($xmin, $x, $xa, $xb);
  22694. $ymin = min($ymin, $y, $ya, $yb);
  22695. $xmax = max($xmax, $x, $xa, $xb);
  22696. $ymax = max($ymax, $y, $ya, $yb);
  22697. if ($relcoord) {
  22698. $xoffset = $x;
  22699. $yoffset = $y;
  22700. }
  22701. }
  22702. }
  22703. break;
  22704. }
  22705. case 'T': { // shorthand/smooth quadratic B\E9zier curveto
  22706. foreach ($params as $ck => $cp) {
  22707. $params[$ck] = $cp;
  22708. if (($ck % 2) != 0) {
  22709. if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
  22710. $x1 = (2 * $x) - $x1;
  22711. $y1 = (2 * $y) - $y1;
  22712. } else {
  22713. $x1 = $x;
  22714. $y1 = $y;
  22715. }
  22716. // convert quadratic points to cubic points
  22717. $xa = ($x + (2 * $x1)) / 3;
  22718. $ya = ($y + (2 * $y1)) / 3;
  22719. $x = $params[($ck - 1)] + $xoffset;
  22720. $y = $params[($ck)] + $yoffset;
  22721. $xb = ($x + (2 * $x1)) / 3;
  22722. $yb = ($y + (2 * $y1)) / 3;
  22723. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  22724. $xmin = min($xmin, $x, $xa, $xb);
  22725. $ymin = min($ymin, $y, $ya, $yb);
  22726. $xmax = max($xmax, $x, $xa, $xb);
  22727. $ymax = max($ymax, $y, $ya, $yb);
  22728. if ($relcoord) {
  22729. $xoffset = $x;
  22730. $yoffset = $y;
  22731. }
  22732. }
  22733. }
  22734. break;
  22735. }
  22736. case 'A': { // elliptical arc
  22737. foreach ($params as $ck => $cp) {
  22738. $params[$ck] = $cp;
  22739. if ((($ck + 1) % 7) == 0) {
  22740. $x0 = $x;
  22741. $y0 = $y;
  22742. $rx = abs($params[($ck - 6)]);
  22743. $ry = abs($params[($ck - 5)]);
  22744. $ang = -$rawparams[($ck - 4)];
  22745. $angle = deg2rad($ang);
  22746. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  22747. $fs = $rawparams[($ck - 2)]; // sweep-flag
  22748. $x = $params[($ck - 1)] + $xoffset;
  22749. $y = $params[$ck] + $yoffset;
  22750. if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
  22751. // endpoints are almost identical
  22752. $xmin = min($xmin, $x);
  22753. $ymin = min($ymin, $y);
  22754. $xmax = max($xmax, $x);
  22755. $ymax = max($ymax, $y);
  22756. } else {
  22757. $cos_ang = cos($angle);
  22758. $sin_ang = sin($angle);
  22759. $a = (($x0 - $x) / 2);
  22760. $b = (($y0 - $y) / 2);
  22761. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  22762. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  22763. $rx2 = $rx * $rx;
  22764. $ry2 = $ry * $ry;
  22765. $xa2 = $xa * $xa;
  22766. $ya2 = $ya * $ya;
  22767. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  22768. if ($delta > 1) {
  22769. $rx *= sqrt($delta);
  22770. $ry *= sqrt($delta);
  22771. $rx2 = $rx * $rx;
  22772. $ry2 = $ry * $ry;
  22773. }
  22774. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  22775. if ($numerator < 0) {
  22776. $root = 0;
  22777. } else {
  22778. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  22779. }
  22780. if ($fa == $fs){
  22781. $root *= -1;
  22782. }
  22783. $cax = $root * (($rx * $ya) / $ry);
  22784. $cay = -$root * (($ry * $xa) / $rx);
  22785. // coordinates of ellipse center
  22786. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  22787. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  22788. // get angles
  22789. $angs = TCPDF_STATIC::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  22790. $dang = TCPDF_STATIC::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
  22791. if (($fs == 0) AND ($dang > 0)) {
  22792. $dang -= (2 * M_PI);
  22793. } elseif (($fs == 1) AND ($dang < 0)) {
  22794. $dang += (2 * M_PI);
  22795. }
  22796. $angf = $angs - $dang;
  22797. if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
  22798. // reverse angles
  22799. $tmp = $angs;
  22800. $angs = $angf;
  22801. $angf = $tmp;
  22802. }
  22803. $angs = round(rad2deg($angs), 6);
  22804. $angf = round(rad2deg($angf), 6);
  22805. // covent angles to positive values
  22806. if (($angs < 0) AND ($angf < 0)) {
  22807. $angs += 360;
  22808. $angf += 360;
  22809. }
  22810. $pie = false;
  22811. if (($key == 0) AND (isset($paths[($key + 1)][1])) AND (trim($paths[($key + 1)][1]) == 'z')) {
  22812. $pie = true;
  22813. }
  22814. list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
  22815. $xmin = min($xmin, $x, $axmin);
  22816. $ymin = min($ymin, $y, $aymin);
  22817. $xmax = max($xmax, $x, $axmax);
  22818. $ymax = max($ymax, $y, $aymax);
  22819. }
  22820. if ($relcoord) {
  22821. $xoffset = $x;
  22822. $yoffset = $y;
  22823. }
  22824. }
  22825. }
  22826. break;
  22827. }
  22828. case 'Z': {
  22829. $this->_out('h');
  22830. break;
  22831. }
  22832. }
  22833. $firstcmd = false;
  22834. } // end foreach
  22835. if (!empty($op)) {
  22836. $this->_out($op);
  22837. }
  22838. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  22839. }
  22840. /**
  22841. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  22842. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  22843. * @param $name (string) 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.
  22844. * @param $attribs (array) 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.
  22845. * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
  22846. * @author Nicola Asuni
  22847. * @since 5.0.000 (2010-05-02)
  22848. * @protected
  22849. */
  22850. protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
  22851. // check if we are in clip mode
  22852. if ($this->svgclipmode) {
  22853. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm[$this->svgclipid]);
  22854. return;
  22855. }
  22856. if ($this->svgdefsmode AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
  22857. if (!isset($attribs['id'])) {
  22858. $attribs['id'] = 'DF_'.(count($this->svgdefs) + 1);
  22859. }
  22860. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  22861. return;
  22862. }
  22863. $clipping = false;
  22864. if ($parser == 'clip-path') {
  22865. // set clipping mode
  22866. $clipping = true;
  22867. }
  22868. // get styling properties
  22869. $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)]; // previous style
  22870. $svgstyle = $this->svgstyles[0]; // set default style
  22871. if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
  22872. // default fill attribute for clipping
  22873. $attribs['fill'] = 'none';
  22874. }
  22875. if (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  22876. // fix style for regular expression
  22877. $attribs['style'] = ';'.$attribs['style'];
  22878. }
  22879. foreach ($prev_svgstyle as $key => $val) {
  22880. if (in_array($key, TCPDF_IMAGES::$svginheritprop)) {
  22881. // inherit previous value
  22882. $svgstyle[$key] = $val;
  22883. }
  22884. if (isset($attribs[$key]) AND !TCPDF_STATIC::empty_string($attribs[$key])) {
  22885. // specific attribute settings
  22886. if ($attribs[$key] == 'inherit') {
  22887. $svgstyle[$key] = $val;
  22888. } else {
  22889. $svgstyle[$key] = $attribs[$key];
  22890. }
  22891. } elseif (isset($attribs['style']) AND !TCPDF_STATIC::empty_string($attribs['style'])) {
  22892. // CSS style syntax
  22893. $attrval = array();
  22894. if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
  22895. if ($attrval[1] == 'inherit') {
  22896. $svgstyle[$key] = $val;
  22897. } else {
  22898. $svgstyle[$key] = $attrval[1];
  22899. }
  22900. }
  22901. }
  22902. }
  22903. // transformation matrix
  22904. if (!empty($ctm)) {
  22905. $tm = $ctm;
  22906. } else {
  22907. $tm = array(1,0,0,1,0,0);
  22908. }
  22909. if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
  22910. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, TCPDF_STATIC::getSVGTransformMatrix($attribs['transform']));
  22911. }
  22912. $svgstyle['transfmatrix'] = $tm;
  22913. $invisible = false;
  22914. if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
  22915. // the current graphics element is invisible (nothing is painted)
  22916. $invisible = true;
  22917. }
  22918. // process tag
  22919. switch($name) {
  22920. case 'defs': {
  22921. $this->svgdefsmode = true;
  22922. break;
  22923. }
  22924. // clipPath
  22925. case 'clipPath': {
  22926. if ($invisible) {
  22927. break;
  22928. }
  22929. $this->svgclipmode = true;
  22930. if (!isset($attribs['id'])) {
  22931. $attribs['id'] = 'CP_'.(count($this->svgcliptm) + 1);
  22932. }
  22933. $this->svgclipid = $attribs['id'];
  22934. $this->svgclippaths[$this->svgclipid] = array();
  22935. $this->svgcliptm[$this->svgclipid] = $tm;
  22936. break;
  22937. }
  22938. case 'svg': {
  22939. // start of SVG object
  22940. break;
  22941. }
  22942. case 'g': {
  22943. // group together related graphics elements
  22944. array_push($this->svgstyles, $svgstyle);
  22945. $this->StartTransform();
  22946. $this->SVGTransform($tm);
  22947. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  22948. break;
  22949. }
  22950. case 'linearGradient': {
  22951. if ($this->pdfa_mode) {
  22952. break;
  22953. }
  22954. if (!isset($attribs['id'])) {
  22955. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  22956. }
  22957. $this->svggradientid = $attribs['id'];
  22958. $this->svggradients[$this->svggradientid] = array();
  22959. $this->svggradients[$this->svggradientid]['type'] = 2;
  22960. $this->svggradients[$this->svggradientid]['stops'] = array();
  22961. if (isset($attribs['gradientUnits'])) {
  22962. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  22963. } else {
  22964. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  22965. }
  22966. //$attribs['spreadMethod']
  22967. if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
  22968. OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
  22969. OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
  22970. OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
  22971. OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
  22972. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  22973. } else {
  22974. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  22975. }
  22976. $x1 = (isset($attribs['x1'])?$attribs['x1']:'0');
  22977. $y1 = (isset($attribs['y1'])?$attribs['y1']:'0');
  22978. $x2 = (isset($attribs['x2'])?$attribs['x2']:'100');
  22979. $y2 = (isset($attribs['y2'])?$attribs['y2']:'0');
  22980. if (isset($attribs['gradientTransform'])) {
  22981. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  22982. }
  22983. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  22984. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  22985. // gradient is defined on another place
  22986. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  22987. }
  22988. break;
  22989. }
  22990. case 'radialGradient': {
  22991. if ($this->pdfa_mode) {
  22992. break;
  22993. }
  22994. if (!isset($attribs['id'])) {
  22995. $attribs['id'] = 'GR_'.(count($this->svggradients) + 1);
  22996. }
  22997. $this->svggradientid = $attribs['id'];
  22998. $this->svggradients[$this->svggradientid] = array();
  22999. $this->svggradients[$this->svggradientid]['type'] = 3;
  23000. $this->svggradients[$this->svggradientid]['stops'] = array();
  23001. if (isset($attribs['gradientUnits'])) {
  23002. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  23003. } else {
  23004. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  23005. }
  23006. //$attribs['spreadMethod']
  23007. if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
  23008. OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
  23009. OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')) )) {
  23010. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  23011. } else {
  23012. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  23013. }
  23014. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  23015. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  23016. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  23017. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  23018. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  23019. if (isset($attribs['gradientTransform'])) {
  23020. $this->svggradients[$this->svggradientid]['gradientTransform'] = TCPDF_STATIC::getSVGTransformMatrix($attribs['gradientTransform']);
  23021. }
  23022. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  23023. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23024. // gradient is defined on another place
  23025. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  23026. }
  23027. break;
  23028. }
  23029. case 'stop': {
  23030. // gradient stops
  23031. if (substr($attribs['offset'], -1) == '%') {
  23032. $offset = floatval(substr($attribs['offset'], -1)) / 100;
  23033. } else {
  23034. $offset = floatval($attribs['offset']);
  23035. if ($offset > 1) {
  23036. $offset /= 100;
  23037. }
  23038. }
  23039. $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors):'black';
  23040. $opacity = isset($svgstyle['stop-opacity'])?$svgstyle['stop-opacity']:1;
  23041. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
  23042. break;
  23043. }
  23044. // paths
  23045. case 'path': {
  23046. if ($invisible) {
  23047. break;
  23048. }
  23049. if (isset($attribs['d'])) {
  23050. $d = trim($attribs['d']);
  23051. if (!empty($d)) {
  23052. $x = (isset($attribs['x'])?$attribs['x']:0);
  23053. $y = (isset($attribs['y'])?$attribs['y']:0);
  23054. $w = (isset($attribs['width'])?$attribs['width']:1);
  23055. $h = (isset($attribs['height'])?$attribs['height']:1);
  23056. $tm = TCPDF_STATIC::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
  23057. if ($clipping) {
  23058. $this->SVGTransform($tm);
  23059. $this->SVGPath($d, 'CNZ');
  23060. } else {
  23061. $this->StartTransform();
  23062. $this->SVGTransform($tm);
  23063. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
  23064. if (!empty($obstyle)) {
  23065. $this->SVGPath($d, $obstyle);
  23066. }
  23067. $this->StopTransform();
  23068. }
  23069. }
  23070. }
  23071. break;
  23072. }
  23073. // shapes
  23074. case 'rect': {
  23075. if ($invisible) {
  23076. break;
  23077. }
  23078. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23079. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23080. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23081. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23082. $rx = (isset($attribs['rx'])?$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false):0);
  23083. $ry = (isset($attribs['ry'])?$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false):$rx);
  23084. if ($clipping) {
  23085. $this->SVGTransform($tm);
  23086. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  23087. } else {
  23088. $this->StartTransform();
  23089. $this->SVGTransform($tm);
  23090. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  23091. if (!empty($obstyle)) {
  23092. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  23093. }
  23094. $this->StopTransform();
  23095. }
  23096. break;
  23097. }
  23098. case 'circle': {
  23099. if ($invisible) {
  23100. break;
  23101. }
  23102. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  23103. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23104. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23105. $x = ($cx - $r);
  23106. $y = ($cy - $r);
  23107. $w = (2 * $r);
  23108. $h = $w;
  23109. if ($clipping) {
  23110. $this->SVGTransform($tm);
  23111. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  23112. } else {
  23113. $this->StartTransform();
  23114. $this->SVGTransform($tm);
  23115. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
  23116. if (!empty($obstyle)) {
  23117. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  23118. }
  23119. $this->StopTransform();
  23120. }
  23121. break;
  23122. }
  23123. case 'ellipse': {
  23124. if ($invisible) {
  23125. break;
  23126. }
  23127. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  23128. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  23129. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0));
  23130. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0));
  23131. $x = ($cx - $rx);
  23132. $y = ($cy - $ry);
  23133. $w = (2 * $rx);
  23134. $h = (2 * $ry);
  23135. if ($clipping) {
  23136. $this->SVGTransform($tm);
  23137. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  23138. } else {
  23139. $this->StartTransform();
  23140. $this->SVGTransform($tm);
  23141. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  23142. if (!empty($obstyle)) {
  23143. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  23144. }
  23145. $this->StopTransform();
  23146. }
  23147. break;
  23148. }
  23149. case 'line': {
  23150. if ($invisible) {
  23151. break;
  23152. }
  23153. $x1 = (isset($attribs['x1'])?$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false):0);
  23154. $y1 = (isset($attribs['y1'])?$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false):0);
  23155. $x2 = (isset($attribs['x2'])?$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false):0);
  23156. $y2 = (isset($attribs['y2'])?$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false):0);
  23157. $x = $x1;
  23158. $y = $y1;
  23159. $w = abs($x2 - $x1);
  23160. $h = abs($y2 - $y1);
  23161. if (!$clipping) {
  23162. $this->StartTransform();
  23163. $this->SVGTransform($tm);
  23164. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
  23165. $this->Line($x1, $y1, $x2, $y2);
  23166. $this->StopTransform();
  23167. }
  23168. break;
  23169. }
  23170. case 'polyline':
  23171. case 'polygon': {
  23172. if ($invisible) {
  23173. break;
  23174. }
  23175. $points = (isset($attribs['points'])?$attribs['points']:'0 0');
  23176. $points = trim($points);
  23177. // note that point may use a complex syntax not covered here
  23178. $points = preg_split('/[\,\s]+/si', $points);
  23179. if (count($points) < 4) {
  23180. break;
  23181. }
  23182. $p = array();
  23183. $xmin = 2147483647;
  23184. $xmax = 0;
  23185. $ymin = 2147483647;
  23186. $ymax = 0;
  23187. foreach ($points as $key => $val) {
  23188. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  23189. if (($key % 2) == 0) {
  23190. // X coordinate
  23191. $xmin = min($xmin, $p[$key]);
  23192. $xmax = max($xmax, $p[$key]);
  23193. } else {
  23194. // Y coordinate
  23195. $ymin = min($ymin, $p[$key]);
  23196. $ymax = max($ymax, $p[$key]);
  23197. }
  23198. }
  23199. $x = $xmin;
  23200. $y = $ymin;
  23201. $w = ($xmax - $xmin);
  23202. $h = ($ymax - $ymin);
  23203. if ($name == 'polyline') {
  23204. $this->StartTransform();
  23205. $this->SVGTransform($tm);
  23206. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
  23207. if (!empty($obstyle)) {
  23208. $this->PolyLine($p, $obstyle, array(), array());
  23209. }
  23210. $this->StopTransform();
  23211. } else { // polygon
  23212. if ($clipping) {
  23213. $this->SVGTransform($tm);
  23214. $this->Polygon($p, 'CNZ', array(), array(), true);
  23215. } else {
  23216. $this->StartTransform();
  23217. $this->SVGTransform($tm);
  23218. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
  23219. if (!empty($obstyle)) {
  23220. $this->Polygon($p, $obstyle, array(), array(), true);
  23221. }
  23222. $this->StopTransform();
  23223. }
  23224. }
  23225. break;
  23226. }
  23227. // image
  23228. case 'image': {
  23229. if ($invisible) {
  23230. break;
  23231. }
  23232. if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
  23233. break;
  23234. }
  23235. $x = (isset($attribs['x'])?$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false):0);
  23236. $y = (isset($attribs['y'])?$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false):0);
  23237. $w = (isset($attribs['width'])?$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false):0);
  23238. $h = (isset($attribs['height'])?$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false):0);
  23239. $img = $attribs['xlink:href'];
  23240. if (!$clipping) {
  23241. $this->StartTransform();
  23242. $this->SVGTransform($tm);
  23243. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  23244. if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
  23245. // embedded image encoded as base64
  23246. $img = '@'.base64_decode(substr($img, strlen($m[0])));
  23247. } else {
  23248. // fix image path
  23249. if (!TCPDF_STATIC::empty_string($this->svgdir) AND (($img{0} == '.') OR (basename($img) == $img))) {
  23250. // replace relative path with full server path
  23251. $img = $this->svgdir.'/'.$img;
  23252. }
  23253. if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
  23254. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  23255. if (($findroot === false) OR ($findroot > 1)) {
  23256. if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
  23257. $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
  23258. } else {
  23259. $img = $_SERVER['DOCUMENT_ROOT'].$img;
  23260. }
  23261. }
  23262. }
  23263. $img = urldecode($img);
  23264. $testscrtype = @parse_url($img);
  23265. if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
  23266. // convert URL to server path
  23267. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  23268. }
  23269. }
  23270. // get image type
  23271. $imgtype = TCPDF_IMAGES::getImageFileType($img);
  23272. if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
  23273. $this->ImageEps($img, $x, $y, $w, $h);
  23274. } elseif ($imgtype == 'svg') {
  23275. $this->ImageSVG($img, $x, $y, $w, $h);
  23276. } else {
  23277. $this->Image($img, $x, $y, $w, $h);
  23278. }
  23279. $this->StopTransform();
  23280. }
  23281. break;
  23282. }
  23283. // text
  23284. case 'text':
  23285. case 'tspan': {
  23286. // only basic support - advanced features must be implemented
  23287. $this->svgtextmode['invisible'] = $invisible;
  23288. if ($invisible) {
  23289. break;
  23290. }
  23291. array_push($this->svgstyles, $svgstyle);
  23292. if (isset($attribs['x'])) {
  23293. $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false);
  23294. } elseif ($name == 'tspan') {
  23295. $x = $this->x;
  23296. } else {
  23297. $x = 0;
  23298. }
  23299. if (isset($attribs['dx'])) {
  23300. $x += $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit, false);
  23301. }
  23302. if (isset($attribs['y'])) {
  23303. $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false);
  23304. } elseif ($name == 'tspan') {
  23305. $y = $this->y;
  23306. } else {
  23307. $y = 0;
  23308. }
  23309. if (isset($attribs['dy'])) {
  23310. $y += $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit, false);
  23311. }
  23312. $svgstyle['text-color'] = $svgstyle['fill'];
  23313. $this->svgtext = '';
  23314. if (isset($svgstyle['text-anchor'])) {
  23315. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  23316. } else {
  23317. $this->svgtextmode['text-anchor'] = 'start';
  23318. }
  23319. if (isset($svgstyle['direction'])) {
  23320. if ($svgstyle['direction'] == 'rtl') {
  23321. $this->svgtextmode['rtl'] = true;
  23322. } else {
  23323. $this->svgtextmode['rtl'] = false;
  23324. }
  23325. } else {
  23326. $this->svgtextmode['rtl'] = false;
  23327. }
  23328. if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
  23329. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  23330. } else {
  23331. $this->svgtextmode['stroke'] = false;
  23332. }
  23333. $this->StartTransform();
  23334. $this->SVGTransform($tm);
  23335. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  23336. $this->x = $x;
  23337. $this->y = $y;
  23338. break;
  23339. }
  23340. // use
  23341. case 'use': {
  23342. if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
  23343. $svgdefid = substr($attribs['xlink:href'], 1);
  23344. if (isset($this->svgdefs[$svgdefid])) {
  23345. $use = $this->svgdefs[$svgdefid];
  23346. if (isset($attribs['xlink:href'])) {
  23347. unset($attribs['xlink:href']);
  23348. }
  23349. if (isset($attribs['id'])) {
  23350. unset($attribs['id']);
  23351. }
  23352. if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
  23353. $attribs['x'] += $use['attribs']['x'];
  23354. }
  23355. if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
  23356. $attribs['y'] += $use['attribs']['y'];
  23357. }
  23358. $attribs = array_merge($use['attribs'], $attribs);
  23359. $this->startSVGElementHandler($parser, $use['name'], $attribs);
  23360. }
  23361. }
  23362. break;
  23363. }
  23364. default: {
  23365. break;
  23366. }
  23367. } // end of switch
  23368. }
  23369. /**
  23370. * Sets the closing SVG element handler function for the XML parser.
  23371. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23372. * @param $name (string) 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.
  23373. * @author Nicola Asuni
  23374. * @since 5.0.000 (2010-05-02)
  23375. * @protected
  23376. */
  23377. protected function endSVGElementHandler($parser, $name) {
  23378. switch($name) {
  23379. case 'defs': {
  23380. $this->svgdefsmode = false;
  23381. break;
  23382. }
  23383. // clipPath
  23384. case 'clipPath': {
  23385. $this->svgclipmode = false;
  23386. break;
  23387. }
  23388. case 'g': {
  23389. // ungroup: remove last style from array
  23390. array_pop($this->svgstyles);
  23391. $this->StopTransform();
  23392. break;
  23393. }
  23394. case 'text':
  23395. case 'tspan': {
  23396. if ($this->svgtextmode['invisible']) {
  23397. // This implementation must be fixed to following the rule:
  23398. // 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.
  23399. break;
  23400. }
  23401. // print text
  23402. $text = $this->svgtext;
  23403. //$text = $this->stringTrim($text);
  23404. $textlen = $this->GetStringWidth($text);
  23405. if ($this->svgtextmode['text-anchor'] != 'start') {
  23406. // check if string is RTL text
  23407. if ($this->svgtextmode['text-anchor'] == 'end') {
  23408. if ($this->svgtextmode['rtl']) {
  23409. $this->x += $textlen;
  23410. } else {
  23411. $this->x -= $textlen;
  23412. }
  23413. } elseif ($this->svgtextmode['text-anchor'] == 'middle') {
  23414. if ($this->svgtextmode['rtl']) {
  23415. $this->x += ($textlen / 2);
  23416. } else {
  23417. $this->x -= ($textlen / 2);
  23418. }
  23419. }
  23420. }
  23421. $textrendermode = $this->textrendermode;
  23422. $textstrokewidth = $this->textstrokewidth;
  23423. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  23424. if ($name == 'text') {
  23425. // store current coordinates
  23426. $tmpx = $this->x;
  23427. $tmpy = $this->y;
  23428. }
  23429. $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  23430. if ($name == 'text') {
  23431. // restore coordinates
  23432. $this->x = $tmpx;
  23433. $this->y = $tmpy;
  23434. }
  23435. // restore previous rendering mode
  23436. $this->textrendermode = $textrendermode;
  23437. $this->textstrokewidth = $textstrokewidth;
  23438. $this->svgtext = '';
  23439. $this->StopTransform();
  23440. array_pop($this->svgstyles);
  23441. break;
  23442. }
  23443. default: {
  23444. break;
  23445. }
  23446. }
  23447. }
  23448. /**
  23449. * Sets the character data handler function for the XML parser.
  23450. * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
  23451. * @param $data (string) The second parameter, data, contains the character data as a string.
  23452. * @author Nicola Asuni
  23453. * @since 5.0.000 (2010-05-02)
  23454. * @protected
  23455. */
  23456. protected function segSVGContentHandler($parser, $data) {
  23457. $this->svgtext .= $data;
  23458. }
  23459. // --- END SVG METHODS -----------------------------------------------------
  23460. } // END OF TCPDF CLASS
  23461. //============================================================+
  23462. // END OF FILE
  23463. //============================================================+