/common/libraries/plugin/phpexcel/PHPExcel/Shared/PDF/tcpdf.php

https://bitbucket.org/cbenelug/chamilo · PHP · 31848 lines · 23824 code · 729 blank · 7295 comment · 3286 complexity · 721400aec663f78f78f877c4863d1691 MD5 · raw file

  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Version : 5.9.009
  5. // Begin : 2002-08-03
  6. // Last Update : 2010-10-21
  7. // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  8. // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2010 Nicola Asuni - Tecnick.com S.r.l.
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the GNU Lesser General Public License
  25. // along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
  26. //
  27. // See LICENSE.TXT file for more information.
  28. // -------------------------------------------------------------------
  29. //
  30. // Description : This is a PHP class for generating PDF documents without
  31. // requiring external extensions.
  32. //
  33. // NOTE:
  34. // This class was originally derived in 2002 from the Public
  35. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  36. // but now is almost entirely rewritten and contains thousands of
  37. // new lines of code and hundreds new features.
  38. //
  39. // Main features:
  40. // * no external libraries are required for the basic functions;
  41. // * all standard page formats, custom page formats, custom margins and units of measure;
  42. // * UTF-8 Unicode and Right-To-Left languages;
  43. // * TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  44. // * font subsetting;
  45. // * methods to publish some XHTML + CSS code, Javascript and Forms;
  46. // * images, graphic (geometric figures) and transformation methods;
  47. // * 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)
  48. // * 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, QR-Code, PDF417;
  49. // * Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  50. // * automatic page header and footer management;
  51. // * document encryption up to 256 bit and digital signature certifications;
  52. // * transactions to UNDO commands;
  53. // * PDF annotations, including links, text and file attachments;
  54. // * text rendering modes (fill, stroke and clipping);
  55. // * multiple columns mode;
  56. // * no-write page regions;
  57. // * bookmarks and table of content;
  58. // * text hyphenation;
  59. // * text stretching and spacing (tracking/kerning);
  60. // * automatic page break, line break and text alignments including justification;
  61. // * automatic page numbering and page groups;
  62. // * move and delete pages;
  63. // * page compression (requires php-zlib extension);
  64. // * XOBject Templates;
  65. //
  66. // -----------------------------------------------------------
  67. // THANKS TO:
  68. //
  69. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  70. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  71. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  72. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  73. // dullus for text Justification.
  74. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  75. // Patrick Benny for text stretch suggestion on Cell().
  76. // Johannes G�ntert for JavaScript support.
  77. // Denis Van Nuffelen for Dynamic Form.
  78. // Jacek Czekaj for multibyte justification
  79. // Anthony Ferrara for the reintroduction of legacy image methods.
  80. // Sourceforge user 1707880 (hucste) for line-trough mode.
  81. // Larry Stanbery for page groups.
  82. // Martin Hall-May for transparency.
  83. // Aaron C. Spike for Polycurve method.
  84. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  85. // Moritz Wagner and Andreas Wurmser for graphic functions.
  86. // Andrew Whitehead for core fonts support.
  87. // Esteban Jo�l Mar�n for OpenType font conversion.
  88. // Teus Hagen for several suggestions and fixes.
  89. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  90. // Kosmas Papachristos for some CSS improvements.
  91. // Marcel Partap for some fixes.
  92. // Won Kyu Park for several suggestions, fixes and patches.
  93. // Dominik Dzienia for QR-code support.
  94. // Laurent Minguet for some suggestions.
  95. // Christian Deligant for some suggestions and fixes.
  96. // Anyone that has reported a bug or sent a suggestion.
  97. //============================================================+
  98. /**
  99. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  100. * 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>
  101. * <h3>TCPDF main features are:</h3>
  102. * <ul>
  103. * <li>no external libraries are required for the basic functions;</li>
  104. * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
  105. * <li>UTF-8 Unicode and Right-To-Left languages;</li>
  106. * <li>TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  107. * <li>font subsetting;</li>
  108. * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
  109. * <li>images, graphic (geometric figures) and transformation methods;
  110. * <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>
  111. * <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, QR-Code, PDF417;</li>
  112. * <li>Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  113. * <li>automatic page header and footer management;</li>
  114. * <li>document encryption up to 256 bit and digital signature certifications;</li>
  115. * <li>transactions to UNDO commands;</li>
  116. * <li>PDF annotations, including links, text and file attachments;</li>
  117. * <li>text rendering modes (fill, stroke and clipping);</li>
  118. * <li>multiple columns mode;</li>
  119. * <li>no-write page regions;</li>
  120. * <li>bookmarks and table of content;</li>
  121. * <li>text hyphenation;</li>
  122. * <li>text stretching and spacing (tracking/kerning);</li>
  123. * <li>automatic page break, line break and text alignments including justification;</li>
  124. * <li>automatic page numbering and page groups;</li>
  125. * <li>move and delete pages;</li>
  126. * <li>page compression (requires php-zlib extension);</li>
  127. * <li>XOBject Templates;</li>
  128. * </ul>
  129. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  130. * @package com.tecnick.tcpdf
  131. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  132. * @author Nicola Asuni
  133. * @copyright 2002-2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  134. * @link http://www.tcpdf.org
  135. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  136. * @version 5.9.009
  137. */
  138. /**
  139. * main configuration file
  140. * (define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file)
  141. */
  142. require_once (dirname(__FILE__) . '/config/tcpdf_config.php');
  143. /**
  144. * define default PDF document producer
  145. */
  146. define('PDF_PRODUCER', 'TCPDF 5.9.009 (http://www.tcpdf.org)');
  147. /**
  148. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  149. * 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>
  150. * @name TCPDF
  151. * @package com.tecnick.tcpdf
  152. * @version 5.9.009
  153. * @author Nicola Asuni - info@tecnick.com
  154. * @link http://www.tcpdf.org
  155. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  156. */
  157. class TCPDF
  158. {
  159. // Protected properties
  160. /**
  161. * @var current page number
  162. * @access protected
  163. */
  164. protected $page;
  165. /**
  166. * @var current object number
  167. * @access protected
  168. */
  169. protected $n;
  170. /**
  171. * @var array of object offsets
  172. * @access protected
  173. */
  174. protected $offsets;
  175. /**
  176. * @var buffer holding in-memory PDF
  177. * @access protected
  178. */
  179. protected $buffer;
  180. /**
  181. * @var array containing pages
  182. * @access protected
  183. */
  184. protected $pages = array();
  185. /**
  186. * @var current document state
  187. * @access protected
  188. */
  189. protected $state;
  190. /**
  191. * @var compression flag
  192. * @access protected
  193. */
  194. protected $compress;
  195. /**
  196. * @var current page orientation (P = Portrait, L = Landscape)
  197. * @access protected
  198. */
  199. protected $CurOrientation;
  200. /**
  201. * @var Page dimensions
  202. * @access protected
  203. */
  204. protected $pagedim = array();
  205. /**
  206. * @var scale factor (number of points in user unit)
  207. * @access protected
  208. */
  209. protected $k;
  210. /**
  211. * @var width of page format in points
  212. * @access protected
  213. */
  214. protected $fwPt;
  215. /**
  216. * @var height of page format in points
  217. * @access protected
  218. */
  219. protected $fhPt;
  220. /**
  221. * @var current width of page in points
  222. * @access protected
  223. */
  224. protected $wPt;
  225. /**
  226. * @var current height of page in points
  227. * @access protected
  228. */
  229. protected $hPt;
  230. /**
  231. * @var current width of page in user unit
  232. * @access protected
  233. */
  234. protected $w;
  235. /**
  236. * @var current height of page in user unit
  237. * @access protected
  238. */
  239. protected $h;
  240. /**
  241. * @var left margin
  242. * @access protected
  243. */
  244. protected $lMargin;
  245. /**
  246. * @var top margin
  247. * @access protected
  248. */
  249. protected $tMargin;
  250. /**
  251. * @var right margin
  252. * @access protected
  253. */
  254. protected $rMargin;
  255. /**
  256. * @var page break margin
  257. * @access protected
  258. */
  259. protected $bMargin;
  260. /**
  261. * @var array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left)
  262. * @since 5.9.000 (2010-10-03)
  263. * @access protected
  264. */
  265. protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  266. /**
  267. * @var array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left)
  268. * @since 5.9.000 (2010-10-04)
  269. * @access protected
  270. */
  271. protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
  272. /**
  273. * @var current horizontal position in user unit for cell positioning
  274. * @access protected
  275. */
  276. protected $x;
  277. /**
  278. * @var current vertical position in user unit for cell positioning
  279. * @access protected
  280. */
  281. protected $y;
  282. /**
  283. * @var height of last cell printed
  284. * @access protected
  285. */
  286. protected $lasth;
  287. /**
  288. * @var line width in user unit
  289. * @access protected
  290. */
  291. protected $LineWidth;
  292. /**
  293. * @var array of standard font names
  294. * @access protected
  295. */
  296. protected $CoreFonts;
  297. /**
  298. * @var array of used fonts
  299. * @access protected
  300. */
  301. protected $fonts = array();
  302. /**
  303. * @var array of font files
  304. * @access protected
  305. */
  306. protected $FontFiles = array();
  307. /**
  308. * @var array of encoding differences
  309. * @access protected
  310. */
  311. protected $diffs = array();
  312. /**
  313. * @var array of used images
  314. * @access protected
  315. */
  316. protected $images = array();
  317. /**
  318. * @var array of Annotations in pages
  319. * @access protected
  320. */
  321. protected $PageAnnots = array();
  322. /**
  323. * @var array of internal links
  324. * @access protected
  325. */
  326. protected $links = array();
  327. /**
  328. * @var current font family
  329. * @access protected
  330. */
  331. protected $FontFamily;
  332. /**
  333. * @var current font style
  334. * @access protected
  335. */
  336. protected $FontStyle;
  337. /**
  338. * @var current font ascent (distance between font top and baseline)
  339. * @access protected
  340. * @since 2.8.000 (2007-03-29)
  341. */
  342. protected $FontAscent;
  343. /**
  344. * @var current font descent (distance between font bottom and baseline)
  345. * @access protected
  346. * @since 2.8.000 (2007-03-29)
  347. */
  348. protected $FontDescent;
  349. /**
  350. * @var underlining flag
  351. * @access protected
  352. */
  353. protected $underline;
  354. /**
  355. * @var overlining flag
  356. * @access protected
  357. */
  358. protected $overline;
  359. /**
  360. * @var current font info
  361. * @access protected
  362. */
  363. protected $CurrentFont;
  364. /**
  365. * @var current font size in points
  366. * @access protected
  367. */
  368. protected $FontSizePt;
  369. /**
  370. * @var current font size in user unit
  371. * @access protected
  372. */
  373. protected $FontSize;
  374. /**
  375. * @var commands for drawing color
  376. * @access protected
  377. */
  378. protected $DrawColor;
  379. /**
  380. * @var commands for filling color
  381. * @access protected
  382. */
  383. protected $FillColor;
  384. /**
  385. * @var commands for text color
  386. * @access protected
  387. */
  388. protected $TextColor;
  389. /**
  390. * @var indicates whether fill and text colors are different
  391. * @access protected
  392. */
  393. protected $ColorFlag;
  394. /**
  395. * @var automatic page breaking
  396. * @access protected
  397. */
  398. protected $AutoPageBreak;
  399. /**
  400. * @var threshold used to trigger page breaks
  401. * @access protected
  402. */
  403. protected $PageBreakTrigger;
  404. /**
  405. * @var flag set when processing footer
  406. * @access protected
  407. */
  408. protected $InFooter = false;
  409. /**
  410. * @var zoom display mode
  411. * @access protected
  412. */
  413. protected $ZoomMode;
  414. /**
  415. * @var layout display mode
  416. * @access protected
  417. */
  418. protected $LayoutMode;
  419. /**
  420. * @var title
  421. * @access protected
  422. */
  423. protected $title = '';
  424. /**
  425. * @var subject
  426. * @access protected
  427. */
  428. protected $subject = '';
  429. /**
  430. * @var author
  431. * @access protected
  432. */
  433. protected $author = '';
  434. /**
  435. * @var keywords
  436. * @access protected
  437. */
  438. protected $keywords = '';
  439. /**
  440. * @var creator
  441. * @access protected
  442. */
  443. protected $creator = '';
  444. /**
  445. * @var alias for total number of pages
  446. * @access protected
  447. */
  448. protected $AliasNbPages = '{nb}';
  449. /**
  450. * @var alias for page number
  451. * @access protected
  452. */
  453. protected $AliasNumPage = '{pnb}';
  454. /**
  455. * @var right-bottom corner X coordinate of inserted image
  456. * @since 2002-07-31
  457. * @author Nicola Asuni
  458. * @access protected
  459. */
  460. protected $img_rb_x;
  461. /**
  462. * @var right-bottom corner Y coordinate of inserted image
  463. * @since 2002-07-31
  464. * @author Nicola Asuni
  465. * @access protected
  466. */
  467. protected $img_rb_y;
  468. /**
  469. * @var adjusting factor to convert pixels to user units.
  470. * @since 2004-06-14
  471. * @author Nicola Asuni
  472. * @access protected
  473. */
  474. protected $imgscale = 1;
  475. /**
  476. * @var boolean set to true when the input text is unicode (require unicode fonts)
  477. * @since 2005-01-02
  478. * @author Nicola Asuni
  479. * @access protected
  480. */
  481. protected $isunicode = false;
  482. /**
  483. * @var object containing unicode data
  484. * @since 5.9.004 (2010-10-18)
  485. * @author Nicola Asuni
  486. * @access protected
  487. */
  488. protected $unicode;
  489. /**
  490. * @var PDF version
  491. * @since 1.5.3
  492. * @access protected
  493. */
  494. protected $PDFVersion = '1.7';
  495. /**
  496. * @var Minimum distance between header and top page margin.
  497. * @access protected
  498. */
  499. protected $header_margin;
  500. /**
  501. * @var Minimum distance between footer and bottom page margin.
  502. * @access protected
  503. */
  504. protected $footer_margin;
  505. /**
  506. * @var original left margin value
  507. * @access protected
  508. * @since 1.53.0.TC013
  509. */
  510. protected $original_lMargin;
  511. /**
  512. * @var original right margin value
  513. * @access protected
  514. * @since 1.53.0.TC013
  515. */
  516. protected $original_rMargin;
  517. /**
  518. * @var Header font.
  519. * @access protected
  520. */
  521. protected $header_font;
  522. /**
  523. * @var Footer font.
  524. * @access protected
  525. */
  526. protected $footer_font;
  527. /**
  528. * @var Language templates.
  529. * @access protected
  530. */
  531. protected $l;
  532. /**
  533. * @var Barcode to print on page footer (only if set).
  534. * @access protected
  535. */
  536. protected $barcode = false;
  537. /**
  538. * @var If true prints header
  539. * @access protected
  540. */
  541. protected $print_header = true;
  542. /**
  543. * @var If true prints footer.
  544. * @access protected
  545. */
  546. protected $print_footer = true;
  547. /**
  548. * @var Header image logo.
  549. * @access protected
  550. */
  551. protected $header_logo = '';
  552. /**
  553. * @var Header image logo width in mm.
  554. * @access protected
  555. */
  556. protected $header_logo_width = 30;
  557. /**
  558. * @var String to print as title on document header.
  559. * @access protected
  560. */
  561. protected $header_title = '';
  562. /**
  563. * @var String to print on document header.
  564. * @access protected
  565. */
  566. protected $header_string = '';
  567. /**
  568. * @var Default number of columns for html table.
  569. * @access protected
  570. */
  571. protected $default_table_columns = 4;
  572. // variables for html parser
  573. /**
  574. * @var HTML PARSER: array to store current link and rendering styles.
  575. * @access protected
  576. */
  577. protected $HREF = array();
  578. /**
  579. * @var store a list of available fonts on filesystem.
  580. * @access protected
  581. */
  582. protected $fontlist = array();
  583. /**
  584. * @var current foreground color
  585. * @access protected
  586. */
  587. protected $fgcolor;
  588. /**
  589. * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  590. * @access protected
  591. */
  592. protected $listordered = array();
  593. /**
  594. * @var HTML PARSER: array count list items on nested lists.
  595. * @access protected
  596. */
  597. protected $listcount = array();
  598. /**
  599. * @var HTML PARSER: current list nesting level.
  600. * @access protected
  601. */
  602. protected $listnum = 0;
  603. /**
  604. * @var HTML PARSER: indent amount for lists.
  605. * @access protected
  606. */
  607. protected $listindent = 0;
  608. /**
  609. * @var HTML PARSER: current list indententation level.
  610. * @access protected
  611. */
  612. protected $listindentlevel = 0;
  613. /**
  614. * @var current background color
  615. * @access protected
  616. */
  617. protected $bgcolor;
  618. /**
  619. * @var Store temporary font size in points.
  620. * @access protected
  621. */
  622. protected $tempfontsize = 10;
  623. /**
  624. * @var spacer for LI tags.
  625. * @access protected
  626. */
  627. protected $lispacer = '';
  628. /**
  629. * @var default encoding
  630. * @access protected
  631. * @since 1.53.0.TC010
  632. */
  633. protected $encoding = 'UTF-8';
  634. /**
  635. * @var PHP internal encoding
  636. * @access protected
  637. * @since 1.53.0.TC016
  638. */
  639. protected $internal_encoding;
  640. /**
  641. * @var indicates if the document language is Right-To-Left
  642. * @access protected
  643. * @since 2.0.000
  644. */
  645. protected $rtl = false;
  646. /**
  647. * @var used to force RTL or LTR string inversion
  648. * @access protected
  649. * @since 2.0.000
  650. */
  651. protected $tmprtl = false;
  652. // --- Variables used for document encryption:
  653. /**
  654. * Indicates whether document is protected
  655. * @access protected
  656. * @since 2.0.000 (2008-01-02)
  657. */
  658. protected $encrypted;
  659. /**
  660. * Array containing encryption settings
  661. * @access protected
  662. * @since 5.0.005 (2010-05-11)
  663. */
  664. protected $encryptdata = array();
  665. /**
  666. * last RC4 key encrypted (cached for optimisation)
  667. * @access protected
  668. * @since 2.0.000 (2008-01-02)
  669. */
  670. protected $last_enc_key;
  671. /**
  672. * last RC4 computed key
  673. * @access protected
  674. * @since 2.0.000 (2008-01-02)
  675. */
  676. protected $last_enc_key_c;
  677. /**
  678. * Encryption padding
  679. * @access protected
  680. */
  681. protected $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  682. /**
  683. * File ID (used on trailer)
  684. * @access protected
  685. * @since 5.0.005 (2010-05-12)
  686. */
  687. protected $file_id;
  688. // --- bookmark ---
  689. /**
  690. * Outlines for bookmark
  691. * @access protected
  692. * @since 2.1.002 (2008-02-12)
  693. */
  694. protected $outlines = array();
  695. /**
  696. * Outline root for bookmark
  697. * @access protected
  698. * @since 2.1.002 (2008-02-12)
  699. */
  700. protected $OutlineRoot;
  701. // --- javascript and form ---
  702. /**
  703. * javascript code
  704. * @access protected
  705. * @since 2.1.002 (2008-02-12)
  706. */
  707. protected $javascript = '';
  708. /**
  709. * javascript counter
  710. * @access protected
  711. * @since 2.1.002 (2008-02-12)
  712. */
  713. protected $n_js;
  714. /**
  715. * line trough state
  716. * @access protected
  717. * @since 2.8.000 (2008-03-19)
  718. */
  719. protected $linethrough;
  720. /**
  721. * Array with additional document-wide usage rights for the document.
  722. * @access protected
  723. * @since 5.8.014 (2010-08-23)
  724. */
  725. protected $ur = array();
  726. /**
  727. * Dot Per Inch Document Resolution (do not change)
  728. * @access protected
  729. * @since 3.0.000 (2008-03-27)
  730. */
  731. protected $dpi = 72;
  732. /**
  733. * Array of page numbers were a new page group was started
  734. * @access protected
  735. * @since 3.0.000 (2008-03-27)
  736. */
  737. protected $newpagegroup = array();
  738. /**
  739. * Contains the number of pages of the groups
  740. * @access protected
  741. * @since 3.0.000 (2008-03-27)
  742. */
  743. protected $pagegroups;
  744. /**
  745. * Contains the alias of the current page group
  746. * @access protected
  747. * @since 3.0.000 (2008-03-27)
  748. */
  749. protected $currpagegroup;
  750. /**
  751. * Restrict the rendering of some elements to screen or printout.
  752. * @access protected
  753. * @since 3.0.000 (2008-03-27)
  754. */
  755. protected $visibility = 'all';
  756. /**
  757. * Print visibility.
  758. * @access protected
  759. * @since 3.0.000 (2008-03-27)
  760. */
  761. protected $n_ocg_print;
  762. /**
  763. * View visibility.
  764. * @access protected
  765. * @since 3.0.000 (2008-03-27)
  766. */
  767. protected $n_ocg_view;
  768. /**
  769. * Array of transparency objects and parameters.
  770. * @access protected
  771. * @since 3.0.000 (2008-03-27)
  772. */
  773. protected $extgstates;
  774. /**
  775. * Set the default JPEG compression quality (1-100)
  776. * @access protected
  777. * @since 3.0.000 (2008-03-27)
  778. */
  779. protected $jpeg_quality;
  780. /**
  781. * Default cell height ratio.
  782. * @access protected
  783. * @since 3.0.014 (2008-05-23)
  784. */
  785. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  786. /**
  787. * PDF viewer preferences.
  788. * @access protected
  789. * @since 3.1.000 (2008-06-09)
  790. */
  791. protected $viewer_preferences;
  792. /**
  793. * A name object specifying how the document should be displayed when opened.
  794. * @access protected
  795. * @since 3.1.000 (2008-06-09)
  796. */
  797. protected $PageMode;
  798. /**
  799. * Array for storing gradient information.
  800. * @access protected
  801. * @since 3.1.000 (2008-06-09)
  802. */
  803. protected $gradients = array();
  804. /**
  805. * Array used to store positions inside the pages buffer.
  806. * keys are the page numbers
  807. * @access protected
  808. * @since 3.2.000 (2008-06-26)
  809. */
  810. protected $intmrk = array();
  811. /**
  812. * Array used to store positions inside the pages buffer.
  813. * keys are the page numbers
  814. * @access protected
  815. * @since 5.7.000 (2010-08-03)
  816. */
  817. protected $bordermrk = array();
  818. /**
  819. * Array used to store page positions to track empty pages.
  820. * keys are the page numbers
  821. * @access protected
  822. * @since 5.8.007 (2010-08-18)
  823. */
  824. protected $emptypagemrk = array();
  825. /**
  826. * Array used to store content positions inside the pages buffer.
  827. * keys are the page numbers
  828. * @access protected
  829. * @since 4.6.021 (2009-07-20)
  830. */
  831. protected $cntmrk = array();
  832. /**
  833. * Array used to store footer positions of each page.
  834. * @access protected
  835. * @since 3.2.000 (2008-07-01)
  836. */
  837. protected $footerpos = array();
  838. /**
  839. * Array used to store footer length of each page.
  840. * @access protected
  841. * @since 4.0.014 (2008-07-29)
  842. */
  843. protected $footerlen = array();
  844. /**
  845. * True if a newline is created.
  846. * @access protected
  847. * @since 3.2.000 (2008-07-01)
  848. */
  849. protected $newline = true;
  850. /**
  851. * End position of the latest inserted line
  852. * @access protected
  853. * @since 3.2.000 (2008-07-01)
  854. */
  855. protected $endlinex = 0;
  856. /**
  857. * PDF string for last line width
  858. * @access protected
  859. * @since 4.0.006 (2008-07-16)
  860. */
  861. protected $linestyleWidth = '';
  862. /**
  863. * PDF string for last line width
  864. * @access protected
  865. * @since 4.0.006 (2008-07-16)
  866. */
  867. protected $linestyleCap = '0 J';
  868. /**
  869. * PDF string for last line width
  870. * @access protected
  871. * @since 4.0.006 (2008-07-16)
  872. */
  873. protected $linestyleJoin = '0 j';
  874. /**
  875. * PDF string for last line width
  876. * @access protected
  877. * @since 4.0.006 (2008-07-16)
  878. */
  879. protected $linestyleDash = '[] 0 d';
  880. /**
  881. * True if marked-content sequence is open
  882. * @access protected
  883. * @since 4.0.013 (2008-07-28)
  884. */
  885. protected $openMarkedContent = false;
  886. /**
  887. * Count the latest inserted vertical spaces on HTML
  888. * @access protected
  889. * @since 4.0.021 (2008-08-24)
  890. */
  891. protected $htmlvspace = 0;
  892. /**
  893. * Array of Spot colors
  894. * @access protected
  895. * @since 4.0.024 (2008-09-12)
  896. */
  897. protected $spot_colors = array();
  898. /**
  899. * Symbol used for HTML unordered list items
  900. * @access protected
  901. * @since 4.0.028 (2008-09-26)
  902. */
  903. protected $lisymbol = '';
  904. /**
  905. * String used to mark the beginning and end of EPS image blocks
  906. * @access protected
  907. * @since 4.1.000 (2008-10-18)
  908. */
  909. protected $epsmarker = 'x#!#EPS#!#x';
  910. /**
  911. * Array of transformation matrix
  912. * @access protected
  913. * @since 4.2.000 (2008-10-29)
  914. */
  915. protected $transfmatrix = array();
  916. /**
  917. * Current key for transformation matrix
  918. * @access protected
  919. * @since 4.8.005 (2009-09-17)
  920. */
  921. protected $transfmatrix_key = 0;
  922. /**
  923. * Booklet mode for double-sided pages
  924. * @access protected
  925. * @since 4.2.000 (2008-10-29)
  926. */
  927. protected $booklet = false;
  928. /**
  929. * Epsilon value used for float calculations
  930. * @access protected
  931. * @since 4.2.000 (2008-10-29)
  932. */
  933. protected $feps = 0.005;
  934. /**
  935. * Array used for custom vertical spaces for HTML tags
  936. * @access protected
  937. * @since 4.2.001 (2008-10-30)
  938. */
  939. protected $tagvspaces = array();
  940. /**
  941. * @var HTML PARSER: custom indent amount for lists.
  942. * Negative value means disabled.
  943. * @access protected
  944. * @since 4.2.007 (2008-11-12)
  945. */
  946. protected $customlistindent = - 1;
  947. /**
  948. * @var if true keeps the border open for the cell sides that cross the page.
  949. * @access protected
  950. * @since 4.2.010 (2008-11-14)
  951. */
  952. protected $opencell = true;
  953. /**
  954. * @var array of files to embedd
  955. * @access protected
  956. * @since 4.4.000 (2008-12-07)
  957. */
  958. protected $embeddedfiles = array();
  959. /**
  960. * @var boolean true when inside html pre tag
  961. * @access protected
  962. * @since 4.4.001 (2008-12-08)
  963. */
  964. protected $premode = false;
  965. /**
  966. * Array used to store positions of graphics transformation blocks inside the page buffer.
  967. * keys are the page numbers
  968. * @access protected
  969. * @since 4.4.002 (2008-12-09)
  970. */
  971. protected $transfmrk = array();
  972. /**
  973. * Default color for html links
  974. * @access protected
  975. * @since 4.4.003 (2008-12-09)
  976. */
  977. protected $htmlLinkColorArray = array(0, 0, 255);
  978. /**
  979. * Default font style to add to html links
  980. * @access protected
  981. * @since 4.4.003 (2008-12-09)
  982. */
  983. protected $htmlLinkFontStyle = 'U';
  984. /**
  985. * Counts the number of pages.
  986. * @access protected
  987. * @since 4.5.000 (2008-12-31)
  988. */
  989. protected $numpages = 0;
  990. /**
  991. * Array containing page lengths in bytes.
  992. * @access protected
  993. * @since 4.5.000 (2008-12-31)
  994. */
  995. protected $pagelen = array();
  996. /**
  997. * Counts the number of pages.
  998. * @access protected
  999. * @since 4.5.000 (2008-12-31)
  1000. */
  1001. protected $numimages = 0;
  1002. /**
  1003. * Store the image keys.
  1004. * @access protected
  1005. * @since 4.5.000 (2008-12-31)
  1006. */
  1007. protected $imagekeys = array();
  1008. /**
  1009. * Length of the buffer in bytes.
  1010. * @access protected
  1011. * @since 4.5.000 (2008-12-31)
  1012. */
  1013. protected $bufferlen = 0;
  1014. /**
  1015. * If true enables disk caching.
  1016. * @access protected
  1017. * @since 4.5.000 (2008-12-31)
  1018. */
  1019. protected $diskcache = false;
  1020. /**
  1021. * Counts the number of fonts.
  1022. * @access protected
  1023. * @since 4.5.000 (2009-01-02)
  1024. */
  1025. protected $numfonts = 0;
  1026. /**
  1027. * Store the font keys.
  1028. * @access protected
  1029. * @since 4.5.000 (2009-01-02)
  1030. */
  1031. protected $fontkeys = array();
  1032. /**
  1033. * Store the font object IDs.
  1034. * @access protected
  1035. * @since 4.8.001 (2009-09-09)
  1036. */
  1037. protected $font_obj_ids = array();
  1038. /**
  1039. * Store the fage status (true when opened, false when closed).
  1040. * @access protected
  1041. * @since 4.5.000 (2009-01-02)
  1042. */
  1043. protected $pageopen = array();
  1044. /**
  1045. * Default monospaced font
  1046. * @access protected
  1047. * @since 4.5.025 (2009-03-10)
  1048. */
  1049. protected $default_monospaced_font = 'courier';
  1050. /**
  1051. * Used to store a cloned copy of the current class object
  1052. * @access protected
  1053. * @since 4.5.029 (2009-03-19)
  1054. */
  1055. protected $objcopy;
  1056. /**
  1057. * Array used to store the lengths of cache files
  1058. * @access protected
  1059. * @since 4.5.029 (2009-03-19)
  1060. */
  1061. protected $cache_file_length = array();
  1062. /**
  1063. * Table header content to be repeated on each new page
  1064. * @access protected
  1065. * @since 4.5.030 (2009-03-20)
  1066. */
  1067. protected $thead = '';
  1068. /**
  1069. * Margins used for table header.
  1070. * @access protected
  1071. * @since 4.5.030 (2009-03-20)
  1072. */
  1073. protected $theadMargins = array();
  1074. /**
  1075. * Cache array for UTF8StringToArray() method.
  1076. * @access protected
  1077. * @since 4.5.037 (2009-04-07)
  1078. */
  1079. protected $cache_UTF8StringToArray = array();
  1080. /**
  1081. * Maximum size of cache array used for UTF8StringToArray() method.
  1082. * @access protected
  1083. * @since 4.5.037 (2009-04-07)
  1084. */
  1085. protected $cache_maxsize_UTF8StringToArray = 8;
  1086. /**
  1087. * Current size of cache array used for UTF8StringToArray() method.
  1088. * @access protected
  1089. * @since 4.5.037 (2009-04-07)
  1090. */
  1091. protected $cache_size_UTF8StringToArray = 0;
  1092. /**
  1093. * If true enables document signing
  1094. * @access protected
  1095. * @since 4.6.005 (2009-04-24)
  1096. */
  1097. protected $sign = false;
  1098. /**
  1099. * Signature data
  1100. * @access protected
  1101. * @since 4.6.005 (2009-04-24)
  1102. */
  1103. protected $signature_data = array();
  1104. /**
  1105. * Signature max length
  1106. * @access protected
  1107. * @since 4.6.005 (2009-04-24)
  1108. */
  1109. protected $signature_max_length = 11742;
  1110. /**
  1111. * data for signature appearance
  1112. * @access protected
  1113. * @since 5.3.011 (2010-06-16)
  1114. */
  1115. protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1116. /**
  1117. * Regular expression used to find blank characters used for word-wrapping.
  1118. * @access protected
  1119. * @since 4.6.006 (2009-04-28)
  1120. */
  1121. protected $re_spaces = '/[^\S\xa0]/';
  1122. /**
  1123. * Array of parts $re_spaces
  1124. * @access protected
  1125. * @since 5.5.011 (2010-07-09)
  1126. */
  1127. protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
  1128. /**
  1129. * Signature object ID
  1130. * @access protected
  1131. * @since 4.6.022 (2009-06-23)
  1132. */
  1133. protected $sig_obj_id = 0;
  1134. /**
  1135. * ByteRange placemark used during signature process.
  1136. * @access protected
  1137. * @since 4.6.028 (2009-08-25)
  1138. */
  1139. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1140. /**
  1141. * Placemark used during signature process.
  1142. * @access protected
  1143. * @since 4.6.028 (2009-08-25)
  1144. */
  1145. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1146. /**
  1147. * ID of page objects
  1148. * @access protected
  1149. * @since 4.7.000 (2009-08-29)
  1150. */
  1151. protected $page_obj_id = array();
  1152. /**
  1153. * List of form annotations IDs
  1154. * @access protected
  1155. * @since 4.8.000 (2009-09-07)
  1156. */
  1157. protected $form_obj_id = array();
  1158. /**
  1159. * 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.
  1160. * @access protected
  1161. * @since 4.8.000 (2009-09-07)
  1162. */
  1163. protected $default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255,
  1164. 255), 'strokeColor' => array(128, 128, 128));
  1165. /**
  1166. * Javascript objects array
  1167. * @access protected
  1168. * @since 4.8.000 (2009-09-07)
  1169. */
  1170. protected $js_objects = array();
  1171. /**
  1172. * Current form action (used during XHTML rendering)
  1173. * @access protected
  1174. * @since 4.8.000 (2009-09-07)
  1175. */
  1176. protected $form_action = '';
  1177. /**
  1178. * Current form encryption type (used during XHTML rendering)
  1179. * @access protected
  1180. * @since 4.8.000 (2009-09-07)
  1181. */
  1182. protected $form_enctype = 'application/x-www-form-urlencoded';
  1183. /**
  1184. * Current method to submit forms.
  1185. * @access protected
  1186. * @since 4.8.000 (2009-09-07)
  1187. */
  1188. protected $form_mode = 'post';
  1189. /**
  1190. * List of fonts used on form fields (fontname => fontkey).
  1191. * @access protected
  1192. * @since 4.8.001 (2009-09-09)
  1193. */
  1194. protected $annotation_fonts = array();
  1195. /**
  1196. * List of radio buttons parent objects.
  1197. * @access protected
  1198. * @since 4.8.001 (2009-09-09)
  1199. */
  1200. protected $radiobutton_groups = array();
  1201. /**
  1202. * List of radio group objects IDs
  1203. * @access protected
  1204. * @since 4.8.001 (2009-09-09)
  1205. */
  1206. protected $radio_groups = array();
  1207. /**
  1208. * Text indentation value (used for text-indent CSS attribute)
  1209. * @access protected
  1210. * @since 4.8.006 (2009-09-23)
  1211. */
  1212. protected $textindent = 0;
  1213. /**
  1214. * Store page number when startTransaction() is called.
  1215. * @access protected
  1216. * @since 4.8.006 (2009-09-23)
  1217. */
  1218. protected $start_transaction_page = 0;
  1219. /**
  1220. * Store Y position when startTransaction() is called.
  1221. * @access protected
  1222. * @since 4.9.001 (2010-03-28)
  1223. */
  1224. protected $start_transaction_y = 0;
  1225. /**
  1226. * True when we are printing the thead section on a new page
  1227. * @access protected
  1228. * @since 4.8.027 (2010-01-25)
  1229. */
  1230. protected $inthead = false;
  1231. /**
  1232. * Array of column measures (width, space, starting Y position)
  1233. * @access protected
  1234. * @since 4.9.001 (2010-03-28)
  1235. */
  1236. protected $columns = array();
  1237. /**
  1238. * Number of colums
  1239. * @access protected
  1240. * @since 4.9.001 (2010-03-28)
  1241. */
  1242. protected $num_columns = 1;
  1243. /**
  1244. * Current column number
  1245. * @access protected
  1246. * @since 4.9.001 (2010-03-28)
  1247. */
  1248. protected $current_column = 0;
  1249. /**
  1250. * Starting page for columns
  1251. * @access protected
  1252. * @since 4.9.001 (2010-03-28)
  1253. */
  1254. protected $column_start_page = 0;
  1255. /**
  1256. * Maximum page and column selected
  1257. * @access protected
  1258. * @since 5.8.000 (2010-08-11)
  1259. */
  1260. protected $maxselcol = array('page' => 0, 'column' => 0);
  1261. /**
  1262. * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding
  1263. * @access protected
  1264. * @since 5.8.000 (2010-08-11)
  1265. */
  1266. protected $colxshift = array('x' => 0, 's' => 0, 'p' => 0);
  1267. /**
  1268. * 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.
  1269. * @access protected
  1270. * @since 4.9.008 (2010-04-03)
  1271. */
  1272. protected $textrendermode = 0;
  1273. /**
  1274. * Text stroke width in doc units
  1275. * @access protected
  1276. * @since 4.9.008 (2010-04-03)
  1277. */
  1278. protected $textstrokewidth = 0;
  1279. /**
  1280. * @var current stroke color
  1281. * @access protected
  1282. * @since 4.9.008 (2010-04-03)
  1283. */
  1284. protected $strokecolor;
  1285. /**
  1286. * @var default unit of measure for document
  1287. * @access protected
  1288. * @since 5.0.000 (2010-04-22)
  1289. */
  1290. protected $pdfunit = 'mm';
  1291. /**
  1292. * @var true when we are on TOC (Table Of Content) page
  1293. * @access protected
  1294. */
  1295. protected $tocpage = false;
  1296. /**
  1297. * @var If true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
  1298. * @access protected
  1299. * @since 5.0.000 (2010-04-26)
  1300. */
  1301. protected $rasterize_vector_images = false;
  1302. /**
  1303. * @var If true enables font subsetting by default
  1304. * @access protected
  1305. * @since 5.3.002 (2010-06-07)
  1306. */
  1307. protected $font_subsetting = true;
  1308. /**
  1309. * @var Array of default graphic settings
  1310. * @access protected
  1311. * @since 5.5.008 (2010-07-02)
  1312. */
  1313. protected $default_graphic_vars = array();
  1314. /**
  1315. * @var Array of XObjects
  1316. * @access protected
  1317. * @since 5.8.014 (2010-08-23)
  1318. */
  1319. protected $xobjects = array();
  1320. /**
  1321. * @var boolean true when we are inside an XObject
  1322. * @access protected
  1323. * @since 5.8.017 (2010-08-24)
  1324. */
  1325. protected $inxobj = false;
  1326. /**
  1327. * @var current XObject ID
  1328. * @access protected
  1329. * @since 5.8.017 (2010-08-24)
  1330. */
  1331. protected $xobjid = '';
  1332. /**
  1333. * @var percentage of character stretching
  1334. * @access protected
  1335. * @since 5.9.000 (2010-09-29)
  1336. */
  1337. protected $font_stretching = 100;
  1338. /**
  1339. * @var increases or decreases the space between characters in a text by the specified amount (tracking/kerning).
  1340. * @access protected
  1341. * @since 5.9.000 (2010-09-29)
  1342. */
  1343. protected $font_spacing = 0;
  1344. /**
  1345. * @var array of no-write regions
  1346. * ('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)
  1347. * @access protected
  1348. * @since 5.9.003 (2010-10-14)
  1349. */
  1350. protected $page_regions = array();
  1351. /**
  1352. * @var array containing HTML color names and values
  1353. * @access protected
  1354. * @since 5.9.004 (2010-10-18)
  1355. */
  1356. protected $webcolor = array();
  1357. /**
  1358. * @var directory used for the last SVG image
  1359. * @access protected
  1360. * @since 5.0.000 (2010-05-05)
  1361. */
  1362. protected $svgdir = '';
  1363. /**
  1364. * @var Deafult unit of measure for SVG
  1365. * @access protected
  1366. * @since 5.0.000 (2010-05-02)
  1367. */
  1368. protected $svgunit = 'px';
  1369. /**
  1370. * @var array of SVG gradients
  1371. * @access protected
  1372. * @since 5.0.000 (2010-05-02)
  1373. */
  1374. protected $svggradients = array();
  1375. /**
  1376. * @var ID of last SVG gradient
  1377. * @access protected
  1378. * @since 5.0.000 (2010-05-02)
  1379. */
  1380. protected $svggradientid = 0;
  1381. /**
  1382. * @var true when in SVG defs group
  1383. * @access protected
  1384. * @since 5.0.000 (2010-05-02)
  1385. */
  1386. protected $svgdefsmode = false;
  1387. /**
  1388. * @var array of SVG defs
  1389. * @access protected
  1390. * @since 5.0.000 (2010-05-02)
  1391. */
  1392. protected $svgdefs = array();
  1393. /**
  1394. * @var true when in SVG clipPath tag
  1395. * @access protected
  1396. * @since 5.0.000 (2010-04-26)
  1397. */
  1398. protected $svgclipmode = false;
  1399. /**
  1400. * @var array of SVG clipPath commands
  1401. * @access protected
  1402. * @since 5.0.000 (2010-05-02)
  1403. */
  1404. protected $svgclippaths = array();
  1405. /**
  1406. * @var array of SVG clipPath tranformation matrix
  1407. * @access protected
  1408. * @since 5.8.022 (2010-08-31)
  1409. */
  1410. protected $svgcliptm = array();
  1411. /**
  1412. * @var ID of last SVG clipPath
  1413. * @access protected
  1414. * @since 5.0.000 (2010-05-02)
  1415. */
  1416. protected $svgclipid = 0;
  1417. /**
  1418. * @var svg text
  1419. * @access protected
  1420. * @since 5.0.000 (2010-05-02)
  1421. */
  1422. protected $svgtext = '';
  1423. /**
  1424. * @var svg text properties
  1425. * @access protected
  1426. * @since 5.8.013 (2010-08-23)
  1427. */
  1428. protected $svgtextmode = array();
  1429. /**
  1430. * @var array of hinheritable SVG properties
  1431. * @access protected
  1432. * @since 5.0.000 (2010-05-02)
  1433. */
  1434. protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters',
  1435. 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font',
  1436. 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight',
  1437. 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing',
  1438. 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke',
  1439. 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit',
  1440. 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing',
  1441. 'writing-mode');
  1442. /**
  1443. * @var array of SVG properties
  1444. * @access protected
  1445. * @since 5.0.000 (2010-05-02)
  1446. */
  1447. protected $svgstyles = array(
  1448. array('alignment-baseline' => 'auto', 'baseline-shift' => 'baseline', 'clip' => 'auto',
  1449. 'clip-path' => 'none', 'clip-rule' => 'nonzero', 'color' => 'black', 'color-interpolation' => 'sRGB',
  1450. 'color-interpolation-filters' => 'linearRGB', 'color-profile' => 'auto', 'color-rendering' => 'auto',
  1451. 'cursor' => 'auto', 'direction' => 'ltr', 'display' => 'inline', 'dominant-baseline' => 'auto',
  1452. 'enable-background' => 'accumulate', 'fill' => 'black', 'fill-opacity' => 1,
  1453. 'fill-rule' => 'nonzero', 'filter' => 'none', 'flood-color' => 'black', 'flood-opacity' => 1,
  1454. 'font' => '', 'font-family' => 'helvetica', 'font-size' => 'medium', 'font-size-adjust' => 'none',
  1455. 'font-stretch' => 'normal', 'font-style' => 'normal', 'font-variant' => 'normal',
  1456. 'font-weight' => 'normal', 'glyph-orientation-horizontal' => '0deg',
  1457. 'glyph-orientation-vertical' => 'auto', 'image-rendering' => 'auto', 'kerning' => 'auto',
  1458. 'letter-spacing' => 'normal', 'lighting-color' => 'white', 'marker' => '', 'marker-end' => 'none',
  1459. 'marker-mid' => 'none', 'marker-start' => 'none', 'mask' => 'none', 'opacity' => 1,
  1460. 'overflow' => 'auto', 'pointer-events' => 'visiblePainted', 'shape-rendering' => 'auto',
  1461. 'stop-color' => 'black', 'stop-opacity' => 1, 'stroke' => 'none', 'stroke-dasharray' => 'none',
  1462. 'stroke-dashoffset' => 0, 'stroke-linecap' => 'butt', 'stroke-linejoin' => 'miter',
  1463. 'stroke-miterlimit' => 4, 'stroke-opacity' => 1, 'stroke-width' => 1, 'text-anchor' => 'start',
  1464. 'text-decoration' => 'none', 'text-rendering' => 'auto', 'unicode-bidi' => 'normal',
  1465. 'visibility' => 'visible', 'word-spacing' => 'normal', 'writing-mode' => 'lr-tb',
  1466. 'text-color' => 'black', 'transfmatrix' => array(1, 0, 0, 1, 0, 0)));
  1467. //------------------------------------------------------------
  1468. // METHODS
  1469. //------------------------------------------------------------
  1470. /**
  1471. * This is the class constructor.
  1472. * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
  1473. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  1474. * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1475. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  1476. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1477. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1478. * @param String $encoding charset encoding; default is UTF-8
  1479. * @access public
  1480. * @see getPageSizeFromFormat(), setPageFormat()
  1481. */
  1482. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false)
  1483. {
  1484. /* Set internal character encoding to ASCII */
  1485. if (function_exists('mb_internal_encoding') and mb_internal_encoding())
  1486. {
  1487. $this->internal_encoding = mb_internal_encoding();
  1488. mb_internal_encoding('ASCII');
  1489. }
  1490. require (dirname(__FILE__) . '/htmlcolors.php');
  1491. $this->webcolor = $webcolor;
  1492. require_once (dirname(__FILE__) . '/unicode_data.php');
  1493. $this->unicode = new TCPDF_UNICODE_DATA();
  1494. $this->font_obj_ids = array();
  1495. $this->page_obj_id = array();
  1496. $this->form_obj_id = array();
  1497. // set disk caching
  1498. $this->diskcache = $diskcache ? true : false;
  1499. // set language direction
  1500. $this->rtl = false;
  1501. $this->tmprtl = false;
  1502. // some checks
  1503. $this->_dochecks();
  1504. // initialization of properties
  1505. $this->isunicode = $unicode;
  1506. $this->page = 0;
  1507. $this->transfmrk[0] = array();
  1508. $this->pagedim = array();
  1509. $this->n = 2;
  1510. $this->buffer = '';
  1511. $this->pages = array();
  1512. $this->state = 0;
  1513. $this->fonts = array();
  1514. $this->FontFiles = array();
  1515. $this->diffs = array();
  1516. $this->images = array();
  1517. $this->links = array();
  1518. $this->gradients = array();
  1519. $this->InFooter = false;
  1520. $this->lasth = 0;
  1521. $this->FontFamily = 'helvetica';
  1522. $this->FontStyle = '';
  1523. $this->FontSizePt = 12;
  1524. $this->underline = false;
  1525. $this->overline = false;
  1526. $this->linethrough = false;
  1527. $this->DrawColor = '0 G';
  1528. $this->FillColor = '0 g';
  1529. $this->TextColor = '0 g';
  1530. $this->ColorFlag = false;
  1531. // encryption values
  1532. $this->encrypted = false;
  1533. $this->last_enc_key = '';
  1534. // standard Unicode fonts
  1535. $this->CoreFonts = array('courier' => 'Courier', 'courierB' => 'Courier-Bold',
  1536. 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', 'helvetica' => 'Helvetica',
  1537. 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique',
  1538. 'helveticaBI' => 'Helvetica-BoldOblique', 'times' => 'Times-Roman', 'timesB' => 'Times-Bold',
  1539. 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', 'symbol' => 'Symbol',
  1540. 'zapfdingbats' => 'ZapfDingbats');
  1541. // set scale factor
  1542. $this->setPageUnit($unit);
  1543. // set page format and orientation
  1544. $this->setPageFormat($format, $orientation);
  1545. // page margins (1 cm)
  1546. $margin = 28.35 / $this->k;
  1547. $this->SetMargins($margin, $margin);
  1548. // internal cell padding
  1549. $cpadding = $margin / 10;
  1550. $this->setCellPaddings($cpadding, 0, $cpadding, 0);
  1551. // cell margins
  1552. $this->setCellMargins(0, 0, 0, 0);
  1553. // line width (0.2 mm)
  1554. $this->LineWidth = 0.57 / $this->k;
  1555. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1556. $this->linestyleCap = '0 J';
  1557. $this->linestyleJoin = '0 j';
  1558. $this->linestyleDash = '[] 0 d';
  1559. // automatic page break
  1560. $this->SetAutoPageBreak(true, (2 * $margin));
  1561. // full width display mode
  1562. $this->SetDisplayMode('fullwidth');
  1563. // compression
  1564. $this->SetCompression(true);
  1565. // set default PDF version number
  1566. $this->PDFVersion = '1.7';
  1567. $this->encoding = $encoding;
  1568. $this->HREF = array();
  1569. $this->getFontsList();
  1570. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1571. $this->strokecolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1572. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1573. $this->extgstates = array();
  1574. // user's rights
  1575. $this->sign = false;
  1576. $this->ur['enabled'] = false;
  1577. $this->ur['document'] = '/FullSave';
  1578. $this->ur['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
  1579. $this->ur['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1580. $this->ur['signature'] = '/Modify';
  1581. $this->ur['ef'] = '/Create/Delete/Modify/Import';
  1582. $this->ur['formex'] = '';
  1583. $this->signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
  1584. // set default JPEG quality
  1585. $this->jpeg_quality = 75;
  1586. // initialize some settings
  1587. $this->utf8Bidi(array(''), '');
  1588. // set default font
  1589. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1590. // check if PCRE Unicode support is enabled
  1591. if ($this->isunicode and (@preg_match('/\pL/u', 'a') == 1))
  1592. {
  1593. // PCRE unicode support is turned ON
  1594. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1595. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1596. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1597. //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
  1598. $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
  1599. }
  1600. else
  1601. {
  1602. // PCRE unicode support is turned OFF
  1603. $this->setSpacesRE('/[^\S\xa0]/');
  1604. }
  1605. $this->default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255,
  1606. 255), 'strokeColor' => array(128, 128, 128));
  1607. // set file ID for trailer
  1608. $this->file_id = md5($this->getRandomSeed('TCPDF' . $orientation . $unit . $format . $encoding));
  1609. // get default graphic vars
  1610. $this->default_graphic_vars = $this->getGraphicVars();
  1611. }
  1612. /**
  1613. * Default destructor.
  1614. * @access public
  1615. * @since 1.53.0.TC016
  1616. */
  1617. public function __destruct()
  1618. {
  1619. // restore internal encoding
  1620. if (isset($this->internal_encoding) and ! empty($this->internal_encoding))
  1621. {
  1622. mb_internal_encoding($this->internal_encoding);
  1623. }
  1624. // unset all class variables
  1625. $this->_destroy(true);
  1626. }
  1627. /**
  1628. * Set the units of measure for the document.
  1629. * @param string $unit User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
  1630. * @access public
  1631. * @since 3.0.015 (2008-06-06)
  1632. */
  1633. public function setPageUnit($unit)
  1634. {
  1635. $unit = strtolower($unit);
  1636. //Set scale factor
  1637. switch ($unit)
  1638. {
  1639. // points
  1640. case 'px' :
  1641. case 'pt' :
  1642. {
  1643. $this->k = 1;
  1644. break;
  1645. }
  1646. // millimeters
  1647. case 'mm' :
  1648. {
  1649. $this->k = $this->dpi / 25.4;
  1650. break;
  1651. }
  1652. // centimeters
  1653. case 'cm' :
  1654. {
  1655. $this->k = $this->dpi / 2.54;
  1656. break;
  1657. }
  1658. // inches
  1659. case 'in' :
  1660. {
  1661. $this->k = $this->dpi;
  1662. break;
  1663. }
  1664. // unsupported unit
  1665. default :
  1666. {
  1667. $this->Error('Incorrect unit: ' . $unit);
  1668. break;
  1669. }
  1670. }
  1671. $this->pdfunit = $unit;
  1672. if (isset($this->CurOrientation))
  1673. {
  1674. $this->setPageOrientation($this->CurOrientation);
  1675. }
  1676. }
  1677. /**
  1678. * Get page dimensions from format name.
  1679. * @param mixed $format The format name. It can be: <ul>
  1680. * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
  1681. * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
  1682. * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
  1683. * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
  1684. * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
  1685. * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
  1686. * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
  1687. * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
  1688. * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
  1689. * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
  1690. * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
  1691. * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
  1692. * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
  1693. * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
  1694. * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
  1695. * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
  1696. * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
  1697. * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
  1698. * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
  1699. * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
  1700. * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
  1701. * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
  1702. * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
  1703. * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
  1704. * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
  1705. * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
  1706. * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
  1707. * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
  1708. * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
  1709. * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
  1710. * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
  1711. * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
  1712. * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
  1713. * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
  1714. * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
  1715. * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
  1716. * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
  1717. * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
  1718. * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
  1719. * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
  1720. * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
  1721. * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
  1722. * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
  1723. * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
  1724. * <li><b>SIS 014711 E Series</b></li>
  1725. * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
  1726. * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
  1727. * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
  1728. * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
  1729. * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
  1730. * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
  1731. * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
  1732. * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
  1733. * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
  1734. * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
  1735. * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
  1736. * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
  1737. * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
  1738. * <li><b>SIS 014711 G Series</b></li>
  1739. * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
  1740. * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
  1741. * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
  1742. * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
  1743. * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
  1744. * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
  1745. * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
  1746. * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
  1747. * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
  1748. * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
  1749. * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
  1750. * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
  1751. * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
  1752. * <li><b>ISO Press</b></li>
  1753. * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
  1754. * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
  1755. * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
  1756. * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
  1757. * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
  1758. * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
  1759. * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
  1760. * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
  1761. * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
  1762. * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
  1763. * <li><b>German DIN 476</b></li>
  1764. * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
  1765. * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
  1766. * <li><b>Variations on the ISO Standard</b></li>
  1767. * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
  1768. * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
  1769. * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
  1770. * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
  1771. * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
  1772. * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
  1773. * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
  1774. * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
  1775. * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
  1776. * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
  1777. * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
  1778. * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
  1779. * <li><b>ANSI Series</b></li>
  1780. * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
  1781. * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
  1782. * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
  1783. * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
  1784. * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
  1785. * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
  1786. * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
  1787. * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
  1788. * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
  1789. * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
  1790. * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
  1791. * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
  1792. * <li><b>Other North American Paper Sizes</b></li>
  1793. * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
  1794. * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
  1795. * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
  1796. * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
  1797. * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
  1798. * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
  1799. * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
  1800. * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
  1801. * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
  1802. * <li><b>Canadian standard CAN 2-9.60M</b></li>
  1803. * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
  1804. * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
  1805. * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
  1806. * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
  1807. * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
  1808. * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
  1809. * <li><b>North American Architectural Sizes</b></li>
  1810. * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
  1811. * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
  1812. * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
  1813. * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
  1814. * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
  1815. * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
  1816. * <li><b>Announcement Envelopes</b></li>
  1817. * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
  1818. * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
  1819. * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
  1820. * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
  1821. * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
  1822. * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
  1823. * <li><b>Commercial Envelopes</b></li>
  1824. * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
  1825. * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
  1826. * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
  1827. * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
  1828. * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
  1829. * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
  1830. * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
  1831. * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
  1832. * <li><b>Catalogue Envelopes</b></li>
  1833. * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
  1834. * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
  1835. * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
  1836. * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
  1837. * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
  1838. * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
  1839. * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
  1840. * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
  1841. * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
  1842. * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
  1843. * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
  1844. * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
  1845. * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
  1846. * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
  1847. * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
  1848. * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
  1849. * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
  1850. * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
  1851. * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
  1852. * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
  1853. * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
  1854. * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
  1855. * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
  1856. * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
  1857. * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
  1858. * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
  1859. * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
  1860. * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
  1861. * <li><b>PA Series</b></li>
  1862. * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
  1863. * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
  1864. * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
  1865. * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
  1866. * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
  1867. * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
  1868. * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
  1869. * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
  1870. * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
  1871. * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
  1872. * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
  1873. * <li><b>Standard Photographic Print Sizes</b></li>
  1874. * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
  1875. * <li>E (82x120 mm ; 3.25x4.72 in)</li>
  1876. * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
  1877. * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
  1878. * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
  1879. * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
  1880. * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
  1881. * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
  1882. * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
  1883. * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
  1884. * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
  1885. * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
  1886. * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
  1887. * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
  1888. * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
  1889. * <li><b>Common Newspaper Sizes</b></li>
  1890. * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
  1891. * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
  1892. * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
  1893. * <li><b>Business Cards</b></li>
  1894. * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
  1895. * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
  1896. * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
  1897. * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
  1898. * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
  1899. * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
  1900. * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
  1901. * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
  1902. * <li><b>Billboards</b></li>
  1903. * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
  1904. * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
  1905. * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
  1906. * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
  1907. * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
  1908. * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
  1909. * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
  1910. * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
  1911. * <li><b>Old Imperial English (some are still used in USA)</b></li>
  1912. * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
  1913. * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
  1914. * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
  1915. * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
  1916. * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
  1917. * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
  1918. * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
  1919. * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
  1920. * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
  1921. * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
  1922. * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
  1923. * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
  1924. * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
  1925. * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
  1926. * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
  1927. * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
  1928. * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
  1929. * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
  1930. * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
  1931. * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
  1932. * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
  1933. * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
  1934. * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
  1935. * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
  1936. * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
  1937. * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
  1938. * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
  1939. * <li><b>Old Imperial Belgian</b></li>
  1940. * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
  1941. * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
  1942. * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
  1943. * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
  1944. * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
  1945. * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
  1946. * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
  1947. * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  1948. * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
  1949. * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
  1950. * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
  1951. * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
  1952. * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
  1953. * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
  1954. * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
  1955. * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
  1956. * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
  1957. * <li><b>Old Imperial French</b></li>
  1958. * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
  1959. * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
  1960. * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
  1961. * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
  1962. * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
  1963. * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
  1964. * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
  1965. * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
  1966. * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
  1967. * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
  1968. * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
  1969. * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
  1970. * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
  1971. * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
  1972. * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
  1973. * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
  1974. * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
  1975. * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
  1976. * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
  1977. * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
  1978. * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
  1979. * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
  1980. * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
  1981. * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
  1982. * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
  1983. * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
  1984. * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
  1985. * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
  1986. * </ul>
  1987. * @return array containing page width and height in points
  1988. * @access public
  1989. * @since 5.0.010 (2010-05-17)
  1990. */
  1991. public function getPageSizeFromFormat($format)
  1992. {
  1993. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
  1994. switch (strtoupper($format))
  1995. {
  1996. // ISO 216 A Series + 2 SIS 014711 extensions
  1997. case 'A0' :
  1998. {
  1999. $pf = array(2383.937, 3370.394);
  2000. break;
  2001. }
  2002. case 'A1' :
  2003. {
  2004. $pf = array(1683.780, 2383.937);
  2005. break;
  2006. }
  2007. case 'A2' :
  2008. {
  2009. $pf = array(1190.551, 1683.780);
  2010. break;
  2011. }
  2012. case 'A3' :
  2013. {
  2014. $pf = array(841.890, 1190.551);
  2015. break;
  2016. }
  2017. case 'A4' :
  2018. {
  2019. $pf = array(595.276, 841.890);
  2020. break;
  2021. }
  2022. case 'A5' :
  2023. {
  2024. $pf = array(419.528, 595.276);
  2025. break;
  2026. }
  2027. case 'A6' :
  2028. {
  2029. $pf = array(297.638, 419.528);
  2030. break;
  2031. }
  2032. case 'A7' :
  2033. {
  2034. $pf = array(209.764, 297.638);
  2035. break;
  2036. }
  2037. case 'A8' :
  2038. {
  2039. $pf = array(147.402, 209.764);
  2040. break;
  2041. }
  2042. case 'A9' :
  2043. {
  2044. $pf = array(104.882, 147.402);
  2045. break;
  2046. }
  2047. case 'A10' :
  2048. {
  2049. $pf = array(73.701, 104.882);
  2050. break;
  2051. }
  2052. case 'A11' :
  2053. {
  2054. $pf = array(51.024, 73.701);
  2055. break;
  2056. }
  2057. case 'A12' :
  2058. {
  2059. $pf = array(36.850, 51.024);
  2060. break;
  2061. }
  2062. // ISO 216 B Series + 2 SIS 014711 extensions
  2063. case 'B0' :
  2064. {
  2065. $pf = array(2834.646, 4008.189);
  2066. break;
  2067. }
  2068. case 'B1' :
  2069. {
  2070. $pf = array(2004.094, 2834.646);
  2071. break;
  2072. }
  2073. case 'B2' :
  2074. {
  2075. $pf = array(1417.323, 2004.094);
  2076. break;
  2077. }
  2078. case 'B3' :
  2079. {
  2080. $pf = array(1000.630, 1417.323);
  2081. break;
  2082. }
  2083. case 'B4' :
  2084. {
  2085. $pf = array(708.661, 1000.630);
  2086. break;
  2087. }
  2088. case 'B5' :
  2089. {
  2090. $pf = array(498.898, 708.661);
  2091. break;
  2092. }
  2093. case 'B6' :
  2094. {
  2095. $pf = array(354.331, 498.898);
  2096. break;
  2097. }
  2098. case 'B7' :
  2099. {
  2100. $pf = array(249.449, 354.331);
  2101. break;
  2102. }
  2103. case 'B8' :
  2104. {
  2105. $pf = array(175.748, 249.449);
  2106. break;
  2107. }
  2108. case 'B9' :
  2109. {
  2110. $pf = array(124.724, 175.748);
  2111. break;
  2112. }
  2113. case 'B10' :
  2114. {
  2115. $pf = array(87.874, 124.724);
  2116. break;
  2117. }
  2118. case 'B11' :
  2119. {
  2120. $pf = array(62.362, 87.874);
  2121. break;
  2122. }
  2123. case 'B12' :
  2124. {
  2125. $pf = array(42.520, 62.362);
  2126. break;
  2127. }
  2128. // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
  2129. case 'C0' :
  2130. {
  2131. $pf = array(2599.370, 3676.535);
  2132. break;
  2133. }
  2134. case 'C1' :
  2135. {
  2136. $pf = array(1836.850, 2599.370);
  2137. break;
  2138. }
  2139. case 'C2' :
  2140. {
  2141. $pf = array(1298.268, 1836.850);
  2142. break;
  2143. }
  2144. case 'C3' :
  2145. {
  2146. $pf = array(918.425, 1298.268);
  2147. break;
  2148. }
  2149. case 'C4' :
  2150. {
  2151. $pf = array(649.134, 918.425);
  2152. break;
  2153. }
  2154. case 'C5' :
  2155. {
  2156. $pf = array(459.213, 649.134);
  2157. break;
  2158. }
  2159. case 'C6' :
  2160. {
  2161. $pf = array(323.150, 459.213);
  2162. break;
  2163. }
  2164. case 'C7' :
  2165. {
  2166. $pf = array(229.606, 323.150);
  2167. break;
  2168. }
  2169. case 'C8' :
  2170. {
  2171. $pf = array(161.575, 229.606);
  2172. break;
  2173. }
  2174. case 'C9' :
  2175. {
  2176. $pf = array(113.386, 161.575);
  2177. break;
  2178. }
  2179. case 'C10' :
  2180. {
  2181. $pf = array(79.370, 113.386);
  2182. break;
  2183. }
  2184. case 'C11' :
  2185. {
  2186. $pf = array(56.693, 79.370);
  2187. break;
  2188. }
  2189. case 'C12' :
  2190. {
  2191. $pf = array(39.685, 56.693);
  2192. break;
  2193. }
  2194. case 'C76' :
  2195. {
  2196. $pf = array(229.606, 459.213);
  2197. break;
  2198. }
  2199. case 'DL' :
  2200. {
  2201. $pf = array(311.811, 623.622);
  2202. break;
  2203. }
  2204. // SIS 014711 E Series
  2205. case 'E0' :
  2206. {
  2207. $pf = array(2491.654, 3517.795);
  2208. break;
  2209. }
  2210. case 'E1' :
  2211. {
  2212. $pf = array(1757.480, 2491.654);
  2213. break;
  2214. }
  2215. case 'E2' :
  2216. {
  2217. $pf = array(1247.244, 1757.480);
  2218. break;
  2219. }
  2220. case 'E3' :
  2221. {
  2222. $pf = array(878.740, 1247.244);
  2223. break;
  2224. }
  2225. case 'E4' :
  2226. {
  2227. $pf = array(623.622, 878.740);
  2228. break;
  2229. }
  2230. case 'E5' :
  2231. {
  2232. $pf = array(439.370, 623.622);
  2233. break;
  2234. }
  2235. case 'E6' :
  2236. {
  2237. $pf = array(311.811, 439.370);
  2238. break;
  2239. }
  2240. case 'E7' :
  2241. {
  2242. $pf = array(221.102, 311.811);
  2243. break;
  2244. }
  2245. case 'E8' :
  2246. {
  2247. $pf = array(155.906, 221.102);
  2248. break;
  2249. }
  2250. case 'E9' :
  2251. {
  2252. $pf = array(110.551, 155.906);
  2253. break;
  2254. }
  2255. case 'E10' :
  2256. {
  2257. $pf = array(76.535, 110.551);
  2258. break;
  2259. }
  2260. case 'E11' :
  2261. {
  2262. $pf = array(53.858, 76.535);
  2263. break;
  2264. }
  2265. case 'E12' :
  2266. {
  2267. $pf = array(36.850, 53.858);
  2268. break;
  2269. }
  2270. // SIS 014711 G Series
  2271. case 'G0' :
  2272. {
  2273. $pf = array(2715.591, 3838.110);
  2274. break;
  2275. }
  2276. case 'G1' :
  2277. {
  2278. $pf = array(1919.055, 2715.591);
  2279. break;
  2280. }
  2281. case 'G2' :
  2282. {
  2283. $pf = array(1357.795, 1919.055);
  2284. break;
  2285. }
  2286. case 'G3' :
  2287. {
  2288. $pf = array(958.110, 1357.795);
  2289. break;
  2290. }
  2291. case 'G4' :
  2292. {
  2293. $pf = array(677.480, 958.110);
  2294. break;
  2295. }
  2296. case 'G5' :
  2297. {
  2298. $pf = array(479.055, 677.480);
  2299. break;
  2300. }
  2301. case 'G6' :
  2302. {
  2303. $pf = array(337.323, 479.055);
  2304. break;
  2305. }
  2306. case 'G7' :
  2307. {
  2308. $pf = array(238.110, 337.323);
  2309. break;
  2310. }
  2311. case 'G8' :
  2312. {
  2313. $pf = array(167.244, 238.110);
  2314. break;
  2315. }
  2316. case 'G9' :
  2317. {
  2318. $pf = array(119.055, 167.244);
  2319. break;
  2320. }
  2321. case 'G10' :
  2322. {
  2323. $pf = array(82.205, 119.055);
  2324. break;
  2325. }
  2326. case 'G11' :
  2327. {
  2328. $pf = array(59.528, 82.205);
  2329. break;
  2330. }
  2331. case 'G12' :
  2332. {
  2333. $pf = array(39.685, 59.528);
  2334. break;
  2335. }
  2336. // ISO Press
  2337. case 'RA0' :
  2338. {
  2339. $pf = array(2437.795, 3458.268);
  2340. break;
  2341. }
  2342. case 'RA1' :
  2343. {
  2344. $pf = array(1729.134, 2437.795);
  2345. break;
  2346. }
  2347. case 'RA2' :
  2348. {
  2349. $pf = array(1218.898, 1729.134);
  2350. break;
  2351. }
  2352. case 'RA3' :
  2353. {
  2354. $pf = array(864.567, 1218.898);
  2355. break;
  2356. }
  2357. case 'RA4' :
  2358. {
  2359. $pf = array(609.449, 864.567);
  2360. break;
  2361. }
  2362. case 'SRA0' :
  2363. {
  2364. $pf = array(2551.181, 3628.346);
  2365. break;
  2366. }
  2367. case 'SRA1' :
  2368. {
  2369. $pf = array(1814.173, 2551.181);
  2370. break;
  2371. }
  2372. case 'SRA2' :
  2373. {
  2374. $pf = array(1275.591, 1814.173);
  2375. break;
  2376. }
  2377. case 'SRA3' :
  2378. {
  2379. $pf = array(907.087, 1275.591);
  2380. break;
  2381. }
  2382. case 'SRA4' :
  2383. {
  2384. $pf = array(637.795, 907.087);
  2385. break;
  2386. }
  2387. // German DIN 476
  2388. case '4A0' :
  2389. {
  2390. $pf = array(4767.874, 6740.787);
  2391. break;
  2392. }
  2393. case '2A0' :
  2394. {
  2395. $pf = array(3370.394, 4767.874);
  2396. break;
  2397. }
  2398. // Variations on the ISO Standard
  2399. case 'A2_EXTRA' :
  2400. {
  2401. $pf = array(1261.417, 1754.646);
  2402. break;
  2403. }
  2404. case 'A3+' :
  2405. {
  2406. $pf = array(932.598, 1369.134);
  2407. break;
  2408. }
  2409. case 'A3_EXTRA' :
  2410. {
  2411. $pf = array(912.756, 1261.417);
  2412. break;
  2413. }
  2414. case 'A3_SUPER' :
  2415. {
  2416. $pf = array(864.567, 1440.000);
  2417. break;
  2418. }
  2419. case 'SUPER_A3' :
  2420. {
  2421. $pf = array(864.567, 1380.472);
  2422. break;
  2423. }
  2424. case 'A4_EXTRA' :
  2425. {
  2426. $pf = array(666.142, 912.756);
  2427. break;
  2428. }
  2429. case 'A4_SUPER' :
  2430. {
  2431. $pf = array(649.134, 912.756);
  2432. break;
  2433. }
  2434. case 'SUPER_A4' :
  2435. {
  2436. $pf = array(643.465, 1009.134);
  2437. break;
  2438. }
  2439. case 'A4_LONG' :
  2440. {
  2441. $pf = array(595.276, 986.457);
  2442. break;
  2443. }
  2444. case 'F4' :
  2445. {
  2446. $pf = array(595.276, 935.433);
  2447. break;
  2448. }
  2449. case 'SO_B5_EXTRA' :
  2450. {
  2451. $pf = array(572.598, 782.362);
  2452. break;
  2453. }
  2454. case 'A5_EXTRA' :
  2455. {
  2456. $pf = array(490.394, 666.142);
  2457. break;
  2458. }
  2459. // ANSI Series
  2460. case 'ANSI_E' :
  2461. {
  2462. $pf = array(2448.000, 3168.000);
  2463. break;
  2464. }
  2465. case 'ANSI_D' :
  2466. {
  2467. $pf = array(1584.000, 2448.000);
  2468. break;
  2469. }
  2470. case 'ANSI_C' :
  2471. {
  2472. $pf = array(1224.000, 1584.000);
  2473. break;
  2474. }
  2475. case 'ANSI_B' :
  2476. {
  2477. $pf = array(792.000, 1224.000);
  2478. break;
  2479. }
  2480. case 'ANSI_A' :
  2481. {
  2482. $pf = array(612.000, 792.000);
  2483. break;
  2484. }
  2485. // Traditional 'Loose' North American Paper Sizes
  2486. case 'USLEDGER' :
  2487. case 'LEDGER' :
  2488. {
  2489. $pf = array(1224.000, 792.000);
  2490. break;
  2491. }
  2492. case 'ORGANIZERK' :
  2493. case 'BIBLE' :
  2494. case 'USTABLOID' :
  2495. case 'TABLOID' :
  2496. {
  2497. $pf = array(792.000, 1224.000);
  2498. break;
  2499. }
  2500. case 'ORGANIZERM' :
  2501. case 'USLETTER' :
  2502. case 'LETTER' :
  2503. {
  2504. $pf = array(612.000, 792.000);
  2505. break;
  2506. }
  2507. case 'USLEGAL' :
  2508. case 'LEGAL' :
  2509. {
  2510. $pf = array(612.000, 1008.000);
  2511. break;
  2512. }
  2513. case 'GOVERNMENTLETTER' :
  2514. case 'GLETTER' :
  2515. {
  2516. $pf = array(576.000, 756.000);
  2517. break;
  2518. }
  2519. case 'JUNIORLEGAL' :
  2520. case 'JLEGAL' :
  2521. {
  2522. $pf = array(576.000, 360.000);
  2523. break;
  2524. }
  2525. // Other North American Paper Sizes
  2526. case 'QUADDEMY' :
  2527. {
  2528. $pf = array(2520.000, 3240.000);
  2529. break;
  2530. }
  2531. case 'SUPER_B' :
  2532. {
  2533. $pf = array(936.000, 1368.000);
  2534. break;
  2535. }
  2536. case 'QUARTO' :
  2537. {
  2538. $pf = array(648.000, 792.000);
  2539. break;
  2540. }
  2541. case 'GOVERNMENTLEGAL' :
  2542. case 'FOLIO' :
  2543. {
  2544. $pf = array(612.000, 936.000);
  2545. break;
  2546. }
  2547. case 'MONARCH' :
  2548. case 'EXECUTIVE' :
  2549. {
  2550. $pf = array(522.000, 756.000);
  2551. break;
  2552. }
  2553. case 'ORGANIZERL' :
  2554. case 'STATEMENT' :
  2555. case 'MEMO' :
  2556. {
  2557. $pf = array(396.000, 612.000);
  2558. break;
  2559. }
  2560. case 'FOOLSCAP' :
  2561. {
  2562. $pf = array(595.440, 936.000);
  2563. break;
  2564. }
  2565. case 'COMPACT' :
  2566. {
  2567. $pf = array(306.000, 486.000);
  2568. break;
  2569. }
  2570. case 'ORGANIZERJ' :
  2571. {
  2572. $pf = array(198.000, 360.000);
  2573. break;
  2574. }
  2575. // Canadian standard CAN 2-9.60M
  2576. case 'P1' :
  2577. {
  2578. $pf = array(1587.402, 2437.795);
  2579. break;
  2580. }
  2581. case 'P2' :
  2582. {
  2583. $pf = array(1218.898, 1587.402);
  2584. break;
  2585. }
  2586. case 'P3' :
  2587. {
  2588. $pf = array(793.701, 1218.898);
  2589. break;
  2590. }
  2591. case 'P4' :
  2592. {
  2593. $pf = array(609.449, 793.701);
  2594. break;
  2595. }
  2596. case 'P5' :
  2597. {
  2598. $pf = array(396.850, 609.449);
  2599. break;
  2600. }
  2601. case 'P6' :
  2602. {
  2603. $pf = array(303.307, 396.850);
  2604. break;
  2605. }
  2606. // North American Architectural Sizes
  2607. case 'ARCH_E' :
  2608. {
  2609. $pf = array(2592.000, 3456.000);
  2610. break;
  2611. }
  2612. case 'ARCH_E1' :
  2613. {
  2614. $pf = array(2160.000, 3024.000);
  2615. break;
  2616. }
  2617. case 'ARCH_D' :
  2618. {
  2619. $pf = array(1728.000, 2592.000);
  2620. break;
  2621. }
  2622. case 'BROADSHEET' :
  2623. case 'ARCH_C' :
  2624. {
  2625. $pf = array(1296.000, 1728.000);
  2626. break;
  2627. }
  2628. case 'ARCH_B' :
  2629. {
  2630. $pf = array(864.000, 1296.000);
  2631. break;
  2632. }
  2633. case 'ARCH_A' :
  2634. {
  2635. $pf = array(648.000, 864.000);
  2636. break;
  2637. }
  2638. // --- North American Envelope Sizes ---
  2639. // - Announcement Envelopes
  2640. case 'ANNENV_A2' :
  2641. {
  2642. $pf = array(314.640, 414.000);
  2643. break;
  2644. }
  2645. case 'ANNENV_A6' :
  2646. {
  2647. $pf = array(342.000, 468.000);
  2648. break;
  2649. }
  2650. case 'ANNENV_A7' :
  2651. {
  2652. $pf = array(378.000, 522.000);
  2653. break;
  2654. }
  2655. case 'ANNENV_A8' :
  2656. {
  2657. $pf = array(396.000, 584.640);
  2658. break;
  2659. }
  2660. case 'ANNENV_A10' :
  2661. {
  2662. $pf = array(450.000, 692.640);
  2663. break;
  2664. }
  2665. case 'ANNENV_SLIM' :
  2666. {
  2667. $pf = array(278.640, 638.640);
  2668. break;
  2669. }
  2670. // - Commercial Envelopes
  2671. case 'COMMENV_N6_1/4' :
  2672. {
  2673. $pf = array(252.000, 432.000);
  2674. break;
  2675. }
  2676. case 'COMMENV_N6_3/4' :
  2677. {
  2678. $pf = array(260.640, 468.000);
  2679. break;
  2680. }
  2681. case 'COMMENV_N8' :
  2682. {
  2683. $pf = array(278.640, 540.000);
  2684. break;
  2685. }
  2686. case 'COMMENV_N9' :
  2687. {
  2688. $pf = array(278.640, 638.640);
  2689. break;
  2690. }
  2691. case 'COMMENV_N10' :
  2692. {
  2693. $pf = array(296.640, 684.000);
  2694. break;
  2695. }
  2696. case 'COMMENV_N11' :
  2697. {
  2698. $pf = array(324.000, 746.640);
  2699. break;
  2700. }
  2701. case 'COMMENV_N12' :
  2702. {
  2703. $pf = array(342.000, 792.000);
  2704. break;
  2705. }
  2706. case 'COMMENV_N14' :
  2707. {
  2708. $pf = array(360.000, 828.000);
  2709. break;
  2710. }
  2711. // - Catalogue Envelopes
  2712. case 'CATENV_N1' :
  2713. {
  2714. $pf = array(432.000, 648.000);
  2715. break;
  2716. }
  2717. case 'CATENV_N1_3/4' :
  2718. {
  2719. $pf = array(468.000, 684.000);
  2720. break;
  2721. }
  2722. case 'CATENV_N2' :
  2723. {
  2724. $pf = array(468.000, 720.000);
  2725. break;
  2726. }
  2727. case 'CATENV_N3' :
  2728. {
  2729. $pf = array(504.000, 720.000);
  2730. break;
  2731. }
  2732. case 'CATENV_N6' :
  2733. {
  2734. $pf = array(540.000, 756.000);
  2735. break;
  2736. }
  2737. case 'CATENV_N7' :
  2738. {
  2739. $pf = array(576.000, 792.000);
  2740. break;
  2741. }
  2742. case 'CATENV_N8' :
  2743. {
  2744. $pf = array(594.000, 810.000);
  2745. break;
  2746. }
  2747. case 'CATENV_N9_1/2' :
  2748. {
  2749. $pf = array(612.000, 756.000);
  2750. break;
  2751. }
  2752. case 'CATENV_N9_3/4' :
  2753. {
  2754. $pf = array(630.000, 810.000);
  2755. break;
  2756. }
  2757. case 'CATENV_N10_1/2' :
  2758. {
  2759. $pf = array(648.000, 864.000);
  2760. break;
  2761. }
  2762. case 'CATENV_N12_1/2' :
  2763. {
  2764. $pf = array(684.000, 900.000);
  2765. break;
  2766. }
  2767. case 'CATENV_N13_1/2' :
  2768. {
  2769. $pf = array(720.000, 936.000);
  2770. break;
  2771. }
  2772. case 'CATENV_N14_1/4' :
  2773. {
  2774. $pf = array(810.000, 882.000);
  2775. break;
  2776. }
  2777. case 'CATENV_N14_1/2' :
  2778. {
  2779. $pf = array(828.000, 1044.000);
  2780. break;
  2781. }
  2782. // Japanese (JIS P 0138-61) Standard B-Series
  2783. case 'JIS_B0' :
  2784. {
  2785. $pf = array(2919.685, 4127.244);
  2786. break;
  2787. }
  2788. case 'JIS_B1' :
  2789. {
  2790. $pf = array(2063.622, 2919.685);
  2791. break;
  2792. }
  2793. case 'JIS_B2' :
  2794. {
  2795. $pf = array(1459.843, 2063.622);
  2796. break;
  2797. }
  2798. case 'JIS_B3' :
  2799. {
  2800. $pf = array(1031.811, 1459.843);
  2801. break;
  2802. }
  2803. case 'JIS_B4' :
  2804. {
  2805. $pf = array(728.504, 1031.811);
  2806. break;
  2807. }
  2808. case 'JIS_B5' :
  2809. {
  2810. $pf = array(515.906, 728.504);
  2811. break;
  2812. }
  2813. case 'JIS_B6' :
  2814. {
  2815. $pf = array(362.835, 515.906);
  2816. break;
  2817. }
  2818. case 'JIS_B7' :
  2819. {
  2820. $pf = array(257.953, 362.835);
  2821. break;
  2822. }
  2823. case 'JIS_B8' :
  2824. {
  2825. $pf = array(181.417, 257.953);
  2826. break;
  2827. }
  2828. case 'JIS_B9' :
  2829. {
  2830. $pf = array(127.559, 181.417);
  2831. break;
  2832. }
  2833. case 'JIS_B10' :
  2834. {
  2835. $pf = array(90.709, 127.559);
  2836. break;
  2837. }
  2838. case 'JIS_B11' :
  2839. {
  2840. $pf = array(62.362, 90.709);
  2841. break;
  2842. }
  2843. case 'JIS_B12' :
  2844. {
  2845. $pf = array(45.354, 62.362);
  2846. break;
  2847. }
  2848. // PA Series
  2849. case 'PA0' :
  2850. {
  2851. $pf = array(2381.102, 3174.803);
  2852. break;
  2853. }
  2854. case 'PA1' :
  2855. {
  2856. $pf = array(1587.402, 2381.102);
  2857. break;
  2858. }
  2859. case 'PA2' :
  2860. {
  2861. $pf = array(1190.551, 1587.402);
  2862. break;
  2863. }
  2864. case 'PA3' :
  2865. {
  2866. $pf = array(793.701, 1190.551);
  2867. break;
  2868. }
  2869. case 'PA4' :
  2870. {
  2871. $pf = array(595.276, 793.701);
  2872. break;
  2873. }
  2874. case 'PA5' :
  2875. {
  2876. $pf = array(396.850, 595.276);
  2877. break;
  2878. }
  2879. case 'PA6' :
  2880. {
  2881. $pf = array(297.638, 396.850);
  2882. break;
  2883. }
  2884. case 'PA7' :
  2885. {
  2886. $pf = array(198.425, 297.638);
  2887. break;
  2888. }
  2889. case 'PA8' :
  2890. {
  2891. $pf = array(147.402, 198.425);
  2892. break;
  2893. }
  2894. case 'PA9' :
  2895. {
  2896. $pf = array(99.213, 147.402);
  2897. break;
  2898. }
  2899. case 'PA10' :
  2900. {
  2901. $pf = array(73.701, 99.213);
  2902. break;
  2903. }
  2904. // Standard Photographic Print Sizes
  2905. case 'PASSPORT_PHOTO' :
  2906. {
  2907. $pf = array(99.213, 127.559);
  2908. break;
  2909. }
  2910. case 'E' :
  2911. {
  2912. $pf = array(233.858, 340.157);
  2913. break;
  2914. }
  2915. case 'L' :
  2916. case '3R' :
  2917. {
  2918. $pf = array(252.283, 360.000);
  2919. break;
  2920. }
  2921. case 'KG' :
  2922. case '4R' :
  2923. {
  2924. $pf = array(289.134, 430.866);
  2925. break;
  2926. }
  2927. case '4D' :
  2928. {
  2929. $pf = array(340.157, 430.866);
  2930. break;
  2931. }
  2932. case '2L' :
  2933. case '5R' :
  2934. {
  2935. $pf = array(360.000, 504.567);
  2936. break;
  2937. }
  2938. case '8P' :
  2939. case '6R' :
  2940. {
  2941. $pf = array(430.866, 575.433);
  2942. break;
  2943. }
  2944. case '6P' :
  2945. case '8R' :
  2946. {
  2947. $pf = array(575.433, 720.000);
  2948. break;
  2949. }
  2950. case '6PW' :
  2951. case 'S8R' :
  2952. {
  2953. $pf = array(575.433, 864.567);
  2954. break;
  2955. }
  2956. case '4P' :
  2957. case '10R' :
  2958. {
  2959. $pf = array(720.000, 864.567);
  2960. break;
  2961. }
  2962. case '4PW' :
  2963. case 'S10R' :
  2964. {
  2965. $pf = array(720.000, 1080.000);
  2966. break;
  2967. }
  2968. case '11R' :
  2969. {
  2970. $pf = array(790.866, 1009.134);
  2971. break;
  2972. }
  2973. case 'S11R' :
  2974. {
  2975. $pf = array(790.866, 1224.567);
  2976. break;
  2977. }
  2978. case '12R' :
  2979. {
  2980. $pf = array(864.567, 1080.000);
  2981. break;
  2982. }
  2983. case 'S12R' :
  2984. {
  2985. $pf = array(864.567, 1292.598);
  2986. break;
  2987. }
  2988. // Common Newspaper Sizes
  2989. case 'NEWSPAPER_BROADSHEET' :
  2990. {
  2991. $pf = array(2125.984, 1700.787);
  2992. break;
  2993. }
  2994. case 'NEWSPAPER_BERLINER' :
  2995. {
  2996. $pf = array(1332.283, 892.913);
  2997. break;
  2998. }
  2999. case 'NEWSPAPER_TABLOID' :
  3000. case 'NEWSPAPER_COMPACT' :
  3001. {
  3002. $pf = array(1218.898, 793.701);
  3003. break;
  3004. }
  3005. // Business Cards
  3006. case 'CREDIT_CARD' :
  3007. case 'BUSINESS_CARD' :
  3008. case 'BUSINESS_CARD_ISO7810' :
  3009. {
  3010. $pf = array(153.014, 242.646);
  3011. break;
  3012. }
  3013. case 'BUSINESS_CARD_ISO216' :
  3014. {
  3015. $pf = array(147.402, 209.764);
  3016. break;
  3017. }
  3018. case 'BUSINESS_CARD_IT' :
  3019. case 'BUSINESS_CARD_UK' :
  3020. case 'BUSINESS_CARD_FR' :
  3021. case 'BUSINESS_CARD_DE' :
  3022. case 'BUSINESS_CARD_ES' :
  3023. {
  3024. $pf = array(155.906, 240.945);
  3025. break;
  3026. }
  3027. case 'BUSINESS_CARD_CA' :
  3028. case 'BUSINESS_CARD_US' :
  3029. {
  3030. $pf = array(144.567, 252.283);
  3031. break;
  3032. }
  3033. case 'BUSINESS_CARD_JP' :
  3034. {
  3035. $pf = array(155.906, 257.953);
  3036. break;
  3037. }
  3038. case 'BUSINESS_CARD_HK' :
  3039. {
  3040. $pf = array(153.071, 255.118);
  3041. break;
  3042. }
  3043. case 'BUSINESS_CARD_AU' :
  3044. case 'BUSINESS_CARD_DK' :
  3045. case 'BUSINESS_CARD_SE' :
  3046. {
  3047. $pf = array(155.906, 255.118);
  3048. break;
  3049. }
  3050. case 'BUSINESS_CARD_RU' :
  3051. case 'BUSINESS_CARD_CZ' :
  3052. case 'BUSINESS_CARD_FI' :
  3053. case 'BUSINESS_CARD_HU' :
  3054. case 'BUSINESS_CARD_IL' :
  3055. {
  3056. $pf = array(141.732, 255.118);
  3057. break;
  3058. }
  3059. // Billboards
  3060. case '4SHEET' :
  3061. {
  3062. $pf = array(2880.000, 4320.000);
  3063. break;
  3064. }
  3065. case '6SHEET' :
  3066. {
  3067. $pf = array(3401.575, 5102.362);
  3068. break;
  3069. }
  3070. case '12SHEET' :
  3071. {
  3072. $pf = array(8640.000, 4320.000);
  3073. break;
  3074. }
  3075. case '16SHEET' :
  3076. {
  3077. $pf = array(5760.000, 8640.000);
  3078. break;
  3079. }
  3080. case '32SHEET' :
  3081. {
  3082. $pf = array(11520.000, 8640.000);
  3083. break;
  3084. }
  3085. case '48SHEET' :
  3086. {
  3087. $pf = array(17280.000, 8640.000);
  3088. break;
  3089. }
  3090. case '64SHEET' :
  3091. {
  3092. $pf = array(23040.000, 8640.000);
  3093. break;
  3094. }
  3095. case '96SHEET' :
  3096. {
  3097. $pf = array(34560.000, 8640.000);
  3098. break;
  3099. }
  3100. // Old European Sizes
  3101. // - Old Imperial English Sizes
  3102. case 'EN_EMPEROR' :
  3103. {
  3104. $pf = array(3456.000, 5184.000);
  3105. break;
  3106. }
  3107. case 'EN_ANTIQUARIAN' :
  3108. {
  3109. $pf = array(2232.000, 3816.000);
  3110. break;
  3111. }
  3112. case 'EN_GRAND_EAGLE' :
  3113. {
  3114. $pf = array(2070.000, 3024.000);
  3115. break;
  3116. }
  3117. case 'EN_DOUBLE_ELEPHANT' :
  3118. {
  3119. $pf = array(1926.000, 2880.000);
  3120. break;
  3121. }
  3122. case 'EN_ATLAS' :
  3123. {
  3124. $pf = array(1872.000, 2448.000);
  3125. break;
  3126. }
  3127. case 'EN_COLOMBIER' :
  3128. {
  3129. $pf = array(1692.000, 2484.000);
  3130. break;
  3131. }
  3132. case 'EN_ELEPHANT' :
  3133. {
  3134. $pf = array(1656.000, 2016.000);
  3135. break;
  3136. }
  3137. case 'EN_DOUBLE_DEMY' :
  3138. {
  3139. $pf = array(1620.000, 2556.000);
  3140. break;
  3141. }
  3142. case 'EN_IMPERIAL' :
  3143. {
  3144. $pf = array(1584.000, 2160.000);
  3145. break;
  3146. }
  3147. case 'EN_PRINCESS' :
  3148. {
  3149. $pf = array(1548.000, 2016.000);
  3150. break;
  3151. }
  3152. case 'EN_CARTRIDGE' :
  3153. {
  3154. $pf = array(1512.000, 1872.000);
  3155. break;
  3156. }
  3157. case 'EN_DOUBLE_LARGE_POST' :
  3158. {
  3159. $pf = array(1512.000, 2376.000);
  3160. break;
  3161. }
  3162. case 'EN_ROYAL' :
  3163. {
  3164. $pf = array(1440.000, 1800.000);
  3165. break;
  3166. }
  3167. case 'EN_SHEET' :
  3168. case 'EN_HALF_POST' :
  3169. {
  3170. $pf = array(1404.000, 1692.000);
  3171. break;
  3172. }
  3173. case 'EN_SUPER_ROYAL' :
  3174. {
  3175. $pf = array(1368.000, 1944.000);
  3176. break;
  3177. }
  3178. case 'EN_DOUBLE_POST' :
  3179. {
  3180. $pf = array(1368.000, 2196.000);
  3181. break;
  3182. }
  3183. case 'EN_MEDIUM' :
  3184. {
  3185. $pf = array(1260.000, 1656.000);
  3186. break;
  3187. }
  3188. case 'EN_DEMY' :
  3189. {
  3190. $pf = array(1260.000, 1620.000);
  3191. break;
  3192. }
  3193. case 'EN_LARGE_POST' :
  3194. {
  3195. $pf = array(1188.000, 1512.000);
  3196. break;
  3197. }
  3198. case 'EN_COPY_DRAUGHT' :
  3199. {
  3200. $pf = array(1152.000, 1440.000);
  3201. break;
  3202. }
  3203. case 'EN_POST' :
  3204. {
  3205. $pf = array(1116.000, 1386.000);
  3206. break;
  3207. }
  3208. case 'EN_CROWN' :
  3209. {
  3210. $pf = array(1080.000, 1440.000);
  3211. break;
  3212. }
  3213. case 'EN_PINCHED_POST' :
  3214. {
  3215. $pf = array(1062.000, 1332.000);
  3216. break;
  3217. }
  3218. case 'EN_BRIEF' :
  3219. {
  3220. $pf = array(972.000, 1152.000);
  3221. break;
  3222. }
  3223. case 'EN_FOOLSCAP' :
  3224. {
  3225. $pf = array(972.000, 1224.000);
  3226. break;
  3227. }
  3228. case 'EN_SMALL_FOOLSCAP' :
  3229. {
  3230. $pf = array(954.000, 1188.000);
  3231. break;
  3232. }
  3233. case 'EN_POTT' :
  3234. {
  3235. $pf = array(900.000, 1080.000);
  3236. break;
  3237. }
  3238. // - Old Imperial Belgian Sizes
  3239. case 'BE_GRAND_AIGLE' :
  3240. {
  3241. $pf = array(1984.252, 2948.031);
  3242. break;
  3243. }
  3244. case 'BE_COLOMBIER' :
  3245. {
  3246. $pf = array(1757.480, 2409.449);
  3247. break;
  3248. }
  3249. case 'BE_DOUBLE_CARRE' :
  3250. {
  3251. $pf = array(1757.480, 2607.874);
  3252. break;
  3253. }
  3254. case 'BE_ELEPHANT' :
  3255. {
  3256. $pf = array(1746.142, 2182.677);
  3257. break;
  3258. }
  3259. case 'BE_PETIT_AIGLE' :
  3260. {
  3261. $pf = array(1700.787, 2381.102);
  3262. break;
  3263. }
  3264. case 'BE_GRAND_JESUS' :
  3265. {
  3266. $pf = array(1559.055, 2069.291);
  3267. break;
  3268. }
  3269. case 'BE_JESUS' :
  3270. {
  3271. $pf = array(1530.709, 2069.291);
  3272. break;
  3273. }
  3274. case 'BE_RAISIN' :
  3275. {
  3276. $pf = array(1417.323, 1842.520);
  3277. break;
  3278. }
  3279. case 'BE_GRAND_MEDIAN' :
  3280. {
  3281. $pf = array(1303.937, 1714.961);
  3282. break;
  3283. }
  3284. case 'BE_DOUBLE_POSTE' :
  3285. {
  3286. $pf = array(1233.071, 1601.575);
  3287. break;
  3288. }
  3289. case 'BE_COQUILLE' :
  3290. {
  3291. $pf = array(1218.898, 1587.402);
  3292. break;
  3293. }
  3294. case 'BE_PETIT_MEDIAN' :
  3295. {
  3296. $pf = array(1176.378, 1502.362);
  3297. break;
  3298. }
  3299. case 'BE_RUCHE' :
  3300. {
  3301. $pf = array(1020.472, 1303.937);
  3302. break;
  3303. }
  3304. case 'BE_PROPATRIA' :
  3305. {
  3306. $pf = array(977.953, 1218.898);
  3307. break;
  3308. }
  3309. case 'BE_LYS' :
  3310. {
  3311. $pf = array(898.583, 1125.354);
  3312. break;
  3313. }
  3314. case 'BE_POT' :
  3315. {
  3316. $pf = array(870.236, 1088.504);
  3317. break;
  3318. }
  3319. case 'BE_ROSETTE' :
  3320. {
  3321. $pf = array(765.354, 983.622);
  3322. break;
  3323. }
  3324. // - Old Imperial French Sizes
  3325. case 'FR_UNIVERS' :
  3326. {
  3327. $pf = array(2834.646, 3685.039);
  3328. break;
  3329. }
  3330. case 'FR_DOUBLE_COLOMBIER' :
  3331. {
  3332. $pf = array(2551.181, 3571.654);
  3333. break;
  3334. }
  3335. case 'FR_GRANDE_MONDE' :
  3336. {
  3337. $pf = array(2551.181, 3571.654);
  3338. break;
  3339. }
  3340. case 'FR_DOUBLE_SOLEIL' :
  3341. {
  3342. $pf = array(2267.717, 3401.575);
  3343. break;
  3344. }
  3345. case 'FR_DOUBLE_JESUS' :
  3346. {
  3347. $pf = array(2154.331, 3174.803);
  3348. break;
  3349. }
  3350. case 'FR_GRAND_AIGLE' :
  3351. {
  3352. $pf = array(2125.984, 3004.724);
  3353. break;
  3354. }
  3355. case 'FR_PETIT_AIGLE' :
  3356. {
  3357. $pf = array(1984.252, 2664.567);
  3358. break;
  3359. }
  3360. case 'FR_DOUBLE_RAISIN' :
  3361. {
  3362. $pf = array(1842.520, 2834.646);
  3363. break;
  3364. }
  3365. case 'FR_JOURNAL' :
  3366. {
  3367. $pf = array(1842.520, 2664.567);
  3368. break;
  3369. }
  3370. case 'FR_COLOMBIER_AFFICHE' :
  3371. {
  3372. $pf = array(1785.827, 2551.181);
  3373. break;
  3374. }
  3375. case 'FR_DOUBLE_CAVALIER' :
  3376. {
  3377. $pf = array(1757.480, 2607.874);
  3378. break;
  3379. }
  3380. case 'FR_CLOCHE' :
  3381. {
  3382. $pf = array(1700.787, 2267.717);
  3383. break;
  3384. }
  3385. case 'FR_SOLEIL' :
  3386. {
  3387. $pf = array(1700.787, 2267.717);
  3388. break;
  3389. }
  3390. case 'FR_DOUBLE_CARRE' :
  3391. {
  3392. $pf = array(1587.402, 2551.181);
  3393. break;
  3394. }
  3395. case 'FR_DOUBLE_COQUILLE' :
  3396. {
  3397. $pf = array(1587.402, 2494.488);
  3398. break;
  3399. }
  3400. case 'FR_JESUS' :
  3401. {
  3402. $pf = array(1587.402, 2154.331);
  3403. break;
  3404. }
  3405. case 'FR_RAISIN' :
  3406. {
  3407. $pf = array(1417.323, 1842.520);
  3408. break;
  3409. }
  3410. case 'FR_CAVALIER' :
  3411. {
  3412. $pf = array(1303.937, 1757.480);
  3413. break;
  3414. }
  3415. case 'FR_DOUBLE_COURONNE' :
  3416. {
  3417. $pf = array(1303.937, 2040.945);
  3418. break;
  3419. }
  3420. case 'FR_CARRE' :
  3421. {
  3422. $pf = array(1275.591, 1587.402);
  3423. break;
  3424. }
  3425. case 'FR_COQUILLE' :
  3426. {
  3427. $pf = array(1247.244, 1587.402);
  3428. break;
  3429. }
  3430. case 'FR_DOUBLE_TELLIERE' :
  3431. {
  3432. $pf = array(1247.244, 1927.559);
  3433. break;
  3434. }
  3435. case 'FR_DOUBLE_CLOCHE' :
  3436. {
  3437. $pf = array(1133.858, 1700.787);
  3438. break;
  3439. }
  3440. case 'FR_DOUBLE_POT' :
  3441. {
  3442. $pf = array(1133.858, 1757.480);
  3443. break;
  3444. }
  3445. case 'FR_ECU' :
  3446. {
  3447. $pf = array(1133.858, 1474.016);
  3448. break;
  3449. }
  3450. case 'FR_COURONNE' :
  3451. {
  3452. $pf = array(1020.472, 1303.937);
  3453. break;
  3454. }
  3455. case 'FR_TELLIERE' :
  3456. {
  3457. $pf = array(963.780, 1247.244);
  3458. break;
  3459. }
  3460. case 'FR_POT' :
  3461. {
  3462. $pf = array(878.740, 1133.858);
  3463. break;
  3464. }
  3465. // DEFAULT ISO A4
  3466. default :
  3467. {
  3468. $pf = array(595.276, 841.890);
  3469. break;
  3470. }
  3471. }
  3472. return $pf;
  3473. }
  3474. /**
  3475. * Change the format of the current page
  3476. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numners (width, height) or an array containing the following measures and options:<ul>
  3477. * <li>['format'] = page format name (one of the above);</li>
  3478. * <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>
  3479. * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
  3480. * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
  3481. * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
  3482. * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
  3483. * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
  3484. * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
  3485. * <li>['CropBox'] : the visible region of default user space:</li>
  3486. * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
  3487. * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
  3488. * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
  3489. * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
  3490. * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
  3491. * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
  3492. * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
  3493. * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
  3494. * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
  3495. * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
  3496. * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
  3497. * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
  3498. * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
  3499. * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
  3500. * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
  3501. * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
  3502. * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
  3503. * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
  3504. * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
  3505. * <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>
  3506. * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
  3507. * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
  3508. * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
  3509. * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
  3510. * <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>
  3511. * <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>
  3512. * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
  3513. * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
  3514. * <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>
  3515. * <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>
  3516. * <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>
  3517. * <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>
  3518. * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
  3519. * </ul>
  3520. * @param string $orientation page orientation. Possible values are (case insensitive):<ul>
  3521. * <li>P or Portrait (default)</li>
  3522. * <li>L or Landscape</li>
  3523. * <li>'' (empty string) for automatic orientation</li>
  3524. * </ul>
  3525. * @access protected
  3526. * @since 3.0.015 (2008-06-06)
  3527. * @see getPageSizeFromFormat()
  3528. */
  3529. protected function setPageFormat($format, $orientation = 'P')
  3530. {
  3531. if (! empty($format) and isset($this->pagedim[$this->page]))
  3532. {
  3533. // remove inherited values
  3534. unset($this->pagedim[$this->page]);
  3535. }
  3536. if (is_string($format))
  3537. {
  3538. // get page measures from format name
  3539. $pf = $this->getPageSizeFromFormat($format);
  3540. $this->fwPt = $pf[0];
  3541. $this->fhPt = $pf[1];
  3542. }
  3543. else
  3544. {
  3545. // the boundaries of the physical medium on which the page shall be displayed or printed
  3546. if (isset($format['MediaBox']))
  3547. {
  3548. $this->setPageBoxes($this->page, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
  3549. $this->fwPt = (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k);
  3550. $this->fhPt = (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k);
  3551. }
  3552. else
  3553. {
  3554. if (isset($format[0]) and is_numeric($format[0]) and isset($format[1]) and is_numeric($format[1]))
  3555. {
  3556. $pf = array(($format[0] * $this->k), ($format[1] * $this->k));
  3557. }
  3558. else
  3559. {
  3560. if (! isset($format['format']))
  3561. {
  3562. // default value
  3563. $format['format'] = 'A4';
  3564. }
  3565. $pf = $this->getPageSizeFromFormat($format['format']);
  3566. }
  3567. $this->fwPt = $pf[0];
  3568. $this->fhPt = $pf[1];
  3569. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  3570. }
  3571. // the visible region of default user space
  3572. if (isset($format['CropBox']))
  3573. {
  3574. $this->setPageBoxes($this->page, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
  3575. }
  3576. // the region to which the contents of the page shall be clipped when output in a production environment
  3577. if (isset($format['BleedBox']))
  3578. {
  3579. $this->setPageBoxes($this->page, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
  3580. }
  3581. // the intended dimensions of the finished page after trimming
  3582. if (isset($format['TrimBox']))
  3583. {
  3584. $this->setPageBoxes($this->page, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
  3585. }
  3586. // the page's meaningful content (including potential white space)
  3587. if (isset($format['ArtBox']))
  3588. {
  3589. $this->setPageBoxes($this->page, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
  3590. }
  3591. // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
  3592. if (isset($format['BoxColorInfo']))
  3593. {
  3594. $this->pagedim[$this->page]['BoxColorInfo'] = $format['BoxColorInfo'];
  3595. }
  3596. if (isset($format['Rotate']) and (($format['Rotate'] % 90) == 0))
  3597. {
  3598. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  3599. $this->pagedim[$this->page]['Rotate'] = intval($format['Rotate']);
  3600. }
  3601. if (isset($format['PZ']))
  3602. {
  3603. // The page's preferred zoom (magnification) factor
  3604. $this->pagedim[$this->page]['PZ'] = floatval($format['PZ']);
  3605. }
  3606. if (isset($format['trans']))
  3607. {
  3608. // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
  3609. if (isset($format['trans']['Dur']))
  3610. {
  3611. // The page's display duration
  3612. $this->pagedim[$this->page]['trans']['Dur'] = floatval($format['trans']['Dur']);
  3613. }
  3614. $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push',
  3615. 'Cover', 'Uncover', 'Fade');
  3616. if (isset($format['trans']['S']) and in_array($format['trans']['S'], $stansition_styles))
  3617. {
  3618. // The transition style that shall be used when moving to this page from another during a presentation
  3619. $this->pagedim[$this->page]['trans']['S'] = $format['trans']['S'];
  3620. $valid_effect = array('Split', 'Blinds');
  3621. $valid_vals = array('H', 'V');
  3622. if (isset($format['trans']['Dm']) and in_array($format['trans']['S'], $valid_effect) and in_array($format['trans']['Dm'], $valid_vals))
  3623. {
  3624. $this->pagedim[$this->page]['trans']['Dm'] = $format['trans']['Dm'];
  3625. }
  3626. $valid_effect = array('Split', 'Box', 'Fly');
  3627. $valid_vals = array('I', 'O');
  3628. if (isset($format['trans']['M']) and in_array($format['trans']['S'], $valid_effect) and in_array($format['trans']['M'], $valid_vals))
  3629. {
  3630. $this->pagedim[$this->page]['trans']['M'] = $format['trans']['M'];
  3631. }
  3632. $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
  3633. if (isset($format['trans']['Di']) and in_array($format['trans']['S'], $valid_effect))
  3634. {
  3635. if (((($format['trans']['Di'] == 90) or ($format['trans']['Di'] == 180)) and ($format['trans']['S'] == 'Wipe')) or (($format['trans']['Di'] == 315) and ($format['trans']['S'] == 'Glitter')) or (($format['trans']['Di'] == 0) or ($format['trans']['Di'] == 270)))
  3636. {
  3637. $this->pagedim[$this->page]['trans']['Di'] = intval($format['trans']['Di']);
  3638. }
  3639. }
  3640. if (isset($format['trans']['SS']) and ($format['trans']['S'] == 'Fly'))
  3641. {
  3642. $this->pagedim[$this->page]['trans']['SS'] = floatval($format['trans']['SS']);
  3643. }
  3644. if (isset($format['trans']['B']) and ($format['trans']['B'] === true) and ($format['trans']['S'] == 'Fly'))
  3645. {
  3646. $this->pagedim[$this->page]['trans']['B'] = 'true';
  3647. }
  3648. }
  3649. else
  3650. {
  3651. $this->pagedim[$this->page]['trans']['S'] = 'R';
  3652. }
  3653. if (isset($format['trans']['D']))
  3654. {
  3655. // The duration of the transition effect, in seconds
  3656. $this->pagedim[$this->page]['trans']['D'] = floatval($format['trans']['D']);
  3657. }
  3658. else
  3659. {
  3660. $this->pagedim[$this->page]['trans']['D'] = 1;
  3661. }
  3662. }
  3663. }
  3664. $this->setPageOrientation($orientation);
  3665. }
  3666. /**
  3667. * Set page boundaries.
  3668. * @param int $page page number
  3669. * @param string $type valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
  3670. * @param float $llx lower-left x coordinate in user units
  3671. * @param float $lly lower-left y coordinate in user units
  3672. * @param float $urx upper-right x coordinate in user units
  3673. * @param float $ury upper-right y coordinate in user units
  3674. * @param boolean $points if true uses user units as unit of measure, otherwise uses PDF points
  3675. * @access public
  3676. * @since 5.0.010 (2010-05-17)
  3677. */
  3678. public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points = false)
  3679. {
  3680. if (! isset($this->pagedim[$page]))
  3681. {
  3682. // initialize array
  3683. $this->pagedim[$page] = array();
  3684. }
  3685. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  3686. if (! in_array($type, $pageboxes))
  3687. {
  3688. return;
  3689. }
  3690. if ($points)
  3691. {
  3692. $k = 1;
  3693. }
  3694. else
  3695. {
  3696. $k = $this->k;
  3697. }
  3698. $this->pagedim[$page][$type]['llx'] = ($llx * $k);
  3699. $this->pagedim[$page][$type]['lly'] = ($lly * $k);
  3700. $this->pagedim[$page][$type]['urx'] = ($urx * $k);
  3701. $this->pagedim[$page][$type]['ury'] = ($ury * $k);
  3702. }
  3703. /**
  3704. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  3705. * @param int $page page number
  3706. * @access protected
  3707. * @since 5.0.010 (2010-05-17)
  3708. */
  3709. protected function swapPageBoxCoordinates($page)
  3710. {
  3711. $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  3712. foreach ($pageboxes as $type)
  3713. {
  3714. // swap X and Y coordinates
  3715. if (isset($this->pagedim[$page][$type]))
  3716. {
  3717. $tmp = $this->pagedim[$page][$type]['llx'];
  3718. $this->pagedim[$page][$type]['llx'] = $this->pagedim[$page][$type]['lly'];
  3719. $this->pagedim[$page][$type]['lly'] = $tmp;
  3720. $tmp = $this->pagedim[$page][$type]['urx'];
  3721. $this->pagedim[$page][$type]['urx'] = $this->pagedim[$page][$type]['ury'];
  3722. $this->pagedim[$page][$type]['ury'] = $tmp;
  3723. }
  3724. }
  3725. }
  3726. /**
  3727. * Set page orientation.
  3728. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
  3729. * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  3730. * @param float $bottommargin bottom margin of the page.
  3731. * @access public
  3732. * @since 3.0.015 (2008-06-06)
  3733. */
  3734. public function setPageOrientation($orientation, $autopagebreak = '', $bottommargin = '')
  3735. {
  3736. if (! isset($this->pagedim[$this->page]['MediaBox']))
  3737. {
  3738. // the boundaries of the physical medium on which the page shall be displayed or printed
  3739. $this->setPageBoxes($this->page, 'MediaBox', 0, 0, $this->fwPt, $this->fhPt, true);
  3740. }
  3741. if (! isset($this->pagedim[$this->page]['CropBox']))
  3742. {
  3743. // the visible region of default user space
  3744. $this->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);
  3745. }
  3746. if (! isset($this->pagedim[$this->page]['BleedBox']))
  3747. {
  3748. // the region to which the contents of the page shall be clipped when output in a production environment
  3749. $this->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);
  3750. }
  3751. if (! isset($this->pagedim[$this->page]['TrimBox']))
  3752. {
  3753. // the intended dimensions of the finished page after trimming
  3754. $this->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);
  3755. }
  3756. if (! isset($this->pagedim[$this->page]['ArtBox']))
  3757. {
  3758. // the page's meaningful content (including potential white space)
  3759. $this->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);
  3760. }
  3761. if (! isset($this->pagedim[$this->page]['Rotate']))
  3762. {
  3763. // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
  3764. $this->pagedim[$this->page]['Rotate'] = 0;
  3765. }
  3766. if (! isset($this->pagedim[$this->page]['PZ']))
  3767. {
  3768. // The page's preferred zoom (magnification) factor
  3769. $this->pagedim[$this->page]['PZ'] = 1;
  3770. }
  3771. if ($this->fwPt > $this->fhPt)
  3772. {
  3773. // landscape
  3774. $default_orientation = 'L';
  3775. }
  3776. else
  3777. {
  3778. // portrait
  3779. $default_orientation = 'P';
  3780. }
  3781. $valid_orientations = array('P', 'L');
  3782. if (empty($orientation))
  3783. {
  3784. $orientation = $default_orientation;
  3785. }
  3786. else
  3787. {
  3788. $orientation = strtoupper($orientation{0});
  3789. }
  3790. if (in_array($orientation, $valid_orientations) and ($orientation != $default_orientation))
  3791. {
  3792. $this->CurOrientation = $orientation;
  3793. $this->wPt = $this->fhPt;
  3794. $this->hPt = $this->fwPt;
  3795. }
  3796. else
  3797. {
  3798. $this->CurOrientation = $default_orientation;
  3799. $this->wPt = $this->fwPt;
  3800. $this->hPt = $this->fhPt;
  3801. }
  3802. if ((abs($this->pagedim[$this->page]['MediaBox']['urx'] - $this->hPt) < $this->feps) and (abs($this->pagedim[$this->page]['MediaBox']['ury'] - $this->wPt) < $this->feps))
  3803. {
  3804. // swap X and Y coordinates (change page orientation)
  3805. $this->swapPageBoxCoordinates($this->page);
  3806. }
  3807. $this->w = $this->wPt / $this->k;
  3808. $this->h = $this->hPt / $this->k;
  3809. if ($this->empty_string($autopagebreak))
  3810. {
  3811. if (isset($this->AutoPageBreak))
  3812. {
  3813. $autopagebreak = $this->AutoPageBreak;
  3814. }
  3815. else
  3816. {
  3817. $autopagebreak = true;
  3818. }
  3819. }
  3820. if ($this->empty_string($bottommargin))
  3821. {
  3822. if (isset($this->bMargin))
  3823. {
  3824. $bottommargin = $this->bMargin;
  3825. }
  3826. else
  3827. {
  3828. // default value = 2 cm
  3829. $bottommargin = 2 * 28.35 / $this->k;
  3830. }
  3831. }
  3832. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  3833. // store page dimensions
  3834. $this->pagedim[$this->page]['w'] = $this->wPt;
  3835. $this->pagedim[$this->page]['h'] = $this->hPt;
  3836. $this->pagedim[$this->page]['wk'] = $this->w;
  3837. $this->pagedim[$this->page]['hk'] = $this->h;
  3838. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  3839. $this->pagedim[$this->page]['bm'] = $bottommargin;
  3840. $this->pagedim[$this->page]['lm'] = $this->lMargin;
  3841. $this->pagedim[$this->page]['rm'] = $this->rMargin;
  3842. $this->pagedim[$this->page]['pb'] = $autopagebreak;
  3843. $this->pagedim[$this->page]['or'] = $this->CurOrientation;
  3844. $this->pagedim[$this->page]['olm'] = $this->original_lMargin;
  3845. $this->pagedim[$this->page]['orm'] = $this->original_rMargin;
  3846. }
  3847. /**
  3848. * Set regular expression to detect withespaces or word separators.
  3849. * The pattern delimiter must be the forward-slash character '/'.
  3850. * Some example patterns are:
  3851. * <pre>
  3852. * Non-Unicode or missing PCRE unicode support: '/[^\S\xa0]/'
  3853. * Unicode and PCRE unicode support: '/[^\S\P{Z}\xa0]/u'
  3854. * Unicode and PCRE unicode support in Chinese mode: '/[^\S\P{Z}\P{Lo}\xa0]/u'
  3855. * if PCRE unicode support is turned ON (\P is the negate class of \p):
  3856. * \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  3857. * \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  3858. * \p{Lo} is needed for Chinese characters because are packed next to each other without spaces in between.
  3859. * </pre>
  3860. * @param string $re regular expression (leave empty for default).
  3861. * @access public
  3862. * @since 4.6.016 (2009-06-15)
  3863. */
  3864. public function setSpacesRE($re = '/[^\S\xa0]/')
  3865. {
  3866. $this->re_spaces = $re;
  3867. $re_parts = explode('/', $re);
  3868. // get pattern parts
  3869. $this->re_space = array();
  3870. if (isset($re_parts[1]) and ! empty($re_parts[1]))
  3871. {
  3872. $this->re_space['p'] = $re_parts[1];
  3873. }
  3874. else
  3875. {
  3876. $this->re_space['p'] = '[\s]';
  3877. }
  3878. // set pattern modifiers
  3879. if (isset($re_parts[2]) and ! empty($re_parts[2]))
  3880. {
  3881. $this->re_space['m'] = $re_parts[2];
  3882. }
  3883. else
  3884. {
  3885. $this->re_space['m'] = '';
  3886. }
  3887. }
  3888. /**
  3889. * Enable or disable Right-To-Left language mode
  3890. * @param Boolean $enable if true enable Right-To-Left language mode.
  3891. * @param Boolean $resetx if true reset the X position on direction change.
  3892. * @access public
  3893. * @since 2.0.000 (2008-01-03)
  3894. */
  3895. public function setRTL($enable, $resetx = true)
  3896. {
  3897. $enable = $enable ? true : false;
  3898. $resetx = ($resetx and ($enable != $this->rtl));
  3899. $this->rtl = $enable;
  3900. $this->tmprtl = false;
  3901. if ($resetx)
  3902. {
  3903. $this->Ln(0);
  3904. }
  3905. }
  3906. /**
  3907. * Return the RTL status
  3908. * @return boolean
  3909. * @access public
  3910. * @since 4.0.012 (2008-07-24)
  3911. */
  3912. public function getRTL()
  3913. {
  3914. return $this->rtl;
  3915. }
  3916. /**
  3917. * Force temporary RTL language direction
  3918. * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  3919. * @access public
  3920. * @since 2.1.000 (2008-01-09)
  3921. */
  3922. public function setTempRTL($mode)
  3923. {
  3924. $newmode = false;
  3925. switch (strtoupper($mode))
  3926. {
  3927. case 'LTR' :
  3928. case 'L' :
  3929. {
  3930. if ($this->rtl)
  3931. {
  3932. $newmode = 'L';
  3933. }
  3934. break;
  3935. }
  3936. case 'RTL' :
  3937. case 'R' :
  3938. {
  3939. if (! $this->rtl)
  3940. {
  3941. $newmode = 'R';
  3942. }
  3943. break;
  3944. }
  3945. case false :
  3946. default :
  3947. {
  3948. $newmode = false;
  3949. break;
  3950. }
  3951. }
  3952. $this->tmprtl = $newmode;
  3953. }
  3954. /**
  3955. * Return the current temporary RTL status
  3956. * @return boolean
  3957. * @access public
  3958. * @since 4.8.014 (2009-11-04)
  3959. */
  3960. public function isRTLTextDir()
  3961. {
  3962. return ($this->rtl or ($this->tmprtl == 'R'));
  3963. }
  3964. /**
  3965. * Set the last cell height.
  3966. * @param float $h cell height.
  3967. * @author Nicola Asuni
  3968. * @access public
  3969. * @since 1.53.0.TC034
  3970. */
  3971. public function setLastH($h)
  3972. {
  3973. $this->lasth = $h;
  3974. }
  3975. /**
  3976. * Reset the last cell height.
  3977. * @access public
  3978. * @since 5.9.000 (2010-10-03)
  3979. */
  3980. public function resetLastH()
  3981. {
  3982. $this->lasth = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  3983. }
  3984. /**
  3985. * Get the last cell height.
  3986. * @return last cell height
  3987. * @access public
  3988. * @since 4.0.017 (2008-08-05)
  3989. */
  3990. public function getLastH()
  3991. {
  3992. return $this->lasth;
  3993. }
  3994. /**
  3995. * Set the adjusting factor to convert pixels to user units.
  3996. * @param float $scale adjusting factor to convert pixels to user units.
  3997. * @author Nicola Asuni
  3998. * @access public
  3999. * @since 1.5.2
  4000. */
  4001. public function setImageScale($scale)
  4002. {
  4003. $this->imgscale = $scale;
  4004. }
  4005. /**
  4006. * Returns the adjusting factor to convert pixels to user units.
  4007. * @return float adjusting factor to convert pixels to user units.
  4008. * @author Nicola Asuni
  4009. * @access public
  4010. * @since 1.5.2
  4011. */
  4012. public function getImageScale()
  4013. {
  4014. return $this->imgscale;
  4015. }
  4016. /**
  4017. * Returns an array of page dimensions:
  4018. * <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>
  4019. * @param int $pagenum page number (empty = current page)
  4020. * @return array of page dimensions.
  4021. * @author Nicola Asuni
  4022. * @access public
  4023. * @since 4.5.027 (2009-03-16)
  4024. */
  4025. public function getPageDimensions($pagenum = '')
  4026. {
  4027. if (empty($pagenum))
  4028. {
  4029. $pagenum = $this->page;
  4030. }
  4031. return $this->pagedim[$pagenum];
  4032. }
  4033. /**
  4034. * Returns the page width in units.
  4035. * @param int $pagenum page number (empty = current page)
  4036. * @return int page width.
  4037. * @author Nicola Asuni
  4038. * @access public
  4039. * @since 1.5.2
  4040. * @see getPageDimensions()
  4041. */
  4042. public function getPageWidth($pagenum = '')
  4043. {
  4044. if (empty($pagenum))
  4045. {
  4046. return $this->w;
  4047. }
  4048. return $this->pagedim[$pagenum]['w'];
  4049. }
  4050. /**
  4051. * Returns the page height in units.
  4052. * @param int $pagenum page number (empty = current page)
  4053. * @return int page height.
  4054. * @author Nicola Asuni
  4055. * @access public
  4056. * @since 1.5.2
  4057. * @see getPageDimensions()
  4058. */
  4059. public function getPageHeight($pagenum = '')
  4060. {
  4061. if (empty($pagenum))
  4062. {
  4063. return $this->h;
  4064. }
  4065. return $this->pagedim[$pagenum]['h'];
  4066. }
  4067. /**
  4068. * Returns the page break margin.
  4069. * @param int $pagenum page number (empty = current page)
  4070. * @return int page break margin.
  4071. * @author Nicola Asuni
  4072. * @access public
  4073. * @since 1.5.2
  4074. * @see getPageDimensions()
  4075. */
  4076. public function getBreakMargin($pagenum = '')
  4077. {
  4078. if (empty($pagenum))
  4079. {
  4080. return $this->bMargin;
  4081. }
  4082. return $this->pagedim[$pagenum]['bm'];
  4083. }
  4084. /**
  4085. * Returns the scale factor (number of points in user unit).
  4086. * @return int scale factor.
  4087. * @author Nicola Asuni
  4088. * @access public
  4089. * @since 1.5.2
  4090. */
  4091. public function getScaleFactor()
  4092. {
  4093. return $this->k;
  4094. }
  4095. /**
  4096. * Defines the left, top and right margins.
  4097. * @param float $left Left margin.
  4098. * @param float $top Top margin.
  4099. * @param float $right Right margin. Default value is the left one.
  4100. * @param boolean $keepmargins if true overwrites the default page margins
  4101. * @access public
  4102. * @since 1.0
  4103. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  4104. */
  4105. public function SetMargins($left, $top, $right = -1, $keepmargins = false)
  4106. {
  4107. //Set left, top and right margins
  4108. $this->lMargin = $left;
  4109. $this->tMargin = $top;
  4110. if ($right == - 1)
  4111. {
  4112. $right = $left;
  4113. }
  4114. $this->rMargin = $right;
  4115. if ($keepmargins)
  4116. {
  4117. // overwrite original values
  4118. $this->original_lMargin = $this->lMargin;
  4119. $this->original_rMargin = $this->rMargin;
  4120. }
  4121. }
  4122. /**
  4123. * 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.
  4124. * @param float $margin The margin.
  4125. * @access public
  4126. * @since 1.4
  4127. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  4128. */
  4129. public function SetLeftMargin($margin)
  4130. {
  4131. //Set left margin
  4132. $this->lMargin = $margin;
  4133. if (($this->page > 0) and ($this->x < $margin))
  4134. {
  4135. $this->x = $margin;
  4136. }
  4137. }
  4138. /**
  4139. * Defines the top margin. The method can be called before creating the first page.
  4140. * @param float $margin The margin.
  4141. * @access public
  4142. * @since 1.5
  4143. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  4144. */
  4145. public function SetTopMargin($margin)
  4146. {
  4147. //Set top margin
  4148. $this->tMargin = $margin;
  4149. if (($this->page > 0) and ($this->y < $margin))
  4150. {
  4151. $this->y = $margin;
  4152. }
  4153. }
  4154. /**
  4155. * Defines the right margin. The method can be called before creating the first page.
  4156. * @param float $margin The margin.
  4157. * @access public
  4158. * @since 1.5
  4159. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  4160. */
  4161. public function SetRightMargin($margin)
  4162. {
  4163. $this->rMargin = $margin;
  4164. if (($this->page > 0) and ($this->x > ($this->w - $margin)))
  4165. {
  4166. $this->x = $this->w - $margin;
  4167. }
  4168. }
  4169. /**
  4170. * Set the same internal Cell padding for top, right, bottom, left-
  4171. * @param float $pad internal padding.
  4172. * @access public
  4173. * @since 2.1.000 (2008-01-09)
  4174. * @see getCellPaddings(), setCellPaddings()
  4175. */
  4176. public function SetCellPadding($pad)
  4177. {
  4178. if ($pad >= 0)
  4179. {
  4180. $this->cell_padding['L'] = $pad;
  4181. $this->cell_padding['T'] = $pad;
  4182. $this->cell_padding['R'] = $pad;
  4183. $this->cell_padding['B'] = $pad;
  4184. }
  4185. }
  4186. /**
  4187. * Set the internal Cell paddings.
  4188. * @param float $left left padding
  4189. * @param float $top top padding
  4190. * @param float $right right padding
  4191. * @param float $bottom bottom padding
  4192. * @access public
  4193. * @since 5.9.000 (2010-10-03)
  4194. * @see getCellPaddings(), SetCellPadding()
  4195. */
  4196. public function setCellPaddings($left = '', $top = '', $right = '', $bottom = '')
  4197. {
  4198. if (($left !== '') and ($left >= 0))
  4199. {
  4200. $this->cell_padding['L'] = $left;
  4201. }
  4202. if (($top !== '') and ($top >= 0))
  4203. {
  4204. $this->cell_padding['T'] = $top;
  4205. }
  4206. if (($right !== '') and ($right >= 0))
  4207. {
  4208. $this->cell_padding['R'] = $right;
  4209. }
  4210. if (($bottom !== '') and ($bottom >= 0))
  4211. {
  4212. $this->cell_padding['B'] = $bottom;
  4213. }
  4214. }
  4215. /**
  4216. * Get the internal Cell padding array.
  4217. * @return array of padding values
  4218. * @access public
  4219. * @since 5.9.000 (2010-10-03)
  4220. * @see setCellPaddings(), SetCellPadding()
  4221. */
  4222. public function getCellPaddings()
  4223. {
  4224. return $this->cell_padding;
  4225. }
  4226. /**
  4227. * Set the internal Cell margins.
  4228. * @param float $left left margin
  4229. * @param float $top top margin
  4230. * @param float $right right margin
  4231. * @param float $bottom bottom margin
  4232. * @access public
  4233. * @since 5.9.000 (2010-10-03)
  4234. * @see getCellMargins()
  4235. */
  4236. public function setCellMargins($left = '', $top = '', $right = '', $bottom = '')
  4237. {
  4238. if (($left !== '') and ($left >= 0))
  4239. {
  4240. $this->cell_margin['L'] = $left;
  4241. }
  4242. if (($top !== '') and ($top >= 0))
  4243. {
  4244. $this->cell_margin['T'] = $top;
  4245. }
  4246. if (($right !== '') and ($right >= 0))
  4247. {
  4248. $this->cell_margin['R'] = $right;
  4249. }
  4250. if (($bottom !== '') and ($bottom >= 0))
  4251. {
  4252. $this->cell_margin['B'] = $bottom;
  4253. }
  4254. }
  4255. /**
  4256. * Get the internal Cell margin array.
  4257. * @return array of margin values
  4258. * @access public
  4259. * @since 5.9.000 (2010-10-03)
  4260. * @see setCellMargins()
  4261. */
  4262. public function getCellMargins()
  4263. {
  4264. return $this->cell_margin;
  4265. }
  4266. /**
  4267. * Adjust the internal Cell padding array to take account of the line width.
  4268. * @param mixed $brd Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  4269. * @return array of adjustments
  4270. * @access public
  4271. * @since 5.9.000 (2010-10-03)
  4272. */
  4273. protected function adjustCellPadding($brd = 0)
  4274. {
  4275. if (empty($brd))
  4276. {
  4277. return;
  4278. }
  4279. if (is_string($brd))
  4280. {
  4281. // convert string to array
  4282. $slen = strlen($brd);
  4283. $newbrd = array();
  4284. for($i = 0; $i < $slen; ++ $i)
  4285. {
  4286. $newbrd[$brd{$i}] = true;
  4287. }
  4288. $brd = $newbrd;
  4289. }
  4290. elseif (($brd === 1) or ($brd === true) or (is_numeric($brd) and (intval($brd) > 0)))
  4291. {
  4292. $brd = array('LRTB' => true);
  4293. }
  4294. if (! is_array($brd))
  4295. {
  4296. return;
  4297. }
  4298. // store current cell padding
  4299. $cp = $this->cell_padding;
  4300. // select border mode
  4301. if (isset($brd['mode']))
  4302. {
  4303. $mode = $brd['mode'];
  4304. unset($brd['mode']);
  4305. }
  4306. else
  4307. {
  4308. $mode = 'normal';
  4309. }
  4310. // process borders
  4311. foreach ($brd as $border => $style)
  4312. {
  4313. $line_width = $this->LineWidth;
  4314. if (is_array($style) and isset($style['width']))
  4315. {
  4316. // get border width
  4317. $line_width = $style['width'];
  4318. }
  4319. $adj = 0; // line width inside the cell
  4320. switch ($mode)
  4321. {
  4322. case 'ext' :
  4323. {
  4324. $adj = 0;
  4325. break;
  4326. }
  4327. case 'int' :
  4328. {
  4329. $adj = $line_width;
  4330. break;
  4331. }
  4332. case 'normal' :
  4333. default :
  4334. {
  4335. $adj = ($line_width / 2);
  4336. break;
  4337. }
  4338. }
  4339. // correct internal cell padding if required to avoid overlap between text and lines
  4340. if ((strpos($border, 'T') !== false) and ($this->cell_padding['T'] < $adj))
  4341. {
  4342. $this->cell_padding['T'] = $adj;
  4343. }
  4344. if ((strpos($border, 'R') !== false) and ($this->cell_padding['R'] < $adj))
  4345. {
  4346. $this->cell_padding['R'] = $adj;
  4347. }
  4348. if ((strpos($border, 'B') !== false) and ($this->cell_padding['B'] < $adj))
  4349. {
  4350. $this->cell_padding['B'] = $adj;
  4351. }
  4352. if ((strpos($border, 'L') !== false) and ($this->cell_padding['L'] < $adj))
  4353. {
  4354. $this->cell_padding['L'] = $adj;
  4355. }
  4356. }
  4357. return array('T' => ($this->cell_padding['T'] - $cp['T']), 'R' => ($this->cell_padding['R'] - $cp['R']),
  4358. 'B' => ($this->cell_padding['B'] - $cp['B']), 'L' => ($this->cell_padding['L'] - $cp['L']));
  4359. }
  4360. /**
  4361. * 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.
  4362. * @param boolean $auto Boolean indicating if mode should be on or off.
  4363. * @param float $margin Distance from the bottom of the page.
  4364. * @access public
  4365. * @since 1.0
  4366. * @see Cell(), MultiCell(), AcceptPageBreak()
  4367. */
  4368. public function SetAutoPageBreak($auto, $margin = 0)
  4369. {
  4370. //Set auto page break mode and triggering margin
  4371. $this->AutoPageBreak = $auto;
  4372. $this->bMargin = $margin;
  4373. $this->PageBreakTrigger = $this->h - $margin;
  4374. }
  4375. /**
  4376. * Defines the way the document is to be displayed by the viewer.
  4377. * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  4378. * @param string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  4379. * @param string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  4380. * @access public
  4381. * @since 1.2
  4382. */
  4383. public function SetDisplayMode($zoom, $layout = 'SinglePage', $mode = 'UseNone')
  4384. {
  4385. //Set display mode in viewer
  4386. if (($zoom == 'fullpage') or ($zoom == 'fullwidth') or ($zoom == 'real') or ($zoom == 'default') or (! is_string($zoom)))
  4387. {
  4388. $this->ZoomMode = $zoom;
  4389. }
  4390. else
  4391. {
  4392. $this->Error('Incorrect zoom display mode: ' . $zoom);
  4393. }
  4394. switch ($layout)
  4395. {
  4396. case 'default' :
  4397. case 'single' :
  4398. case 'SinglePage' :
  4399. {
  4400. $this->LayoutMode = 'SinglePage';
  4401. break;
  4402. }
  4403. case 'continuous' :
  4404. case 'OneColumn' :
  4405. {
  4406. $this->LayoutMode = 'OneColumn';
  4407. break;
  4408. }
  4409. case 'two' :
  4410. case 'TwoColumnLeft' :
  4411. {
  4412. $this->LayoutMode = 'TwoColumnLeft';
  4413. break;
  4414. }
  4415. case 'TwoColumnRight' :
  4416. {
  4417. $this->LayoutMode = 'TwoColumnRight';
  4418. break;
  4419. }
  4420. case 'TwoPageLeft' :
  4421. {
  4422. $this->LayoutMode = 'TwoPageLeft';
  4423. break;
  4424. }
  4425. case 'TwoPageRight' :
  4426. {
  4427. $this->LayoutMode = 'TwoPageRight';
  4428. break;
  4429. }
  4430. default :
  4431. {
  4432. $this->LayoutMode = 'SinglePage';
  4433. }
  4434. }
  4435. switch ($mode)
  4436. {
  4437. case 'UseNone' :
  4438. {
  4439. $this->PageMode = 'UseNone';
  4440. break;
  4441. }
  4442. case 'UseOutlines' :
  4443. {
  4444. $this->PageMode = 'UseOutlines';
  4445. break;
  4446. }
  4447. case 'UseThumbs' :
  4448. {
  4449. $this->PageMode = 'UseThumbs';
  4450. break;
  4451. }
  4452. case 'FullScreen' :
  4453. {
  4454. $this->PageMode = 'FullScreen';
  4455. break;
  4456. }
  4457. case 'UseOC' :
  4458. {
  4459. $this->PageMode = 'UseOC';
  4460. break;
  4461. }
  4462. case '' :
  4463. {
  4464. $this->PageMode = 'UseAttachments';
  4465. break;
  4466. }
  4467. default :
  4468. {
  4469. $this->PageMode = 'UseNone';
  4470. }
  4471. }
  4472. }
  4473. /**
  4474. * 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.
  4475. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  4476. * @param boolean $compress Boolean indicating if compression must be enabled.
  4477. * @access public
  4478. * @since 1.4
  4479. */
  4480. public function SetCompression($compress)
  4481. {
  4482. //Set page compression
  4483. if (function_exists('gzcompress'))
  4484. {
  4485. $this->compress = $compress ? true : false;
  4486. }
  4487. else
  4488. {
  4489. $this->compress = false;
  4490. }
  4491. }
  4492. /**
  4493. * Defines the title of the document.
  4494. * @param string $title The title.
  4495. * @access public
  4496. * @since 1.2
  4497. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  4498. */
  4499. public function SetTitle($title)
  4500. {
  4501. //Title of document
  4502. $this->title = $title;
  4503. }
  4504. /**
  4505. * Defines the subject of the document.
  4506. * @param string $subject The subject.
  4507. * @access public
  4508. * @since 1.2
  4509. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  4510. */
  4511. public function SetSubject($subject)
  4512. {
  4513. //Subject of document
  4514. $this->subject = $subject;
  4515. }
  4516. /**
  4517. * Defines the author of the document.
  4518. * @param string $author The name of the author.
  4519. * @access public
  4520. * @since 1.2
  4521. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  4522. */
  4523. public function SetAuthor($author)
  4524. {
  4525. //Author of document
  4526. $this->author = $author;
  4527. }
  4528. /**
  4529. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  4530. * @param string $keywords The list of keywords.
  4531. * @access public
  4532. * @since 1.2
  4533. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  4534. */
  4535. public function SetKeywords($keywords)
  4536. {
  4537. //Keywords of document
  4538. $this->keywords = $keywords;
  4539. }
  4540. /**
  4541. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  4542. * @param string $creator The name of the creator.
  4543. * @access public
  4544. * @since 1.2
  4545. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  4546. */
  4547. public function SetCreator($creator)
  4548. {
  4549. //Creator of document
  4550. $this->creator = $creator;
  4551. }
  4552. /**
  4553. * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
  4554. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  4555. * @param string $msg The error message
  4556. * @access public
  4557. * @since 1.0
  4558. */
  4559. public function Error($msg)
  4560. {
  4561. // unset all class variables
  4562. $this->_destroy(true);
  4563. // exit program and print error
  4564. die('<strong>TCPDF ERROR: </strong>' . $msg);
  4565. }
  4566. /**
  4567. * This method begins the generation of the PDF document.
  4568. * It is not necessary to call it explicitly because AddPage() does it automatically.
  4569. * Note: no page is created by this method
  4570. * @access public
  4571. * @since 1.0
  4572. * @see AddPage(), Close()
  4573. */
  4574. public function Open()
  4575. {
  4576. //Begin document
  4577. $this->state = 1;
  4578. }
  4579. /**
  4580. * Terminates the PDF document.
  4581. * It is not necessary to call this method explicitly because Output() does it automatically.
  4582. * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  4583. * @access public
  4584. * @since 1.0
  4585. * @see Open(), Output()
  4586. */
  4587. public function Close()
  4588. {
  4589. if ($this->state == 3)
  4590. {
  4591. return;
  4592. }
  4593. if ($this->page == 0)
  4594. {
  4595. $this->AddPage();
  4596. }
  4597. // save current graphic settings
  4598. $gvars = $this->getGraphicVars();
  4599. $this->lastpage(true);
  4600. $this->SetAutoPageBreak(false);
  4601. $this->x = 0;
  4602. $this->y = $this->h - (1 / $this->k);
  4603. $this->lMargin = 0;
  4604. $this->_out('q');
  4605. $this->setVisibility('screen');
  4606. $this->SetFont('helvetica', '', 1);
  4607. $this->SetTextColor(255, 255, 255);
  4608. $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";
  4609. $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
  4610. $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
  4611. $this->setVisibility('all');
  4612. $this->_out('Q');
  4613. // restore graphic settings
  4614. $this->setGraphicVars($gvars);
  4615. // close page
  4616. $this->endPage();
  4617. // close document
  4618. $this->_enddoc();
  4619. // unset all class variables (except critical ones)
  4620. $this->_destroy(false);
  4621. }
  4622. /**
  4623. * Move pointer at the specified document page and update page dimensions.
  4624. * @param int $pnum page number (1 ... numpages)
  4625. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  4626. * @access public
  4627. * @since 2.1.000 (2008-01-07)
  4628. * @see getPage(), lastpage(), getNumPages()
  4629. */
  4630. public function setPage($pnum, $resetmargins = false)
  4631. {
  4632. if (($pnum == $this->page) and ($this->state == 2))
  4633. {
  4634. return;
  4635. }
  4636. if (($pnum > 0) and ($pnum <= $this->numpages))
  4637. {
  4638. $this->state = 2;
  4639. // save current graphic settings
  4640. //$gvars = $this->getGraphicVars();
  4641. $oldpage = $this->page;
  4642. $this->page = $pnum;
  4643. $this->wPt = $this->pagedim[$this->page]['w'];
  4644. $this->hPt = $this->pagedim[$this->page]['h'];
  4645. $this->w = $this->pagedim[$this->page]['wk'];
  4646. $this->h = $this->pagedim[$this->page]['hk'];
  4647. $this->tMargin = $this->pagedim[$this->page]['tm'];
  4648. $this->bMargin = $this->pagedim[$this->page]['bm'];
  4649. $this->original_lMargin = $this->pagedim[$this->page]['olm'];
  4650. $this->original_rMargin = $this->pagedim[$this->page]['orm'];
  4651. $this->AutoPageBreak = $this->pagedim[$this->page]['pb'];
  4652. $this->CurOrientation = $this->pagedim[$this->page]['or'];
  4653. $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
  4654. // restore graphic settings
  4655. //$this->setGraphicVars($gvars);
  4656. if ($resetmargins)
  4657. {
  4658. $this->lMargin = $this->pagedim[$this->page]['olm'];
  4659. $this->rMargin = $this->pagedim[$this->page]['orm'];
  4660. $this->SetY($this->tMargin);
  4661. }
  4662. else
  4663. {
  4664. // account for booklet mode
  4665. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm'])
  4666. {
  4667. $deltam = $this->pagedim[$this->page]['olm'] - $this->pagedim[$this->page]['orm'];
  4668. $this->lMargin += $deltam;
  4669. $this->rMargin -= $deltam;
  4670. }
  4671. }
  4672. }
  4673. else
  4674. {
  4675. $this->Error('Wrong page number on setPage() function: ' . $pnum);
  4676. }
  4677. }
  4678. /**
  4679. * Reset pointer to the last document page.
  4680. * @param boolean $resetmargins if true reset left, right, top margins and Y position.
  4681. * @access public
  4682. * @since 2.0.000 (2008-01-04)
  4683. * @see setPage(), getPage(), getNumPages()
  4684. */
  4685. public function lastPage($resetmargins = false)
  4686. {
  4687. $this->setPage($this->getNumPages(), $resetmargins);
  4688. }
  4689. /**
  4690. * Get current document page number.
  4691. * @return int page number
  4692. * @access public
  4693. * @since 2.1.000 (2008-01-07)
  4694. * @see setPage(), lastpage(), getNumPages()
  4695. */
  4696. public function getPage()
  4697. {
  4698. return $this->page;
  4699. }
  4700. /**
  4701. * Get the total number of insered pages.
  4702. * @return int number of pages
  4703. * @access public
  4704. * @since 2.1.000 (2008-01-07)
  4705. * @see setPage(), getPage(), lastpage()
  4706. */
  4707. public function getNumPages()
  4708. {
  4709. return $this->numpages;
  4710. }
  4711. /**
  4712. * Adds a new TOC (Table Of Content) page to the document.
  4713. * @param string $orientation page orientation.
  4714. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  4715. * @access public
  4716. * @since 5.0.001 (2010-05-06)
  4717. * @see AddPage(), startPage(), endPage(), endTOCPage()
  4718. */
  4719. public function addTOCPage($orientation = '', $format = '', $keepmargins = false)
  4720. {
  4721. $this->AddPage($orientation, $format, $keepmargins, true);
  4722. }
  4723. /**
  4724. * Terminate the current TOC (Table Of Content) page
  4725. * @access public
  4726. * @since 5.0.001 (2010-05-06)
  4727. * @see AddPage(), startPage(), endPage(), addTOCPage()
  4728. */
  4729. public function endTOCPage()
  4730. {
  4731. $this->endPage(true);
  4732. }
  4733. /**
  4734. * 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).
  4735. * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
  4736. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  4737. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4738. * @param boolean $keepmargins if true overwrites the default page margins with the current margins
  4739. * @param boolean $tocpage if true set the tocpage state to true (the added page will be used to display Table Of Content).
  4740. * @access public
  4741. * @since 1.0
  4742. * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  4743. */
  4744. public function AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
  4745. {
  4746. if ($this->inxobj)
  4747. {
  4748. // we are inside an XObject template
  4749. return;
  4750. }
  4751. if (! isset($this->original_lMargin) or $keepmargins)
  4752. {
  4753. $this->original_lMargin = $this->lMargin;
  4754. }
  4755. if (! isset($this->original_rMargin) or $keepmargins)
  4756. {
  4757. $this->original_rMargin = $this->rMargin;
  4758. }
  4759. // terminate previous page
  4760. $this->endPage();
  4761. // start new page
  4762. $this->startPage($orientation, $format, $tocpage);
  4763. }
  4764. /**
  4765. * Terminate the current page
  4766. * @param boolean $tocpage if true set the tocpage state to false (end the page used to display Table Of Content).
  4767. * @access public
  4768. * @since 4.2.010 (2008-11-14)
  4769. * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
  4770. */
  4771. public function endPage($tocpage = false)
  4772. {
  4773. // check if page is already closed
  4774. if (($this->page == 0) or ($this->numpages > $this->page) or (! $this->pageopen[$this->page]))
  4775. {
  4776. return;
  4777. }
  4778. $this->InFooter = true;
  4779. // print page footer
  4780. $this->setFooter();
  4781. // close page
  4782. $this->_endpage();
  4783. // mark page as closed
  4784. $this->pageopen[$this->page] = false;
  4785. $this->InFooter = false;
  4786. if ($tocpage)
  4787. {
  4788. $this->tocpage = false;
  4789. }
  4790. }
  4791. /**
  4792. * Starts a new page to the document. The page must be closed using the endPage() function.
  4793. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  4794. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  4795. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  4796. * @access public
  4797. * @since 4.2.010 (2008-11-14)
  4798. * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
  4799. */
  4800. public function startPage($orientation = '', $format = '', $tocpage = false)
  4801. {
  4802. if ($tocpage)
  4803. {
  4804. $this->tocpage = true;
  4805. }
  4806. if ($this->numpages > $this->page)
  4807. {
  4808. // this page has been already added
  4809. $this->setPage($this->page + 1);
  4810. $this->SetY($this->tMargin);
  4811. return;
  4812. }
  4813. // start a new page
  4814. if ($this->state == 0)
  4815. {
  4816. $this->Open();
  4817. }
  4818. ++ $this->numpages;
  4819. $this->swapMargins($this->booklet);
  4820. // save current graphic settings
  4821. $gvars = $this->getGraphicVars();
  4822. // start new page
  4823. $this->_beginpage($orientation, $format);
  4824. // mark page as open
  4825. $this->pageopen[$this->page] = true;
  4826. // restore graphic settings
  4827. $this->setGraphicVars($gvars);
  4828. // mark this point
  4829. $this->setPageMark();
  4830. // print page header
  4831. $this->setHeader();
  4832. // restore graphic settings
  4833. $this->setGraphicVars($gvars);
  4834. // mark this point
  4835. $this->setPageMark();
  4836. // print table header (if any)
  4837. $this->setTableHeader();
  4838. // set mark for empty page check
  4839. $this->emptypagemrk[$this->page] = $this->pagelen[$this->page];
  4840. }
  4841. /**
  4842. * Set start-writing mark on current page stream used to put borders and fills.
  4843. * Borders and fills are always created after content and inserted on the position marked by this method.
  4844. * This function must be called after calling Image() function for a background image.
  4845. * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
  4846. * @access public
  4847. * @since 4.0.016 (2008-07-30)
  4848. */
  4849. public function setPageMark()
  4850. {
  4851. $this->intmrk[$this->page] = $this->pagelen[$this->page];
  4852. $this->bordermrk[$this->page] = $this->intmrk[$this->page];
  4853. $this->setContentMark();
  4854. }
  4855. /**
  4856. * Set start-writing mark on selected page.
  4857. * Borders and fills are always created after content and inserted on the position marked by this method.
  4858. * @param int $page page number (default is the current page)
  4859. * @access protected
  4860. * @since 4.6.021 (2009-07-20)
  4861. */
  4862. protected function setContentMark($page = 0)
  4863. {
  4864. if ($page <= 0)
  4865. {
  4866. $page = $this->page;
  4867. }
  4868. if (isset($this->footerlen[$page]))
  4869. {
  4870. $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
  4871. }
  4872. else
  4873. {
  4874. $this->cntmrk[$page] = $this->pagelen[$page];
  4875. }
  4876. }
  4877. /**
  4878. * Set header data.
  4879. * @param string $ln header image logo
  4880. * @param string $lw header image logo width in mm
  4881. * @param string $ht string to print as title on document header
  4882. * @param string $hs string to print on document header
  4883. * @access public
  4884. */
  4885. public function setHeaderData($ln = '', $lw = 0, $ht = '', $hs = '')
  4886. {
  4887. $this->header_logo = $ln;
  4888. $this->header_logo_width = $lw;
  4889. $this->header_title = $ht;
  4890. $this->header_string = $hs;
  4891. }
  4892. /**
  4893. * Returns header data:
  4894. * <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>
  4895. * @return array()
  4896. * @access public
  4897. * @since 4.0.012 (2008-07-24)
  4898. */
  4899. public function getHeaderData()
  4900. {
  4901. $ret = array();
  4902. $ret['logo'] = $this->header_logo;
  4903. $ret['logo_width'] = $this->header_logo_width;
  4904. $ret['title'] = $this->header_title;
  4905. $ret['string'] = $this->header_string;
  4906. return $ret;
  4907. }
  4908. /**
  4909. * Set header margin.
  4910. * (minimum distance between header and top page margin)
  4911. * @param int $hm distance in user units
  4912. * @access public
  4913. */
  4914. public function setHeaderMargin($hm = 10)
  4915. {
  4916. $this->header_margin = $hm;
  4917. }
  4918. /**
  4919. * Returns header margin in user units.
  4920. * @return float
  4921. * @since 4.0.012 (2008-07-24)
  4922. * @access public
  4923. */
  4924. public function getHeaderMargin()
  4925. {
  4926. return $this->header_margin;
  4927. }
  4928. /**
  4929. * Set footer margin.
  4930. * (minimum distance between footer and bottom page margin)
  4931. * @param int $fm distance in user units
  4932. * @access public
  4933. */
  4934. public function setFooterMargin($fm = 10)
  4935. {
  4936. $this->footer_margin = $fm;
  4937. }
  4938. /**
  4939. * Returns footer margin in user units.
  4940. * @return float
  4941. * @since 4.0.012 (2008-07-24)
  4942. * @access public
  4943. */
  4944. public function getFooterMargin()
  4945. {
  4946. return $this->footer_margin;
  4947. }
  4948. /**
  4949. * Set a flag to print page header.
  4950. * @param boolean $val set to true to print the page header (default), false otherwise.
  4951. * @access public
  4952. */
  4953. public function setPrintHeader($val = true)
  4954. {
  4955. $this->print_header = $val;
  4956. }
  4957. /**
  4958. * Set a flag to print page footer.
  4959. * @param boolean $value set to true to print the page footer (default), false otherwise.
  4960. * @access public
  4961. */
  4962. public function setPrintFooter($val = true)
  4963. {
  4964. $this->print_footer = $val;
  4965. }
  4966. /**
  4967. * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
  4968. * @return float
  4969. * @access public
  4970. */
  4971. public function getImageRBX()
  4972. {
  4973. return $this->img_rb_x;
  4974. }
  4975. /**
  4976. * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
  4977. * @return float
  4978. * @access public
  4979. */
  4980. public function getImageRBY()
  4981. {
  4982. return $this->img_rb_y;
  4983. }
  4984. /**
  4985. * This method is used to render the page header.
  4986. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  4987. * @access public
  4988. */
  4989. public function Header()
  4990. {
  4991. $ormargins = $this->getOriginalMargins();
  4992. $headerfont = $this->getHeaderFont();
  4993. $headerdata = $this->getHeaderData();
  4994. if (($headerdata['logo']) and ($headerdata['logo'] != K_BLANK_IMAGE))
  4995. {
  4996. $this->Image(K_PATH_IMAGES . $headerdata['logo'], '', '', $headerdata['logo_width']);
  4997. $imgy = $this->getImageRBY();
  4998. }
  4999. else
  5000. {
  5001. $imgy = $this->GetY();
  5002. }
  5003. $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
  5004. // set starting margin for text data cell
  5005. if ($this->getRTL())
  5006. {
  5007. $header_x = $ormargins['right'] + ($headerdata['logo_width'] * 1.1);
  5008. }
  5009. else
  5010. {
  5011. $header_x = $ormargins['left'] + ($headerdata['logo_width'] * 1.1);
  5012. }
  5013. $this->SetTextColor(0, 0, 0);
  5014. // header title
  5015. $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
  5016. $this->SetX($header_x);
  5017. $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
  5018. // header string
  5019. $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  5020. $this->SetX($header_x);
  5021. $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
  5022. // print an ending header line
  5023. $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt',
  5024. 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  5025. $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
  5026. if ($this->getRTL())
  5027. {
  5028. $this->SetX($ormargins['right']);
  5029. }
  5030. else
  5031. {
  5032. $this->SetX($ormargins['left']);
  5033. }
  5034. $this->Cell(0, 0, '', 'T', 0, 'C');
  5035. }
  5036. /**
  5037. * This method is used to render the page footer.
  5038. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  5039. * @access public
  5040. */
  5041. public function Footer()
  5042. {
  5043. $cur_y = $this->GetY();
  5044. $ormargins = $this->getOriginalMargins();
  5045. $this->SetTextColor(0, 0, 0);
  5046. //set style for cell border
  5047. $line_width = 0.85 / $this->getScaleFactor();
  5048. $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0,
  5049. 'color' => array(0, 0, 0)));
  5050. //print document barcode
  5051. $barcode = $this->getBarcode();
  5052. if (! empty($barcode))
  5053. {
  5054. $this->Ln($line_width);
  5055. $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3);
  5056. $style = array('position' => $this->rtl ? 'R' : 'L', 'align' => $this->rtl ? 'R' : 'L', 'stretch' => false,
  5057. 'fitwidth' => true, 'cellfitalign' => '', 'border' => false, 'padding' => 0,
  5058. 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'text' => false);
  5059. $this->write1DBarcode($barcode, 'C128B', '', $cur_y + $line_width, '', (($this->getFooterMargin() / 3) - $line_width), 0.3, $style, '');
  5060. }
  5061. if (empty($this->pagegroups))
  5062. {
  5063. $pagenumtxt = $this->l['w_page'] . ' ' . $this->getAliasNumPage() . ' / ' . $this->getAliasNbPages();
  5064. }
  5065. else
  5066. {
  5067. $pagenumtxt = $this->l['w_page'] . ' ' . $this->getPageNumGroupAlias() . ' / ' . $this->getPageGroupAlias();
  5068. }
  5069. $this->SetY($cur_y);
  5070. //Print page number
  5071. if ($this->getRTL())
  5072. {
  5073. $this->SetX($ormargins['right']);
  5074. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
  5075. }
  5076. else
  5077. {
  5078. $this->SetX($ormargins['left']);
  5079. $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
  5080. }
  5081. }
  5082. /**
  5083. * This method is used to render the page header.
  5084. * @access protected
  5085. * @since 4.0.012 (2008-07-24)
  5086. */
  5087. protected function setHeader()
  5088. {
  5089. if ($this->print_header)
  5090. {
  5091. $this->setGraphicVars($this->default_graphic_vars);
  5092. $temp_thead = $this->thead;
  5093. $temp_theadMargins = $this->theadMargins;
  5094. $lasth = $this->lasth;
  5095. $this->_out('q');
  5096. $this->rMargin = $this->original_rMargin;
  5097. $this->lMargin = $this->original_lMargin;
  5098. $this->SetCellPadding(0);
  5099. //set current position
  5100. if ($this->rtl)
  5101. {
  5102. $this->SetXY($this->original_rMargin, $this->header_margin);
  5103. }
  5104. else
  5105. {
  5106. $this->SetXY($this->original_lMargin, $this->header_margin);
  5107. }
  5108. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  5109. $this->Header();
  5110. //restore position
  5111. if ($this->rtl)
  5112. {
  5113. $this->SetXY($this->original_rMargin, $this->tMargin);
  5114. }
  5115. else
  5116. {
  5117. $this->SetXY($this->original_lMargin, $this->tMargin);
  5118. }
  5119. $this->_out('Q');
  5120. $this->lasth = $lasth;
  5121. $this->thead = $temp_thead;
  5122. $this->theadMargins = $temp_theadMargins;
  5123. $this->newline = false;
  5124. }
  5125. }
  5126. /**
  5127. * This method is used to render the page footer.
  5128. * @access protected
  5129. * @since 4.0.012 (2008-07-24)
  5130. */
  5131. protected function setFooter()
  5132. {
  5133. //Page footer
  5134. // save current graphic settings
  5135. $gvars = $this->getGraphicVars();
  5136. // mark this point
  5137. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  5138. $this->_out("\n");
  5139. if ($this->print_footer)
  5140. {
  5141. $this->setGraphicVars($this->default_graphic_vars);
  5142. $this->current_column = 0;
  5143. $this->num_columns = 1;
  5144. $temp_thead = $this->thead;
  5145. $temp_theadMargins = $this->theadMargins;
  5146. $lasth = $this->lasth;
  5147. $this->_out('q');
  5148. $this->rMargin = $this->original_rMargin;
  5149. $this->lMargin = $this->original_lMargin;
  5150. $this->SetCellPadding(0);
  5151. //set current position
  5152. $footer_y = $this->h - $this->footer_margin;
  5153. if ($this->rtl)
  5154. {
  5155. $this->SetXY($this->original_rMargin, $footer_y);
  5156. }
  5157. else
  5158. {
  5159. $this->SetXY($this->original_lMargin, $footer_y);
  5160. }
  5161. $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
  5162. $this->Footer();
  5163. //restore position
  5164. if ($this->rtl)
  5165. {
  5166. $this->SetXY($this->original_rMargin, $this->tMargin);
  5167. }
  5168. else
  5169. {
  5170. $this->SetXY($this->original_lMargin, $this->tMargin);
  5171. }
  5172. $this->_out('Q');
  5173. $this->lasth = $lasth;
  5174. $this->thead = $temp_thead;
  5175. $this->theadMargins = $temp_theadMargins;
  5176. }
  5177. // restore graphic settings
  5178. $this->setGraphicVars($gvars);
  5179. $this->current_column = $gvars['current_column'];
  5180. $this->num_columns = $gvars['num_columns'];
  5181. // calculate footer length
  5182. $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
  5183. }
  5184. /**
  5185. * This method is used to render the table header on new page (if any).
  5186. * @access protected
  5187. * @since 4.5.030 (2009-03-25)
  5188. */
  5189. protected function setTableHeader()
  5190. {
  5191. if ($this->num_columns > 1)
  5192. {
  5193. // multi column mode
  5194. return;
  5195. }
  5196. if (isset($this->theadMargins['top']))
  5197. {
  5198. // restore the original top-margin
  5199. $this->tMargin = $this->theadMargins['top'];
  5200. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  5201. $this->y = $this->tMargin;
  5202. }
  5203. if (! $this->empty_string($this->thead) and (! $this->inthead))
  5204. {
  5205. // set margins
  5206. $prev_lMargin = $this->lMargin;
  5207. $prev_rMargin = $this->rMargin;
  5208. $prev_cell_padding = $this->cell_padding;
  5209. $this->lMargin = $this->theadMargins['lmargin'] + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$this->theadMargins['page']]['olm']);
  5210. $this->rMargin = $this->theadMargins['rmargin'] + ($this->pagedim[$this->page]['orm'] - $this->pagedim[$this->theadMargins['page']]['orm']);
  5211. $this->cell_padding = $this->theadMargins['cell_padding'];
  5212. if ($this->rtl)
  5213. {
  5214. $this->x = $this->w - $this->rMargin;
  5215. }
  5216. else
  5217. {
  5218. $this->x = $this->lMargin;
  5219. }
  5220. // print table header
  5221. $this->writeHTML($this->thead, false, false, false, false, '');
  5222. // set new top margin to skip the table headers
  5223. if (! isset($this->theadMargins['top']))
  5224. {
  5225. $this->theadMargins['top'] = $this->tMargin;
  5226. }
  5227. $this->tMargin = $this->y;
  5228. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  5229. $this->lasth = 0;
  5230. $this->lMargin = $prev_lMargin;
  5231. $this->rMargin = $prev_rMargin;
  5232. $this->cell_padding = $prev_cell_padding;
  5233. }
  5234. }
  5235. /**
  5236. * Returns the current page number.
  5237. * @return int page number
  5238. * @access public
  5239. * @since 1.0
  5240. * @see AliasNbPages(), getAliasNbPages()
  5241. */
  5242. public function PageNo()
  5243. {
  5244. return $this->page;
  5245. }
  5246. /**
  5247. * Defines a new spot color.
  5248. * It can be expressed in RGB components or gray scale.
  5249. * The method can be called before the first page is created and the value is retained from page to page.
  5250. * @param int $c Cyan color for CMYK. Value between 0 and 255
  5251. * @param int $m Magenta color for CMYK. Value between 0 and 255
  5252. * @param int $y Yellow color for CMYK. Value between 0 and 255
  5253. * @param int $k Key (Black) color for CMYK. Value between 0 and 255
  5254. * @access public
  5255. * @since 4.0.024 (2008-09-12)
  5256. * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  5257. */
  5258. public function AddSpotColor($name, $c, $m, $y, $k)
  5259. {
  5260. if (! isset($this->spot_colors[$name]))
  5261. {
  5262. $i = 1 + count($this->spot_colors);
  5263. $this->spot_colors[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
  5264. }
  5265. }
  5266. /**
  5267. * Defines the color used for all drawing operations (lines, rectangles and cell borders).
  5268. * It can be expressed in RGB components or gray scale.
  5269. * The method can be called before the first page is created and the value is retained from page to page.
  5270. * @param array $color array of colors
  5271. * @param boolean $ret if true do not send the command.
  5272. * @return string the PDF command
  5273. * @access public
  5274. * @since 3.1.000 (2008-06-11)
  5275. * @see SetDrawColor()
  5276. */
  5277. public function SetDrawColorArray($color, $ret = false)
  5278. {
  5279. if (is_array($color))
  5280. {
  5281. $color = array_values($color);
  5282. $r = isset($color[0]) ? $color[0] : - 1;
  5283. $g = isset($color[1]) ? $color[1] : - 1;
  5284. $b = isset($color[2]) ? $color[2] : - 1;
  5285. $k = isset($color[3]) ? $color[3] : - 1;
  5286. if ($r >= 0)
  5287. {
  5288. return $this->SetDrawColor($r, $g, $b, $k, $ret);
  5289. }
  5290. }
  5291. return '';
  5292. }
  5293. /**
  5294. * 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.
  5295. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  5296. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  5297. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  5298. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  5299. * @param boolean $ret if true do not send the command.
  5300. * @return string the PDF command
  5301. * @access public
  5302. * @since 1.3
  5303. * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  5304. */
  5305. public function SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false)
  5306. {
  5307. // set default values
  5308. if (! is_numeric($col1))
  5309. {
  5310. $col1 = 0;
  5311. }
  5312. if (! is_numeric($col2))
  5313. {
  5314. $col2 = - 1;
  5315. }
  5316. if (! is_numeric($col3))
  5317. {
  5318. $col3 = - 1;
  5319. }
  5320. if (! is_numeric($col4))
  5321. {
  5322. $col4 = - 1;
  5323. }
  5324. //Set color for all stroking operations
  5325. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  5326. {
  5327. // Grey scale
  5328. $this->DrawColor = sprintf('%.3F G', $col1 / 255);
  5329. $this->strokecolor = array('G' => $col1);
  5330. }
  5331. elseif ($col4 == - 1)
  5332. {
  5333. // RGB
  5334. $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $col1 / 255, $col2 / 255, $col3 / 255);
  5335. $this->strokecolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5336. }
  5337. else
  5338. {
  5339. // CMYK
  5340. $this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  5341. $this->strokecolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5342. }
  5343. if ($this->page > 0)
  5344. {
  5345. if (! $ret)
  5346. {
  5347. $this->_out($this->DrawColor);
  5348. }
  5349. return $this->DrawColor;
  5350. }
  5351. return '';
  5352. }
  5353. /**
  5354. * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
  5355. * @param string $name name of the spot color
  5356. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5357. * @access public
  5358. * @since 4.0.024 (2008-09-12)
  5359. * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
  5360. */
  5361. public function SetDrawSpotColor($name, $tint = 100)
  5362. {
  5363. if (! isset($this->spot_colors[$name]))
  5364. {
  5365. $this->Error('Undefined spot color: ' . $name);
  5366. }
  5367. $this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->spot_colors[$name]['i'], $tint / 100);
  5368. if ($this->page > 0)
  5369. {
  5370. $this->_out($this->DrawColor);
  5371. }
  5372. }
  5373. /**
  5374. * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
  5375. * It can be expressed in RGB components or gray scale.
  5376. * The method can be called before the first page is created and the value is retained from page to page.
  5377. * @param array $color array of colors
  5378. * @access public
  5379. * @since 3.1.000 (2008-6-11)
  5380. * @see SetFillColor()
  5381. */
  5382. public function SetFillColorArray($color)
  5383. {
  5384. if (is_array($color))
  5385. {
  5386. $color = array_values($color);
  5387. $r = isset($color[0]) ? $color[0] : - 1;
  5388. $g = isset($color[1]) ? $color[1] : - 1;
  5389. $b = isset($color[2]) ? $color[2] : - 1;
  5390. $k = isset($color[3]) ? $color[3] : - 1;
  5391. if ($r >= 0)
  5392. {
  5393. $this->SetFillColor($r, $g, $b, $k);
  5394. }
  5395. }
  5396. }
  5397. /**
  5398. * 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.
  5399. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  5400. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  5401. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  5402. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  5403. * @access public
  5404. * @since 1.3
  5405. * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  5406. */
  5407. public function SetFillColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  5408. {
  5409. // set default values
  5410. if (! is_numeric($col1))
  5411. {
  5412. $col1 = 0;
  5413. }
  5414. if (! is_numeric($col2))
  5415. {
  5416. $col2 = - 1;
  5417. }
  5418. if (! is_numeric($col3))
  5419. {
  5420. $col3 = - 1;
  5421. }
  5422. if (! is_numeric($col4))
  5423. {
  5424. $col4 = - 1;
  5425. }
  5426. //Set color for all filling operations
  5427. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  5428. {
  5429. // Grey scale
  5430. $this->FillColor = sprintf('%.3F g', $col1 / 255);
  5431. $this->bgcolor = array('G' => $col1);
  5432. }
  5433. elseif ($col4 == - 1)
  5434. {
  5435. // RGB
  5436. $this->FillColor = sprintf('%.3F %.3F %.3F rg', $col1 / 255, $col2 / 255, $col3 / 255);
  5437. $this->bgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5438. }
  5439. else
  5440. {
  5441. // CMYK
  5442. $this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  5443. $this->bgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5444. }
  5445. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5446. if ($this->page > 0)
  5447. {
  5448. $this->_out($this->FillColor);
  5449. }
  5450. }
  5451. /**
  5452. * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
  5453. * @param string $name name of the spot color
  5454. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5455. * @access public
  5456. * @since 4.0.024 (2008-09-12)
  5457. * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
  5458. */
  5459. public function SetFillSpotColor($name, $tint = 100)
  5460. {
  5461. if (! isset($this->spot_colors[$name]))
  5462. {
  5463. $this->Error('Undefined spot color: ' . $name);
  5464. }
  5465. $this->FillColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint / 100);
  5466. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5467. if ($this->page > 0)
  5468. {
  5469. $this->_out($this->FillColor);
  5470. }
  5471. }
  5472. /**
  5473. * Defines the color used for text. It can be expressed in RGB components or gray scale.
  5474. * The method can be called before the first page is created and the value is retained from page to page.
  5475. * @param array $color array of colors
  5476. * @access public
  5477. * @since 3.1.000 (2008-6-11)
  5478. * @see SetFillColor()
  5479. */
  5480. public function SetTextColorArray($color)
  5481. {
  5482. if (is_array($color))
  5483. {
  5484. $color = array_values($color);
  5485. $r = isset($color[0]) ? $color[0] : - 1;
  5486. $g = isset($color[1]) ? $color[1] : - 1;
  5487. $b = isset($color[2]) ? $color[2] : - 1;
  5488. $k = isset($color[3]) ? $color[3] : - 1;
  5489. if ($r >= 0)
  5490. {
  5491. $this->SetTextColor($r, $g, $b, $k);
  5492. }
  5493. }
  5494. }
  5495. /**
  5496. * 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.
  5497. * @param int $col1 Gray level for single color, or Red color for RGB, or Cyan color for CMYK. Value between 0 and 255
  5498. * @param int $col2 Green color for RGB, or Magenta color for CMYK. Value between 0 and 255
  5499. * @param int $col3 Blue color for RGB, or Yellow color for CMYK. Value between 0 and 255
  5500. * @param int $col4 Key (Black) color for CMYK. Value between 0 and 255
  5501. * @access public
  5502. * @since 1.3
  5503. * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  5504. */
  5505. public function SetTextColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1)
  5506. {
  5507. // set default values
  5508. if (! is_numeric($col1))
  5509. {
  5510. $col1 = 0;
  5511. }
  5512. if (! is_numeric($col2))
  5513. {
  5514. $col2 = - 1;
  5515. }
  5516. if (! is_numeric($col3))
  5517. {
  5518. $col3 = - 1;
  5519. }
  5520. if (! is_numeric($col4))
  5521. {
  5522. $col4 = - 1;
  5523. }
  5524. //Set color for text
  5525. if (($col2 == - 1) and ($col3 == - 1) and ($col4 == - 1))
  5526. {
  5527. // Grey scale
  5528. $this->TextColor = sprintf('%.3F g', $col1 / 255);
  5529. $this->fgcolor = array('G' => $col1);
  5530. }
  5531. elseif ($col4 == - 1)
  5532. {
  5533. // RGB
  5534. $this->TextColor = sprintf('%.3F %.3F %.3F rg', $col1 / 255, $col2 / 255, $col3 / 255);
  5535. $this->fgcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
  5536. }
  5537. else
  5538. {
  5539. // CMYK
  5540. $this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', $col1 / 100, $col2 / 100, $col3 / 100, $col4 / 100);
  5541. $this->fgcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
  5542. }
  5543. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5544. }
  5545. /**
  5546. * Defines the spot color used for text.
  5547. * @param string $name name of the spot color
  5548. * @param int $tint the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  5549. * @access public
  5550. * @since 4.0.024 (2008-09-12)
  5551. * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
  5552. */
  5553. public function SetTextSpotColor($name, $tint = 100)
  5554. {
  5555. if (! isset($this->spot_colors[$name]))
  5556. {
  5557. $this->Error('Undefined spot color: ' . $name);
  5558. }
  5559. $this->TextColor = sprintf('/CS%d cs %.3F scn', $this->spot_colors[$name]['i'], $tint / 100);
  5560. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  5561. if ($this->page > 0)
  5562. {
  5563. $this->_out($this->TextColor);
  5564. }
  5565. }
  5566. /**
  5567. * Returns the length of a string in user unit. A font must be selected.<br>
  5568. * @param string $s The string whose length is to be computed
  5569. * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  5570. * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line-trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  5571. * @param float $fontsize Font size in points. The default value is the current size.
  5572. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  5573. * @return mixed int total string length or array of characted widths
  5574. * @author Nicola Asuni
  5575. * @access public
  5576. * @since 1.2
  5577. */
  5578. public function GetStringWidth($s, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  5579. {
  5580. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize, $getarray);
  5581. }
  5582. /**
  5583. * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
  5584. * @param string $sa The array of chars whose total length is to be computed
  5585. * @param string $fontname Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
  5586. * @param string $fontstyle Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
  5587. * @param float $fontsize Font size in points. The default value is the current size.
  5588. * @param boolean $getarray if true returns an array of characters widths, if false returns the total length.
  5589. * @return mixed int total string length or array of characted widths
  5590. * @author Nicola Asuni
  5591. * @access public
  5592. * @since 2.4.000 (2008-03-06)
  5593. */
  5594. public function GetArrStringWidth($sa, $fontname = '', $fontstyle = '', $fontsize = 0, $getarray = false)
  5595. {
  5596. // store current values
  5597. if (! $this->empty_string($fontname))
  5598. {
  5599. $prev_FontFamily = $this->FontFamily;
  5600. $prev_FontStyle = $this->FontStyle;
  5601. $prev_FontSizePt = $this->FontSizePt;
  5602. $this->SetFont($fontname, $fontstyle, $fontsize);
  5603. }
  5604. // convert UTF-8 array to Latin1 if required
  5605. $sa = $this->UTF8ArrToLatin1($sa);
  5606. $w = 0; // total width
  5607. $wa = array(); // array of characters widths
  5608. foreach ($sa as $ck => $char)
  5609. {
  5610. // character width
  5611. $cw = $this->GetCharWidth($char, isset($sa[($ck + 1)]));
  5612. $wa[] = $cw;
  5613. $w += $cw;
  5614. }
  5615. // restore previous values
  5616. if (! $this->empty_string($fontname))
  5617. {
  5618. $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
  5619. }
  5620. if ($getarray)
  5621. {
  5622. return $wa;
  5623. }
  5624. return $w;
  5625. }
  5626. /**
  5627. * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking/kerning).
  5628. * @param int $char The char code whose length is to be returned
  5629. * @param boolean $notlast set to false for the latest character on string, true otherwise (default)
  5630. * @return float char width
  5631. * @author Nicola Asuni
  5632. * @access public
  5633. * @since 2.4.000 (2008-03-06)
  5634. */
  5635. public function GetCharWidth($char, $notlast = true)
  5636. {
  5637. // get raw width
  5638. $chw = $this->getRawCharWidth($char);
  5639. if (($this->font_spacing != 0) and $notlast)
  5640. {
  5641. // increase/decrease font spacing
  5642. $chw += $this->font_spacing;
  5643. }
  5644. if ($this->font_stretching != 100)
  5645. {
  5646. // fixed stretching mode
  5647. $chw *= ($this->font_stretching / 100);
  5648. }
  5649. return $chw;
  5650. }
  5651. /**
  5652. * Returns the length of the char in user unit for the current font.
  5653. * @param int $char The char code whose length is to be returned
  5654. * @return float char width
  5655. * @author Nicola Asuni
  5656. * @access public
  5657. * @since 5.9.000 (2010-09-28)
  5658. */
  5659. public function getRawCharWidth($char)
  5660. {
  5661. if ($char == 173)
  5662. {
  5663. // SHY character will not be printed
  5664. return (0);
  5665. }
  5666. $cw = &$this->CurrentFont['cw'];
  5667. if (isset($cw[$char]))
  5668. {
  5669. $w = $cw[$char];
  5670. }
  5671. elseif (isset($this->CurrentFont['dw']))
  5672. {
  5673. // default width
  5674. $w = $this->CurrentFont['dw'];
  5675. }
  5676. elseif (isset($cw[32]))
  5677. {
  5678. // default width
  5679. $w = $cw[32];
  5680. }
  5681. else
  5682. {
  5683. $w = 600;
  5684. }
  5685. return ($w * $this->FontSize / 1000);
  5686. }
  5687. /**
  5688. * Returns the numbero of characters in a string.
  5689. * @param string $s The input string.
  5690. * @return int number of characters
  5691. * @access public
  5692. * @since 2.0.0001 (2008-01-07)
  5693. */
  5694. public function GetNumChars($s)
  5695. {
  5696. if ($this->isUnicodeFont())
  5697. {
  5698. return count($this->UTF8StringToArray($s));
  5699. }
  5700. return strlen($s);
  5701. }
  5702. /**
  5703. * Fill the list of available fonts ($this->fontlist).
  5704. * @access protected
  5705. * @since 4.0.013 (2008-07-28)
  5706. */
  5707. protected function getFontsList()
  5708. {
  5709. $fontsdir = opendir($this->_getfontpath());
  5710. while (($file = readdir($fontsdir)) !== false)
  5711. {
  5712. if (substr($file, - 4) == '.php')
  5713. {
  5714. array_push($this->fontlist, strtolower(basename($file, '.php')));
  5715. }
  5716. }
  5717. closedir($fontsdir);
  5718. }
  5719. /**
  5720. * Imports a TrueType, Type1, core, or CID0 font and makes it available.
  5721. * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
  5722. * 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.
  5723. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  5724. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  5725. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  5726. * @return array containing the font data, or false in case of error.
  5727. * @param mixed $subset if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  5728. * @access public
  5729. * @since 1.5
  5730. * @see SetFont(), setFontSubsetting()
  5731. */
  5732. public function AddFont($family, $style = '', $fontfile = '', $subset = 'default')
  5733. {
  5734. if ($subset === 'default')
  5735. {
  5736. $subset = $this->font_subsetting;
  5737. }
  5738. if ($this->empty_string($family))
  5739. {
  5740. if (! $this->empty_string($this->FontFamily))
  5741. {
  5742. $family = $this->FontFamily;
  5743. }
  5744. else
  5745. {
  5746. $this->Error('Empty font family');
  5747. }
  5748. }
  5749. // move embedded styles on $style
  5750. if (substr($family, - 1) == 'I')
  5751. {
  5752. $style .= 'I';
  5753. $family = substr($family, 0, - 1);
  5754. }
  5755. if (substr($family, - 1) == 'B')
  5756. {
  5757. $style .= 'B';
  5758. $family = substr($family, 0, - 1);
  5759. }
  5760. // normalize family name
  5761. $family = strtolower($family);
  5762. if ((! $this->isunicode) and ($family == 'arial'))
  5763. {
  5764. $family = 'helvetica';
  5765. }
  5766. if (($family == 'symbol') or ($family == 'zapfdingbats'))
  5767. {
  5768. $style = '';
  5769. }
  5770. $tempstyle = strtoupper($style);
  5771. $style = '';
  5772. // underline
  5773. if (strpos($tempstyle, 'U') !== false)
  5774. {
  5775. $this->underline = true;
  5776. }
  5777. else
  5778. {
  5779. $this->underline = false;
  5780. }
  5781. // line-through (deleted)
  5782. if (strpos($tempstyle, 'D') !== false)
  5783. {
  5784. $this->linethrough = true;
  5785. }
  5786. else
  5787. {
  5788. $this->linethrough = false;
  5789. }
  5790. // overline
  5791. if (strpos($tempstyle, 'O') !== false)
  5792. {
  5793. $this->overline = true;
  5794. }
  5795. else
  5796. {
  5797. $this->overline = false;
  5798. }
  5799. // bold
  5800. if (strpos($tempstyle, 'B') !== false)
  5801. {
  5802. $style .= 'B';
  5803. }
  5804. // oblique
  5805. if (strpos($tempstyle, 'I') !== false)
  5806. {
  5807. $style .= 'I';
  5808. }
  5809. $bistyle = $style;
  5810. $fontkey = $family . $style;
  5811. $font_style = $style . ($this->underline ? 'U' : '') . ($this->linethrough ? 'D' : '') . ($this->overline ? 'O' : '');
  5812. $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
  5813. // check if the font has been already added
  5814. $fb = $this->getFontBuffer($fontkey);
  5815. if ($fb !== false)
  5816. {
  5817. if ($this->inxobj)
  5818. {
  5819. // we are inside an XObject template
  5820. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $fb['i'];
  5821. }
  5822. return $fontdata;
  5823. }
  5824. if (isset($type))
  5825. {
  5826. unset($type);
  5827. }
  5828. if (isset($cw))
  5829. {
  5830. unset($cw);
  5831. }
  5832. // get specified font directory (if any)
  5833. $fontdir = false;
  5834. if (! $this->empty_string($fontfile))
  5835. {
  5836. $fontdir = dirname($fontfile);
  5837. if ($this->empty_string($fontdir) or ($fontdir == '.'))
  5838. {
  5839. $fontdir = '';
  5840. }
  5841. else
  5842. {
  5843. $fontdir .= '/';
  5844. }
  5845. }
  5846. // search and include font file
  5847. if ($this->empty_string($fontfile) or (! file_exists($fontfile)))
  5848. {
  5849. // build a standard filenames for specified font
  5850. $fontfile1 = str_replace(' ', '', $family) . strtolower($style) . '.php';
  5851. $fontfile2 = str_replace(' ', '', $family) . '.php';
  5852. // search files on various directories
  5853. if (($fontdir !== false) and file_exists($fontdir . $fontfile1))
  5854. {
  5855. $fontfile = $fontdir . $fontfile1;
  5856. }
  5857. elseif (file_exists($this->_getfontpath() . $fontfile1))
  5858. {
  5859. $fontfile = $this->_getfontpath() . $fontfile1;
  5860. }
  5861. elseif (file_exists($fontfile1))
  5862. {
  5863. $fontfile = $fontfile1;
  5864. }
  5865. elseif (($fontdir !== false) and file_exists($fontdir . $fontfile2))
  5866. {
  5867. $fontfile = $fontdir . $fontfile2;
  5868. }
  5869. elseif (file_exists($this->_getfontpath() . $fontfile2))
  5870. {
  5871. $fontfile = $this->_getfontpath() . $fontfile2;
  5872. }
  5873. else
  5874. {
  5875. $fontfile = $fontfile2;
  5876. }
  5877. }
  5878. // include font file
  5879. if (file_exists($fontfile))
  5880. {
  5881. include ($fontfile);
  5882. }
  5883. else
  5884. {
  5885. $this->Error('Could not include font definition file: ' . $family . '');
  5886. }
  5887. // check font parameters
  5888. if ((! isset($type)) or (! isset($cw)))
  5889. {
  5890. $this->Error('The font definition file has a bad format: ' . $fontfile . '');
  5891. }
  5892. // SET default parameters
  5893. if (! isset($file) or $this->empty_string($file))
  5894. {
  5895. $file = '';
  5896. }
  5897. if (! isset($enc) or $this->empty_string($enc))
  5898. {
  5899. $enc = '';
  5900. }
  5901. if (! isset($cidinfo) or $this->empty_string($cidinfo))
  5902. {
  5903. $cidinfo = array('Registry' => 'Adobe', 'Ordering' => 'Identity', 'Supplement' => 0);
  5904. $cidinfo['uni2cid'] = array();
  5905. }
  5906. if (! isset($ctg) or $this->empty_string($ctg))
  5907. {
  5908. $ctg = '';
  5909. }
  5910. if (! isset($desc) or $this->empty_string($desc))
  5911. {
  5912. $desc = array();
  5913. }
  5914. if (! isset($up) or $this->empty_string($up))
  5915. {
  5916. $up = - 100;
  5917. }
  5918. if (! isset($ut) or $this->empty_string($ut))
  5919. {
  5920. $ut = 50;
  5921. }
  5922. if (! isset($cw) or $this->empty_string($cw))
  5923. {
  5924. $cw = array();
  5925. }
  5926. if (! isset($dw) or $this->empty_string($dw))
  5927. {
  5928. // set default width
  5929. if (isset($desc['MissingWidth']) and ($desc['MissingWidth'] > 0))
  5930. {
  5931. $dw = $desc['MissingWidth'];
  5932. }
  5933. elseif (isset($cw[32]))
  5934. {
  5935. $dw = $cw[32];
  5936. }
  5937. else
  5938. {
  5939. $dw = 600;
  5940. }
  5941. }
  5942. ++ $this->numfonts;
  5943. if ($type == 'cidfont0')
  5944. {
  5945. // register CID font (all styles at once)
  5946. $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
  5947. $sname = $name . $styles[$bistyle];
  5948. // artificial bold
  5949. if (strpos($bistyle, 'B') !== false)
  5950. {
  5951. if (isset($desc['StemV']))
  5952. {
  5953. $desc['StemV'] *= 2;
  5954. }
  5955. else
  5956. {
  5957. $desc['StemV'] = 120;
  5958. }
  5959. }
  5960. // artificial italic
  5961. if (strpos($bistyle, 'I') !== false)
  5962. {
  5963. if (isset($desc['ItalicAngle']))
  5964. {
  5965. $desc['ItalicAngle'] -= 11;
  5966. }
  5967. else
  5968. {
  5969. $desc['ItalicAngle'] = - 11;
  5970. }
  5971. }
  5972. }
  5973. elseif ($type == 'core')
  5974. {
  5975. $name = $this->CoreFonts[$fontkey];
  5976. $subset = false;
  5977. }
  5978. elseif (($type == 'TrueType') or ($type == 'Type1'))
  5979. {
  5980. $subset = false;
  5981. }
  5982. elseif ($type == 'TrueTypeUnicode')
  5983. {
  5984. $enc = 'Identity-H';
  5985. }
  5986. else
  5987. {
  5988. $this->Error('Unknow font type: ' . $type . '');
  5989. }
  5990. // initialize subsetchars to contain default ASCII values (0-255)
  5991. $subsetchars = array_fill(0, 256, true);
  5992. $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts, 'type' => $type,
  5993. 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc,
  5994. 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset,
  5995. 'subsetchars' => $subsetchars));
  5996. if ($this->inxobj)
  5997. {
  5998. // we are inside an XObject template
  5999. $this->xobjects[$this->xobjid]['fonts'][$fontkey] = $this->numfonts;
  6000. }
  6001. if (isset($diff) and (! empty($diff)))
  6002. {
  6003. //Search existing encodings
  6004. $d = 0;
  6005. $nb = count($this->diffs);
  6006. for($i = 1; $i <= $nb; ++ $i)
  6007. {
  6008. if ($this->diffs[$i] == $diff)
  6009. {
  6010. $d = $i;
  6011. break;
  6012. }
  6013. }
  6014. if ($d == 0)
  6015. {
  6016. $d = $nb + 1;
  6017. $this->diffs[$d] = $diff;
  6018. }
  6019. $this->setFontSubBuffer($fontkey, 'diff', $d);
  6020. }
  6021. if (! $this->empty_string($file))
  6022. {
  6023. if (! isset($this->FontFiles[$file]))
  6024. {
  6025. if ((strcasecmp($type, 'TrueType') == 0) or (strcasecmp($type, 'TrueTypeUnicode') == 0))
  6026. {
  6027. $this->FontFiles[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir,
  6028. 'subset' => $subset, 'fontkeys' => array($fontkey));
  6029. }
  6030. elseif ($type != 'core')
  6031. {
  6032. $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir,
  6033. 'subset' => $subset, 'fontkeys' => array($fontkey));
  6034. }
  6035. }
  6036. else
  6037. {
  6038. // update fontkeys that are sharing this font file
  6039. $this->FontFiles[$file]['subset'] = ($this->FontFiles[$file]['subset'] and $subset);
  6040. if (! in_array($fontkey, $this->FontFiles[$file]['fontkeys']))
  6041. {
  6042. $this->FontFiles[$file]['fontkeys'][] = $fontkey;
  6043. }
  6044. }
  6045. }
  6046. return $fontdata;
  6047. }
  6048. /**
  6049. * Sets the font used to print character strings.
  6050. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  6051. * The method can be called before the first page is created and the font is retained from page to page.
  6052. * If you just wish to change the current font size, it is simpler to call SetFontSize().
  6053. * 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 />
  6054. * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
  6055. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li><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.
  6056. * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  6057. * @param string $fontfile The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  6058. * @param mixed $subset if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
  6059. * @author Nicola Asuni
  6060. * @access public
  6061. * @since 1.0
  6062. * @see AddFont(), SetFontSize()
  6063. */
  6064. public function SetFont($family, $style = '', $size = 0, $fontfile = '', $subset = 'default')
  6065. {
  6066. //Select a font; size given in points
  6067. if ($size == 0)
  6068. {
  6069. $size = $this->FontSizePt;
  6070. }
  6071. // try to add font (if not already added)
  6072. $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
  6073. $this->FontFamily = $fontdata['family'];
  6074. $this->FontStyle = $fontdata['style'];
  6075. $this->CurrentFont = $this->getFontBuffer($fontdata['fontkey']);
  6076. $this->SetFontSize($size);
  6077. }
  6078. /**
  6079. * Defines the size of the current font.
  6080. * @param float $size The size (in points)
  6081. * @param boolean $out if true output the font size command, otherwise only set the font properties.
  6082. * @access public
  6083. * @since 1.0
  6084. * @see SetFont()
  6085. */
  6086. public function SetFontSize($size, $out = true)
  6087. {
  6088. // font size in points
  6089. $this->FontSizePt = $size;
  6090. // font size in user units
  6091. $this->FontSize = $size / $this->k;
  6092. // calculate some font metrics
  6093. if (isset($this->CurrentFont['desc']['FontBBox']))
  6094. {
  6095. $bbox = explode(' ', substr($this->CurrentFont['desc']['FontBBox'], 1, - 1));
  6096. $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
  6097. }
  6098. else
  6099. {
  6100. $font_height = $size * 1.219;
  6101. }
  6102. if (isset($this->CurrentFont['desc']['Ascent']) and ($this->CurrentFont['desc']['Ascent'] > 0))
  6103. {
  6104. $font_ascent = ($this->CurrentFont['desc']['Ascent'] * $size / 1000);
  6105. }
  6106. if (isset($this->CurrentFont['desc']['Descent']) and ($this->CurrentFont['desc']['Descent'] <= 0))
  6107. {
  6108. $font_descent = (- $this->CurrentFont['desc']['Descent'] * $size / 1000);
  6109. }
  6110. if (! isset($font_ascent) and ! isset($font_descent))
  6111. {
  6112. // core font
  6113. $font_ascent = 0.76 * $font_height;
  6114. $font_descent = $font_height - $font_ascent;
  6115. }
  6116. elseif (! isset($font_descent))
  6117. {
  6118. $font_descent = $font_height - $font_ascent;
  6119. }
  6120. elseif (! isset($font_ascent))
  6121. {
  6122. $font_ascent = $font_height - $font_descent;
  6123. }
  6124. $this->FontAscent = $font_ascent / $this->k;
  6125. $this->FontDescent = $font_descent / $this->k;
  6126. if ($out and ($this->page > 0) and (isset($this->CurrentFont['i'])))
  6127. {
  6128. $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  6129. }
  6130. }
  6131. /**
  6132. * Return the font descent value
  6133. * @param string $font font name
  6134. * @param string $style font style
  6135. * @param float $size The size (in points)
  6136. * @return int font descent
  6137. * @access public
  6138. * @author Nicola Asuni
  6139. * @since 4.9.003 (2010-03-30)
  6140. */
  6141. public function getFontDescent($font, $style = '', $size = 0)
  6142. {
  6143. $fontdata = $this->AddFont($font, $style);
  6144. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6145. if (isset($fontinfo['desc']['Descent']) and ($fontinfo['desc']['Descent'] <= 0))
  6146. {
  6147. $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
  6148. }
  6149. else
  6150. {
  6151. $descent = 1.219 * 0.24 * $size;
  6152. }
  6153. return ($descent / $this->k);
  6154. }
  6155. /**
  6156. * Return the font ascent value
  6157. * @param string $font font name
  6158. * @param string $style font style
  6159. * @param float $size The size (in points)
  6160. * @return int font ascent
  6161. * @access public
  6162. * @author Nicola Asuni
  6163. * @since 4.9.003 (2010-03-30)
  6164. */
  6165. public function getFontAscent($font, $style = '', $size = 0)
  6166. {
  6167. $fontdata = $this->AddFont($font, $style);
  6168. $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
  6169. if (isset($fontinfo['desc']['Ascent']) and ($fontinfo['desc']['Ascent'] > 0))
  6170. {
  6171. $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
  6172. }
  6173. else
  6174. {
  6175. $ascent = 1.219 * 0.76 * $size;
  6176. }
  6177. return ($ascent / $this->k);
  6178. }
  6179. /**
  6180. * Defines the default monospaced font.
  6181. * @param string $font Font name.
  6182. * @access public
  6183. * @since 4.5.025
  6184. */
  6185. public function SetDefaultMonospacedFont($font)
  6186. {
  6187. $this->default_monospaced_font = $font;
  6188. }
  6189. /**
  6190. * 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 />
  6191. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  6192. * @access public
  6193. * @since 1.5
  6194. * @see Cell(), Write(), Image(), Link(), SetLink()
  6195. */
  6196. public function AddLink()
  6197. {
  6198. //Create a new internal link
  6199. $n = count($this->links) + 1;
  6200. $this->links[$n] = array(0, 0);
  6201. return $n;
  6202. }
  6203. /**
  6204. * Defines the page and position a link points to.
  6205. * @param int $link The link identifier returned by AddLink()
  6206. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  6207. * @param int $page Number of target page; -1 indicates the current page. This is the default value
  6208. * @access public
  6209. * @since 1.5
  6210. * @see AddLink()
  6211. */
  6212. public function SetLink($link, $y = 0, $page = -1)
  6213. {
  6214. if ($y == - 1)
  6215. {
  6216. $y = $this->y;
  6217. }
  6218. if ($page == - 1)
  6219. {
  6220. $page = $this->page;
  6221. }
  6222. $this->links[$link] = array($page, $y);
  6223. }
  6224. /**
  6225. * Puts a link on a rectangular area of the page.
  6226. * 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.
  6227. * @param float $x Abscissa of the upper-left corner of the rectangle
  6228. * @param float $y Ordinate of the upper-left corner of the rectangle
  6229. * @param float $w Width of the rectangle
  6230. * @param float $h Height of the rectangle
  6231. * @param mixed $link URL or identifier returned by AddLink()
  6232. * @param int $spaces number of spaces on the text to link
  6233. * @access public
  6234. * @since 1.5
  6235. * @see AddLink(), Annotation(), Cell(), Write(), Image()
  6236. */
  6237. public function Link($x, $y, $w, $h, $link, $spaces = 0)
  6238. {
  6239. $this->Annotation($x, $y, $w, $h, $link, array('Subtype' => 'Link'), $spaces);
  6240. }
  6241. /**
  6242. * Puts a markup annotation on a rectangular area of the page.
  6243. * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
  6244. * @param float $x Abscissa of the upper-left corner of the rectangle
  6245. * @param float $y Ordinate of the upper-left corner of the rectangle
  6246. * @param float $w Width of the rectangle
  6247. * @param float $h Height of the rectangle
  6248. * @param string $text annotation text or alternate content
  6249. * @param array $opt array of options (see section 8.4 of PDF reference 1.7).
  6250. * @param int $spaces number of spaces on the text to link
  6251. * @access public
  6252. * @since 4.0.018 (2008-08-06)
  6253. */
  6254. public function Annotation($x, $y, $w, $h, $text, $opt = array('Subtype'=>'Text'), $spaces = 0)
  6255. {
  6256. if ($this->inxobj)
  6257. {
  6258. // store parameters for later use on template
  6259. $this->xobjects[$this->xobjid]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w,
  6260. 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
  6261. return;
  6262. }
  6263. if ($x === '')
  6264. {
  6265. $x = $this->x;
  6266. }
  6267. if ($y === '')
  6268. {
  6269. $y = $this->y;
  6270. }
  6271. // check page for no-write regions and adapt page margins if necessary
  6272. $this->checkPageRegions($h, $x, $y);
  6273. // recalculate coordinates to account for graphic transformations
  6274. if (isset($this->transfmatrix) and ! empty($this->transfmatrix))
  6275. {
  6276. for($i = $this->transfmatrix_key; $i > 0; -- $i)
  6277. {
  6278. $maxid = count($this->transfmatrix[$i]) - 1;
  6279. for($j = $maxid; $j >= 0; -- $j)
  6280. {
  6281. $ctm = $this->transfmatrix[$i][$j];
  6282. if (isset($ctm['a']))
  6283. {
  6284. $x = $x * $this->k;
  6285. $y = ($this->h - $y) * $this->k;
  6286. $w = $w * $this->k;
  6287. $h = $h * $this->k;
  6288. // top left
  6289. $xt = $x;
  6290. $yt = $y;
  6291. $x1 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6292. $y1 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6293. // top right
  6294. $xt = $x + $w;
  6295. $yt = $y;
  6296. $x2 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6297. $y2 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6298. // bottom left
  6299. $xt = $x;
  6300. $yt = $y - $h;
  6301. $x3 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6302. $y3 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6303. // bottom right
  6304. $xt = $x + $w;
  6305. $yt = $y - $h;
  6306. $x4 = ($ctm['a'] * $xt) + ($ctm['c'] * $yt) + $ctm['e'];
  6307. $y4 = ($ctm['b'] * $xt) + ($ctm['d'] * $yt) + $ctm['f'];
  6308. // new coordinates (rectangle area)
  6309. $x = min($x1, $x2, $x3, $x4);
  6310. $y = max($y1, $y2, $y3, $y4);
  6311. $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k;
  6312. $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k;
  6313. $x = $x / $this->k;
  6314. $y = $this->h - ($y / $this->k);
  6315. }
  6316. }
  6317. }
  6318. }
  6319. if ($this->page <= 0)
  6320. {
  6321. $page = 1;
  6322. }
  6323. else
  6324. {
  6325. $page = $this->page;
  6326. }
  6327. if (! isset($this->PageAnnots[$page]))
  6328. {
  6329. $this->PageAnnots[$page] = array();
  6330. }
  6331. ++ $this->n;
  6332. $this->PageAnnots[$page][] = array('n' => $this->n, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text,
  6333. 'opt' => $opt, 'numspaces' => $spaces);
  6334. if ((($opt['Subtype'] == 'FileAttachment') or ($opt['Subtype'] == 'Sound')) and (! $this->empty_string($opt['FS'])) and file_exists($opt['FS']) and (! isset($this->embeddedfiles[basename($opt['FS'])])))
  6335. {
  6336. ++ $this->n;
  6337. $this->embeddedfiles[basename($opt['FS'])] = array('n' => $this->n, 'file' => $opt['FS']);
  6338. }
  6339. // Add widgets annotation's icons
  6340. if (isset($opt['mk']['i']) and file_exists($opt['mk']['i']))
  6341. {
  6342. $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
  6343. }
  6344. if (isset($opt['mk']['ri']) and file_exists($opt['mk']['ri']))
  6345. {
  6346. $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  6347. }
  6348. if (isset($opt['mk']['ix']) and file_exists($opt['mk']['ix']))
  6349. {
  6350. $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
  6351. }
  6352. }
  6353. /**
  6354. * Embedd the attached files.
  6355. * @since 4.4.000 (2008-12-07)
  6356. * @access protected
  6357. * @see Annotation()
  6358. */
  6359. protected function _putEmbeddedFiles()
  6360. {
  6361. reset($this->embeddedfiles);
  6362. foreach ($this->embeddedfiles as $filename => $filedata)
  6363. {
  6364. $data = file_get_contents($filedata['file']);
  6365. $filter = '';
  6366. if ($this->compress)
  6367. {
  6368. $data = gzcompress($data);
  6369. $filter = ' /Filter /FlateDecode';
  6370. }
  6371. $stream = $this->_getrawstream($data, $filedata['n']);
  6372. $out = $this->_getobj($filedata['n']) . "\n";
  6373. $out .= '<< /Type /EmbeddedFile' . $filter . ' /Length ' . strlen($stream) . ' >>';
  6374. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  6375. $out .= "\n" . 'endobj';
  6376. $this->_out($out);
  6377. }
  6378. }
  6379. /**
  6380. * Prints a text cell at the specified position.
  6381. * The origin is on the left of the first charcter, on the baseline.
  6382. * This method allows to place a string precisely on the page.
  6383. * @param float $x Abscissa of the cell origin
  6384. * @param float $y Ordinate of the cell origin
  6385. * @param string $txt String to print
  6386. * @param int $fstroke outline size in user units (false = disable)
  6387. * @param boolean $fclip if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
  6388. * @param boolean $ffill if true fills the text
  6389. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6390. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6391. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6392. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  6393. * @param mixed $link URL or identifier returned by AddLink().
  6394. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6395. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  6396. * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
  6397. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  6398. * @param boolean $rtloff if true uses the page top-left corner as origin of axis for $x and $y initial position.
  6399. * @access public
  6400. * @since 1.0
  6401. * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
  6402. */
  6403. 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)
  6404. {
  6405. $textrendermode = $this->textrendermode;
  6406. $textstrokewidth = $this->textstrokewidth;
  6407. $this->setTextRenderingMode($fstroke, $ffill, $fclip);
  6408. $this->SetXY($x, $y, $rtloff);
  6409. $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
  6410. // restore previous rendering mode
  6411. $this->textrendermode = $textrendermode;
  6412. $this->textstrokewidth = $textstrokewidth;
  6413. }
  6414. /**
  6415. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
  6416. * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  6417. * This method is called automatically and should not be called directly by the application.
  6418. * @return boolean
  6419. * @access public
  6420. * @since 1.4
  6421. * @see SetAutoPageBreak()
  6422. */
  6423. public function AcceptPageBreak()
  6424. {
  6425. if ($this->num_columns > 1)
  6426. {
  6427. // multi column mode
  6428. if ($this->current_column < ($this->num_columns - 1))
  6429. {
  6430. // go to next column
  6431. $this->selectColumn($this->current_column + 1);
  6432. }
  6433. else
  6434. {
  6435. // add a new page
  6436. $this->AddPage();
  6437. // set first column
  6438. $this->selectColumn(0);
  6439. }
  6440. // avoid page breaking from checkPageBreak()
  6441. return false;
  6442. }
  6443. return $this->AutoPageBreak;
  6444. }
  6445. /**
  6446. * Add page if needed.
  6447. * @param float $h Cell height. Default value: 0.
  6448. * @param mixed $y starting y position, leave empty for current position.
  6449. * @param boolean $addpage if true add a page, otherwise only return the true/false state
  6450. * @return boolean true in case of page break, false otherwise.
  6451. * @since 3.2.000 (2008-07-01)
  6452. * @access protected
  6453. */
  6454. protected function checkPageBreak($h = 0, $y = '', $addpage = true)
  6455. {
  6456. if ($this->empty_string($y))
  6457. {
  6458. $y = $this->y;
  6459. }
  6460. $current_page = $this->page;
  6461. if ((($y + $h) > $this->PageBreakTrigger) and (! $this->InFooter) and ($this->AcceptPageBreak()))
  6462. {
  6463. if ($addpage)
  6464. {
  6465. //Automatic page break
  6466. $x = $this->x;
  6467. $this->AddPage($this->CurOrientation);
  6468. $this->y = $this->tMargin;
  6469. $oldpage = $this->page - 1;
  6470. if ($this->rtl)
  6471. {
  6472. if ($this->pagedim[$this->page]['orm'] != $this->pagedim[$oldpage]['orm'])
  6473. {
  6474. $this->x = $x - ($this->pagedim[$this->page]['orm'] - $this->pagedim[$oldpage]['orm']);
  6475. }
  6476. else
  6477. {
  6478. $this->x = $x;
  6479. }
  6480. }
  6481. else
  6482. {
  6483. if ($this->pagedim[$this->page]['olm'] != $this->pagedim[$oldpage]['olm'])
  6484. {
  6485. $this->x = $x + ($this->pagedim[$this->page]['olm'] - $this->pagedim[$oldpage]['olm']);
  6486. }
  6487. else
  6488. {
  6489. $this->x = $x;
  6490. }
  6491. }
  6492. }
  6493. $this->newline = true;
  6494. return true;
  6495. }
  6496. if ($current_page != $this->page)
  6497. {
  6498. // account for columns mode
  6499. $this->newline = true;
  6500. return true;
  6501. }
  6502. return false;
  6503. }
  6504. /**
  6505. * Removes SHY characters from text.
  6506. * Unicode Data:<ul>
  6507. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  6508. * <li>HTML Entity (decimal): &amp;#173;</li>
  6509. * <li>HTML Entity (hex): &amp;#xad;</li>
  6510. * <li>HTML Entity (named): &amp;shy;</li>
  6511. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  6512. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  6513. * <li>UTF-8 character: chr(194).chr(173)</li>
  6514. * </ul>
  6515. * @param string $txt input string
  6516. * @return string without SHY characters.
  6517. * @access public
  6518. * @since (4.5.019) 2009-02-28
  6519. */
  6520. public function removeSHY($txt = '')
  6521. {
  6522. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  6523. if (! $this->isunicode)
  6524. {
  6525. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  6526. }
  6527. return $txt;
  6528. }
  6529. /**
  6530. * 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 />
  6531. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  6532. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  6533. * @param float $h Cell height. Default value: 0.
  6534. * @param string $txt String to print. Default value: empty string.
  6535. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6536. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6537. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6538. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  6539. * @param mixed $link URL or identifier returned by AddLink().
  6540. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6541. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  6542. * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  6543. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
  6544. * @access public
  6545. * @since 1.0
  6546. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  6547. */
  6548. 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')
  6549. {
  6550. $prev_cell_margin = $this->cell_margin;
  6551. $prev_cell_padding = $this->cell_padding;
  6552. $this->adjustCellPadding($border);
  6553. if (! $ignore_min_height)
  6554. {
  6555. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  6556. if ($h < $min_cell_height)
  6557. {
  6558. $h = $min_cell_height;
  6559. }
  6560. }
  6561. $this->checkPageBreak($h + $this->cell_margin['T'] + $this->cell_margin['B']);
  6562. $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
  6563. $this->cell_padding = $prev_cell_padding;
  6564. $this->cell_margin = $prev_cell_margin;
  6565. }
  6566. /**
  6567. * 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 />
  6568. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  6569. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  6570. * @param float $h Cell height. Default value: 0.
  6571. * @param string $txt String to print. Default value: empty string.
  6572. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  6573. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  6574. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  6575. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  6576. * @param mixed $link URL or identifier returned by AddLink().
  6577. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  6578. * @param boolean $ignore_min_height if true ignore automatic minimum height value.
  6579. * @param string $calign cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
  6580. * @param string $valign text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
  6581. * @return string containing cell code
  6582. * @access protected
  6583. * @since 1.0
  6584. * @see Cell()
  6585. */
  6586. 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')
  6587. {
  6588. $prev_cell_margin = $this->cell_margin;
  6589. $prev_cell_padding = $this->cell_padding;
  6590. $txt = $this->removeSHY($txt);
  6591. $rs = ''; //string to be returned
  6592. $this->adjustCellPadding($border);
  6593. if (! $ignore_min_height)
  6594. {
  6595. $min_cell_height = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  6596. if ($h < $min_cell_height)
  6597. {
  6598. $h = $min_cell_height;
  6599. }
  6600. }
  6601. // check page for no-write regions and adapt page margins if necessary
  6602. $this->checkPageRegions($h);
  6603. $k = $this->k;
  6604. if ($this->rtl)
  6605. {
  6606. $x = $this->x - $this->cell_margin['R'];
  6607. }
  6608. else
  6609. {
  6610. $x = $this->x + $this->cell_margin['L'];
  6611. }
  6612. $y = $this->y + $this->cell_margin['T'];
  6613. $prev_font_stretching = $this->font_stretching;
  6614. $prev_font_spacing = $this->font_spacing;
  6615. // cell vertical alignment
  6616. switch ($calign)
  6617. {
  6618. case 'A' :
  6619. {
  6620. // font top
  6621. switch ($valign)
  6622. {
  6623. case 'T' :
  6624. {
  6625. // top
  6626. $y -= $this->cell_padding['T'];
  6627. break;
  6628. }
  6629. case 'B' :
  6630. {
  6631. // bottom
  6632. $y -= ($h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent);
  6633. break;
  6634. }
  6635. default :
  6636. case 'C' :
  6637. case 'M' :
  6638. {
  6639. // center
  6640. $y -= (($h - $this->FontAscent - $this->FontDescent) / 2);
  6641. break;
  6642. }
  6643. }
  6644. break;
  6645. }
  6646. case 'L' :
  6647. {
  6648. // font baseline
  6649. switch ($valign)
  6650. {
  6651. case 'T' :
  6652. {
  6653. // top
  6654. $y -= ($this->cell_padding['T'] + $this->FontAscent);
  6655. break;
  6656. }
  6657. case 'B' :
  6658. {
  6659. // bottom
  6660. $y -= ($h - $this->cell_padding['B'] - $this->FontDescent);
  6661. break;
  6662. }
  6663. default :
  6664. case 'C' :
  6665. case 'M' :
  6666. {
  6667. // center
  6668. $y -= (($h + $this->FontAscent - $this->FontDescent) / 2);
  6669. break;
  6670. }
  6671. }
  6672. break;
  6673. }
  6674. case 'D' :
  6675. {
  6676. // font bottom
  6677. switch ($valign)
  6678. {
  6679. case 'T' :
  6680. {
  6681. // top
  6682. $y -= ($this->cell_padding['T'] + $this->FontAscent + $this->FontDescent);
  6683. break;
  6684. }
  6685. case 'B' :
  6686. {
  6687. // bottom
  6688. $y -= ($h - $this->cell_padding['B']);
  6689. break;
  6690. }
  6691. default :
  6692. case 'C' :
  6693. case 'M' :
  6694. {
  6695. // center
  6696. $y -= (($h + $this->FontAscent + $this->FontDescent) / 2);
  6697. break;
  6698. }
  6699. }
  6700. break;
  6701. }
  6702. case 'B' :
  6703. {
  6704. // cell bottom
  6705. $y -= $h;
  6706. break;
  6707. }
  6708. case 'C' :
  6709. case 'M' :
  6710. {
  6711. // cell center
  6712. $y -= ($h / 2);
  6713. break;
  6714. }
  6715. default :
  6716. case 'T' :
  6717. {
  6718. // cell top
  6719. break;
  6720. }
  6721. }
  6722. // text vertical alignment
  6723. switch ($valign)
  6724. {
  6725. case 'T' :
  6726. {
  6727. // top
  6728. $yt = $y + $this->cell_padding['T'];
  6729. break;
  6730. }
  6731. case 'B' :
  6732. {
  6733. // bottom
  6734. $yt = $y + $h - $this->cell_padding['B'] - $this->FontAscent - $this->FontDescent;
  6735. break;
  6736. }
  6737. default :
  6738. case 'C' :
  6739. case 'M' :
  6740. {
  6741. // center
  6742. $yt = $y + (($h - $this->FontAscent - $this->FontDescent) / 2);
  6743. break;
  6744. }
  6745. }
  6746. $basefonty = $yt + $this->FontAscent;
  6747. if ($this->empty_string($w) or ($w <= 0))
  6748. {
  6749. if ($this->rtl)
  6750. {
  6751. $w = $x - $this->lMargin;
  6752. }
  6753. else
  6754. {
  6755. $w = $this->w - $this->rMargin - $x;
  6756. }
  6757. }
  6758. $s = '';
  6759. // fill and borders
  6760. if (is_string($border) and (strlen($border) == 4))
  6761. {
  6762. // full border
  6763. $border = 1;
  6764. }
  6765. if ($fill or ($border == 1))
  6766. {
  6767. if ($fill)
  6768. {
  6769. $op = ($border == 1) ? 'B' : 'f';
  6770. }
  6771. else
  6772. {
  6773. $op = 'S';
  6774. }
  6775. if ($this->rtl)
  6776. {
  6777. $xk = (($x - $w) * $k);
  6778. }
  6779. else
  6780. {
  6781. $xk = ($x * $k);
  6782. }
  6783. $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $y) * $k), ($w * $k), (- $h * $k), $op);
  6784. }
  6785. // draw borders
  6786. $s .= $this->getCellBorder($x, $y, $w, $h, $border);
  6787. if ($txt != '')
  6788. {
  6789. $txt2 = $txt;
  6790. if ($this->isunicode)
  6791. {
  6792. if (($this->CurrentFont['type'] == 'core') or ($this->CurrentFont['type'] == 'TrueType') or ($this->CurrentFont['type'] == 'Type1'))
  6793. {
  6794. $txt2 = $this->UTF8ToLatin1($txt2);
  6795. }
  6796. else
  6797. {
  6798. $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
  6799. $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl);
  6800. if (defined('K_THAI_TOPCHARS') and (K_THAI_TOPCHARS == true))
  6801. {
  6802. // ---- Fix for bug #2977340 "Incorrect Thai characters position arrangement" ----
  6803. // NOTE: this doesn't work with HTML justification
  6804. // Symbols that could overlap on the font top (only works in LTR)
  6805. $topchar = array(3611,
  6806. 3613, 3615, 3650, 3651, 3652); // chars that extends on top
  6807. $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658,
  6808. 3659, 3660, 3661, 3662); // symbols with top position
  6809. $numchars = count($unicode); // number of chars
  6810. $unik = 0;
  6811. $uniblock = array();
  6812. $uniblock[$unik] = array();
  6813. $uniblock[$unik][] = $unicode[0];
  6814. // resolve overlapping conflicts by splitting the string in several parts
  6815. for($i = 1; $i < $numchars; ++ $i)
  6816. {
  6817. // check if symbols overlaps at top
  6818. if (in_array($unicode[$i], $topsym) and (in_array($unicode[($i - 1)], $topsym) or in_array($unicode[($i - 1)], $topchar)))
  6819. {
  6820. // move symbols to another array
  6821. ++ $unik;
  6822. $uniblock[$unik] = array();
  6823. $uniblock[$unik][] = $unicode[$i];
  6824. ++ $unik;
  6825. $uniblock[$unik] = array();
  6826. $unicode[$i] = 0x200b; // Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  6827. }
  6828. else
  6829. {
  6830. $uniblock[$unik][] = $unicode[$i];
  6831. }
  6832. }
  6833. // ---- END OF Fix for bug #2977340
  6834. }
  6835. $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
  6836. }
  6837. }
  6838. $txt2 = $this->_escape($txt2);
  6839. // get current text width (considering general font stretching and spacing)
  6840. $txwidth = $this->GetStringWidth($txt);
  6841. $width = $txwidth;
  6842. // check for stretch mode
  6843. if ($stretch > 0)
  6844. {
  6845. // calculate ratio between cell width and text width
  6846. if ($width <= 0)
  6847. {
  6848. $ratio = 1;
  6849. }
  6850. else
  6851. {
  6852. $ratio = (($w - $this->cell_padding['L'] - $this->cell_padding['R']) / $width);
  6853. }
  6854. // check if stretching is required
  6855. if (($ratio < 1) or (($ratio > 1) and (($stretch % 2) == 0)))
  6856. {
  6857. // the text will be stretched to fit cell width
  6858. if ($stretch > 2)
  6859. {
  6860. // set new character spacing
  6861. $this->font_spacing += ($w - $this->cell_padding['L'] - $this->cell_padding['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching / 100));
  6862. }
  6863. else
  6864. {
  6865. // set new horizontal stretching
  6866. $this->font_stretching *= $ratio;
  6867. }
  6868. // recalculate text width (the text fills the entire cell)
  6869. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6870. // reset alignment
  6871. $align = '';
  6872. }
  6873. }
  6874. if ($this->font_stretching != 100)
  6875. {
  6876. // apply font stretching
  6877. $rs .= sprintf('BT %.2F Tz ET ', $this->font_stretching);
  6878. }
  6879. if ($this->font_spacing != 0)
  6880. {
  6881. // increase/decrease font spacing
  6882. $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing * $this->k));
  6883. }
  6884. if ($this->ColorFlag)
  6885. {
  6886. $s .= 'q ' . $this->TextColor . ' ';
  6887. }
  6888. // rendering mode
  6889. $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode, $this->textstrokewidth);
  6890. // count number of spaces
  6891. $ns = substr_count($txt, chr(32));
  6892. // Justification
  6893. $spacewidth = 0;
  6894. if (($align == 'J') and ($ns > 0))
  6895. {
  6896. if ($this->isUnicodeFont())
  6897. {
  6898. // get string width without spaces
  6899. $width = $this->GetStringWidth(str_replace(' ', '', $txt));
  6900. // calculate average space width
  6901. $spacewidth = - 1000 * ($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1) / $this->FontSize;
  6902. if ($this->font_stretching != 100)
  6903. {
  6904. // word spacing is affected by stretching
  6905. $spacewidth /= ($this->font_stretching / 100);
  6906. }
  6907. // set word position to be used with TJ operator
  6908. $txt2 = str_replace(chr(0) . chr(32), ') ' . sprintf('%.3F', $spacewidth) . ' (', $txt2);
  6909. $unicode_justification = true;
  6910. }
  6911. else
  6912. {
  6913. // get string width
  6914. $width = $txwidth;
  6915. // new space width
  6916. $spacewidth = (($w - $width - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1)) * $this->k;
  6917. if ($this->font_stretching != 100)
  6918. {
  6919. // word spacing (Tw) is affected by stretching
  6920. $spacewidth /= ($this->font_stretching / 100);
  6921. }
  6922. // set word spacing
  6923. $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
  6924. }
  6925. $width = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  6926. }
  6927. // replace carriage return characters
  6928. $txt2 = str_replace("\r", ' ', $txt2);
  6929. switch ($align)
  6930. {
  6931. case 'C' :
  6932. {
  6933. $dx = ($w - $width) / 2;
  6934. break;
  6935. }
  6936. case 'R' :
  6937. {
  6938. if ($this->rtl)
  6939. {
  6940. $dx = $this->cell_padding['R'];
  6941. }
  6942. else
  6943. {
  6944. $dx = $w - $width - $this->cell_padding['R'];
  6945. }
  6946. break;
  6947. }
  6948. case 'L' :
  6949. {
  6950. if ($this->rtl)
  6951. {
  6952. $dx = $w - $width - $this->cell_padding['L'];
  6953. }
  6954. else
  6955. {
  6956. $dx = $this->cell_padding['L'];
  6957. }
  6958. break;
  6959. }
  6960. case 'J' :
  6961. default :
  6962. {
  6963. if ($this->rtl)
  6964. {
  6965. $dx = $this->cell_padding['R'];
  6966. }
  6967. else
  6968. {
  6969. $dx = $this->cell_padding['L'];
  6970. }
  6971. break;
  6972. }
  6973. }
  6974. if ($this->rtl)
  6975. {
  6976. $xdx = $x - $dx - $width;
  6977. }
  6978. else
  6979. {
  6980. $xdx = $x + $dx;
  6981. }
  6982. $xdk = $xdx * $k;
  6983. // print text
  6984. $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
  6985. if (isset($uniblock))
  6986. {
  6987. // print overlapping characters as separate string
  6988. $xshift = 0; // horizontal shift
  6989. $ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
  6990. $spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns ? $ns : 1));
  6991. foreach ($uniblock as $uk => $uniarr)
  6992. {
  6993. if (($uk % 2) == 0)
  6994. {
  6995. // x space to skip
  6996. if ($spacewidth != 0)
  6997. {
  6998. // justification shift
  6999. $xshift += (count(array_keys($uniarr, 32)) * $spw);
  7000. }
  7001. $xshift += $this->GetArrStringWidth($uniarr); // + shift justification
  7002. }
  7003. else
  7004. {
  7005. // character to print
  7006. $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
  7007. $topchr = $this->_escape($topchr);
  7008. $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk + ($xshift * $k)), $ty, $topchr);
  7009. }
  7010. }
  7011. }
  7012. if ($this->underline)
  7013. {
  7014. $s .= ' ' . $this->_dounderlinew($xdx, $basefonty, $width);
  7015. }
  7016. if ($this->linethrough)
  7017. {
  7018. $s .= ' ' . $this->_dolinethroughw($xdx, $basefonty, $width);
  7019. }
  7020. if ($this->overline)
  7021. {
  7022. $s .= ' ' . $this->_dooverlinew($xdx, $basefonty, $width);
  7023. }
  7024. if ($this->ColorFlag)
  7025. {
  7026. $s .= ' Q';
  7027. }
  7028. if ($link)
  7029. {
  7030. $this->Link($xdx, $yt, $width, ($this->FontAscent + $this->FontDescent), $link, $ns);
  7031. }
  7032. }
  7033. // output cell
  7034. if ($s)
  7035. {
  7036. // output cell
  7037. $rs .= $s;
  7038. if ($this->font_spacing != 0)
  7039. {
  7040. // reset font spacing mode
  7041. $rs .= ' BT 0 Tc ET';
  7042. }
  7043. if ($this->font_stretching != 100)
  7044. {
  7045. // reset font stretching mode
  7046. $rs .= ' BT 100 Tz ET';
  7047. }
  7048. }
  7049. // reset word spacing
  7050. if (! $this->isUnicodeFont() and ($align == 'J'))
  7051. {
  7052. $rs .= ' BT 0 Tw ET';
  7053. }
  7054. // reset stretching and spacing
  7055. $this->font_stretching = $prev_font_stretching;
  7056. $this->font_spacing = $prev_font_spacing;
  7057. $this->lasth = $h;
  7058. if ($ln > 0)
  7059. {
  7060. //Go to the beginning of the next line
  7061. $this->y = $y + $h + $this->cell_margin['B'];
  7062. if ($ln == 1)
  7063. {
  7064. if ($this->rtl)
  7065. {
  7066. $this->x = $this->w - $this->rMargin;
  7067. }
  7068. else
  7069. {
  7070. $this->x = $this->lMargin;
  7071. }
  7072. }
  7073. }
  7074. else
  7075. {
  7076. // go left or right by case
  7077. if ($this->rtl)
  7078. {
  7079. $this->x = $x - $w - $this->cell_margin['L'];
  7080. }
  7081. else
  7082. {
  7083. $this->x = $x + $w + $this->cell_margin['R'];
  7084. }
  7085. }
  7086. $gstyles = '' . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ' . $this->FillColor . "\n";
  7087. $rs = $gstyles . $rs;
  7088. $this->cell_padding = $prev_cell_padding;
  7089. $this->cell_margin = $prev_cell_margin;
  7090. return $rs;
  7091. }
  7092. /**
  7093. * Returns the code to draw the cell border
  7094. * @param float $x X coordinate.
  7095. * @param float $y Y coordinate.
  7096. * @param float $w Cell width.
  7097. * @param float $h Cell height.
  7098. * @param mixed $brd Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7099. * @param string $mode border position respect the square edge: normal: centered; ext: external; int: internal;
  7100. * @return string containing cell border code
  7101. * @access protected
  7102. * @see SetLineStyle()
  7103. * @since 5.7.000 (2010-08-02)
  7104. */
  7105. protected function getCellBorder($x, $y, $w, $h, $brd)
  7106. {
  7107. $s = ''; // string to be returned
  7108. if (empty($brd))
  7109. {
  7110. return $s;
  7111. }
  7112. if ($brd == 1)
  7113. {
  7114. $brd = array('LRTB' => true);
  7115. }
  7116. // calculate coordinates for border
  7117. $k = $this->k;
  7118. if ($this->rtl)
  7119. {
  7120. $xeL = ($x - $w) * $k;
  7121. $xeR = $x * $k;
  7122. }
  7123. else
  7124. {
  7125. $xeL = $x * $k;
  7126. $xeR = ($x + $w) * $k;
  7127. }
  7128. $yeL = (($this->h - ($y + $h)) * $k);
  7129. $yeT = (($this->h - $y) * $k);
  7130. $xeT = $xeL;
  7131. $xeB = $xeR;
  7132. $yeR = $yeT;
  7133. $yeB = $yeL;
  7134. if (is_string($brd))
  7135. {
  7136. // convert string to array
  7137. $slen = strlen($brd);
  7138. $newbrd = array();
  7139. for($i = 0; $i < $slen; ++ $i)
  7140. {
  7141. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  7142. }
  7143. $brd = $newbrd;
  7144. }
  7145. if (isset($brd['mode']))
  7146. {
  7147. $mode = $brd['mode'];
  7148. unset($brd['mode']);
  7149. }
  7150. else
  7151. {
  7152. $mode = 'normal';
  7153. }
  7154. foreach ($brd as $border => $style)
  7155. {
  7156. if (is_array($style) and ! empty($style))
  7157. {
  7158. // apply border style
  7159. $prev_style = $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ';
  7160. $s .= $this->SetLineStyle($style, true) . "\n";
  7161. }
  7162. switch ($mode)
  7163. {
  7164. case 'ext' :
  7165. {
  7166. $off = (($this->LineWidth / 2) * $k);
  7167. $xL = $xeL - $off;
  7168. $xR = $xeR + $off;
  7169. $yT = $yeT + $off;
  7170. $yL = $yeL - $off;
  7171. $xT = $xL;
  7172. $xB = $xR;
  7173. $yR = $yT;
  7174. $yB = $yL;
  7175. $w += $this->LineWidth;
  7176. $h += $this->LineWidth;
  7177. break;
  7178. }
  7179. case 'int' :
  7180. {
  7181. $off = ($this->LineWidth / 2) * $k;
  7182. $xL = $xeL + $off;
  7183. $xR = $xeR - $off;
  7184. $yT = $yeT - $off;
  7185. $yL = $yeL + $off;
  7186. $xT = $xL;
  7187. $xB = $xR;
  7188. $yR = $yT;
  7189. $yB = $yL;
  7190. $w -= $this->LineWidth;
  7191. $h -= $this->LineWidth;
  7192. break;
  7193. }
  7194. case 'normal' :
  7195. default :
  7196. {
  7197. $xL = $xeL;
  7198. $xT = $xeT;
  7199. $xB = $xeB;
  7200. $xR = $xeR;
  7201. $yL = $yeL;
  7202. $yT = $yeT;
  7203. $yB = $yeB;
  7204. $yR = $yeR;
  7205. break;
  7206. }
  7207. }
  7208. // draw borders by case
  7209. if (strlen($border) == 4)
  7210. {
  7211. $s .= sprintf('%.2F %.2F %.2F %.2F re S ', $xT, $yT, ($w * $k), (- $h * $k));
  7212. }
  7213. elseif (strlen($border) == 3)
  7214. {
  7215. if (strpos($border, 'B') === false)
  7216. { // LTR
  7217. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7218. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7219. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7220. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7221. $s .= 'S ';
  7222. }
  7223. elseif (strpos($border, 'L') === false)
  7224. { // TRB
  7225. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7226. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7227. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7228. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7229. $s .= 'S ';
  7230. }
  7231. elseif (strpos($border, 'T') === false)
  7232. { // RBL
  7233. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7234. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7235. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7236. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7237. $s .= 'S ';
  7238. }
  7239. elseif (strpos($border, 'R') === false)
  7240. { // BLT
  7241. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7242. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7243. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7244. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7245. $s .= 'S ';
  7246. }
  7247. }
  7248. elseif (strlen($border) == 2)
  7249. {
  7250. if ((strpos($border, 'L') !== false) and (strpos($border, 'T') !== false))
  7251. { // LT
  7252. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7253. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7254. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7255. $s .= 'S ';
  7256. }
  7257. elseif ((strpos($border, 'T') !== false) and (strpos($border, 'R') !== false))
  7258. { // TR
  7259. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7260. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7261. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7262. $s .= 'S ';
  7263. }
  7264. elseif ((strpos($border, 'R') !== false) and (strpos($border, 'B') !== false))
  7265. { // RB
  7266. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7267. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7268. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7269. $s .= 'S ';
  7270. }
  7271. elseif ((strpos($border, 'B') !== false) and (strpos($border, 'L') !== false))
  7272. { // BL
  7273. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7274. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7275. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7276. $s .= 'S ';
  7277. }
  7278. elseif ((strpos($border, 'L') !== false) and (strpos($border, 'R') !== false))
  7279. { // LR
  7280. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7281. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7282. $s .= 'S ';
  7283. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7284. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7285. $s .= 'S ';
  7286. }
  7287. elseif ((strpos($border, 'T') !== false) and (strpos($border, 'B') !== false))
  7288. { // TB
  7289. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7290. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7291. $s .= 'S ';
  7292. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7293. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7294. $s .= 'S ';
  7295. }
  7296. }
  7297. else
  7298. { // strlen($border) == 1
  7299. if (strpos($border, 'L') !== false)
  7300. { // L
  7301. $s .= sprintf('%.2F %.2F m ', $xL, $yL);
  7302. $s .= sprintf('%.2F %.2F l ', $xT, $yT);
  7303. $s .= 'S ';
  7304. }
  7305. elseif (strpos($border, 'T') !== false)
  7306. { // T
  7307. $s .= sprintf('%.2F %.2F m ', $xT, $yT);
  7308. $s .= sprintf('%.2F %.2F l ', $xR, $yR);
  7309. $s .= 'S ';
  7310. }
  7311. elseif (strpos($border, 'R') !== false)
  7312. { // R
  7313. $s .= sprintf('%.2F %.2F m ', $xR, $yR);
  7314. $s .= sprintf('%.2F %.2F l ', $xB, $yB);
  7315. $s .= 'S ';
  7316. }
  7317. elseif (strpos($border, 'B') !== false)
  7318. { // B
  7319. $s .= sprintf('%.2F %.2F m ', $xB, $yB);
  7320. $s .= sprintf('%.2F %.2F l ', $xL, $yL);
  7321. $s .= 'S ';
  7322. }
  7323. }
  7324. if (is_array($style) and ! empty($style))
  7325. {
  7326. // reset border style to previous value
  7327. $s .= "\n" . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . "\n";
  7328. }
  7329. }
  7330. return $s;
  7331. }
  7332. /**
  7333. * This method allows printing text with line breaks.
  7334. * 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 />
  7335. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  7336. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  7337. * @param float $h Cell minimum height. The cell extends automatically if needed.
  7338. * @param string $txt String to print
  7339. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7340. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
  7341. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  7342. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
  7343. * @param float $x x position in user units
  7344. * @param float $y y position in user units
  7345. * @param boolean $reseth if true reset the last cell height (default true).
  7346. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  7347. * @param boolean $ishtml set to true if $txt is HTML content (default = false).
  7348. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  7349. * @param float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
  7350. * @param string $valign Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false.
  7351. * @param boolean $fitcell if true attempt to fit all the text within the cell by reducing the font size.
  7352. * @return int Return the number of cells or 1 for html mode.
  7353. * @access public
  7354. * @since 1.3
  7355. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  7356. */
  7357. 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)
  7358. {
  7359. $prev_cell_margin = $this->cell_margin;
  7360. $prev_cell_padding = $this->cell_padding;
  7361. // adjust internal padding
  7362. $this->adjustCellPadding($border);
  7363. $mc_padding = $this->cell_padding;
  7364. $mc_margin = $this->cell_margin;
  7365. $this->cell_padding['T'] = 0;
  7366. $this->cell_padding['B'] = 0;
  7367. $this->setCellMargins(0, 0, 0, 0);
  7368. if ($this->empty_string($this->lasth) or $reseth)
  7369. {
  7370. // reset row height
  7371. $this->resetLastH();
  7372. }
  7373. if (! $this->empty_string($y))
  7374. {
  7375. $this->SetY($y);
  7376. }
  7377. else
  7378. {
  7379. $y = $this->GetY();
  7380. }
  7381. $resth = 0;
  7382. if ((! $this->InFooter) and (($y + $h + $mc_margin['T'] + $mc_margin['B']) > $this->PageBreakTrigger))
  7383. {
  7384. // spit cell in more pages/columns
  7385. $newh = $this->PageBreakTrigger - $y;
  7386. $resth = $h - $newh; // cell to be printed on the next page/column
  7387. $h = $newh;
  7388. }
  7389. // get current page number
  7390. $startpage = $this->page;
  7391. // get current column
  7392. $startcolumn = $this->current_column;
  7393. if (! $this->empty_string($x))
  7394. {
  7395. $this->SetX($x);
  7396. }
  7397. else
  7398. {
  7399. $x = $this->GetX();
  7400. }
  7401. // check page for no-write regions and adapt page margins if necessary
  7402. $this->checkPageRegions(0, $x, $y);
  7403. // apply margins
  7404. $oy = $y + $mc_margin['T'];
  7405. if ($this->rtl)
  7406. {
  7407. $ox = $this->w - $x - $mc_margin['R'];
  7408. }
  7409. else
  7410. {
  7411. $ox = $x + $mc_margin['L'];
  7412. }
  7413. $this->x = $ox;
  7414. $this->y = $oy;
  7415. // set width
  7416. if ($this->empty_string($w) or ($w <= 0))
  7417. {
  7418. if ($this->rtl)
  7419. {
  7420. $w = $this->x - $this->lMargin - $mc_margin['L'];
  7421. }
  7422. else
  7423. {
  7424. $w = $this->w - $this->x - $this->rMargin - $mc_margin['R'];
  7425. }
  7426. }
  7427. // store original margin values
  7428. $lMargin = $this->lMargin;
  7429. $rMargin = $this->rMargin;
  7430. if ($this->rtl)
  7431. {
  7432. $this->rMargin = $this->w - $this->x;
  7433. $this->lMargin = $this->x - $w;
  7434. }
  7435. else
  7436. {
  7437. $this->lMargin = $this->x;
  7438. $this->rMargin = $this->w - $this->x - $w;
  7439. }
  7440. if ($autopadding)
  7441. {
  7442. // add top padding
  7443. $this->y += $mc_padding['T'];
  7444. }
  7445. if ($ishtml)
  7446. { // ******* Write HTML text
  7447. $this->writeHTML($txt, true, 0, $reseth, true, $align);
  7448. $nl = 1;
  7449. }
  7450. else
  7451. { // ******* Write simple text
  7452. // vertical alignment
  7453. if ($maxh > 0)
  7454. {
  7455. // get text height
  7456. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  7457. if ($fitcell)
  7458. {
  7459. $prev_FontSizePt = $this->FontSizePt;
  7460. // try to reduce font size to fit text on cell (use a quick search algorithm)
  7461. $fmin = 1;
  7462. $fmax = $this->FontSizePt;
  7463. $prev_text_height = $text_height;
  7464. $maxit = 100; // max number of iterations
  7465. while ($maxit > 0)
  7466. {
  7467. $fmid = (($fmax + $fmin) / 2);
  7468. $this->SetFontSize($fmid, false);
  7469. $this->resetLastH();
  7470. $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
  7471. if (($text_height == $maxh) or (($text_height < $maxh) and ($fmin >= ($fmax - 0.01))))
  7472. {
  7473. break;
  7474. }
  7475. elseif ($text_height < $maxh)
  7476. {
  7477. $fmin = $fmid;
  7478. }
  7479. else
  7480. {
  7481. $fmax = $fmid;
  7482. }
  7483. -- $maxit;
  7484. }
  7485. $this->SetFontSize($this->FontSizePt);
  7486. }
  7487. if ($text_height < $maxh)
  7488. {
  7489. if ($valign == 'M')
  7490. {
  7491. // text vertically centered
  7492. $this->y += (($maxh - $text_height) / 2);
  7493. }
  7494. elseif ($valign == 'B')
  7495. {
  7496. // text vertically aligned on bottom
  7497. $this->y += ($maxh - $text_height);
  7498. }
  7499. }
  7500. }
  7501. $nl = $this->Write($this->lasth, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
  7502. if ($fitcell)
  7503. {
  7504. // restore font size
  7505. $this->SetFontSize($prev_FontSizePt);
  7506. }
  7507. }
  7508. if ($autopadding)
  7509. {
  7510. // add bottom padding
  7511. $this->y += $mc_padding['B'];
  7512. }
  7513. // Get end-of-text Y position
  7514. $currentY = $this->y;
  7515. // get latest page number
  7516. $endpage = $this->page;
  7517. if ($resth > 0)
  7518. {
  7519. $skip = ($endpage - $startpage);
  7520. $tmpresth = $resth;
  7521. while ($tmpresth > 0)
  7522. {
  7523. if ($skip <= 0)
  7524. {
  7525. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  7526. $this->checkPageBreak($this->PageBreakTrigger + 1);
  7527. }
  7528. if ($this->num_columns > 1)
  7529. {
  7530. $tmpresth -= ($this->h - $this->y - $this->bMargin);
  7531. }
  7532. else
  7533. {
  7534. $tmpresth -= ($this->h - $this->tMargin - $this->bMargin);
  7535. }
  7536. -- $skip;
  7537. }
  7538. $currentY = $this->y;
  7539. $endpage = $this->page;
  7540. }
  7541. // get latest column
  7542. $endcolumn = $this->current_column;
  7543. if ($this->num_columns == 0)
  7544. {
  7545. $this->num_columns = 1;
  7546. }
  7547. // get border modes
  7548. $border_start = $this->getBorderMode($border, $position = 'start');
  7549. $border_end = $this->getBorderMode($border, $position = 'end');
  7550. $border_middle = $this->getBorderMode($border, $position = 'middle');
  7551. // design borders around HTML cells.
  7552. for($page = $startpage; $page <= $endpage; ++ $page)
  7553. { // for each page
  7554. $ccode = '';
  7555. $this->setPage($page);
  7556. if ($this->num_columns < 2)
  7557. {
  7558. // single-column mode
  7559. $this->SetX($x);
  7560. $this->y = $this->tMargin;
  7561. }
  7562. // account for margin changes
  7563. if ($page > $startpage)
  7564. {
  7565. if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm']))
  7566. {
  7567. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  7568. }
  7569. elseif ((! $this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm']))
  7570. {
  7571. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  7572. }
  7573. }
  7574. if ($startpage == $endpage)
  7575. {
  7576. // single page
  7577. for($column = $startcolumn; $column <= $endcolumn; ++ $column)
  7578. { // for each column
  7579. $this->selectColumn($column);
  7580. if ($this->rtl)
  7581. {
  7582. $this->x -= $mc_margin['R'];
  7583. }
  7584. else
  7585. {
  7586. $this->x += $mc_margin['L'];
  7587. }
  7588. if ($startcolumn == $endcolumn)
  7589. { // single column
  7590. $cborder = $border;
  7591. $h = max($h, ($currentY - $oy));
  7592. $this->y = $oy;
  7593. }
  7594. elseif ($column == $startcolumn)
  7595. { // first column
  7596. $cborder = $border_start;
  7597. $this->y = $oy;
  7598. $h = $this->h - $this->y - $this->bMargin;
  7599. }
  7600. elseif ($column == $endcolumn)
  7601. { // end column
  7602. $cborder = $border_end;
  7603. $h = $currentY - $this->y;
  7604. if ($resth > $h)
  7605. {
  7606. $h = $resth;
  7607. }
  7608. }
  7609. else
  7610. { // middle column
  7611. $cborder = $border_middle;
  7612. $h = $this->h - $this->y - $this->bMargin;
  7613. $resth -= $h;
  7614. }
  7615. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7616. } // end for each column
  7617. }
  7618. elseif ($page == $startpage)
  7619. { // first page
  7620. for($column = $startcolumn; $column < $this->num_columns; ++ $column)
  7621. { // for each column
  7622. $this->selectColumn($column);
  7623. if ($this->rtl)
  7624. {
  7625. $this->x -= $mc_margin['R'];
  7626. }
  7627. else
  7628. {
  7629. $this->x += $mc_margin['L'];
  7630. }
  7631. if ($column == $startcolumn)
  7632. { // first column
  7633. $cborder = $border_start;
  7634. $this->y = $oy;
  7635. $h = $this->h - $this->y - $this->bMargin;
  7636. }
  7637. else
  7638. { // middle column
  7639. $cborder = $border_middle;
  7640. $h = $this->h - $this->y - $this->bMargin;
  7641. $resth -= $h;
  7642. }
  7643. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7644. } // end for each column
  7645. }
  7646. elseif ($page == $endpage)
  7647. { // last page
  7648. for($column = 0; $column <= $endcolumn; ++ $column)
  7649. { // for each column
  7650. $this->selectColumn($column);
  7651. if ($this->rtl)
  7652. {
  7653. $this->x -= $mc_margin['R'];
  7654. }
  7655. else
  7656. {
  7657. $this->x += $mc_margin['L'];
  7658. }
  7659. if ($column == $endcolumn)
  7660. {
  7661. // end column
  7662. $cborder = $border_end;
  7663. $h = $currentY - $this->y;
  7664. if ($resth > $h)
  7665. {
  7666. $h = $resth;
  7667. }
  7668. }
  7669. else
  7670. {
  7671. // middle column
  7672. $cborder = $border_middle;
  7673. $h = $this->h - $this->y - $this->bMargin;
  7674. $resth -= $h;
  7675. }
  7676. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7677. } // end for each column
  7678. }
  7679. else
  7680. { // middle page
  7681. for($column = 0; $column < $this->num_columns; ++ $column)
  7682. { // for each column
  7683. $this->selectColumn($column);
  7684. if ($this->rtl)
  7685. {
  7686. $this->x -= $mc_margin['R'];
  7687. }
  7688. else
  7689. {
  7690. $this->x += $mc_margin['L'];
  7691. }
  7692. $cborder = $border_middle;
  7693. $h = $this->h - $this->y - $this->bMargin;
  7694. $resth -= $h;
  7695. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  7696. } // end for each column
  7697. }
  7698. if ($cborder or $fill)
  7699. {
  7700. // draw border and fill
  7701. if ($this->inxobj)
  7702. {
  7703. // we are inside an XObject template
  7704. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false)
  7705. {
  7706. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  7707. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  7708. }
  7709. else
  7710. {
  7711. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  7712. }
  7713. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  7714. $pstart = substr($pagebuff, 0, $pagemark);
  7715. $pend = substr($pagebuff, $pagemark);
  7716. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $ccode . $pend;
  7717. $pagemark += strlen($ccode);
  7718. }
  7719. else
  7720. {
  7721. if (end($this->transfmrk[$this->page]) !== false)
  7722. {
  7723. $pagemarkkey = key($this->transfmrk[$this->page]);
  7724. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  7725. }
  7726. elseif ($this->InFooter)
  7727. {
  7728. $pagemark = &$this->footerpos[$this->page];
  7729. }
  7730. else
  7731. {
  7732. $pagemark = &$this->intmrk[$this->page];
  7733. }
  7734. $pagebuff = $this->getPageBuffer($this->page);
  7735. $pstart = substr($pagebuff, 0, $pagemark);
  7736. $pend = substr($pagebuff, $pagemark);
  7737. $this->setPageBuffer($this->page, $pstart . $ccode . $pend);
  7738. $pagemark += strlen($ccode);
  7739. }
  7740. }
  7741. } // end for each page
  7742. // Get end-of-cell Y position
  7743. $currentY = $this->GetY();
  7744. // restore original margin values
  7745. $this->SetLeftMargin($lMargin);
  7746. $this->SetRightMargin($rMargin);
  7747. if ($ln > 0)
  7748. {
  7749. //Go to the beginning of the next line
  7750. $this->SetY($currentY + $mc_margin['B']);
  7751. if ($ln == 2)
  7752. {
  7753. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  7754. }
  7755. }
  7756. else
  7757. {
  7758. // go left or right by case
  7759. $this->setPage($startpage);
  7760. $this->y = $y;
  7761. $this->SetX($x + $w + $mc_margin['L'] + $mc_margin['R']);
  7762. }
  7763. $this->setContentMark();
  7764. $this->cell_padding = $prev_cell_padding;
  7765. $this->cell_margin = $prev_cell_margin;
  7766. return $nl;
  7767. }
  7768. /**
  7769. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  7770. * @param mixed $brd Indicates if borders must be drawn around the cell block. 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: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7771. * @param string multicell position: 'start', 'middle', 'end'
  7772. * @return border mode array
  7773. * @access protected
  7774. * @since 4.4.002 (2008-12-09)
  7775. */
  7776. protected function getBorderMode($brd, $position = 'start')
  7777. {
  7778. if ((! $this->opencell) or empty($brd))
  7779. {
  7780. return $brd;
  7781. }
  7782. if ($brd == 1)
  7783. {
  7784. $brd = 'LTRB';
  7785. }
  7786. if (is_string($brd))
  7787. {
  7788. // convert string to array
  7789. $slen = strlen($brd);
  7790. $newbrd = array();
  7791. for($i = 0; $i < $slen; ++ $i)
  7792. {
  7793. $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
  7794. }
  7795. $brd = $newbrd;
  7796. }
  7797. foreach ($brd as $border => $style)
  7798. {
  7799. switch ($position)
  7800. {
  7801. case 'start' :
  7802. {
  7803. if (strpos($border, 'B') !== false)
  7804. {
  7805. // remove bottom line
  7806. $newkey = str_replace('B', '', $border);
  7807. if (strlen($newkey) > 0)
  7808. {
  7809. $brd[$newkey] = $style;
  7810. }
  7811. unset($brd[$border]);
  7812. }
  7813. break;
  7814. }
  7815. case 'middle' :
  7816. {
  7817. if (strpos($border, 'B') !== false)
  7818. {
  7819. // remove bottom line
  7820. $newkey = str_replace('B', '', $border);
  7821. if (strlen($newkey) > 0)
  7822. {
  7823. $brd[$newkey] = $style;
  7824. }
  7825. unset($brd[$border]);
  7826. $border = $newkey;
  7827. }
  7828. if (strpos($border, 'T') !== false)
  7829. {
  7830. // remove bottom line
  7831. $newkey = str_replace('T', '', $border);
  7832. if (strlen($newkey) > 0)
  7833. {
  7834. $brd[$newkey] = $style;
  7835. }
  7836. unset($brd[$border]);
  7837. }
  7838. break;
  7839. }
  7840. case 'end' :
  7841. {
  7842. if (strpos($border, 'T') !== false)
  7843. {
  7844. // remove bottom line
  7845. $newkey = str_replace('T', '', $border);
  7846. if (strlen($newkey) > 0)
  7847. {
  7848. $brd[$newkey] = $style;
  7849. }
  7850. unset($brd[$border]);
  7851. }
  7852. break;
  7853. }
  7854. }
  7855. }
  7856. return $brd;
  7857. }
  7858. /**
  7859. * This method return the estimated number of lines for print a simple text string using Multicell() method.
  7860. * @param string $txt String for calculating his height
  7861. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  7862. * @param boolean $reseth if true reset the last cell height (default false).
  7863. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  7864. * @param float $cellpadding Internal cell padding, if empty uses default cell padding.
  7865. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7866. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  7867. * @author Alexander Escalona Fern�ndez, Nicola Asuni
  7868. * @access public
  7869. * @since 4.5.011
  7870. */
  7871. public function getNumLines($txt, $w = 0, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0)
  7872. {
  7873. if ($txt === '')
  7874. {
  7875. // empty string
  7876. return 1;
  7877. }
  7878. // adjust internal padding
  7879. $prev_cell_padding = $this->cell_padding;
  7880. $prev_lasth = $this->lasth;
  7881. if (is_array($cellpadding))
  7882. {
  7883. $this->cell_padding = $cellpadding;
  7884. }
  7885. $this->adjustCellPadding($border);
  7886. if ($this->empty_string($w) or ($w <= 0))
  7887. {
  7888. if ($this->rtl)
  7889. {
  7890. $w = $this->x - $this->lMargin;
  7891. }
  7892. else
  7893. {
  7894. $w = $this->w - $this->rMargin - $this->x;
  7895. }
  7896. }
  7897. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  7898. if ($reseth)
  7899. {
  7900. // reset row height
  7901. $this->resetLastH();
  7902. }
  7903. $lines = 1;
  7904. $sum = 0;
  7905. $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
  7906. $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
  7907. $length = count($chars);
  7908. $lastSeparator = - 1;
  7909. for($i = 0; $i < $length; ++ $i)
  7910. {
  7911. $charWidth = $charsWidth[$i];
  7912. if (preg_match($this->re_spaces, $this->unichr($chars[$i])))
  7913. {
  7914. $lastSeparator = $i;
  7915. }
  7916. if ((($sum + $charWidth) > $wmax) or ($chars[$i] == 10))
  7917. {
  7918. ++ $lines;
  7919. if ($lastSeparator != - 1)
  7920. {
  7921. $i = $lastSeparator;
  7922. $lastSeparator = - 1;
  7923. $sum = 0;
  7924. }
  7925. else
  7926. {
  7927. $sum = $charWidth;
  7928. }
  7929. }
  7930. else
  7931. {
  7932. $sum += $charWidth;
  7933. }
  7934. }
  7935. if ($chars[($length - 1)] == 10)
  7936. {
  7937. -- $lines;
  7938. }
  7939. $this->cell_padding = $prev_cell_padding;
  7940. $this->lasth = $prev_lasth;
  7941. return $lines;
  7942. }
  7943. /**
  7944. * This method return the estimated needed height for print a simple text string in Multicell() method.
  7945. * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
  7946. * <pre>
  7947. * // store current object
  7948. * $pdf->startTransaction();
  7949. * // store starting values
  7950. * $start_y = $pdf->GetY();
  7951. * $start_page = $pdf->getPage();
  7952. * // call your printing functions with your parameters
  7953. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7954. * $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);
  7955. * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7956. * // get the new Y
  7957. * $end_y = $pdf->GetY();
  7958. * $end_page = $pdf->getPage();
  7959. * // calculate height
  7960. * $height = 0;
  7961. * if ($end_page == $start_page) {
  7962. * $height = $end_y - $start_y;
  7963. * } else {
  7964. * for ($page=$start_page; $page <= $end_page; ++$page) {
  7965. * $this->setPage($page);
  7966. * if ($page == $start_page) {
  7967. * // first page
  7968. * $height = $this->h - $start_y - $this->bMargin;
  7969. * } elseif ($page == $end_page) {
  7970. * // last page
  7971. * $height = $end_y - $this->tMargin;
  7972. * } else {
  7973. * $height = $this->h - $this->tMargin - $this->bMargin;
  7974. * }
  7975. * }
  7976. * }
  7977. * // restore previous object
  7978. * $pdf = $pdf->rollbackTransaction();
  7979. * </pre>
  7980. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  7981. * @param string $txt String for calculating his height
  7982. * @param boolean $reseth if true reset the last cell height (default false).
  7983. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width (default true).
  7984. * @param float $cellpadding Internal cell padding, if empty uses default cell padding.
  7985. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  7986. * @return float Return the minimal height needed for multicell method for printing the $txt param.
  7987. * @author Nicola Asuni, Alexander Escalona Fern�ndez
  7988. * @access public
  7989. */
  7990. public function getStringHeight($w, $txt, $reseth = false, $autopadding = true, $cellpadding = '', $border = 0)
  7991. {
  7992. // adjust internal padding
  7993. $prev_cell_padding = $this->cell_padding;
  7994. $prev_lasth = $this->lasth;
  7995. if (is_array($cellpadding))
  7996. {
  7997. $this->cell_padding = $cellpadding;
  7998. }
  7999. $this->adjustCellPadding($border);
  8000. $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
  8001. $height = $lines * ($this->FontSize * $this->cell_height_ratio);
  8002. if ($autopadding)
  8003. {
  8004. // add top and bottom padding
  8005. $height += ($this->cell_padding['T'] + $this->cell_padding['B']);
  8006. }
  8007. $this->cell_padding = $prev_cell_padding;
  8008. $this->lasth = $prev_lasth;
  8009. return $height;
  8010. }
  8011. /**
  8012. * This method prints text from the current position.<br />
  8013. * @param float $h Line height
  8014. * @param string $txt String to print
  8015. * @param mixed $link URL or identifier returned by AddLink()
  8016. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  8017. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
  8018. * @param boolean $ln if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
  8019. * @param int $stretch font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
  8020. * @param boolean $firstline if true prints only the first line and return the remaining string.
  8021. * @param boolean $firstblock if true the string is the starting of a line.
  8022. * @param float $maxh maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
  8023. * @param float $wadj first line width will be reduced by this amount (used in HTML mode).
  8024. * @param array $margin margin array of the parent container
  8025. * @return mixed Return the number of cells or the remaining string if $firstline = true.
  8026. * @access public
  8027. * @since 1.5
  8028. */
  8029. public function Write($h, $txt, $link = '', $fill = false, $align = '', $ln = false, $stretch = 0, $firstline = false, $firstblock = false, $maxh = 0, $wadj = 0, $margin = '')
  8030. {
  8031. // check page for no-write regions and adapt page margins if necessary
  8032. $this->checkPageRegions($h);
  8033. if (strlen($txt) == 0)
  8034. {
  8035. // fix empty text
  8036. $txt = ' ';
  8037. }
  8038. if ($margin === '')
  8039. {
  8040. // set default margins
  8041. $margin = $this->cell_margin;
  8042. }
  8043. // remove carriage returns
  8044. $s = str_replace("\r", '', $txt);
  8045. // check if string contains arabic text
  8046. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $s))
  8047. {
  8048. $arabic = true;
  8049. }
  8050. else
  8051. {
  8052. $arabic = false;
  8053. }
  8054. // check if string contains RTL text
  8055. if ($arabic or ($this->tmprtl == 'R') or preg_match($this->unicode->uni_RE_PATTERN_RTL, $s))
  8056. {
  8057. $rtlmode = true;
  8058. }
  8059. else
  8060. {
  8061. $rtlmode = false;
  8062. }
  8063. // get a char width
  8064. $chrwidth = $this->GetCharWidth('.');
  8065. // get array of unicode values
  8066. $chars = $this->UTF8StringToArray($s);
  8067. // get array of chars
  8068. $uchars = $this->UTF8ArrayToUniArray($chars);
  8069. // get the number of characters
  8070. $nb = count($chars);
  8071. // replacement for SHY character (minus symbol)
  8072. $shy_replacement = 45;
  8073. $shy_replacement_char = $this->unichr($shy_replacement);
  8074. // widht for SHY replacement
  8075. $shy_replacement_width = $this->GetCharWidth($shy_replacement);
  8076. // max Y
  8077. $maxy = $this->y + $maxh - $h - $this->cell_padding['T'] - $this->cell_padding['B'];
  8078. // calculate remaining line width ($w)
  8079. if ($this->rtl)
  8080. {
  8081. $w = $this->x - $this->lMargin;
  8082. }
  8083. else
  8084. {
  8085. $w = $this->w - $this->rMargin - $this->x;
  8086. }
  8087. // max column width
  8088. $wmax = $w - $wadj;
  8089. if (! $firstline)
  8090. {
  8091. $wmax -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  8092. }
  8093. if ((! $firstline) and (($chrwidth > $wmax) or ($this->GetCharWidth($chars[0]) > $wmax)))
  8094. {
  8095. // a single character do not fit on column
  8096. return '';
  8097. }
  8098. // minimum row height
  8099. $row_height = max($h, $this->FontSize * $this->cell_height_ratio);
  8100. $start_page = $this->page;
  8101. $i = 0; // character position
  8102. $j = 0; // current starting position
  8103. $sep = - 1; // position of the last blank space
  8104. $shy = false; // true if the last blank is a soft hypen (SHY)
  8105. $l = 0; // current string length
  8106. $nl = 0; //number of lines
  8107. $linebreak = false;
  8108. $pc = 0; // previous character
  8109. // for each character
  8110. while ($i < $nb)
  8111. {
  8112. if (($maxh > 0) and ($this->y >= $maxy))
  8113. {
  8114. break;
  8115. }
  8116. //Get the current character
  8117. $c = $chars[$i];
  8118. if ($c == 10)
  8119. { // 10 = "\n" = new line
  8120. //Explicit line break
  8121. if ($align == 'J')
  8122. {
  8123. if ($this->rtl)
  8124. {
  8125. $talign = 'R';
  8126. }
  8127. else
  8128. {
  8129. $talign = 'L';
  8130. }
  8131. }
  8132. else
  8133. {
  8134. $talign = $align;
  8135. }
  8136. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  8137. if ($firstline)
  8138. {
  8139. $startx = $this->x;
  8140. $tmparr = array_slice($chars, $j, ($i - $j));
  8141. if ($rtlmode)
  8142. {
  8143. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8144. }
  8145. $linew = $this->GetArrStringWidth($tmparr);
  8146. unset($tmparr);
  8147. if ($this->rtl)
  8148. {
  8149. $this->endlinex = $startx - $linew;
  8150. }
  8151. else
  8152. {
  8153. $this->endlinex = $startx + $linew;
  8154. }
  8155. $w = $linew;
  8156. $tmpcellpadding = $this->cell_padding;
  8157. if ($maxh == 0)
  8158. {
  8159. $this->SetCellPadding(0);
  8160. }
  8161. }
  8162. if ($firstblock and $this->isRTLTextDir())
  8163. {
  8164. $tmpstr = $this->stringRightTrim($tmpstr);
  8165. }
  8166. // Skip newlines at the begining of a page or column
  8167. if (! empty($tmpstr) or ($this->y < ($this->PageBreakTrigger - $row_height)))
  8168. {
  8169. $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
  8170. }
  8171. unset($tmpstr);
  8172. if ($firstline)
  8173. {
  8174. $this->cell_padding = $tmpcellpadding;
  8175. return ($this->UniArrSubString($uchars, $i));
  8176. }
  8177. ++ $nl;
  8178. $j = $i + 1;
  8179. $l = 0;
  8180. $sep = - 1;
  8181. $shy = false;
  8182. // account for margin changes
  8183. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and (! $this->InFooter))
  8184. {
  8185. $this->AcceptPageBreak();
  8186. if ($this->rtl)
  8187. {
  8188. $this->x -= $margin['R'];
  8189. }
  8190. else
  8191. {
  8192. $this->x += $margin['L'];
  8193. }
  8194. $this->lMargin += $margin['L'];
  8195. $this->rMargin += $margin['R'];
  8196. }
  8197. $w = $this->getRemainingWidth();
  8198. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  8199. }
  8200. else
  8201. {
  8202. // 160 is the non-breaking space.
  8203. // 173 is SHY (Soft Hypen).
  8204. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  8205. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  8206. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  8207. if (($c != 160) and (($c == 173) or preg_match($this->re_spaces, $this->unichr($c))))
  8208. {
  8209. // update last blank space position
  8210. $sep = $i;
  8211. // check if is a SHY
  8212. if ($c == 173)
  8213. {
  8214. $shy = true;
  8215. if ($pc == 45)
  8216. {
  8217. $tmp_shy_replacement_width = 0;
  8218. $tmp_shy_replacement_char = '';
  8219. }
  8220. else
  8221. {
  8222. $tmp_shy_replacement_width = $shy_replacement_width;
  8223. $tmp_shy_replacement_char = $shy_replacement_char;
  8224. }
  8225. }
  8226. else
  8227. {
  8228. $shy = false;
  8229. }
  8230. }
  8231. // update string length
  8232. if ($this->isUnicodeFont() and ($arabic))
  8233. {
  8234. // with bidirectional algorithm some chars may be changed affecting the line length
  8235. // *** very slow ***
  8236. $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl));
  8237. }
  8238. else
  8239. {
  8240. $l += $this->GetCharWidth($c);
  8241. }
  8242. if (($l > $wmax) or (($c == 173) and (($l + $tmp_shy_replacement_width) > $wmax)))
  8243. {
  8244. // we have reached the end of column
  8245. if ($sep == - 1)
  8246. {
  8247. // check if the line was already started
  8248. if (($this->rtl and ($this->x <= ($this->w - $this->rMargin - $chrwidth))) or ((! $this->rtl) and ($this->x >= ($this->lMargin + $chrwidth))))
  8249. {
  8250. // print a void cell and go to next line
  8251. $this->Cell($w, $h, '', 0, 1);
  8252. $linebreak = true;
  8253. if ($firstline)
  8254. {
  8255. return ($this->UniArrSubString($uchars, $j));
  8256. }
  8257. }
  8258. else
  8259. {
  8260. // truncate the word because do not fit on column
  8261. $tmpstr = $this->UniArrSubString($uchars, $j, $i);
  8262. if ($firstline)
  8263. {
  8264. $startx = $this->x;
  8265. $tmparr = array_slice($chars, $j, ($i - $j));
  8266. if ($rtlmode)
  8267. {
  8268. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8269. }
  8270. $linew = $this->GetArrStringWidth($tmparr);
  8271. unset($tmparr);
  8272. if ($this->rtl)
  8273. {
  8274. $this->endlinex = $startx - $linew;
  8275. }
  8276. else
  8277. {
  8278. $this->endlinex = $startx + $linew;
  8279. }
  8280. $w = $linew;
  8281. $tmpcellpadding = $this->cell_padding;
  8282. if ($maxh == 0)
  8283. {
  8284. $this->SetCellPadding(0);
  8285. }
  8286. }
  8287. if ($firstblock and $this->isRTLTextDir())
  8288. {
  8289. $tmpstr = $this->stringRightTrim($tmpstr);
  8290. }
  8291. $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
  8292. unset($tmpstr);
  8293. if ($firstline)
  8294. {
  8295. $this->cell_padding = $tmpcellpadding;
  8296. return ($this->UniArrSubString($uchars, $i));
  8297. }
  8298. $j = $i;
  8299. -- $i;
  8300. }
  8301. }
  8302. else
  8303. {
  8304. // word wrapping
  8305. if ($this->rtl and (! $firstblock) and ($sep < $i))
  8306. {
  8307. $endspace = 1;
  8308. }
  8309. else
  8310. {
  8311. $endspace = 0;
  8312. }
  8313. if ($shy)
  8314. {
  8315. // add hypen (minus symbol) at the end of the line
  8316. $shy_width = $tmp_shy_replacement_width;
  8317. if ($this->rtl)
  8318. {
  8319. $shy_char_left = $tmp_shy_replacement_char;
  8320. $shy_char_right = '';
  8321. }
  8322. else
  8323. {
  8324. $shy_char_left = '';
  8325. $shy_char_right = $tmp_shy_replacement_char;
  8326. }
  8327. }
  8328. else
  8329. {
  8330. $shy_width = 0;
  8331. $shy_char_left = '';
  8332. $shy_char_right = '';
  8333. }
  8334. $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
  8335. if ($firstline)
  8336. {
  8337. $startx = $this->x;
  8338. $tmparr = array_slice($chars, $j, (($sep + $endspace) - $j));
  8339. if ($rtlmode)
  8340. {
  8341. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8342. }
  8343. $linew = $this->GetArrStringWidth($tmparr);
  8344. unset($tmparr);
  8345. if ($this->rtl)
  8346. {
  8347. $this->endlinex = $startx - $linew - $shy_width;
  8348. }
  8349. else
  8350. {
  8351. $this->endlinex = $startx + $linew + $shy_width;
  8352. }
  8353. $w = $linew;
  8354. $tmpcellpadding = $this->cell_padding;
  8355. if ($maxh == 0)
  8356. {
  8357. $this->SetCellPadding(0);
  8358. }
  8359. }
  8360. // print the line
  8361. if ($firstblock and $this->isRTLTextDir())
  8362. {
  8363. $tmpstr = $this->stringRightTrim($tmpstr);
  8364. }
  8365. $this->Cell($w, $h, $shy_char_left . $tmpstr . $shy_char_right, 0, 1, $align, $fill, $link, $stretch);
  8366. unset($tmpstr);
  8367. if ($firstline)
  8368. {
  8369. // return the remaining text
  8370. $this->cell_padding = $tmpcellpadding;
  8371. return ($this->UniArrSubString($uchars, ($sep + $endspace)));
  8372. }
  8373. $i = $sep;
  8374. $sep = - 1;
  8375. $shy = false;
  8376. $j = ($i + 1);
  8377. }
  8378. // account for margin changes
  8379. if ((($this->y + $this->lasth) > $this->PageBreakTrigger) and (! $this->InFooter))
  8380. {
  8381. $this->AcceptPageBreak();
  8382. if ($this->rtl)
  8383. {
  8384. $this->x -= $margin['R'];
  8385. }
  8386. else
  8387. {
  8388. $this->x += $margin['L'];
  8389. }
  8390. $this->lMargin += $margin['L'];
  8391. $this->rMargin += $margin['R'];
  8392. }
  8393. $w = $this->getRemainingWidth();
  8394. $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];
  8395. if ($linebreak)
  8396. {
  8397. $linebreak = false;
  8398. }
  8399. else
  8400. {
  8401. ++ $nl;
  8402. $l = 0;
  8403. }
  8404. }
  8405. }
  8406. // save last character
  8407. $pc = $c;
  8408. ++ $i;
  8409. } // end while i < nb
  8410. // print last substring (if any)
  8411. if ($l > 0)
  8412. {
  8413. switch ($align)
  8414. {
  8415. case 'J' :
  8416. case 'C' :
  8417. {
  8418. $w = $w;
  8419. break;
  8420. }
  8421. case 'L' :
  8422. {
  8423. if ($this->rtl)
  8424. {
  8425. $w = $w;
  8426. }
  8427. else
  8428. {
  8429. $w = $l;
  8430. }
  8431. break;
  8432. }
  8433. case 'R' :
  8434. {
  8435. if ($this->rtl)
  8436. {
  8437. $w = $l;
  8438. }
  8439. else
  8440. {
  8441. $w = $w;
  8442. }
  8443. break;
  8444. }
  8445. default :
  8446. {
  8447. $w = $l;
  8448. break;
  8449. }
  8450. }
  8451. $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
  8452. if ($firstline)
  8453. {
  8454. $startx = $this->x;
  8455. $tmparr = array_slice($chars, $j, ($nb - $j));
  8456. if ($rtlmode)
  8457. {
  8458. $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
  8459. }
  8460. $linew = $this->GetArrStringWidth($tmparr);
  8461. unset($tmparr);
  8462. if ($this->rtl)
  8463. {
  8464. $this->endlinex = $startx - $linew;
  8465. }
  8466. else
  8467. {
  8468. $this->endlinex = $startx + $linew;
  8469. }
  8470. $w = $linew;
  8471. $tmpcellpadding = $this->cell_padding;
  8472. if ($maxh == 0)
  8473. {
  8474. $this->SetCellPadding(0);
  8475. }
  8476. }
  8477. if ($firstblock and $this->isRTLTextDir())
  8478. {
  8479. $tmpstr = $this->stringRightTrim($tmpstr);
  8480. }
  8481. $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
  8482. unset($tmpstr);
  8483. if ($firstline)
  8484. {
  8485. $this->cell_padding = $tmpcellpadding;
  8486. return ($this->UniArrSubString($uchars, $nb));
  8487. }
  8488. ++ $nl;
  8489. }
  8490. if ($firstline)
  8491. {
  8492. return '';
  8493. }
  8494. return $nl;
  8495. }
  8496. /**
  8497. * Returns the remaining width between the current position and margins.
  8498. * @return int Return the remaining width
  8499. * @access protected
  8500. */
  8501. protected function getRemainingWidth()
  8502. {
  8503. $this->checkPageRegions();
  8504. if ($this->rtl)
  8505. {
  8506. return ($this->x - $this->lMargin);
  8507. }
  8508. else
  8509. {
  8510. return ($this->w - $this->rMargin - $this->x);
  8511. }
  8512. }
  8513. /**
  8514. * Extract a slice of the $strarr array and return it as string.
  8515. * @param string $strarr The input array of characters.
  8516. * @param int $start the starting element of $strarr.
  8517. * @param int $end first element that will not be returned.
  8518. * @return Return part of a string
  8519. * @access public
  8520. */
  8521. public function UTF8ArrSubString($strarr, $start = '', $end = '')
  8522. {
  8523. if (strlen($start) == 0)
  8524. {
  8525. $start = 0;
  8526. }
  8527. if (strlen($end) == 0)
  8528. {
  8529. $end = count($strarr);
  8530. }
  8531. $string = '';
  8532. for($i = $start; $i < $end; ++ $i)
  8533. {
  8534. $string .= $this->unichr($strarr[$i]);
  8535. }
  8536. return $string;
  8537. }
  8538. /**
  8539. * Extract a slice of the $uniarr array and return it as string.
  8540. * @param string $uniarr The input array of characters.
  8541. * @param int $start the starting element of $strarr.
  8542. * @param int $end first element that will not be returned.
  8543. * @return Return part of a string
  8544. * @access public
  8545. * @since 4.5.037 (2009-04-07)
  8546. */
  8547. public function UniArrSubString($uniarr, $start = '', $end = '')
  8548. {
  8549. if (strlen($start) == 0)
  8550. {
  8551. $start = 0;
  8552. }
  8553. if (strlen($end) == 0)
  8554. {
  8555. $end = count($uniarr);
  8556. }
  8557. $string = '';
  8558. for($i = $start; $i < $end; ++ $i)
  8559. {
  8560. $string .= $uniarr[$i];
  8561. }
  8562. return $string;
  8563. }
  8564. /**
  8565. * Convert an array of UTF8 values to array of unicode characters
  8566. * @param string $ta The input array of UTF8 values.
  8567. * @return Return array of unicode characters
  8568. * @access public
  8569. * @since 4.5.037 (2009-04-07)
  8570. */
  8571. public function UTF8ArrayToUniArray($ta)
  8572. {
  8573. return array_map(array($this, 'unichr'), $ta);
  8574. }
  8575. /**
  8576. * Returns the unicode caracter specified by UTF-8 value
  8577. * @param int $c UTF-8 value
  8578. * @return Returns the specified character.
  8579. * @author Miguel Perez, Nicola Asuni
  8580. * @access public
  8581. * @since 2.3.000 (2008-03-05)
  8582. */
  8583. public function unichr($c)
  8584. {
  8585. if (! $this->isunicode)
  8586. {
  8587. return chr($c);
  8588. }
  8589. elseif ($c <= 0x7F)
  8590. {
  8591. // one byte
  8592. return chr($c);
  8593. }
  8594. elseif ($c <= 0x7FF)
  8595. {
  8596. // two bytes
  8597. return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
  8598. }
  8599. elseif ($c <= 0xFFFF)
  8600. {
  8601. // three bytes
  8602. return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  8603. }
  8604. elseif ($c <= 0x10FFFF)
  8605. {
  8606. // four bytes
  8607. return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
  8608. }
  8609. else
  8610. {
  8611. return '';
  8612. }
  8613. }
  8614. /**
  8615. * Return the image type given the file name or array returned by getimagesize() function.
  8616. * @param string $imgfile image file name
  8617. * @param array $iminfo array of image information returned by getimagesize() function.
  8618. * @return string image type
  8619. * @since 4.8.017 (2009-11-27)
  8620. */
  8621. public function getImageFileType($imgfile, $iminfo = array())
  8622. {
  8623. $type = '';
  8624. if (isset($iminfo['mime']) and ! empty($iminfo['mime']))
  8625. {
  8626. $mime = explode('/', $iminfo['mime']);
  8627. if ((count($mime) > 1) and ($mime[0] == 'image') and (! empty($mime[1])))
  8628. {
  8629. $type = strtolower(trim($mime[1]));
  8630. }
  8631. }
  8632. if (empty($type))
  8633. {
  8634. $fileinfo = pathinfo($imgfile);
  8635. if (isset($fileinfo['extension']) and (! $this->empty_string($fileinfo['extension'])))
  8636. {
  8637. $type = strtolower(trim($fileinfo['extension']));
  8638. }
  8639. }
  8640. if ($type == 'jpg')
  8641. {
  8642. $type = 'jpeg';
  8643. }
  8644. return $type;
  8645. }
  8646. /**
  8647. * Set the block dimensions accounting for page breaks and page/column fitting
  8648. * @param float $w width
  8649. * @param float $h height
  8650. * @param float $x X coordinate
  8651. * @param float $y Y coodiante
  8652. * @param boolean $fitonpage if true the block is resized to not exceed page dimensions.
  8653. * @access protected
  8654. * @since 5.5.009 (2010-07-05)
  8655. */
  8656. protected function fitBlock(&$w, &$h, &$x, &$y, $fitonpage = false)
  8657. {
  8658. // resize the block to be vertically contained on a single page or single column
  8659. if ($fitonpage or $this->AutoPageBreak)
  8660. {
  8661. $ratio_wh = ($w / $h);
  8662. if ($h > ($this->PageBreakTrigger - $this->tMargin))
  8663. {
  8664. $h = $this->PageBreakTrigger - $this->tMargin;
  8665. $w = ($h * $ratio_wh);
  8666. }
  8667. // resize the block to be horizontally contained on a single page or single column
  8668. if ($fitonpage)
  8669. {
  8670. $maxw = ($this->w - $this->lMargin - $this->rMargin);
  8671. if ($w > $maxw)
  8672. {
  8673. $w = $maxw;
  8674. $h = ($w / $ratio_wh);
  8675. }
  8676. }
  8677. }
  8678. // Check whether we need a new page or new column first as this does not fit
  8679. $prev_x = $this->x;
  8680. $prev_y = $this->y;
  8681. if ($this->checkPageBreak($h, $y) or ($this->y < $prev_y))
  8682. {
  8683. $y = $this->y;
  8684. if ($this->rtl)
  8685. {
  8686. $x += ($prev_x - $this->x);
  8687. }
  8688. else
  8689. {
  8690. $x += ($this->x - $prev_x);
  8691. }
  8692. }
  8693. // resize the block to be contained on the remaining available page or column space
  8694. if ($fitonpage)
  8695. {
  8696. $ratio_wh = ($w / $h);
  8697. if (($y + $h) > $this->PageBreakTrigger)
  8698. {
  8699. $h = $this->PageBreakTrigger - $y;
  8700. $w = ($h * $ratio_wh);
  8701. }
  8702. if ((! $this->rtl) and (($x + $w) > ($this->w - $this->rMargin)))
  8703. {
  8704. $w = $this->w - $this->rMargin - $x;
  8705. $h = ($w / $ratio_wh);
  8706. }
  8707. elseif (($this->rtl) and (($x - $w) < ($this->lMargin)))
  8708. {
  8709. $w = $x - $this->lMargin;
  8710. $h = ($w / $ratio_wh);
  8711. }
  8712. }
  8713. }
  8714. /**
  8715. * Puts an image in the page.
  8716. * The upper-left corner must be given.
  8717. * The dimensions can be specified in different ways:<ul>
  8718. * <li>explicit width and height (expressed in user unit)</li>
  8719. * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
  8720. * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  8721. * 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;
  8722. * The format can be specified explicitly or inferred from the file extension.<br />
  8723. * It is possible to put a link on the image.<br />
  8724. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  8725. * @param string $file Name of the file containing the image.
  8726. * @param float $x Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
  8727. * @param float $y Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
  8728. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8729. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  8730. * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  8731. * @param mixed $link URL or identifier returned by AddLink().
  8732. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  8733. * @param mixed $resize If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
  8734. * @param int $dpi dot-per-inch resolution used on resize
  8735. * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  8736. * @param boolean $ismask true if this image is a mask, false otherwise
  8737. * @param mixed $imgmask image object returned by this function or false
  8738. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  8739. * @param boolean $fitbox If true scale image dimensions proportionally to fit within the ($w, $h) box.
  8740. * @param boolean $hidden if true do not display the image.
  8741. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  8742. * @return image information
  8743. * @access public
  8744. * @since 1.1
  8745. */
  8746. 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)
  8747. {
  8748. if ($x === '')
  8749. {
  8750. $x = $this->x;
  8751. }
  8752. if ($y === '')
  8753. {
  8754. $y = $this->y;
  8755. }
  8756. // check page for no-write regions and adapt page margins if necessary
  8757. $this->checkPageRegions($h, $x, $y);
  8758. $cached_file = false; // true when the file is cached
  8759. // get image dimensions
  8760. $imsize = @getimagesize($file);
  8761. if ($imsize === FALSE)
  8762. {
  8763. // try to encode spaces on filename
  8764. $file = str_replace(' ', '%20', $file);
  8765. $imsize = @getimagesize($file);
  8766. if ($imsize === FALSE)
  8767. {
  8768. if (function_exists('curl_init'))
  8769. {
  8770. // try to get remote file data using cURL
  8771. $cs = curl_init(); // curl session
  8772. curl_setopt($cs, CURLOPT_URL, $file);
  8773. curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
  8774. curl_setopt($cs, CURLOPT_FAILONERROR, true);
  8775. curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
  8776. curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
  8777. curl_setopt($cs, CURLOPT_TIMEOUT, 30);
  8778. $imgdata = curl_exec($cs);
  8779. curl_close($cs);
  8780. if ($imgdata !== FALSE)
  8781. {
  8782. // copy image to cache
  8783. $file = tempnam(K_PATH_CACHE, 'img_');
  8784. $fp = fopen($file, 'w');
  8785. fwrite($fp, $imgdata);
  8786. fclose($fp);
  8787. unset($imgdata);
  8788. $cached_file = true;
  8789. $imsize = @getimagesize($file);
  8790. if ($imsize === FALSE)
  8791. {
  8792. unlink($file);
  8793. $cached_file = false;
  8794. }
  8795. }
  8796. }
  8797. elseif (($w > 0) and ($h > 0))
  8798. {
  8799. // get measures from specified data
  8800. $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8801. $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k;
  8802. $imsize = array($pw, $ph);
  8803. }
  8804. }
  8805. }
  8806. if ($imsize === FALSE)
  8807. {
  8808. $this->Error('[Image] Unable to get image: ' . $file);
  8809. }
  8810. // get original image width and height in pixels
  8811. list($pixw, $pixh) = $imsize;
  8812. // calculate image width and height on document
  8813. if (($w <= 0) and ($h <= 0))
  8814. {
  8815. // convert image size to document unit
  8816. $w = $this->pixelsToUnits($pixw);
  8817. $h = $this->pixelsToUnits($pixh);
  8818. }
  8819. elseif ($w <= 0)
  8820. {
  8821. $w = $h * $pixw / $pixh;
  8822. }
  8823. elseif ($h <= 0)
  8824. {
  8825. $h = $w * $pixh / $pixw;
  8826. }
  8827. elseif ($fitbox and ($w > 0) and ($h > 0))
  8828. {
  8829. // scale image dimensions proportionally to fit within the ($w, $h) box
  8830. if ((($w * $pixh) / ($h * $pixw)) < 1)
  8831. {
  8832. $h = $w * $pixh / $pixw;
  8833. }
  8834. else
  8835. {
  8836. $w = $h * $pixw / $pixh;
  8837. }
  8838. }
  8839. // fit the image on available space
  8840. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  8841. // calculate new minimum dimensions in pixels
  8842. $neww = round($w * $this->k * $dpi / $this->dpi);
  8843. $newh = round($h * $this->k * $dpi / $this->dpi);
  8844. // check if resize is necessary (resize is used only to reduce the image)
  8845. $newsize = ($neww * $newh);
  8846. $pixsize = ($pixw * $pixh);
  8847. if (intval($resize) == 2)
  8848. {
  8849. $resize = true;
  8850. }
  8851. elseif ($newsize >= $pixsize)
  8852. {
  8853. $resize = false;
  8854. }
  8855. // check if image has been already added on document
  8856. $newimage = true;
  8857. if (in_array($file, $this->imagekeys))
  8858. {
  8859. $newimage = false;
  8860. // get existing image data
  8861. $info = $this->getImageBuffer($file);
  8862. // check if the newer image is larger
  8863. $oldsize = ($info['w'] * $info['h']);
  8864. if ((($oldsize < $newsize) and ($resize)) or (($oldsize < $pixsize) and (! $resize)))
  8865. {
  8866. $newimage = true;
  8867. }
  8868. }
  8869. if ($newimage)
  8870. {
  8871. //First use of image, get info
  8872. $type = strtolower($type);
  8873. if ($type == '')
  8874. {
  8875. $type = $this->getImageFileType($file, $imsize);
  8876. }
  8877. elseif ($type == 'jpg')
  8878. {
  8879. $type = 'jpeg';
  8880. }
  8881. $mqr = $this->get_mqr();
  8882. $this->set_mqr(false);
  8883. // Specific image handlers
  8884. $mtd = '_parse' . $type;
  8885. // GD image handler function
  8886. $gdfunction = 'imagecreatefrom' . $type;
  8887. $info = false;
  8888. if ((method_exists($this, $mtd)) and (! ($resize and function_exists($gdfunction))))
  8889. {
  8890. // TCPDF image functions
  8891. $info = $this->$mtd($file);
  8892. if ($info == 'pngalpha')
  8893. {
  8894. return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
  8895. }
  8896. }
  8897. if (! $info)
  8898. {
  8899. if (function_exists($gdfunction))
  8900. {
  8901. // GD library
  8902. $img = $gdfunction($file);
  8903. if ($resize)
  8904. {
  8905. $imgr = imagecreatetruecolor($neww, $newh);
  8906. if (($type == 'gif') or ($type == 'png'))
  8907. {
  8908. $imgr = $this->_setGDImageTransparency($imgr, $img);
  8909. }
  8910. imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
  8911. if (($type == 'gif') or ($type == 'png'))
  8912. {
  8913. $info = $this->_toPNG($imgr);
  8914. }
  8915. else
  8916. {
  8917. $info = $this->_toJPEG($imgr);
  8918. }
  8919. }
  8920. else
  8921. {
  8922. if (($type == 'gif') or ($type == 'png'))
  8923. {
  8924. $info = $this->_toPNG($img);
  8925. }
  8926. else
  8927. {
  8928. $info = $this->_toJPEG($img);
  8929. }
  8930. }
  8931. }
  8932. elseif (extension_loaded('imagick'))
  8933. {
  8934. // ImageMagick library
  8935. $img = new Imagick();
  8936. if ($type == 'SVG')
  8937. {
  8938. // get SVG file content
  8939. $svgimg = file_get_contents($file);
  8940. // get width and height
  8941. $regs = array();
  8942. if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs))
  8943. {
  8944. $svgtag = $regs[1];
  8945. $tmp = array();
  8946. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp))
  8947. {
  8948. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  8949. $owu = sprintf('%.3F', ($ow * $dpi / 72)) . $this->pdfunit;
  8950. $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="' . $owu . '"', $svgtag, 1);
  8951. }
  8952. else
  8953. {
  8954. $ow = $w;
  8955. }
  8956. $tmp = array();
  8957. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp))
  8958. {
  8959. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  8960. $ohu = sprintf('%.3F', ($oh * $dpi / 72)) . $this->pdfunit;
  8961. $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="' . $ohu . '"', $svgtag, 1);
  8962. }
  8963. else
  8964. {
  8965. $oh = $h;
  8966. }
  8967. $tmp = array();
  8968. if (! preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp))
  8969. {
  8970. $vbw = ($ow * $this->imgscale * $this->k);
  8971. $vbh = ($oh * $this->imgscale * $this->k);
  8972. $vbox = sprintf(' viewBox="0 0 %.3F %.3F" ', $vbw, $vbh);
  8973. $svgtag = $vbox . $svgtag;
  8974. }
  8975. $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg' . $svgtag . '>', $svgimg, 1);
  8976. }
  8977. $img->readImageBlob($svgimg);
  8978. }
  8979. else
  8980. {
  8981. $img->readImage($file);
  8982. }
  8983. if ($resize)
  8984. {
  8985. $img->resizeImage($neww, $newh, 10, 1, false);
  8986. }
  8987. $img->setCompressionQuality($this->jpeg_quality);
  8988. $img->setImageFormat('jpeg');
  8989. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  8990. $img->writeImage($tempname);
  8991. $info = $this->_parsejpeg($tempname);
  8992. unlink($tempname);
  8993. $img->destroy();
  8994. }
  8995. else
  8996. {
  8997. return;
  8998. }
  8999. }
  9000. if ($info === false)
  9001. {
  9002. //If false, we cannot process image
  9003. return;
  9004. }
  9005. $this->set_mqr($mqr);
  9006. if ($ismask)
  9007. {
  9008. // force grayscale
  9009. $info['cs'] = 'DeviceGray';
  9010. }
  9011. $info['i'] = $this->numimages;
  9012. if (! in_array($file, $this->imagekeys))
  9013. {
  9014. ++ $info['i'];
  9015. }
  9016. if ($imgmask !== false)
  9017. {
  9018. $info['masked'] = $imgmask;
  9019. }
  9020. // add image to document
  9021. $this->setImageBuffer($file, $info);
  9022. }
  9023. if ($cached_file)
  9024. {
  9025. // remove cached file
  9026. unlink($file);
  9027. }
  9028. // set alignment
  9029. $this->img_rb_y = $y + $h;
  9030. // set alignment
  9031. if ($this->rtl)
  9032. {
  9033. if ($palign == 'L')
  9034. {
  9035. $ximg = $this->lMargin;
  9036. }
  9037. elseif ($palign == 'C')
  9038. {
  9039. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  9040. }
  9041. elseif ($palign == 'R')
  9042. {
  9043. $ximg = $this->w - $this->rMargin - $w;
  9044. }
  9045. else
  9046. {
  9047. $ximg = $x - $w;
  9048. }
  9049. $this->img_rb_x = $ximg;
  9050. }
  9051. else
  9052. {
  9053. if ($palign == 'L')
  9054. {
  9055. $ximg = $this->lMargin;
  9056. }
  9057. elseif ($palign == 'C')
  9058. {
  9059. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  9060. }
  9061. elseif ($palign == 'R')
  9062. {
  9063. $ximg = $this->w - $this->rMargin - $w;
  9064. }
  9065. else
  9066. {
  9067. $ximg = $x;
  9068. }
  9069. $this->img_rb_x = $ximg + $w;
  9070. }
  9071. if ($ismask or $hidden)
  9072. {
  9073. // image is not displayed
  9074. return $info['i'];
  9075. }
  9076. $xkimg = $ximg * $this->k;
  9077. $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%u Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - ($y + $h)) * $this->k), $info['i']));
  9078. if (! empty($border))
  9079. {
  9080. $bx = $this->x;
  9081. $by = $this->y;
  9082. $this->x = $ximg;
  9083. if ($this->rtl)
  9084. {
  9085. $this->x += $w;
  9086. }
  9087. $this->y = $y;
  9088. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  9089. $this->x = $bx;
  9090. $this->y = $by;
  9091. }
  9092. if ($link)
  9093. {
  9094. $this->Link($ximg, $y, $w, $h, $link, 0);
  9095. }
  9096. // set pointer to align the next text/objects
  9097. switch ($align)
  9098. {
  9099. case 'T' :
  9100. {
  9101. $this->y = $y;
  9102. $this->x = $this->img_rb_x;
  9103. break;
  9104. }
  9105. case 'M' :
  9106. {
  9107. $this->y = $y + round($h / 2);
  9108. $this->x = $this->img_rb_x;
  9109. break;
  9110. }
  9111. case 'B' :
  9112. {
  9113. $this->y = $this->img_rb_y;
  9114. $this->x = $this->img_rb_x;
  9115. break;
  9116. }
  9117. case 'N' :
  9118. {
  9119. $this->SetY($this->img_rb_y);
  9120. break;
  9121. }
  9122. default :
  9123. {
  9124. break;
  9125. }
  9126. }
  9127. $this->endlinex = $this->img_rb_x;
  9128. if ($this->inxobj)
  9129. {
  9130. // we are inside an XObject template
  9131. $this->xobjects[$this->xobjid]['images'][] = $info['i'];
  9132. }
  9133. return $info['i'];
  9134. }
  9135. /**
  9136. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  9137. * @param boolean $mqr FALSE for off, TRUE for on.
  9138. * @since 4.6.025 (2009-08-17)
  9139. */
  9140. public function set_mqr($mqr)
  9141. {
  9142. if (! defined('PHP_VERSION_ID'))
  9143. {
  9144. $version = PHP_VERSION;
  9145. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  9146. }
  9147. if (PHP_VERSION_ID < 50300)
  9148. {
  9149. @set_magic_quotes_runtime($mqr);
  9150. }
  9151. }
  9152. /**
  9153. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  9154. * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  9155. * @since 4.6.025 (2009-08-17)
  9156. */
  9157. public function get_mqr()
  9158. {
  9159. if (! defined('PHP_VERSION_ID'))
  9160. {
  9161. $version = PHP_VERSION;
  9162. define('PHP_VERSION_ID', (($version{0} * 10000) + ($version{2} * 100) + $version{4}));
  9163. }
  9164. if (PHP_VERSION_ID < 50300)
  9165. {
  9166. return @get_magic_quotes_runtime();
  9167. }
  9168. return 0;
  9169. }
  9170. /**
  9171. * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
  9172. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  9173. * @param string $file Image file name.
  9174. * @param image $image Image object.
  9175. * return image JPEG image object.
  9176. * @access protected
  9177. */
  9178. protected function _toJPEG($image)
  9179. {
  9180. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  9181. imagejpeg($image, $tempname, $this->jpeg_quality);
  9182. imagedestroy($image);
  9183. $retvars = $this->_parsejpeg($tempname);
  9184. // tidy up by removing temporary image
  9185. unlink($tempname);
  9186. return $retvars;
  9187. }
  9188. /**
  9189. * Convert the loaded image to a PNG and then return a structure for the PDF creator.
  9190. * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
  9191. * @param string $file Image file name.
  9192. * @param image $image Image object.
  9193. * return image PNG image object.
  9194. * @access protected
  9195. * @since 4.9.016 (2010-04-20)
  9196. */
  9197. protected function _toPNG($image)
  9198. {
  9199. $tempname = tempnam(K_PATH_CACHE, 'jpg_');
  9200. imagepng($image, $tempname);
  9201. imagedestroy($image);
  9202. $retvars = $this->_parsepng($tempname);
  9203. // tidy up by removing temporary image
  9204. unlink($tempname);
  9205. return $retvars;
  9206. }
  9207. /**
  9208. * Set the transparency for the given GD image.
  9209. * @param image $new_image GD image object
  9210. * @param image $image GD image object.
  9211. * return GD image object.
  9212. * @access protected
  9213. * @since 4.9.016 (2010-04-20)
  9214. */
  9215. protected function _setGDImageTransparency($new_image, $image)
  9216. {
  9217. // transparency index
  9218. $tid = imagecolortransparent($image);
  9219. // default transparency color
  9220. $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
  9221. if ($tid >= 0)
  9222. {
  9223. // get the colors for the transparency index
  9224. $tcol = imagecolorsforindex($image, $tid);
  9225. }
  9226. $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
  9227. imagefill($new_image, 0, 0, $tid);
  9228. imagecolortransparent($new_image, $tid);
  9229. return $new_image;
  9230. }
  9231. /**
  9232. * Extract info from a JPEG file without using the GD library.
  9233. * @param string $file image file to parse
  9234. * @return array structure containing the image data
  9235. * @access protected
  9236. */
  9237. protected function _parsejpeg($file)
  9238. {
  9239. $a = getimagesize($file);
  9240. if (empty($a))
  9241. {
  9242. $this->Error('Missing or incorrect image file: ' . $file);
  9243. }
  9244. if ($a[2] != 2)
  9245. {
  9246. $this->Error('Not a JPEG file: ' . $file);
  9247. }
  9248. if ((! isset($a['channels'])) or ($a['channels'] == 3))
  9249. {
  9250. $colspace = 'DeviceRGB';
  9251. }
  9252. elseif ($a['channels'] == 4)
  9253. {
  9254. $colspace = 'DeviceCMYK';
  9255. }
  9256. else
  9257. {
  9258. $colspace = 'DeviceGray';
  9259. }
  9260. $bpc = isset($a['bits']) ? $a['bits'] : 8;
  9261. $data = file_get_contents($file);
  9262. return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
  9263. }
  9264. /**
  9265. * Extract info from a PNG file without using the GD library.
  9266. * @param string $file image file to parse
  9267. * @return array structure containing the image data
  9268. * @access protected
  9269. */
  9270. protected function _parsepng($file)
  9271. {
  9272. $f = fopen($file, 'rb');
  9273. if ($f === false)
  9274. {
  9275. $this->Error('Can\'t open image file: ' . $file);
  9276. }
  9277. //Check signature
  9278. if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10))
  9279. {
  9280. $this->Error('Not a PNG file: ' . $file);
  9281. }
  9282. //Read header chunk
  9283. fread($f, 4);
  9284. if (fread($f, 4) != 'IHDR')
  9285. {
  9286. $this->Error('Incorrect PNG file: ' . $file);
  9287. }
  9288. $w = $this->_freadint($f);
  9289. $h = $this->_freadint($f);
  9290. $bpc = ord(fread($f, 1));
  9291. if ($bpc > 8)
  9292. {
  9293. //$this->Error('16-bit depth not supported: '.$file);
  9294. fclose($f);
  9295. return false;
  9296. }
  9297. $ct = ord(fread($f, 1));
  9298. if ($ct == 0)
  9299. {
  9300. $colspace = 'DeviceGray';
  9301. }
  9302. elseif ($ct == 2)
  9303. {
  9304. $colspace = 'DeviceRGB';
  9305. }
  9306. elseif ($ct == 3)
  9307. {
  9308. $colspace = 'Indexed';
  9309. }
  9310. else
  9311. {
  9312. // alpha channel
  9313. fclose($f);
  9314. return 'pngalpha';
  9315. }
  9316. if (ord(fread($f, 1)) != 0)
  9317. {
  9318. //$this->Error('Unknown compression method: '.$file);
  9319. fclose($f);
  9320. return false;
  9321. }
  9322. if (ord(fread($f, 1)) != 0)
  9323. {
  9324. //$this->Error('Unknown filter method: '.$file);
  9325. fclose($f);
  9326. return false;
  9327. }
  9328. if (ord(fread($f, 1)) != 0)
  9329. {
  9330. //$this->Error('Interlacing not supported: '.$file);
  9331. fclose($f);
  9332. return false;
  9333. }
  9334. fread($f, 4);
  9335. $parms = '/DecodeParms << /Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . ' >>';
  9336. //Scan chunks looking for palette, transparency and image data
  9337. $pal = '';
  9338. $trns = '';
  9339. $data = '';
  9340. do
  9341. {
  9342. $n = $this->_freadint($f);
  9343. $type = fread($f, 4);
  9344. if ($type == 'PLTE')
  9345. {
  9346. //Read palette
  9347. $pal = $this->rfread($f, $n);
  9348. fread($f, 4);
  9349. }
  9350. elseif ($type == 'tRNS')
  9351. {
  9352. //Read transparency info
  9353. $t = $this->rfread($f, $n);
  9354. if ($ct == 0)
  9355. {
  9356. $trns = array(ord(substr($t, 1, 1)));
  9357. }
  9358. elseif ($ct == 2)
  9359. {
  9360. $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
  9361. }
  9362. else
  9363. {
  9364. $pos = strpos($t, chr(0));
  9365. if ($pos !== false)
  9366. {
  9367. $trns = array($pos);
  9368. }
  9369. }
  9370. fread($f, 4);
  9371. }
  9372. elseif ($type == 'IDAT')
  9373. {
  9374. //Read image data block
  9375. $data .= $this->rfread($f, $n);
  9376. fread($f, 4);
  9377. }
  9378. elseif ($type == 'IEND')
  9379. {
  9380. break;
  9381. }
  9382. else
  9383. {
  9384. $this->rfread($f, $n + 4);
  9385. }
  9386. }
  9387. while ($n);
  9388. if (($colspace == 'Indexed') and (empty($pal)))
  9389. {
  9390. //$this->Error('Missing palette in '.$file);
  9391. fclose($f);
  9392. return false;
  9393. }
  9394. fclose($f);
  9395. return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms,
  9396. 'pal' => $pal, 'trns' => $trns, 'data' => $data);
  9397. }
  9398. /**
  9399. * Binary-safe and URL-safe file read.
  9400. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
  9401. * @param resource $handle
  9402. * @param int $length
  9403. * @return Returns the read string or FALSE in case of error.
  9404. * @author Nicola Asuni
  9405. * @access protected
  9406. * @since 4.5.027 (2009-03-16)
  9407. */
  9408. protected function rfread($handle, $length)
  9409. {
  9410. $data = fread($handle, $length);
  9411. if ($data === false)
  9412. {
  9413. return false;
  9414. }
  9415. $rest = $length - strlen($data);
  9416. if ($rest > 0)
  9417. {
  9418. $data .= $this->rfread($handle, $rest);
  9419. }
  9420. return $data;
  9421. }
  9422. /**
  9423. * Extract info from a PNG image with alpha channel using the GD library.
  9424. * @param string $file Name of the file containing the image.
  9425. * @param float $x Abscissa of the upper-left corner.
  9426. * @param float $y Ordinate of the upper-left corner.
  9427. * @param float $wpx Original width of the image in pixels.
  9428. * @param float $hpx original height of the image in pixels.
  9429. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9430. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  9431. * @param string $type Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  9432. * @param mixed $link URL or identifier returned by AddLink().
  9433. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  9434. * @param boolean $resize If true resize (reduce) the image to fit $w and $h (requires GD library).
  9435. * @param int $dpi dot-per-inch resolution used on resize
  9436. * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  9437. * @author Nicola Asuni
  9438. * @access protected
  9439. * @since 4.3.007 (2008-12-04)
  9440. * @see Image()
  9441. */
  9442. protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign)
  9443. {
  9444. // create temp image file (without alpha channel)
  9445. $tempfile_plain = tempnam(K_PATH_CACHE, 'mskp_');
  9446. // create temp alpha file
  9447. $tempfile_alpha = tempnam(K_PATH_CACHE, 'mska_');
  9448. if (extension_loaded('imagick'))
  9449. { // ImageMagick
  9450. // ImageMagick library
  9451. $img = new Imagick();
  9452. $img->readImage($file);
  9453. // clone image object
  9454. $imga = $img->clone();
  9455. // extract alpha channel
  9456. $img->separateImageChannel(imagick :: CHANNEL_ALPHA | imagick :: CHANNEL_OPACITY | imagick :: CHANNEL_MATTE);
  9457. $img->negateImage(true);
  9458. $img->setImageFormat('png');
  9459. $img->writeImage($tempfile_alpha);
  9460. // remove alpha channel
  9461. $imga->separateImageChannel(imagick :: CHANNEL_ALL & ~ (imagick :: CHANNEL_ALPHA | imagick :: CHANNEL_OPACITY | imagick :: CHANNEL_MATTE));
  9462. $imga->setImageFormat('png');
  9463. $imga->writeImage($tempfile_plain);
  9464. }
  9465. else
  9466. { // GD library
  9467. // generate images
  9468. $img = imagecreatefrompng($file);
  9469. $imgalpha = imagecreate($wpx, $hpx);
  9470. // generate gray scale palette (0 -> 255)
  9471. for($c = 0; $c < 256; ++ $c)
  9472. {
  9473. ImageColorAllocate($imgalpha, $c, $c, $c);
  9474. }
  9475. // extract alpha channel
  9476. for($xpx = 0; $xpx < $wpx; ++ $xpx)
  9477. {
  9478. for($ypx = 0; $ypx < $hpx; ++ $ypx)
  9479. {
  9480. $color = imagecolorat($img, $xpx, $ypx);
  9481. $alpha = ($color >> 24); // shifts off the first 24 bits (where 8x3 are used for each color), and returns the remaining 7 allocated bits (commonly used for alpha)
  9482. $alpha = (((127 - $alpha) / 127) * 255); // GD alpha is only 7 bit (0 -> 127)
  9483. $alpha = $this->getGDgamma($alpha); // correct gamma
  9484. imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
  9485. }
  9486. }
  9487. imagepng($imgalpha, $tempfile_alpha);
  9488. imagedestroy($imgalpha);
  9489. // extract image without alpha channel
  9490. $imgplain = imagecreatetruecolor($wpx, $hpx);
  9491. imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
  9492. imagepng($imgplain, $tempfile_plain);
  9493. imagedestroy($imgplain);
  9494. }
  9495. // embed mask image
  9496. $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
  9497. // embed image, masked with previously embedded mask
  9498. $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
  9499. // remove temp files
  9500. unlink($tempfile_alpha);
  9501. unlink($tempfile_plain);
  9502. }
  9503. /**
  9504. * Correct the gamma value to be used with GD library
  9505. * @param float $v the gamma value to be corrected
  9506. * @access protected
  9507. * @since 4.3.007 (2008-12-04)
  9508. */
  9509. protected function getGDgamma($v)
  9510. {
  9511. return (pow(($v / 255), 2.2) * 255);
  9512. }
  9513. /**
  9514. * Performs a line break.
  9515. * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  9516. * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  9517. * @param boolean $cell if true add the current left (or right o for RTL) padding to the X coordinate
  9518. * @access public
  9519. * @since 1.0
  9520. * @see Cell()
  9521. */
  9522. public function Ln($h = '', $cell = false)
  9523. {
  9524. 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']))
  9525. {
  9526. // revove vertical space from the top of the column
  9527. return;
  9528. }
  9529. if ($cell)
  9530. {
  9531. if ($this->rtl)
  9532. {
  9533. $cellpadding = $this->cell_padding['R'];
  9534. }
  9535. else
  9536. {
  9537. $cellpadding = $this->cell_padding['L'];
  9538. }
  9539. }
  9540. else
  9541. {
  9542. $cellpadding = 0;
  9543. }
  9544. if ($this->rtl)
  9545. {
  9546. $this->x = $this->w - $this->rMargin - $cellpadding;
  9547. }
  9548. else
  9549. {
  9550. $this->x = $this->lMargin + $cellpadding;
  9551. }
  9552. if (is_string($h))
  9553. {
  9554. $this->y += $this->lasth;
  9555. }
  9556. else
  9557. {
  9558. $this->y += $h;
  9559. }
  9560. $this->newline = true;
  9561. }
  9562. /**
  9563. * Returns the relative X value of current position.
  9564. * The value is relative to the left border for LTR languages and to the right border for RTL languages.
  9565. * @return float
  9566. * @access public
  9567. * @since 1.2
  9568. * @see SetX(), GetY(), SetY()
  9569. */
  9570. public function GetX()
  9571. {
  9572. //Get x position
  9573. if ($this->rtl)
  9574. {
  9575. return ($this->w - $this->x);
  9576. }
  9577. else
  9578. {
  9579. return $this->x;
  9580. }
  9581. }
  9582. /**
  9583. * Returns the absolute X value of current position.
  9584. * @return float
  9585. * @access public
  9586. * @since 1.2
  9587. * @see SetX(), GetY(), SetY()
  9588. */
  9589. public function GetAbsX()
  9590. {
  9591. return $this->x;
  9592. }
  9593. /**
  9594. * Returns the ordinate of the current position.
  9595. * @return float
  9596. * @access public
  9597. * @since 1.0
  9598. * @see SetY(), GetX(), SetX()
  9599. */
  9600. public function GetY()
  9601. {
  9602. return $this->y;
  9603. }
  9604. /**
  9605. * Defines the abscissa of the current position.
  9606. * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
  9607. * @param float $x The value of the abscissa.
  9608. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  9609. * @access public
  9610. * @since 1.2
  9611. * @see GetX(), GetY(), SetY(), SetXY()
  9612. */
  9613. public function SetX($x, $rtloff = false)
  9614. {
  9615. if (! $rtloff and $this->rtl)
  9616. {
  9617. if ($x >= 0)
  9618. {
  9619. $this->x = $this->w - $x;
  9620. }
  9621. else
  9622. {
  9623. $this->x = abs($x);
  9624. }
  9625. }
  9626. else
  9627. {
  9628. if ($x >= 0)
  9629. {
  9630. $this->x = $x;
  9631. }
  9632. else
  9633. {
  9634. $this->x = $this->w + $x;
  9635. }
  9636. }
  9637. if ($this->x < 0)
  9638. {
  9639. $this->x = 0;
  9640. }
  9641. if ($this->x > $this->w)
  9642. {
  9643. $this->x = $this->w;
  9644. }
  9645. }
  9646. /**
  9647. * Moves the current abscissa back to the left margin and sets the ordinate.
  9648. * If the passed value is negative, it is relative to the bottom of the page.
  9649. * @param float $y The value of the ordinate.
  9650. * @param bool $resetx if true (default) reset the X position.
  9651. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  9652. * @access public
  9653. * @since 1.0
  9654. * @see GetX(), GetY(), SetY(), SetXY()
  9655. */
  9656. public function SetY($y, $resetx = true, $rtloff = false)
  9657. {
  9658. if ($resetx)
  9659. {
  9660. //reset x
  9661. if (! $rtloff and $this->rtl)
  9662. {
  9663. $this->x = $this->w - $this->rMargin;
  9664. }
  9665. else
  9666. {
  9667. $this->x = $this->lMargin;
  9668. }
  9669. }
  9670. if ($y >= 0)
  9671. {
  9672. $this->y = $y;
  9673. }
  9674. else
  9675. {
  9676. $this->y = $this->h + $y;
  9677. }
  9678. if ($this->y < 0)
  9679. {
  9680. $this->y = 0;
  9681. }
  9682. if ($this->y > $this->h)
  9683. {
  9684. $this->y = $this->h;
  9685. }
  9686. }
  9687. /**
  9688. * Defines the abscissa and ordinate of the current position.
  9689. * If the passed values are negative, they are relative respectively to the right and bottom of the page.
  9690. * @param float $x The value of the abscissa.
  9691. * @param float $y The value of the ordinate.
  9692. * @param boolean $rtloff if true always uses the page top-left corner as origin of axis.
  9693. * @access public
  9694. * @since 1.2
  9695. * @see SetX(), SetY()
  9696. */
  9697. public function SetXY($x, $y, $rtloff = false)
  9698. {
  9699. $this->SetY($y, false, $rtloff);
  9700. $this->SetX($x, $rtloff);
  9701. }
  9702. /**
  9703. * Send the document to a given destination: string, local file or browser.
  9704. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  9705. * The method first calls Close() if necessary to terminate the document.
  9706. * @param string $name The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
  9707. * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li></ul>
  9708. * @access public
  9709. * @since 1.0
  9710. * @see Close()
  9711. */
  9712. public function Output($name = 'doc.pdf', $dest = 'I')
  9713. {
  9714. //Output PDF to some destination
  9715. //Finish document if necessary
  9716. if ($this->state < 3)
  9717. {
  9718. $this->Close();
  9719. }
  9720. //Normalize parameters
  9721. if (is_bool($dest))
  9722. {
  9723. $dest = $dest ? 'D' : 'F';
  9724. }
  9725. $dest = strtoupper($dest);
  9726. if ($dest{0} != 'F')
  9727. {
  9728. $name = preg_replace('/[\s]+/', '_', $name);
  9729. $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
  9730. }
  9731. if ($this->sign)
  9732. {
  9733. // *** apply digital signature to the document ***
  9734. // get the document content
  9735. $pdfdoc = $this->getBuffer();
  9736. // remove last newline
  9737. $pdfdoc = substr($pdfdoc, 0, - 1);
  9738. // Remove the original buffer
  9739. if (isset($this->diskcache) and $this->diskcache)
  9740. {
  9741. // remove buffer file from cache
  9742. unlink($this->buffer);
  9743. }
  9744. unset($this->buffer);
  9745. // remove filler space
  9746. $byterange_string_len = strlen($this->byterange_string);
  9747. // define the ByteRange
  9748. $byte_range = array();
  9749. $byte_range[0] = 0;
  9750. $byte_range[1] = strpos($pdfdoc, $this->byterange_string) + $byterange_string_len + 10;
  9751. $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2;
  9752. $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
  9753. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . substr($pdfdoc, $byte_range[2]);
  9754. // replace the ByteRange
  9755. $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
  9756. $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
  9757. $pdfdoc = str_replace($this->byterange_string, $byterange, $pdfdoc);
  9758. // write the document to a temporary folder
  9759. $tempdoc = tempnam(K_PATH_CACHE, 'tmppdf_');
  9760. $f = fopen($tempdoc, 'wb');
  9761. if (! $f)
  9762. {
  9763. $this->Error('Unable to create temporary file: ' . $tempdoc);
  9764. }
  9765. $pdfdoc_length = strlen($pdfdoc);
  9766. fwrite($f, $pdfdoc, $pdfdoc_length);
  9767. fclose($f);
  9768. // get digital signature via openssl library
  9769. $tempsign = tempnam(K_PATH_CACHE, 'tmpsig_');
  9770. if (empty($this->signature_data['extracerts']))
  9771. {
  9772. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array(
  9773. $this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
  9774. }
  9775. else
  9776. {
  9777. openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array(
  9778. $this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']);
  9779. }
  9780. unlink($tempdoc);
  9781. // read signature
  9782. $signature = file_get_contents($tempsign);
  9783. unlink($tempsign);
  9784. // extract signature
  9785. $signature = substr($signature, $pdfdoc_length);
  9786. $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") + 13));
  9787. $tmparr = explode("\n\n", $signature);
  9788. $signature = $tmparr[1];
  9789. unset($tmparr);
  9790. // decode signature
  9791. $signature = base64_decode(trim($signature));
  9792. // convert signature to hex
  9793. $signature = current(unpack('H*', $signature));
  9794. $signature = str_pad($signature, $this->signature_max_length, '0');
  9795. // Add signature to the document
  9796. $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . '<' . $signature . '>' . substr($pdfdoc, $byte_range[1]);
  9797. $this->diskcache = false;
  9798. $this->buffer = &$pdfdoc;
  9799. $this->bufferlen = strlen($pdfdoc);
  9800. }
  9801. switch ($dest)
  9802. {
  9803. case 'I' :
  9804. {
  9805. // Send PDF to the standard output
  9806. if (ob_get_contents())
  9807. {
  9808. $this->Error('Some data has already been output, can\'t send PDF file');
  9809. }
  9810. if (php_sapi_name() != 'cli')
  9811. {
  9812. //We send to a browser
  9813. header('Content-Type: application/pdf');
  9814. if (headers_sent())
  9815. {
  9816. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9817. }
  9818. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9819. header('Pragma: public');
  9820. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9821. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9822. header('Content-Length: ' . $this->bufferlen);
  9823. header('Content-Disposition: inline; filename="' . basename($name) . '";');
  9824. }
  9825. echo $this->getBuffer();
  9826. break;
  9827. }
  9828. case 'D' :
  9829. {
  9830. // Download PDF as file
  9831. if (ob_get_contents())
  9832. {
  9833. $this->Error('Some data has already been output, can\'t send PDF file');
  9834. }
  9835. header('Content-Description: File Transfer');
  9836. if (headers_sent())
  9837. {
  9838. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9839. }
  9840. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9841. header('Pragma: public');
  9842. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9843. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9844. // force download dialog
  9845. header('Content-Type: application/force-download');
  9846. header('Content-Type: application/octet-stream', false);
  9847. header('Content-Type: application/download', false);
  9848. header('Content-Type: application/pdf', false);
  9849. // use the Content-Disposition header to supply a recommended filename
  9850. header('Content-Disposition: attachment; filename="' . basename($name) . '";');
  9851. header('Content-Transfer-Encoding: binary');
  9852. header('Content-Length: ' . $this->bufferlen);
  9853. echo $this->getBuffer();
  9854. break;
  9855. }
  9856. case 'F' :
  9857. case 'FI' :
  9858. case 'FD' :
  9859. {
  9860. // Save PDF to a local file
  9861. if ($this->diskcache)
  9862. {
  9863. copy($this->buffer, $name);
  9864. }
  9865. else
  9866. {
  9867. $f = fopen($name, 'wb');
  9868. if (! $f)
  9869. {
  9870. $this->Error('Unable to create output file: ' . $name);
  9871. }
  9872. fwrite($f, $this->getBuffer(), $this->bufferlen);
  9873. fclose($f);
  9874. }
  9875. if ($dest == 'FI')
  9876. {
  9877. // send headers to browser
  9878. header('Content-Type: application/pdf');
  9879. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9880. header('Pragma: public');
  9881. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9882. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9883. header('Content-Length: ' . filesize($name));
  9884. header('Content-Disposition: inline; filename="' . basename($name) . '";');
  9885. // send document to the browser
  9886. echo file_get_contents($name);
  9887. }
  9888. elseif ($dest == 'FD')
  9889. {
  9890. // send headers to browser
  9891. if (ob_get_contents())
  9892. {
  9893. $this->Error('Some data has already been output, can\'t send PDF file');
  9894. }
  9895. header('Content-Description: File Transfer');
  9896. if (headers_sent())
  9897. {
  9898. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  9899. }
  9900. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  9901. header('Pragma: public');
  9902. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  9903. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  9904. // force download dialog
  9905. header('Content-Type: application/force-download');
  9906. header('Content-Type: application/octet-stream', false);
  9907. header('Content-Type: application/download', false);
  9908. header('Content-Type: application/pdf', false);
  9909. // use the Content-Disposition header to supply a recommended filename
  9910. header('Content-Disposition: attachment; filename="' . basename($name) . '";');
  9911. header('Content-Transfer-Encoding: binary');
  9912. header('Content-Length: ' . filesize($name));
  9913. // send document to the browser
  9914. echo file_get_contents($name);
  9915. }
  9916. break;
  9917. }
  9918. case 'S' :
  9919. {
  9920. // Returns PDF as a string
  9921. return $this->getBuffer();
  9922. }
  9923. default :
  9924. {
  9925. $this->Error('Incorrect output destination: ' . $dest);
  9926. }
  9927. }
  9928. return '';
  9929. }
  9930. /**
  9931. * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
  9932. * @param boolean $destroyall if true destroys all class variables, otherwise preserves critical variables.
  9933. * @param boolean $preserve_objcopy if true preserves the objcopy variable
  9934. * @access public
  9935. * @since 4.5.016 (2009-02-24)
  9936. */
  9937. public function _destroy($destroyall = false, $preserve_objcopy = false)
  9938. {
  9939. if ($destroyall and isset($this->diskcache) and $this->diskcache and (! $preserve_objcopy) and (! $this->empty_string($this->buffer)))
  9940. {
  9941. // remove buffer file from cache
  9942. unlink($this->buffer);
  9943. }
  9944. foreach (array_keys(get_object_vars($this)) as $val)
  9945. {
  9946. if ($destroyall or (($val != 'internal_encoding') and ($val != 'state') and ($val != 'bufferlen') and ($val != 'buffer') and ($val != 'diskcache') and ($val != 'sign') and ($val != 'signature_data') and ($val != 'signature_max_length') and ($val != 'byterange_string')))
  9947. {
  9948. if ((! $preserve_objcopy or ($val != 'objcopy')) and isset($this->$val))
  9949. {
  9950. unset($this->$val);
  9951. }
  9952. }
  9953. }
  9954. }
  9955. /**
  9956. * Check for locale-related bug
  9957. * @access protected
  9958. */
  9959. protected function _dochecks()
  9960. {
  9961. //Check for locale-related bug
  9962. if (1.1 == 1)
  9963. {
  9964. $this->Error('Don\'t alter the locale before including class file');
  9965. }
  9966. //Check for decimal separator
  9967. if (sprintf('%.1F', 1.0) != '1.0')
  9968. {
  9969. setlocale(LC_NUMERIC, 'C');
  9970. }
  9971. }
  9972. /**
  9973. * Return fonts path
  9974. * @return string
  9975. * @access protected
  9976. */
  9977. protected function _getfontpath()
  9978. {
  9979. if (! defined('K_PATH_FONTS') and is_dir(dirname(__FILE__) . '/fonts'))
  9980. {
  9981. define('K_PATH_FONTS', dirname(__FILE__) . '/fonts/');
  9982. }
  9983. return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
  9984. }
  9985. /**
  9986. * Output pages.
  9987. * @access protected
  9988. */
  9989. protected function _putpages()
  9990. {
  9991. $nb = $this->numpages;
  9992. if (! empty($this->AliasNbPages))
  9993. {
  9994. $nbs = $this->formatPageNumber($nb);
  9995. $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
  9996. $alias_a = $this->_escape($this->AliasNbPages);
  9997. $alias_au = $this->_escape('{' . $this->AliasNbPages . '}');
  9998. if ($this->isunicode)
  9999. {
  10000. $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
  10001. $alias_bu = $this->_escape($this->UTF8ToLatin1('{' . $this->AliasNbPages . '}'));
  10002. $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages, false, $this->tmprtl));
  10003. $alias_cu = $this->_escape($this->utf8StrRev('{' . $this->AliasNbPages . '}', false, $this->tmprtl));
  10004. }
  10005. }
  10006. if (! empty($this->AliasNumPage))
  10007. {
  10008. $alias_pa = $this->_escape($this->AliasNumPage);
  10009. $alias_pau = $this->_escape('{' . $this->AliasNumPage . '}');
  10010. if ($this->isunicode)
  10011. {
  10012. $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
  10013. $alias_pbu = $this->_escape($this->UTF8ToLatin1('{' . $this->AliasNumPage . '}'));
  10014. $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage, false, $this->tmprtl));
  10015. $alias_pcu = $this->_escape($this->utf8StrRev('{' . $this->AliasNumPage . '}', false, $this->tmprtl));
  10016. }
  10017. }
  10018. $pagegroupnum = 0;
  10019. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  10020. for($n = 1; $n <= $nb; ++ $n)
  10021. {
  10022. $temppage = $this->getPageBuffer($n);
  10023. if (! empty($this->pagegroups))
  10024. {
  10025. if (isset($this->newpagegroup[$n]))
  10026. {
  10027. $pagegroupnum = 0;
  10028. }
  10029. ++ $pagegroupnum;
  10030. foreach ($this->pagegroups as $k => $v)
  10031. {
  10032. // replace total pages group numbers
  10033. $vs = $this->formatPageNumber($v);
  10034. $vu = $this->UTF8ToUTF16BE($vs, false);
  10035. $alias_ga = $this->_escape($k);
  10036. $alias_gau = $this->_escape('{' . $k . '}');
  10037. if ($this->isunicode)
  10038. {
  10039. $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
  10040. $alias_gbu = $this->_escape($this->UTF8ToLatin1('{' . $k . '}'));
  10041. $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  10042. $alias_gcu = $this->_escape($this->utf8StrRev('{' . $k . '}', false, $this->tmprtl));
  10043. }
  10044. $temppage = str_replace($alias_gau, $vu, $temppage);
  10045. if ($this->isunicode)
  10046. {
  10047. $temppage = str_replace($alias_gbu, $vu, $temppage);
  10048. $temppage = str_replace($alias_gcu, $vu, $temppage);
  10049. $temppage = str_replace($alias_gb, $vs, $temppage);
  10050. $temppage = str_replace($alias_gc, $vs, $temppage);
  10051. }
  10052. $temppage = str_replace($alias_ga, $vs, $temppage);
  10053. // replace page group numbers
  10054. $pvs = $this->formatPageNumber($pagegroupnum);
  10055. $pvu = $this->UTF8ToUTF16BE($pvs, false);
  10056. $pk = str_replace('{nb', '{pnb', $k);
  10057. $alias_pga = $this->_escape($pk);
  10058. $alias_pgau = $this->_escape('{' . $pk . '}');
  10059. if ($this->isunicode)
  10060. {
  10061. $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
  10062. $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{' . $pk . '}'));
  10063. $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl));
  10064. $alias_pgcu = $this->_escape($this->utf8StrRev('{' . $pk . '}', false, $this->tmprtl));
  10065. }
  10066. $temppage = str_replace($alias_pgau, $pvu, $temppage);
  10067. if ($this->isunicode)
  10068. {
  10069. $temppage = str_replace($alias_pgbu, $pvu, $temppage);
  10070. $temppage = str_replace($alias_pgcu, $pvu, $temppage);
  10071. $temppage = str_replace($alias_pgb, $pvs, $temppage);
  10072. $temppage = str_replace($alias_pgc, $pvs, $temppage);
  10073. }
  10074. $temppage = str_replace($alias_pga, $pvs, $temppage);
  10075. }
  10076. }
  10077. if (! empty($this->AliasNbPages))
  10078. {
  10079. // replace total pages number
  10080. $temppage = str_replace($alias_au, $nbu, $temppage);
  10081. if ($this->isunicode)
  10082. {
  10083. $temppage = str_replace($alias_bu, $nbu, $temppage);
  10084. $temppage = str_replace($alias_cu, $nbu, $temppage);
  10085. $temppage = str_replace($alias_b, $nbs, $temppage);
  10086. $temppage = str_replace($alias_c, $nbs, $temppage);
  10087. }
  10088. $temppage = str_replace($alias_a, $nbs, $temppage);
  10089. }
  10090. if (! empty($this->AliasNumPage))
  10091. {
  10092. // replace page number
  10093. $pnbs = $this->formatPageNumber($n);
  10094. $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
  10095. $temppage = str_replace($alias_pau, $pnbu, $temppage);
  10096. if ($this->isunicode)
  10097. {
  10098. $temppage = str_replace($alias_pbu, $pnbu, $temppage);
  10099. $temppage = str_replace($alias_pcu, $pnbu, $temppage);
  10100. $temppage = str_replace($alias_pb, $pnbs, $temppage);
  10101. $temppage = str_replace($alias_pc, $pnbs, $temppage);
  10102. }
  10103. $temppage = str_replace($alias_pa, $pnbs, $temppage);
  10104. }
  10105. $temppage = str_replace($this->epsmarker, '', $temppage);
  10106. //Page
  10107. $this->page_obj_id[$n] = $this->_newobj();
  10108. $out = '<<';
  10109. $out .= ' /Type /Page';
  10110. $out .= ' /Parent 1 0 R';
  10111. $out .= ' /LastModified ' . $this->_datestring();
  10112. $out .= ' /Resources 2 0 R';
  10113. $boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  10114. foreach ($boxes as $box)
  10115. {
  10116. $out .= ' /' . $box;
  10117. $out .= sprintf(' [%.2F %.2F %.2F %.2F]', $this->pagedim[$n][$box]['llx'], $this->pagedim[$n][$box]['lly'], $this->pagedim[$n][$box]['urx'], $this->pagedim[$n][$box]['ury']);
  10118. }
  10119. if (isset($this->pagedim[$n]['BoxColorInfo']) and ! empty($this->pagedim[$n]['BoxColorInfo']))
  10120. {
  10121. $out .= ' /BoxColorInfo <<';
  10122. foreach ($boxes as $box)
  10123. {
  10124. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]))
  10125. {
  10126. $out .= ' /' . $box . ' <<';
  10127. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['C']))
  10128. {
  10129. $color = $this->pagedim[$n]['BoxColorInfo'][$box]['C'];
  10130. $out .= ' /C [';
  10131. $out .= sprintf(' %.3F %.3F %.3F', $color[0] / 255, $color[1] / 255, $color[2] / 255);
  10132. $out .= ' ]';
  10133. }
  10134. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['W']))
  10135. {
  10136. $out .= ' /W ' . ($this->pagedim[$n]['BoxColorInfo'][$box]['W'] * $this->k);
  10137. }
  10138. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['S']))
  10139. {
  10140. $out .= ' /S /' . $this->pagedim[$n]['BoxColorInfo'][$box]['S'];
  10141. }
  10142. if (isset($this->pagedim[$n]['BoxColorInfo'][$box]['D']))
  10143. {
  10144. $dashes = $this->pagedim[$n]['BoxColorInfo'][$box]['D'];
  10145. $out .= ' /D [';
  10146. foreach ($dashes as $dash)
  10147. {
  10148. $out .= sprintf(' %.3F', ($dash * $this->k));
  10149. }
  10150. $out .= ' ]';
  10151. }
  10152. $out .= ' >>';
  10153. }
  10154. }
  10155. $out .= ' >>';
  10156. }
  10157. $out .= ' /Contents ' . ($this->n + 1) . ' 0 R';
  10158. $out .= ' /Rotate ' . $this->pagedim[$n]['Rotate'];
  10159. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
  10160. if (isset($this->pagedim[$n]['trans']) and ! empty($this->pagedim[$n]['trans']))
  10161. {
  10162. // page transitions
  10163. if (isset($this->pagedim[$n]['trans']['Dur']))
  10164. {
  10165. $out .= ' /Dur ' . $this->pagedim[$n]['trans']['Dur'];
  10166. }
  10167. $out .= ' /Trans <<';
  10168. $out .= ' /Type /Trans';
  10169. if (isset($this->pagedim[$n]['trans']['S']))
  10170. {
  10171. $out .= ' /S /' . $this->pagedim[$n]['trans']['S'];
  10172. }
  10173. if (isset($this->pagedim[$n]['trans']['D']))
  10174. {
  10175. $out .= ' /D ' . $this->pagedim[$n]['trans']['D'];
  10176. }
  10177. if (isset($this->pagedim[$n]['trans']['Dm']))
  10178. {
  10179. $out .= ' /Dm /' . $this->pagedim[$n]['trans']['Dm'];
  10180. }
  10181. if (isset($this->pagedim[$n]['trans']['M']))
  10182. {
  10183. $out .= ' /M /' . $this->pagedim[$n]['trans']['M'];
  10184. }
  10185. if (isset($this->pagedim[$n]['trans']['Di']))
  10186. {
  10187. $out .= ' /Di ' . $this->pagedim[$n]['trans']['Di'];
  10188. }
  10189. if (isset($this->pagedim[$n]['trans']['SS']))
  10190. {
  10191. $out .= ' /SS ' . $this->pagedim[$n]['trans']['SS'];
  10192. }
  10193. if (isset($this->pagedim[$n]['trans']['B']))
  10194. {
  10195. $out .= ' /B ' . $this->pagedim[$n]['trans']['B'];
  10196. }
  10197. $out .= ' >>';
  10198. }
  10199. $out .= $this->_getannotsrefs($n);
  10200. $out .= ' /PZ ' . $this->pagedim[$n]['PZ'];
  10201. $out .= ' >>';
  10202. $out .= "\n" . 'endobj';
  10203. $this->_out($out);
  10204. //Page content
  10205. $p = ($this->compress) ? gzcompress($temppage) : $temppage;
  10206. $this->_newobj();
  10207. $p = $this->_getrawstream($p);
  10208. $this->_out('<<' . $filter . '/Length ' . strlen($p) . '>> stream' . "\n" . $p . "\n" . 'endstream' . "\n" . 'endobj');
  10209. if ($this->diskcache)
  10210. {
  10211. // remove temporary files
  10212. unlink($this->pages[$n]);
  10213. }
  10214. }
  10215. //Pages root
  10216. $out = $this->_getobj(1) . "\n";
  10217. $out .= '<< /Type /Pages /Kids [';
  10218. foreach ($this->page_obj_id as $page_obj)
  10219. {
  10220. $out .= ' ' . $page_obj . ' 0 R';
  10221. }
  10222. $out .= ' ] /Count ' . $nb . ' >>';
  10223. $out .= "\n" . 'endobj';
  10224. $this->_out($out);
  10225. }
  10226. /**
  10227. * Output references to page annotations
  10228. * @param int $n page number
  10229. * @access protected
  10230. * @author Nicola Asuni
  10231. * @since 4.7.000 (2008-08-29)
  10232. * @deprecated
  10233. */
  10234. protected function _putannotsrefs($n)
  10235. {
  10236. $this->_out($this->_getannotsrefs($n));
  10237. }
  10238. /**
  10239. * Get references to page annotations.
  10240. * @param int $n page number
  10241. * @return string
  10242. * @access protected
  10243. * @author Nicola Asuni
  10244. * @since 5.0.010 (2010-05-17)
  10245. */
  10246. protected function _getannotsrefs($n)
  10247. {
  10248. if (! (isset($this->PageAnnots[$n]) or ($this->sign and isset($this->signature_data['cert_type']))))
  10249. {
  10250. return '';
  10251. }
  10252. $out = ' /Annots [';
  10253. if (isset($this->PageAnnots[$n]))
  10254. {
  10255. foreach ($this->PageAnnots[$n] as $key => $val)
  10256. {
  10257. if (! in_array($val['n'], $this->radio_groups))
  10258. {
  10259. $out .= ' ' . $val['n'] . ' 0 R';
  10260. }
  10261. }
  10262. // add radiobutton groups
  10263. if (isset($this->radiobutton_groups[$n]))
  10264. {
  10265. foreach ($this->radiobutton_groups[$n] as $key => $data)
  10266. {
  10267. if (isset($data['n']))
  10268. {
  10269. $out .= ' ' . $data['n'] . ' 0 R';
  10270. }
  10271. }
  10272. }
  10273. }
  10274. if ($this->sign and ($n == $this->signature_appearance['page']) and isset($this->signature_data['cert_type']))
  10275. {
  10276. // set reference for signature object
  10277. $out .= ' ' . $this->sig_obj_id . ' 0 R';
  10278. }
  10279. $out .= ' ]';
  10280. return $out;
  10281. }
  10282. /**
  10283. * Output annotations objects for all pages.
  10284. * !!! THIS METHOD IS NOT YET COMPLETED !!!
  10285. * See section 12.5 of PDF 32000_2008 reference.
  10286. * @access protected
  10287. * @author Nicola Asuni
  10288. * @since 4.0.018 (2008-08-06)
  10289. */
  10290. protected function _putannotsobjs()
  10291. {
  10292. // reset object counter
  10293. for($n = 1; $n <= $this->numpages; ++ $n)
  10294. {
  10295. if (isset($this->PageAnnots[$n]))
  10296. {
  10297. // set page annotations
  10298. foreach ($this->PageAnnots[$n] as $key => $pl)
  10299. {
  10300. $annot_obj_id = $this->PageAnnots[$n][$key]['n'];
  10301. // create annotation object for grouping radiobuttons
  10302. if (isset($this->radiobutton_groups[$n][$pl['txt']]) and is_array($this->radiobutton_groups[$n][$pl['txt']]))
  10303. {
  10304. $radio_button_obj_id = $this->radiobutton_groups[$n][$pl['txt']]['n'];
  10305. $annots = '<<';
  10306. $annots .= ' /Type /Annot';
  10307. $annots .= ' /Subtype /Widget';
  10308. $annots .= ' /Rect [0 0 0 0]';
  10309. $annots .= ' /T ' . $this->_datastring($pl['txt'], $radio_button_obj_id);
  10310. $annots .= ' /FT /Btn';
  10311. $annots .= ' /Ff 49152';
  10312. $annots .= ' /Kids [';
  10313. foreach ($this->radiobutton_groups[$n][$pl['txt']] as $key => $data)
  10314. {
  10315. if ($key !== 'n')
  10316. {
  10317. $annots .= ' ' . $data['kid'] . ' 0 R';
  10318. if ($data['def'] !== 'Off')
  10319. {
  10320. $defval = $data['def'];
  10321. }
  10322. }
  10323. }
  10324. $annots .= ' ]';
  10325. if (isset($defval))
  10326. {
  10327. $annots .= ' /V /' . $defval;
  10328. }
  10329. $annots .= ' >>';
  10330. $this->_out($this->_getobj($radio_button_obj_id) . "\n" . $annots . "\n" . 'endobj');
  10331. $this->form_obj_id[] = $radio_button_obj_id;
  10332. // store object id to be used on Parent entry of Kids
  10333. $this->radiobutton_groups[$n][$pl['txt']] = $radio_button_obj_id;
  10334. }
  10335. $formfield = false;
  10336. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  10337. $a = $pl['x'] * $this->k;
  10338. $b = $this->pagedim[$n]['h'] - (($pl['y'] + $pl['h']) * $this->k);
  10339. $c = $pl['w'] * $this->k;
  10340. $d = $pl['h'] * $this->k;
  10341. $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a + $c, $b + $d);
  10342. // create new annotation object
  10343. $annots = '<</Type /Annot';
  10344. $annots .= ' /Subtype /' . $pl['opt']['subtype'];
  10345. $annots .= ' /Rect [' . $rect . ']';
  10346. $ft = array('Btn', 'Tx', 'Ch', 'Sig');
  10347. if (isset($pl['opt']['ft']) and in_array($pl['opt']['ft'], $ft))
  10348. {
  10349. $annots .= ' /FT /' . $pl['opt']['ft'];
  10350. $formfield = true;
  10351. }
  10352. $annots .= ' /Contents ' . $this->_textstring($pl['txt'], $annot_obj_id);
  10353. $annots .= ' /P ' . $this->page_obj_id[$n] . ' 0 R';
  10354. $annots .= ' /NM ' . $this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
  10355. $annots .= ' /M ' . $this->_datestring($annot_obj_id);
  10356. if (isset($pl['opt']['f']))
  10357. {
  10358. $val = 0;
  10359. if (is_array($pl['opt']['f']))
  10360. {
  10361. foreach ($pl['opt']['f'] as $f)
  10362. {
  10363. switch (strtolower($f))
  10364. {
  10365. case 'invisible' :
  10366. {
  10367. $val += 1 << 0;
  10368. break;
  10369. }
  10370. case 'hidden' :
  10371. {
  10372. $val += 1 << 1;
  10373. break;
  10374. }
  10375. case 'print' :
  10376. {
  10377. $val += 1 << 2;
  10378. break;
  10379. }
  10380. case 'nozoom' :
  10381. {
  10382. $val += 1 << 3;
  10383. break;
  10384. }
  10385. case 'norotate' :
  10386. {
  10387. $val += 1 << 4;
  10388. break;
  10389. }
  10390. case 'noview' :
  10391. {
  10392. $val += 1 << 5;
  10393. break;
  10394. }
  10395. case 'readonly' :
  10396. {
  10397. $val += 1 << 6;
  10398. break;
  10399. }
  10400. case 'locked' :
  10401. {
  10402. $val += 1 << 8;
  10403. break;
  10404. }
  10405. case 'togglenoview' :
  10406. {
  10407. $val += 1 << 9;
  10408. break;
  10409. }
  10410. case 'lockedcontents' :
  10411. {
  10412. $val += 1 << 10;
  10413. break;
  10414. }
  10415. default :
  10416. {
  10417. break;
  10418. }
  10419. }
  10420. }
  10421. }
  10422. else
  10423. {
  10424. $val = intval($pl['opt']['f']);
  10425. }
  10426. $annots .= ' /F ' . intval($val);
  10427. }
  10428. if (isset($pl['opt']['as']) and is_string($pl['opt']['as']))
  10429. {
  10430. $annots .= ' /AS /' . $pl['opt']['as'];
  10431. }
  10432. if (isset($pl['opt']['ap']))
  10433. {
  10434. // appearance stream
  10435. $annots .= ' /AP <<';
  10436. if (is_array($pl['opt']['ap']))
  10437. {
  10438. foreach ($pl['opt']['ap'] as $apmode => $apdef)
  10439. {
  10440. // $apmode can be: n = normal; r = rollover; d = down;
  10441. $annots .= ' /' . strtoupper($apmode);
  10442. if (is_array($apdef))
  10443. {
  10444. $annots .= ' <<';
  10445. foreach ($apdef as $apstate => $stream)
  10446. {
  10447. // reference to XObject that define the appearance for this mode-state
  10448. $apsobjid = $this->_putAPXObject($c, $d, $stream);
  10449. $annots .= ' /' . $apstate . ' ' . $apsobjid . ' 0 R';
  10450. }
  10451. $annots .= ' >>';
  10452. }
  10453. else
  10454. {
  10455. // reference to XObject that define the appearance for this mode
  10456. $apsobjid = $this->_putAPXObject($c, $d, $apdef);
  10457. $annots .= ' ' . $apsobjid . ' 0 R';
  10458. }
  10459. }
  10460. }
  10461. else
  10462. {
  10463. $annots .= $pl['opt']['ap'];
  10464. }
  10465. $annots .= ' >>';
  10466. }
  10467. if (isset($pl['opt']['bs']) and (is_array($pl['opt']['bs'])))
  10468. {
  10469. $annots .= ' /BS <<';
  10470. $annots .= ' /Type /Border';
  10471. if (isset($pl['opt']['bs']['w']))
  10472. {
  10473. $annots .= ' /W ' . intval($pl['opt']['bs']['w']);
  10474. }
  10475. $bstyles = array('S', 'D', 'B', 'I', 'U');
  10476. if (isset($pl['opt']['bs']['s']) and in_array($pl['opt']['bs']['s'], $bstyles))
  10477. {
  10478. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  10479. }
  10480. if (isset($pl['opt']['bs']['d']) and (is_array($pl['opt']['bs']['d'])))
  10481. {
  10482. $annots .= ' /D [';
  10483. foreach ($pl['opt']['bs']['d'] as $cord)
  10484. {
  10485. $annots .= ' ' . intval($cord);
  10486. }
  10487. $annots .= ']';
  10488. }
  10489. $annots .= ' >>';
  10490. }
  10491. else
  10492. {
  10493. $annots .= ' /Border [';
  10494. if (isset($pl['opt']['border']) and (count($pl['opt']['border']) >= 3))
  10495. {
  10496. $annots .= intval($pl['opt']['border'][0]) . ' ';
  10497. $annots .= intval($pl['opt']['border'][1]) . ' ';
  10498. $annots .= intval($pl['opt']['border'][2]);
  10499. if (isset($pl['opt']['border'][3]) and is_array($pl['opt']['border'][3]))
  10500. {
  10501. $annots .= ' [';
  10502. foreach ($pl['opt']['border'][3] as $dash)
  10503. {
  10504. $annots .= intval($dash) . ' ';
  10505. }
  10506. $annots .= ']';
  10507. }
  10508. }
  10509. else
  10510. {
  10511. $annots .= '0 0 0';
  10512. }
  10513. $annots .= ']';
  10514. }
  10515. if (isset($pl['opt']['be']) and (is_array($pl['opt']['be'])))
  10516. {
  10517. $annots .= ' /BE <<';
  10518. $bstyles = array('S', 'C');
  10519. if (isset($pl['opt']['be']['s']) and in_array($pl['opt']['be']['s'], $markups))
  10520. {
  10521. $annots .= ' /S /' . $pl['opt']['bs']['s'];
  10522. }
  10523. else
  10524. {
  10525. $annots .= ' /S /S';
  10526. }
  10527. if (isset($pl['opt']['be']['i']) and ($pl['opt']['be']['i'] >= 0) and ($pl['opt']['be']['i'] <= 2))
  10528. {
  10529. $annots .= ' /I ' . sprintf(' %.4F', $pl['opt']['be']['i']);
  10530. }
  10531. $annots .= '>>';
  10532. }
  10533. if (isset($pl['opt']['c']) and (is_array($pl['opt']['c'])) and ! empty($pl['opt']['c']))
  10534. {
  10535. $annots .= ' /C [';
  10536. foreach ($pl['opt']['c'] as $col)
  10537. {
  10538. $col = intval($col);
  10539. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  10540. $annots .= sprintf(' %.4F', $color);
  10541. }
  10542. $annots .= ']';
  10543. }
  10544. //$annots .= ' /StructParent ';
  10545. //$annots .= ' /OC ';
  10546. $markups = array('text', 'freetext', 'line', 'square',
  10547. 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp',
  10548. 'caret', 'ink', 'fileattachment', 'sound');
  10549. if (in_array(strtolower($pl['opt']['subtype']), $markups))
  10550. {
  10551. // this is a markup type
  10552. if (isset($pl['opt']['t']) and is_string($pl['opt']['t']))
  10553. {
  10554. $annots .= ' /T ' . $this->_textstring($pl['opt']['t'], $annot_obj_id);
  10555. }
  10556. //$annots .= ' /Popup ';
  10557. if (isset($pl['opt']['ca']))
  10558. {
  10559. $annots .= ' /CA ' . sprintf('%.4F', floatval($pl['opt']['ca']));
  10560. }
  10561. if (isset($pl['opt']['rc']))
  10562. {
  10563. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc'], $annot_obj_id);
  10564. }
  10565. $annots .= ' /CreationDate ' . $this->_datestring($annot_obj_id);
  10566. //$annots .= ' /IRT ';
  10567. if (isset($pl['opt']['subj']))
  10568. {
  10569. $annots .= ' /Subj ' . $this->_textstring($pl['opt']['subj'], $annot_obj_id);
  10570. }
  10571. //$annots .= ' /RT ';
  10572. //$annots .= ' /IT ';
  10573. //$annots .= ' /ExData ';
  10574. }
  10575. $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt',
  10576. 'ROpenArrow', 'RClosedArrow', 'Slash');
  10577. // Annotation types
  10578. switch (strtolower($pl['opt']['subtype']))
  10579. {
  10580. case 'text' :
  10581. {
  10582. if (isset($pl['opt']['open']))
  10583. {
  10584. $annots .= ' /Open ' . (strtolower($pl['opt']['open']) == 'true' ? 'true' : 'false');
  10585. }
  10586. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note',
  10587. 'Paragraph');
  10588. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  10589. {
  10590. $annots .= ' /Name /' . $pl['opt']['name'];
  10591. }
  10592. else
  10593. {
  10594. $annots .= ' /Name /Note';
  10595. }
  10596. $statemodels = array('Marked', 'Review');
  10597. if (isset($pl['opt']['statemodel']) and in_array($pl['opt']['statemodel'], $statemodels))
  10598. {
  10599. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  10600. }
  10601. else
  10602. {
  10603. $pl['opt']['statemodel'] = 'Marked';
  10604. $annots .= ' /StateModel /' . $pl['opt']['statemodel'];
  10605. }
  10606. if ($pl['opt']['statemodel'] == 'Marked')
  10607. {
  10608. $states = array('Accepted', 'Unmarked');
  10609. }
  10610. else
  10611. {
  10612. $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
  10613. }
  10614. if (isset($pl['opt']['state']) and in_array($pl['opt']['state'], $states))
  10615. {
  10616. $annots .= ' /State /' . $pl['opt']['state'];
  10617. }
  10618. else
  10619. {
  10620. if ($pl['opt']['statemodel'] == 'Marked')
  10621. {
  10622. $annots .= ' /State /Unmarked';
  10623. }
  10624. else
  10625. {
  10626. $annots .= ' /State /None';
  10627. }
  10628. }
  10629. break;
  10630. }
  10631. case 'link' :
  10632. {
  10633. if (is_string($pl['txt']))
  10634. {
  10635. // external URI link
  10636. $annots .= ' /A <</S /URI /URI ' . $this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id) . '>>';
  10637. }
  10638. else
  10639. {
  10640. // internal link
  10641. $l = $this->links[$pl['txt']];
  10642. $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($l[0])], ($this->pagedim[$l[0]]['h'] - ($l[1] * $this->k)));
  10643. }
  10644. $hmodes = array('N', 'I', 'O', 'P');
  10645. if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmodes))
  10646. {
  10647. $annots .= ' /H /' . $pl['opt']['h'];
  10648. }
  10649. else
  10650. {
  10651. $annots .= ' /H /I';
  10652. }
  10653. //$annots .= ' /PA ';
  10654. //$annots .= ' /Quadpoints ';
  10655. break;
  10656. }
  10657. case 'freetext' :
  10658. {
  10659. if (isset($pl['opt']['da']) and ! empty($pl['opt']['da']))
  10660. {
  10661. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  10662. }
  10663. if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2))
  10664. {
  10665. $annots .= ' /Q ' . intval($pl['opt']['q']);
  10666. }
  10667. if (isset($pl['opt']['rc']))
  10668. {
  10669. $annots .= ' /RC ' . $this->_textstring($pl['opt']['rc'], $annot_obj_id);
  10670. }
  10671. if (isset($pl['opt']['ds']))
  10672. {
  10673. $annots .= ' /DS ' . $this->_textstring($pl['opt']['ds'], $annot_obj_id);
  10674. }
  10675. if (isset($pl['opt']['cl']) and is_array($pl['opt']['cl']))
  10676. {
  10677. $annots .= ' /CL [';
  10678. foreach ($pl['opt']['cl'] as $cl)
  10679. {
  10680. $annots .= sprintf('%.4F ', $cl * $this->k);
  10681. }
  10682. $annots .= ']';
  10683. }
  10684. $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
  10685. if (isset($pl['opt']['it']) and in_array($pl['opt']['it'], $tfit))
  10686. {
  10687. $annots .= ' /IT /' . $pl['opt']['it'];
  10688. }
  10689. if (isset($pl['opt']['rd']) and is_array($pl['opt']['rd']))
  10690. {
  10691. $l = $pl['opt']['rd'][0] * $this->k;
  10692. $r = $pl['opt']['rd'][1] * $this->k;
  10693. $t = $pl['opt']['rd'][2] * $this->k;
  10694. $b = $pl['opt']['rd'][3] * $this->k;
  10695. $annots .= ' /RD [' . sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b) . ']';
  10696. }
  10697. if (isset($pl['opt']['le']) and in_array($pl['opt']['le'], $lineendings))
  10698. {
  10699. $annots .= ' /LE /' . $pl['opt']['le'];
  10700. }
  10701. break;
  10702. }
  10703. case 'line' :
  10704. {
  10705. break;
  10706. }
  10707. case 'square' :
  10708. {
  10709. break;
  10710. }
  10711. case 'circle' :
  10712. {
  10713. break;
  10714. }
  10715. case 'polygon' :
  10716. {
  10717. break;
  10718. }
  10719. case 'polyline' :
  10720. {
  10721. break;
  10722. }
  10723. case 'highlight' :
  10724. {
  10725. break;
  10726. }
  10727. case 'underline' :
  10728. {
  10729. break;
  10730. }
  10731. case 'squiggly' :
  10732. {
  10733. break;
  10734. }
  10735. case 'strikeout' :
  10736. {
  10737. break;
  10738. }
  10739. case 'stamp' :
  10740. {
  10741. break;
  10742. }
  10743. case 'caret' :
  10744. {
  10745. break;
  10746. }
  10747. case 'ink' :
  10748. {
  10749. break;
  10750. }
  10751. case 'popup' :
  10752. {
  10753. break;
  10754. }
  10755. case 'fileattachment' :
  10756. {
  10757. if (! isset($pl['opt']['fs']))
  10758. {
  10759. break;
  10760. }
  10761. $filename = basename($pl['opt']['fs']);
  10762. if (isset($this->embeddedfiles[$filename]['n']))
  10763. {
  10764. $annots .= ' /FS <</Type /Filespec /F ' . $this->_datastring($filename, $annot_obj_id) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  10765. $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
  10766. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  10767. {
  10768. $annots .= ' /Name /' . $pl['opt']['name'];
  10769. }
  10770. else
  10771. {
  10772. $annots .= ' /Name /PushPin';
  10773. }
  10774. }
  10775. break;
  10776. }
  10777. case 'sound' :
  10778. {
  10779. if (! isset($pl['opt']['fs']))
  10780. {
  10781. break;
  10782. }
  10783. $filename = basename($pl['opt']['fs']);
  10784. if (isset($this->embeddedfiles[$filename]['n']))
  10785. {
  10786. // ... TO BE COMPLETED ...
  10787. // /R /C /B /E /CO /CP
  10788. $annots .= ' /Sound <</Type /Filespec /F ' . $this->_datastring($filename, $annot_obj_id) . ' /EF <</F ' . $this->embeddedfiles[$filename]['n'] . ' 0 R>> >>';
  10789. $iconsapp = array('Speaker', 'Mic');
  10790. if (isset($pl['opt']['name']) and in_array($pl['opt']['name'], $iconsapp))
  10791. {
  10792. $annots .= ' /Name /' . $pl['opt']['name'];
  10793. }
  10794. else
  10795. {
  10796. $annots .= ' /Name /Speaker';
  10797. }
  10798. }
  10799. break;
  10800. }
  10801. case 'movie' :
  10802. {
  10803. break;
  10804. }
  10805. case 'widget' :
  10806. {
  10807. $hmode = array('N', 'I', 'O', 'P', 'T');
  10808. if (isset($pl['opt']['h']) and in_array($pl['opt']['h'], $hmode))
  10809. {
  10810. $annots .= ' /H /' . $pl['opt']['h'];
  10811. }
  10812. if (isset($pl['opt']['mk']) and (is_array($pl['opt']['mk'])) and ! empty($pl['opt']['mk']))
  10813. {
  10814. $annots .= ' /MK <<';
  10815. if (isset($pl['opt']['mk']['r']))
  10816. {
  10817. $annots .= ' /R ' . $pl['opt']['mk']['r'];
  10818. }
  10819. if (isset($pl['opt']['mk']['bc']) and (is_array($pl['opt']['mk']['bc'])))
  10820. {
  10821. $annots .= ' /BC [';
  10822. foreach ($pl['opt']['mk']['bc'] as $col)
  10823. {
  10824. $col = intval($col);
  10825. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  10826. $annots .= sprintf(' %.2F', $color);
  10827. }
  10828. $annots .= ']';
  10829. }
  10830. if (isset($pl['opt']['mk']['bg']) and (is_array($pl['opt']['mk']['bg'])))
  10831. {
  10832. $annots .= ' /BG [';
  10833. foreach ($pl['opt']['mk']['bg'] as $col)
  10834. {
  10835. $col = intval($col);
  10836. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  10837. $annots .= sprintf(' %.2F', $color);
  10838. }
  10839. $annots .= ']';
  10840. }
  10841. if (isset($pl['opt']['mk']['ca']))
  10842. {
  10843. $annots .= ' /CA ' . $pl['opt']['mk']['ca'];
  10844. }
  10845. if (isset($pl['opt']['mk']['rc']))
  10846. {
  10847. $annots .= ' /RC ' . $pl['opt']['mk']['rc'];
  10848. }
  10849. if (isset($pl['opt']['mk']['ac']))
  10850. {
  10851. $annots .= ' /AC ' . $pl['opt']['mk']['ac'];
  10852. }
  10853. if (isset($pl['opt']['mk']['i']))
  10854. {
  10855. $info = $this->getImageBuffer($pl['opt']['mk']['i']);
  10856. if ($info !== false)
  10857. {
  10858. $annots .= ' /I ' . $info['n'] . ' 0 R';
  10859. }
  10860. }
  10861. if (isset($pl['opt']['mk']['ri']))
  10862. {
  10863. $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
  10864. if ($info !== false)
  10865. {
  10866. $annots .= ' /RI ' . $info['n'] . ' 0 R';
  10867. }
  10868. }
  10869. if (isset($pl['opt']['mk']['ix']))
  10870. {
  10871. $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
  10872. if ($info !== false)
  10873. {
  10874. $annots .= ' /IX ' . $info['n'] . ' 0 R';
  10875. }
  10876. }
  10877. if (isset($pl['opt']['mk']['if']) and (is_array($pl['opt']['mk']['if'])) and ! empty($pl['opt']['mk']['if']))
  10878. {
  10879. $annots .= ' /IF <<';
  10880. $if_sw = array('A', 'B', 'S', 'N');
  10881. if (isset($pl['opt']['mk']['if']['sw']) and in_array($pl['opt']['mk']['if']['sw'], $if_sw))
  10882. {
  10883. $annots .= ' /SW /' . $pl['opt']['mk']['if']['sw'];
  10884. }
  10885. $if_s = array('A', 'P');
  10886. if (isset($pl['opt']['mk']['if']['s']) and in_array($pl['opt']['mk']['if']['s'], $if_s))
  10887. {
  10888. $annots .= ' /S /' . $pl['opt']['mk']['if']['s'];
  10889. }
  10890. if (isset($pl['opt']['mk']['if']['a']) and (is_array($pl['opt']['mk']['if']['a'])) and ! empty($pl['opt']['mk']['if']['a']))
  10891. {
  10892. $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
  10893. }
  10894. if (isset($pl['opt']['mk']['if']['fb']) and ($pl['opt']['mk']['if']['fb']))
  10895. {
  10896. $annots .= ' /FB true';
  10897. }
  10898. $annots .= '>>';
  10899. }
  10900. if (isset($pl['opt']['mk']['tp']) and ($pl['opt']['mk']['tp'] >= 0) and ($pl['opt']['mk']['tp'] <= 6))
  10901. {
  10902. $annots .= ' /TP ' . intval($pl['opt']['mk']['tp']);
  10903. }
  10904. else
  10905. {
  10906. $annots .= ' /TP 0';
  10907. }
  10908. $annots .= '>>';
  10909. } // end MK
  10910. // --- Entries for field dictionaries ---
  10911. if (isset($this->radiobutton_groups[$n][$pl['txt']]))
  10912. {
  10913. // set parent
  10914. $annots .= ' /Parent ' . $this->radiobutton_groups[$n][$pl['txt']] . ' 0 R';
  10915. }
  10916. if (isset($pl['opt']['t']) and is_string($pl['opt']['t']))
  10917. {
  10918. $annots .= ' /T ' . $this->_datastring($pl['opt']['t'], $annot_obj_id);
  10919. }
  10920. if (isset($pl['opt']['tu']) and is_string($pl['opt']['tu']))
  10921. {
  10922. $annots .= ' /TU ' . $this->_datastring($pl['opt']['tu'], $annot_obj_id);
  10923. }
  10924. if (isset($pl['opt']['tm']) and is_string($pl['opt']['tm']))
  10925. {
  10926. $annots .= ' /TM ' . $this->_datastring($pl['opt']['tm'], $annot_obj_id);
  10927. }
  10928. if (isset($pl['opt']['ff']))
  10929. {
  10930. if (is_array($pl['opt']['ff']))
  10931. {
  10932. // array of bit settings
  10933. $flag = 0;
  10934. foreach ($pl['opt']['ff'] as $val)
  10935. {
  10936. $flag += 1 << ($val - 1);
  10937. }
  10938. }
  10939. else
  10940. {
  10941. $flag = intval($pl['opt']['ff']);
  10942. }
  10943. $annots .= ' /Ff ' . $flag;
  10944. }
  10945. if (isset($pl['opt']['maxlen']))
  10946. {
  10947. $annots .= ' /MaxLen ' . intval($pl['opt']['maxlen']);
  10948. }
  10949. if (isset($pl['opt']['v']))
  10950. {
  10951. $annots .= ' /V';
  10952. if (is_array($pl['opt']['v']))
  10953. {
  10954. foreach ($pl['opt']['v'] as $optval)
  10955. {
  10956. if (is_float($optval))
  10957. {
  10958. $optval = sprintf('%.2F', $optval);
  10959. }
  10960. $annots .= ' ' . $optval;
  10961. }
  10962. }
  10963. else
  10964. {
  10965. $annots .= ' ' . $this->_textstring($pl['opt']['v'], $annot_obj_id);
  10966. }
  10967. }
  10968. if (isset($pl['opt']['dv']))
  10969. {
  10970. $annots .= ' /DV';
  10971. if (is_array($pl['opt']['dv']))
  10972. {
  10973. foreach ($pl['opt']['dv'] as $optval)
  10974. {
  10975. if (is_float($optval))
  10976. {
  10977. $optval = sprintf('%.2F', $optval);
  10978. }
  10979. $annots .= ' ' . $optval;
  10980. }
  10981. }
  10982. else
  10983. {
  10984. $annots .= ' ' . $this->_textstring($pl['opt']['dv'], $annot_obj_id);
  10985. }
  10986. }
  10987. if (isset($pl['opt']['rv']))
  10988. {
  10989. $annots .= ' /RV';
  10990. if (is_array($pl['opt']['rv']))
  10991. {
  10992. foreach ($pl['opt']['rv'] as $optval)
  10993. {
  10994. if (is_float($optval))
  10995. {
  10996. $optval = sprintf('%.2F', $optval);
  10997. }
  10998. $annots .= ' ' . $optval;
  10999. }
  11000. }
  11001. else
  11002. {
  11003. $annots .= ' ' . $this->_textstring($pl['opt']['rv'], $annot_obj_id);
  11004. }
  11005. }
  11006. if (isset($pl['opt']['a']) and ! empty($pl['opt']['a']))
  11007. {
  11008. $annots .= ' /A << ' . $pl['opt']['a'] . ' >>';
  11009. }
  11010. if (isset($pl['opt']['aa']) and ! empty($pl['opt']['aa']))
  11011. {
  11012. $annots .= ' /AA << ' . $pl['opt']['aa'] . ' >>';
  11013. }
  11014. if (isset($pl['opt']['da']) and ! empty($pl['opt']['da']))
  11015. {
  11016. $annots .= ' /DA (' . $pl['opt']['da'] . ')';
  11017. }
  11018. if (isset($pl['opt']['q']) and ($pl['opt']['q'] >= 0) and ($pl['opt']['q'] <= 2))
  11019. {
  11020. $annots .= ' /Q ' . intval($pl['opt']['q']);
  11021. }
  11022. if (isset($pl['opt']['opt']) and (is_array($pl['opt']['opt'])) and ! empty($pl['opt']['opt']))
  11023. {
  11024. $annots .= ' /Opt [';
  11025. foreach ($pl['opt']['opt'] as $copt)
  11026. {
  11027. if (is_array($copt))
  11028. {
  11029. $annots .= ' [' . $this->_textstring($copt[0], $annot_obj_id) . ' ' . $this->_textstring($copt[1], $annot_obj_id) . ']';
  11030. }
  11031. else
  11032. {
  11033. $annots .= ' ' . $this->_textstring($copt, $annot_obj_id);
  11034. }
  11035. }
  11036. $annots .= ']';
  11037. }
  11038. if (isset($pl['opt']['ti']))
  11039. {
  11040. $annots .= ' /TI ' . intval($pl['opt']['ti']);
  11041. }
  11042. if (isset($pl['opt']['i']) and (is_array($pl['opt']['i'])) and ! empty($pl['opt']['i']))
  11043. {
  11044. $annots .= ' /I [';
  11045. foreach ($pl['opt']['i'] as $copt)
  11046. {
  11047. $annots .= intval($copt) . ' ';
  11048. }
  11049. $annots .= ']';
  11050. }
  11051. break;
  11052. }
  11053. case 'screen' :
  11054. {
  11055. break;
  11056. }
  11057. case 'printermark' :
  11058. {
  11059. break;
  11060. }
  11061. case 'trapnet' :
  11062. {
  11063. break;
  11064. }
  11065. case 'watermark' :
  11066. {
  11067. break;
  11068. }
  11069. case '3d' :
  11070. {
  11071. break;
  11072. }
  11073. default :
  11074. {
  11075. break;
  11076. }
  11077. }
  11078. $annots .= '>>';
  11079. // create new annotation object
  11080. $this->_out($this->_getobj($annot_obj_id) . "\n" . $annots . "\n" . 'endobj');
  11081. if ($formfield and ! isset($this->radiobutton_groups[$n][$pl['txt']]))
  11082. {
  11083. // store reference of form object
  11084. $this->form_obj_id[] = $annot_obj_id;
  11085. }
  11086. }
  11087. }
  11088. } // end for each page
  11089. }
  11090. /**
  11091. * Put appearance streams XObject used to define annotation's appearance states
  11092. * @param int $w annotation width
  11093. * @param int $h annotation height
  11094. * @param string $stream appearance stream
  11095. * @return int object ID
  11096. * @access protected
  11097. * @since 4.8.001 (2009-09-09)
  11098. */
  11099. protected function _putAPXObject($w = 0, $h = 0, $stream = '')
  11100. {
  11101. $stream = trim($stream);
  11102. $out = $this->_getobj() . "\n";
  11103. $this->xobjects['AX' . $this->n] = array('n' => $this->n);
  11104. $out .= '<<';
  11105. $out .= ' /Type /XObject';
  11106. $out .= ' /Subtype /Form';
  11107. $out .= ' /FormType 1';
  11108. if ($this->compress)
  11109. {
  11110. $stream = gzcompress($stream);
  11111. $out .= ' /Filter /FlateDecode';
  11112. }
  11113. $rect = sprintf('%.2F %.2F', $w, $h);
  11114. $out .= ' /BBox [0 0 ' . $rect . ']';
  11115. $out .= ' /Matrix [1 0 0 1 0 0]';
  11116. $out .= ' /Resources <<';
  11117. $out .= ' /ProcSet [/PDF /Text]';
  11118. $out .= ' /Font <<';
  11119. foreach ($this->annotation_fonts as $fontkey => $fontid)
  11120. {
  11121. $out .= ' /F' . $fontid . ' ' . $this->font_obj_ids[$fontkey] . ' 0 R';
  11122. }
  11123. $out .= ' >>';
  11124. $out .= ' >>';
  11125. $stream = $this->_getrawstream($stream);
  11126. $out .= ' /Length ' . strlen($stream);
  11127. $out .= ' >>';
  11128. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  11129. $out .= "\n" . 'endobj';
  11130. $this->_out($out);
  11131. return $this->n;
  11132. }
  11133. /**
  11134. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  11135. * @param string $str string from where to extract value
  11136. * @param int $offset point from where to read the data
  11137. * @return int 32 bit value
  11138. * @author Nicola Asuni
  11139. * @access protected
  11140. * @since 5.2.000 (2010-06-02)
  11141. */
  11142. protected function _getULONG(&$str, &$offset)
  11143. {
  11144. $v = unpack('Ni', substr($str, $offset, 4));
  11145. $offset += 4;
  11146. return $v['i'];
  11147. }
  11148. /**
  11149. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  11150. * @param string $str string from where to extract value
  11151. * @param int $offset point from where to read the data
  11152. * @return int 16 bit value
  11153. * @author Nicola Asuni
  11154. * @access protected
  11155. * @since 5.2.000 (2010-06-02)
  11156. */
  11157. protected function _getUSHORT(&$str, &$offset)
  11158. {
  11159. $v = unpack('ni', substr($str, $offset, 2));
  11160. $offset += 2;
  11161. return $v['i'];
  11162. }
  11163. /**
  11164. * Get SHORT from string (Big Endian 16-bit signed integer).
  11165. * @param string $str string from where to extract value
  11166. * @param int $offset point from where to read the data
  11167. * @return int 16 bit value
  11168. * @author Nicola Asuni
  11169. * @access protected
  11170. * @since 5.2.000 (2010-06-02)
  11171. */
  11172. protected function _getSHORT(&$str, &$offset)
  11173. {
  11174. $v = unpack('si', substr($str, $offset, 2));
  11175. $offset += 2;
  11176. return $v['i'];
  11177. }
  11178. /**
  11179. * Get BYTE from string (8-bit unsigned integer).
  11180. * @param string $str string from where to extract value
  11181. * @param int $offset point from where to read the data
  11182. * @return int 8 bit value
  11183. * @author Nicola Asuni
  11184. * @access protected
  11185. * @since 5.2.000 (2010-06-02)
  11186. */
  11187. protected function _getBYTE(&$str, &$offset)
  11188. {
  11189. $v = unpack('Ci', substr($str, $offset, 1));
  11190. ++ $offset;
  11191. return $v['i'];
  11192. }
  11193. /**
  11194. * Returns a subset of the TrueType font data without the unused glyphs.
  11195. * @param string $font TrueType font data
  11196. * @param array $subsetchars array of used characters (the glyphs to keep)
  11197. * @return string a subset of TrueType font data without the unused glyphs
  11198. * @author Nicola Asuni
  11199. * @access protected
  11200. * @since 5.2.000 (2010-06-02)
  11201. */
  11202. protected function _getTrueTypeFontSubset($font, $subsetchars)
  11203. {
  11204. ksort($subsetchars);
  11205. $offset = 0; // offset position of the font data
  11206. if ($this->_getULONG($font, $offset) != 0x10000)
  11207. {
  11208. // sfnt version must be 0x00010000 for TrueType version 1.0.
  11209. return $font;
  11210. }
  11211. // get number of tables
  11212. $numTables = $this->_getUSHORT($font, $offset);
  11213. // skip searchRange, entrySelector and rangeShift
  11214. $offset += 6;
  11215. // tables array
  11216. $table = array();
  11217. // for each table
  11218. for($i = 0; $i < $numTables; ++ $i)
  11219. {
  11220. // get table info
  11221. $tag = substr($font, $offset, 4);
  11222. $offset += 4;
  11223. $table[$tag] = array();
  11224. $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
  11225. $table[$tag]['offset'] = $this->_getULONG($font, $offset);
  11226. $table[$tag]['length'] = $this->_getULONG($font, $offset);
  11227. }
  11228. // check magicNumber
  11229. $offset = $table['head']['offset'] + 12;
  11230. if ($this->_getULONG($font, $offset) != 0x5F0F3CF5)
  11231. {
  11232. // magicNumber must be 0x5F0F3CF5
  11233. return $font;
  11234. }
  11235. // get offset mode (indexToLocFormat : 0 = short, 1 = long)
  11236. $offset = $table['head']['offset'] + 50;
  11237. $short_offset = ($this->_getSHORT($font, $offset) == 0);
  11238. // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
  11239. $indexToLoc = array();
  11240. $offset = $table['loca']['offset'];
  11241. if ($short_offset)
  11242. {
  11243. // short version
  11244. $n = $table['loca']['length'] / 2; // numGlyphs + 1
  11245. for($i = 0; $i < $n; ++ $i)
  11246. {
  11247. $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
  11248. }
  11249. }
  11250. else
  11251. {
  11252. // long version
  11253. $n = $table['loca']['length'] / 4; // numGlyphs + 1
  11254. for($i = 0; $i < $n; ++ $i)
  11255. {
  11256. $indexToLoc[$i] = $this->_getULONG($font, $offset);
  11257. }
  11258. }
  11259. // get glyphs indexes of chars from cmap table
  11260. $subsetglyphs = array(); // glyph IDs on key
  11261. $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
  11262. $offset = $table['cmap']['offset'] + 2;
  11263. $numEncodingTables = $this->_getUSHORT($font, $offset);
  11264. $encodingTables = array();
  11265. for($i = 0; $i < $numEncodingTables; ++ $i)
  11266. {
  11267. $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
  11268. $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
  11269. $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
  11270. }
  11271. foreach ($encodingTables as $enctable)
  11272. {
  11273. if (($enctable['platformID'] == 3) and ($enctable['encodingID'] == 0))
  11274. {
  11275. $modesymbol = true;
  11276. }
  11277. else
  11278. {
  11279. $modesymbol = false;
  11280. }
  11281. $offset = $table['cmap']['offset'] + $enctable['offset'];
  11282. $format = $this->_getUSHORT($font, $offset);
  11283. switch ($format)
  11284. {
  11285. case 0 :
  11286. { // Format 0: Byte encoding table
  11287. $offset += 4; // skip length and version/language
  11288. for($k = 0; $k < 256; ++ $k)
  11289. {
  11290. if (isset($subsetchars[$k]))
  11291. {
  11292. $g = $this->_getBYTE($font, $offset);
  11293. $subsetglyphs[$g] = $k;
  11294. }
  11295. else
  11296. {
  11297. ++ $offset;
  11298. }
  11299. }
  11300. break;
  11301. }
  11302. case 2 :
  11303. { // Format 2: High-byte mapping through table
  11304. $offset += 4; // skip length and version
  11305. // to be implemented ...
  11306. break;
  11307. }
  11308. case 4 :
  11309. { // Format 4: Segment mapping to delta values
  11310. $length = $this->_getUSHORT($font, $offset);
  11311. $offset += 2; // skip version/language
  11312. $segCount = ($this->_getUSHORT($font, $offset) / 2);
  11313. $offset += 6; // skip searchRange, entrySelector, rangeShift
  11314. $endCount = array(); // array of end character codes for each segment
  11315. for($k = 0; $k < $segCount; ++ $k)
  11316. {
  11317. $endCount[$k] = $this->_getUSHORT($font, $offset);
  11318. }
  11319. $offset += 2; // skip reservedPad
  11320. $startCount = array(); // array of start character codes for each segment
  11321. for($k = 0; $k < $segCount; ++ $k)
  11322. {
  11323. $startCount[$k] = $this->_getUSHORT($font, $offset);
  11324. }
  11325. $idDelta = array(); // delta for all character codes in segment
  11326. for($k = 0; $k < $segCount; ++ $k)
  11327. {
  11328. $idDelta[$k] = $this->_getUSHORT($font, $offset);
  11329. }
  11330. $idRangeOffset = array(); // Offsets into glyphIdArray or 0
  11331. for($k = 0; $k < $segCount; ++ $k)
  11332. {
  11333. $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
  11334. }
  11335. $gidlen = ($length / 2) - 8 - (4 * $segCount);
  11336. $glyphIdArray = array(); // glyph index array
  11337. for($k = 0; $k < $gidlen; ++ $k)
  11338. {
  11339. $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
  11340. }
  11341. for($k = 0; $k < $segCount; ++ $k)
  11342. {
  11343. for($c = $startCount[$k]; $c <= $endCount[$k]; ++ $c)
  11344. {
  11345. if (isset($subsetchars[$c]))
  11346. {
  11347. if ($idRangeOffset[$k] == 0)
  11348. {
  11349. $g = $c;
  11350. }
  11351. else
  11352. {
  11353. $gid = (($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
  11354. $g = $glyphIdArray[$gid];
  11355. }
  11356. $g += ($idDelta[$k] - 65536);
  11357. if ($g < 0)
  11358. {
  11359. $g = 0;
  11360. }
  11361. $subsetglyphs[$g] = $c;
  11362. }
  11363. }
  11364. }
  11365. break;
  11366. }
  11367. case 6 :
  11368. { // Format 6: Trimmed table mapping
  11369. $offset += 4; // skip length and version/language
  11370. $firstCode = $this->_getUSHORT($font, $offset);
  11371. $entryCount = $this->_getUSHORT($font, $offset);
  11372. for($k = 0; $k < $entryCount; ++ $k)
  11373. {
  11374. $c = ($k + $firstCode);
  11375. if (isset($subsetchars[$c]))
  11376. {
  11377. $g = $this->_getUSHORT($font, $offset);
  11378. $subsetglyphs[$g] = $c;
  11379. }
  11380. else
  11381. {
  11382. $offset += 2;
  11383. }
  11384. }
  11385. break;
  11386. }
  11387. case 8 :
  11388. { // Format 8: Mixed 16-bit and 32-bit coverage
  11389. $offset += 10; // skip length and version
  11390. // to be implemented ...
  11391. break;
  11392. }
  11393. case 10 :
  11394. { // Format 10: Trimmed array
  11395. $offset += 10; // skip length and version/language
  11396. $startCharCode = $this->_getULONG($font, $offset);
  11397. $numChars = $this->_getULONG($font, $offset);
  11398. for($k = 0; $k < $numChars; ++ $k)
  11399. {
  11400. $c = ($k + $startCharCode);
  11401. if (isset($subsetchars[$c]))
  11402. {
  11403. $g = $this->_getUSHORT($font, $offset);
  11404. $subsetglyphs[$g] = $c;
  11405. }
  11406. else
  11407. {
  11408. $offset += 2;
  11409. }
  11410. }
  11411. break;
  11412. }
  11413. case 12 :
  11414. { // Format 12: Segmented coverage
  11415. $offset += 10; // skip length and version/language
  11416. $nGroups = $this->_getULONG($font, $offset);
  11417. for($k = 0; $k < $nGroups; ++ $k)
  11418. {
  11419. $startCharCode = $this->_getULONG($font, $offset);
  11420. $endCharCode = $this->_getULONG($font, $offset);
  11421. $startGlyphCode = $this->_getULONG($font, $offset);
  11422. for($c = $startCharCode; $c <= $endCharCode; ++ $c)
  11423. {
  11424. if (isset($subsetchars[$c]))
  11425. {
  11426. $subsetglyphs[$startGlyphCode] = $c;
  11427. }
  11428. ++ $startGlyphCode;
  11429. }
  11430. }
  11431. break;
  11432. }
  11433. }
  11434. }
  11435. // sort glyphs by key
  11436. ksort($subsetglyphs);
  11437. // add composite glyps to $subsetglyphs and remove missing glyphs
  11438. foreach ($subsetglyphs as $key => $val)
  11439. {
  11440. if (isset($indexToLoc[$key]))
  11441. {
  11442. $offset = $table['glyf']['offset'] + $indexToLoc[$key];
  11443. $numberOfContours = $this->_getSHORT($font, $offset);
  11444. if ($numberOfContours < 0)
  11445. { // composite glyph
  11446. $offset += 8; // skip xMin, yMin, xMax, yMax
  11447. do
  11448. {
  11449. $flags = $this->_getUSHORT($font, $offset);
  11450. $glyphIndex = $this->_getUSHORT($font, $offset);
  11451. if (! isset($subsetglyphs[$glyphIndex]) and isset($indexToLoc[$glyphIndex]))
  11452. {
  11453. // add missing glyphs
  11454. $subsetglyphs[$glyphIndex] = true;
  11455. }
  11456. // skip some bytes by case
  11457. if ($flags & 1)
  11458. {
  11459. $offset += 4;
  11460. }
  11461. else
  11462. {
  11463. $offset += 2;
  11464. }
  11465. if ($flags & 8)
  11466. {
  11467. $offset += 2;
  11468. }
  11469. elseif ($flags & 64)
  11470. {
  11471. $offset += 4;
  11472. }
  11473. elseif ($flags & 128)
  11474. {
  11475. $offset += 8;
  11476. }
  11477. }
  11478. while ($flags & 32);
  11479. }
  11480. }
  11481. else
  11482. {
  11483. unset($subsetglyphs[$key]);
  11484. }
  11485. }
  11486. // build new glyf table with only used glyphs
  11487. $glyf = '';
  11488. $glyfSize = 0;
  11489. // create new empty indexToLoc table
  11490. $newIndexToLoc = array_fill(0, count($indexToLoc), 0);
  11491. $goffset = 0;
  11492. foreach ($subsetglyphs as $glyphID => $char)
  11493. {
  11494. if (isset($indexToLoc[$glyphID]) and isset($indexToLoc[($glyphID + 1)]))
  11495. {
  11496. $start = $indexToLoc[$glyphID];
  11497. $length = ($indexToLoc[($glyphID + 1)] - $start);
  11498. $glyf .= substr($font, ($table['glyf']['offset'] + $start), $length);
  11499. $newIndexToLoc[$glyphID] = $goffset;
  11500. $goffset += $length;
  11501. }
  11502. }
  11503. // build new loca table
  11504. $loca = '';
  11505. if ($short_offset)
  11506. {
  11507. foreach ($newIndexToLoc as $glyphID => $offset)
  11508. {
  11509. $loca .= pack('n', ($offset / 2));
  11510. }
  11511. }
  11512. else
  11513. {
  11514. foreach ($newIndexToLoc as $glyphID => $offset)
  11515. {
  11516. $loca .= pack('N', $offset);
  11517. }
  11518. }
  11519. // array of table names to preserve (loca and glyf tables will be added later)
  11520. //$table_names = array ('cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', 'fpgm', 'prep');
  11521. // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
  11522. $table_names = array('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
  11523. // get the tables to preserve
  11524. $offset = 12;
  11525. foreach ($table as $tag => $val)
  11526. {
  11527. if (in_array($tag, $table_names))
  11528. {
  11529. $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
  11530. if ($tag == 'head')
  11531. {
  11532. // set the checkSumAdjustment to 0
  11533. $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8) . "\x0\x0\x0\x0" . substr($table[$tag]['data'], 12);
  11534. }
  11535. $pad = 4 - ($table[$tag]['length'] % 4);
  11536. if ($pad != 4)
  11537. {
  11538. // the length of a table must be a multiple of four bytes
  11539. $table[$tag]['length'] += $pad;
  11540. $table[$tag]['data'] .= str_repeat("\x0", $pad);
  11541. }
  11542. $table[$tag]['offset'] = $offset;
  11543. $offset += $table[$tag]['length'];
  11544. // check sum is not changed (so keep the following line commented)
  11545. //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
  11546. }
  11547. else
  11548. {
  11549. unset($table[$tag]);
  11550. }
  11551. }
  11552. // add loca
  11553. $table['loca']['data'] = $loca;
  11554. $table['loca']['length'] = strlen($loca);
  11555. $pad = 4 - ($table['loca']['length'] % 4);
  11556. if ($pad != 4)
  11557. {
  11558. // the length of a table must be a multiple of four bytes
  11559. $table['loca']['length'] += $pad;
  11560. $table['loca']['data'] .= str_repeat("\x0", $pad);
  11561. }
  11562. $table['loca']['offset'] = $offset;
  11563. $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
  11564. $offset += $table['loca']['length'];
  11565. // add glyf
  11566. $table['glyf']['data'] = $glyf;
  11567. $table['glyf']['length'] = strlen($glyf);
  11568. $pad = 4 - ($table['glyf']['length'] % 4);
  11569. if ($pad != 4)
  11570. {
  11571. // the length of a table must be a multiple of four bytes
  11572. $table['glyf']['length'] += $pad;
  11573. $table['glyf']['data'] .= str_repeat("\x0", $pad);
  11574. }
  11575. $table['glyf']['offset'] = $offset;
  11576. $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
  11577. // rebuild font
  11578. $font = '';
  11579. $font .= pack('N', 0x10000); // sfnt version
  11580. $numTables = count($table);
  11581. $font .= pack('n', $numTables); // numTables
  11582. $entrySelector = floor(log($numTables, 2));
  11583. $searchRange = pow(2, $entrySelector) * 16;
  11584. $rangeShift = ($numTables * 16) - $searchRange;
  11585. $font .= pack('n', $searchRange); // searchRange
  11586. $font .= pack('n', $entrySelector); // entrySelector
  11587. $font .= pack('n', $rangeShift); // rangeShift
  11588. $offset = ($numTables * 16);
  11589. foreach ($table as $tag => $data)
  11590. {
  11591. $font .= $tag; // tag
  11592. $font .= pack('N', $data['checkSum']); // checkSum
  11593. $font .= pack('N', ($data['offset'] + $offset)); // offset
  11594. $font .= pack('N', $data['length']); // length
  11595. }
  11596. foreach ($table as $data)
  11597. {
  11598. $font .= $data['data'];
  11599. }
  11600. // set checkSumAdjustment on head table
  11601. $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
  11602. $font = substr($font, 0, $table['head']['offset'] + 8) . pack('N', $checkSumAdjustment) . substr($font, $table['head']['offset'] + 12);
  11603. return $font;
  11604. }
  11605. /**
  11606. * Returs the checksum of a TTF table.
  11607. * @param string $table table to check
  11608. * @param int $length lenght of table in bytes
  11609. * @return int checksum
  11610. * @author Nicola Asuni
  11611. * @access protected
  11612. * @since 5.2.000 (2010-06-02)
  11613. */
  11614. protected function _getTTFtableChecksum($table, $length)
  11615. {
  11616. $sum = 0;
  11617. $tlen = ($length / 4);
  11618. $offset = 0;
  11619. for($i = 0; $i < $tlen; ++ $i)
  11620. {
  11621. $v = unpack('Ni', substr($table, $offset, 4));
  11622. $sum += $v['i'];
  11623. $offset += 4;
  11624. }
  11625. $sum = unpack('Ni', pack('N', $sum));
  11626. return $sum['i'];
  11627. }
  11628. /**
  11629. * Outputs font widths
  11630. * @param array $font font data
  11631. * @param int $cidoffset offset for CID values
  11632. * @return PDF command string for font widths
  11633. * @author Nicola Asuni
  11634. * @access protected
  11635. * @since 4.4.000 (2008-12-07)
  11636. */
  11637. protected function _putfontwidths($font, $cidoffset = 0)
  11638. {
  11639. ksort($font['cw']);
  11640. $rangeid = 0;
  11641. $range = array();
  11642. $prevcid = - 2;
  11643. $prevwidth = - 1;
  11644. $interval = false;
  11645. // for each character
  11646. foreach ($font['cw'] as $cid => $width)
  11647. {
  11648. $cid -= $cidoffset;
  11649. if ($font['subset'] and ($cid > 255) and (! isset($font['subsetchars'][$cid])))
  11650. {
  11651. // ignore the unused characters (font subsetting)
  11652. continue;
  11653. }
  11654. if ($width != $font['dw'])
  11655. {
  11656. if ($cid == ($prevcid + 1))
  11657. {
  11658. // consecutive CID
  11659. if ($width == $prevwidth)
  11660. {
  11661. if ($width == $range[$rangeid][0])
  11662. {
  11663. $range[$rangeid][] = $width;
  11664. }
  11665. else
  11666. {
  11667. array_pop($range[$rangeid]);
  11668. // new range
  11669. $rangeid = $prevcid;
  11670. $range[$rangeid] = array();
  11671. $range[$rangeid][] = $prevwidth;
  11672. $range[$rangeid][] = $width;
  11673. }
  11674. $interval = true;
  11675. $range[$rangeid]['interval'] = true;
  11676. }
  11677. else
  11678. {
  11679. if ($interval)
  11680. {
  11681. // new range
  11682. $rangeid = $cid;
  11683. $range[$rangeid] = array();
  11684. $range[$rangeid][] = $width;
  11685. }
  11686. else
  11687. {
  11688. $range[$rangeid][] = $width;
  11689. }
  11690. $interval = false;
  11691. }
  11692. }
  11693. else
  11694. {
  11695. // new range
  11696. $rangeid = $cid;
  11697. $range[$rangeid] = array();
  11698. $range[$rangeid][] = $width;
  11699. $interval = false;
  11700. }
  11701. $prevcid = $cid;
  11702. $prevwidth = $width;
  11703. }
  11704. }
  11705. // optimize ranges
  11706. $prevk = - 1;
  11707. $nextk = - 1;
  11708. $prevint = false;
  11709. foreach ($range as $k => $ws)
  11710. {
  11711. $cws = count($ws);
  11712. if (($k == $nextk) and (! $prevint) and ((! isset($ws['interval'])) or ($cws < 4)))
  11713. {
  11714. if (isset($range[$k]['interval']))
  11715. {
  11716. unset($range[$k]['interval']);
  11717. }
  11718. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  11719. unset($range[$k]);
  11720. }
  11721. else
  11722. {
  11723. $prevk = $k;
  11724. }
  11725. $nextk = $k + $cws;
  11726. if (isset($ws['interval']))
  11727. {
  11728. if ($cws > 3)
  11729. {
  11730. $prevint = true;
  11731. }
  11732. else
  11733. {
  11734. $prevint = false;
  11735. }
  11736. unset($range[$k]['interval']);
  11737. -- $nextk;
  11738. }
  11739. else
  11740. {
  11741. $prevint = false;
  11742. }
  11743. }
  11744. // output data
  11745. $w = '';
  11746. foreach ($range as $k => $ws)
  11747. {
  11748. if (count(array_count_values($ws)) == 1)
  11749. {
  11750. // interval mode is more compact
  11751. $w .= ' ' . $k . ' ' . ($k + count($ws) - 1) . ' ' . $ws[0];
  11752. }
  11753. else
  11754. {
  11755. // range mode
  11756. $w .= ' ' . $k . ' [ ' . implode(' ', $ws) . ' ]';
  11757. }
  11758. }
  11759. return '/W [' . $w . ' ]';
  11760. }
  11761. /**
  11762. * Output fonts.
  11763. * @author Nicola Asuni
  11764. * @access protected
  11765. */
  11766. protected function _putfonts()
  11767. {
  11768. $nf = $this->n;
  11769. foreach ($this->diffs as $diff)
  11770. {
  11771. //Encodings
  11772. $this->_newobj();
  11773. $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . '] >>' . "\n" . 'endobj');
  11774. }
  11775. $mqr = $this->get_mqr();
  11776. $this->set_mqr(false);
  11777. foreach ($this->FontFiles as $file => $info)
  11778. {
  11779. // search and get font file to embedd
  11780. $fontdir = $info['fontdir'];
  11781. $file = strtolower($file);
  11782. $fontfile = '';
  11783. // search files on various directories
  11784. if (($fontdir !== false) and file_exists($fontdir . $file))
  11785. {
  11786. $fontfile = $fontdir . $file;
  11787. }
  11788. elseif (file_exists($this->_getfontpath() . $file))
  11789. {
  11790. $fontfile = $this->_getfontpath() . $file;
  11791. }
  11792. elseif (file_exists($file))
  11793. {
  11794. $fontfile = $file;
  11795. }
  11796. if (! $this->empty_string($fontfile))
  11797. {
  11798. $font = file_get_contents($fontfile);
  11799. $compressed = (substr($file, - 2) == '.z');
  11800. if ((! $compressed) and (isset($info['length2'])))
  11801. {
  11802. $header = (ord($font{0}) == 128);
  11803. if ($header)
  11804. {
  11805. //Strip first binary header
  11806. $font = substr($font, 6);
  11807. }
  11808. if ($header and (ord($font{$info['length1']}) == 128))
  11809. {
  11810. //Strip second binary header
  11811. $font = substr($font, 0, $info['length1']) . substr($font, ($info['length1'] + 6));
  11812. }
  11813. }
  11814. elseif ($info['subset'] and ((! $compressed) or ($compressed and function_exists('gzcompress'))))
  11815. {
  11816. if ($compressed)
  11817. {
  11818. // uncompress font
  11819. $font = gzuncompress($font);
  11820. }
  11821. // merge subset characters
  11822. $subsetchars = array(); // used chars
  11823. foreach ($info['fontkeys'] as $fontkey)
  11824. {
  11825. $fontinfo = $this->getFontBuffer($fontkey);
  11826. $subsetchars += $fontinfo['subsetchars'];
  11827. }
  11828. $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
  11829. if ($compressed)
  11830. {
  11831. // recompress font
  11832. $font = gzcompress($font);
  11833. }
  11834. }
  11835. $this->_newobj();
  11836. $this->FontFiles[$file]['n'] = $this->n;
  11837. $stream = $this->_getrawstream($font);
  11838. $out = '<< /Length ' . strlen($stream);
  11839. if ($compressed)
  11840. {
  11841. $out .= ' /Filter /FlateDecode';
  11842. }
  11843. $out .= ' /Length1 ' . $info['length1'];
  11844. if (isset($info['length2']))
  11845. {
  11846. $out .= ' /Length2 ' . $info['length2'] . ' /Length3 0';
  11847. }
  11848. $out .= ' >>';
  11849. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  11850. $out .= "\n" . 'endobj';
  11851. $this->_out($out);
  11852. }
  11853. }
  11854. $this->set_mqr($mqr);
  11855. foreach ($this->fontkeys as $k)
  11856. {
  11857. //Font objects
  11858. $font = $this->getFontBuffer($k);
  11859. $type = $font['type'];
  11860. $name = $font['name'];
  11861. if ($type == 'core')
  11862. {
  11863. // standard core font
  11864. $out = $this->_getobj($this->font_obj_ids[$k]) . "\n";
  11865. $out .= '<</Type /Font';
  11866. $out .= ' /Subtype /Type1';
  11867. $out .= ' /BaseFont /' . $name;
  11868. $out .= ' /Name /F' . $font['i'];
  11869. if ((strtolower($name) != 'symbol') and (strtolower($name) != 'zapfdingbats'))
  11870. {
  11871. $out .= ' /Encoding /WinAnsiEncoding';
  11872. }
  11873. if ($k == 'helvetica')
  11874. {
  11875. // add default font for annotations
  11876. $this->annotation_fonts[$k] = $font['i'];
  11877. }
  11878. $out .= ' >>';
  11879. $out .= "\n" . 'endobj';
  11880. $this->_out($out);
  11881. }
  11882. elseif (($type == 'Type1') or ($type == 'TrueType'))
  11883. {
  11884. // additional Type1 or TrueType font
  11885. $out = $this->_getobj($this->font_obj_ids[$k]) . "\n";
  11886. $out .= '<</Type /Font';
  11887. $out .= ' /Subtype /' . $type;
  11888. $out .= ' /BaseFont /' . $name;
  11889. $out .= ' /Name /F' . $font['i'];
  11890. $out .= ' /FirstChar 32 /LastChar 255';
  11891. $out .= ' /Widths ' . ($this->n + 1) . ' 0 R';
  11892. $out .= ' /FontDescriptor ' . ($this->n + 2) . ' 0 R';
  11893. if ($font['enc'])
  11894. {
  11895. if (isset($font['diff']))
  11896. {
  11897. $out .= ' /Encoding ' . ($nf + $font['diff']) . ' 0 R';
  11898. }
  11899. else
  11900. {
  11901. $out .= ' /Encoding /WinAnsiEncoding';
  11902. }
  11903. }
  11904. $out .= ' >>';
  11905. $out .= "\n" . 'endobj';
  11906. $this->_out($out);
  11907. // Widths
  11908. $this->_newobj();
  11909. $cw = &$font['cw'];
  11910. $s = '[';
  11911. for($i = 32; $i < 256; ++ $i)
  11912. {
  11913. $s .= $cw[$i] . ' ';
  11914. }
  11915. $s .= ']';
  11916. $s .= "\n" . 'endobj';
  11917. $this->_out($s);
  11918. //Descriptor
  11919. $this->_newobj();
  11920. $s = '<</Type /FontDescriptor /FontName /' . $name;
  11921. foreach ($font['desc'] as $fdk => $fdv)
  11922. {
  11923. if (is_float($fdv))
  11924. {
  11925. $fdv = sprintf('%.3F', $fdv);
  11926. }
  11927. $s .= ' /' . $fdk . ' ' . $fdv . '';
  11928. }
  11929. if (! $this->empty_string($font['file']))
  11930. {
  11931. $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R';
  11932. }
  11933. $s .= '>>';
  11934. $s .= "\n" . 'endobj';
  11935. $this->_out($s);
  11936. }
  11937. else
  11938. {
  11939. // additional types
  11940. $mtd = '_put' . strtolower($type);
  11941. if (! method_exists($this, $mtd))
  11942. {
  11943. $this->Error('Unsupported font type: ' . $type);
  11944. }
  11945. $this->$mtd($font);
  11946. }
  11947. }
  11948. }
  11949. /**
  11950. * Adds unicode fonts.<br>
  11951. * Based on PDF Reference 1.3 (section 5)
  11952. * @param array $font font data
  11953. * @access protected
  11954. * @author Nicola Asuni
  11955. * @since 1.52.0.TC005 (2005-01-05)
  11956. */
  11957. protected function _puttruetypeunicode($font)
  11958. {
  11959. $fontname = '';
  11960. if ($font['subset'])
  11961. {
  11962. // change name for font subsetting
  11963. $subtag = sprintf('%06u', $font['i']);
  11964. $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
  11965. $fontname .= $subtag . '+';
  11966. }
  11967. $fontname .= $font['name'];
  11968. // Type0 Font
  11969. // A composite font composed of other fonts, organized hierarchically
  11970. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']]) . "\n";
  11971. $out .= '<< /Type /Font';
  11972. $out .= ' /Subtype /Type0';
  11973. $out .= ' /BaseFont /' . $fontname;
  11974. $out .= ' /Name /F' . $font['i'];
  11975. $out .= ' /Encoding /' . $font['enc'];
  11976. $out .= ' /ToUnicode ' . ($this->n + 1) . ' 0 R';
  11977. $out .= ' /DescendantFonts [' . ($this->n + 2) . ' 0 R]';
  11978. $out .= ' >>';
  11979. $out .= "\n" . 'endobj';
  11980. $this->_out($out);
  11981. // ToUnicode map for Identity-H
  11982. $stream = "/CIDInit /ProcSet findresource begin\n";
  11983. $stream .= "12 dict begin\n";
  11984. $stream .= "begincmap\n";
  11985. $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
  11986. $stream .= "/CMapName /Adobe-Identity-UCS def\n";
  11987. $stream .= "/CMapType 2 def\n";
  11988. $stream .= "/WMode 0 def\n";
  11989. $stream .= "1 begincodespacerange\n";
  11990. $stream .= "<0000> <FFFF>\n";
  11991. $stream .= "endcodespacerange\n";
  11992. $stream .= "100 beginbfrange\n";
  11993. $stream .= "<0000> <00ff> <0000>\n";
  11994. $stream .= "<0100> <01ff> <0100>\n";
  11995. $stream .= "<0200> <02ff> <0200>\n";
  11996. $stream .= "<0300> <03ff> <0300>\n";
  11997. $stream .= "<0400> <04ff> <0400>\n";
  11998. $stream .= "<0500> <05ff> <0500>\n";
  11999. $stream .= "<0600> <06ff> <0600>\n";
  12000. $stream .= "<0700> <07ff> <0700>\n";
  12001. $stream .= "<0800> <08ff> <0800>\n";
  12002. $stream .= "<0900> <09ff> <0900>\n";
  12003. $stream .= "<0a00> <0aff> <0a00>\n";
  12004. $stream .= "<0b00> <0bff> <0b00>\n";
  12005. $stream .= "<0c00> <0cff> <0c00>\n";
  12006. $stream .= "<0d00> <0dff> <0d00>\n";
  12007. $stream .= "<0e00> <0eff> <0e00>\n";
  12008. $stream .= "<0f00> <0fff> <0f00>\n";
  12009. $stream .= "<1000> <10ff> <1000>\n";
  12010. $stream .= "<1100> <11ff> <1100>\n";
  12011. $stream .= "<1200> <12ff> <1200>\n";
  12012. $stream .= "<1300> <13ff> <1300>\n";
  12013. $stream .= "<1400> <14ff> <1400>\n";
  12014. $stream .= "<1500> <15ff> <1500>\n";
  12015. $stream .= "<1600> <16ff> <1600>\n";
  12016. $stream .= "<1700> <17ff> <1700>\n";
  12017. $stream .= "<1800> <18ff> <1800>\n";
  12018. $stream .= "<1900> <19ff> <1900>\n";
  12019. $stream .= "<1a00> <1aff> <1a00>\n";
  12020. $stream .= "<1b00> <1bff> <1b00>\n";
  12021. $stream .= "<1c00> <1cff> <1c00>\n";
  12022. $stream .= "<1d00> <1dff> <1d00>\n";
  12023. $stream .= "<1e00> <1eff> <1e00>\n";
  12024. $stream .= "<1f00> <1fff> <1f00>\n";
  12025. $stream .= "<2000> <20ff> <2000>\n";
  12026. $stream .= "<2100> <21ff> <2100>\n";
  12027. $stream .= "<2200> <22ff> <2200>\n";
  12028. $stream .= "<2300> <23ff> <2300>\n";
  12029. $stream .= "<2400> <24ff> <2400>\n";
  12030. $stream .= "<2500> <25ff> <2500>\n";
  12031. $stream .= "<2600> <26ff> <2600>\n";
  12032. $stream .= "<2700> <27ff> <2700>\n";
  12033. $stream .= "<2800> <28ff> <2800>\n";
  12034. $stream .= "<2900> <29ff> <2900>\n";
  12035. $stream .= "<2a00> <2aff> <2a00>\n";
  12036. $stream .= "<2b00> <2bff> <2b00>\n";
  12037. $stream .= "<2c00> <2cff> <2c00>\n";
  12038. $stream .= "<2d00> <2dff> <2d00>\n";
  12039. $stream .= "<2e00> <2eff> <2e00>\n";
  12040. $stream .= "<2f00> <2fff> <2f00>\n";
  12041. $stream .= "<3000> <30ff> <3000>\n";
  12042. $stream .= "<3100> <31ff> <3100>\n";
  12043. $stream .= "<3200> <32ff> <3200>\n";
  12044. $stream .= "<3300> <33ff> <3300>\n";
  12045. $stream .= "<3400> <34ff> <3400>\n";
  12046. $stream .= "<3500> <35ff> <3500>\n";
  12047. $stream .= "<3600> <36ff> <3600>\n";
  12048. $stream .= "<3700> <37ff> <3700>\n";
  12049. $stream .= "<3800> <38ff> <3800>\n";
  12050. $stream .= "<3900> <39ff> <3900>\n";
  12051. $stream .= "<3a00> <3aff> <3a00>\n";
  12052. $stream .= "<3b00> <3bff> <3b00>\n";
  12053. $stream .= "<3c00> <3cff> <3c00>\n";
  12054. $stream .= "<3d00> <3dff> <3d00>\n";
  12055. $stream .= "<3e00> <3eff> <3e00>\n";
  12056. $stream .= "<3f00> <3fff> <3f00>\n";
  12057. $stream .= "<4000> <40ff> <4000>\n";
  12058. $stream .= "<4100> <41ff> <4100>\n";
  12059. $stream .= "<4200> <42ff> <4200>\n";
  12060. $stream .= "<4300> <43ff> <4300>\n";
  12061. $stream .= "<4400> <44ff> <4400>\n";
  12062. $stream .= "<4500> <45ff> <4500>\n";
  12063. $stream .= "<4600> <46ff> <4600>\n";
  12064. $stream .= "<4700> <47ff> <4700>\n";
  12065. $stream .= "<4800> <48ff> <4800>\n";
  12066. $stream .= "<4900> <49ff> <4900>\n";
  12067. $stream .= "<4a00> <4aff> <4a00>\n";
  12068. $stream .= "<4b00> <4bff> <4b00>\n";
  12069. $stream .= "<4c00> <4cff> <4c00>\n";
  12070. $stream .= "<4d00> <4dff> <4d00>\n";
  12071. $stream .= "<4e00> <4eff> <4e00>\n";
  12072. $stream .= "<4f00> <4fff> <4f00>\n";
  12073. $stream .= "<5000> <50ff> <5000>\n";
  12074. $stream .= "<5100> <51ff> <5100>\n";
  12075. $stream .= "<5200> <52ff> <5200>\n";
  12076. $stream .= "<5300> <53ff> <5300>\n";
  12077. $stream .= "<5400> <54ff> <5400>\n";
  12078. $stream .= "<5500> <55ff> <5500>\n";
  12079. $stream .= "<5600> <56ff> <5600>\n";
  12080. $stream .= "<5700> <57ff> <5700>\n";
  12081. $stream .= "<5800> <58ff> <5800>\n";
  12082. $stream .= "<5900> <59ff> <5900>\n";
  12083. $stream .= "<5a00> <5aff> <5a00>\n";
  12084. $stream .= "<5b00> <5bff> <5b00>\n";
  12085. $stream .= "<5c00> <5cff> <5c00>\n";
  12086. $stream .= "<5d00> <5dff> <5d00>\n";
  12087. $stream .= "<5e00> <5eff> <5e00>\n";
  12088. $stream .= "<5f00> <5fff> <5f00>\n";
  12089. $stream .= "<6000> <60ff> <6000>\n";
  12090. $stream .= "<6100> <61ff> <6100>\n";
  12091. $stream .= "<6200> <62ff> <6200>\n";
  12092. $stream .= "<6300> <63ff> <6300>\n";
  12093. $stream .= "endbfrange\n";
  12094. $stream .= "100 beginbfrange\n";
  12095. $stream .= "<6400> <64ff> <6400>\n";
  12096. $stream .= "<6500> <65ff> <6500>\n";
  12097. $stream .= "<6600> <66ff> <6600>\n";
  12098. $stream .= "<6700> <67ff> <6700>\n";
  12099. $stream .= "<6800> <68ff> <6800>\n";
  12100. $stream .= "<6900> <69ff> <6900>\n";
  12101. $stream .= "<6a00> <6aff> <6a00>\n";
  12102. $stream .= "<6b00> <6bff> <6b00>\n";
  12103. $stream .= "<6c00> <6cff> <6c00>\n";
  12104. $stream .= "<6d00> <6dff> <6d00>\n";
  12105. $stream .= "<6e00> <6eff> <6e00>\n";
  12106. $stream .= "<6f00> <6fff> <6f00>\n";
  12107. $stream .= "<7000> <70ff> <7000>\n";
  12108. $stream .= "<7100> <71ff> <7100>\n";
  12109. $stream .= "<7200> <72ff> <7200>\n";
  12110. $stream .= "<7300> <73ff> <7300>\n";
  12111. $stream .= "<7400> <74ff> <7400>\n";
  12112. $stream .= "<7500> <75ff> <7500>\n";
  12113. $stream .= "<7600> <76ff> <7600>\n";
  12114. $stream .= "<7700> <77ff> <7700>\n";
  12115. $stream .= "<7800> <78ff> <7800>\n";
  12116. $stream .= "<7900> <79ff> <7900>\n";
  12117. $stream .= "<7a00> <7aff> <7a00>\n";
  12118. $stream .= "<7b00> <7bff> <7b00>\n";
  12119. $stream .= "<7c00> <7cff> <7c00>\n";
  12120. $stream .= "<7d00> <7dff> <7d00>\n";
  12121. $stream .= "<7e00> <7eff> <7e00>\n";
  12122. $stream .= "<7f00> <7fff> <7f00>\n";
  12123. $stream .= "<8000> <80ff> <8000>\n";
  12124. $stream .= "<8100> <81ff> <8100>\n";
  12125. $stream .= "<8200> <82ff> <8200>\n";
  12126. $stream .= "<8300> <83ff> <8300>\n";
  12127. $stream .= "<8400> <84ff> <8400>\n";
  12128. $stream .= "<8500> <85ff> <8500>\n";
  12129. $stream .= "<8600> <86ff> <8600>\n";
  12130. $stream .= "<8700> <87ff> <8700>\n";
  12131. $stream .= "<8800> <88ff> <8800>\n";
  12132. $stream .= "<8900> <89ff> <8900>\n";
  12133. $stream .= "<8a00> <8aff> <8a00>\n";
  12134. $stream .= "<8b00> <8bff> <8b00>\n";
  12135. $stream .= "<8c00> <8cff> <8c00>\n";
  12136. $stream .= "<8d00> <8dff> <8d00>\n";
  12137. $stream .= "<8e00> <8eff> <8e00>\n";
  12138. $stream .= "<8f00> <8fff> <8f00>\n";
  12139. $stream .= "<9000> <90ff> <9000>\n";
  12140. $stream .= "<9100> <91ff> <9100>\n";
  12141. $stream .= "<9200> <92ff> <9200>\n";
  12142. $stream .= "<9300> <93ff> <9300>\n";
  12143. $stream .= "<9400> <94ff> <9400>\n";
  12144. $stream .= "<9500> <95ff> <9500>\n";
  12145. $stream .= "<9600> <96ff> <9600>\n";
  12146. $stream .= "<9700> <97ff> <9700>\n";
  12147. $stream .= "<9800> <98ff> <9800>\n";
  12148. $stream .= "<9900> <99ff> <9900>\n";
  12149. $stream .= "<9a00> <9aff> <9a00>\n";
  12150. $stream .= "<9b00> <9bff> <9b00>\n";
  12151. $stream .= "<9c00> <9cff> <9c00>\n";
  12152. $stream .= "<9d00> <9dff> <9d00>\n";
  12153. $stream .= "<9e00> <9eff> <9e00>\n";
  12154. $stream .= "<9f00> <9fff> <9f00>\n";
  12155. $stream .= "<a000> <a0ff> <a000>\n";
  12156. $stream .= "<a100> <a1ff> <a100>\n";
  12157. $stream .= "<a200> <a2ff> <a200>\n";
  12158. $stream .= "<a300> <a3ff> <a300>\n";
  12159. $stream .= "<a400> <a4ff> <a400>\n";
  12160. $stream .= "<a500> <a5ff> <a500>\n";
  12161. $stream .= "<a600> <a6ff> <a600>\n";
  12162. $stream .= "<a700> <a7ff> <a700>\n";
  12163. $stream .= "<a800> <a8ff> <a800>\n";
  12164. $stream .= "<a900> <a9ff> <a900>\n";
  12165. $stream .= "<aa00> <aaff> <aa00>\n";
  12166. $stream .= "<ab00> <abff> <ab00>\n";
  12167. $stream .= "<ac00> <acff> <ac00>\n";
  12168. $stream .= "<ad00> <adff> <ad00>\n";
  12169. $stream .= "<ae00> <aeff> <ae00>\n";
  12170. $stream .= "<af00> <afff> <af00>\n";
  12171. $stream .= "<b000> <b0ff> <b000>\n";
  12172. $stream .= "<b100> <b1ff> <b100>\n";
  12173. $stream .= "<b200> <b2ff> <b200>\n";
  12174. $stream .= "<b300> <b3ff> <b300>\n";
  12175. $stream .= "<b400> <b4ff> <b400>\n";
  12176. $stream .= "<b500> <b5ff> <b500>\n";
  12177. $stream .= "<b600> <b6ff> <b600>\n";
  12178. $stream .= "<b700> <b7ff> <b700>\n";
  12179. $stream .= "<b800> <b8ff> <b800>\n";
  12180. $stream .= "<b900> <b9ff> <b900>\n";
  12181. $stream .= "<ba00> <baff> <ba00>\n";
  12182. $stream .= "<bb00> <bbff> <bb00>\n";
  12183. $stream .= "<bc00> <bcff> <bc00>\n";
  12184. $stream .= "<bd00> <bdff> <bd00>\n";
  12185. $stream .= "<be00> <beff> <be00>\n";
  12186. $stream .= "<bf00> <bfff> <bf00>\n";
  12187. $stream .= "<c000> <c0ff> <c000>\n";
  12188. $stream .= "<c100> <c1ff> <c100>\n";
  12189. $stream .= "<c200> <c2ff> <c200>\n";
  12190. $stream .= "<c300> <c3ff> <c300>\n";
  12191. $stream .= "<c400> <c4ff> <c400>\n";
  12192. $stream .= "<c500> <c5ff> <c500>\n";
  12193. $stream .= "<c600> <c6ff> <c600>\n";
  12194. $stream .= "<c700> <c7ff> <c700>\n";
  12195. $stream .= "endbfrange\n";
  12196. $stream .= "56 beginbfrange\n";
  12197. $stream .= "<c800> <c8ff> <c800>\n";
  12198. $stream .= "<c900> <c9ff> <c900>\n";
  12199. $stream .= "<ca00> <caff> <ca00>\n";
  12200. $stream .= "<cb00> <cbff> <cb00>\n";
  12201. $stream .= "<cc00> <ccff> <cc00>\n";
  12202. $stream .= "<cd00> <cdff> <cd00>\n";
  12203. $stream .= "<ce00> <ceff> <ce00>\n";
  12204. $stream .= "<cf00> <cfff> <cf00>\n";
  12205. $stream .= "<d000> <d0ff> <d000>\n";
  12206. $stream .= "<d100> <d1ff> <d100>\n";
  12207. $stream .= "<d200> <d2ff> <d200>\n";
  12208. $stream .= "<d300> <d3ff> <d300>\n";
  12209. $stream .= "<d400> <d4ff> <d400>\n";
  12210. $stream .= "<d500> <d5ff> <d500>\n";
  12211. $stream .= "<d600> <d6ff> <d600>\n";
  12212. $stream .= "<d700> <d7ff> <d700>\n";
  12213. $stream .= "<d800> <d8ff> <d800>\n";
  12214. $stream .= "<d900> <d9ff> <d900>\n";
  12215. $stream .= "<da00> <daff> <da00>\n";
  12216. $stream .= "<db00> <dbff> <db00>\n";
  12217. $stream .= "<dc00> <dcff> <dc00>\n";
  12218. $stream .= "<dd00> <ddff> <dd00>\n";
  12219. $stream .= "<de00> <deff> <de00>\n";
  12220. $stream .= "<df00> <dfff> <df00>\n";
  12221. $stream .= "<e000> <e0ff> <e000>\n";
  12222. $stream .= "<e100> <e1ff> <e100>\n";
  12223. $stream .= "<e200> <e2ff> <e200>\n";
  12224. $stream .= "<e300> <e3ff> <e300>\n";
  12225. $stream .= "<e400> <e4ff> <e400>\n";
  12226. $stream .= "<e500> <e5ff> <e500>\n";
  12227. $stream .= "<e600> <e6ff> <e600>\n";
  12228. $stream .= "<e700> <e7ff> <e700>\n";
  12229. $stream .= "<e800> <e8ff> <e800>\n";
  12230. $stream .= "<e900> <e9ff> <e900>\n";
  12231. $stream .= "<ea00> <eaff> <ea00>\n";
  12232. $stream .= "<eb00> <ebff> <eb00>\n";
  12233. $stream .= "<ec00> <ecff> <ec00>\n";
  12234. $stream .= "<ed00> <edff> <ed00>\n";
  12235. $stream .= "<ee00> <eeff> <ee00>\n";
  12236. $stream .= "<ef00> <efff> <ef00>\n";
  12237. $stream .= "<f000> <f0ff> <f000>\n";
  12238. $stream .= "<f100> <f1ff> <f100>\n";
  12239. $stream .= "<f200> <f2ff> <f200>\n";
  12240. $stream .= "<f300> <f3ff> <f300>\n";
  12241. $stream .= "<f400> <f4ff> <f400>\n";
  12242. $stream .= "<f500> <f5ff> <f500>\n";
  12243. $stream .= "<f600> <f6ff> <f600>\n";
  12244. $stream .= "<f700> <f7ff> <f700>\n";
  12245. $stream .= "<f800> <f8ff> <f800>\n";
  12246. $stream .= "<f900> <f9ff> <f900>\n";
  12247. $stream .= "<fa00> <faff> <fa00>\n";
  12248. $stream .= "<fb00> <fbff> <fb00>\n";
  12249. $stream .= "<fc00> <fcff> <fc00>\n";
  12250. $stream .= "<fd00> <fdff> <fd00>\n";
  12251. $stream .= "<fe00> <feff> <fe00>\n";
  12252. $stream .= "<ff00> <ffff> <ff00>\n";
  12253. $stream .= "endbfrange\n";
  12254. $stream .= "endcmap\n";
  12255. $stream .= "CMapName currentdict /CMap defineresource pop\n";
  12256. $stream .= "end\n";
  12257. $stream .= "end";
  12258. // ToUnicode Object
  12259. $this->_newobj();
  12260. $stream = ($this->compress) ? gzcompress($stream) : $stream;
  12261. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  12262. $stream = $this->_getrawstream($stream);
  12263. $this->_out('<<' . $filter . '/Length ' . strlen($stream) . '>> stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj');
  12264. // CIDFontType2
  12265. // A CIDFont whose glyph descriptions are based on TrueType font technology
  12266. $oid = $this->_newobj();
  12267. $out = '<< /Type /Font';
  12268. $out .= ' /Subtype /CIDFontType2';
  12269. $out .= ' /BaseFont /' . $fontname;
  12270. // A dictionary containing entries that define the character collection of the CIDFont.
  12271. $cidinfo = '/Registry ' . $this->_datastring($font['cidinfo']['Registry'], $oid);
  12272. $cidinfo .= ' /Ordering ' . $this->_datastring($font['cidinfo']['Ordering'], $oid);
  12273. $cidinfo .= ' /Supplement ' . $font['cidinfo']['Supplement'];
  12274. $out .= ' /CIDSystemInfo << ' . $cidinfo . ' >>';
  12275. $out .= ' /FontDescriptor ' . ($this->n + 1) . ' 0 R';
  12276. $out .= ' /DW ' . $font['dw']; // default width
  12277. $out .= "\n" . $this->_putfontwidths($font, 0);
  12278. if (isset($font['ctg']) and (! $this->empty_string($font['ctg'])))
  12279. {
  12280. $out .= "\n" . '/CIDToGIDMap ' . ($this->n + 2) . ' 0 R';
  12281. }
  12282. $out .= ' >>';
  12283. $out .= "\n" . 'endobj';
  12284. $this->_out($out);
  12285. // Font descriptor
  12286. // A font descriptor describing the CIDFont default metrics other than its glyph widths
  12287. $this->_newobj();
  12288. $out = '<< /Type /FontDescriptor';
  12289. $out .= ' /FontName /' . $fontname;
  12290. foreach ($font['desc'] as $key => $value)
  12291. {
  12292. if (is_float($value))
  12293. {
  12294. $value = sprintf('%.3F', $value);
  12295. }
  12296. $out .= ' /' . $key . ' ' . $value;
  12297. }
  12298. $fontdir = false;
  12299. if (! $this->empty_string($font['file']))
  12300. {
  12301. // A stream containing a TrueType font
  12302. $out .= ' /FontFile2 ' . $this->FontFiles[$font['file']]['n'] . ' 0 R';
  12303. $fontdir = $this->FontFiles[$font['file']]['fontdir'];
  12304. }
  12305. $out .= ' >>';
  12306. $out .= "\n" . 'endobj';
  12307. $this->_out($out);
  12308. if (isset($font['ctg']) and (! $this->empty_string($font['ctg'])))
  12309. {
  12310. $this->_newobj();
  12311. // Embed CIDToGIDMap
  12312. // A specification of the mapping from CIDs to glyph indices
  12313. // search and get CTG font file to embedd
  12314. $ctgfile = strtolower($font['ctg']);
  12315. // search and get ctg font file to embedd
  12316. $fontfile = '';
  12317. // search files on various directories
  12318. if (($fontdir !== false) and file_exists($fontdir . $ctgfile))
  12319. {
  12320. $fontfile = $fontdir . $ctgfile;
  12321. }
  12322. elseif (file_exists($this->_getfontpath() . $ctgfile))
  12323. {
  12324. $fontfile = $this->_getfontpath() . $ctgfile;
  12325. }
  12326. elseif (file_exists($ctgfile))
  12327. {
  12328. $fontfile = $ctgfile;
  12329. }
  12330. if ($this->empty_string($fontfile))
  12331. {
  12332. $this->Error('Font file not found: ' . $ctgfile);
  12333. }
  12334. $stream = $this->_getrawstream(file_get_contents($fontfile));
  12335. $out = '<< /Length ' . strlen($stream) . '';
  12336. if (substr($fontfile, - 2) == '.z')
  12337. { // check file extension
  12338. // Decompresses data encoded using the public-domain
  12339. // zlib/deflate compression method, reproducing the
  12340. // original text or binary data
  12341. $out .= ' /Filter /FlateDecode';
  12342. }
  12343. $out .= ' >>';
  12344. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  12345. $out .= "\n" . 'endobj';
  12346. $this->_out($out);
  12347. }
  12348. }
  12349. /**
  12350. * Output CID-0 fonts.
  12351. * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
  12352. * @param array $font font data
  12353. * @access protected
  12354. * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
  12355. * @since 3.2.000 (2008-06-23)
  12356. */
  12357. protected function _putcidfont0($font)
  12358. {
  12359. $cidoffset = 0;
  12360. if (! isset($font['cw'][1]))
  12361. {
  12362. $cidoffset = 31;
  12363. }
  12364. if (isset($font['cidinfo']['uni2cid']))
  12365. {
  12366. // convert unicode to cid.
  12367. $uni2cid = $font['cidinfo']['uni2cid'];
  12368. $cw = array();
  12369. foreach ($font['cw'] as $uni => $width)
  12370. {
  12371. if (isset($uni2cid[$uni]))
  12372. {
  12373. $cw[($uni2cid[$uni] + $cidoffset)] = $width;
  12374. }
  12375. elseif ($uni < 256)
  12376. {
  12377. $cw[$uni] = $width;
  12378. } // else unknown character
  12379. }
  12380. $font = array_merge($font, array('cw' => $cw));
  12381. }
  12382. $name = $font['name'];
  12383. $enc = $font['enc'];
  12384. if ($enc)
  12385. {
  12386. $longname = $name . '-' . $enc;
  12387. }
  12388. else
  12389. {
  12390. $longname = $name;
  12391. }
  12392. $out = $this->_getobj($this->font_obj_ids[$font['fontkey']]) . "\n";
  12393. $out .= '<</Type /Font';
  12394. $out .= ' /Subtype /Type0';
  12395. $out .= ' /BaseFont /' . $longname;
  12396. $out .= ' /Name /F' . $font['i'];
  12397. if ($enc)
  12398. {
  12399. $out .= ' /Encoding /' . $enc;
  12400. }
  12401. $out .= ' /DescendantFonts [' . ($this->n + 1) . ' 0 R]';
  12402. $out .= ' >>';
  12403. $out .= "\n" . 'endobj';
  12404. $this->_out($out);
  12405. $oid = $this->_newobj();
  12406. $out = '<</Type /Font';
  12407. $out .= ' /Subtype /CIDFontType0';
  12408. $out .= ' /BaseFont /' . $name;
  12409. $cidinfo = '/Registry ' . $this->_datastring($font['cidinfo']['Registry'], $oid);
  12410. $cidinfo .= ' /Ordering ' . $this->_datastring($font['cidinfo']['Ordering'], $oid);
  12411. $cidinfo .= ' /Supplement ' . $font['cidinfo']['Supplement'];
  12412. $out .= ' /CIDSystemInfo <<' . $cidinfo . '>>';
  12413. $out .= ' /FontDescriptor ' . ($this->n + 1) . ' 0 R';
  12414. $out .= ' /DW ' . $font['dw'];
  12415. $out .= "\n" . $this->_putfontwidths($font, $cidoffset);
  12416. $out .= ' >>';
  12417. $out .= "\n" . 'endobj';
  12418. $this->_out($out);
  12419. $this->_newobj();
  12420. $s = '<</Type /FontDescriptor /FontName /' . $name;
  12421. foreach ($font['desc'] as $k => $v)
  12422. {
  12423. if ($k != 'Style')
  12424. {
  12425. if (is_float($v))
  12426. {
  12427. $v = sprintf('%.3F', $v);
  12428. }
  12429. $s .= ' /' . $k . ' ' . $v . '';
  12430. }
  12431. }
  12432. $s .= '>>';
  12433. $s .= "\n" . 'endobj';
  12434. $this->_out($s);
  12435. }
  12436. /**
  12437. * Output images.
  12438. * @access protected
  12439. */
  12440. protected function _putimages()
  12441. {
  12442. $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';
  12443. foreach ($this->imagekeys as $file)
  12444. {
  12445. $info = $this->getImageBuffer($file);
  12446. $oid = $this->_newobj();
  12447. $this->xobjects['I' . $info['i']] = array('n' => $oid);
  12448. $this->setImageSubBuffer($file, 'n', $this->n);
  12449. $out = '<</Type /XObject';
  12450. $out .= ' /Subtype /Image';
  12451. $out .= ' /Width ' . $info['w'];
  12452. $out .= ' /Height ' . $info['h'];
  12453. if (array_key_exists('masked', $info))
  12454. {
  12455. $out .= ' /SMask ' . ($this->n - 1) . ' 0 R';
  12456. }
  12457. if ($info['cs'] == 'Indexed')
  12458. {
  12459. $out .= ' /ColorSpace [/Indexed /DeviceRGB ' . ((strlen($info['pal']) / 3) - 1) . ' ' . ($this->n + 1) . ' 0 R]';
  12460. }
  12461. else
  12462. {
  12463. $out .= ' /ColorSpace /' . $info['cs'];
  12464. if ($info['cs'] == 'DeviceCMYK')
  12465. {
  12466. $out .= ' /Decode [1 0 1 0 1 0 1 0]';
  12467. }
  12468. }
  12469. $out .= ' /BitsPerComponent ' . $info['bpc'];
  12470. if (isset($info['f']))
  12471. {
  12472. $out .= ' /Filter /' . $info['f'];
  12473. }
  12474. if (isset($info['parms']))
  12475. {
  12476. $out .= ' ' . $info['parms'];
  12477. }
  12478. if (isset($info['trns']) and is_array($info['trns']))
  12479. {
  12480. $trns = '';
  12481. $count_info = count($info['trns']);
  12482. for($i = 0; $i < $count_info; ++ $i)
  12483. {
  12484. $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' ';
  12485. }
  12486. $out .= ' /Mask [' . $trns . ']';
  12487. }
  12488. $stream = $this->_getrawstream($info['data']);
  12489. $out .= ' /Length ' . strlen($stream) . ' >>';
  12490. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  12491. $out .= "\n" . 'endobj';
  12492. $this->_out($out);
  12493. //Palette
  12494. if ($info['cs'] == 'Indexed')
  12495. {
  12496. $this->_newobj();
  12497. $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  12498. $pal = $this->_getrawstream($pal);
  12499. $this->_out('<<' . $filter . '/Length ' . strlen($pal) . '>> stream' . "\n" . $pal . "\n" . 'endstream' . "\n" . 'endobj');
  12500. }
  12501. }
  12502. }
  12503. /**
  12504. * Output Form XObjects Templates.
  12505. * @author Nicola Asuni
  12506. * @since 5.8.017 (2010-08-24)
  12507. * @access protected
  12508. * @see startTemplate(), endTemplate(), printTemplate()
  12509. */
  12510. protected function _putxobjects()
  12511. {
  12512. foreach ($this->xobjects as $key => $data)
  12513. {
  12514. if (isset($data['outdata']))
  12515. {
  12516. $stream = trim($data['outdata']);
  12517. $out = $this->_getobj($data['n']) . "\n";
  12518. $out .= '<<';
  12519. $out .= ' /Type /XObject';
  12520. $out .= ' /Subtype /Form';
  12521. $out .= ' /FormType 1';
  12522. if ($this->compress)
  12523. {
  12524. $stream = gzcompress($stream);
  12525. $out .= ' /Filter /FlateDecode';
  12526. }
  12527. $out .= sprintf(' /BBox [%.2F %.2F %.2F %.2F]', ($data['x'] * $this->k), (- $data['y'] * $this->k), (($data['w'] + $data['x']) * $this->k), (($data['h'] - $data['y']) * $this->k));
  12528. $out .= ' /Matrix [1 0 0 1 0 0]';
  12529. $out .= ' /Resources <<';
  12530. $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  12531. // fonts
  12532. if (! empty($data['fonts']))
  12533. {
  12534. $out .= ' /Font <<';
  12535. foreach ($data['fonts'] as $fontkey => $fontid)
  12536. {
  12537. $out .= ' /F' . $fontid . ' ' . $this->font_obj_ids[$fontkey] . ' 0 R';
  12538. }
  12539. $out .= ' >>';
  12540. }
  12541. // images or nested xobjects
  12542. if (! empty($data['images']) or ! empty($data['xobjects']))
  12543. {
  12544. $out .= ' /XObject <<';
  12545. foreach ($data['images'] as $imgid)
  12546. {
  12547. $out .= ' /I' . $imgid . ' ' . $this->xobjects['I' . $imgid]['n'] . ' 0 R';
  12548. }
  12549. foreach ($data['xobjects'] as $sub_id => $sub_objid)
  12550. {
  12551. $out .= ' /' . $sub_id . ' ' . $sub_objid['n'] . ' 0 R';
  12552. }
  12553. $out .= ' >>';
  12554. }
  12555. $out .= ' >>';
  12556. $stream = $this->_getrawstream($stream);
  12557. $out .= ' /Length ' . strlen($stream);
  12558. $out .= ' >>';
  12559. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  12560. $out .= "\n" . 'endobj';
  12561. $this->_out($out);
  12562. }
  12563. }
  12564. }
  12565. /**
  12566. * Output Spot Colors Resources.
  12567. * @access protected
  12568. * @since 4.0.024 (2008-09-12)
  12569. */
  12570. protected function _putspotcolors()
  12571. {
  12572. foreach ($this->spot_colors as $name => $color)
  12573. {
  12574. $this->_newobj();
  12575. $this->spot_colors[$name]['n'] = $this->n;
  12576. $out = '[/Separation /' . str_replace(' ', '#20', $name);
  12577. $out .= ' /DeviceCMYK <<';
  12578. $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
  12579. $out .= ' ' . sprintf('/C1 [%.4F %.4F %.4F %.4F] ', $color['c'] / 100, $color['m'] / 100, $color['y'] / 100, $color['k'] / 100);
  12580. $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
  12581. $out .= "\n" . 'endobj';
  12582. $this->_out($out);
  12583. }
  12584. }
  12585. /**
  12586. * Return XObjects Dictionary.
  12587. * @return string XObjects dictionary
  12588. * @access protected
  12589. * @since 5.8.014 (2010-08-23)
  12590. */
  12591. protected function _getxobjectdict()
  12592. {
  12593. $out = '';
  12594. foreach ($this->xobjects as $id => $objid)
  12595. {
  12596. $out .= ' /' . $id . ' ' . $objid['n'] . ' 0 R';
  12597. }
  12598. return $out;
  12599. }
  12600. /**
  12601. * Output Resources Dictionary.
  12602. * @access protected
  12603. */
  12604. protected function _putresourcedict()
  12605. {
  12606. $out = $this->_getobj(2) . "\n";
  12607. $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
  12608. $out .= ' /Font <<';
  12609. foreach ($this->fontkeys as $fontkey)
  12610. {
  12611. $font = $this->getFontBuffer($fontkey);
  12612. $out .= ' /F' . $font['i'] . ' ' . $font['n'] . ' 0 R';
  12613. }
  12614. $out .= ' >>';
  12615. $out .= ' /XObject <<';
  12616. $out .= $this->_getxobjectdict();
  12617. $out .= ' >>';
  12618. // visibility
  12619. $out .= ' /Properties <</OC1 ' . $this->n_ocg_print . ' 0 R /OC2 ' . $this->n_ocg_view . ' 0 R>>';
  12620. // transparency
  12621. $out .= ' /ExtGState <<';
  12622. foreach ($this->extgstates as $k => $extgstate)
  12623. {
  12624. if (isset($extgstate['name']))
  12625. {
  12626. $out .= ' /' . $extgstate['name'];
  12627. }
  12628. else
  12629. {
  12630. $out .= ' /GS' . $k;
  12631. }
  12632. $out .= ' ' . $extgstate['n'] . ' 0 R';
  12633. }
  12634. $out .= ' >>';
  12635. // gradient patterns
  12636. if (isset($this->gradients) and (count($this->gradients) > 0))
  12637. {
  12638. $out .= ' /Pattern <<';
  12639. foreach ($this->gradients as $id => $grad)
  12640. {
  12641. $out .= ' /p' . $id . ' ' . $grad['pattern'] . ' 0 R';
  12642. }
  12643. $out .= ' >>';
  12644. }
  12645. // gradient shadings
  12646. if (isset($this->gradients) and (count($this->gradients) > 0))
  12647. {
  12648. $out .= ' /Shading <<';
  12649. foreach ($this->gradients as $id => $grad)
  12650. {
  12651. $out .= ' /Sh' . $id . ' ' . $grad['id'] . ' 0 R';
  12652. }
  12653. $out .= ' >>';
  12654. }
  12655. // spot colors
  12656. if (isset($this->spot_colors) and (count($this->spot_colors) > 0))
  12657. {
  12658. $out .= ' /ColorSpace <<';
  12659. foreach ($this->spot_colors as $color)
  12660. {
  12661. $out .= ' /CS' . $color['i'] . ' ' . $color['n'] . ' 0 R';
  12662. }
  12663. $out .= ' >>';
  12664. }
  12665. $out .= ' >>';
  12666. $out .= "\n" . 'endobj';
  12667. $this->_out($out);
  12668. }
  12669. /**
  12670. * Output Resources.
  12671. * @access protected
  12672. */
  12673. protected function _putresources()
  12674. {
  12675. $this->_putextgstates();
  12676. $this->_putocg();
  12677. $this->_putfonts();
  12678. $this->_putimages();
  12679. $this->_putxobjects();
  12680. $this->_putspotcolors();
  12681. $this->_putshaders();
  12682. $this->_putresourcedict();
  12683. $this->_putbookmarks();
  12684. $this->_putEmbeddedFiles();
  12685. $this->_putannotsobjs();
  12686. $this->_putjavascript();
  12687. $this->_putencryption();
  12688. }
  12689. /**
  12690. * Adds some Metadata information (Document Information Dictionary)
  12691. * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
  12692. * @return int object id
  12693. * @access protected
  12694. */
  12695. protected function _putinfo()
  12696. {
  12697. $oid = $this->_newobj();
  12698. $out = '<<';
  12699. if (! $this->empty_string($this->title))
  12700. {
  12701. // The document's title.
  12702. $out .= ' /Title ' . $this->_textstring($this->title, $oid);
  12703. }
  12704. if (! $this->empty_string($this->author))
  12705. {
  12706. // The name of the person who created the document.
  12707. $out .= ' /Author ' . $this->_textstring($this->author, $oid);
  12708. }
  12709. if (! $this->empty_string($this->subject))
  12710. {
  12711. // The subject of the document.
  12712. $out .= ' /Subject ' . $this->_textstring($this->subject, $oid);
  12713. }
  12714. if (! $this->empty_string($this->keywords))
  12715. {
  12716. // Keywords associated with the document.
  12717. $out .= ' /Keywords ' . $this->_textstring($this->keywords . ' TCP' . 'DF', $oid);
  12718. }
  12719. if (! $this->empty_string($this->creator))
  12720. {
  12721. // 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.
  12722. $out .= ' /Creator ' . $this->_textstring($this->creator, $oid);
  12723. }
  12724. if (defined('PDF_PRODUCER'))
  12725. {
  12726. // If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF.
  12727. $out .= ' /Producer ' . $this->_textstring(PDF_PRODUCER . ' (TCP' . 'DF)', $oid);
  12728. }
  12729. else
  12730. {
  12731. // default producer
  12732. $out .= ' /Producer ' . $this->_textstring('TCP' . 'DF', $oid);
  12733. }
  12734. // The date and time the document was created, in human-readable form
  12735. $out .= ' /CreationDate ' . $this->_datestring();
  12736. // The date and time the document was most recently modified, in human-readable form
  12737. $out .= ' /ModDate ' . $this->_datestring();
  12738. // A name object indicating whether the document has been modified to include trapping information
  12739. $out .= ' /Trapped /False';
  12740. $out .= ' >>';
  12741. $out .= "\n" . 'endobj';
  12742. $this->_out($out);
  12743. return $oid;
  12744. }
  12745. /**
  12746. * Output Catalog.
  12747. * @return int object id
  12748. * @access protected
  12749. */
  12750. protected function _putcatalog()
  12751. {
  12752. $oid = $this->_newobj();
  12753. $out = '<< /Type /Catalog';
  12754. $out .= ' /Pages 1 0 R';
  12755. if ($this->ZoomMode == 'fullpage')
  12756. {
  12757. $out .= ' /OpenAction [' . $this->page_obj_id[1] . ' 0 R /Fit]';
  12758. }
  12759. elseif ($this->ZoomMode == 'fullwidth')
  12760. {
  12761. $out .= ' /OpenAction [' . $this->page_obj_id[1] . ' 0 R /FitH null]';
  12762. }
  12763. elseif ($this->ZoomMode == 'real')
  12764. {
  12765. $out .= ' /OpenAction [' . $this->page_obj_id[1] . ' 0 R /XYZ null null 1]';
  12766. }
  12767. elseif (! is_string($this->ZoomMode))
  12768. {
  12769. $out .= sprintf(' /OpenAction [' . $this->page_obj_id[1] . ' 0 R /XYZ null null %.2F]', ($this->ZoomMode / 100));
  12770. }
  12771. if (isset($this->LayoutMode) and (! $this->empty_string($this->LayoutMode)))
  12772. {
  12773. $out .= ' /PageLayout /' . $this->LayoutMode;
  12774. }
  12775. if (isset($this->PageMode) and (! $this->empty_string($this->PageMode)))
  12776. {
  12777. $out .= ' /PageMode /' . $this->PageMode;
  12778. }
  12779. if (isset($this->l['a_meta_language']))
  12780. {
  12781. $out .= ' /Lang ' . $this->_textstring($this->l['a_meta_language'], $oid);
  12782. }
  12783. $out .= ' /Names <<';
  12784. if ((! empty($this->javascript)) or (! empty($this->js_objects)))
  12785. {
  12786. $out .= ' /JavaScript ' . ($this->n_js) . ' 0 R';
  12787. }
  12788. $out .= ' >>';
  12789. if (count($this->outlines) > 0)
  12790. {
  12791. $out .= ' /Outlines ' . $this->OutlineRoot . ' 0 R';
  12792. $out .= ' /PageMode /UseOutlines';
  12793. }
  12794. $out .= ' ' . $this->_putviewerpreferences();
  12795. $p = $this->n_ocg_print . ' 0 R';
  12796. $v = $this->n_ocg_view . ' 0 R';
  12797. $as = '<< /Event /Print /OCGs [' . $p . ' ' . $v . '] /Category [/Print] >> << /Event /View /OCGs [' . $p . ' ' . $v . '] /Category [/View] >>';
  12798. $out .= ' /OCProperties << /OCGs [' . $p . ' ' . $v . '] /D << /ON [' . $p . '] /OFF [' . $v . '] /AS [' . $as . '] >> >>';
  12799. // AcroForm
  12800. if (! empty($this->form_obj_id) or ($this->sign and isset($this->signature_data['cert_type'])))
  12801. {
  12802. $out .= ' /AcroForm <<';
  12803. $objrefs = '';
  12804. if ($this->sign and isset($this->signature_data['cert_type']))
  12805. {
  12806. $objrefs .= $this->sig_obj_id . ' 0 R';
  12807. }
  12808. if (! empty($this->form_obj_id))
  12809. {
  12810. foreach ($this->form_obj_id as $objid)
  12811. {
  12812. $objrefs .= ' ' . $objid . ' 0 R';
  12813. }
  12814. }
  12815. $out .= ' /Fields [' . $objrefs . ']';
  12816. if (! empty($this->form_obj_id) and ! $this->sign)
  12817. {
  12818. // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
  12819. $out .= ' /NeedAppearances true';
  12820. }
  12821. if ($this->sign and isset($this->signature_data['cert_type']))
  12822. {
  12823. if ($this->signature_data['cert_type'] > 0)
  12824. {
  12825. $out .= ' /SigFlags 3';
  12826. }
  12827. else
  12828. {
  12829. $out .= ' /SigFlags 1';
  12830. }
  12831. }
  12832. //$out .= ' /CO ';
  12833. if (isset($this->annotation_fonts) and ! empty($this->annotation_fonts))
  12834. {
  12835. $out .= ' /DR <<';
  12836. $out .= ' /Font <<';
  12837. foreach ($this->annotation_fonts as $fontkey => $fontid)
  12838. {
  12839. $out .= ' /F' . $fontid . ' ' . $this->font_obj_ids[$fontkey] . ' 0 R';
  12840. }
  12841. $out .= ' >> >>';
  12842. }
  12843. $font = $this->getFontBuffer('helvetica');
  12844. $out .= ' /DA (/F' . $font['i'] . ' 0 Tf 0 g)';
  12845. $out .= ' /Q ' . (($this->rtl) ? '2' : '0');
  12846. //$out .= ' /XFA ';
  12847. $out .= ' >>';
  12848. // signatures
  12849. if ($this->sign and isset($this->signature_data['cert_type']))
  12850. {
  12851. if ($this->signature_data['cert_type'] > 0)
  12852. {
  12853. $out .= ' /Perms << /DocMDP ' . ($this->sig_obj_id + 1) . ' 0 R >>';
  12854. }
  12855. else
  12856. {
  12857. $out .= ' /Perms << /UR3 ' . ($this->sig_obj_id + 1) . ' 0 R >>';
  12858. }
  12859. }
  12860. }
  12861. $out .= ' >>';
  12862. $out .= "\n" . 'endobj';
  12863. $this->_out($out);
  12864. return $oid;
  12865. }
  12866. /**
  12867. * Output viewer preferences.
  12868. * @return string for viewer preferences
  12869. * @author Nicola asuni
  12870. * @since 3.1.000 (2008-06-09)
  12871. * @access protected
  12872. */
  12873. protected function _putviewerpreferences()
  12874. {
  12875. $out = '/ViewerPreferences <<';
  12876. if ($this->rtl)
  12877. {
  12878. $out .= ' /Direction /R2L';
  12879. }
  12880. else
  12881. {
  12882. $out .= ' /Direction /L2R';
  12883. }
  12884. if (isset($this->viewer_preferences['HideToolbar']) and ($this->viewer_preferences['HideToolbar']))
  12885. {
  12886. $out .= ' /HideToolbar true';
  12887. }
  12888. if (isset($this->viewer_preferences['HideMenubar']) and ($this->viewer_preferences['HideMenubar']))
  12889. {
  12890. $out .= ' /HideMenubar true';
  12891. }
  12892. if (isset($this->viewer_preferences['HideWindowUI']) and ($this->viewer_preferences['HideWindowUI']))
  12893. {
  12894. $out .= ' /HideWindowUI true';
  12895. }
  12896. if (isset($this->viewer_preferences['FitWindow']) and ($this->viewer_preferences['FitWindow']))
  12897. {
  12898. $out .= ' /FitWindow true';
  12899. }
  12900. if (isset($this->viewer_preferences['CenterWindow']) and ($this->viewer_preferences['CenterWindow']))
  12901. {
  12902. $out .= ' /CenterWindow true';
  12903. }
  12904. if (isset($this->viewer_preferences['DisplayDocTitle']) and ($this->viewer_preferences['DisplayDocTitle']))
  12905. {
  12906. $out .= ' /DisplayDocTitle true';
  12907. }
  12908. if (isset($this->viewer_preferences['NonFullScreenPageMode']))
  12909. {
  12910. $out .= ' /NonFullScreenPageMode /' . $this->viewer_preferences['NonFullScreenPageMode'];
  12911. }
  12912. if (isset($this->viewer_preferences['ViewArea']))
  12913. {
  12914. $out .= ' /ViewArea /' . $this->viewer_preferences['ViewArea'];
  12915. }
  12916. if (isset($this->viewer_preferences['ViewClip']))
  12917. {
  12918. $out .= ' /ViewClip /' . $this->viewer_preferences['ViewClip'];
  12919. }
  12920. if (isset($this->viewer_preferences['PrintArea']))
  12921. {
  12922. $out .= ' /PrintArea /' . $this->viewer_preferences['PrintArea'];
  12923. }
  12924. if (isset($this->viewer_preferences['PrintClip']))
  12925. {
  12926. $out .= ' /PrintClip /' . $this->viewer_preferences['PrintClip'];
  12927. }
  12928. if (isset($this->viewer_preferences['PrintScaling']))
  12929. {
  12930. $out .= ' /PrintScaling /' . $this->viewer_preferences['PrintScaling'];
  12931. }
  12932. if (isset($this->viewer_preferences['Duplex']) and (! $this->empty_string($this->viewer_preferences['Duplex'])))
  12933. {
  12934. $out .= ' /Duplex /' . $this->viewer_preferences['Duplex'];
  12935. }
  12936. if (isset($this->viewer_preferences['PickTrayByPDFSize']))
  12937. {
  12938. if ($this->viewer_preferences['PickTrayByPDFSize'])
  12939. {
  12940. $out .= ' /PickTrayByPDFSize true';
  12941. }
  12942. else
  12943. {
  12944. $out .= ' /PickTrayByPDFSize false';
  12945. }
  12946. }
  12947. if (isset($this->viewer_preferences['PrintPageRange']))
  12948. {
  12949. $PrintPageRangeNum = '';
  12950. foreach ($this->viewer_preferences['PrintPageRange'] as $k => $v)
  12951. {
  12952. $PrintPageRangeNum .= ' ' . ($v - 1) . '';
  12953. }
  12954. $out .= ' /PrintPageRange [' . substr($PrintPageRangeNum, 1) . ']';
  12955. }
  12956. if (isset($this->viewer_preferences['NumCopies']))
  12957. {
  12958. $out .= ' /NumCopies ' . intval($this->viewer_preferences['NumCopies']);
  12959. }
  12960. $out .= ' >>';
  12961. return $out;
  12962. }
  12963. /**
  12964. * Output PDF header.
  12965. * @access protected
  12966. */
  12967. protected function _putheader()
  12968. {
  12969. $this->_out('%PDF-' . $this->PDFVersion);
  12970. }
  12971. /**
  12972. * Output end of document (EOF).
  12973. * @access protected
  12974. */
  12975. protected function _enddoc()
  12976. {
  12977. $this->state = 1;
  12978. $this->_putheader();
  12979. $this->_putpages();
  12980. $this->_putresources();
  12981. // Signature
  12982. if ($this->sign and isset($this->signature_data['cert_type']))
  12983. {
  12984. // widget annotation for signature
  12985. $out = $this->_getobj($this->sig_obj_id) . "\n";
  12986. $out .= '<< /Type /Annot';
  12987. $out .= ' /Subtype /Widget';
  12988. $out .= ' /Rect [' . $this->signature_appearance['rect'] . ']';
  12989. $out .= ' /P ' . $this->page_obj_id[($this->signature_appearance['page'])] . ' 0 R'; // link to signature appearance page
  12990. $out .= ' /F 4';
  12991. $out .= ' /FT /Sig';
  12992. $out .= ' /T ' . $this->_textstring('Signature', $this->sig_obj_id);
  12993. $out .= ' /Ff 0';
  12994. $out .= ' /V ' . ($this->sig_obj_id + 1) . ' 0 R';
  12995. $out .= ' >>';
  12996. $out .= "\n" . 'endobj';
  12997. $this->_out($out);
  12998. // signature
  12999. $this->_putsignature();
  13000. }
  13001. // Info
  13002. $objid_info = $this->_putinfo();
  13003. // Catalog
  13004. $objid_catalog = $this->_putcatalog();
  13005. // Cross-ref
  13006. $o = $this->bufferlen;
  13007. // XREF section
  13008. $this->_out('xref');
  13009. $this->_out('0 ' . ($this->n + 1));
  13010. $this->_out('0000000000 65535 f ');
  13011. for($i = 1; $i <= $this->n; ++ $i)
  13012. {
  13013. $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));
  13014. }
  13015. // TRAILER
  13016. $out = 'trailer <<';
  13017. $out .= ' /Size ' . ($this->n + 1);
  13018. $out .= ' /Root ' . $objid_catalog . ' 0 R';
  13019. $out .= ' /Info ' . $objid_info . ' 0 R';
  13020. if ($this->encrypted)
  13021. {
  13022. $out .= ' /Encrypt ' . $this->encryptdata['objid'] . ' 0 R';
  13023. }
  13024. $out .= ' /ID [ <' . $this->file_id . '> <' . $this->file_id . '> ]';
  13025. $out .= ' >>';
  13026. $this->_out($out);
  13027. $this->_out('startxref');
  13028. $this->_out($o);
  13029. $this->_out('%%EOF');
  13030. $this->state = 3; // end-of-doc
  13031. if ($this->diskcache)
  13032. {
  13033. // remove temporary files used for images
  13034. foreach ($this->imagekeys as $key)
  13035. {
  13036. // remove temporary files
  13037. unlink($this->images[$key]);
  13038. }
  13039. foreach ($this->fontkeys as $key)
  13040. {
  13041. // remove temporary files
  13042. unlink($this->fonts[$key]);
  13043. }
  13044. }
  13045. }
  13046. /**
  13047. * Initialize a new page.
  13048. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  13049. * @param mixed $format The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
  13050. * @access protected
  13051. * @see getPageSizeFromFormat(), setPageFormat()
  13052. */
  13053. protected function _beginpage($orientation = '', $format = '')
  13054. {
  13055. ++ $this->page;
  13056. $this->setPageBuffer($this->page, '');
  13057. // initialize array for graphics tranformation positions inside a page buffer
  13058. $this->transfmrk[$this->page] = array();
  13059. $this->state = 2;
  13060. if ($this->empty_string($orientation))
  13061. {
  13062. if (isset($this->CurOrientation))
  13063. {
  13064. $orientation = $this->CurOrientation;
  13065. }
  13066. elseif ($this->fwPt > $this->fhPt)
  13067. {
  13068. // landscape
  13069. $orientation = 'L';
  13070. }
  13071. else
  13072. {
  13073. // portrait
  13074. $orientation = 'P';
  13075. }
  13076. }
  13077. if ($this->empty_string($format))
  13078. {
  13079. $this->pagedim[$this->page] = $this->pagedim[($this->page - 1)];
  13080. $this->setPageOrientation($orientation);
  13081. }
  13082. else
  13083. {
  13084. $this->setPageFormat($format, $orientation);
  13085. }
  13086. if ($this->rtl)
  13087. {
  13088. $this->x = $this->w - $this->rMargin;
  13089. }
  13090. else
  13091. {
  13092. $this->x = $this->lMargin;
  13093. }
  13094. $this->y = $this->tMargin;
  13095. if (isset($this->newpagegroup[$this->page]))
  13096. {
  13097. // start a new group
  13098. $n = sizeof($this->pagegroups) + 1;
  13099. $alias = '{nb' . $n . '}';
  13100. $this->pagegroups[$alias] = 1;
  13101. $this->currpagegroup = $alias;
  13102. }
  13103. elseif ($this->currpagegroup)
  13104. {
  13105. ++ $this->pagegroups[$this->currpagegroup];
  13106. }
  13107. }
  13108. /**
  13109. * Mark end of page.
  13110. * @access protected
  13111. */
  13112. protected function _endpage()
  13113. {
  13114. $this->setVisibility('all');
  13115. $this->state = 1;
  13116. }
  13117. /**
  13118. * Begin a new object and return the object number.
  13119. * @return int object number
  13120. * @access protected
  13121. */
  13122. protected function _newobj()
  13123. {
  13124. $this->_out($this->_getobj());
  13125. return $this->n;
  13126. }
  13127. /**
  13128. * Return the starting object string for the selected object ID.
  13129. * @param int $objid Object ID (leave empty to get a new ID).
  13130. * @return string the starting object string
  13131. * @access protected
  13132. * @since 5.8.009 (2010-08-20)
  13133. */
  13134. protected function _getobj($objid = '')
  13135. {
  13136. if ($objid === '')
  13137. {
  13138. ++ $this->n;
  13139. $objid = $this->n;
  13140. }
  13141. $this->offsets[$objid] = $this->bufferlen;
  13142. return $objid . ' 0 obj';
  13143. }
  13144. /**
  13145. * Underline text.
  13146. * @param int $x X coordinate
  13147. * @param int $y Y coordinate
  13148. * @param string $txt text to underline
  13149. * @access protected
  13150. */
  13151. protected function _dounderline($x, $y, $txt)
  13152. {
  13153. $w = $this->GetStringWidth($txt);
  13154. return $this->_dounderlinew($x, $y, $w);
  13155. }
  13156. /**
  13157. * Underline for rectangular text area.
  13158. * @param int $x X coordinate
  13159. * @param int $y Y coordinate
  13160. * @param int $w width to underline
  13161. * @access protected
  13162. * @since 4.8.008 (2009-09-29)
  13163. */
  13164. protected function _dounderlinew($x, $y, $w)
  13165. {
  13166. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  13167. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew), $w * $this->k, $linew);
  13168. }
  13169. /**
  13170. * Line through text.
  13171. * @param int $x X coordinate
  13172. * @param int $y Y coordinate
  13173. * @param string $txt text to linethrough
  13174. * @access protected
  13175. */
  13176. protected function _dolinethrough($x, $y, $txt)
  13177. {
  13178. $w = $this->GetStringWidth($txt);
  13179. return $this->_dolinethroughw($x, $y, $w);
  13180. }
  13181. /**
  13182. * Line through for rectangular text area.
  13183. * @param int $x X coordinate
  13184. * @param int $y Y coordinate
  13185. * @param string $txt text to linethrough
  13186. * @access protected
  13187. * @since 4.9.008 (2009-09-29)
  13188. */
  13189. protected function _dolinethroughw($x, $y, $w)
  13190. {
  13191. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  13192. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ((($this->h - $y) * $this->k) + $linew + ($this->FontSizePt / 3)), $w * $this->k, $linew);
  13193. }
  13194. /**
  13195. * Overline text.
  13196. * @param int $x X coordinate
  13197. * @param int $y Y coordinate
  13198. * @param string $txt text to overline
  13199. * @access protected
  13200. * @since 4.9.015 (2010-04-19)
  13201. */
  13202. protected function _dooverline($x, $y, $txt)
  13203. {
  13204. $w = $this->GetStringWidth($txt);
  13205. return $this->_dooverlinew($x, $y, $w);
  13206. }
  13207. /**
  13208. * Overline for rectangular text area.
  13209. * @param int $x X coordinate
  13210. * @param int $y Y coordinate
  13211. * @param int $w width to overline
  13212. * @access protected
  13213. * @since 4.9.015 (2010-04-19)
  13214. */
  13215. protected function _dooverlinew($x, $y, $w)
  13216. {
  13217. $linew = - $this->CurrentFont['ut'] / 1000 * $this->FontSizePt;
  13218. return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, (($this->h - $y + $this->FontAscent) * $this->k) - $linew, $w * $this->k, $linew);
  13219. }
  13220. /**
  13221. * Read a 4-byte (32 bit) integer from file.
  13222. * @param string $f file name.
  13223. * @return 4-byte integer
  13224. * @access protected
  13225. */
  13226. protected function _freadint($f)
  13227. {
  13228. $a = unpack('Ni', fread($f, 4));
  13229. return $a['i'];
  13230. }
  13231. /**
  13232. * Add "\" before "\", "(" and ")"
  13233. * @param string $s string to escape.
  13234. * @return string escaped string.
  13235. * @access protected
  13236. */
  13237. protected function _escape($s)
  13238. {
  13239. // the chr(13) substitution fixes the Bugs item #1421290.
  13240. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  13241. }
  13242. /**
  13243. * Format a data string for meta information
  13244. * @param string $s data string to escape.
  13245. * @param int $n object ID
  13246. * @return string escaped string.
  13247. * @access protected
  13248. */
  13249. protected function _datastring($s, $n = 0)
  13250. {
  13251. if ($n == 0)
  13252. {
  13253. $n = $this->n;
  13254. }
  13255. $s = $this->_encrypt_data($n, $s);
  13256. return '(' . $this->_escape($s) . ')';
  13257. }
  13258. /**
  13259. * Returns a formatted date for meta information
  13260. * @param int $n object ID
  13261. * @return string escaped date string.
  13262. * @access protected
  13263. * @since 4.6.028 (2009-08-25)
  13264. */
  13265. protected function _datestring($n = 0)
  13266. {
  13267. $current_time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0) . '\'';
  13268. return $this->_datastring('D:' . $current_time, $n);
  13269. }
  13270. /**
  13271. * Format a text string for meta information
  13272. * @param string $s string to escape.
  13273. * @param int $n object ID
  13274. * @return string escaped string.
  13275. * @access protected
  13276. */
  13277. protected function _textstring($s, $n = 0)
  13278. {
  13279. if ($this->isunicode)
  13280. {
  13281. //Convert string to UTF-16BE
  13282. $s = $this->UTF8ToUTF16BE($s, true);
  13283. }
  13284. return $this->_datastring($s, $n);
  13285. }
  13286. /**
  13287. * THIS METHOD IS DEPRECATED
  13288. * Format a text string
  13289. * @param string $s string to escape.
  13290. * @return string escaped string.
  13291. * @access protected
  13292. * @deprecated
  13293. */
  13294. protected function _escapetext($s)
  13295. {
  13296. if ($this->isunicode)
  13297. {
  13298. if (($this->CurrentFont['type'] == 'core') or ($this->CurrentFont['type'] == 'TrueType') or ($this->CurrentFont['type'] == 'Type1'))
  13299. {
  13300. $s = $this->UTF8ToLatin1($s);
  13301. }
  13302. else
  13303. {
  13304. //Convert string to UTF-16BE and reverse RTL language
  13305. $s = $this->utf8StrRev($s, false, $this->tmprtl);
  13306. }
  13307. }
  13308. return $this->_escape($s);
  13309. }
  13310. /**
  13311. * get raw output stream.
  13312. * @param string $s string to output.
  13313. * @param int $n object reference for encryption mode
  13314. * @access protected
  13315. * @author Nicola Asuni
  13316. * @since 5.5.000 (2010-06-22)
  13317. */
  13318. protected function _getrawstream($s, $n = 0)
  13319. {
  13320. if ($n <= 0)
  13321. {
  13322. // default to current object
  13323. $n = $this->n;
  13324. }
  13325. return $this->_encrypt_data($n, $s);
  13326. }
  13327. /**
  13328. * Format output stream (DEPRECATED).
  13329. * @param string $s string to output.
  13330. * @param int $n object reference for encryption mode
  13331. * @access protected
  13332. * @deprecated
  13333. */
  13334. protected function _getstream($s, $n = 0)
  13335. {
  13336. return 'stream' . "\n" . $this->_getrawstream($s, $n) . "\n" . 'endstream';
  13337. }
  13338. /**
  13339. * Output a stream (DEPRECATED).
  13340. * @param string $s string to output.
  13341. * @param int $n object reference for encryption mode
  13342. * @access protected
  13343. * @deprecated
  13344. */
  13345. protected function _putstream($s, $n = 0)
  13346. {
  13347. $this->_out($this->_getstream($s, $n));
  13348. }
  13349. /**
  13350. * Output a string to the document.
  13351. * @param string $s string to output.
  13352. * @access protected
  13353. */
  13354. protected function _out($s)
  13355. {
  13356. if ($this->state == 2)
  13357. {
  13358. if ($this->inxobj)
  13359. {
  13360. // we are inside an XObject template
  13361. $this->xobjects[$this->xobjid]['outdata'] .= $s . "\n";
  13362. }
  13363. elseif ((! $this->InFooter) and isset($this->footerlen[$this->page]) and ($this->footerlen[$this->page] > 0))
  13364. {
  13365. // puts data before page footer
  13366. $pagebuff = $this->getPageBuffer($this->page);
  13367. $page = substr($pagebuff, 0, - $this->footerlen[$this->page]);
  13368. $footer = substr($pagebuff, - $this->footerlen[$this->page]);
  13369. $this->setPageBuffer($this->page, $page . $s . "\n" . $footer);
  13370. // update footer position
  13371. $this->footerpos[$this->page] += strlen($s . "\n");
  13372. }
  13373. else
  13374. {
  13375. $this->setPageBuffer($this->page, $s . "\n", true);
  13376. }
  13377. }
  13378. else
  13379. {
  13380. $this->setBuffer($s . "\n");
  13381. }
  13382. }
  13383. /**
  13384. * Converts UTF-8 strings to codepoints array.<br>
  13385. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  13386. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  13387. * <pre>
  13388. * Char. number range | UTF-8 octet sequence
  13389. * (hexadecimal) | (binary)
  13390. * --------------------+-----------------------------------------------
  13391. * 0000 0000-0000 007F | 0xxxxxxx
  13392. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  13393. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  13394. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  13395. * ---------------------------------------------------------------------
  13396. *
  13397. * ABFN notation:
  13398. * ---------------------------------------------------------------------
  13399. * UTF8-octets = *( UTF8-char )
  13400. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  13401. * UTF8-1 = %x00-7F
  13402. * UTF8-2 = %xC2-DF UTF8-tail
  13403. *
  13404. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  13405. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  13406. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  13407. * %xF4 %x80-8F 2( UTF8-tail )
  13408. * UTF8-tail = %x80-BF
  13409. * ---------------------------------------------------------------------
  13410. * </pre>
  13411. * @param string $str string to process.
  13412. * @return array containing codepoints (UTF-8 characters values)
  13413. * @access protected
  13414. * @author Nicola Asuni
  13415. * @since 1.53.0.TC005 (2005-01-05)
  13416. */
  13417. protected function UTF8StringToArray($str)
  13418. {
  13419. // build a unique string key
  13420. $strkey = md5($str);
  13421. if (isset($this->cache_UTF8StringToArray[$strkey]))
  13422. {
  13423. // return cached value
  13424. $chrarray = $this->cache_UTF8StringToArray[$strkey]['s'];
  13425. if (! isset($this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']]))
  13426. {
  13427. if ($this->isunicode)
  13428. {
  13429. foreach ($chrarray as $chr)
  13430. {
  13431. // store this char for font subsetting
  13432. $this->CurrentFont['subsetchars'][$chr] = true;
  13433. }
  13434. // update font subsetchars
  13435. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  13436. }
  13437. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  13438. }
  13439. return $chrarray;
  13440. }
  13441. // check cache size
  13442. if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray)
  13443. {
  13444. // remove first element
  13445. array_shift($this->cache_UTF8StringToArray);
  13446. }
  13447. // new cache array for selected string
  13448. $this->cache_UTF8StringToArray[$strkey] = array('s' => array(), 'f' => array());
  13449. ++ $this->cache_size_UTF8StringToArray;
  13450. if (! $this->isunicode)
  13451. {
  13452. // split string into array of equivalent codes
  13453. $strarr = array();
  13454. $strlen = strlen($str);
  13455. for($i = 0; $i < $strlen; ++ $i)
  13456. {
  13457. $strarr[] = ord($str{$i});
  13458. }
  13459. // insert new value on cache
  13460. $this->cache_UTF8StringToArray[$strkey]['s'] = $strarr;
  13461. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  13462. return $strarr;
  13463. }
  13464. $unichar = - 1; // last unicode char
  13465. $unicode = array(); // array containing unicode values
  13466. $bytes = array(); // array containing single character byte sequences
  13467. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  13468. $str .= ''; // force $str to be a string
  13469. $length = strlen($str);
  13470. for($i = 0; $i < $length; ++ $i)
  13471. {
  13472. $char = ord($str{$i}); // get one string character at time
  13473. if (count($bytes) == 0)
  13474. { // get starting octect
  13475. if ($char <= 0x7F)
  13476. {
  13477. $unichar = $char; // use the character "as is" because is ASCII
  13478. $numbytes = 1;
  13479. }
  13480. elseif (($char >> 0x05) == 0x06)
  13481. { // 2 bytes character (0x06 = 110 BIN)
  13482. $bytes[] = ($char - 0xC0) << 0x06;
  13483. $numbytes = 2;
  13484. }
  13485. elseif (($char >> 0x04) == 0x0E)
  13486. { // 3 bytes character (0x0E = 1110 BIN)
  13487. $bytes[] = ($char - 0xE0) << 0x0C;
  13488. $numbytes = 3;
  13489. }
  13490. elseif (($char >> 0x03) == 0x1E)
  13491. { // 4 bytes character (0x1E = 11110 BIN)
  13492. $bytes[] = ($char - 0xF0) << 0x12;
  13493. $numbytes = 4;
  13494. }
  13495. else
  13496. {
  13497. // use replacement character for other invalid sequences
  13498. $unichar = 0xFFFD;
  13499. $bytes = array();
  13500. $numbytes = 1;
  13501. }
  13502. }
  13503. elseif (($char >> 0x06) == 0x02)
  13504. { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  13505. $bytes[] = $char - 0x80;
  13506. if (count($bytes) == $numbytes)
  13507. {
  13508. // compose UTF-8 bytes to a single unicode value
  13509. $char = $bytes[0];
  13510. for($j = 1; $j < $numbytes; ++ $j)
  13511. {
  13512. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  13513. }
  13514. if ((($char >= 0xD800) and ($char <= 0xDFFF)) or ($char >= 0x10FFFF))
  13515. {
  13516. /* The definition of UTF-8 prohibits encoding character numbers between
  13517. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  13518. encoding form (as surrogate pairs) and do not directly represent
  13519. characters. */
  13520. $unichar = 0xFFFD; // use replacement character
  13521. }
  13522. else
  13523. {
  13524. $unichar = $char; // add char to array
  13525. }
  13526. // reset data for next char
  13527. $bytes = array();
  13528. $numbytes = 1;
  13529. }
  13530. }
  13531. else
  13532. {
  13533. // use replacement character for other invalid sequences
  13534. $unichar = 0xFFFD;
  13535. $bytes = array();
  13536. $numbytes = 1;
  13537. }
  13538. if ($unichar >= 0)
  13539. {
  13540. // insert unicode value into array
  13541. $unicode[] = $unichar;
  13542. // store this char for font subsetting
  13543. $this->CurrentFont['subsetchars'][$unichar] = true;
  13544. $unichar = - 1;
  13545. }
  13546. }
  13547. // update font subsetchars
  13548. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  13549. // insert new value on cache
  13550. $this->cache_UTF8StringToArray[$strkey]['s'] = $unicode;
  13551. $this->cache_UTF8StringToArray[$strkey]['f'][$this->CurrentFont['fontkey']] = true;
  13552. return $unicode;
  13553. }
  13554. /**
  13555. * Converts UTF-8 strings to UTF16-BE.<br>
  13556. * @param string $str string to process.
  13557. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  13558. * @return string
  13559. * @access protected
  13560. * @author Nicola Asuni
  13561. * @since 1.53.0.TC005 (2005-01-05)
  13562. * @uses UTF8StringToArray(), arrUTF8ToUTF16BE()
  13563. */
  13564. protected function UTF8ToUTF16BE($str, $setbom = true)
  13565. {
  13566. if (! $this->isunicode)
  13567. {
  13568. return $str; // string is not in unicode
  13569. }
  13570. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  13571. return $this->arrUTF8ToUTF16BE($unicode, $setbom);
  13572. }
  13573. /**
  13574. * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
  13575. * @param string $str string to process.
  13576. * @return string
  13577. * @author Andrew Whitehead, Nicola Asuni
  13578. * @access protected
  13579. * @since 3.2.000 (2008-06-23)
  13580. */
  13581. protected function UTF8ToLatin1($str)
  13582. {
  13583. if (! $this->isunicode)
  13584. {
  13585. return $str; // string is not in unicode
  13586. }
  13587. $outstr = ''; // string to be returned
  13588. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  13589. foreach ($unicode as $char)
  13590. {
  13591. if ($char < 256)
  13592. {
  13593. $outstr .= chr($char);
  13594. }
  13595. elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin))
  13596. {
  13597. // map from UTF-8
  13598. $outstr .= chr($this->unicode->uni_utf8tolatin[$char]);
  13599. }
  13600. elseif ($char == 0xFFFD)
  13601. {
  13602. // skip
  13603. }
  13604. else
  13605. {
  13606. $outstr .= '?';
  13607. }
  13608. }
  13609. return $outstr;
  13610. }
  13611. /**
  13612. * Converts UTF-8 characters array to array of Latin1 characters<br>
  13613. * @param array $unicode array containing UTF-8 unicode values
  13614. * @return array
  13615. * @author Nicola Asuni
  13616. * @access protected
  13617. * @since 4.8.023 (2010-01-15)
  13618. */
  13619. protected function UTF8ArrToLatin1($unicode)
  13620. {
  13621. if ((! $this->isunicode) or $this->isUnicodeFont())
  13622. {
  13623. return $unicode;
  13624. }
  13625. $outarr = array(); // array to be returned
  13626. foreach ($unicode as $char)
  13627. {
  13628. if ($char < 256)
  13629. {
  13630. $outarr[] = $char;
  13631. }
  13632. elseif (array_key_exists($char, $this->unicode->uni_utf8tolatin))
  13633. {
  13634. // map from UTF-8
  13635. $outarr[] = $this->unicode->uni_utf8tolatin[$char];
  13636. }
  13637. elseif ($char == 0xFFFD)
  13638. {
  13639. // skip
  13640. }
  13641. else
  13642. {
  13643. $outarr[] = 63; // '?' character
  13644. }
  13645. }
  13646. return $outarr;
  13647. }
  13648. /**
  13649. * Converts array of UTF-8 characters to UTF16-BE string.<br>
  13650. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  13651. * <pre>
  13652. * Encoding UTF-16:
  13653. *
  13654. * Encoding of a single character from an ISO 10646 character value to
  13655. * UTF-16 proceeds as follows. Let U be the character number, no greater
  13656. * than 0x10FFFF.
  13657. *
  13658. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  13659. * terminate.
  13660. *
  13661. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  13662. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  13663. * represented in 20 bits.
  13664. *
  13665. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  13666. * 0xDC00, respectively. These integers each have 10 bits free to
  13667. * encode the character value, for a total of 20 bits.
  13668. *
  13669. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  13670. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  13671. * bits of W2. Terminate.
  13672. *
  13673. * Graphically, steps 2 through 4 look like:
  13674. * U' = yyyyyyyyyyxxxxxxxxxx
  13675. * W1 = 110110yyyyyyyyyy
  13676. * W2 = 110111xxxxxxxxxx
  13677. * </pre>
  13678. * @param array $unicode array containing UTF-8 unicode values
  13679. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  13680. * @return string
  13681. * @access protected
  13682. * @author Nicola Asuni
  13683. * @since 2.1.000 (2008-01-08)
  13684. * @see UTF8ToUTF16BE()
  13685. */
  13686. protected function arrUTF8ToUTF16BE($unicode, $setbom = true)
  13687. {
  13688. $outstr = ''; // string to be returned
  13689. if ($setbom)
  13690. {
  13691. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  13692. }
  13693. foreach ($unicode as $char)
  13694. {
  13695. if ($char == 0x200b)
  13696. {
  13697. // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
  13698. }
  13699. elseif ($char == 0xFFFD)
  13700. {
  13701. $outstr .= "\xFF\xFD"; // replacement character
  13702. }
  13703. elseif ($char < 0x10000)
  13704. {
  13705. $outstr .= chr($char >> 0x08);
  13706. $outstr .= chr($char & 0xFF);
  13707. }
  13708. else
  13709. {
  13710. $char -= 0x10000;
  13711. $w1 = 0xD800 | ($char >> 0x10);
  13712. $w2 = 0xDC00 | ($char & 0x3FF);
  13713. $outstr .= chr($w1 >> 0x08);
  13714. $outstr .= chr($w1 & 0xFF);
  13715. $outstr .= chr($w2 >> 0x08);
  13716. $outstr .= chr($w2 & 0xFF);
  13717. }
  13718. }
  13719. return $outstr;
  13720. }
  13721. // ====================================================
  13722. /**
  13723. * Set header font.
  13724. * @param array $font font
  13725. * @access public
  13726. * @since 1.1
  13727. */
  13728. public function setHeaderFont($font)
  13729. {
  13730. $this->header_font = $font;
  13731. }
  13732. /**
  13733. * Get header font.
  13734. * @return array()
  13735. * @access public
  13736. * @since 4.0.012 (2008-07-24)
  13737. */
  13738. public function getHeaderFont()
  13739. {
  13740. return $this->header_font;
  13741. }
  13742. /**
  13743. * Set footer font.
  13744. * @param array $font font
  13745. * @access public
  13746. * @since 1.1
  13747. */
  13748. public function setFooterFont($font)
  13749. {
  13750. $this->footer_font = $font;
  13751. }
  13752. /**
  13753. * Get Footer font.
  13754. * @return array()
  13755. * @access public
  13756. * @since 4.0.012 (2008-07-24)
  13757. */
  13758. public function getFooterFont()
  13759. {
  13760. return $this->footer_font;
  13761. }
  13762. /**
  13763. * Set language array.
  13764. * @param array $language
  13765. * @access public
  13766. * @since 1.1
  13767. */
  13768. public function setLanguageArray($language)
  13769. {
  13770. $this->l = $language;
  13771. if (isset($this->l['a_meta_dir']))
  13772. {
  13773. $this->rtl = $this->l['a_meta_dir'] == 'rtl' ? true : false;
  13774. }
  13775. else
  13776. {
  13777. $this->rtl = false;
  13778. }
  13779. }
  13780. /**
  13781. * Returns the PDF data.
  13782. * @access public
  13783. */
  13784. public function getPDFData()
  13785. {
  13786. if ($this->state < 3)
  13787. {
  13788. $this->Close();
  13789. }
  13790. return $this->buffer;
  13791. }
  13792. /**
  13793. * Output anchor link.
  13794. * @param string $url link URL or internal link (i.e.: &lt;a href="#23,4.5"&gt;link to page 23 at 4.5 Y position&lt;/a&gt;)
  13795. * @param string $name link name
  13796. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  13797. * @param boolean $firstline if true prints only the first line and return the remaining string.
  13798. * @param array $color array of RGB text color
  13799. * @param string $style font style (U, D, B, I)
  13800. * @param boolean $firstblock if true the string is the starting of a line.
  13801. * @return the number of cells used or the remaining text if $firstline = true;
  13802. * @access public
  13803. */
  13804. public function addHtmlLink($url, $name, $fill = false, $firstline = false, $color = '', $style = -1, $firstblock = false)
  13805. {
  13806. if (! $this->empty_string($url) and ($url{0} == '#'))
  13807. {
  13808. // convert url to internal link
  13809. $lnkdata = explode(',', $url);
  13810. if (isset($lnkdata[0]))
  13811. {
  13812. $page = intval(substr($lnkdata[0], 1));
  13813. if (empty($page) or ($page <= 0))
  13814. {
  13815. $page = $this->page;
  13816. }
  13817. if (isset($lnkdata[1]) and (strlen($lnkdata[1]) > 0))
  13818. {
  13819. $lnky = floatval($lnkdata[1]);
  13820. }
  13821. else
  13822. {
  13823. $lnky = 0;
  13824. }
  13825. $url = $this->AddLink();
  13826. $this->SetLink($url, $lnky, $page);
  13827. }
  13828. }
  13829. // store current settings
  13830. $prevcolor = $this->fgcolor;
  13831. $prevstyle = $this->FontStyle;
  13832. if (empty($color))
  13833. {
  13834. $this->SetTextColorArray($this->htmlLinkColorArray);
  13835. }
  13836. else
  13837. {
  13838. $this->SetTextColorArray($color);
  13839. }
  13840. if ($style == - 1)
  13841. {
  13842. $this->SetFont('', $this->FontStyle . $this->htmlLinkFontStyle);
  13843. }
  13844. else
  13845. {
  13846. $this->SetFont('', $this->FontStyle . $style);
  13847. }
  13848. $ret = $this->Write($this->lasth, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
  13849. // restore settings
  13850. $this->SetFont('', $prevstyle);
  13851. $this->SetTextColorArray($prevcolor);
  13852. return $ret;
  13853. }
  13854. /**
  13855. * Returns an associative array (keys: R,G,B) from an html color name or a six-digit or three-digit hexadecimal color representation (i.e. #3FE5AA or #7FF).
  13856. * @param string $color html color
  13857. * @return array RGB color or false in case of error.
  13858. * @access public
  13859. */
  13860. public function convertHTMLColorToDec($color = '#FFFFFF')
  13861. {
  13862. $returncolor = false;
  13863. $color = preg_replace('/[\s]*/', '', $color); // remove extra spaces
  13864. $color = strtolower($color);
  13865. if (($dotpos = strpos($color, '.')) !== false)
  13866. {
  13867. // remove class parent (i.e.: color.red)
  13868. $color = substr($color, ($dotpos + 1));
  13869. }
  13870. if (strlen($color) == 0)
  13871. {
  13872. return false;
  13873. }
  13874. // RGB ARRAY
  13875. if (substr($color, 0, 3) == 'rgb')
  13876. {
  13877. $codes = substr($color, 4);
  13878. $codes = str_replace(')', '', $codes);
  13879. $returncolor = explode(',', $codes);
  13880. return $returncolor;
  13881. }
  13882. // CMYK ARRAY
  13883. if (substr($color, 0, 4) == 'cmyk')
  13884. {
  13885. $codes = substr($color, 5);
  13886. $codes = str_replace(')', '', $codes);
  13887. $returncolor = explode(',', $codes);
  13888. return $returncolor;
  13889. }
  13890. // COLOR NAME
  13891. if (substr($color, 0, 1) != '#')
  13892. {
  13893. // decode color name
  13894. if (isset($this->webcolor[$color]))
  13895. {
  13896. $color_code = $this->webcolor[$color];
  13897. }
  13898. else
  13899. {
  13900. return false;
  13901. }
  13902. }
  13903. else
  13904. {
  13905. $color_code = substr($color, 1);
  13906. }
  13907. // RGB VALUE
  13908. switch (strlen($color_code))
  13909. {
  13910. case 3 :
  13911. {
  13912. // three-digit hexadecimal representation
  13913. $r = substr($color_code, 0, 1);
  13914. $g = substr($color_code, 1, 1);
  13915. $b = substr($color_code, 2, 1);
  13916. $returncolor['R'] = hexdec($r . $r);
  13917. $returncolor['G'] = hexdec($g . $g);
  13918. $returncolor['B'] = hexdec($b . $b);
  13919. break;
  13920. }
  13921. case 6 :
  13922. {
  13923. // six-digit hexadecimal representation
  13924. $returncolor['R'] = hexdec(substr($color_code, 0, 2));
  13925. $returncolor['G'] = hexdec(substr($color_code, 2, 2));
  13926. $returncolor['B'] = hexdec(substr($color_code, 4, 2));
  13927. break;
  13928. }
  13929. }
  13930. return $returncolor;
  13931. }
  13932. /**
  13933. * Converts pixels to User's Units.
  13934. * @param int $px pixels
  13935. * @return float value in user's unit
  13936. * @access public
  13937. * @see setImageScale(), getImageScale()
  13938. */
  13939. public function pixelsToUnits($px)
  13940. {
  13941. return ($px / ($this->imgscale * $this->k));
  13942. }
  13943. /**
  13944. * Reverse function for htmlentities.
  13945. * Convert entities in UTF-8.
  13946. * @param string $text_to_convert Text to convert.
  13947. * @return string converted text string
  13948. * @access public
  13949. */
  13950. public function unhtmlentities($text_to_convert)
  13951. {
  13952. return html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
  13953. }
  13954. // ENCRYPTION METHODS ----------------------------------
  13955. /**
  13956. * Returns a string containing random data to be used as a seed for encryption methods.
  13957. * @param string $seed starting seed value
  13958. * @return string containing random data
  13959. * @author Nicola Asuni
  13960. * @since 5.9.006 (2010-10-19)
  13961. * @access protected
  13962. */
  13963. protected function getRandomSeed($seed = '')
  13964. {
  13965. $seed .= microtime();
  13966. if (function_exists('openssl_random_pseudo_bytes'))
  13967. {
  13968. $seed .= openssl_random_pseudo_bytes(512);
  13969. }
  13970. $seed .= uniqid('', true);
  13971. $seed .= rand();
  13972. $seed .= getmypid();
  13973. $seed .= __FILE__;
  13974. $seed .= $this->bufferlen;
  13975. if (isset($_SERVER['REMOTE_ADDR']))
  13976. {
  13977. $seed .= $_SERVER['REMOTE_ADDR'];
  13978. }
  13979. if (isset($_SERVER['HTTP_USER_AGENT']))
  13980. {
  13981. $seed .= $_SERVER['HTTP_USER_AGENT'];
  13982. }
  13983. if (isset($_SERVER['HTTP_ACCEPT']))
  13984. {
  13985. $seed .= $_SERVER['HTTP_ACCEPT'];
  13986. }
  13987. if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
  13988. {
  13989. $seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
  13990. }
  13991. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
  13992. {
  13993. $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  13994. }
  13995. if (isset($_SERVER['HTTP_ACCEPT_CHARSET']))
  13996. {
  13997. $seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
  13998. }
  13999. $seed .= rand();
  14000. $seed .= uniqid('', true);
  14001. $seed .= microtime();
  14002. return $seed;
  14003. }
  14004. /**
  14005. * Compute encryption key depending on object number where the encrypted data is stored.
  14006. * This is used for all strings and streams without crypt filter specifier.
  14007. * @param int $n object number
  14008. * @return int object key
  14009. * @access protected
  14010. * @author Nicola Asuni
  14011. * @since 2.0.000 (2008-01-02)
  14012. */
  14013. protected function _objectkey($n)
  14014. {
  14015. $objkey = $this->encryptdata['key'] . pack('VXxx', $n);
  14016. if ($this->encryptdata['mode'] == 2)
  14017. { // AES-128
  14018. // AES padding
  14019. $objkey .= "\x73\x41\x6C\x54"; // sAlT
  14020. }
  14021. $objkey = substr($this->_md5_16($objkey), 0, (($this->encryptdata['Length'] / 8) + 5));
  14022. $objkey = substr($objkey, 0, 16);
  14023. return $objkey;
  14024. }
  14025. /**
  14026. * Encrypt the input string.
  14027. * @param int $n object number
  14028. * @param string $s data string to encrypt
  14029. * @return encrypted string
  14030. * @access protected
  14031. * @author Nicola Asuni
  14032. * @since 5.0.005 (2010-05-11)
  14033. */
  14034. protected function _encrypt_data($n, $s)
  14035. {
  14036. if (! $this->encrypted)
  14037. {
  14038. return $s;
  14039. }
  14040. switch ($this->encryptdata['mode'])
  14041. {
  14042. case 0 : // RC4-40
  14043. case 1 :
  14044. { // RC4-128
  14045. $s = $this->_RC4($this->_objectkey($n), $s);
  14046. break;
  14047. }
  14048. case 2 :
  14049. { // AES-128
  14050. $s = $this->_AES($this->_objectkey($n), $s);
  14051. break;
  14052. }
  14053. case 3 :
  14054. { // AES-256
  14055. $s = $this->_AES($this->encryptdata['key'], $s);
  14056. break;
  14057. }
  14058. }
  14059. return $s;
  14060. }
  14061. /**
  14062. * Put encryption on PDF document.
  14063. * @access protected
  14064. * @author Nicola Asuni
  14065. * @since 2.0.000 (2008-01-02)
  14066. */
  14067. protected function _putencryption()
  14068. {
  14069. if (! $this->encrypted)
  14070. {
  14071. return;
  14072. }
  14073. $this->encryptdata['objid'] = $this->_newobj();
  14074. $out = '<<';
  14075. if (! isset($this->encryptdata['Filter']) or empty($this->encryptdata['Filter']))
  14076. {
  14077. $this->encryptdata['Filter'] = 'Standard';
  14078. }
  14079. $out .= ' /Filter /' . $this->encryptdata['Filter'];
  14080. if (isset($this->encryptdata['SubFilter']) and ! empty($this->encryptdata['SubFilter']))
  14081. {
  14082. $out .= ' /SubFilter /' . $this->encryptdata['SubFilter'];
  14083. }
  14084. if (! isset($this->encryptdata['V']) or empty($this->encryptdata['V']))
  14085. {
  14086. $this->encryptdata['V'] = 1;
  14087. }
  14088. // V is a code specifying the algorithm to be used in encrypting and decrypting the document
  14089. $out .= ' /V ' . $this->encryptdata['V'];
  14090. if (isset($this->encryptdata['Length']) and ! empty($this->encryptdata['Length']))
  14091. {
  14092. // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
  14093. $out .= ' /Length ' . $this->encryptdata['Length'];
  14094. }
  14095. else
  14096. {
  14097. $out .= ' /Length 40';
  14098. }
  14099. if ($this->encryptdata['V'] >= 4)
  14100. {
  14101. if (! isset($this->encryptdata['StmF']) or empty($this->encryptdata['StmF']))
  14102. {
  14103. $this->encryptdata['StmF'] = 'Identity';
  14104. }
  14105. if (! isset($this->encryptdata['StrF']) or empty($this->encryptdata['StrF']))
  14106. {
  14107. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  14108. $this->encryptdata['StrF'] = 'Identity';
  14109. }
  14110. // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
  14111. if (isset($this->encryptdata['CF']) and ! empty($this->encryptdata['CF']))
  14112. {
  14113. $out .= ' /CF <<';
  14114. $out .= ' /' . $this->encryptdata['StmF'] . ' <<';
  14115. $out .= ' /Type /CryptFilter';
  14116. if (isset($this->encryptdata['CF']['CFM']) and ! empty($this->encryptdata['CF']['CFM']))
  14117. {
  14118. // The method used
  14119. $out .= ' /CFM /' . $this->encryptdata['CF']['CFM'];
  14120. if ($this->encryptdata['pubkey'])
  14121. {
  14122. $out .= ' /Recipients [';
  14123. foreach ($this->encryptdata['Recipients'] as $rec)
  14124. {
  14125. $out .= ' <' . $rec . '>';
  14126. }
  14127. $out .= ' ]';
  14128. if (isset($this->encryptdata['CF']['EncryptMetadata']) and (! $this->encryptdata['CF']['EncryptMetadata']))
  14129. {
  14130. $out .= ' /EncryptMetadata false';
  14131. }
  14132. else
  14133. {
  14134. $out .= ' /EncryptMetadata true';
  14135. }
  14136. }
  14137. }
  14138. else
  14139. {
  14140. $out .= ' /CFM /None';
  14141. }
  14142. if (isset($this->encryptdata['CF']['AuthEvent']) and ! empty($this->encryptdata['CF']['AuthEvent']))
  14143. {
  14144. // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
  14145. $out .= ' /AuthEvent /' . $this->encryptdata['CF']['AuthEvent'];
  14146. }
  14147. else
  14148. {
  14149. $out .= ' /AuthEvent /DocOpen';
  14150. }
  14151. if (isset($this->encryptdata['CF']['Length']) and ! empty($this->encryptdata['CF']['Length']))
  14152. {
  14153. // The bit length of the encryption key.
  14154. $out .= ' /Length ' . $this->encryptdata['CF']['Length'];
  14155. }
  14156. $out .= ' >> >>';
  14157. }
  14158. // The name of the crypt filter that shall be used by default when decrypting streams.
  14159. $out .= ' /StmF /' . $this->encryptdata['StmF'];
  14160. // The name of the crypt filter that shall be used when decrypting all strings in the document.
  14161. $out .= ' /StrF /' . $this->encryptdata['StrF'];
  14162. if (isset($this->encryptdata['EFF']) and ! empty($this->encryptdata['EFF']))
  14163. {
  14164. // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
  14165. $out .= ' /EFF /' . $this->encryptdata[''];
  14166. }
  14167. }
  14168. // Additional encryption dictionary entries for the standard security handler
  14169. if ($this->encryptdata['pubkey'])
  14170. {
  14171. if (($this->encryptdata['V'] < 4) and isset($this->encryptdata['Recipients']) and ! empty($this->encryptdata['Recipients']))
  14172. {
  14173. $out .= ' /Recipients [';
  14174. foreach ($this->encryptdata['Recipients'] as $rec)
  14175. {
  14176. $out .= ' <' . $rec . '>';
  14177. }
  14178. $out .= ' ]';
  14179. }
  14180. }
  14181. else
  14182. {
  14183. $out .= ' /R';
  14184. if ($this->encryptdata['V'] == 5)
  14185. { // AES-256
  14186. $out .= ' 5';
  14187. $out .= ' /OE (' . $this->_escape($this->encryptdata['OE']) . ')';
  14188. $out .= ' /UE (' . $this->_escape($this->encryptdata['UE']) . ')';
  14189. $out .= ' /Perms (' . $this->_escape($this->encryptdata['perms']) . ')';
  14190. }
  14191. elseif ($this->encryptdata['V'] == 4)
  14192. { // AES-128
  14193. $out .= ' 4';
  14194. }
  14195. elseif ($this->encryptdata['V'] < 2)
  14196. { // RC-40
  14197. $out .= ' 2';
  14198. }
  14199. else
  14200. { // RC-128
  14201. $out .= ' 3';
  14202. }
  14203. $out .= ' /O (' . $this->_escape($this->encryptdata['O']) . ')';
  14204. $out .= ' /U (' . $this->_escape($this->encryptdata['U']) . ')';
  14205. $out .= ' /P ' . $this->encryptdata['P'];
  14206. if (isset($this->encryptdata['EncryptMetadata']) and (! $this->encryptdata['EncryptMetadata']))
  14207. {
  14208. $out .= ' /EncryptMetadata false';
  14209. }
  14210. else
  14211. {
  14212. $out .= ' /EncryptMetadata true';
  14213. }
  14214. }
  14215. $out .= ' >>';
  14216. $out .= "\n" . 'endobj';
  14217. $this->_out($out);
  14218. }
  14219. /**
  14220. * Returns the input text encrypted using RC4 algorithm and the specified key.
  14221. * RC4 is the standard encryption algorithm used in PDF format
  14222. * @param string $key encryption key
  14223. * @param String $text input text to be encrypted
  14224. * @return String encrypted text
  14225. * @access protected
  14226. * @since 2.0.000 (2008-01-02)
  14227. * @author Klemen Vodopivec, Nicola Asuni
  14228. */
  14229. protected function _RC4($key, $text)
  14230. {
  14231. if (function_exists('mcrypt_decrypt') and ($out = @mcrypt_decrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, '')))
  14232. {
  14233. // try to use mcrypt function if exist
  14234. return $out;
  14235. }
  14236. if ($this->last_enc_key != $key)
  14237. {
  14238. $k = str_repeat($key, ((256 / strlen($key)) + 1));
  14239. $rc4 = range(0, 255);
  14240. $j = 0;
  14241. for($i = 0; $i < 256; ++ $i)
  14242. {
  14243. $t = $rc4[$i];
  14244. $j = ($j + $t + ord($k{$i})) % 256;
  14245. $rc4[$i] = $rc4[$j];
  14246. $rc4[$j] = $t;
  14247. }
  14248. $this->last_enc_key = $key;
  14249. $this->last_enc_key_c = $rc4;
  14250. }
  14251. else
  14252. {
  14253. $rc4 = $this->last_enc_key_c;
  14254. }
  14255. $len = strlen($text);
  14256. $a = 0;
  14257. $b = 0;
  14258. $out = '';
  14259. for($i = 0; $i < $len; ++ $i)
  14260. {
  14261. $a = ($a + 1) % 256;
  14262. $t = $rc4[$a];
  14263. $b = ($b + $t) % 256;
  14264. $rc4[$a] = $rc4[$b];
  14265. $rc4[$b] = $t;
  14266. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  14267. $out .= chr(ord($text{$i}) ^ $k);
  14268. }
  14269. return $out;
  14270. }
  14271. /**
  14272. * Returns the input text exrypted using AES algorithm and the specified key.
  14273. * This method requires mcrypt.
  14274. * @param string $key encryption key
  14275. * @param String $text input text to be encrypted
  14276. * @return String encrypted text
  14277. * @access protected
  14278. * @author Nicola Asuni
  14279. * @since 5.0.005 (2010-05-11)
  14280. */
  14281. protected function _AES($key, $text)
  14282. {
  14283. // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
  14284. $padding = 16 - (strlen($text) % 16);
  14285. $text .= str_repeat(chr($padding), $padding);
  14286. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
  14287. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  14288. $text = $iv . $text;
  14289. return $text;
  14290. }
  14291. /**
  14292. * Encrypts a string using MD5 and returns it's value as a binary string.
  14293. * @param string $str input string
  14294. * @return String MD5 encrypted binary string
  14295. * @access protected
  14296. * @since 2.0.000 (2008-01-02)
  14297. * @author Klemen Vodopivec
  14298. */
  14299. protected function _md5_16($str)
  14300. {
  14301. return pack('H*', md5($str));
  14302. }
  14303. /**
  14304. * Compute U value (used for encryption)
  14305. * @return string U value
  14306. * @access protected
  14307. * @since 2.0.000 (2008-01-02)
  14308. * @author Nicola Asuni
  14309. */
  14310. protected function _Uvalue()
  14311. {
  14312. if ($this->encryptdata['mode'] == 0)
  14313. { // RC4-40
  14314. return $this->_RC4($this->encryptdata['key'], $this->enc_padding);
  14315. }
  14316. elseif ($this->encryptdata['mode'] < 3)
  14317. { // RC4-128, AES-128
  14318. $tmp = $this->_md5_16($this->enc_padding . $this->encryptdata['fileid']);
  14319. $enc = $this->_RC4($this->encryptdata['key'], $tmp);
  14320. $len = strlen($tmp);
  14321. for($i = 1; $i <= 19; ++ $i)
  14322. {
  14323. $ek = '';
  14324. for($j = 0; $j < $len; ++ $j)
  14325. {
  14326. $ek .= chr(ord($this->encryptdata['key']{$j}) ^ $i);
  14327. }
  14328. $enc = $this->_RC4($ek, $enc);
  14329. }
  14330. $enc .= str_repeat("\x00", 16);
  14331. return substr($enc, 0, 32);
  14332. }
  14333. elseif ($this->encryptdata['mode'] == 3)
  14334. { // AES-256
  14335. $seed = $this->_md5_16($this->getRandomSeed());
  14336. // User Validation Salt
  14337. $this->encryptdata['UVS'] = substr($seed, 0, 8);
  14338. // User Key Salt
  14339. $this->encryptdata['UKS'] = substr($seed, 8, 16);
  14340. return hash('sha256', $this->encryptdata['user_password'] . $this->encryptdata['UVS'], true) . $this->encryptdata['UVS'] . $this->encryptdata['UKS'];
  14341. }
  14342. }
  14343. /**
  14344. * Compute UE value (used for encryption)
  14345. * @return string UE value
  14346. * @access protected
  14347. * @since 5.9.006 (2010-10-19)
  14348. * @author Nicola Asuni
  14349. */
  14350. protected function _UEvalue()
  14351. {
  14352. $hashkey = hash('sha256', $this->encryptdata['user_password'] . $this->encryptdata['UKS'], true);
  14353. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  14354. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  14355. }
  14356. /**
  14357. * Compute O value (used for encryption)
  14358. * @return string O value
  14359. * @access protected
  14360. * @since 2.0.000 (2008-01-02)
  14361. * @author Nicola Asuni
  14362. */
  14363. protected function _Ovalue()
  14364. {
  14365. if ($this->encryptdata['mode'] < 3)
  14366. { // RC4-40, RC4-128, AES-128
  14367. $tmp = $this->_md5_16($this->encryptdata['owner_password']);
  14368. if ($this->encryptdata['mode'] > 0)
  14369. {
  14370. for($i = 0; $i < 50; ++ $i)
  14371. {
  14372. $tmp = $this->_md5_16($tmp);
  14373. }
  14374. }
  14375. $owner_key = substr($tmp, 0, ($this->encryptdata['Length'] / 8));
  14376. $enc = $this->_RC4($owner_key, $this->encryptdata['user_password']);
  14377. if ($this->encryptdata['mode'] > 0)
  14378. {
  14379. $len = strlen($owner_key);
  14380. for($i = 1; $i <= 19; ++ $i)
  14381. {
  14382. $ek = '';
  14383. for($j = 0; $j < $len; ++ $j)
  14384. {
  14385. $ek .= chr(ord($owner_key{$j}) ^ $i);
  14386. }
  14387. $enc = $this->_RC4($ek, $enc);
  14388. }
  14389. }
  14390. return $enc;
  14391. }
  14392. elseif ($this->encryptdata['mode'] == 3)
  14393. { // AES-256
  14394. $seed = $this->_md5_16($this->getRandomSeed());
  14395. // Owner Validation Salt
  14396. $this->encryptdata['OVS'] = substr($seed, 0, 8);
  14397. // Owner Key Salt
  14398. $this->encryptdata['OKS'] = substr($seed, 8, 16);
  14399. return hash('sha256', $this->encryptdata['owner_password'] . $this->encryptdata['OVS'] . $this->encryptdata['U'], true) . $this->encryptdata['OVS'] . $this->encryptdata['OKS'];
  14400. }
  14401. }
  14402. /**
  14403. * Compute OE value (used for encryption)
  14404. * @return string OE value
  14405. * @access protected
  14406. * @since 5.9.006 (2010-10-19)
  14407. * @author Nicola Asuni
  14408. */
  14409. protected function _OEvalue()
  14410. {
  14411. $hashkey = hash('sha256', $this->encryptdata['owner_password'] . $this->encryptdata['OKS'] . $this->encryptdata['U'], true);
  14412. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  14413. return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $hashkey, $this->encryptdata['key'], MCRYPT_MODE_CBC, $iv);
  14414. }
  14415. /**
  14416. * Convert password for AES-256 encryption mode
  14417. * @return string password
  14418. * @access protected
  14419. * @since 5.9.006 (2010-10-19)
  14420. * @author Nicola Asuni
  14421. */
  14422. protected function _fixAES256Password($password)
  14423. {
  14424. $psw = ''; // password to be returned
  14425. $psw_array = $this->utf8Bidi($this->UTF8StringToArray($password), $password, $this->rtl);
  14426. foreach ($psw_array as $c)
  14427. {
  14428. $psw .= $this->unichr($c);
  14429. }
  14430. return substr($psw, 0, 127);
  14431. }
  14432. /**
  14433. * Compute encryption key
  14434. * @access protected
  14435. * @since 2.0.000 (2008-01-02)
  14436. * @author Nicola Asuni
  14437. */
  14438. protected function _generateencryptionkey()
  14439. {
  14440. $keybytelen = ($this->encryptdata['Length'] / 8);
  14441. if (! $this->encryptdata['pubkey'])
  14442. { // standard mode
  14443. if ($this->encryptdata['mode'] == 3)
  14444. { // AES-256
  14445. // generate 256 bit random key
  14446. $this->encryptdata['key'] = substr(hash('sha256', $this->getRandomSeed(), true), 0, $keybytelen);
  14447. // truncate passwords
  14448. $this->encryptdata['user_password'] = $this->_fixAES256Password($this->encryptdata['user_password']);
  14449. $this->encryptdata['owner_password'] = $this->_fixAES256Password($this->encryptdata['owner_password']);
  14450. // Compute U value
  14451. $this->encryptdata['U'] = $this->_Uvalue();
  14452. // Compute UE value
  14453. $this->encryptdata['UE'] = $this->_UEvalue();
  14454. // Compute O value
  14455. $this->encryptdata['O'] = $this->_Ovalue();
  14456. // Compute OE value
  14457. $this->encryptdata['OE'] = $this->_OEvalue();
  14458. // Compute P value
  14459. $this->encryptdata['P'] = $this->encryptdata['protection'];
  14460. // Computing the encryption dictionary's Perms (permissions) value
  14461. $perms = $this->getEncPermissionsString($this->encryptdata['protection']); // bytes 0-3
  14462. $perms .= chr(255) . chr(255) . chr(255) . chr(255); // bytes 4-7
  14463. if (isset($this->encryptdata['CF']['EncryptMetadata']) and (! $this->encryptdata['CF']['EncryptMetadata']))
  14464. { // byte 8
  14465. $perms .= 'F';
  14466. }
  14467. else
  14468. {
  14469. $perms .= 'T';
  14470. }
  14471. $perms .= 'adb'; // bytes 9-11
  14472. $perms .= 'nick'; // bytes 12-15
  14473. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
  14474. $this->encryptdata['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->encryptdata['key'], $perms, MCRYPT_MODE_ECB, $iv);
  14475. }
  14476. else
  14477. { // RC4-40, RC4-128, AES-128
  14478. // Pad passwords
  14479. $this->encryptdata['user_password'] = substr($this->encryptdata['user_password'] . $this->enc_padding, 0, 32);
  14480. $this->encryptdata['owner_password'] = substr($this->encryptdata['owner_password'] . $this->enc_padding, 0, 32);
  14481. // Compute O value
  14482. $this->encryptdata['O'] = $this->_Ovalue();
  14483. // get default permissions (reverse byte order)
  14484. $permissions = $this->getEncPermissionsString($this->encryptdata['protection']);
  14485. // Compute encryption key
  14486. $tmp = $this->_md5_16($this->encryptdata['user_password'] . $this->encryptdata['O'] . $permissions . $this->encryptdata['fileid']);
  14487. if ($this->encryptdata['mode'] > 0)
  14488. {
  14489. for($i = 0; $i < 50; ++ $i)
  14490. {
  14491. $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
  14492. }
  14493. }
  14494. $this->encryptdata['key'] = substr($tmp, 0, $keybytelen);
  14495. // Compute U value
  14496. $this->encryptdata['U'] = $this->_Uvalue();
  14497. // Compute P value
  14498. $this->encryptdata['P'] = $this->encryptdata['protection'];
  14499. }
  14500. }
  14501. else
  14502. { // Public-Key mode
  14503. // random 20-byte seed
  14504. $seed = sha1($this->getRandomSeed(), true);
  14505. $recipient_bytes = '';
  14506. foreach ($this->encryptdata['pubkeys'] as $pubkey)
  14507. {
  14508. // for each public certificate
  14509. if (isset($pubkey['p']))
  14510. {
  14511. $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
  14512. }
  14513. else
  14514. {
  14515. $pkprotection = $this->encryptdata['protection'];
  14516. }
  14517. // get default permissions (reverse byte order)
  14518. $pkpermissions = $this->getEncPermissionsString($pkprotection);
  14519. // envelope data
  14520. $envelope = $seed . $pkpermissions;
  14521. // write the envelope data to a temporary file
  14522. $tempkeyfile = tempnam(K_PATH_CACHE, 'tmpkey_');
  14523. $f = fopen($tempkeyfile, 'wb');
  14524. if (! $f)
  14525. {
  14526. $this->Error('Unable to create temporary key file: ' . $tempkeyfile);
  14527. }
  14528. $envelope_lenght = strlen($envelope);
  14529. fwrite($f, $envelope, $envelope_lenght);
  14530. fclose($f);
  14531. $tempencfile = tempnam(K_PATH_CACHE, 'tmpenc_');
  14532. if (! openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_DETACHED | PKCS7_BINARY))
  14533. {
  14534. $this->Error('Unable to encrypt the file: ' . $tempkeyfile);
  14535. }
  14536. unlink($tempkeyfile);
  14537. // read encryption signature
  14538. $signature = file_get_contents($tempencfile, false, null, $envelope_lenght);
  14539. unlink($tempencfile);
  14540. // extract signature
  14541. $signature = substr($signature, strpos($signature, 'Content-Disposition'));
  14542. $tmparr = explode("\n\n", $signature);
  14543. $signature = trim($tmparr[1]);
  14544. unset($tmparr);
  14545. // decode signature
  14546. $signature = base64_decode($signature);
  14547. // convert signature to hex
  14548. $hexsignature = current(unpack('H*', $signature));
  14549. // store signature on recipients array
  14550. $this->encryptdata['Recipients'][] = $hexsignature;
  14551. // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
  14552. $recipient_bytes .= $signature;
  14553. }
  14554. // calculate encryption key
  14555. if ($this->encryptdata['mode'] == 3)
  14556. { // AES-256
  14557. $this->encryptdata['key'] = substr(hash('sha256', $seed . $recipient_bytes, true), 0, $keybytelen);
  14558. }
  14559. else
  14560. { // RC4-40, RC4-128, AES-128
  14561. $this->encryptdata['key'] = substr(sha1($seed . $recipient_bytes, true), 0, $keybytelen);
  14562. }
  14563. }
  14564. }
  14565. /**
  14566. * Return the premission code used on encryption (P value).
  14567. * @param Array $permissions the set of permissions (specify the ones you want to block).
  14568. * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  14569. * @access protected
  14570. * @since 5.0.005 (2010-05-12)
  14571. * @author Nicola Asuni
  14572. */
  14573. protected function getUserPermissionCode($permissions, $mode = 0)
  14574. {
  14575. $options = array('owner' => 2, // bit 2 -- inverted logic: cleared by default
  14576. 'print' => 4, // bit 3
  14577. 'modify' => 8, // bit 4
  14578. 'copy' => 16, // bit 5
  14579. 'annot-forms' => 32, // bit 6
  14580. 'fill-forms' => 256, // bit 9
  14581. 'extract' => 512, // bit 10
  14582. 'assemble' => 1024, // bit 11
  14583. 'print-high' => 2048)// bit 12
  14584. ;
  14585. $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
  14586. foreach ($permissions as $permission)
  14587. {
  14588. if (! isset($options[$permission]))
  14589. {
  14590. $this->Error('Incorrect permission: ' . $permission);
  14591. }
  14592. if (($mode > 0) or ($options[$permission] <= 32))
  14593. {
  14594. // set only valid permissions
  14595. if ($options[$permission] == 2)
  14596. {
  14597. // the logic for bit 2 is inverted (cleared by default)
  14598. $protection += $options[$permission];
  14599. }
  14600. else
  14601. {
  14602. $protection -= $options[$permission];
  14603. }
  14604. }
  14605. }
  14606. return $protection;
  14607. }
  14608. /**
  14609. * Set document protection
  14610. * Remark: the protection against modification is for people who have the full Acrobat product.
  14611. * 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.
  14612. * 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.
  14613. * @param Array $permissions the set of permissions (specify the ones you want to block):<ul><li>print : Print the document;</li><li>modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';</li><li>copy : Copy or otherwise extract text and graphics from the document;</li><li>annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);</li><li>fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;</li><li>extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);</li><li>assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;</li><li>print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.</li><li>owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.</li></ul>
  14614. * @param String $user_pass user password. Empty by default.
  14615. * @param String $owner_pass owner password. If not specified, a random value is used.
  14616. * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  14617. * @param String $pubkeys array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../tcpdf.crt', 'p' => array('print')))
  14618. * @access public
  14619. * @since 2.0.000 (2008-01-02)
  14620. * @author Nicola Asuni
  14621. */
  14622. 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)
  14623. {
  14624. $this->encryptdata['protection'] = $this->getUserPermissionCode($permissions, $mode);
  14625. if (($pubkeys !== null) and (is_array($pubkeys)))
  14626. {
  14627. // public-key mode
  14628. $this->encryptdata['pubkeys'] = $pubkeys;
  14629. if ($mode == 0)
  14630. {
  14631. // public-Key Security requires at least 128 bit
  14632. $mode = 1;
  14633. }
  14634. if (! function_exists('openssl_pkcs7_encrypt'))
  14635. {
  14636. $this->Error('Public-Key Security requires openssl library.');
  14637. }
  14638. // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
  14639. $this->encryptdata['pubkey'] = true;
  14640. $this->encryptdata['Filter'] = 'Adobe.PubSec';
  14641. $this->encryptdata['StmF'] = 'DefaultCryptFilter';
  14642. $this->encryptdata['StrF'] = 'DefaultCryptFilter';
  14643. }
  14644. else
  14645. {
  14646. // standard mode (password mode)
  14647. $this->encryptdata['pubkey'] = false;
  14648. $this->encryptdata['Filter'] = 'Standard';
  14649. $this->encryptdata['StmF'] = 'StdCF';
  14650. $this->encryptdata['StrF'] = 'StdCF';
  14651. }
  14652. if ($mode > 1)
  14653. { // AES
  14654. if (! extension_loaded('mcrypt'))
  14655. {
  14656. $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
  14657. }
  14658. if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) === false)
  14659. {
  14660. $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
  14661. }
  14662. if (($mode == 3) and ! function_exists('hash'))
  14663. {
  14664. // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
  14665. $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
  14666. }
  14667. }
  14668. if ($owner_pass === null)
  14669. {
  14670. $owner_pass = md5($this->getRandomSeed());
  14671. }
  14672. $this->encryptdata['user_password'] = $user_pass;
  14673. $this->encryptdata['owner_password'] = $owner_pass;
  14674. $this->encryptdata['mode'] = $mode;
  14675. switch ($mode)
  14676. {
  14677. case 0 :
  14678. { // RC4 40 bit
  14679. $this->encryptdata['V'] = 1;
  14680. $this->encryptdata['Length'] = 40;
  14681. $this->encryptdata['CF']['CFM'] = 'V2';
  14682. break;
  14683. }
  14684. case 1 :
  14685. { // RC4 128 bit
  14686. $this->encryptdata['V'] = 2;
  14687. $this->encryptdata['Length'] = 128;
  14688. $this->encryptdata['CF']['CFM'] = 'V2';
  14689. if ($this->encryptdata['pubkey'])
  14690. {
  14691. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s4';
  14692. $this->encryptdata['Recipients'] = array();
  14693. }
  14694. break;
  14695. }
  14696. case 2 :
  14697. { // AES 128 bit
  14698. $this->encryptdata['V'] = 4;
  14699. $this->encryptdata['Length'] = 128;
  14700. $this->encryptdata['CF']['CFM'] = 'AESV2';
  14701. $this->encryptdata['CF']['Length'] = 128;
  14702. if ($this->encryptdata['pubkey'])
  14703. {
  14704. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  14705. $this->encryptdata['Recipients'] = array();
  14706. }
  14707. break;
  14708. }
  14709. case 3 :
  14710. { // AES 256 bit
  14711. $this->encryptdata['V'] = 5;
  14712. $this->encryptdata['Length'] = 256;
  14713. $this->encryptdata['CF']['CFM'] = 'AESV3';
  14714. $this->encryptdata['CF']['Length'] = 256;
  14715. if ($this->encryptdata['pubkey'])
  14716. {
  14717. $this->encryptdata['SubFilter'] = 'adbe.pkcs7.s5';
  14718. $this->encryptdata['Recipients'] = array();
  14719. }
  14720. break;
  14721. }
  14722. }
  14723. $this->encrypted = true;
  14724. $this->encryptdata['fileid'] = $this->convertHexStringToString($this->file_id);
  14725. $this->_generateencryptionkey();
  14726. }
  14727. /**
  14728. * Convert hexadecimal string to string
  14729. * @param string $bs byte-string to convert
  14730. * @return String
  14731. * @access protected
  14732. * @since 5.0.005 (2010-05-12)
  14733. * @author Nicola Asuni
  14734. */
  14735. protected function convertHexStringToString($bs)
  14736. {
  14737. $string = ''; // string to be returned
  14738. $bslenght = strlen($bs);
  14739. if (($bslenght % 2) != 0)
  14740. {
  14741. // padding
  14742. $bs .= '0';
  14743. ++ $bslenght;
  14744. }
  14745. for($i = 0; $i < $bslenght; $i += 2)
  14746. {
  14747. $string .= chr(hexdec($bs{$i} . $bs{($i + 1)}));
  14748. }
  14749. return $string;
  14750. }
  14751. /**
  14752. * Convert string to hexadecimal string (byte string)
  14753. * @param string $s string to convert
  14754. * @return byte string
  14755. * @access protected
  14756. * @since 5.0.010 (2010-05-17)
  14757. * @author Nicola Asuni
  14758. */
  14759. protected function convertStringToHexString($s)
  14760. {
  14761. $bs = '';
  14762. $chars = preg_split('//', $s, - 1, PREG_SPLIT_NO_EMPTY);
  14763. foreach ($chars as $c)
  14764. {
  14765. $bs .= sprintf('%02s', dechex(ord($c)));
  14766. }
  14767. return $bs;
  14768. }
  14769. /**
  14770. * Convert encryption P value to a string of bytes, low-order byte first.
  14771. * @param string $protection 32bit encryption permission value (P value)
  14772. * @return String
  14773. * @access protected
  14774. * @since 5.0.005 (2010-05-12)
  14775. * @author Nicola Asuni
  14776. */
  14777. protected function getEncPermissionsString($protection)
  14778. {
  14779. $binprot = sprintf('%032b', $protection);
  14780. $str = chr(bindec(substr($binprot, 24, 8)));
  14781. $str .= chr(bindec(substr($binprot, 16, 8)));
  14782. $str .= chr(bindec(substr($binprot, 8, 8)));
  14783. $str .= chr(bindec(substr($binprot, 0, 8)));
  14784. return $str;
  14785. }
  14786. // END OF ENCRYPTION FUNCTIONS -------------------------
  14787. // START TRANSFORMATIONS SECTION -----------------------
  14788. /**
  14789. * Starts a 2D tranformation saving current graphic state.
  14790. * This function must be called before scaling, mirroring, translation, rotation and skewing.
  14791. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  14792. * @access public
  14793. * @since 2.1.000 (2008-01-07)
  14794. * @see StartTransform(), StopTransform()
  14795. */
  14796. public function StartTransform()
  14797. {
  14798. $this->_out('q');
  14799. if ($this->inxobj)
  14800. {
  14801. // we are inside an XObject template
  14802. $this->xobjects[$this->xobjid]['transfmrk'][] = strlen($this->xobjects[$this->xobjid]['outdata']);
  14803. }
  14804. else
  14805. {
  14806. $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
  14807. }
  14808. ++ $this->transfmatrix_key;
  14809. $this->transfmatrix[$this->transfmatrix_key] = array();
  14810. }
  14811. /**
  14812. * Stops a 2D tranformation restoring previous graphic state.
  14813. * This function must be called after scaling, mirroring, translation, rotation and skewing.
  14814. * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
  14815. * @access public
  14816. * @since 2.1.000 (2008-01-07)
  14817. * @see StartTransform(), StopTransform()
  14818. */
  14819. public function StopTransform()
  14820. {
  14821. $this->_out('Q');
  14822. if (isset($this->transfmatrix[$this->transfmatrix_key]))
  14823. {
  14824. array_pop($this->transfmatrix[$this->transfmatrix_key]);
  14825. -- $this->transfmatrix_key;
  14826. }
  14827. if ($this->inxobj)
  14828. {
  14829. // we are inside an XObject template
  14830. array_pop($this->xobjects[$this->xobjid]['transfmrk']);
  14831. }
  14832. else
  14833. {
  14834. array_pop($this->transfmrk[$this->page]);
  14835. }
  14836. }
  14837. /**
  14838. * Horizontal Scaling.
  14839. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  14840. * @param int $x abscissa of the scaling center. Default is current x position
  14841. * @param int $y ordinate of the scaling center. Default is current y position
  14842. * @access public
  14843. * @since 2.1.000 (2008-01-07)
  14844. * @see StartTransform(), StopTransform()
  14845. */
  14846. public function ScaleX($s_x, $x = '', $y = '')
  14847. {
  14848. $this->Scale($s_x, 100, $x, $y);
  14849. }
  14850. /**
  14851. * Vertical Scaling.
  14852. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  14853. * @param int $x abscissa of the scaling center. Default is current x position
  14854. * @param int $y ordinate of the scaling center. Default is current y position
  14855. * @access public
  14856. * @since 2.1.000 (2008-01-07)
  14857. * @see StartTransform(), StopTransform()
  14858. */
  14859. public function ScaleY($s_y, $x = '', $y = '')
  14860. {
  14861. $this->Scale(100, $s_y, $x, $y);
  14862. }
  14863. /**
  14864. * Vertical and horizontal proportional Scaling.
  14865. * @param float $s scaling factor for width and height as percent. 0 is not allowed.
  14866. * @param int $x abscissa of the scaling center. Default is current x position
  14867. * @param int $y ordinate of the scaling center. Default is current y position
  14868. * @access public
  14869. * @since 2.1.000 (2008-01-07)
  14870. * @see StartTransform(), StopTransform()
  14871. */
  14872. public function ScaleXY($s, $x = '', $y = '')
  14873. {
  14874. $this->Scale($s, $s, $x, $y);
  14875. }
  14876. /**
  14877. * Vertical and horizontal non-proportional Scaling.
  14878. * @param float $s_x scaling factor for width as percent. 0 is not allowed.
  14879. * @param float $s_y scaling factor for height as percent. 0 is not allowed.
  14880. * @param int $x abscissa of the scaling center. Default is current x position
  14881. * @param int $y ordinate of the scaling center. Default is current y position
  14882. * @access public
  14883. * @since 2.1.000 (2008-01-07)
  14884. * @see StartTransform(), StopTransform()
  14885. */
  14886. public function Scale($s_x, $s_y, $x = '', $y = '')
  14887. {
  14888. if ($x === '')
  14889. {
  14890. $x = $this->x;
  14891. }
  14892. if ($y === '')
  14893. {
  14894. $y = $this->y;
  14895. }
  14896. if (($s_x == 0) or ($s_y == 0))
  14897. {
  14898. $this->Error('Please do not use values equal to zero for scaling');
  14899. }
  14900. $y = ($this->h - $y) * $this->k;
  14901. $x *= $this->k;
  14902. //calculate elements of transformation matrix
  14903. $s_x /= 100;
  14904. $s_y /= 100;
  14905. $tm = array();
  14906. $tm[0] = $s_x;
  14907. $tm[1] = 0;
  14908. $tm[2] = 0;
  14909. $tm[3] = $s_y;
  14910. $tm[4] = $x * (1 - $s_x);
  14911. $tm[5] = $y * (1 - $s_y);
  14912. //scale the coordinate system
  14913. $this->Transform($tm);
  14914. }
  14915. /**
  14916. * Horizontal Mirroring.
  14917. * @param int $x abscissa of the point. Default is current x position
  14918. * @access public
  14919. * @since 2.1.000 (2008-01-07)
  14920. * @see StartTransform(), StopTransform()
  14921. */
  14922. public function MirrorH($x = '')
  14923. {
  14924. $this->Scale(- 100, 100, $x);
  14925. }
  14926. /**
  14927. * Verical Mirroring.
  14928. * @param int $y ordinate of the point. Default is current y position
  14929. * @access public
  14930. * @since 2.1.000 (2008-01-07)
  14931. * @see StartTransform(), StopTransform()
  14932. */
  14933. public function MirrorV($y = '')
  14934. {
  14935. $this->Scale(100, - 100, '', $y);
  14936. }
  14937. /**
  14938. * Point reflection mirroring.
  14939. * @param int $x abscissa of the point. Default is current x position
  14940. * @param int $y ordinate of the point. Default is current y position
  14941. * @access public
  14942. * @since 2.1.000 (2008-01-07)
  14943. * @see StartTransform(), StopTransform()
  14944. */
  14945. public function MirrorP($x = '', $y = '')
  14946. {
  14947. $this->Scale(- 100, - 100, $x, $y);
  14948. }
  14949. /**
  14950. * Reflection against a straight line through point (x, y) with the gradient angle (angle).
  14951. * @param float $angle gradient angle of the straight line. Default is 0 (horizontal line).
  14952. * @param int $x abscissa of the point. Default is current x position
  14953. * @param int $y ordinate of the point. Default is current y position
  14954. * @access public
  14955. * @since 2.1.000 (2008-01-07)
  14956. * @see StartTransform(), StopTransform()
  14957. */
  14958. public function MirrorL($angle = 0, $x = '', $y = '')
  14959. {
  14960. $this->Scale(- 100, 100, $x, $y);
  14961. $this->Rotate(- 2 * ($angle - 90), $x, $y);
  14962. }
  14963. /**
  14964. * Translate graphic object horizontally.
  14965. * @param int $t_x movement to the right (or left for RTL)
  14966. * @access public
  14967. * @since 2.1.000 (2008-01-07)
  14968. * @see StartTransform(), StopTransform()
  14969. */
  14970. public function TranslateX($t_x)
  14971. {
  14972. $this->Translate($t_x, 0);
  14973. }
  14974. /**
  14975. * Translate graphic object vertically.
  14976. * @param int $t_y movement to the bottom
  14977. * @access public
  14978. * @since 2.1.000 (2008-01-07)
  14979. * @see StartTransform(), StopTransform()
  14980. */
  14981. public function TranslateY($t_y)
  14982. {
  14983. $this->Translate(0, $t_y);
  14984. }
  14985. /**
  14986. * Translate graphic object horizontally and vertically.
  14987. * @param int $t_x movement to the right
  14988. * @param int $t_y movement to the bottom
  14989. * @access public
  14990. * @since 2.1.000 (2008-01-07)
  14991. * @see StartTransform(), StopTransform()
  14992. */
  14993. public function Translate($t_x, $t_y)
  14994. {
  14995. //calculate elements of transformation matrix
  14996. $tm = array();
  14997. $tm[0] = 1;
  14998. $tm[1] = 0;
  14999. $tm[2] = 0;
  15000. $tm[3] = 1;
  15001. $tm[4] = $t_x * $this->k;
  15002. $tm[5] = - $t_y * $this->k;
  15003. //translate the coordinate system
  15004. $this->Transform($tm);
  15005. }
  15006. /**
  15007. * Rotate object.
  15008. * @param float $angle angle in degrees for counter-clockwise rotation
  15009. * @param int $x abscissa of the rotation center. Default is current x position
  15010. * @param int $y ordinate of the rotation center. Default is current y position
  15011. * @access public
  15012. * @since 2.1.000 (2008-01-07)
  15013. * @see StartTransform(), StopTransform()
  15014. */
  15015. public function Rotate($angle, $x = '', $y = '')
  15016. {
  15017. if ($x === '')
  15018. {
  15019. $x = $this->x;
  15020. }
  15021. if ($y === '')
  15022. {
  15023. $y = $this->y;
  15024. }
  15025. $y = ($this->h - $y) * $this->k;
  15026. $x *= $this->k;
  15027. //calculate elements of transformation matrix
  15028. $tm = array();
  15029. $tm[0] = cos(deg2rad($angle));
  15030. $tm[1] = sin(deg2rad($angle));
  15031. $tm[2] = - $tm[1];
  15032. $tm[3] = $tm[0];
  15033. $tm[4] = $x + ($tm[1] * $y) - ($tm[0] * $x);
  15034. $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
  15035. //rotate the coordinate system around ($x,$y)
  15036. $this->Transform($tm);
  15037. }
  15038. /**
  15039. * Skew horizontally.
  15040. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  15041. * @param int $x abscissa of the skewing center. default is current x position
  15042. * @param int $y ordinate of the skewing center. default is current y position
  15043. * @access public
  15044. * @since 2.1.000 (2008-01-07)
  15045. * @see StartTransform(), StopTransform()
  15046. */
  15047. public function SkewX($angle_x, $x = '', $y = '')
  15048. {
  15049. $this->Skew($angle_x, 0, $x, $y);
  15050. }
  15051. /**
  15052. * Skew vertically.
  15053. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  15054. * @param int $x abscissa of the skewing center. default is current x position
  15055. * @param int $y ordinate of the skewing center. default is current y position
  15056. * @access public
  15057. * @since 2.1.000 (2008-01-07)
  15058. * @see StartTransform(), StopTransform()
  15059. */
  15060. public function SkewY($angle_y, $x = '', $y = '')
  15061. {
  15062. $this->Skew(0, $angle_y, $x, $y);
  15063. }
  15064. /**
  15065. * Skew.
  15066. * @param float $angle_x angle in degrees between -90 (skew to the left) and 90 (skew to the right)
  15067. * @param float $angle_y angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
  15068. * @param int $x abscissa of the skewing center. default is current x position
  15069. * @param int $y ordinate of the skewing center. default is current y position
  15070. * @access public
  15071. * @since 2.1.000 (2008-01-07)
  15072. * @see StartTransform(), StopTransform()
  15073. */
  15074. public function Skew($angle_x, $angle_y, $x = '', $y = '')
  15075. {
  15076. if ($x === '')
  15077. {
  15078. $x = $this->x;
  15079. }
  15080. if ($y === '')
  15081. {
  15082. $y = $this->y;
  15083. }
  15084. if (($angle_x <= - 90) or ($angle_x >= 90) or ($angle_y <= - 90) or ($angle_y >= 90))
  15085. {
  15086. $this->Error('Please use values between -90 and +90 degrees for Skewing.');
  15087. }
  15088. $x *= $this->k;
  15089. $y = ($this->h - $y) * $this->k;
  15090. //calculate elements of transformation matrix
  15091. $tm = array();
  15092. $tm[0] = 1;
  15093. $tm[1] = tan(deg2rad($angle_y));
  15094. $tm[2] = tan(deg2rad($angle_x));
  15095. $tm[3] = 1;
  15096. $tm[4] = - $tm[2] * $y;
  15097. $tm[5] = - $tm[1] * $x;
  15098. //skew the coordinate system
  15099. $this->Transform($tm);
  15100. }
  15101. /**
  15102. * Apply graphic transformations.
  15103. * @param array $tm transformation matrix
  15104. * @access protected
  15105. * @since 2.1.000 (2008-01-07)
  15106. * @see StartTransform(), StopTransform()
  15107. */
  15108. protected function Transform($tm)
  15109. {
  15110. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  15111. // add tranformation matrix
  15112. $this->transfmatrix[$this->transfmatrix_key][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2],
  15113. 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
  15114. // update transformation mark
  15115. if ($this->inxobj)
  15116. {
  15117. // we are inside an XObject template
  15118. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false)
  15119. {
  15120. $key = key($this->xobjects[$this->xobjid]['transfmrk']);
  15121. $this->xobjects[$this->xobjid]['transfmrk'][$key] = strlen($this->xobjects[$this->xobjid]['outdata']);
  15122. }
  15123. }
  15124. elseif (end($this->transfmrk[$this->page]) !== false)
  15125. {
  15126. $key = key($this->transfmrk[$this->page]);
  15127. $this->transfmrk[$this->page][$key] = $this->pagelen[$this->page];
  15128. }
  15129. }
  15130. // END TRANSFORMATIONS SECTION -------------------------
  15131. // START GRAPHIC FUNCTIONS SECTION ---------------------
  15132. // The following section is based on the code provided by David Hernandez Sanz
  15133. /**
  15134. * 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.
  15135. * @param float $width The width.
  15136. * @access public
  15137. * @since 1.0
  15138. * @see Line(), Rect(), Cell(), MultiCell()
  15139. */
  15140. public function SetLineWidth($width)
  15141. {
  15142. //Set line width
  15143. $this->LineWidth = $width;
  15144. $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
  15145. if ($this->page > 0)
  15146. {
  15147. $this->_out($this->linestyleWidth);
  15148. }
  15149. }
  15150. /**
  15151. * Returns the current the line width.
  15152. * @return int Line width
  15153. * @access public
  15154. * @since 2.1.000 (2008-01-07)
  15155. * @see Line(), SetLineWidth()
  15156. */
  15157. public function GetLineWidth()
  15158. {
  15159. return $this->LineWidth;
  15160. }
  15161. /**
  15162. * Set line style.
  15163. * @param array $style Line style. Array with keys among the following:
  15164. * <ul>
  15165. * <li>width (float): Width of the line in user units.</li>
  15166. * <li>cap (string): Type of cap to put on the line. Possible values are:
  15167. * butt, round, square. The difference between "square" and "butt" is that
  15168. * "square" projects a flat end past the end of the line.</li>
  15169. * <li>join (string): Type of join. Possible values are: miter, round,
  15170. * bevel.</li>
  15171. * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
  15172. * series of length values, which are the lengths of the on and off dashes.
  15173. * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
  15174. * 1 off, 2 on, 1 off, ...</li>
  15175. * <li>phase (integer): Modifier on the dash pattern which is used to shift
  15176. * the point at which the pattern starts.</li>
  15177. * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
  15178. * </ul>
  15179. * @param boolean $ret if true do not send the command.
  15180. * @return string the PDF command
  15181. * @access public
  15182. * @since 2.1.000 (2008-01-08)
  15183. */
  15184. public function SetLineStyle($style, $ret = false)
  15185. {
  15186. $s = ''; // string to be returned
  15187. if (! is_array($style))
  15188. {
  15189. return;
  15190. }
  15191. extract($style);
  15192. if (isset($width))
  15193. {
  15194. $this->LineWidth = $width;
  15195. $this->linestyleWidth = sprintf('%.2F w', ($width * $this->k));
  15196. $s .= $this->linestyleWidth . ' ';
  15197. }
  15198. if (isset($cap))
  15199. {
  15200. $ca = array('butt' => 0, 'round' => 1, 'square' => 2);
  15201. if (isset($ca[$cap]))
  15202. {
  15203. $this->linestyleCap = $ca[$cap] . ' J';
  15204. $s .= $this->linestyleCap . ' ';
  15205. }
  15206. }
  15207. if (isset($join))
  15208. {
  15209. $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
  15210. if (isset($ja[$join]))
  15211. {
  15212. $this->linestyleJoin = $ja[$join] . ' j';
  15213. $s .= $this->linestyleJoin . ' ';
  15214. }
  15215. }
  15216. if (isset($dash))
  15217. {
  15218. $dash_string = '';
  15219. if ($dash)
  15220. {
  15221. if (preg_match('/^.+,/', $dash) > 0)
  15222. {
  15223. $tab = explode(',', $dash);
  15224. }
  15225. else
  15226. {
  15227. $tab = array($dash);
  15228. }
  15229. $dash_string = '';
  15230. foreach ($tab as $i => $v)
  15231. {
  15232. if ($i)
  15233. {
  15234. $dash_string .= ' ';
  15235. }
  15236. $dash_string .= sprintf('%.2F', $v);
  15237. }
  15238. }
  15239. if (! isset($phase) or ! $dash)
  15240. {
  15241. $phase = 0;
  15242. }
  15243. $this->linestyleDash = sprintf('[%s] %.2F d', $dash_string, $phase);
  15244. $s .= $this->linestyleDash . ' ';
  15245. }
  15246. if (isset($color))
  15247. {
  15248. $s .= $this->SetDrawColorArray($color, true) . ' ';
  15249. }
  15250. if (! $ret)
  15251. {
  15252. $this->_out($s);
  15253. }
  15254. return $s;
  15255. }
  15256. /**
  15257. * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
  15258. * @param float $x Abscissa of point.
  15259. * @param float $y Ordinate of point.
  15260. * @access protected
  15261. * @since 2.1.000 (2008-01-08)
  15262. */
  15263. protected function _outPoint($x, $y)
  15264. {
  15265. $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k));
  15266. }
  15267. /**
  15268. * Append a straight line segment from the current point to the point (x, y).
  15269. * The new current point shall be (x, y).
  15270. * @param float $x Abscissa of end point.
  15271. * @param float $y Ordinate of end point.
  15272. * @access protected
  15273. * @since 2.1.000 (2008-01-08)
  15274. */
  15275. protected function _outLine($x, $y)
  15276. {
  15277. $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k));
  15278. }
  15279. /**
  15280. * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
  15281. * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  15282. * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  15283. * @param float $w Width.
  15284. * @param float $h Height.
  15285. * @param string $op options
  15286. * @access protected
  15287. * @since 2.1.000 (2008-01-08)
  15288. */
  15289. protected function _outRect($x, $y, $w, $h, $op)
  15290. {
  15291. $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, - $h * $this->k, $op));
  15292. }
  15293. /**
  15294. * Append a cubic B�zier 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�zier control points.
  15295. * The new current point shall be (x3, y3).
  15296. * @param float $x1 Abscissa of control point 1.
  15297. * @param float $y1 Ordinate of control point 1.
  15298. * @param float $x2 Abscissa of control point 2.
  15299. * @param float $y2 Ordinate of control point 2.
  15300. * @param float $x3 Abscissa of end point.
  15301. * @param float $y3 Ordinate of end point.
  15302. * @access protected
  15303. * @since 2.1.000 (2008-01-08)
  15304. */
  15305. protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3)
  15306. {
  15307. $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  15308. }
  15309. /**
  15310. * Append a cubic B�zier 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�zier control points.
  15311. * The new current point shall be (x3, y3).
  15312. * @param float $x2 Abscissa of control point 2.
  15313. * @param float $y2 Ordinate of control point 2.
  15314. * @param float $x3 Abscissa of end point.
  15315. * @param float $y3 Ordinate of end point.
  15316. * @access protected
  15317. * @since 4.9.019 (2010-04-26)
  15318. */
  15319. protected function _outCurveV($x2, $y2, $x3, $y3)
  15320. {
  15321. $this->_out(sprintf('%.2F %.2F %.2F %.2F v', $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  15322. }
  15323. /**
  15324. * Append a cubic B�zier 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�zier control points.
  15325. * The new current point shall be (x3, y3).
  15326. * @param float $x1 Abscissa of control point 1.
  15327. * @param float $y1 Ordinate of control point 1.
  15328. * @param float $x2 Abscissa of control point 2.
  15329. * @param float $y2 Ordinate of control point 2.
  15330. * @param float $x3 Abscissa of end point.
  15331. * @param float $y3 Ordinate of end point.
  15332. * @access protected
  15333. * @since 2.1.000 (2008-01-08)
  15334. */
  15335. protected function _outCurveY($x1, $y1, $x3, $y3)
  15336. {
  15337. $this->_out(sprintf('%.2F %.2F %.2F %.2F y', $x1 * $this->k, ($this->h - $y1) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
  15338. }
  15339. /**
  15340. * Draws a line between two points.
  15341. * @param float $x1 Abscissa of first point.
  15342. * @param float $y1 Ordinate of first point.
  15343. * @param float $x2 Abscissa of second point.
  15344. * @param float $y2 Ordinate of second point.
  15345. * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15346. * @access public
  15347. * @since 1.0
  15348. * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
  15349. */
  15350. public function Line($x1, $y1, $x2, $y2, $style = array())
  15351. {
  15352. if (is_array($style))
  15353. {
  15354. $this->SetLineStyle($style);
  15355. }
  15356. $this->_outPoint($x1, $y1);
  15357. $this->_outLine($x2, $y2);
  15358. $this->_out('S');
  15359. }
  15360. /**
  15361. * Draws a rectangle.
  15362. * @param float $x Abscissa of upper-left corner (or upper-right corner for RTL language).
  15363. * @param float $y Ordinate of upper-left corner (or upper-right corner for RTL language).
  15364. * @param float $w Width.
  15365. * @param float $h Height.
  15366. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15367. * @param array $border_style Border style of rectangle. Array with keys among the following:
  15368. * <ul>
  15369. * <li>all: Line style of all borders. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15370. * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15371. * </ul>
  15372. * If a key is not present or is null, not draws the border. Default value: default line style (empty array).
  15373. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15374. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15375. * @access public
  15376. * @since 1.0
  15377. * @see SetLineStyle()
  15378. */
  15379. public function Rect($x, $y, $w, $h, $style = '', $border_style = array(), $fill_color = array())
  15380. {
  15381. if (! (false === strpos($style, 'F')) and ! empty($fill_color))
  15382. {
  15383. $this->SetFillColorArray($fill_color);
  15384. }
  15385. $op = $this->getPathPaintOperator($style);
  15386. if ((! $border_style) or (isset($border_style['all'])))
  15387. {
  15388. if (isset($border_style['all']) and $border_style['all'])
  15389. {
  15390. $this->SetLineStyle($border_style['all']);
  15391. $border_style = array();
  15392. }
  15393. }
  15394. $this->_outRect($x, $y, $w, $h, $op);
  15395. if ($border_style)
  15396. {
  15397. $border_style2 = array();
  15398. foreach ($border_style as $line => $value)
  15399. {
  15400. $length = strlen($line);
  15401. for($i = 0; $i < $length; ++ $i)
  15402. {
  15403. $border_style2[$line[$i]] = $value;
  15404. }
  15405. }
  15406. $border_style = $border_style2;
  15407. if (isset($border_style['L']) and $border_style['L'])
  15408. {
  15409. $this->Line($x, $y, $x, $y + $h, $border_style['L']);
  15410. }
  15411. if (isset($border_style['T']) and $border_style['T'])
  15412. {
  15413. $this->Line($x, $y, $x + $w, $y, $border_style['T']);
  15414. }
  15415. if (isset($border_style['R']) and $border_style['R'])
  15416. {
  15417. $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']);
  15418. }
  15419. if (isset($border_style['B']) and $border_style['B'])
  15420. {
  15421. $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']);
  15422. }
  15423. }
  15424. }
  15425. /**
  15426. * Draws a Bezier curve.
  15427. * The Bezier curve is a tangent to the line between the control points at
  15428. * either end of the curve.
  15429. * @param float $x0 Abscissa of start point.
  15430. * @param float $y0 Ordinate of start point.
  15431. * @param float $x1 Abscissa of control point 1.
  15432. * @param float $y1 Ordinate of control point 1.
  15433. * @param float $x2 Abscissa of control point 2.
  15434. * @param float $y2 Ordinate of control point 2.
  15435. * @param float $x3 Abscissa of end point.
  15436. * @param float $y3 Ordinate of end point.
  15437. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15438. * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15439. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15440. * @access public
  15441. * @see SetLineStyle()
  15442. * @since 2.1.000 (2008-01-08)
  15443. */
  15444. public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style = '', $line_style = array(), $fill_color = array())
  15445. {
  15446. if (! (false === strpos($style, 'F')) and isset($fill_color))
  15447. {
  15448. $this->SetFillColorArray($fill_color);
  15449. }
  15450. $op = $this->getPathPaintOperator($style);
  15451. if ($line_style)
  15452. {
  15453. $this->SetLineStyle($line_style);
  15454. }
  15455. $this->_outPoint($x0, $y0);
  15456. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  15457. $this->_out($op);
  15458. }
  15459. /**
  15460. * Draws a poly-Bezier curve.
  15461. * Each Bezier curve segment is a tangent to the line between the control points at
  15462. * either end of the curve.
  15463. * @param float $x0 Abscissa of start point.
  15464. * @param float $y0 Ordinate of start point.
  15465. * @param float $segments An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
  15466. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15467. * @param array $line_style Line style of curve. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15468. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15469. * @access public
  15470. * @see SetLineStyle()
  15471. * @since 3.0008 (2008-05-12)
  15472. */
  15473. public function Polycurve($x0, $y0, $segments, $style = '', $line_style = array(), $fill_color = array())
  15474. {
  15475. if (! (false === strpos($style, 'F')) and isset($fill_color))
  15476. {
  15477. $this->SetFillColorArray($fill_color);
  15478. }
  15479. $op = $this->getPathPaintOperator($style);
  15480. if ($op == 'f')
  15481. {
  15482. $line_style = array();
  15483. }
  15484. if ($line_style)
  15485. {
  15486. $this->SetLineStyle($line_style);
  15487. }
  15488. $this->_outPoint($x0, $y0);
  15489. foreach ($segments as $segment)
  15490. {
  15491. list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
  15492. $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
  15493. }
  15494. $this->_out($op);
  15495. }
  15496. /**
  15497. * Draws an ellipse.
  15498. * An ellipse is formed from n Bezier curves.
  15499. * @param float $x0 Abscissa of center point.
  15500. * @param float $y0 Ordinate of center point.
  15501. * @param float $rx Horizontal radius.
  15502. * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  15503. * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  15504. * @param float $astart: Angle start of draw line. Default value: 0.
  15505. * @param float $afinish: Angle finish of draw line. Default value: 360.
  15506. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15507. * @param array $line_style Line style of ellipse. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15508. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15509. * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  15510. * @author Nicola Asuni
  15511. * @access public
  15512. * @since 2.1.000 (2008-01-08)
  15513. */
  15514. public function Ellipse($x0, $y0, $rx, $ry = '', $angle = 0, $astart = 0, $afinish = 360, $style = '', $line_style = array(), $fill_color = array(), $nc = 2)
  15515. {
  15516. if ($this->empty_string($ry) or ($ry == 0))
  15517. {
  15518. $ry = $rx;
  15519. }
  15520. if (! (false === strpos($style, 'F')) and isset($fill_color))
  15521. {
  15522. $this->SetFillColorArray($fill_color);
  15523. }
  15524. $op = $this->getPathPaintOperator($style);
  15525. if ($op == 'f')
  15526. {
  15527. $line_style = array();
  15528. }
  15529. if ($line_style)
  15530. {
  15531. $this->SetLineStyle($line_style);
  15532. }
  15533. $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc);
  15534. $this->_out($op);
  15535. }
  15536. /**
  15537. * Append an elliptical arc to the current path.
  15538. * An ellipse is formed from n Bezier curves.
  15539. * @param float $xc Abscissa of center point.
  15540. * @param float $yc Ordinate of center point.
  15541. * @param float $rx Horizontal radius.
  15542. * @param float $ry Vertical radius (if ry = 0 then is a circle, see {@link Circle Circle}). Default value: 0.
  15543. * @param float $xang: Angle between the X-axis and the major axis of the ellipse. Default value: 0.
  15544. * @param float $angs: Angle start of draw line. Default value: 0.
  15545. * @param float $angf: Angle finish of draw line. Default value: 360.
  15546. * @param boolean $pie if true do not mark the border point (used to draw pie sectors).
  15547. * @param integer $nc Number of curves used to draw a 90 degrees portion of ellipse.
  15548. * @author Nicola Asuni
  15549. * @access protected
  15550. * @since 4.9.019 (2010-04-26)
  15551. */
  15552. protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang = 0, $angs = 0, $angf = 360, $pie = false, $nc = 2)
  15553. {
  15554. $k = $this->k;
  15555. if ($nc < 2)
  15556. {
  15557. $nc = 2;
  15558. }
  15559. if ($pie)
  15560. {
  15561. // center of the arc
  15562. $this->_outPoint($xc, $yc);
  15563. }
  15564. $xang = deg2rad((float) $xang);
  15565. $angs = deg2rad((float) $angs);
  15566. $angf = deg2rad((float) $angf);
  15567. $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
  15568. $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
  15569. if ($as < 0)
  15570. {
  15571. $as += (2 * M_PI);
  15572. }
  15573. if ($af < 0)
  15574. {
  15575. $af += (2 * M_PI);
  15576. }
  15577. if ($as > $af)
  15578. {
  15579. // reverse rotation go clockwise
  15580. $as -= (2 * M_PI);
  15581. }
  15582. $total_angle = ($af - $as);
  15583. if ($nc < 2)
  15584. {
  15585. $nc = 2;
  15586. }
  15587. // total arcs to draw
  15588. $nc *= (2 * abs($total_angle) / M_PI);
  15589. $nc = round($nc) + 1;
  15590. // angle of each arc
  15591. $arcang = $total_angle / $nc;
  15592. // center point in PDF coordiantes
  15593. $x0 = $xc;
  15594. $y0 = ($this->h - $yc);
  15595. // starting angle
  15596. $ang = $as;
  15597. $alpha = sin($arcang) * ((sqrt(4 + (3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
  15598. $cos_xang = cos($xang);
  15599. $sin_xang = sin($xang);
  15600. $cos_ang = cos($ang);
  15601. $sin_ang = sin($ang);
  15602. // first arc point
  15603. $px1 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  15604. $py1 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  15605. // first Bezier control point
  15606. $qx1 = ($alpha * ((- $rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  15607. $qy1 = ($alpha * ((- $rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  15608. if ($pie)
  15609. {
  15610. $this->_outLine($px1, $this->h - $py1);
  15611. }
  15612. else
  15613. {
  15614. $this->_outPoint($px1, $this->h - $py1);
  15615. }
  15616. // draw arcs
  15617. for($i = 1; $i <= $nc; ++ $i)
  15618. {
  15619. // starting angle
  15620. $ang = $as + ($i * $arcang);
  15621. $cos_xang = cos($xang);
  15622. $sin_xang = sin($xang);
  15623. $cos_ang = cos($ang);
  15624. $sin_ang = sin($ang);
  15625. // second arc point
  15626. $px2 = $x0 + ($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
  15627. $py2 = $y0 + ($rx * $sin_xang * $cos_ang) + ($ry * $cos_xang * $sin_ang);
  15628. // second Bezier control point
  15629. $qx2 = ($alpha * ((- $rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
  15630. $qy2 = ($alpha * ((- $rx * $sin_xang * $sin_ang) + ($ry * $cos_xang * $cos_ang)));
  15631. // draw arc
  15632. $this->_outCurve(($px1 + $qx1), ($this->h - ($py1 + $qy1)), ($px2 - $qx2), ($this->h - ($py2 - $qy2)), $px2, ($this->h - $py2));
  15633. // move to next point
  15634. $px1 = $px2;
  15635. $py1 = $py2;
  15636. $qx1 = $qx2;
  15637. $qy1 = $qy2;
  15638. }
  15639. if ($pie)
  15640. {
  15641. $this->_outLine($xc, $yc);
  15642. }
  15643. }
  15644. /**
  15645. * Draws a circle.
  15646. * A circle is formed from n Bezier curves.
  15647. * @param float $x0 Abscissa of center point.
  15648. * @param float $y0 Ordinate of center point.
  15649. * @param float $r Radius.
  15650. * @param float $angstr: Angle start of draw line. Default value: 0.
  15651. * @param float $angend: Angle finish of draw line. Default value: 360.
  15652. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15653. * @param array $line_style Line style of circle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15654. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  15655. * @param integer $nc Number of curves used to draw a 90 degrees portion of circle.
  15656. * @access public
  15657. * @since 2.1.000 (2008-01-08)
  15658. */
  15659. public function Circle($x0, $y0, $r, $angstr = 0, $angend = 360, $style = '', $line_style = array(), $fill_color = array(), $nc = 2)
  15660. {
  15661. $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
  15662. }
  15663. /**
  15664. * Draws a polygonal line
  15665. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  15666. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15667. * @param array $line_style Line style of polygon. Array with keys among the following:
  15668. * <ul>
  15669. * <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15670. * <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15671. * </ul>
  15672. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  15673. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15674. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  15675. * @access public
  15676. * @since 4.8.003 (2009-09-15)
  15677. */
  15678. public function PolyLine($p, $style = '', $line_style = array(), $fill_color = array())
  15679. {
  15680. $this->Polygon($p, $style, $line_style, $fill_color, false);
  15681. }
  15682. /**
  15683. * Draws a polygon.
  15684. * @param array $p Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
  15685. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15686. * @param array $line_style Line style of polygon. Array with keys among the following:
  15687. * <ul>
  15688. * <li>all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15689. * <li>0 to ($np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15690. * </ul>
  15691. * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
  15692. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15693. * @param boolean $closed if true the polygon is closes, otherwise will remain open
  15694. * @access public
  15695. * @since 2.1.000 (2008-01-08)
  15696. */
  15697. public function Polygon($p, $style = '', $line_style = array(), $fill_color = array(), $closed = true)
  15698. {
  15699. $nc = count($p); // number of coordinates
  15700. $np = $nc / 2; // number of points
  15701. if ($closed)
  15702. {
  15703. // close polygon by adding the first 2 points at the end (one line)
  15704. for($i = 0; $i < 4; ++ $i)
  15705. {
  15706. $p[$nc + $i] = $p[$i];
  15707. }
  15708. // copy style for the last added line
  15709. if (isset($line_style[0]))
  15710. {
  15711. $line_style[$np] = $line_style[0];
  15712. }
  15713. $nc += 4;
  15714. }
  15715. if (! (false === strpos($style, 'F')) and isset($fill_color))
  15716. {
  15717. $this->SetFillColorArray($fill_color);
  15718. }
  15719. $op = $this->getPathPaintOperator($style);
  15720. if ($op == 'f')
  15721. {
  15722. $line_style = array();
  15723. }
  15724. $draw = true;
  15725. if ($line_style)
  15726. {
  15727. if (isset($line_style['all']))
  15728. {
  15729. $this->SetLineStyle($line_style['all']);
  15730. }
  15731. else
  15732. {
  15733. $draw = false;
  15734. if ($op == 'B')
  15735. {
  15736. // draw fill
  15737. $op = 'f';
  15738. $this->_outPoint($p[0], $p[1]);
  15739. for($i = 2; $i < $nc; $i = $i + 2)
  15740. {
  15741. $this->_outLine($p[$i], $p[$i + 1]);
  15742. }
  15743. $this->_out($op);
  15744. }
  15745. // draw outline
  15746. $this->_outPoint($p[0], $p[1]);
  15747. for($i = 2; $i < $nc; $i = $i + 2)
  15748. {
  15749. $line_num = ($i / 2) - 1;
  15750. if (isset($line_style[$line_num]))
  15751. {
  15752. if ($line_style[$line_num] != 0)
  15753. {
  15754. if (is_array($line_style[$line_num]))
  15755. {
  15756. $this->_out('S');
  15757. $this->SetLineStyle($line_style[$line_num]);
  15758. $this->_outPoint($p[$i - 2], $p[$i - 1]);
  15759. $this->_outLine($p[$i], $p[$i + 1]);
  15760. $this->_out('S');
  15761. $this->_outPoint($p[$i], $p[$i + 1]);
  15762. }
  15763. else
  15764. {
  15765. $this->_outLine($p[$i], $p[$i + 1]);
  15766. }
  15767. }
  15768. }
  15769. else
  15770. {
  15771. $this->_outLine($p[$i], $p[$i + 1]);
  15772. }
  15773. }
  15774. $this->_out($op);
  15775. }
  15776. }
  15777. if ($draw)
  15778. {
  15779. $this->_outPoint($p[0], $p[1]);
  15780. for($i = 2; $i < $nc; $i = $i + 2)
  15781. {
  15782. $this->_outLine($p[$i], $p[$i + 1]);
  15783. }
  15784. $this->_out($op);
  15785. }
  15786. }
  15787. /**
  15788. * Draws a regular polygon.
  15789. * @param float $x0 Abscissa of center point.
  15790. * @param float $y0 Ordinate of center point.
  15791. * @param float $r: Radius of inscribed circle.
  15792. * @param integer $ns Number of sides.
  15793. * @param float $angle Angle oriented (anti-clockwise). Default value: 0.
  15794. * @param boolean $draw_circle Draw inscribed circle or not. Default value: false.
  15795. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15796. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  15797. * <ul>
  15798. * <li>all: Line style of all sides. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15799. * <li>0 to ($ns - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15800. * </ul>
  15801. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  15802. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  15803. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  15804. * <ul>
  15805. * <li>D or empty string: Draw (default).</li>
  15806. * <li>F: Fill.</li>
  15807. * <li>DF or FD: Draw and fill.</li>
  15808. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  15809. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  15810. * </ul>
  15811. * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15812. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  15813. * @access public
  15814. * @since 2.1.000 (2008-01-08)
  15815. */
  15816. 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())
  15817. {
  15818. if (3 > $ns)
  15819. {
  15820. $ns = 3;
  15821. }
  15822. if ($draw_circle)
  15823. {
  15824. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  15825. }
  15826. $p = array();
  15827. for($i = 0; $i < $ns; ++ $i)
  15828. {
  15829. $a = $angle + ($i * 360 / $ns);
  15830. $a_rad = deg2rad((float) $a);
  15831. $p[] = $x0 + ($r * sin($a_rad));
  15832. $p[] = $y0 + ($r * cos($a_rad));
  15833. }
  15834. $this->Polygon($p, $style, $line_style, $fill_color);
  15835. }
  15836. /**
  15837. * Draws a star polygon
  15838. * @param float $x0 Abscissa of center point.
  15839. * @param float $y0 Ordinate of center point.
  15840. * @param float $r Radius of inscribed circle.
  15841. * @param integer $nv Number of vertices.
  15842. * @param integer $ng Number of gap (if ($ng % $nv = 1) then is a regular polygon).
  15843. * @param float $angle: Angle oriented (anti-clockwise). Default value: 0.
  15844. * @param boolean $draw_circle: Draw inscribed circle or not. Default value is false.
  15845. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15846. * @param array $line_style Line style of polygon sides. Array with keys among the following:
  15847. * <ul>
  15848. * <li>all: Line style of all sides. Array like for
  15849. * {@link SetLineStyle SetLineStyle}.</li>
  15850. * <li>0 to (n - 1): Line style of each side. Array like for {@link SetLineStyle SetLineStyle}.</li>
  15851. * </ul>
  15852. * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
  15853. * @param array $fill_color Fill color. Format: array(red, green, blue). Default value: default color (empty array).
  15854. * @param string $circle_style Style of rendering of inscribed circle (if draws). Possible values are:
  15855. * <ul>
  15856. * <li>D or empty string: Draw (default).</li>
  15857. * <li>F: Fill.</li>
  15858. * <li>DF or FD: Draw and fill.</li>
  15859. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  15860. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  15861. * </ul>
  15862. * @param array $circle_outLine_style Line style of inscribed circle (if draws). Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15863. * @param array $circle_fill_color Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
  15864. * @access public
  15865. * @since 2.1.000 (2008-01-08)
  15866. */
  15867. 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())
  15868. {
  15869. if ($nv < 2)
  15870. {
  15871. $nv = 2;
  15872. }
  15873. if ($draw_circle)
  15874. {
  15875. $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
  15876. }
  15877. $p2 = array();
  15878. $visited = array();
  15879. for($i = 0; $i < $nv; ++ $i)
  15880. {
  15881. $a = $angle + ($i * 360 / $nv);
  15882. $a_rad = deg2rad((float) $a);
  15883. $p2[] = $x0 + ($r * sin($a_rad));
  15884. $p2[] = $y0 + ($r * cos($a_rad));
  15885. $visited[] = false;
  15886. }
  15887. $p = array();
  15888. $i = 0;
  15889. do
  15890. {
  15891. $p[] = $p2[$i * 2];
  15892. $p[] = $p2[($i * 2) + 1];
  15893. $visited[$i] = true;
  15894. $i += $ng;
  15895. $i %= $nv;
  15896. }
  15897. while (! $visited[$i]);
  15898. $this->Polygon($p, $style, $line_style, $fill_color);
  15899. }
  15900. /**
  15901. * Draws a rounded rectangle.
  15902. * @param float $x Abscissa of upper-left corner.
  15903. * @param float $y Ordinate of upper-left corner.
  15904. * @param float $w Width.
  15905. * @param float $h Height.
  15906. * @param float $r the radius of the circle used to round off the corners of the rectangle.
  15907. * @param string $round_corner Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
  15908. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15909. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15910. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15911. * @access public
  15912. * @since 2.1.000 (2008-01-08)
  15913. */
  15914. public function RoundedRect($x, $y, $w, $h, $r, $round_corner = '1111', $style = '', $border_style = array(), $fill_color = array())
  15915. {
  15916. $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
  15917. }
  15918. /**
  15919. * Draws a rounded rectangle.
  15920. * @param float $x Abscissa of upper-left corner.
  15921. * @param float $y Ordinate of upper-left corner.
  15922. * @param float $w Width.
  15923. * @param float $h Height.
  15924. * @param float $rx the x-axis radius of the ellipse used to round off the corners of the rectangle.
  15925. * @param float $ry the y-axis radius of the ellipse used to round off the corners of the rectangle.
  15926. * @param string $round_corner Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
  15927. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  15928. * @param array $border_style Border style of rectangle. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
  15929. * @param array $fill_color Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
  15930. * @access public
  15931. * @since 4.9.019 (2010-04-22)
  15932. */
  15933. public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner = '1111', $style = '', $border_style = array(), $fill_color = array())
  15934. {
  15935. if (($round_corner == '0000') or (($rx == $ry) and ($rx == 0)))
  15936. {
  15937. // Not rounded
  15938. $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
  15939. return;
  15940. }
  15941. // Rounded
  15942. if (! (false === strpos($style, 'F')) and isset($fill_color))
  15943. {
  15944. $this->SetFillColorArray($fill_color);
  15945. }
  15946. $op = $this->getPathPaintOperator($style);
  15947. if ($op == 'f')
  15948. {
  15949. $border_style = array();
  15950. }
  15951. if ($border_style)
  15952. {
  15953. $this->SetLineStyle($border_style);
  15954. }
  15955. $MyArc = 4 / 3 * (sqrt(2) - 1);
  15956. $this->_outPoint($x + $rx, $y);
  15957. $xc = $x + $w - $rx;
  15958. $yc = $y + $ry;
  15959. $this->_outLine($xc, $y);
  15960. if ($round_corner[0])
  15961. {
  15962. $this->_outCurve($xc + ($rx * $MyArc), $yc - $ry, $xc + $rx, $yc - ($ry * $MyArc), $xc + $rx, $yc);
  15963. }
  15964. else
  15965. {
  15966. $this->_outLine($x + $w, $y);
  15967. }
  15968. $xc = $x + $w - $rx;
  15969. $yc = $y + $h - $ry;
  15970. $this->_outLine($x + $w, $yc);
  15971. if ($round_corner[1])
  15972. {
  15973. $this->_outCurve($xc + $rx, $yc + ($ry * $MyArc), $xc + ($rx * $MyArc), $yc + $ry, $xc, $yc + $ry);
  15974. }
  15975. else
  15976. {
  15977. $this->_outLine($x + $w, $y + $h);
  15978. }
  15979. $xc = $x + $rx;
  15980. $yc = $y + $h - $ry;
  15981. $this->_outLine($xc, $y + $h);
  15982. if ($round_corner[2])
  15983. {
  15984. $this->_outCurve($xc - ($rx * $MyArc), $yc + $ry, $xc - $rx, $yc + ($ry * $MyArc), $xc - $rx, $yc);
  15985. }
  15986. else
  15987. {
  15988. $this->_outLine($x, $y + $h);
  15989. }
  15990. $xc = $x + $rx;
  15991. $yc = $y + $ry;
  15992. $this->_outLine($x, $yc);
  15993. if ($round_corner[3])
  15994. {
  15995. $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
  15996. }
  15997. else
  15998. {
  15999. $this->_outLine($x, $y);
  16000. $this->_outLine($x + $rx, $y);
  16001. }
  16002. $this->_out($op);
  16003. }
  16004. /**
  16005. * Draws a grahic arrow.
  16006. * @param float $x0 Abscissa of first point.
  16007. * @param float $y0 Ordinate of first point.
  16008. * @param float $x0 Abscissa of second point.
  16009. * @param float $y1 Ordinate of second point.
  16010. * @param int $head_style (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
  16011. * @param float $arm_size length of arrowhead arms
  16012. * @param int $arm_angle angle between an arm and the shaft
  16013. * @author Piotr Galecki, Nicola Asuni, Andy Meier
  16014. * @since 4.6.018 (2009-07-10)
  16015. */
  16016. public function Arrow($x0, $y0, $x1, $y1, $head_style = 0, $arm_size = 5, $arm_angle = 15)
  16017. {
  16018. // getting arrow direction angle
  16019. // 0 deg angle is when both arms go along X axis. angle grows clockwise.
  16020. $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
  16021. if ($dir_angle < 0)
  16022. {
  16023. $dir_angle += (2 * M_PI);
  16024. }
  16025. $arm_angle = deg2rad($arm_angle);
  16026. $sx1 = $x1;
  16027. $sy1 = $y1;
  16028. if ($head_style > 0)
  16029. {
  16030. // calculate the stopping point for the arrow shaft
  16031. $sx1 = $x1 + (($arm_size - $this->LineWidth) * cos($dir_angle));
  16032. $sy1 = $y1 + (($arm_size - $this->LineWidth) * sin($dir_angle));
  16033. }
  16034. // main arrow line / shaft
  16035. $this->Line($x0, $y0, $sx1, $sy1);
  16036. // left arrowhead arm tip
  16037. $x2L = $x1 + ($arm_size * cos($dir_angle + $arm_angle));
  16038. $y2L = $y1 + ($arm_size * sin($dir_angle + $arm_angle));
  16039. // right arrowhead arm tip
  16040. $x2R = $x1 + ($arm_size * cos($dir_angle - $arm_angle));
  16041. $y2R = $y1 + ($arm_size * sin($dir_angle - $arm_angle));
  16042. $mode = 'D';
  16043. $style = array();
  16044. switch ($head_style)
  16045. {
  16046. case 0 :
  16047. {
  16048. // draw only arrowhead arms
  16049. $mode = 'D';
  16050. $style = array(1, 1, 0);
  16051. break;
  16052. }
  16053. case 1 :
  16054. {
  16055. // draw closed arrowhead, but no fill
  16056. $mode = 'D';
  16057. break;
  16058. }
  16059. case 2 :
  16060. {
  16061. // closed and filled arrowhead
  16062. $mode = 'DF';
  16063. break;
  16064. }
  16065. case 3 :
  16066. {
  16067. // filled arrowhead
  16068. $mode = 'F';
  16069. break;
  16070. }
  16071. }
  16072. $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
  16073. }
  16074. // END GRAPHIC FUNCTIONS SECTION -----------------------
  16075. // BIDIRECTIONAL TEXT SECTION --------------------------
  16076. /**
  16077. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  16078. * @param string $str string to manipulate.
  16079. * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  16080. * @param bool $forcertl if true forces RTL text direction
  16081. * @return string
  16082. * @access protected
  16083. * @author Nicola Asuni
  16084. * @since 2.1.000 (2008-01-08)
  16085. */
  16086. protected function utf8StrRev($str, $setbom = false, $forcertl = false)
  16087. {
  16088. return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl);
  16089. }
  16090. /**
  16091. * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  16092. * @param array $arr array of unicode values.
  16093. * @param string $str string to manipulate (or empty value).
  16094. * @param bool $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  16095. * @param bool $forcertl if true forces RTL text direction
  16096. * @return string
  16097. * @access protected
  16098. * @author Nicola Asuni
  16099. * @since 4.9.000 (2010-03-27)
  16100. */
  16101. protected function utf8StrArrRev($arr, $str = '', $setbom = false, $forcertl = false)
  16102. {
  16103. return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom);
  16104. }
  16105. /**
  16106. * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
  16107. * @param array $ta array of characters composing the string.
  16108. * @param string $str string to process
  16109. * @param bool $forcertl if 'R' forces RTL, if 'L' forces LTR
  16110. * @return array of unicode chars
  16111. * @author Nicola Asuni
  16112. * @access protected
  16113. * @since 2.4.000 (2008-03-06)
  16114. */
  16115. protected function utf8Bidi($ta, $str = '', $forcertl = false)
  16116. {
  16117. // paragraph embedding level
  16118. $pel = 0;
  16119. // max level
  16120. $maxlevel = 0;
  16121. if ($this->empty_string($str))
  16122. {
  16123. // create string from array
  16124. $str = $this->UTF8ArrSubString($ta);
  16125. }
  16126. // check if string contains arabic text
  16127. if (preg_match($this->unicode->uni_RE_PATTERN_ARABIC, $str))
  16128. {
  16129. $arabic = true;
  16130. }
  16131. else
  16132. {
  16133. $arabic = false;
  16134. }
  16135. // check if string contains RTL text
  16136. if (! ($forcertl or $arabic or preg_match($this->unicode->uni_RE_PATTERN_RTL, $str)))
  16137. {
  16138. return $ta;
  16139. }
  16140. // get number of chars
  16141. $numchars = count($ta);
  16142. if ($forcertl == 'R')
  16143. {
  16144. $pel = 1;
  16145. }
  16146. elseif ($forcertl == 'L')
  16147. {
  16148. $pel = 0;
  16149. }
  16150. else
  16151. {
  16152. // P2. In each paragraph, find the first character of type L, AL, or R.
  16153. // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
  16154. for($i = 0; $i < $numchars; ++ $i)
  16155. {
  16156. $type = $this->unicode->uni_type[$ta[$i]];
  16157. if ($type == 'L')
  16158. {
  16159. $pel = 0;
  16160. break;
  16161. }
  16162. elseif (($type == 'AL') or ($type == 'R'))
  16163. {
  16164. $pel = 1;
  16165. break;
  16166. }
  16167. }
  16168. }
  16169. // Current Embedding Level
  16170. $cel = $pel;
  16171. // directional override status
  16172. $dos = 'N';
  16173. $remember = array();
  16174. // start-of-level-run
  16175. $sor = $pel % 2 ? 'R' : 'L';
  16176. $eor = $sor;
  16177. // Array of characters data
  16178. $chardata = Array();
  16179. // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
  16180. // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
  16181. for($i = 0; $i < $numchars; ++ $i)
  16182. {
  16183. if ($ta[$i] == $this->unicode->uni_RLE)
  16184. {
  16185. // X2. With each RLE, compute the least greater odd embedding level.
  16186. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  16187. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  16188. $next_level = $cel + ($cel % 2) + 1;
  16189. if ($next_level < 62)
  16190. {
  16191. $remember[] = array('num' => $this->unicode->uni_RLE, 'cel' => $cel, 'dos' => $dos);
  16192. $cel = $next_level;
  16193. $dos = 'N';
  16194. $sor = $eor;
  16195. $eor = $cel % 2 ? 'R' : 'L';
  16196. }
  16197. }
  16198. elseif ($ta[$i] == $this->unicode->uni_LRE)
  16199. {
  16200. // X3. With each LRE, compute the least greater even embedding level.
  16201. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
  16202. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  16203. $next_level = $cel + 2 - ($cel % 2);
  16204. if ($next_level < 62)
  16205. {
  16206. $remember[] = array('num' => $this->unicode->uni_LRE, 'cel' => $cel, 'dos' => $dos);
  16207. $cel = $next_level;
  16208. $dos = 'N';
  16209. $sor = $eor;
  16210. $eor = $cel % 2 ? 'R' : 'L';
  16211. }
  16212. }
  16213. elseif ($ta[$i] == $this->unicode->uni_RLO)
  16214. {
  16215. // X4. With each RLO, compute the least greater odd embedding level.
  16216. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
  16217. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  16218. $next_level = $cel + ($cel % 2) + 1;
  16219. if ($next_level < 62)
  16220. {
  16221. $remember[] = array('num' => $this->unicode->uni_RLO, 'cel' => $cel, 'dos' => $dos);
  16222. $cel = $next_level;
  16223. $dos = 'R';
  16224. $sor = $eor;
  16225. $eor = $cel % 2 ? 'R' : 'L';
  16226. }
  16227. }
  16228. elseif ($ta[$i] == $this->unicode->uni_LRO)
  16229. {
  16230. // X5. With each LRO, compute the least greater even embedding level.
  16231. // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
  16232. // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
  16233. $next_level = $cel + 2 - ($cel % 2);
  16234. if ($next_level < 62)
  16235. {
  16236. $remember[] = array('num' => $this->unicode->uni_LRO, 'cel' => $cel, 'dos' => $dos);
  16237. $cel = $next_level;
  16238. $dos = 'L';
  16239. $sor = $eor;
  16240. $eor = $cel % 2 ? 'R' : 'L';
  16241. }
  16242. }
  16243. elseif ($ta[$i] == $this->unicode->uni_PDF)
  16244. {
  16245. // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
  16246. if (count($remember))
  16247. {
  16248. $last = count($remember) - 1;
  16249. if (($remember[$last]['num'] == $this->unicode->uni_RLE) or ($remember[$last]['num'] == $this->unicode->uni_LRE) or ($remember[$last]['num'] == $this->unicode->uni_RLO) or ($remember[$last]['num'] == $this->unicode->uni_LRO))
  16250. {
  16251. $match = array_pop($remember);
  16252. $cel = $match['cel'];
  16253. $dos = $match['dos'];
  16254. $sor = $eor;
  16255. $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
  16256. }
  16257. }
  16258. }
  16259. elseif (($ta[$i] != $this->unicode->uni_RLE) and ($ta[$i] != $this->unicode->uni_LRE) and ($ta[$i] != $this->unicode->uni_RLO) and ($ta[$i] != $this->unicode->uni_LRO) and ($ta[$i] != $this->unicode->uni_PDF))
  16260. {
  16261. // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
  16262. // a. Set the level of the current character to the current embedding level.
  16263. // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
  16264. if ($dos != 'N')
  16265. {
  16266. $chardir = $dos;
  16267. }
  16268. else
  16269. {
  16270. if (isset($this->unicode->uni_type[$ta[$i]]))
  16271. {
  16272. $chardir = $this->unicode->uni_type[$ta[$i]];
  16273. }
  16274. else
  16275. {
  16276. $chardir = 'L';
  16277. }
  16278. }
  16279. // stores string characters and other information
  16280. $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir,
  16281. 'sor' => $sor, 'eor' => $eor);
  16282. }
  16283. } // end for each char
  16284. // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
  16285. // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
  16286. // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
  16287. // 3.3.3 Resolving Weak Types
  16288. // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
  16289. // Nonspacing marks are now resolved based on the previous characters.
  16290. $numchars = count($chardata);
  16291. // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
  16292. $prevlevel = - 1; // track level changes
  16293. $levcount = 0; // counts consecutive chars at the same level
  16294. for($i = 0; $i < $numchars; ++ $i)
  16295. {
  16296. if ($chardata[$i]['type'] == 'NSM')
  16297. {
  16298. if ($levcount)
  16299. {
  16300. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16301. }
  16302. elseif ($i > 0)
  16303. {
  16304. $chardata[$i]['type'] = $chardata[($i - 1)]['type'];
  16305. }
  16306. }
  16307. if ($chardata[$i]['level'] != $prevlevel)
  16308. {
  16309. $levcount = 0;
  16310. }
  16311. else
  16312. {
  16313. ++ $levcount;
  16314. }
  16315. $prevlevel = $chardata[$i]['level'];
  16316. }
  16317. // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
  16318. $prevlevel = - 1;
  16319. $levcount = 0;
  16320. for($i = 0; $i < $numchars; ++ $i)
  16321. {
  16322. if ($chardata[$i]['char'] == 'EN')
  16323. {
  16324. for($j = $levcount; $j >= 0; $j --)
  16325. {
  16326. if ($chardata[$j]['type'] == 'AL')
  16327. {
  16328. $chardata[$i]['type'] = 'AN';
  16329. }
  16330. elseif (($chardata[$j]['type'] == 'L') or ($chardata[$j]['type'] == 'R'))
  16331. {
  16332. break;
  16333. }
  16334. }
  16335. }
  16336. if ($chardata[$i]['level'] != $prevlevel)
  16337. {
  16338. $levcount = 0;
  16339. }
  16340. else
  16341. {
  16342. ++ $levcount;
  16343. }
  16344. $prevlevel = $chardata[$i]['level'];
  16345. }
  16346. // W3. Change all ALs to R.
  16347. for($i = 0; $i < $numchars; ++ $i)
  16348. {
  16349. if ($chardata[$i]['type'] == 'AL')
  16350. {
  16351. $chardata[$i]['type'] = 'R';
  16352. }
  16353. }
  16354. // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
  16355. $prevlevel = - 1;
  16356. $levcount = 0;
  16357. for($i = 0; $i < $numchars; ++ $i)
  16358. {
  16359. if (($levcount > 0) and (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] == $prevlevel))
  16360. {
  16361. if (($chardata[$i]['type'] == 'ES') and ($chardata[($i - 1)]['type'] == 'EN') and ($chardata[($i + 1)]['type'] == 'EN'))
  16362. {
  16363. $chardata[$i]['type'] = 'EN';
  16364. }
  16365. elseif (($chardata[$i]['type'] == 'CS') and ($chardata[($i - 1)]['type'] == 'EN') and ($chardata[($i + 1)]['type'] == 'EN'))
  16366. {
  16367. $chardata[$i]['type'] = 'EN';
  16368. }
  16369. elseif (($chardata[$i]['type'] == 'CS') and ($chardata[($i - 1)]['type'] == 'AN') and ($chardata[($i + 1)]['type'] == 'AN'))
  16370. {
  16371. $chardata[$i]['type'] = 'AN';
  16372. }
  16373. }
  16374. if ($chardata[$i]['level'] != $prevlevel)
  16375. {
  16376. $levcount = 0;
  16377. }
  16378. else
  16379. {
  16380. ++ $levcount;
  16381. }
  16382. $prevlevel = $chardata[$i]['level'];
  16383. }
  16384. // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
  16385. $prevlevel = - 1;
  16386. $levcount = 0;
  16387. for($i = 0; $i < $numchars; ++ $i)
  16388. {
  16389. if ($chardata[$i]['type'] == 'ET')
  16390. {
  16391. if (($levcount > 0) and ($chardata[($i - 1)]['type'] == 'EN'))
  16392. {
  16393. $chardata[$i]['type'] = 'EN';
  16394. }
  16395. else
  16396. {
  16397. $j = $i + 1;
  16398. while (($j < $numchars) and ($chardata[$j]['level'] == $prevlevel))
  16399. {
  16400. if ($chardata[$j]['type'] == 'EN')
  16401. {
  16402. $chardata[$i]['type'] = 'EN';
  16403. break;
  16404. }
  16405. elseif ($chardata[$j]['type'] != 'ET')
  16406. {
  16407. break;
  16408. }
  16409. ++ $j;
  16410. }
  16411. }
  16412. }
  16413. if ($chardata[$i]['level'] != $prevlevel)
  16414. {
  16415. $levcount = 0;
  16416. }
  16417. else
  16418. {
  16419. ++ $levcount;
  16420. }
  16421. $prevlevel = $chardata[$i]['level'];
  16422. }
  16423. // W6. Otherwise, separators and terminators change to Other Neutral.
  16424. $prevlevel = - 1;
  16425. $levcount = 0;
  16426. for($i = 0; $i < $numchars; ++ $i)
  16427. {
  16428. if (($chardata[$i]['type'] == 'ET') or ($chardata[$i]['type'] == 'ES') or ($chardata[$i]['type'] == 'CS'))
  16429. {
  16430. $chardata[$i]['type'] = 'ON';
  16431. }
  16432. if ($chardata[$i]['level'] != $prevlevel)
  16433. {
  16434. $levcount = 0;
  16435. }
  16436. else
  16437. {
  16438. ++ $levcount;
  16439. }
  16440. $prevlevel = $chardata[$i]['level'];
  16441. }
  16442. //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
  16443. $prevlevel = - 1;
  16444. $levcount = 0;
  16445. for($i = 0; $i < $numchars; ++ $i)
  16446. {
  16447. if ($chardata[$i]['char'] == 'EN')
  16448. {
  16449. for($j = $levcount; $j >= 0; $j --)
  16450. {
  16451. if ($chardata[$j]['type'] == 'L')
  16452. {
  16453. $chardata[$i]['type'] = 'L';
  16454. }
  16455. elseif ($chardata[$j]['type'] == 'R')
  16456. {
  16457. break;
  16458. }
  16459. }
  16460. }
  16461. if ($chardata[$i]['level'] != $prevlevel)
  16462. {
  16463. $levcount = 0;
  16464. }
  16465. else
  16466. {
  16467. ++ $levcount;
  16468. }
  16469. $prevlevel = $chardata[$i]['level'];
  16470. }
  16471. // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
  16472. $prevlevel = - 1;
  16473. $levcount = 0;
  16474. for($i = 0; $i < $numchars; ++ $i)
  16475. {
  16476. if (($levcount > 0) and (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] == $prevlevel))
  16477. {
  16478. if (($chardata[$i]['type'] == 'N') and ($chardata[($i - 1)]['type'] == 'L') and ($chardata[($i + 1)]['type'] == 'L'))
  16479. {
  16480. $chardata[$i]['type'] = 'L';
  16481. }
  16482. elseif (($chardata[$i]['type'] == 'N') and (($chardata[($i - 1)]['type'] == 'R') or ($chardata[($i - 1)]['type'] == 'EN') or ($chardata[($i - 1)]['type'] == 'AN')) and (($chardata[($i + 1)]['type'] == 'R') or ($chardata[($i + 1)]['type'] == 'EN') or ($chardata[($i + 1)]['type'] == 'AN')))
  16483. {
  16484. $chardata[$i]['type'] = 'R';
  16485. }
  16486. elseif ($chardata[$i]['type'] == 'N')
  16487. {
  16488. // N2. Any remaining neutrals take the embedding direction
  16489. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16490. }
  16491. }
  16492. elseif (($levcount == 0) and (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] == $prevlevel))
  16493. {
  16494. // first char
  16495. if (($chardata[$i]['type'] == 'N') and ($chardata[$i]['sor'] == 'L') and ($chardata[($i + 1)]['type'] == 'L'))
  16496. {
  16497. $chardata[$i]['type'] = 'L';
  16498. }
  16499. elseif (($chardata[$i]['type'] == 'N') and (($chardata[$i]['sor'] == 'R') or ($chardata[$i]['sor'] == 'EN') or ($chardata[$i]['sor'] == 'AN')) and (($chardata[($i + 1)]['type'] == 'R') or ($chardata[($i + 1)]['type'] == 'EN') or ($chardata[($i + 1)]['type'] == 'AN')))
  16500. {
  16501. $chardata[$i]['type'] = 'R';
  16502. }
  16503. elseif ($chardata[$i]['type'] == 'N')
  16504. {
  16505. // N2. Any remaining neutrals take the embedding direction
  16506. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16507. }
  16508. }
  16509. elseif (($levcount > 0) and ((($i + 1) == $numchars) or (($i + 1) < $numchars) and ($chardata[($i + 1)]['level'] != $prevlevel)))
  16510. {
  16511. //last char
  16512. if (($chardata[$i]['type'] == 'N') and ($chardata[($i - 1)]['type'] == 'L') and ($chardata[$i]['eor'] == 'L'))
  16513. {
  16514. $chardata[$i]['type'] = 'L';
  16515. }
  16516. elseif (($chardata[$i]['type'] == 'N') and (($chardata[($i - 1)]['type'] == 'R') or ($chardata[($i - 1)]['type'] == 'EN') or ($chardata[($i - 1)]['type'] == 'AN')) and (($chardata[$i]['eor'] == 'R') or ($chardata[$i]['eor'] == 'EN') or ($chardata[$i]['eor'] == 'AN')))
  16517. {
  16518. $chardata[$i]['type'] = 'R';
  16519. }
  16520. elseif ($chardata[$i]['type'] == 'N')
  16521. {
  16522. // N2. Any remaining neutrals take the embedding direction
  16523. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16524. }
  16525. }
  16526. elseif ($chardata[$i]['type'] == 'N')
  16527. {
  16528. // N2. Any remaining neutrals take the embedding direction
  16529. $chardata[$i]['type'] = $chardata[$i]['sor'];
  16530. }
  16531. if ($chardata[$i]['level'] != $prevlevel)
  16532. {
  16533. $levcount = 0;
  16534. }
  16535. else
  16536. {
  16537. ++ $levcount;
  16538. }
  16539. $prevlevel = $chardata[$i]['level'];
  16540. }
  16541. // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
  16542. // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
  16543. for($i = 0; $i < $numchars; ++ $i)
  16544. {
  16545. $odd = $chardata[$i]['level'] % 2;
  16546. if ($odd)
  16547. {
  16548. if (($chardata[$i]['type'] == 'L') or ($chardata[$i]['type'] == 'AN') or ($chardata[$i]['type'] == 'EN'))
  16549. {
  16550. $chardata[$i]['level'] += 1;
  16551. }
  16552. }
  16553. else
  16554. {
  16555. if ($chardata[$i]['type'] == 'R')
  16556. {
  16557. $chardata[$i]['level'] += 1;
  16558. }
  16559. elseif (($chardata[$i]['type'] == 'AN') or ($chardata[$i]['type'] == 'EN'))
  16560. {
  16561. $chardata[$i]['level'] += 2;
  16562. }
  16563. }
  16564. $maxlevel = max($chardata[$i]['level'], $maxlevel);
  16565. }
  16566. // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
  16567. // 1. Segment separators,
  16568. // 2. Paragraph separators,
  16569. // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
  16570. // 4. Any sequence of white space characters at the end of the line.
  16571. for($i = 0; $i < $numchars; ++ $i)
  16572. {
  16573. if (($chardata[$i]['type'] == 'B') or ($chardata[$i]['type'] == 'S'))
  16574. {
  16575. $chardata[$i]['level'] = $pel;
  16576. }
  16577. elseif ($chardata[$i]['type'] == 'WS')
  16578. {
  16579. $j = $i + 1;
  16580. while ($j < $numchars)
  16581. {
  16582. if ((($chardata[$j]['type'] == 'B') or ($chardata[$j]['type'] == 'S')) or (($j == ($numchars - 1)) and ($chardata[$j]['type'] == 'WS')))
  16583. {
  16584. $chardata[$i]['level'] = $pel;
  16585. break;
  16586. }
  16587. elseif ($chardata[$j]['type'] != 'WS')
  16588. {
  16589. break;
  16590. }
  16591. ++ $j;
  16592. }
  16593. }
  16594. }
  16595. // Arabic Shaping
  16596. // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run.
  16597. if ($arabic)
  16598. {
  16599. $endedletter = array(1569, 1570, 1571, 1572, 1573, 1575, 1577, 1583, 1584, 1585, 1586, 1608, 1688);
  16600. $alfletter = array(1570, 1571, 1573, 1575);
  16601. $chardata2 = $chardata;
  16602. $laaletter = false;
  16603. $charAL = array();
  16604. $x = 0;
  16605. for($i = 0; $i < $numchars; ++ $i)
  16606. {
  16607. if (($this->unicode->uni_type[$chardata[$i]['char']] == 'AL') or ($chardata[$i]['char'] == 32) or ($chardata[$i]['char'] == 8204))
  16608. {
  16609. $charAL[$x] = $chardata[$i];
  16610. $charAL[$x]['i'] = $i;
  16611. $chardata[$i]['x'] = $x;
  16612. ++ $x;
  16613. }
  16614. }
  16615. $numAL = $x;
  16616. for($i = 0; $i < $numchars; ++ $i)
  16617. {
  16618. $thischar = $chardata[$i];
  16619. if ($i > 0)
  16620. {
  16621. $prevchar = $chardata[($i - 1)];
  16622. }
  16623. else
  16624. {
  16625. $prevchar = false;
  16626. }
  16627. if (($i + 1) < $numchars)
  16628. {
  16629. $nextchar = $chardata[($i + 1)];
  16630. }
  16631. else
  16632. {
  16633. $nextchar = false;
  16634. }
  16635. if ($this->unicode->uni_type[$thischar['char']] == 'AL')
  16636. {
  16637. $x = $thischar['x'];
  16638. if ($x > 0)
  16639. {
  16640. $prevchar = $charAL[($x - 1)];
  16641. }
  16642. else
  16643. {
  16644. $prevchar = false;
  16645. }
  16646. if (($x + 1) < $numAL)
  16647. {
  16648. $nextchar = $charAL[($x + 1)];
  16649. }
  16650. else
  16651. {
  16652. $nextchar = false;
  16653. }
  16654. // if laa letter
  16655. if (($prevchar !== false) and ($prevchar['char'] == 1604) and (in_array($thischar['char'], $alfletter)))
  16656. {
  16657. $arabicarr = $this->unicode->uni_laa_array;
  16658. $laaletter = true;
  16659. if ($x > 1)
  16660. {
  16661. $prevchar = $charAL[($x - 2)];
  16662. }
  16663. else
  16664. {
  16665. $prevchar = false;
  16666. }
  16667. }
  16668. else
  16669. {
  16670. $arabicarr = $this->unicode->uni_arabicsubst;
  16671. $laaletter = false;
  16672. }
  16673. if (($prevchar !== false) and ($nextchar !== false) and (($this->unicode->uni_type[$prevchar['char']] == 'AL') or ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) and (($this->unicode->uni_type[$nextchar['char']] == 'AL') or ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) and ($prevchar['type'] == $thischar['type']) and ($nextchar['type'] == $thischar['type']) and ($nextchar['char'] != 1567))
  16674. {
  16675. if (in_array($prevchar['char'], $endedletter))
  16676. {
  16677. if (isset($arabicarr[$thischar['char']][2]))
  16678. {
  16679. // initial
  16680. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  16681. }
  16682. }
  16683. else
  16684. {
  16685. if (isset($arabicarr[$thischar['char']][3]))
  16686. {
  16687. // medial
  16688. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
  16689. }
  16690. }
  16691. }
  16692. elseif (($nextchar !== false) and (($this->unicode->uni_type[$nextchar['char']] == 'AL') or ($this->unicode->uni_type[$nextchar['char']] == 'NSM')) and ($nextchar['type'] == $thischar['type']) and ($nextchar['char'] != 1567))
  16693. {
  16694. if (isset($arabicarr[$chardata[$i]['char']][2]))
  16695. {
  16696. // initial
  16697. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
  16698. }
  16699. }
  16700. elseif ((($prevchar !== false) and (($this->unicode->uni_type[$prevchar['char']] == 'AL') or ($this->unicode->uni_type[$prevchar['char']] == 'NSM')) and ($prevchar['type'] == $thischar['type'])) or (($nextchar !== false) and ($nextchar['char'] == 1567)))
  16701. {
  16702. // final
  16703. if (($i > 1) and ($thischar['char'] == 1607) and ($chardata[$i - 1]['char'] == 1604) and ($chardata[$i - 2]['char'] == 1604))
  16704. {
  16705. //Allah Word
  16706. // mark characters to delete with false
  16707. $chardata2[$i - 2]['char'] = false;
  16708. $chardata2[$i - 1]['char'] = false;
  16709. $chardata2[$i]['char'] = 65010;
  16710. }
  16711. else
  16712. {
  16713. if (($prevchar !== false) and in_array($prevchar['char'], $endedletter))
  16714. {
  16715. if (isset($arabicarr[$thischar['char']][0]))
  16716. {
  16717. // isolated
  16718. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  16719. }
  16720. }
  16721. else
  16722. {
  16723. if (isset($arabicarr[$thischar['char']][1]))
  16724. {
  16725. // final
  16726. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
  16727. }
  16728. }
  16729. }
  16730. }
  16731. elseif (isset($arabicarr[$thischar['char']][0]))
  16732. {
  16733. // isolated
  16734. $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
  16735. }
  16736. // if laa letter
  16737. if ($laaletter)
  16738. {
  16739. // mark characters to delete with false
  16740. $chardata2[($charAL[($x - 1)]['i'])]['char'] = false;
  16741. }
  16742. } // end if AL (Arabic Letter)
  16743. } // end for each char
  16744. /*
  16745. * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
  16746. * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
  16747. */
  16748. $cw = &$this->CurrentFont['cw'];
  16749. for($i = 0; $i < ($numchars - 1); ++ $i)
  16750. {
  16751. if (($chardata2[$i]['char'] == 1617) and (isset($this->unicode->uni_diacritics[($chardata2[$i + 1]['char'])])))
  16752. {
  16753. // check if the subtitution font is defined on current font
  16754. if (isset($cw[($this->unicode->uni_diacritics[($chardata2[$i + 1]['char'])])]))
  16755. {
  16756. $chardata2[$i]['char'] = false;
  16757. $chardata2[$i + 1]['char'] = $this->unicode->uni_diacritics[($chardata2[$i + 1]['char'])];
  16758. }
  16759. }
  16760. }
  16761. // remove marked characters
  16762. foreach ($chardata2 as $key => $value)
  16763. {
  16764. if ($value['char'] === false)
  16765. {
  16766. unset($chardata2[$key]);
  16767. }
  16768. }
  16769. $chardata = array_values($chardata2);
  16770. $numchars = count($chardata);
  16771. unset($chardata2);
  16772. unset($arabicarr);
  16773. unset($laaletter);
  16774. unset($charAL);
  16775. }
  16776. // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
  16777. for($j = $maxlevel; $j > 0; $j --)
  16778. {
  16779. $ordarray = Array();
  16780. $revarr = Array();
  16781. $onlevel = false;
  16782. for($i = 0; $i < $numchars; ++ $i)
  16783. {
  16784. if ($chardata[$i]['level'] >= $j)
  16785. {
  16786. $onlevel = true;
  16787. if (isset($this->unicode->uni_mirror[$chardata[$i]['char']]))
  16788. {
  16789. // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
  16790. $chardata[$i]['char'] = $this->unicode->uni_mirror[$chardata[$i]['char']];
  16791. }
  16792. $revarr[] = $chardata[$i];
  16793. }
  16794. else
  16795. {
  16796. if ($onlevel)
  16797. {
  16798. $revarr = array_reverse($revarr);
  16799. $ordarray = array_merge($ordarray, $revarr);
  16800. $revarr = Array();
  16801. $onlevel = false;
  16802. }
  16803. $ordarray[] = $chardata[$i];
  16804. }
  16805. }
  16806. if ($onlevel)
  16807. {
  16808. $revarr = array_reverse($revarr);
  16809. $ordarray = array_merge($ordarray, $revarr);
  16810. }
  16811. $chardata = $ordarray;
  16812. }
  16813. $ordarray = array();
  16814. for($i = 0; $i < $numchars; ++ $i)
  16815. {
  16816. $ordarray[] = $chardata[$i]['char'];
  16817. // store char values for subsetting
  16818. $this->CurrentFont['subsetchars'][$chardata[$i]['char']] = true;
  16819. }
  16820. // update font subsetchars
  16821. $this->setFontSubBuffer($this->CurrentFont['fontkey'], 'subsetchars', $this->CurrentFont['subsetchars']);
  16822. return $ordarray;
  16823. }
  16824. // END OF BIDIRECTIONAL TEXT SECTION -------------------
  16825. /**
  16826. * Adds a bookmark.
  16827. * @param string $txt bookmark description.
  16828. * @param int $level bookmark level (minimum value is 0).
  16829. * @param float $y Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
  16830. * @param int $page target page number (leave empty for current page).
  16831. * @access public
  16832. * @author Olivier Plathey, Nicola Asuni
  16833. * @since 2.1.002 (2008-02-12)
  16834. */
  16835. public function Bookmark($txt, $level = 0, $y = -1, $page = '')
  16836. {
  16837. if ($level < 0)
  16838. {
  16839. $level = 0;
  16840. }
  16841. if (isset($this->outlines[0]))
  16842. {
  16843. $lastoutline = end($this->outlines);
  16844. $maxlevel = $lastoutline['l'] + 1;
  16845. }
  16846. else
  16847. {
  16848. $maxlevel = 0;
  16849. }
  16850. if ($level > $maxlevel)
  16851. {
  16852. $level = $maxlevel;
  16853. }
  16854. if ($y == - 1)
  16855. {
  16856. $y = $this->GetY();
  16857. }
  16858. if (empty($page))
  16859. {
  16860. $page = $this->PageNo();
  16861. if (empty($page))
  16862. {
  16863. return;
  16864. }
  16865. }
  16866. $this->outlines[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page);
  16867. }
  16868. /**
  16869. * Create a bookmark PDF string.
  16870. * @access protected
  16871. * @author Olivier Plathey, Nicola Asuni
  16872. * @since 2.1.002 (2008-02-12)
  16873. */
  16874. protected function _putbookmarks()
  16875. {
  16876. $nb = count($this->outlines);
  16877. if ($nb == 0)
  16878. {
  16879. return;
  16880. }
  16881. // get sorting columns
  16882. $outline_p = array();
  16883. $outline_y = array();
  16884. foreach ($this->outlines as $key => $row)
  16885. {
  16886. $outline_p[$key] = $row['p'];
  16887. $outline_k[$key] = $key;
  16888. }
  16889. // sort outlines by page and original position
  16890. array_multisort($outline_p, SORT_NUMERIC, SORT_ASC, $outline_k, SORT_NUMERIC, SORT_ASC, $this->outlines);
  16891. $lru = array();
  16892. $level = 0;
  16893. foreach ($this->outlines as $i => $o)
  16894. {
  16895. if ($o['l'] > 0)
  16896. {
  16897. $parent = $lru[($o['l'] - 1)];
  16898. //Set parent and last pointers
  16899. $this->outlines[$i]['parent'] = $parent;
  16900. $this->outlines[$parent]['last'] = $i;
  16901. if ($o['l'] > $level)
  16902. {
  16903. //Level increasing: set first pointer
  16904. $this->outlines[$parent]['first'] = $i;
  16905. }
  16906. }
  16907. else
  16908. {
  16909. $this->outlines[$i]['parent'] = $nb;
  16910. }
  16911. if (($o['l'] <= $level) and ($i > 0))
  16912. {
  16913. //Set prev and next pointers
  16914. $prev = $lru[$o['l']];
  16915. $this->outlines[$prev]['next'] = $i;
  16916. $this->outlines[$i]['prev'] = $prev;
  16917. }
  16918. $lru[$o['l']] = $i;
  16919. $level = $o['l'];
  16920. }
  16921. //Outline items
  16922. $n = $this->n + 1;
  16923. $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';
  16924. foreach ($this->outlines as $i => $o)
  16925. {
  16926. if (isset($this->page_obj_id[($o['p'])]))
  16927. {
  16928. $oid = $this->_newobj();
  16929. // covert HTML title to string
  16930. $title = preg_replace($nltags, "\n", $o['t']);
  16931. $title = preg_replace("/[\r]+/si", '', $title);
  16932. $title = preg_replace("/[\n]+/si", "\n", $title);
  16933. $title = strip_tags($title);
  16934. $title = $this->stringTrim($title);
  16935. $out = '<</Title ' . $this->_textstring($title, $oid);
  16936. $out .= ' /Parent ' . ($n + $o['parent']) . ' 0 R';
  16937. if (isset($o['prev']))
  16938. {
  16939. $out .= ' /Prev ' . ($n + $o['prev']) . ' 0 R';
  16940. }
  16941. if (isset($o['next']))
  16942. {
  16943. $out .= ' /Next ' . ($n + $o['next']) . ' 0 R';
  16944. }
  16945. if (isset($o['first']))
  16946. {
  16947. $out .= ' /First ' . ($n + $o['first']) . ' 0 R';
  16948. }
  16949. if (isset($o['last']))
  16950. {
  16951. $out .= ' /Last ' . ($n + $o['last']) . ' 0 R';
  16952. }
  16953. $out .= ' ' . sprintf('/Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id[($o['p'])], ($this->pagedim[$o['p']]['h'] - ($o['y'] * $this->k)));
  16954. $out .= ' /Count 0 >>';
  16955. $out .= "\n" . 'endobj';
  16956. $this->_out($out);
  16957. }
  16958. }
  16959. //Outline root
  16960. $this->OutlineRoot = $this->_newobj();
  16961. $this->_out('<< /Type /Outlines /First ' . $n . ' 0 R /Last ' . ($n + $lru[0]) . ' 0 R >>' . "\n" . 'endobj');
  16962. }
  16963. // --- JAVASCRIPT ------------------------------------------------------
  16964. /**
  16965. * Adds a javascript
  16966. * @param string $script Javascript code
  16967. * @access public
  16968. * @author Johannes G�ntert, Nicola Asuni
  16969. * @since 2.1.002 (2008-02-12)
  16970. */
  16971. public function IncludeJS($script)
  16972. {
  16973. $this->javascript .= $script;
  16974. }
  16975. /**
  16976. * Adds a javascript object and return object ID
  16977. * @param string $script Javascript code
  16978. * @param boolean $onload if true executes this object when opening the document
  16979. * @return int internal object ID
  16980. * @access public
  16981. * @author Nicola Asuni
  16982. * @since 4.8.000 (2009-09-07)
  16983. */
  16984. public function addJavascriptObject($script, $onload = false)
  16985. {
  16986. ++ $this->n;
  16987. $this->js_objects[$this->n] = array('n' => $this->n, 'js' => $script, 'onload' => $onload);
  16988. return $this->n;
  16989. }
  16990. /**
  16991. * Create a javascript PDF string.
  16992. * @access protected
  16993. * @author Johannes G�ntert, Nicola Asuni
  16994. * @since 2.1.002 (2008-02-12)
  16995. */
  16996. protected function _putjavascript()
  16997. {
  16998. if (empty($this->javascript) and empty($this->js_objects))
  16999. {
  17000. return;
  17001. }
  17002. if (strpos($this->javascript, 'this.addField') > 0)
  17003. {
  17004. if (! $this->ur['enabled'])
  17005. {
  17006. //$this->setUserRights();
  17007. }
  17008. // the following two lines are used to avoid form fields duplication after saving
  17009. // The addField method only works when releasing user rights (UR3)
  17010. $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
  17011. $jsb = "getField('tcpdfdocsaved').value='saved';";
  17012. $this->javascript = $jsa . "\n" . $this->javascript . "\n" . $jsb;
  17013. }
  17014. $this->n_js = $this->_newobj();
  17015. $out = ' << /Names [';
  17016. if (! empty($this->javascript))
  17017. {
  17018. $out .= ' (EmbeddedJS) ' . ($this->n + 1) . ' 0 R';
  17019. }
  17020. if (! empty($this->js_objects))
  17021. {
  17022. foreach ($this->js_objects as $key => $val)
  17023. {
  17024. if ($val['onload'])
  17025. {
  17026. $out .= ' (JS' . $key . ') ' . $key . ' 0 R';
  17027. }
  17028. }
  17029. }
  17030. $out .= ' ] >>';
  17031. $out .= "\n" . 'endobj';
  17032. $this->_out($out);
  17033. // default Javascript object
  17034. if (! empty($this->javascript))
  17035. {
  17036. $obj_id = $this->_newobj();
  17037. $out = '<< /S /JavaScript';
  17038. $out .= ' /JS ' . $this->_textstring($this->javascript, $obj_id);
  17039. $out .= ' >>';
  17040. $out .= "\n" . 'endobj';
  17041. $this->_out($out);
  17042. }
  17043. // additional Javascript objects
  17044. if (! empty($this->js_objects))
  17045. {
  17046. foreach ($this->js_objects as $key => $val)
  17047. {
  17048. $out = $this->_getobj($key) . "\n" . ' << /S /JavaScript /JS ' . $this->_textstring($val['js'], $key) . ' >>' . "\n" . 'endobj';
  17049. $this->_out($out);
  17050. }
  17051. }
  17052. }
  17053. /**
  17054. * Convert color to javascript color.
  17055. * @param string $color color name or #RRGGBB
  17056. * @access protected
  17057. * @author Denis Van Nuffelen, Nicola Asuni
  17058. * @since 2.1.002 (2008-02-12)
  17059. */
  17060. protected function _JScolor($color)
  17061. {
  17062. static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow',
  17063. 'dkGray', 'gray', 'ltGray');
  17064. if (substr($color, 0, 1) == '#')
  17065. {
  17066. return sprintf("['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color, 1, 2)) / 255, hexdec(substr($color, 3, 2)) / 255, hexdec(substr($color, 5, 2)) / 255);
  17067. }
  17068. if (! in_array($color, $aColors))
  17069. {
  17070. $this->Error('Invalid color: ' . $color);
  17071. }
  17072. return 'color.' . $color;
  17073. }
  17074. /**
  17075. * Adds a javascript form field.
  17076. * @param string $type field type
  17077. * @param string $name field name
  17078. * @param int $x horizontal position
  17079. * @param int $y vertical position
  17080. * @param int $w width
  17081. * @param int $h height
  17082. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17083. * @access protected
  17084. * @author Denis Van Nuffelen, Nicola Asuni
  17085. * @since 2.1.002 (2008-02-12)
  17086. */
  17087. protected function _addfield($type, $name, $x, $y, $w, $h, $prop)
  17088. {
  17089. if ($this->rtl)
  17090. {
  17091. $x = $x - $w;
  17092. }
  17093. // the followind avoid fields duplication after saving the document
  17094. $this->javascript .= "if(getField('tcpdfdocsaved').value != 'saved') {";
  17095. $k = $this->k;
  17096. $this->javascript .= sprintf("f" . $name . "=this.addField('%s','%s',%u,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo() - 1, $x * $k, ($this->h - $y) * $k + 1, ($x + $w) * $k, ($this->h - $y - $h) * $k + 1) . "\n";
  17097. $this->javascript .= 'f' . $name . '.textSize=' . $this->FontSizePt . ";\n";
  17098. while (list($key, $val) = each($prop))
  17099. {
  17100. if (strcmp(substr($key, - 5), 'Color') == 0)
  17101. {
  17102. $val = $this->_JScolor($val);
  17103. }
  17104. else
  17105. {
  17106. $val = "'" . $val . "'";
  17107. }
  17108. $this->javascript .= 'f' . $name . '.' . $key . '=' . $val . ";\n";
  17109. }
  17110. if ($this->rtl)
  17111. {
  17112. $this->x -= $w;
  17113. }
  17114. else
  17115. {
  17116. $this->x += $w;
  17117. }
  17118. $this->javascript .= '}';
  17119. }
  17120. // --- FORM FIELDS -----------------------------------------------------
  17121. /**
  17122. * Convert JavaScript form fields properties array to Annotation Properties array.
  17123. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17124. * @return array of annotation properties
  17125. * @access protected
  17126. * @author Nicola Asuni
  17127. * @since 4.8.000 (2009-09-06)
  17128. */
  17129. protected function getAnnotOptFromJSProp($prop)
  17130. {
  17131. if (isset($prop['aopt']) and is_array($prop['aopt']))
  17132. {
  17133. // the annotation options area lready defined
  17134. return $prop['aopt'];
  17135. }
  17136. $opt = array(); // value to be returned
  17137. // alignment: Controls how the text is laid out within the text field.
  17138. if (isset($prop['alignment']))
  17139. {
  17140. switch ($prop['alignment'])
  17141. {
  17142. case 'left' :
  17143. {
  17144. $opt['q'] = 0;
  17145. break;
  17146. }
  17147. case 'center' :
  17148. {
  17149. $opt['q'] = 1;
  17150. break;
  17151. }
  17152. case 'right' :
  17153. {
  17154. $opt['q'] = 2;
  17155. break;
  17156. }
  17157. default :
  17158. {
  17159. $opt['q'] = ($this->rtl) ? 2 : 0;
  17160. break;
  17161. }
  17162. }
  17163. }
  17164. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  17165. if (isset($prop['lineWidth']))
  17166. {
  17167. $linewidth = intval($prop['lineWidth']);
  17168. }
  17169. else
  17170. {
  17171. $linewidth = 1;
  17172. }
  17173. // borderStyle: The border style for a field.
  17174. if (isset($prop['borderStyle']))
  17175. {
  17176. switch ($prop['borderStyle'])
  17177. {
  17178. case 'border.d' :
  17179. case 'dashed' :
  17180. {
  17181. $opt['border'] = array(0, 0, $linewidth, array(3, 2));
  17182. $opt['bs'] = array('w' => $linewidth, 's' => 'D', 'd' => array(3, 2));
  17183. break;
  17184. }
  17185. case 'border.b' :
  17186. case 'beveled' :
  17187. {
  17188. $opt['border'] = array(0, 0, $linewidth);
  17189. $opt['bs'] = array('w' => $linewidth, 's' => 'B');
  17190. break;
  17191. }
  17192. case 'border.i' :
  17193. case 'inset' :
  17194. {
  17195. $opt['border'] = array(0, 0, $linewidth);
  17196. $opt['bs'] = array('w' => $linewidth, 's' => 'I');
  17197. break;
  17198. }
  17199. case 'border.u' :
  17200. case 'underline' :
  17201. {
  17202. $opt['border'] = array(0, 0, $linewidth);
  17203. $opt['bs'] = array('w' => $linewidth, 's' => 'U');
  17204. break;
  17205. }
  17206. default :
  17207. case 'border.s' :
  17208. case 'solid' :
  17209. {
  17210. $opt['border'] = array(0, 0, $linewidth);
  17211. $opt['bs'] = array('w' => $linewidth, 's' => 'S');
  17212. break;
  17213. }
  17214. }
  17215. }
  17216. if (isset($prop['border']) and is_array($prop['border']))
  17217. {
  17218. $opt['border'] = $prop['border'];
  17219. }
  17220. if (! isset($opt['mk']))
  17221. {
  17222. $opt['mk'] = array();
  17223. }
  17224. if (! isset($opt['mk']['if']))
  17225. {
  17226. $opt['mk']['if'] = array();
  17227. }
  17228. $opt['mk']['if']['a'] = array(0.5, 0.5);
  17229. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  17230. if (isset($prop['buttonAlignX']))
  17231. {
  17232. $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
  17233. }
  17234. // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  17235. if (isset($prop['buttonAlignY']))
  17236. {
  17237. $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
  17238. }
  17239. // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  17240. if (isset($prop['buttonFitBounds']) and ($prop['buttonFitBounds'] == 'true'))
  17241. {
  17242. $opt['mk']['if']['fb'] = true;
  17243. }
  17244. // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  17245. if (isset($prop['buttonScaleHow']))
  17246. {
  17247. switch ($prop['buttonScaleHow'])
  17248. {
  17249. case 'scaleHow.proportional' :
  17250. {
  17251. $opt['mk']['if']['s'] = 'P';
  17252. break;
  17253. }
  17254. case 'scaleHow.anamorphic' :
  17255. {
  17256. $opt['mk']['if']['s'] = 'A';
  17257. break;
  17258. }
  17259. }
  17260. }
  17261. // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  17262. if (isset($prop['buttonScaleWhen']))
  17263. {
  17264. switch ($prop['buttonScaleWhen'])
  17265. {
  17266. case 'scaleWhen.always' :
  17267. {
  17268. $opt['mk']['if']['sw'] = 'A';
  17269. break;
  17270. }
  17271. case 'scaleWhen.never' :
  17272. {
  17273. $opt['mk']['if']['sw'] = 'N';
  17274. break;
  17275. }
  17276. case 'scaleWhen.tooBig' :
  17277. {
  17278. $opt['mk']['if']['sw'] = 'B';
  17279. break;
  17280. }
  17281. case 'scaleWhen.tooSmall' :
  17282. {
  17283. $opt['mk']['if']['sw'] = 'S';
  17284. break;
  17285. }
  17286. }
  17287. }
  17288. // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  17289. if (isset($prop['buttonPosition']))
  17290. {
  17291. switch ($prop['buttonPosition'])
  17292. {
  17293. case 0 :
  17294. case 'position.textOnly' :
  17295. {
  17296. $opt['mk']['tp'] = 0;
  17297. break;
  17298. }
  17299. case 1 :
  17300. case 'position.iconOnly' :
  17301. {
  17302. $opt['mk']['tp'] = 1;
  17303. break;
  17304. }
  17305. case 2 :
  17306. case 'position.iconTextV' :
  17307. {
  17308. $opt['mk']['tp'] = 2;
  17309. break;
  17310. }
  17311. case 3 :
  17312. case 'position.textIconV' :
  17313. {
  17314. $opt['mk']['tp'] = 3;
  17315. break;
  17316. }
  17317. case 4 :
  17318. case 'position.iconTextH' :
  17319. {
  17320. $opt['mk']['tp'] = 4;
  17321. break;
  17322. }
  17323. case 5 :
  17324. case 'position.textIconH' :
  17325. {
  17326. $opt['mk']['tp'] = 5;
  17327. break;
  17328. }
  17329. case 6 :
  17330. case 'position.overlay' :
  17331. {
  17332. $opt['mk']['tp'] = 6;
  17333. break;
  17334. }
  17335. }
  17336. }
  17337. // fillColor: Specifies the background color for a field.
  17338. if (isset($prop['fillColor']))
  17339. {
  17340. if (is_array($prop['fillColor']))
  17341. {
  17342. $opt['mk']['bg'] = $prop['fillColor'];
  17343. }
  17344. else
  17345. {
  17346. $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']);
  17347. }
  17348. }
  17349. // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
  17350. if (isset($prop['strokeColor']))
  17351. {
  17352. if (is_array($prop['strokeColor']))
  17353. {
  17354. $opt['mk']['bc'] = $prop['strokeColor'];
  17355. }
  17356. else
  17357. {
  17358. $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']);
  17359. }
  17360. }
  17361. // rotation: The rotation of a widget in counterclockwise increments.
  17362. if (isset($prop['rotation']))
  17363. {
  17364. $opt['mk']['r'] = $prop['rotation'];
  17365. }
  17366. // charLimit: Limits the number of characters that a user can type into a text field.
  17367. if (isset($prop['charLimit']))
  17368. {
  17369. $opt['maxlen'] = intval($prop['charLimit']);
  17370. }
  17371. if (! isset($ff))
  17372. {
  17373. $ff = 0;
  17374. }
  17375. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  17376. if (isset($prop['readonly']) and ($prop['readonly'] == 'true'))
  17377. {
  17378. $ff += 1 << 0;
  17379. }
  17380. // required: Specifies whether a field requires a value.
  17381. if (isset($prop['required']) and ($prop['required'] == 'true'))
  17382. {
  17383. $ff += 1 << 1;
  17384. }
  17385. // multiline: Controls how text is wrapped within the field.
  17386. if (isset($prop['multiline']) and ($prop['multiline'] == 'true'))
  17387. {
  17388. $ff += 1 << 12;
  17389. }
  17390. // password: Specifies whether the field should display asterisks when data is entered in the field.
  17391. if (isset($prop['password']) and ($prop['password'] == 'true'))
  17392. {
  17393. $ff += 1 << 13;
  17394. }
  17395. // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  17396. if (isset($prop['NoToggleToOff']) and ($prop['NoToggleToOff'] == 'true'))
  17397. {
  17398. $ff += 1 << 14;
  17399. }
  17400. // Radio: If set, the field is a set of radio buttons.
  17401. if (isset($prop['Radio']) and ($prop['Radio'] == 'true'))
  17402. {
  17403. $ff += 1 << 15;
  17404. }
  17405. // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  17406. if (isset($prop['Pushbutton']) and ($prop['Pushbutton'] == 'true'))
  17407. {
  17408. $ff += 1 << 16;
  17409. }
  17410. // Combo: If set, the field is a combo box; if clear, the field is a list box.
  17411. if (isset($prop['Combo']) and ($prop['Combo'] == 'true'))
  17412. {
  17413. $ff += 1 << 17;
  17414. }
  17415. // editable: Controls whether a combo box is editable.
  17416. if (isset($prop['editable']) and ($prop['editable'] == 'true'))
  17417. {
  17418. $ff += 1 << 18;
  17419. }
  17420. // Sort: If set, the field's option items shall be sorted alphabetically.
  17421. if (isset($prop['Sort']) and ($prop['Sort'] == 'true'))
  17422. {
  17423. $ff += 1 << 19;
  17424. }
  17425. // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  17426. if (isset($prop['fileSelect']) and ($prop['fileSelect'] == 'true'))
  17427. {
  17428. $ff += 1 << 20;
  17429. }
  17430. // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  17431. if (isset($prop['multipleSelection']) and ($prop['multipleSelection'] == 'true'))
  17432. {
  17433. $ff += 1 << 21;
  17434. }
  17435. // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  17436. if (isset($prop['doNotSpellCheck']) and ($prop['doNotSpellCheck'] == 'true'))
  17437. {
  17438. $ff += 1 << 22;
  17439. }
  17440. // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  17441. if (isset($prop['doNotScroll']) and ($prop['doNotScroll'] == 'true'))
  17442. {
  17443. $ff += 1 << 23;
  17444. }
  17445. // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set.
  17446. if (isset($prop['comb']) and ($prop['comb'] == 'true'))
  17447. {
  17448. $ff += 1 << 24;
  17449. }
  17450. // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons.
  17451. if (isset($prop['radiosInUnison']) and ($prop['radiosInUnison'] == 'true'))
  17452. {
  17453. $ff += 1 << 25;
  17454. }
  17455. // richText: If true, the field allows rich text formatting.
  17456. if (isset($prop['richText']) and ($prop['richText'] == 'true'))
  17457. {
  17458. $ff += 1 << 25;
  17459. }
  17460. // commitOnSelChange: Controls whether a field value is committed after a selection change.
  17461. if (isset($prop['commitOnSelChange']) and ($prop['commitOnSelChange'] == 'true'))
  17462. {
  17463. $ff += 1 << 26;
  17464. }
  17465. $opt['ff'] = $ff;
  17466. // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  17467. if (isset($prop['defaultValue']))
  17468. {
  17469. $opt['dv'] = $prop['defaultValue'];
  17470. }
  17471. $f = 4; // default value for annotation flags
  17472. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  17473. if (isset($prop['readonly']) and ($prop['readonly'] == 'true'))
  17474. {
  17475. $f += 1 << 6;
  17476. }
  17477. // display: Controls whether the field is hidden or visible on screen and in print.
  17478. if (isset($prop['display']))
  17479. {
  17480. if ($prop['display'] == 'display.visible')
  17481. {
  17482. //
  17483. }
  17484. elseif ($prop['display'] == 'display.hidden')
  17485. {
  17486. $f += 1 << 1;
  17487. }
  17488. elseif ($prop['display'] == 'display.noPrint')
  17489. {
  17490. $f -= 1 << 2;
  17491. }
  17492. elseif ($prop['display'] == 'display.noView')
  17493. {
  17494. $f += 1 << 5;
  17495. }
  17496. }
  17497. $opt['f'] = $f;
  17498. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  17499. if (isset($prop['currentValueIndices']) and is_array($prop['currentValueIndices']))
  17500. {
  17501. $opt['i'] = $prop['currentValueIndices'];
  17502. }
  17503. // value: The value of the field data that the user has entered.
  17504. if (isset($prop['value']))
  17505. {
  17506. if (is_array($prop['value']))
  17507. {
  17508. $opt['opt'] = array();
  17509. foreach ($prop['value'] as $key => $optval)
  17510. {
  17511. // exportValues: An array of strings representing the export values for the field.
  17512. if (isset($prop['exportValues'][$key]))
  17513. {
  17514. $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
  17515. }
  17516. else
  17517. {
  17518. $opt['opt'][$key] = $prop['value'][$key];
  17519. }
  17520. }
  17521. }
  17522. else
  17523. {
  17524. $opt['v'] = $prop['value'];
  17525. }
  17526. }
  17527. // richValue: This property specifies the text contents and formatting of a rich text field.
  17528. if (isset($prop['richValue']))
  17529. {
  17530. $opt['rv'] = $prop['richValue'];
  17531. }
  17532. // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  17533. if (isset($prop['submitName']))
  17534. {
  17535. $opt['tm'] = $prop['submitName'];
  17536. }
  17537. // name: Fully qualified field name.
  17538. if (isset($prop['name']))
  17539. {
  17540. $opt['t'] = $prop['name'];
  17541. }
  17542. // userName: The user name (short description string) of the field.
  17543. if (isset($prop['userName']))
  17544. {
  17545. $opt['tu'] = $prop['userName'];
  17546. }
  17547. // highlight: Defines how a button reacts when a user clicks it.
  17548. if (isset($prop['highlight']))
  17549. {
  17550. switch ($prop['highlight'])
  17551. {
  17552. case 'none' :
  17553. case 'highlight.n' :
  17554. {
  17555. $opt['h'] = 'N';
  17556. break;
  17557. }
  17558. case 'invert' :
  17559. case 'highlight.i' :
  17560. {
  17561. $opt['h'] = 'i';
  17562. break;
  17563. }
  17564. case 'push' :
  17565. case 'highlight.p' :
  17566. {
  17567. $opt['h'] = 'P';
  17568. break;
  17569. }
  17570. case 'outline' :
  17571. case 'highlight.o' :
  17572. {
  17573. $opt['h'] = 'O';
  17574. break;
  17575. }
  17576. }
  17577. }
  17578. // Unsupported options:
  17579. // - calcOrderIndex: Changes the calculation order of fields in the document.
  17580. // - delay: Delays the redrawing of a field's appearance.
  17581. // - defaultStyle: This property defines the default style attributes for the form field.
  17582. // - style: Allows the user to set the glyph style of a check box or radio button.
  17583. // - textColor, textFont, textSize
  17584. return $opt;
  17585. }
  17586. /**
  17587. * Set default properties for form fields.
  17588. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17589. * @access public
  17590. * @author Nicola Asuni
  17591. * @since 4.8.000 (2009-09-06)
  17592. */
  17593. public function setFormDefaultProp($prop = array())
  17594. {
  17595. $this->default_form_prop = $prop;
  17596. }
  17597. /**
  17598. * Return the default properties for form fields.
  17599. * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17600. * @access public
  17601. * @author Nicola Asuni
  17602. * @since 4.8.000 (2009-09-06)
  17603. */
  17604. public function getFormDefaultProp()
  17605. {
  17606. return $this->default_form_prop;
  17607. }
  17608. /**
  17609. * Creates a text field
  17610. * @param string $name field name
  17611. * @param float $w Width of the rectangle
  17612. * @param float $h Height of the rectangle
  17613. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17614. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17615. * @param float $x Abscissa of the upper-left corner of the rectangle
  17616. * @param float $y Ordinate of the upper-left corner of the rectangle
  17617. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17618. * @access public
  17619. * @author Nicola Asuni
  17620. * @since 4.8.000 (2009-09-07)
  17621. */
  17622. public function TextField($name, $w, $h, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  17623. {
  17624. if ($x === '')
  17625. {
  17626. $x = $this->x;
  17627. }
  17628. if ($y === '')
  17629. {
  17630. $y = $this->y;
  17631. }
  17632. // check page for no-write regions and adapt page margins if necessary
  17633. $this->checkPageRegions($h, $x, $y);
  17634. if ($js)
  17635. {
  17636. $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
  17637. return;
  17638. }
  17639. // get default style
  17640. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17641. // get annotation data
  17642. $popt = $this->getAnnotOptFromJSProp($prop);
  17643. // set default appearance stream
  17644. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17645. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17646. $popt['da'] = $fontstyle;
  17647. $popt['ap'] = array();
  17648. $popt['ap']['n'] = 'q BT ' . $fontstyle . ' ET Q';
  17649. // merge options
  17650. $opt = array_merge($popt, $opt);
  17651. // remove some conflicting options
  17652. unset($opt['bs']);
  17653. // set remaining annotation data
  17654. $opt['Subtype'] = 'Widget';
  17655. $opt['ft'] = 'Tx';
  17656. $opt['t'] = $name;
  17657. /*
  17658. Additional annotation's parameters (check _putannotsobj() method):
  17659. //$opt['f']
  17660. //$opt['ap']
  17661. //$opt['as']
  17662. //$opt['bs']
  17663. //$opt['be']
  17664. //$opt['c']
  17665. //$opt['border']
  17666. //$opt['h']
  17667. //$opt['mk']
  17668. //$opt['mk']['r']
  17669. //$opt['mk']['bc']
  17670. //$opt['mk']['bg']
  17671. //$opt['mk']['ca']
  17672. //$opt['mk']['rc']
  17673. //$opt['mk']['ac']
  17674. //$opt['mk']['i']
  17675. //$opt['mk']['ri']
  17676. //$opt['mk']['ix']
  17677. //$opt['mk']['if']
  17678. //$opt['mk']['if']['sw']
  17679. //$opt['mk']['if']['s']
  17680. //$opt['mk']['if']['a']
  17681. //$opt['mk']['if']['fb']
  17682. //$opt['mk']['tp']
  17683. //$opt['tu']
  17684. //$opt['tm']
  17685. //$opt['ff']
  17686. //$opt['v']
  17687. //$opt['dv']
  17688. //$opt['a']
  17689. //$opt['aa']
  17690. //$opt['q']
  17691. */
  17692. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17693. if ($this->rtl)
  17694. {
  17695. $this->x -= $w;
  17696. }
  17697. else
  17698. {
  17699. $this->x += $w;
  17700. }
  17701. }
  17702. /**
  17703. * Creates a RadioButton field
  17704. * @param string $name field name
  17705. * @param int $w width
  17706. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17707. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17708. * @param string $onvalue value to be returned if selected.
  17709. * @param boolean $checked define the initial state.
  17710. * @param float $x Abscissa of the upper-left corner of the rectangle
  17711. * @param float $y Ordinate of the upper-left corner of the rectangle
  17712. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17713. * @access public
  17714. * @author Nicola Asuni
  17715. * @since 4.8.000 (2009-09-07)
  17716. */
  17717. public function RadioButton($name, $w, $prop = array(), $opt = array(), $onvalue = 'On', $checked = false, $x = '', $y = '', $js = false)
  17718. {
  17719. if ($x === '')
  17720. {
  17721. $x = $this->x;
  17722. }
  17723. if ($y === '')
  17724. {
  17725. $y = $this->y;
  17726. }
  17727. // check page for no-write regions and adapt page margins if necessary
  17728. $this->checkPageRegions($w, $x, $y);
  17729. if ($js)
  17730. {
  17731. $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
  17732. return;
  17733. }
  17734. if ($this->empty_string($onvalue))
  17735. {
  17736. $onvalue = 'On';
  17737. }
  17738. if ($checked)
  17739. {
  17740. $defval = $onvalue;
  17741. }
  17742. else
  17743. {
  17744. $defval = 'Off';
  17745. }
  17746. // set data for parent group
  17747. if (! isset($this->radiobutton_groups[$this->page]))
  17748. {
  17749. $this->radiobutton_groups[$this->page] = array();
  17750. }
  17751. if (! isset($this->radiobutton_groups[$this->page][$name]))
  17752. {
  17753. $this->radiobutton_groups[$this->page][$name] = array();
  17754. ++ $this->n;
  17755. $this->radiobutton_groups[$this->page][$name]['n'] = $this->n;
  17756. $this->radio_groups[] = $this->n;
  17757. $kid = ($this->n + 2);
  17758. }
  17759. else
  17760. {
  17761. $kid = ($this->n + 1);
  17762. }
  17763. // save object ID to be added on Kids entry on parent object
  17764. $this->radiobutton_groups[$this->page][$name][] = array('kid' => $kid, 'def' => $defval);
  17765. // get default style
  17766. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17767. $prop['NoToggleToOff'] = 'true';
  17768. $prop['Radio'] = 'true';
  17769. $prop['borderStyle'] = 'inset';
  17770. // get annotation data
  17771. $popt = $this->getAnnotOptFromJSProp($prop);
  17772. // set additional default values
  17773. $font = 'zapfdingbats';
  17774. $this->AddFont($font);
  17775. $tmpfont = $this->getFontBuffer($font);
  17776. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  17777. $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  17778. $popt['da'] = $fontstyle;
  17779. $popt['ap'] = array();
  17780. $popt['ap']['n'] = array();
  17781. $popt['ap']['n'][$onvalue] = 'q BT ' . $fontstyle . ' 0 0 Td (8) Tj ET Q';
  17782. $popt['ap']['n']['Off'] = 'q BT ' . $fontstyle . ' 0 0 Td (8) Tj ET Q';
  17783. if (! isset($popt['mk']))
  17784. {
  17785. $popt['mk'] = array();
  17786. }
  17787. $popt['mk']['ca'] = '(l)';
  17788. // merge options
  17789. $opt = array_merge($popt, $opt);
  17790. // set remaining annotation data
  17791. $opt['Subtype'] = 'Widget';
  17792. $opt['ft'] = 'Btn';
  17793. if ($checked)
  17794. {
  17795. $opt['v'] = array('/' . $onvalue);
  17796. $opt['as'] = $onvalue;
  17797. }
  17798. else
  17799. {
  17800. $opt['as'] = 'Off';
  17801. }
  17802. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  17803. if ($this->rtl)
  17804. {
  17805. $this->x -= $w;
  17806. }
  17807. else
  17808. {
  17809. $this->x += $w;
  17810. }
  17811. }
  17812. /**
  17813. * Creates a List-box field
  17814. * @param string $name field name
  17815. * @param int $w width
  17816. * @param int $h height
  17817. * @param array $values array containing the list of values.
  17818. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17819. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17820. * @param float $x Abscissa of the upper-left corner of the rectangle
  17821. * @param float $y Ordinate of the upper-left corner of the rectangle
  17822. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17823. * @access public
  17824. * @author Nicola Asuni
  17825. * @since 4.8.000 (2009-09-07)
  17826. */
  17827. public function ListBox($name, $w, $h, $values, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  17828. {
  17829. if ($x === '')
  17830. {
  17831. $x = $this->x;
  17832. }
  17833. if ($y === '')
  17834. {
  17835. $y = $this->y;
  17836. }
  17837. // check page for no-write regions and adapt page margins if necessary
  17838. $this->checkPageRegions($h, $x, $y);
  17839. if ($js)
  17840. {
  17841. $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
  17842. $s = '';
  17843. foreach ($values as $value)
  17844. {
  17845. $s .= "'" . addslashes($value) . "',";
  17846. }
  17847. $this->javascript .= 'f' . $name . '.setItems([' . substr($s, 0, - 1) . "]);\n";
  17848. return;
  17849. }
  17850. // get default style
  17851. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17852. // get annotation data
  17853. $popt = $this->getAnnotOptFromJSProp($prop);
  17854. // set additional default values
  17855. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17856. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17857. $popt['da'] = $fontstyle;
  17858. $popt['ap'] = array();
  17859. $popt['ap']['n'] = 'q BT ' . $fontstyle . ' ET Q';
  17860. // merge options
  17861. $opt = array_merge($popt, $opt);
  17862. // set remaining annotation data
  17863. $opt['Subtype'] = 'Widget';
  17864. $opt['ft'] = 'Ch';
  17865. $opt['t'] = $name;
  17866. $opt['opt'] = $values;
  17867. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17868. if ($this->rtl)
  17869. {
  17870. $this->x -= $w;
  17871. }
  17872. else
  17873. {
  17874. $this->x += $w;
  17875. }
  17876. }
  17877. /**
  17878. * Creates a Combo-box field
  17879. * @param string $name field name
  17880. * @param int $w width
  17881. * @param int $h height
  17882. * @param array $values array containing the list of values.
  17883. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17884. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17885. * @param float $x Abscissa of the upper-left corner of the rectangle
  17886. * @param float $y Ordinate of the upper-left corner of the rectangle
  17887. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17888. * @access public
  17889. * @author Nicola Asuni
  17890. * @since 4.8.000 (2009-09-07)
  17891. */
  17892. public function ComboBox($name, $w, $h, $values, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  17893. {
  17894. if ($x === '')
  17895. {
  17896. $x = $this->x;
  17897. }
  17898. if ($y === '')
  17899. {
  17900. $y = $this->y;
  17901. }
  17902. // check page for no-write regions and adapt page margins if necessary
  17903. $this->checkPageRegions($h, $x, $y);
  17904. if ($js)
  17905. {
  17906. $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
  17907. $s = '';
  17908. foreach ($values as $value)
  17909. {
  17910. $s .= "'" . addslashes($value) . "',";
  17911. }
  17912. $this->javascript .= 'f' . $name . '.setItems([' . substr($s, 0, - 1) . "]);\n";
  17913. return;
  17914. }
  17915. // get default style
  17916. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17917. $prop['Combo'] = true;
  17918. // get annotation data
  17919. $popt = $this->getAnnotOptFromJSProp($prop);
  17920. // set additional default options
  17921. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  17922. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  17923. $popt['da'] = $fontstyle;
  17924. $popt['ap'] = array();
  17925. $popt['ap']['n'] = 'q BT ' . $fontstyle . ' ET Q';
  17926. // merge options
  17927. $opt = array_merge($popt, $opt);
  17928. // set remaining annotation data
  17929. $opt['Subtype'] = 'Widget';
  17930. $opt['ft'] = 'Ch';
  17931. $opt['t'] = $name;
  17932. $opt['opt'] = $values;
  17933. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  17934. if ($this->rtl)
  17935. {
  17936. $this->x -= $w;
  17937. }
  17938. else
  17939. {
  17940. $this->x += $w;
  17941. }
  17942. }
  17943. /**
  17944. * Creates a CheckBox field
  17945. * @param string $name field name
  17946. * @param int $w width
  17947. * @param boolean $checked define the initial state.
  17948. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  17949. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  17950. * @param string $onvalue value to be returned if selected.
  17951. * @param float $x Abscissa of the upper-left corner of the rectangle
  17952. * @param float $y Ordinate of the upper-left corner of the rectangle
  17953. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  17954. * @access public
  17955. * @author Nicola Asuni
  17956. * @since 4.8.000 (2009-09-07)
  17957. */
  17958. public function CheckBox($name, $w, $checked = false, $prop = array(), $opt = array(), $onvalue = 'Yes', $x = '', $y = '', $js = false)
  17959. {
  17960. if ($x === '')
  17961. {
  17962. $x = $this->x;
  17963. }
  17964. if ($y === '')
  17965. {
  17966. $y = $this->y;
  17967. }
  17968. // check page for no-write regions and adapt page margins if necessary
  17969. $this->checkPageRegions($w, $x, $y);
  17970. if ($js)
  17971. {
  17972. $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
  17973. return;
  17974. }
  17975. if (! isset($prop['value']))
  17976. {
  17977. $prop['value'] = array('Yes');
  17978. }
  17979. // get default style
  17980. $prop = array_merge($this->getFormDefaultProp(), $prop);
  17981. $prop['borderStyle'] = 'inset';
  17982. // get annotation data
  17983. $popt = $this->getAnnotOptFromJSProp($prop);
  17984. // set additional default options
  17985. $font = 'zapfdingbats';
  17986. $this->AddFont($font);
  17987. $tmpfont = $this->getFontBuffer($font);
  17988. $this->annotation_fonts[$tmpfont['fontkey']] = $tmpfont['i'];
  17989. $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt, $this->TextColor);
  17990. $popt['da'] = $fontstyle;
  17991. $popt['ap'] = array();
  17992. $popt['ap']['n'] = array();
  17993. $popt['ap']['n']['Yes'] = 'q BT ' . $fontstyle . ' 0 0 Td (8) Tj ET Q';
  17994. $popt['ap']['n']['Off'] = 'q BT ' . $fontstyle . ' 0 0 Td (8) Tj ET Q';
  17995. // merge options
  17996. $opt = array_merge($popt, $opt);
  17997. // set remaining annotation data
  17998. $opt['Subtype'] = 'Widget';
  17999. $opt['ft'] = 'Btn';
  18000. $opt['t'] = $name;
  18001. $opt['opt'] = array($onvalue);
  18002. if ($checked)
  18003. {
  18004. $opt['v'] = array('/0');
  18005. $opt['as'] = 'Yes';
  18006. }
  18007. else
  18008. {
  18009. $opt['v'] = array('/Off');
  18010. $opt['as'] = 'Off';
  18011. }
  18012. $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
  18013. if ($this->rtl)
  18014. {
  18015. $this->x -= $w;
  18016. }
  18017. else
  18018. {
  18019. $this->x += $w;
  18020. }
  18021. }
  18022. /**
  18023. * Creates a button field
  18024. * @param string $name field name
  18025. * @param int $w width
  18026. * @param int $h height
  18027. * @param string $caption caption.
  18028. * @param mixed $action action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008.
  18029. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  18030. * @param array $opt annotation parameters. Possible values are described on official PDF32000_2008 reference.
  18031. * @param float $x Abscissa of the upper-left corner of the rectangle
  18032. * @param float $y Ordinate of the upper-left corner of the rectangle
  18033. * @param boolean $js if true put the field using JavaScript (requires Acrobat Writer to be rendered).
  18034. * @access public
  18035. * @author Nicola Asuni
  18036. * @since 4.8.000 (2009-09-07)
  18037. */
  18038. public function Button($name, $w, $h, $caption, $action, $prop = array(), $opt = array(), $x = '', $y = '', $js = false)
  18039. {
  18040. if ($x === '')
  18041. {
  18042. $x = $this->x;
  18043. }
  18044. if ($y === '')
  18045. {
  18046. $y = $this->y;
  18047. }
  18048. // check page for no-write regions and adapt page margins if necessary
  18049. $this->checkPageRegions($h, $x, $y);
  18050. if ($js)
  18051. {
  18052. $this->_addfield('button', $name, $this->x, $this->y, $w, $h, $prop);
  18053. $this->javascript .= 'f' . $name . ".buttonSetCaption('" . addslashes($caption) . "');\n";
  18054. $this->javascript .= 'f' . $name . ".setAction('MouseUp','" . addslashes($action) . "');\n";
  18055. $this->javascript .= 'f' . $name . ".highlight='push';\n";
  18056. $this->javascript .= 'f' . $name . ".print=false;\n";
  18057. return;
  18058. }
  18059. // get default style
  18060. $prop = array_merge($this->getFormDefaultProp(), $prop);
  18061. $prop['Pushbutton'] = 'true';
  18062. $prop['highlight'] = 'push';
  18063. $prop['display'] = 'display.noPrint';
  18064. // get annotation data
  18065. $popt = $this->getAnnotOptFromJSProp($prop);
  18066. $this->annotation_fonts[$this->CurrentFont['fontkey']] = $this->CurrentFont['i'];
  18067. $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont['i'], $this->FontSizePt, $this->TextColor);
  18068. $popt['da'] = $fontstyle;
  18069. $popt['ap'] = array();
  18070. $popt['ap']['n'] = 'q BT ' . $fontstyle . ' ET Q';
  18071. // set additional default options
  18072. if (! isset($popt['mk']))
  18073. {
  18074. $popt['mk'] = array();
  18075. }
  18076. $ann_obj_id = ($this->n + 1);
  18077. if (! empty($action) and ! is_array($action))
  18078. {
  18079. $ann_obj_id = ($this->n + 2);
  18080. }
  18081. $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
  18082. $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
  18083. $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
  18084. // merge options
  18085. $opt = array_merge($popt, $opt);
  18086. // set remaining annotation data
  18087. $opt['Subtype'] = 'Widget';
  18088. $opt['ft'] = 'Btn';
  18089. $opt['t'] = $caption;
  18090. $opt['v'] = $name;
  18091. if (! empty($action))
  18092. {
  18093. if (is_array($action))
  18094. {
  18095. // form action options as on section 12.7.5 of PDF32000_2008.
  18096. $opt['aa'] = '/D <<';
  18097. $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
  18098. foreach ($action as $key => $val)
  18099. {
  18100. if (($key == 'S') and in_array($val, $bmode))
  18101. {
  18102. $opt['aa'] .= ' /S /' . $val;
  18103. }
  18104. elseif (($key == 'F') and (! empty($val)))
  18105. {
  18106. $opt['aa'] .= ' /F ' . $this->_datastring($val, $ann_obj_id);
  18107. }
  18108. elseif (($key == 'Fields') and is_array($val) and ! empty($val))
  18109. {
  18110. $opt['aa'] .= ' /Fields [';
  18111. foreach ($val as $field)
  18112. {
  18113. $opt['aa'] .= ' ' . $this->_textstring($field, $ann_obj_id);
  18114. }
  18115. $opt['aa'] .= ']';
  18116. }
  18117. elseif (($key == 'Flags'))
  18118. {
  18119. $ff = 0;
  18120. if (is_array($val))
  18121. {
  18122. foreach ($val as $flag)
  18123. {
  18124. switch ($flag)
  18125. {
  18126. case 'Include/Exclude' :
  18127. {
  18128. $ff += 1 << 0;
  18129. break;
  18130. }
  18131. case 'IncludeNoValueFields' :
  18132. {
  18133. $ff += 1 << 1;
  18134. break;
  18135. }
  18136. case 'ExportFormat' :
  18137. {
  18138. $ff += 1 << 2;
  18139. break;
  18140. }
  18141. case 'GetMethod' :
  18142. {
  18143. $ff += 1 << 3;
  18144. break;
  18145. }
  18146. case 'SubmitCoordinates' :
  18147. {
  18148. $ff += 1 << 4;
  18149. break;
  18150. }
  18151. case 'XFDF' :
  18152. {
  18153. $ff += 1 << 5;
  18154. break;
  18155. }
  18156. case 'IncludeAppendSaves' :
  18157. {
  18158. $ff += 1 << 6;
  18159. break;
  18160. }
  18161. case 'IncludeAnnotations' :
  18162. {
  18163. $ff += 1 << 7;
  18164. break;
  18165. }
  18166. case 'SubmitPDF' :
  18167. {
  18168. $ff += 1 << 8;
  18169. break;
  18170. }
  18171. case 'CanonicalFormat' :
  18172. {
  18173. $ff += 1 << 9;
  18174. break;
  18175. }
  18176. case 'ExclNonUserAnnots' :
  18177. {
  18178. $ff += 1 << 10;
  18179. break;
  18180. }
  18181. case 'ExclFKey' :
  18182. {
  18183. $ff += 1 << 11;
  18184. break;
  18185. }
  18186. case 'EmbedForm' :
  18187. {
  18188. $ff += 1 << 13;
  18189. break;
  18190. }
  18191. }
  18192. }
  18193. }
  18194. else
  18195. {
  18196. $ff = intval($val);
  18197. }
  18198. $opt['aa'] .= ' /Flags ' . $ff;
  18199. }
  18200. }
  18201. $opt['aa'] .= ' >>';
  18202. }
  18203. else
  18204. {
  18205. // Javascript action or raw action command
  18206. $js_obj_id = $this->addJavascriptObject($action);
  18207. $opt['aa'] = '/D ' . $js_obj_id . ' 0 R';
  18208. }
  18209. }
  18210. $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
  18211. if ($this->rtl)
  18212. {
  18213. $this->x -= $w;
  18214. }
  18215. else
  18216. {
  18217. $this->x += $w;
  18218. }
  18219. }
  18220. // --- END FORMS FIELDS ------------------------------------------------
  18221. /**
  18222. * Add certification signature (DocMDP or UR3)
  18223. * You can set only one signature type
  18224. * @access protected
  18225. * @author Nicola Asuni
  18226. * @since 4.6.008 (2009-05-07)
  18227. */
  18228. protected function _putsignature()
  18229. {
  18230. if ((! $this->sign) or (! isset($this->signature_data['cert_type'])))
  18231. {
  18232. return;
  18233. }
  18234. $out = $this->_getobj($this->sig_obj_id + 1) . "\n";
  18235. $out .= '<< /Type /Sig';
  18236. $out .= ' /Filter /Adobe.PPKLite';
  18237. $out .= ' /SubFilter /adbe.pkcs7.detached';
  18238. $out .= ' ' . $this->byterange_string;
  18239. $out .= ' /Contents<' . str_repeat('0', $this->signature_max_length) . '>';
  18240. $out .= ' /Reference ['; // array of signature reference dictionaries
  18241. $out .= ' << /Type /SigRef';
  18242. if ($this->signature_data['cert_type'] > 0)
  18243. {
  18244. $out .= ' /TransformMethod /DocMDP';
  18245. $out .= ' /TransformParams <<';
  18246. $out .= ' /Type /TransformParams';
  18247. $out .= ' /V /1.2';
  18248. $out .= ' /P ' . $this->signature_data['cert_type'];
  18249. }
  18250. else
  18251. {
  18252. $out .= ' /TransformMethod /UR3';
  18253. $out .= ' /TransformParams <<';
  18254. $out .= ' /Type /TransformParams';
  18255. $out .= ' /V /2.2';
  18256. if (! $this->empty_string($this->ur['document']))
  18257. {
  18258. $out .= ' /Document[' . $this->ur['document'] . ']';
  18259. }
  18260. if (! $this->empty_string($this->ur['form']))
  18261. {
  18262. $out .= ' /Form[' . $this->ur['form'] . ']';
  18263. }
  18264. if (! $this->empty_string($this->ur['signature']))
  18265. {
  18266. $out .= ' /Signature[' . $this->ur['signature'] . ']';
  18267. }
  18268. if (! $this->empty_string($this->ur['annots']))
  18269. {
  18270. $out .= ' /Annots[' . $this->ur['annots'] . ']';
  18271. }
  18272. if (! $this->empty_string($this->ur['ef']))
  18273. {
  18274. $out .= ' /EF[' . $this->ur['ef'] . ']';
  18275. }
  18276. if (! $this->empty_string($this->ur['formex']))
  18277. {
  18278. $out .= ' /FormEX[' . $this->ur['formex'] . ']';
  18279. }
  18280. }
  18281. $out .= ' >>'; // close TransformParams
  18282. // optional digest data (values must be calculated and replaced later)
  18283. //$out .= ' /Data ********** 0 R';
  18284. //$out .= ' /DigestMethod/MD5';
  18285. //$out .= ' /DigestLocation[********** 34]';
  18286. //$out .= ' /DigestValue<********************************>';
  18287. $out .= ' >>';
  18288. $out .= ' ]'; // end of reference
  18289. if (isset($this->signature_data['info']['Name']) and ! $this->empty_string($this->signature_data['info']['Name']))
  18290. {
  18291. $out .= ' /Name ' . $this->_textstring($this->signature_data['info']['Name']);
  18292. }
  18293. if (isset($this->signature_data['info']['Location']) and ! $this->empty_string($this->signature_data['info']['Location']))
  18294. {
  18295. $out .= ' /Location ' . $this->_textstring($this->signature_data['info']['Location']);
  18296. }
  18297. if (isset($this->signature_data['info']['Reason']) and ! $this->empty_string($this->signature_data['info']['Reason']))
  18298. {
  18299. $out .= ' /Reason ' . $this->_textstring($this->signature_data['info']['Reason']);
  18300. }
  18301. if (isset($this->signature_data['info']['ContactInfo']) and ! $this->empty_string($this->signature_data['info']['ContactInfo']))
  18302. {
  18303. $out .= ' /ContactInfo ' . $this->_textstring($this->signature_data['info']['ContactInfo']);
  18304. }
  18305. $out .= ' /M ' . $this->_datestring();
  18306. $out .= ' >>';
  18307. $out .= "\n" . 'endobj';
  18308. $this->_out($out);
  18309. }
  18310. /**
  18311. * Set User's Rights for PDF Reader
  18312. * WARNING: This is experimental and currently do not work.
  18313. * Check the PDF Reference 8.7.1 Transform Methods,
  18314. * Table 8.105 Entries in the UR transform parameters dictionary
  18315. * @param boolean $enable if true enable user's rights on PDF reader
  18316. * @param string $document Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data.
  18317. * @param string $annots Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations.
  18318. * @param string $form Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
  18319. * @param string $signature Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field.
  18320. * @param string $ef Names specifying additional usage rights for named embedded files in the document. Valid names are /Create/Delete/Modify/Import, which permit the user to perform the named operation on named embedded files
  18321. Names specifying additional embedded-files-related usage rights for the document.
  18322. * @param string $formex Names specifying additional form-field-related usage rights. The only valid name is BarcodePlaintext, which permits text form field data to be encoded as a plaintext two-dimensional barcode.
  18323. * @access public
  18324. * @author Nicola Asuni
  18325. * @since 2.9.000 (2008-03-26)
  18326. */
  18327. public function setUserRights($enable = true, $document = '/FullSave', $annots = '/Create/Delete/Modify/Copy/Import/Export', $form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate', $signature = '/Modify', $ef = '/Create/Delete/Modify/Import', $formex = '')
  18328. {
  18329. $this->ur['enabled'] = $enable;
  18330. $this->ur['document'] = $document;
  18331. $this->ur['annots'] = $annots;
  18332. $this->ur['form'] = $form;
  18333. $this->ur['signature'] = $signature;
  18334. $this->ur['ef'] = $ef;
  18335. $this->ur['formex'] = $formex;
  18336. if (! $this->sign)
  18337. {
  18338. $this->setSignature('', '', '', '', 0, array());
  18339. }
  18340. }
  18341. /**
  18342. * Enable document signature (requires the OpenSSL Library).
  18343. * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
  18344. * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  18345. * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  18346. * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
  18347. * @param mixed $signing_cert signing certificate (string or filename prefixed with 'file://')
  18348. * @param mixed $private_key private key (string or filename prefixed with 'file://')
  18349. * @param string $private_key_password password
  18350. * @param string $extracerts specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.
  18351. * @param int $cert_type The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
  18352. * @param array $info array of option information: Name, Location, Reason, ContactInfo.
  18353. * @access public
  18354. * @author Nicola Asuni
  18355. * @since 4.6.005 (2009-04-24)
  18356. */
  18357. public function setSignature($signing_cert = '', $private_key = '', $private_key_password = '', $extracerts = '', $cert_type = 2, $info = array())
  18358. {
  18359. // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
  18360. // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
  18361. // to convert pfx certificate to pem: openssl
  18362. // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
  18363. $this->sign = true;
  18364. ++ $this->n;
  18365. $this->sig_obj_id = $this->n; // signature widget
  18366. ++ $this->n; // signature object ($this->sig_obj_id + 1)
  18367. $this->signature_data = array();
  18368. if (strlen($signing_cert) == 0)
  18369. {
  18370. $signing_cert = 'file://' . dirname(__FILE__) . '/tcpdf.crt';
  18371. $private_key_password = 'tcpdfdemo';
  18372. }
  18373. if (strlen($private_key) == 0)
  18374. {
  18375. $private_key = $signing_cert;
  18376. }
  18377. $this->signature_data['signcert'] = $signing_cert;
  18378. $this->signature_data['privkey'] = $private_key;
  18379. $this->signature_data['password'] = $private_key_password;
  18380. $this->signature_data['extracerts'] = $extracerts;
  18381. $this->signature_data['cert_type'] = $cert_type;
  18382. $this->signature_data['info'] = $info;
  18383. }
  18384. /**
  18385. * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
  18386. * @param float $x Abscissa of the upper-left corner.
  18387. * @param float $y Ordinate of the upper-left corner.
  18388. * @param float $w Width of the signature area.
  18389. * @param float $h Height of the signature area.
  18390. * @param int $page option page number (if < 0 the current page is used).
  18391. * @access public
  18392. * @author Nicola Asuni
  18393. * @since 5.3.011 (2010-06-17)
  18394. */
  18395. public function setSignatureAppearance($x = 0, $y = 0, $w = 0, $h = 0, $page = -1)
  18396. {
  18397. if (($page < 1) or ($page > $this->numpages))
  18398. {
  18399. $this->signature_appearance['page'] = $this->page;
  18400. }
  18401. else
  18402. {
  18403. $this->signature_appearance['page'] = intval($page);
  18404. }
  18405. $a = $x * $this->k;
  18406. $b = $this->pagedim[($this->signature_appearance['page'])]['h'] - (($y + $h) * $this->k);
  18407. $c = $w * $this->k;
  18408. $d = $h * $this->k;
  18409. $this->signature_appearance['rect'] = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a + $c, $b + $d);
  18410. }
  18411. /**
  18412. * Create a new page group.
  18413. * NOTE: call this function before calling AddPage()
  18414. * @param int $page starting group page (leave empty for next page).
  18415. * @access public
  18416. * @since 3.0.000 (2008-03-27)
  18417. */
  18418. public function startPageGroup($page = '')
  18419. {
  18420. if (empty($page))
  18421. {
  18422. $page = $this->page + 1;
  18423. }
  18424. $this->newpagegroup[$page] = true;
  18425. }
  18426. /**
  18427. * Defines an alias for the total number of pages.
  18428. * It will be substituted as the document is closed.
  18429. * @param string $alias The alias.
  18430. * @access public
  18431. * @since 1.4
  18432. * @see getAliasNbPages(), PageNo(), Footer()
  18433. */
  18434. public function AliasNbPages($alias = '{nb}')
  18435. {
  18436. $this->AliasNbPages = $alias;
  18437. }
  18438. /**
  18439. * Returns the string alias used for the total number of pages.
  18440. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  18441. * @return string
  18442. * @access public
  18443. * @since 4.0.018 (2008-08-08)
  18444. * @see AliasNbPages(), PageNo(), Footer()
  18445. */
  18446. public function getAliasNbPages()
  18447. {
  18448. if ($this->isUnicodeFont())
  18449. {
  18450. return '{' . $this->AliasNbPages . '}';
  18451. }
  18452. return $this->AliasNbPages;
  18453. }
  18454. /**
  18455. * Defines an alias for the page number.
  18456. * It will be substituted as the document is closed.
  18457. * @param string $alias The alias.
  18458. * @access public
  18459. * @since 4.5.000 (2009-01-02)
  18460. * @see getAliasNbPages(), PageNo(), Footer()
  18461. */
  18462. public function AliasNumPage($alias = '{pnb}')
  18463. {
  18464. //Define an alias for total number of pages
  18465. $this->AliasNumPage = $alias;
  18466. }
  18467. /**
  18468. * Returns the string alias used for the page number.
  18469. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  18470. * @return string
  18471. * @access public
  18472. * @since 4.5.000 (2009-01-02)
  18473. * @see AliasNbPages(), PageNo(), Footer()
  18474. */
  18475. public function getAliasNumPage()
  18476. {
  18477. if ($this->isUnicodeFont())
  18478. {
  18479. return '{' . $this->AliasNumPage . '}';
  18480. }
  18481. return $this->AliasNumPage;
  18482. }
  18483. /**
  18484. * Return the current page in the group.
  18485. * @return current page in the group
  18486. * @access public
  18487. * @since 3.0.000 (2008-03-27)
  18488. */
  18489. public function getGroupPageNo()
  18490. {
  18491. return $this->pagegroups[$this->currpagegroup];
  18492. }
  18493. /**
  18494. * Returns the current group page number formatted as a string.
  18495. * @access public
  18496. * @since 4.3.003 (2008-11-18)
  18497. * @see PaneNo(), formatPageNumber()
  18498. */
  18499. public function getGroupPageNoFormatted()
  18500. {
  18501. return $this->formatPageNumber($this->getGroupPageNo());
  18502. }
  18503. /**
  18504. * Return the alias of the current page group
  18505. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  18506. * (will be replaced by the total number of pages in this group).
  18507. * @return alias of the current page group
  18508. * @access public
  18509. * @since 3.0.000 (2008-03-27)
  18510. */
  18511. public function getPageGroupAlias()
  18512. {
  18513. if ($this->isUnicodeFont())
  18514. {
  18515. return '{' . $this->currpagegroup . '}';
  18516. }
  18517. return $this->currpagegroup;
  18518. }
  18519. /**
  18520. * Return the alias for the page number on the current page group
  18521. * If the current font is unicode type, the returned string is surrounded by additional curly braces.
  18522. * (will be replaced by the total number of pages in this group).
  18523. * @return alias of the current page group
  18524. * @access public
  18525. * @since 4.5.000 (2009-01-02)
  18526. */
  18527. public function getPageNumGroupAlias()
  18528. {
  18529. if ($this->isUnicodeFont())
  18530. {
  18531. return '{' . str_replace('{nb', '{pnb', $this->currpagegroup) . '}';
  18532. }
  18533. return str_replace('{nb', '{pnb', $this->currpagegroup);
  18534. }
  18535. /**
  18536. * Format the page numbers.
  18537. * This method can be overriden for custom formats.
  18538. * @param int $num page number
  18539. * @access protected
  18540. * @since 4.2.005 (2008-11-06)
  18541. */
  18542. protected function formatPageNumber($num)
  18543. {
  18544. return number_format((float) $num, 0, '', '.');
  18545. }
  18546. /**
  18547. * Format the page numbers on the Table Of Content.
  18548. * This method can be overriden for custom formats.
  18549. * @param int $num page number
  18550. * @access protected
  18551. * @since 4.5.001 (2009-01-04)
  18552. * @see addTOC(), addHTMLTOC()
  18553. */
  18554. protected function formatTOCPageNumber($num)
  18555. {
  18556. return number_format((float) $num, 0, '', '.');
  18557. }
  18558. /**
  18559. * Returns the current page number formatted as a string.
  18560. * @access public
  18561. * @since 4.2.005 (2008-11-06)
  18562. * @see PaneNo(), formatPageNumber()
  18563. */
  18564. public function PageNoFormatted()
  18565. {
  18566. return $this->formatPageNumber($this->PageNo());
  18567. }
  18568. /**
  18569. * Put visibility settings.
  18570. * @access protected
  18571. * @since 3.0.000 (2008-03-27)
  18572. */
  18573. protected function _putocg()
  18574. {
  18575. $this->n_ocg_print = $this->_newobj();
  18576. $this->_out('<< /Type /OCG /Name ' . $this->_textstring('print', $this->n_ocg_print) . ' /Usage << /Print <</PrintState /ON>> /View <</ViewState /OFF>> >> >>' . "\n" . 'endobj');
  18577. $this->n_ocg_view = $this->_newobj();
  18578. $this->_out('<< /Type /OCG /Name ' . $this->_textstring('view', $this->n_ocg_view) . ' /Usage << /Print <</PrintState /OFF>> /View <</ViewState /ON>> >> >>' . "\n" . 'endobj');
  18579. }
  18580. /**
  18581. * Set the visibility of the successive elements.
  18582. * This can be useful, for instance, to put a background
  18583. * image or color that will show on screen but won't print.
  18584. * @param string $v visibility mode. Legal values are: all, print, screen.
  18585. * @access public
  18586. * @since 3.0.000 (2008-03-27)
  18587. */
  18588. public function setVisibility($v)
  18589. {
  18590. if ($this->openMarkedContent)
  18591. {
  18592. // close existing open marked-content
  18593. $this->_out('EMC');
  18594. $this->openMarkedContent = false;
  18595. }
  18596. switch ($v)
  18597. {
  18598. case 'print' :
  18599. {
  18600. $this->_out('/OC /OC1 BDC');
  18601. $this->openMarkedContent = true;
  18602. break;
  18603. }
  18604. case 'screen' :
  18605. {
  18606. $this->_out('/OC /OC2 BDC');
  18607. $this->openMarkedContent = true;
  18608. break;
  18609. }
  18610. case 'all' :
  18611. {
  18612. $this->_out('');
  18613. break;
  18614. }
  18615. default :
  18616. {
  18617. $this->Error('Incorrect visibility: ' . $v);
  18618. break;
  18619. }
  18620. }
  18621. $this->visibility = $v;
  18622. }
  18623. /**
  18624. * Add transparency parameters to the current extgstate
  18625. * @param array $params parameters
  18626. * @return the number of extgstates
  18627. * @access protected
  18628. * @since 3.0.000 (2008-03-27)
  18629. */
  18630. protected function addExtGState($parms)
  18631. {
  18632. $n = count($this->extgstates) + 1;
  18633. // check if this ExtGState already exist
  18634. for($i = 1; $i < $n; ++ $i)
  18635. {
  18636. if ($this->extgstates[$i]['parms'] == $parms)
  18637. {
  18638. // return reference to existing ExtGState
  18639. return $i;
  18640. }
  18641. }
  18642. $this->extgstates[$n]['parms'] = $parms;
  18643. return $n;
  18644. }
  18645. /**
  18646. * Add an extgstate
  18647. * @param array $gs extgstate
  18648. * @access protected
  18649. * @since 3.0.000 (2008-03-27)
  18650. */
  18651. protected function setExtGState($gs)
  18652. {
  18653. $this->_out(sprintf('/GS%d gs', $gs));
  18654. }
  18655. /**
  18656. * Put extgstates for object transparency
  18657. * @param array $gs extgstate
  18658. * @access protected
  18659. * @since 3.0.000 (2008-03-27)
  18660. */
  18661. protected function _putextgstates()
  18662. {
  18663. $ne = count($this->extgstates);
  18664. for($i = 1; $i <= $ne; ++ $i)
  18665. {
  18666. $this->extgstates[$i]['n'] = $this->_newobj();
  18667. $out = '<< /Type /ExtGState';
  18668. foreach ($this->extgstates[$i]['parms'] as $k => $v)
  18669. {
  18670. if (is_float($v))
  18671. {
  18672. $v = sprintf('%.2F', $v);
  18673. }
  18674. $out .= ' /' . $k . ' ' . $v;
  18675. }
  18676. $out .= ' >>';
  18677. $out .= "\n" . 'endobj';
  18678. $this->_out($out);
  18679. }
  18680. }
  18681. /**
  18682. * Set alpha for stroking (CA) and non-stroking (ca) operations.
  18683. * @param float $alpha real value from 0 (transparent) to 1 (opaque)
  18684. * @param string $bm blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  18685. * @access public
  18686. * @since 3.0.000 (2008-03-27)
  18687. */
  18688. public function setAlpha($alpha, $bm = 'Normal')
  18689. {
  18690. $gs = $this->addExtGState(array('ca' => $alpha, 'CA' => $alpha, 'BM' => '/' . $bm, 'AIS' => 'false'));
  18691. $this->setExtGState($gs);
  18692. }
  18693. /**
  18694. * Set the default JPEG compression quality (1-100)
  18695. * @param int $quality JPEG quality, integer between 1 and 100
  18696. * @access public
  18697. * @since 3.0.000 (2008-03-27)
  18698. */
  18699. public function setJPEGQuality($quality)
  18700. {
  18701. if (($quality < 1) or ($quality > 100))
  18702. {
  18703. $quality = 75;
  18704. }
  18705. $this->jpeg_quality = intval($quality);
  18706. }
  18707. /**
  18708. * Set the default number of columns in a row for HTML tables.
  18709. * @param int $cols number of columns
  18710. * @access public
  18711. * @since 3.0.014 (2008-06-04)
  18712. */
  18713. public function setDefaultTableColumns($cols = 4)
  18714. {
  18715. $this->default_table_columns = intval($cols);
  18716. }
  18717. /**
  18718. * Set the height of the cell (line height) respect the font height.
  18719. * @param int $h cell proportion respect font height (typical value = 1.25).
  18720. * @access public
  18721. * @since 3.0.014 (2008-06-04)
  18722. */
  18723. public function setCellHeightRatio($h)
  18724. {
  18725. $this->cell_height_ratio = $h;
  18726. }
  18727. /**
  18728. * return the height of cell repect font height.
  18729. * @access public
  18730. * @since 4.0.012 (2008-07-24)
  18731. */
  18732. public function getCellHeightRatio()
  18733. {
  18734. return $this->cell_height_ratio;
  18735. }
  18736. /**
  18737. * Set the PDF version (check PDF reference for valid values).
  18738. * Default value is 1.t
  18739. * @access public
  18740. * @since 3.1.000 (2008-06-09)
  18741. */
  18742. public function setPDFVersion($version = '1.7')
  18743. {
  18744. $this->PDFVersion = $version;
  18745. }
  18746. /**
  18747. * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
  18748. * (see Section 8.1 of PDF reference, "Viewer Preferences").
  18749. * <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>
  18750. * @param array $preferences array of options.
  18751. * @author Nicola Asuni
  18752. * @access public
  18753. * @since 3.1.000 (2008-06-09)
  18754. */
  18755. public function setViewerPreferences($preferences)
  18756. {
  18757. $this->viewer_preferences = $preferences;
  18758. }
  18759. /**
  18760. * Paints color transition registration bars
  18761. * @param float $x abscissa of the top left corner of the rectangle.
  18762. * @param float $y ordinate of the top left corner of the rectangle.
  18763. * @param float $w width of the rectangle.
  18764. * @param float $h height of the rectangle.
  18765. * @param boolean $transition if true prints tcolor transitions to white.
  18766. * @param boolean $vertical if true prints bar vertically.
  18767. * @param string $colors colors to print, one letter per color separated by comma (for example 'A,W,R,G,B,C,M,Y,K'): A=black, W=white, R=red, G=green, B=blue, C=cyan, M=magenta, Y=yellow, K=black.
  18768. * @author Nicola Asuni
  18769. * @since 4.9.000 (2010-03-26)
  18770. * @access public
  18771. */
  18772. public function colorRegistrationBar($x, $y, $w, $h, $transition = true, $vertical = false, $colors = 'A,R,G,B,C,M,Y,K')
  18773. {
  18774. $bars = explode(',', $colors);
  18775. $numbars = count($bars); // number of bars to print
  18776. // set bar measures
  18777. if ($vertical)
  18778. {
  18779. $coords = array(0, 0, 0, 1);
  18780. $wb = $w / $numbars; // bar width
  18781. $hb = $h; // bar height
  18782. $xd = $wb; // delta x
  18783. $yd = 0; // delta y
  18784. }
  18785. else
  18786. {
  18787. $coords = array(1, 0, 0, 0);
  18788. $wb = $w; // bar width
  18789. $hb = $h / $numbars; // bar height
  18790. $xd = 0; // delta x
  18791. $yd = $hb; // delta y
  18792. }
  18793. $xb = $x;
  18794. $yb = $y;
  18795. foreach ($bars as $col)
  18796. {
  18797. switch ($col)
  18798. {
  18799. // set transition colors
  18800. case 'A' :
  18801. { // BLACK
  18802. $col_a = array(255);
  18803. $col_b = array(0);
  18804. break;
  18805. }
  18806. case 'W' :
  18807. { // WHITE
  18808. $col_a = array(0);
  18809. $col_b = array(255);
  18810. break;
  18811. }
  18812. case 'R' :
  18813. { // R
  18814. $col_a = array(255, 255, 255);
  18815. $col_b = array(255, 0, 0);
  18816. break;
  18817. }
  18818. case 'G' :
  18819. { // G
  18820. $col_a = array(255, 255, 255);
  18821. $col_b = array(0, 255, 0);
  18822. break;
  18823. }
  18824. case 'B' :
  18825. { // B
  18826. $col_a = array(255, 255, 255);
  18827. $col_b = array(0, 0, 255);
  18828. break;
  18829. }
  18830. case 'C' :
  18831. { // C
  18832. $col_a = array(0, 0, 0, 0);
  18833. $col_b = array(100, 0, 0, 0);
  18834. break;
  18835. }
  18836. case 'M' :
  18837. { // M
  18838. $col_a = array(0, 0, 0, 0);
  18839. $col_b = array(0, 100, 0, 0);
  18840. break;
  18841. }
  18842. case 'Y' :
  18843. { // Y
  18844. $col_a = array(0, 0, 0, 0);
  18845. $col_b = array(0, 0, 100, 0);
  18846. break;
  18847. }
  18848. case 'K' :
  18849. { // K
  18850. $col_a = array(0, 0, 0, 0);
  18851. $col_b = array(0, 0, 0, 100);
  18852. break;
  18853. }
  18854. default :
  18855. { // GRAY
  18856. $col_a = array(255);
  18857. $col_b = array(0);
  18858. break;
  18859. }
  18860. }
  18861. if ($transition)
  18862. {
  18863. // color gradient
  18864. $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
  18865. }
  18866. else
  18867. {
  18868. // color rectangle
  18869. $this->SetFillColorArray($col_b);
  18870. $this->Rect($xb, $yb, $wb, $hb, 'F', array());
  18871. }
  18872. $xb += $xd;
  18873. $yb += $yd;
  18874. }
  18875. }
  18876. /**
  18877. * Paints crop mark
  18878. * @param float $x abscissa of the crop mark center.
  18879. * @param float $y ordinate of the crop mark center.
  18880. * @param float $w width of the crop mark.
  18881. * @param float $h height of the crop mark.
  18882. * @param string $type type of crop mark, one sybol per type separated by comma: A = top left, B = top right, C = bottom left, D = bottom right.
  18883. * @param array $color crop mark color (default black).
  18884. * @author Nicola Asuni
  18885. * @since 4.9.000 (2010-03-26)
  18886. * @access public
  18887. */
  18888. public function cropMark($x, $y, $w, $h, $type = 'A,B,C,D', $color = array(0,0,0))
  18889. {
  18890. $this->SetLineStyle(array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0,
  18891. 'color' => $color));
  18892. $crops = explode(',', $type);
  18893. $numcrops = count($crops); // number of crop marks to print
  18894. $dw = $w / 4; // horizontal space to leave before the intersection point
  18895. $dh = $h / 4; // vertical space to leave before the intersection point
  18896. foreach ($crops as $crop)
  18897. {
  18898. switch ($crop)
  18899. {
  18900. case 'A' :
  18901. {
  18902. $x1 = $x;
  18903. $y1 = $y - $h;
  18904. $x2 = $x;
  18905. $y2 = $y - $dh;
  18906. $x3 = $x - $w;
  18907. $y3 = $y;
  18908. $x4 = $x - $dw;
  18909. $y4 = $y;
  18910. break;
  18911. }
  18912. case 'B' :
  18913. {
  18914. $x1 = $x;
  18915. $y1 = $y - $h;
  18916. $x2 = $x;
  18917. $y2 = $y - $dh;
  18918. $x3 = $x + $dw;
  18919. $y3 = $y;
  18920. $x4 = $x + $w;
  18921. $y4 = $y;
  18922. break;
  18923. }
  18924. case 'C' :
  18925. {
  18926. $x1 = $x - $w;
  18927. $y1 = $y;
  18928. $x2 = $x - $dw;
  18929. $y2 = $y;
  18930. $x3 = $x;
  18931. $y3 = $y + $dh;
  18932. $x4 = $x;
  18933. $y4 = $y + $h;
  18934. break;
  18935. }
  18936. case 'D' :
  18937. {
  18938. $x1 = $x + $dw;
  18939. $y1 = $y;
  18940. $x2 = $x + $w;
  18941. $y2 = $y;
  18942. $x3 = $x;
  18943. $y3 = $y + $dh;
  18944. $x4 = $x;
  18945. $y4 = $y + $h;
  18946. break;
  18947. }
  18948. }
  18949. $this->Line($x1, $y1, $x2, $y2);
  18950. $this->Line($x3, $y3, $x4, $y4);
  18951. }
  18952. }
  18953. /**
  18954. * Paints a registration mark
  18955. * @param float $x abscissa of the registration mark center.
  18956. * @param float $y ordinate of the registration mark center.
  18957. * @param float $r radius of the crop mark.
  18958. * @param boolean $double if true print two concentric crop marks.
  18959. * @param array $cola crop mark color (default black).
  18960. * @param array $colb second crop mark color.
  18961. * @author Nicola Asuni
  18962. * @since 4.9.000 (2010-03-26)
  18963. * @access public
  18964. */
  18965. public function registrationMark($x, $y, $r, $double = false, $cola = array(0,0,0), $colb = array(255,255,255))
  18966. {
  18967. $line_style = array('width' => (0.5 / $this->k), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0,
  18968. 'color' => $cola);
  18969. $this->SetFillColorArray($cola);
  18970. $this->PieSector($x, $y, $r, 90, 180, 'F');
  18971. $this->PieSector($x, $y, $r, 270, 360, 'F');
  18972. $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
  18973. if ($double)
  18974. {
  18975. $r2 = $r * 0.5;
  18976. $this->SetFillColorArray($colb);
  18977. $this->PieSector($x, $y, $r2, 90, 180, 'F');
  18978. $this->PieSector($x, $y, $r2, 270, 360, 'F');
  18979. $this->SetFillColorArray($cola);
  18980. $this->PieSector($x, $y, $r2, 0, 90, 'F');
  18981. $this->PieSector($x, $y, $r2, 180, 270, 'F');
  18982. $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8);
  18983. }
  18984. }
  18985. /**
  18986. * Paints a linear colour gradient.
  18987. * @param float $x abscissa of the top left corner of the rectangle.
  18988. * @param float $y ordinate of the top left corner of the rectangle.
  18989. * @param float $w width of the rectangle.
  18990. * @param float $h height of the rectangle.
  18991. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  18992. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  18993. * @param array $coords array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  18994. * @author Andreas W�rmser, Nicola Asuni
  18995. * @since 3.1.000 (2008-06-09)
  18996. * @access public
  18997. */
  18998. public function LinearGradient($x, $y, $w, $h, $col1 = array(), $col2 = array(), $coords = array(0,0,1,0))
  18999. {
  19000. $this->Clip($x, $y, $w, $h);
  19001. $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1),
  19002. array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  19003. }
  19004. /**
  19005. * Paints a radial colour gradient.
  19006. * @param float $x abscissa of the top left corner of the rectangle.
  19007. * @param float $y ordinate of the top left corner of the rectangle.
  19008. * @param float $w width of the rectangle.
  19009. * @param float $h height of the rectangle.
  19010. * @param array $col1 first color (Grayscale, RGB or CMYK components).
  19011. * @param array $col2 second color (Grayscale, RGB or CMYK components).
  19012. * @param array $coords array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined.
  19013. * @author Andreas W�rmser, Nicola Asuni
  19014. * @since 3.1.000 (2008-06-09)
  19015. * @access public
  19016. */
  19017. public function RadialGradient($x, $y, $w, $h, $col1 = array(), $col2 = array(), $coords = array(0.5,0.5,0.5,0.5,1))
  19018. {
  19019. $this->Clip($x, $y, $w, $h);
  19020. $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1),
  19021. array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
  19022. }
  19023. /**
  19024. * Paints a coons patch mesh.
  19025. * @param float $x abscissa of the top left corner of the rectangle.
  19026. * @param float $y ordinate of the top left corner of the rectangle.
  19027. * @param float $w width of the rectangle.
  19028. * @param float $h height of the rectangle.
  19029. * @param array $col1 first color (lower left corner) (RGB components).
  19030. * @param array $col2 second color (lower right corner) (RGB components).
  19031. * @param array $col3 third color (upper right corner) (RGB components).
  19032. * @param array $col4 fourth color (upper left corner) (RGB components).
  19033. * @param array $coords <ul><li>for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).</li><li>for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches</li></ul>
  19034. * @param array $coords_min minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
  19035. * @param array $coords_max maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
  19036. * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  19037. * @author Andreas W�rmser, Nicola Asuni
  19038. * @since 3.1.000 (2008-06-09)
  19039. * @access public
  19040. */
  19041. 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)
  19042. {
  19043. $this->Clip($x, $y, $w, $h);
  19044. $n = count($this->gradients) + 1;
  19045. $this->gradients[$n] = array();
  19046. $this->gradients[$n]['type'] = 6; //coons patch mesh
  19047. $this->gradients[$n]['coords'] = array();
  19048. $this->gradients[$n]['antialias'] = $antialias;
  19049. $this->gradients[$n]['colors'] = array();
  19050. $this->gradients[$n]['transparency'] = false;
  19051. //check the coords array if it is the simple array or the multi patch array
  19052. if (! isset($coords[0]['f']))
  19053. {
  19054. //simple array -> convert to multi patch array
  19055. if (! isset($col1[1]))
  19056. {
  19057. $col1[1] = $col1[2] = $col1[0];
  19058. }
  19059. if (! isset($col2[1]))
  19060. {
  19061. $col2[1] = $col2[2] = $col2[0];
  19062. }
  19063. if (! isset($col3[1]))
  19064. {
  19065. $col3[1] = $col3[2] = $col3[0];
  19066. }
  19067. if (! isset($col4[1]))
  19068. {
  19069. $col4[1] = $col4[2] = $col4[0];
  19070. }
  19071. $patch_array[0]['f'] = 0;
  19072. $patch_array[0]['points'] = $coords;
  19073. $patch_array[0]['colors'][0]['r'] = $col1[0];
  19074. $patch_array[0]['colors'][0]['g'] = $col1[1];
  19075. $patch_array[0]['colors'][0]['b'] = $col1[2];
  19076. $patch_array[0]['colors'][1]['r'] = $col2[0];
  19077. $patch_array[0]['colors'][1]['g'] = $col2[1];
  19078. $patch_array[0]['colors'][1]['b'] = $col2[2];
  19079. $patch_array[0]['colors'][2]['r'] = $col3[0];
  19080. $patch_array[0]['colors'][2]['g'] = $col3[1];
  19081. $patch_array[0]['colors'][2]['b'] = $col3[2];
  19082. $patch_array[0]['colors'][3]['r'] = $col4[0];
  19083. $patch_array[0]['colors'][3]['g'] = $col4[1];
  19084. $patch_array[0]['colors'][3]['b'] = $col4[2];
  19085. }
  19086. else
  19087. {
  19088. //multi patch array
  19089. $patch_array = $coords;
  19090. }
  19091. $bpcd = 65535; //16 bits per coordinate
  19092. //build the data stream
  19093. $this->gradients[$n]['stream'] = '';
  19094. $count_patch = count($patch_array);
  19095. for($i = 0; $i < $count_patch; ++ $i)
  19096. {
  19097. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  19098. $count_points = count($patch_array[$i]['points']);
  19099. for($j = 0; $j < $count_points; ++ $j)
  19100. {
  19101. //each point as 16 bit
  19102. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
  19103. if ($patch_array[$i]['points'][$j] < 0)
  19104. {
  19105. $patch_array[$i]['points'][$j] = 0;
  19106. }
  19107. if ($patch_array[$i]['points'][$j] > $bpcd)
  19108. {
  19109. $patch_array[$i]['points'][$j] = $bpcd;
  19110. }
  19111. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
  19112. $this->gradients[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] % 256));
  19113. }
  19114. $count_cols = count($patch_array[$i]['colors']);
  19115. for($j = 0; $j < $count_cols; ++ $j)
  19116. {
  19117. //each color component as 8 bit
  19118. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
  19119. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
  19120. $this->gradients[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
  19121. }
  19122. }
  19123. //paint the gradient
  19124. $this->_out('/Sh' . $n . ' sh');
  19125. //restore previous Graphic State
  19126. $this->_out('Q');
  19127. }
  19128. /**
  19129. * Set a rectangular clipping area.
  19130. * @param float $x abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
  19131. * @param float $y ordinate of the top left corner of the rectangle.
  19132. * @param float $w width of the rectangle.
  19133. * @param float $h height of the rectangle.
  19134. * @author Andreas W�rmser, Nicola Asuni
  19135. * @since 3.1.000 (2008-06-09)
  19136. * @access protected
  19137. */
  19138. protected function Clip($x, $y, $w, $h)
  19139. {
  19140. if ($this->rtl)
  19141. {
  19142. $x = $this->w - $x - $w;
  19143. }
  19144. //save current Graphic State
  19145. $s = 'q';
  19146. //set clipping area
  19147. $s .= sprintf(' %.2F %.2F %.2F %.2F re W n', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, - $h * $this->k);
  19148. //set up transformation matrix for gradient
  19149. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k);
  19150. $this->_out($s);
  19151. }
  19152. /**
  19153. * Output gradient.
  19154. * @param int $type type of gradient (1 Function-based shading; 2 Axial shading; 3 Radial shading; 4 Free-form Gouraud-shaded triangle mesh; 5 Lattice-form Gouraud-shaded triangle mesh; 6 Coons patch mesh; 7 Tensor-product patch mesh). (Not all types are currently supported)
  19155. * @param array $coords array of coordinates.
  19156. * @param array $stops array gradient color components: color = array of GRAY, RGB or CMYK color components; offset = (0 to 1) represents a location along the gradient vector; exponent = exponent of the exponential interpolation function (default = 1).
  19157. * @param array $background An array of colour components appropriate to the colour space, specifying a single background colour value.
  19158. * @param boolean $antialias A flag indicating whether to filter the shading function to prevent aliasing artifacts.
  19159. * @author Nicola Asuni
  19160. * @since 3.1.000 (2008-06-09)
  19161. * @access public
  19162. */
  19163. public function Gradient($type, $coords, $stops, $background = array(), $antialias = false)
  19164. {
  19165. $n = count($this->gradients) + 1;
  19166. $this->gradients[$n] = array();
  19167. $this->gradients[$n]['type'] = $type;
  19168. $this->gradients[$n]['coords'] = $coords;
  19169. $this->gradients[$n]['antialias'] = $antialias;
  19170. $this->gradients[$n]['colors'] = array();
  19171. $this->gradients[$n]['transparency'] = false;
  19172. // color space
  19173. $numcolspace = count($stops[0]['color']);
  19174. $bcolor = array_values($background);
  19175. switch ($numcolspace)
  19176. {
  19177. case 4 :
  19178. { // CMYK
  19179. $this->gradients[$n]['colspace'] = 'DeviceCMYK';
  19180. if (! empty($background))
  19181. {
  19182. $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F %.3F', $bcolor[0] / 100, $bcolor[1] / 100, $bcolor[2] / 100, $bcolor[3] / 100);
  19183. }
  19184. break;
  19185. }
  19186. case 3 :
  19187. { // RGB
  19188. $this->gradients[$n]['colspace'] = 'DeviceRGB';
  19189. if (! empty($background))
  19190. {
  19191. $this->gradients[$n]['background'] = sprintf('%.3F %.3F %.3F', $bcolor[0] / 255, $bcolor[1] / 255, $bcolor[2] / 255);
  19192. }
  19193. break;
  19194. }
  19195. case 1 :
  19196. { // Gray scale
  19197. $this->gradients[$n]['colspace'] = 'DeviceGray';
  19198. if (! empty($background))
  19199. {
  19200. $this->gradients[$n]['background'] = sprintf('%.3F', $bcolor[0] / 255);
  19201. }
  19202. break;
  19203. }
  19204. }
  19205. $num_stops = count($stops);
  19206. $last_stop_id = $num_stops - 1;
  19207. foreach ($stops as $key => $stop)
  19208. {
  19209. $this->gradients[$n]['colors'][$key] = array();
  19210. // offset represents a location along the gradient vector
  19211. if (isset($stop['offset']))
  19212. {
  19213. $this->gradients[$n]['colors'][$key]['offset'] = $stop['offset'];
  19214. }
  19215. else
  19216. {
  19217. if ($key == 0)
  19218. {
  19219. $this->gradients[$n]['colors'][$key]['offset'] = 0;
  19220. }
  19221. elseif ($key == $last_stop_id)
  19222. {
  19223. $this->gradients[$n]['colors'][$key]['offset'] = 1;
  19224. }
  19225. else
  19226. {
  19227. $offsetstep = (1 - $this->gradients[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
  19228. $this->gradients[$n]['colors'][$key]['offset'] = $this->gradients[$n]['colors'][($key - 1)]['offset'] + $offsetstep;
  19229. }
  19230. }
  19231. if (isset($stop['opacity']))
  19232. {
  19233. $this->gradients[$n]['colors'][$key]['opacity'] = $stop['opacity'];
  19234. if ($stop['opacity'] < 1)
  19235. {
  19236. $this->gradients[$n]['transparency'] = true;
  19237. }
  19238. }
  19239. else
  19240. {
  19241. $this->gradients[$n]['colors'][$key]['opacity'] = 1;
  19242. }
  19243. // exponent for the exponential interpolation function
  19244. if (isset($stop['exponent']))
  19245. {
  19246. $this->gradients[$n]['colors'][$key]['exponent'] = $stop['exponent'];
  19247. }
  19248. else
  19249. {
  19250. $this->gradients[$n]['colors'][$key]['exponent'] = 1;
  19251. }
  19252. // set colors
  19253. $color = array_values($stop['color']);
  19254. switch ($numcolspace)
  19255. {
  19256. case 4 :
  19257. { // CMYK
  19258. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F %.3F', $color[0] / 100, $color[1] / 100, $color[2] / 100, $color[3] / 100);
  19259. break;
  19260. }
  19261. case 3 :
  19262. { // RGB
  19263. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F', $color[0] / 255, $color[1] / 255, $color[2] / 255);
  19264. break;
  19265. }
  19266. case 1 :
  19267. { // Gray scale
  19268. $this->gradients[$n]['colors'][$key]['color'] = sprintf('%.3F', $color[0] / 255);
  19269. break;
  19270. }
  19271. }
  19272. }
  19273. if ($this->gradients[$n]['transparency'])
  19274. {
  19275. // paint luminosity gradient
  19276. $this->_out('/TGS' . $n . ' gs');
  19277. }
  19278. //paint the gradient
  19279. $this->_out('/Sh' . $n . ' sh');
  19280. //restore previous Graphic State
  19281. $this->_out('Q');
  19282. }
  19283. /**
  19284. * Output gradient shaders.
  19285. * @author Nicola Asuni
  19286. * @since 3.1.000 (2008-06-09)
  19287. * @access protected
  19288. */
  19289. function _putshaders()
  19290. {
  19291. $idt = count($this->gradients); //index for transparency gradients
  19292. foreach ($this->gradients as $id => $grad)
  19293. {
  19294. if (($grad['type'] == 2) or ($grad['type'] == 3))
  19295. {
  19296. $fc = $this->_newobj();
  19297. $out = '<<';
  19298. $out .= ' /FunctionType 3';
  19299. $out .= ' /Domain [0 1]';
  19300. $functions = '';
  19301. $bounds = '';
  19302. $encode = '';
  19303. $i = 1;
  19304. $num_cols = count($grad['colors']);
  19305. $lastcols = $num_cols - 1;
  19306. for($i = 1; $i < $num_cols; ++ $i)
  19307. {
  19308. $functions .= ($fc + $i) . ' 0 R ';
  19309. if ($i < $lastcols)
  19310. {
  19311. $bounds .= sprintf('%.3F ', $grad['colors'][$i]['offset']);
  19312. }
  19313. $encode .= '0 1 ';
  19314. }
  19315. $out .= ' /Functions [' . trim($functions) . ']';
  19316. $out .= ' /Bounds [' . trim($bounds) . ']';
  19317. $out .= ' /Encode [' . trim($encode) . ']';
  19318. $out .= ' >>';
  19319. $out .= "\n" . 'endobj';
  19320. $this->_out($out);
  19321. for($i = 1; $i < $num_cols; ++ $i)
  19322. {
  19323. $this->_newobj();
  19324. $out = '<<';
  19325. $out .= ' /FunctionType 2';
  19326. $out .= ' /Domain [0 1]';
  19327. $out .= ' /C0 [' . $grad['colors'][($i - 1)]['color'] . ']';
  19328. $out .= ' /C1 [' . $grad['colors'][$i]['color'] . ']';
  19329. $out .= ' /N ' . $grad['colors'][$i]['exponent'];
  19330. $out .= ' >>';
  19331. $out .= "\n" . 'endobj';
  19332. $this->_out($out);
  19333. }
  19334. // set transparency fuctions
  19335. if ($grad['transparency'])
  19336. {
  19337. $ft = $this->_newobj();
  19338. $out = '<<';
  19339. $out .= ' /FunctionType 3';
  19340. $out .= ' /Domain [0 1]';
  19341. $functions = '';
  19342. $i = 1;
  19343. $num_cols = count($grad['colors']);
  19344. for($i = 1; $i < $num_cols; ++ $i)
  19345. {
  19346. $functions .= ($ft + $i) . ' 0 R ';
  19347. }
  19348. $out .= ' /Functions [' . trim($functions) . ']';
  19349. $out .= ' /Bounds [' . trim($bounds) . ']';
  19350. $out .= ' /Encode [' . trim($encode) . ']';
  19351. $out .= ' >>';
  19352. $out .= "\n" . 'endobj';
  19353. $this->_out($out);
  19354. for($i = 1; $i < $num_cols; ++ $i)
  19355. {
  19356. $this->_newobj();
  19357. $out = '<<';
  19358. $out .= ' /FunctionType 2';
  19359. $out .= ' /Domain [0 1]';
  19360. $out .= ' /C0 [' . $grad['colors'][($i - 1)]['opacity'] . ']';
  19361. $out .= ' /C1 [' . $grad['colors'][$i]['opacity'] . ']';
  19362. $out .= ' /N ' . $grad['colors'][$i]['exponent'];
  19363. $out .= ' >>';
  19364. $out .= "\n" . 'endobj';
  19365. $this->_out($out);
  19366. }
  19367. }
  19368. }
  19369. // set shading object
  19370. $this->_newobj();
  19371. $out = '<< /ShadingType ' . $grad['type'];
  19372. if (isset($grad['colspace']))
  19373. {
  19374. $out .= ' /ColorSpace /' . $grad['colspace'];
  19375. }
  19376. else
  19377. {
  19378. $out .= ' /ColorSpace /DeviceRGB';
  19379. }
  19380. if (isset($grad['background']) and ! empty($grad['background']))
  19381. {
  19382. $out .= ' /Background [' . $grad['background'] . ']';
  19383. }
  19384. if (isset($grad['antialias']) and ($grad['antialias'] === true))
  19385. {
  19386. $out .= ' /AntiAlias true';
  19387. }
  19388. if ($grad['type'] == 2)
  19389. {
  19390. $out .= ' ' . sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
  19391. $out .= ' /Domain [0 1]';
  19392. $out .= ' /Function ' . $fc . ' 0 R';
  19393. $out .= ' /Extend [true true]';
  19394. $out .= ' >>';
  19395. }
  19396. elseif ($grad['type'] == 3)
  19397. {
  19398. //x0, y0, r0, x1, y1, r1
  19399. //at this this time radius of inner circle is 0
  19400. $out .= ' ' . sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
  19401. $out .= ' /Domain [0 1]';
  19402. $out .= ' /Function ' . $fc . ' 0 R';
  19403. $out .= ' /Extend [true true]';
  19404. $out .= ' >>';
  19405. }
  19406. elseif ($grad['type'] == 6)
  19407. {
  19408. $out .= ' /BitsPerCoordinate 16';
  19409. $out .= ' /BitsPerComponent 8';
  19410. $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
  19411. $out .= ' /BitsPerFlag 8';
  19412. $stream = $this->_getrawstream($grad['stream']);
  19413. $out .= ' /Length ' . strlen($stream);
  19414. $out .= ' >>';
  19415. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  19416. }
  19417. $out .= "\n" . 'endobj';
  19418. $this->_out($out);
  19419. if ($grad['transparency'])
  19420. {
  19421. $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
  19422. $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function ' . $ft . ' ', $shading_transparency);
  19423. }
  19424. $this->gradients[$id]['id'] = $this->n;
  19425. // set pattern object
  19426. $this->_newobj();
  19427. $out = '<< /Type /Pattern /PatternType 2';
  19428. $out .= ' /Shading ' . $this->gradients[$id]['id'] . ' 0 R';
  19429. $out .= ' >>';
  19430. $out .= "\n" . 'endobj';
  19431. $this->_out($out);
  19432. $this->gradients[$id]['pattern'] = $this->n;
  19433. // set shading and pattern for transparency mask
  19434. if ($grad['transparency'])
  19435. {
  19436. // luminosity pattern
  19437. $idgs = $id + $idt;
  19438. $this->_newobj();
  19439. $this->_out($shading_transparency);
  19440. $this->gradients[$idgs]['id'] = $this->n;
  19441. $this->_newobj();
  19442. $out = '<< /Type /Pattern /PatternType 2';
  19443. $out .= ' /Shading ' . $this->gradients[$idgs]['id'] . ' 0 R';
  19444. $out .= ' >>';
  19445. $out .= "\n" . 'endobj';
  19446. $this->_out($out);
  19447. $this->gradients[$idgs]['pattern'] = $this->n;
  19448. // luminosity XObject
  19449. $oid = $this->_newobj();
  19450. $this->xobjects['LX' . $oid] = array('n' => $oid);
  19451. $filter = '';
  19452. $stream = 'q /a0 gs /Pattern cs /p' . $idgs . ' scn 0 0 ' . $this->wPt . ' ' . $this->hPt . ' re f Q';
  19453. if ($this->compress)
  19454. {
  19455. $filter = ' /Filter /FlateDecode';
  19456. $stream = gzcompress($stream);
  19457. }
  19458. $stream = $this->_getrawstream($stream);
  19459. $out = '<< /Type /XObject /Subtype /Form /FormType 1' . $filter;
  19460. $out .= ' /Length ' . strlen($stream);
  19461. $rect = sprintf('%.2F %.2F', $this->wPt, $this->hPt);
  19462. $out .= ' /BBox [0 0 ' . $rect . ']';
  19463. $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
  19464. $out .= ' /Resources <<';
  19465. $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
  19466. $out .= ' /Pattern << /p' . $idgs . ' ' . $this->gradients[$idgs]['pattern'] . ' 0 R >>';
  19467. $out .= ' >>';
  19468. $out .= ' >> ';
  19469. $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
  19470. $out .= "\n" . 'endobj';
  19471. $this->_out($out);
  19472. // SMask
  19473. $this->_newobj();
  19474. $out = '<< /Type /Mask /S /Luminosity /G ' . ($this->n - 1) . ' 0 R >>' . "\n" . 'endobj';
  19475. $this->_out($out);
  19476. // ExtGState
  19477. $this->_newobj();
  19478. $out = '<< /Type /ExtGState /SMask ' . ($this->n - 1) . ' 0 R /AIS false >>' . "\n" . 'endobj';
  19479. $this->_out($out);
  19480. $this->extgstates[] = array('n' => $this->n, 'name' => 'TGS' . $id);
  19481. }
  19482. }
  19483. }
  19484. /**
  19485. * Draw the sector of a circle.
  19486. * It can be used for instance to render pie charts.
  19487. * @param float $xc abscissa of the center.
  19488. * @param float $yc ordinate of the center.
  19489. * @param float $r radius.
  19490. * @param float $a start angle (in degrees).
  19491. * @param float $b end angle (in degrees).
  19492. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  19493. * @param float $cw: indicates whether to go clockwise (default: true).
  19494. * @param float $o: origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
  19495. * @author Maxime Delorme, Nicola Asuni
  19496. * @since 3.1.000 (2008-06-09)
  19497. * @access public
  19498. */
  19499. public function PieSector($xc, $yc, $r, $a, $b, $style = 'FD', $cw = true, $o = 90)
  19500. {
  19501. $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
  19502. }
  19503. /**
  19504. * Draw the sector of an ellipse.
  19505. * It can be used for instance to render pie charts.
  19506. * @param float $xc abscissa of the center.
  19507. * @param float $yc ordinate of the center.
  19508. * @param float $rx the x-axis radius.
  19509. * @param float $ry the y-axis radius.
  19510. * @param float $a start angle (in degrees).
  19511. * @param float $b end angle (in degrees).
  19512. * @param string $style Style of rendering. See the getPathPaintOperator() function for more information.
  19513. * @param float $cw: indicates whether to go clockwise.
  19514. * @param float $o: origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
  19515. * @param integer $nc Number of curves used to draw a 90 degrees portion of arc.
  19516. * @author Maxime Delorme, Nicola Asuni
  19517. * @since 3.1.000 (2008-06-09)
  19518. * @access public
  19519. */
  19520. public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style = 'FD', $cw = false, $o = 0, $nc = 2)
  19521. {
  19522. if ($this->rtl)
  19523. {
  19524. $xc = $this->w - $xc;
  19525. }
  19526. $op = $this->getPathPaintOperator($style);
  19527. if ($op == 'f')
  19528. {
  19529. $line_style = array();
  19530. }
  19531. if ($cw)
  19532. {
  19533. $d = $b;
  19534. $b = 360 - $a + $o;
  19535. $a = 360 - $d + $o;
  19536. }
  19537. else
  19538. {
  19539. $b += $o;
  19540. $a += $o;
  19541. }
  19542. $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
  19543. $this->_out($op);
  19544. }
  19545. /**
  19546. * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
  19547. * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  19548. * Only vector drawing is supported, not text or bitmap.
  19549. * 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).
  19550. * @param string $file Name of the file containing the image.
  19551. * @param float $x Abscissa of the upper-left corner.
  19552. * @param float $y Ordinate of the upper-left corner.
  19553. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  19554. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  19555. * @param mixed $link URL or identifier returned by AddLink().
  19556. * @param boolean useBoundingBox specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
  19557. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  19558. * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  19559. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  19560. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  19561. * @author Valentin Schmidt, Nicola Asuni
  19562. * @since 3.1.000 (2008-06-09)
  19563. * @access public
  19564. */
  19565. public function ImageEps($file, $x = '', $y = '', $w = 0, $h = 0, $link = '', $useBoundingBox = true, $align = '', $palign = '', $border = 0, $fitonpage = false)
  19566. {
  19567. if ($this->rasterize_vector_images and ($w > 0) and ($h > 0))
  19568. {
  19569. // convert EPS to raster image using GD or ImageMagick libraries
  19570. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  19571. }
  19572. if ($x === '')
  19573. {
  19574. $x = $this->x;
  19575. }
  19576. if ($y === '')
  19577. {
  19578. $y = $this->y;
  19579. }
  19580. // check page for no-write regions and adapt page margins if necessary
  19581. $this->checkPageRegions($h, $x, $y);
  19582. $k = $this->k;
  19583. $data = file_get_contents($file);
  19584. if ($data === false)
  19585. {
  19586. $this->Error('EPS file not found: ' . $file);
  19587. }
  19588. $regs = array();
  19589. // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
  19590. preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
  19591. if (count($regs) > 1)
  19592. {
  19593. $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
  19594. if (strpos($version_str, 'Adobe Illustrator') !== false)
  19595. {
  19596. $versexp = explode(' ', $version_str);
  19597. $version = (float) array_pop($versexp);
  19598. if ($version >= 9)
  19599. {
  19600. $this->Error('This version of Adobe Illustrator file is not supported: ' . $file);
  19601. }
  19602. }
  19603. }
  19604. // strip binary bytes in front of PS-header
  19605. $start = strpos($data, '%!PS-Adobe');
  19606. if ($start > 0)
  19607. {
  19608. $data = substr($data, $start);
  19609. }
  19610. // find BoundingBox params
  19611. preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
  19612. if (count($regs) > 1)
  19613. {
  19614. list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
  19615. }
  19616. else
  19617. {
  19618. $this->Error('No BoundingBox found in EPS file: ' . $file);
  19619. }
  19620. $start = strpos($data, '%%EndSetup');
  19621. if ($start === false)
  19622. {
  19623. $start = strpos($data, '%%EndProlog');
  19624. }
  19625. if ($start === false)
  19626. {
  19627. $start = strpos($data, '%%BoundingBox');
  19628. }
  19629. $data = substr($data, $start);
  19630. $end = strpos($data, '%%PageTrailer');
  19631. if ($end === false)
  19632. {
  19633. $end = strpos($data, 'showpage');
  19634. }
  19635. if ($end)
  19636. {
  19637. $data = substr($data, 0, $end);
  19638. }
  19639. // calculate image width and height on document
  19640. if (($w <= 0) and ($h <= 0))
  19641. {
  19642. $w = ($x2 - $x1) / $k;
  19643. $h = ($y2 - $y1) / $k;
  19644. }
  19645. elseif ($w <= 0)
  19646. {
  19647. $w = ($x2 - $x1) / $k * ($h / (($y2 - $y1) / $k));
  19648. }
  19649. elseif ($h <= 0)
  19650. {
  19651. $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
  19652. }
  19653. // fit the image on available space
  19654. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  19655. if ($this->rasterize_vector_images)
  19656. {
  19657. // convert EPS to raster image using GD or ImageMagick libraries
  19658. return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
  19659. }
  19660. // set scaling factors
  19661. $scale_x = $w / (($x2 - $x1) / $k);
  19662. $scale_y = $h / (($y2 - $y1) / $k);
  19663. // set alignment
  19664. $this->img_rb_y = $y + $h;
  19665. // set alignment
  19666. if ($this->rtl)
  19667. {
  19668. if ($palign == 'L')
  19669. {
  19670. $ximg = $this->lMargin;
  19671. }
  19672. elseif ($palign == 'C')
  19673. {
  19674. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19675. }
  19676. elseif ($palign == 'R')
  19677. {
  19678. $ximg = $this->w - $this->rMargin - $w;
  19679. }
  19680. else
  19681. {
  19682. $ximg = $x - $w;
  19683. }
  19684. $this->img_rb_x = $ximg;
  19685. }
  19686. else
  19687. {
  19688. if ($palign == 'L')
  19689. {
  19690. $ximg = $this->lMargin;
  19691. }
  19692. elseif ($palign == 'C')
  19693. {
  19694. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  19695. }
  19696. elseif ($palign == 'R')
  19697. {
  19698. $ximg = $this->w - $this->rMargin - $w;
  19699. }
  19700. else
  19701. {
  19702. $ximg = $x;
  19703. }
  19704. $this->img_rb_x = $ximg + $w;
  19705. }
  19706. if ($useBoundingBox)
  19707. {
  19708. $dx = $ximg * $k - $x1;
  19709. $dy = $y * $k - $y1;
  19710. }
  19711. else
  19712. {
  19713. $dx = $ximg * $k;
  19714. $dy = $y * $k;
  19715. }
  19716. // save the current graphic state
  19717. $this->_out('q' . $this->epsmarker);
  19718. // translate
  19719. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
  19720. // scale
  19721. if (isset($scale_x))
  19722. {
  19723. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
  19724. }
  19725. // handle pc/unix/mac line endings
  19726. preg_match('/[\r\n]+/s', $data, $regs);
  19727. $lines = explode($regs[0], $data);
  19728. $u = 0;
  19729. $cnt = count($lines);
  19730. for($i = 0; $i < $cnt; ++ $i)
  19731. {
  19732. $line = $lines[$i];
  19733. if (($line == '') or ($line{0} == '%'))
  19734. {
  19735. continue;
  19736. }
  19737. $len = strlen($line);
  19738. $chunks = explode(' ', $line);
  19739. $cmd = array_pop($chunks);
  19740. // RGB
  19741. if (($cmd == 'Xa') or ($cmd == 'XA'))
  19742. {
  19743. $b = array_pop($chunks);
  19744. $g = array_pop($chunks);
  19745. $r = array_pop($chunks);
  19746. $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!
  19747. continue;
  19748. }
  19749. switch ($cmd)
  19750. {
  19751. case 'm' :
  19752. case 'l' :
  19753. case 'v' :
  19754. case 'y' :
  19755. case 'c' :
  19756. case 'k' :
  19757. case 'K' :
  19758. case 'g' :
  19759. case 'G' :
  19760. case 's' :
  19761. case 'S' :
  19762. case 'J' :
  19763. case 'j' :
  19764. case 'w' :
  19765. case 'M' :
  19766. case 'd' :
  19767. case 'n' :
  19768. {
  19769. $this->_out($line);
  19770. break;
  19771. }
  19772. case 'x' :
  19773. { // custom fill color
  19774. list($c, $m, $y, $k) = $chunks;
  19775. $this->_out('' . $c . ' ' . $m . ' ' . $y . ' ' . $k . ' k');
  19776. break;
  19777. }
  19778. case 'X' :
  19779. { // custom stroke color
  19780. list($c, $m, $y, $k) = $chunks;
  19781. $this->_out('' . $c . ' ' . $m . ' ' . $y . ' ' . $k . ' K');
  19782. break;
  19783. }
  19784. case 'Y' :
  19785. case 'N' :
  19786. case 'V' :
  19787. case 'L' :
  19788. case 'C' :
  19789. {
  19790. $line{$len - 1} = strtolower($cmd);
  19791. $this->_out($line);
  19792. break;
  19793. }
  19794. case 'b' :
  19795. case 'B' :
  19796. {
  19797. $this->_out($cmd . '*');
  19798. break;
  19799. }
  19800. case 'f' :
  19801. case 'F' :
  19802. {
  19803. if ($u > 0)
  19804. {
  19805. $isU = false;
  19806. $max = min($i + 5, $cnt);
  19807. for($j = $i + 1; $j < $max; ++ $j)
  19808. {
  19809. $isU = ($isU or (($lines[$j] == 'U') or ($lines[$j] == '*U')));
  19810. }
  19811. if ($isU)
  19812. {
  19813. $this->_out('f*');
  19814. }
  19815. }
  19816. else
  19817. {
  19818. $this->_out('f*');
  19819. }
  19820. break;
  19821. }
  19822. case '*u' :
  19823. {
  19824. ++ $u;
  19825. break;
  19826. }
  19827. case '*U' :
  19828. {
  19829. -- $u;
  19830. break;
  19831. }
  19832. }
  19833. }
  19834. // restore previous graphic state
  19835. $this->_out($this->epsmarker . 'Q');
  19836. if (! empty($border))
  19837. {
  19838. $bx = $this->x;
  19839. $by = $this->y;
  19840. $this->x = $ximg;
  19841. if ($this->rtl)
  19842. {
  19843. $this->x += $w;
  19844. }
  19845. $this->y = $y;
  19846. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  19847. $this->x = $bx;
  19848. $this->y = $by;
  19849. }
  19850. if ($link)
  19851. {
  19852. $this->Link($ximg, $y, $w, $h, $link, 0);
  19853. }
  19854. // set pointer to align the next text/objects
  19855. switch ($align)
  19856. {
  19857. case 'T' :
  19858. {
  19859. $this->y = $y;
  19860. $this->x = $this->img_rb_x;
  19861. break;
  19862. }
  19863. case 'M' :
  19864. {
  19865. $this->y = $y + round($h / 2);
  19866. $this->x = $this->img_rb_x;
  19867. break;
  19868. }
  19869. case 'B' :
  19870. {
  19871. $this->y = $this->img_rb_y;
  19872. $this->x = $this->img_rb_x;
  19873. break;
  19874. }
  19875. case 'N' :
  19876. {
  19877. $this->SetY($this->img_rb_y);
  19878. break;
  19879. }
  19880. default :
  19881. {
  19882. break;
  19883. }
  19884. }
  19885. $this->endlinex = $this->img_rb_x;
  19886. }
  19887. /**
  19888. * Set document barcode.
  19889. * @param string $bc barcode
  19890. * @access public
  19891. */
  19892. public function setBarcode($bc = '')
  19893. {
  19894. $this->barcode = $bc;
  19895. }
  19896. /**
  19897. * Get current barcode.
  19898. * @return string
  19899. * @access public
  19900. * @since 4.0.012 (2008-07-24)
  19901. */
  19902. public function getBarcode()
  19903. {
  19904. return $this->barcode;
  19905. }
  19906. /**
  19907. * Print a Linear Barcode.
  19908. * @param string $code code to print
  19909. * @param string $type type of barcode (see barcodes.php for supported formats).
  19910. * @param int $x x position in user units (empty string = current x position)
  19911. * @param int $y y position in user units (empty string = current y position)
  19912. * @param int $w width in user units (empty string = remaining page width)
  19913. * @param int $h height in user units (empty string = remaining page height)
  19914. * @param float $xres width of the smallest bar in user units (empty string = default value = 0.4mm)
  19915. * @param array $style array of options:<ul>
  19916. * <li>boolean $style['border'] if true prints a border</li>
  19917. * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
  19918. * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
  19919. * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
  19920. * <li>array $style['fgcolor'] color array for bars and text</li>
  19921. * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
  19922. * <li>boolean $style['text'] if true prints text below the barcode</li>
  19923. * <li>string $style['label'] override default label</li>
  19924. * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
  19925. * <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>
  19926. * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
  19927. * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
  19928. * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
  19929. * <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>
  19930. * <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>
  19931. * @param string $align Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  19932. * @author Nicola Asuni
  19933. * @since 3.1.000 (2008-06-09)
  19934. * @access public
  19935. */
  19936. public function write1DBarcode($code, $type, $x = '', $y = '', $w = '', $h = '', $xres = '', $style = '', $align = '')
  19937. {
  19938. if ($this->empty_string(trim($code)))
  19939. {
  19940. return;
  19941. }
  19942. require_once (dirname(__FILE__) . '/barcodes.php');
  19943. // save current graphic settings
  19944. $gvars = $this->getGraphicVars();
  19945. // create new barcode object
  19946. $barcodeobj = new TCPDFBarcode($code, $type);
  19947. $arrcode = $barcodeobj->getBarcodeArray();
  19948. if ($arrcode === false)
  19949. {
  19950. $this->Error('Error in 1D barcode string');
  19951. }
  19952. // set default values
  19953. if (! isset($style['position']))
  19954. {
  19955. $style['position'] = '';
  19956. }
  19957. elseif ($style['position'] == 'S')
  19958. {
  19959. // keep this for backward compatibility
  19960. $style['position'] = '';
  19961. $style['stretch'] = true;
  19962. }
  19963. if (! isset($style['fitwidth']))
  19964. {
  19965. if (! isset($style['stretch']))
  19966. {
  19967. $style['fitwidth'] = true;
  19968. }
  19969. else
  19970. {
  19971. $style['fitwidth'] = false;
  19972. }
  19973. }
  19974. if ($style['fitwidth'])
  19975. {
  19976. // disable stretch
  19977. $style['stretch'] = false;
  19978. }
  19979. if (! isset($style['stretch']))
  19980. {
  19981. if (($w === '') or ($w <= 0))
  19982. {
  19983. $style['stretch'] = false;
  19984. }
  19985. else
  19986. {
  19987. $style['stretch'] = true;
  19988. }
  19989. }
  19990. if (! isset($style['fgcolor']))
  19991. {
  19992. $style['fgcolor'] = array(0, 0, 0); // default black
  19993. }
  19994. if (! isset($style['bgcolor']))
  19995. {
  19996. $style['bgcolor'] = false; // default transparent
  19997. }
  19998. if (! isset($style['border']))
  19999. {
  20000. $style['border'] = false;
  20001. }
  20002. $fontsize = 0;
  20003. if (! isset($style['text']))
  20004. {
  20005. $style['text'] = false;
  20006. }
  20007. if ($style['text'] and isset($style['font']))
  20008. {
  20009. if (isset($style['fontsize']))
  20010. {
  20011. $fontsize = $style['fontsize'];
  20012. }
  20013. $this->SetFont($style['font'], '', $fontsize);
  20014. }
  20015. if (! isset($style['stretchtext']))
  20016. {
  20017. $style['stretchtext'] = 4;
  20018. }
  20019. if ($x === '')
  20020. {
  20021. $x = $this->x;
  20022. }
  20023. if ($y === '')
  20024. {
  20025. $y = $this->y;
  20026. }
  20027. // check page for no-write regions and adapt page margins if necessary
  20028. $this->checkPageRegions($h, $x, $y);
  20029. if (($w === '') or ($w <= 0))
  20030. {
  20031. if ($this->rtl)
  20032. {
  20033. $w = $x - $this->lMargin;
  20034. }
  20035. else
  20036. {
  20037. $w = $this->w - $this->rMargin - $x;
  20038. }
  20039. }
  20040. // padding
  20041. if (! isset($style['padding']))
  20042. {
  20043. $padding = 0;
  20044. }
  20045. elseif ($style['padding'] === 'auto')
  20046. {
  20047. $padding = 10 * ($w / ($arrcode['maxw'] + 20));
  20048. }
  20049. else
  20050. {
  20051. $padding = floatval($style['padding']);
  20052. }
  20053. // horizontal padding
  20054. if (! isset($style['hpadding']))
  20055. {
  20056. $hpadding = $padding;
  20057. }
  20058. elseif ($style['hpadding'] === 'auto')
  20059. {
  20060. $hpadding = 10 * ($w / ($arrcode['maxw'] + 20));
  20061. }
  20062. else
  20063. {
  20064. $hpadding = floatval($style['hpadding']);
  20065. }
  20066. // vertical padding
  20067. if (! isset($style['vpadding']))
  20068. {
  20069. $vpadding = $padding;
  20070. }
  20071. elseif ($style['vpadding'] === 'auto')
  20072. {
  20073. $vpadding = ($hpadding / 2);
  20074. }
  20075. else
  20076. {
  20077. $vpadding = floatval($style['vpadding']);
  20078. }
  20079. // calculate xres (single bar width)
  20080. $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
  20081. if ($style['stretch'])
  20082. {
  20083. $xres = $max_xres;
  20084. }
  20085. else
  20086. {
  20087. if ($this->empty_string($xres))
  20088. {
  20089. $xres = (0.141 * $this->k); // default bar width = 0.4 mm
  20090. }
  20091. if ($xres > $max_xres)
  20092. {
  20093. // correct xres to fit on $w
  20094. $xres = $max_xres;
  20095. }
  20096. if ((isset($style['padding']) and ($style['padding'] === 'auto')) or (isset($style['hpadding']) and ($style['hpadding'] === 'auto')))
  20097. {
  20098. $hpadding = 10 * $xres;
  20099. if (isset($style['vpadding']) and ($style['vpadding'] === 'auto'))
  20100. {
  20101. $vpadding = ($hpadding / 2);
  20102. }
  20103. }
  20104. }
  20105. if ($style['fitwidth'])
  20106. {
  20107. $wold = $w;
  20108. $w = (($arrcode['maxw'] * $xres) + (2 * $hpadding));
  20109. if (isset($style['cellfitalign']))
  20110. {
  20111. switch ($style['cellfitalign'])
  20112. {
  20113. case 'L' :
  20114. {
  20115. if ($this->rtl)
  20116. {
  20117. $x -= ($wold - $w);
  20118. }
  20119. break;
  20120. }
  20121. case 'R' :
  20122. {
  20123. if (! $this->rtl)
  20124. {
  20125. $x += ($wold - $w);
  20126. }
  20127. break;
  20128. }
  20129. case 'C' :
  20130. {
  20131. if ($this->rtl)
  20132. {
  20133. $x -= (($wold - $w) / 2);
  20134. }
  20135. else
  20136. {
  20137. $x += (($wold - $w) / 2);
  20138. }
  20139. break;
  20140. }
  20141. default :
  20142. {
  20143. break;
  20144. }
  20145. }
  20146. }
  20147. }
  20148. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  20149. // height
  20150. if (($h === '') or ($h <= 0))
  20151. {
  20152. // set default height
  20153. $h = (($arrcode['maxw'] * $xres) / 3) + (2 * $vpadding) + $text_height;
  20154. }
  20155. $barh = $h - $text_height - (2 * $vpadding);
  20156. if ($barh <= 0)
  20157. {
  20158. // try to reduce font or padding to fit barcode on available height
  20159. if ($text_height > $h)
  20160. {
  20161. $fontsize = (($h * $this->k) / (4 * $this->cell_height_ratio));
  20162. $text_height = ($this->cell_height_ratio * $fontsize / $this->k);
  20163. $this->SetFont($style['font'], '', $fontsize);
  20164. }
  20165. if ($vpadding > 0)
  20166. {
  20167. $vpadding = (($h - $text_height) / 4);
  20168. }
  20169. $barh = $h - $text_height - (2 * $vpadding);
  20170. }
  20171. // fit the barcode on available space
  20172. $this->fitBlock($w, $h, $x, $y, false);
  20173. // set alignment
  20174. $this->img_rb_y = $y + $h;
  20175. // set alignment
  20176. if ($this->rtl)
  20177. {
  20178. if ($style['position'] == 'L')
  20179. {
  20180. $xpos = $this->lMargin;
  20181. }
  20182. elseif ($style['position'] == 'C')
  20183. {
  20184. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  20185. }
  20186. elseif ($style['position'] == 'R')
  20187. {
  20188. $xpos = $this->w - $this->rMargin - $w;
  20189. }
  20190. else
  20191. {
  20192. $xpos = $x - $w;
  20193. }
  20194. $this->img_rb_x = $xpos;
  20195. }
  20196. else
  20197. {
  20198. if ($style['position'] == 'L')
  20199. {
  20200. $xpos = $this->lMargin;
  20201. }
  20202. elseif ($style['position'] == 'C')
  20203. {
  20204. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  20205. }
  20206. elseif ($style['position'] == 'R')
  20207. {
  20208. $xpos = $this->w - $this->rMargin - $w;
  20209. }
  20210. else
  20211. {
  20212. $xpos = $x;
  20213. }
  20214. $this->img_rb_x = $xpos + $w;
  20215. }
  20216. $xpos_rect = $xpos;
  20217. if (! isset($style['align']))
  20218. {
  20219. $style['align'] = 'C';
  20220. }
  20221. switch ($style['align'])
  20222. {
  20223. case 'L' :
  20224. {
  20225. $xpos = $xpos_rect + $hpadding;
  20226. break;
  20227. }
  20228. case 'R' :
  20229. {
  20230. $xpos = $xpos_rect + ($w - ($arrcode['maxw'] * $xres)) - $hpadding;
  20231. break;
  20232. }
  20233. case 'C' :
  20234. default :
  20235. {
  20236. $xpos = $xpos_rect + (($w - ($arrcode['maxw'] * $xres)) / 2);
  20237. break;
  20238. }
  20239. }
  20240. $xpos_text = $xpos;
  20241. // barcode is always printed in LTR direction
  20242. $tempRTL = $this->rtl;
  20243. $this->rtl = false;
  20244. // print background color
  20245. if ($style['bgcolor'])
  20246. {
  20247. $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  20248. }
  20249. elseif ($style['border'])
  20250. {
  20251. $this->Rect($xpos_rect, $y, $w, $h, 'D');
  20252. }
  20253. // set foreground color
  20254. $this->SetDrawColorArray($style['fgcolor']);
  20255. $this->SetTextColorArray($style['fgcolor']);
  20256. // print bars
  20257. foreach ($arrcode['bcode'] as $k => $v)
  20258. {
  20259. $bw = ($v['w'] * $xres);
  20260. if ($v['t'])
  20261. {
  20262. // draw a vertical bar
  20263. $ypos = $y + $vpadding + ($v['p'] * $barh / $arrcode['maxh']);
  20264. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
  20265. }
  20266. $xpos += $bw;
  20267. }
  20268. // print text
  20269. if ($style['text'])
  20270. {
  20271. if (isset($style['label']) and ! $this->empty_string($style['label']))
  20272. {
  20273. $label = $style['label'];
  20274. }
  20275. else
  20276. {
  20277. $label = $code;
  20278. }
  20279. $txtwidth = ($arrcode['maxw'] * $xres);
  20280. if ($this->GetStringWidth($label) > $txtwidth)
  20281. {
  20282. $style['stretchtext'] = 2;
  20283. }
  20284. // print text
  20285. $this->x = $xpos_text;
  20286. $this->y = $y + $vpadding + $barh;
  20287. $cellpadding = $this->cell_padding;
  20288. $this->SetCellPadding(0);
  20289. $this->Cell($txtwidth, '', $label, 0, 0, 'C', 0, '', $style['stretchtext'], false, 'T', 'T');
  20290. $this->cell_padding = $cellpadding;
  20291. }
  20292. // restore original direction
  20293. $this->rtl = $tempRTL;
  20294. // restore previous settings
  20295. $this->setGraphicVars($gvars);
  20296. // set pointer to align the next text/objects
  20297. switch ($align)
  20298. {
  20299. case 'T' :
  20300. {
  20301. $this->y = $y;
  20302. $this->x = $this->img_rb_x;
  20303. break;
  20304. }
  20305. case 'M' :
  20306. {
  20307. $this->y = $y + round($h / 2);
  20308. $this->x = $this->img_rb_x;
  20309. break;
  20310. }
  20311. case 'B' :
  20312. {
  20313. $this->y = $this->img_rb_y;
  20314. $this->x = $this->img_rb_x;
  20315. break;
  20316. }
  20317. case 'N' :
  20318. {
  20319. $this->SetY($this->img_rb_y);
  20320. break;
  20321. }
  20322. default :
  20323. {
  20324. break;
  20325. }
  20326. }
  20327. $this->endlinex = $this->img_rb_x;
  20328. }
  20329. /**
  20330. * This function is DEPRECATED, please use the new write1DBarcode() function.
  20331. * @param int $x x position in user units
  20332. * @param int $y y position in user units
  20333. * @param int $w width in user units
  20334. * @param int $h height position in user units
  20335. * @param string $type type of barcode
  20336. * @param string $style barcode style
  20337. * @param string $font font for text
  20338. * @param int $xres x resolution
  20339. * @param string $code code to print
  20340. * @deprecated deprecated since version 3.1.000 (2008-06-10)
  20341. * @access public
  20342. * @see write1DBarcode()
  20343. */
  20344. public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code)
  20345. {
  20346. // convert old settings for the new write1DBarcode() function.
  20347. $xres = 1 / $xres;
  20348. $newstyle = array('position' => '', 'align' => '', 'stretch' => false, 'fitwidth' => false,
  20349. 'cellfitalign' => '', 'border' => false, 'padding' => 0, 'fgcolor' => array(0, 0, 0), 'bgcolor' => false,
  20350. 'text' => true, 'font' => $font, 'fontsize' => 8, 'stretchtext' => 4);
  20351. if ($style & 1)
  20352. {
  20353. $newstyle['border'] = true;
  20354. }
  20355. if ($style & 2)
  20356. {
  20357. $newstyle['bgcolor'] = false;
  20358. }
  20359. if ($style & 4)
  20360. {
  20361. $newstyle['position'] = 'C';
  20362. }
  20363. elseif ($style & 8)
  20364. {
  20365. $newstyle['position'] = 'L';
  20366. }
  20367. elseif ($style & 16)
  20368. {
  20369. $newstyle['position'] = 'R';
  20370. }
  20371. if ($style & 128)
  20372. {
  20373. $newstyle['text'] = true;
  20374. }
  20375. if ($style & 256)
  20376. {
  20377. $newstyle['stretchtext'] = 4;
  20378. }
  20379. $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, '');
  20380. }
  20381. /**
  20382. * Print 2D Barcode.
  20383. * @param string $code code to print
  20384. * @param string $type type of barcode (see 2dbarcodes.php for supported formats).
  20385. * @param int $x x position in user units
  20386. * @param int $y y position in user units
  20387. * @param int $w width in user units
  20388. * @param int $h height in user units
  20389. * @param array $style array of options:<ul>
  20390. * <li>boolean $style['border'] if true prints a border around the barcode</li>
  20391. * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
  20392. * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
  20393. * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
  20394. * <li>int $style['module_width'] width of a single module in points</li>
  20395. * <li>int $style['module_height'] height of a single module in points</li>
  20396. * <li>array $style['fgcolor'] color array for bars and text</li>
  20397. * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
  20398. * <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>
  20399. * <li>$style['module_height'] height of a single module in points</li></ul>
  20400. * @param string $align Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  20401. * @param boolean $distort if true distort the barcode to fit width and height, otherwise preserve aspect ratio
  20402. * @author Nicola Asuni
  20403. * @since 4.5.037 (2009-04-07)
  20404. * @access public
  20405. */
  20406. public function write2DBarcode($code, $type, $x = '', $y = '', $w = '', $h = '', $style = '', $align = '', $distort = false)
  20407. {
  20408. if ($this->empty_string(trim($code)))
  20409. {
  20410. return;
  20411. }
  20412. require_once (dirname(__FILE__) . '/2dbarcodes.php');
  20413. // save current graphic settings
  20414. $gvars = $this->getGraphicVars();
  20415. // create new barcode object
  20416. $barcodeobj = new TCPDF2DBarcode($code, $type);
  20417. $arrcode = $barcodeobj->getBarcodeArray();
  20418. if (($arrcode === false) or empty($arrcode))
  20419. {
  20420. $this->Error('Error in 2D barcode string');
  20421. }
  20422. // set default values
  20423. if (! isset($style['position']))
  20424. {
  20425. $style['position'] = '';
  20426. }
  20427. if (! isset($style['fgcolor']))
  20428. {
  20429. $style['fgcolor'] = array(0, 0, 0); // default black
  20430. }
  20431. if (! isset($style['bgcolor']))
  20432. {
  20433. $style['bgcolor'] = false; // default transparent
  20434. }
  20435. if (! isset($style['border']))
  20436. {
  20437. $style['border'] = false;
  20438. }
  20439. // padding
  20440. if (! isset($style['padding']))
  20441. {
  20442. $style['padding'] = 0;
  20443. }
  20444. elseif ($style['padding'] === 'auto')
  20445. {
  20446. $style['padding'] = 4;
  20447. }
  20448. if (! isset($style['hpadding']))
  20449. {
  20450. $style['hpadding'] = $style['padding'];
  20451. }
  20452. elseif ($style['hpadding'] === 'auto')
  20453. {
  20454. $style['hpadding'] = 4;
  20455. }
  20456. if (! isset($style['vpadding']))
  20457. {
  20458. $style['vpadding'] = $style['padding'];
  20459. }
  20460. elseif ($style['vpadding'] === 'auto')
  20461. {
  20462. $style['vpadding'] = 4;
  20463. }
  20464. // cell (module) dimension
  20465. if (! isset($style['module_width']))
  20466. {
  20467. $style['module_width'] = 1; // width of a single module in points
  20468. }
  20469. if (! isset($style['module_height']))
  20470. {
  20471. $style['module_height'] = 1; // height of a single module in points
  20472. }
  20473. if ($x === '')
  20474. {
  20475. $x = $this->x;
  20476. }
  20477. if ($y === '')
  20478. {
  20479. $y = $this->y;
  20480. }
  20481. // check page for no-write regions and adapt page margins if necessary
  20482. $this->checkPageRegions($h, $x, $y);
  20483. // number of barcode columns and rows
  20484. $rows = $arrcode['num_rows'];
  20485. $cols = $arrcode['num_cols'];
  20486. // module width and height
  20487. $mw = $style['module_width'];
  20488. $mh = $style['module_height'];
  20489. // get max dimensions
  20490. if ($this->rtl)
  20491. {
  20492. $maxw = $x - $this->lMargin;
  20493. }
  20494. else
  20495. {
  20496. $maxw = $this->w - $this->rMargin - $x;
  20497. }
  20498. $maxh = ($this->h - $this->tMargin - $this->bMargin);
  20499. $ratioHW = ($rows * $mh) / ($cols * $mw);
  20500. $ratioWH = ($cols * $mw) / ($rows * $mh);
  20501. if (! $distort)
  20502. {
  20503. if (($maxw * $ratioHW) > $maxh)
  20504. {
  20505. $maxw = $maxh * $ratioWH;
  20506. }
  20507. if (($maxh * $ratioWH) > $maxw)
  20508. {
  20509. $maxh = $maxw * $ratioHW;
  20510. }
  20511. }
  20512. // set maximum dimesions
  20513. if ($w > $maxw)
  20514. {
  20515. $w = $maxw;
  20516. }
  20517. if ($h > $maxh)
  20518. {
  20519. $h = $maxh;
  20520. }
  20521. $hpad = (2 * $style['hpadding']);
  20522. $vpad = (2 * $style['vpadding']);
  20523. // set dimensions
  20524. if ((($w === '') or ($w <= 0)) and (($h === '') or ($h <= 0)))
  20525. {
  20526. $w = ($cols + $hpad) * ($mw / $this->k);
  20527. $h = ($rows + $vpad) * ($mh / $this->k);
  20528. }
  20529. elseif (($w === '') or ($w <= 0))
  20530. {
  20531. $w = $h * $ratioWH;
  20532. }
  20533. elseif (($h === '') or ($h <= 0))
  20534. {
  20535. $h = $w * $ratioHW;
  20536. }
  20537. // barcode size (excluding padding)
  20538. $bw = ($w * $cols) / ($cols + $hpad);
  20539. $bh = ($h * $rows) / ($rows + $vpad);
  20540. // dimension of single barcode cell unit
  20541. $cw = $bw / $cols;
  20542. $ch = $bh / $rows;
  20543. if (! $distort)
  20544. {
  20545. if (($cw / $ch) > ($mw / $mh))
  20546. {
  20547. // correct horizontal distortion
  20548. $cw = $ch * $mw / $mh;
  20549. $bw = $cw * $cols;
  20550. $style['hpadding'] = ($w - $bw) / (2 * $cw);
  20551. }
  20552. else
  20553. {
  20554. // correct vertical distortion
  20555. $ch = $cw * $mh / $mw;
  20556. $bh = $ch * $rows;
  20557. $style['vpadding'] = ($h - $bh) / (2 * $ch);
  20558. }
  20559. }
  20560. // fit the barcode on available space
  20561. $this->fitBlock($w, $h, $x, $y, false);
  20562. // set alignment
  20563. $this->img_rb_y = $y + $h;
  20564. // set alignment
  20565. if ($this->rtl)
  20566. {
  20567. if ($style['position'] == 'L')
  20568. {
  20569. $xpos = $this->lMargin;
  20570. }
  20571. elseif ($style['position'] == 'C')
  20572. {
  20573. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  20574. }
  20575. elseif ($style['position'] == 'R')
  20576. {
  20577. $xpos = $this->w - $this->rMargin - $w;
  20578. }
  20579. else
  20580. {
  20581. $xpos = $x - $w;
  20582. }
  20583. $this->img_rb_x = $xpos;
  20584. }
  20585. else
  20586. {
  20587. if ($style['position'] == 'L')
  20588. {
  20589. $xpos = $this->lMargin;
  20590. }
  20591. elseif ($style['position'] == 'C')
  20592. {
  20593. $xpos = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  20594. }
  20595. elseif ($style['position'] == 'R')
  20596. {
  20597. $xpos = $this->w - $this->rMargin - $w;
  20598. }
  20599. else
  20600. {
  20601. $xpos = $x;
  20602. }
  20603. $this->img_rb_x = $xpos + $w;
  20604. }
  20605. $xstart = $xpos + ($style['hpadding'] * $cw);
  20606. $ystart = $y + ($style['vpadding'] * $ch);
  20607. // barcode is always printed in LTR direction
  20608. $tempRTL = $this->rtl;
  20609. $this->rtl = false;
  20610. // print background color
  20611. if ($style['bgcolor'])
  20612. {
  20613. $this->Rect($xpos, $y, $w, $h, $style['border'] ? 'DF' : 'F', '', $style['bgcolor']);
  20614. }
  20615. elseif ($style['border'])
  20616. {
  20617. $this->Rect($xpos, $y, $w, $h, 'D');
  20618. }
  20619. // set foreground color
  20620. $this->SetDrawColorArray($style['fgcolor']);
  20621. // print barcode cells
  20622. // for each row
  20623. for($r = 0; $r < $rows; ++ $r)
  20624. {
  20625. $xr = $xstart;
  20626. // for each column
  20627. for($c = 0; $c < $cols; ++ $c)
  20628. {
  20629. if ($arrcode['bcode'][$r][$c] == 1)
  20630. {
  20631. // draw a single barcode cell
  20632. $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
  20633. }
  20634. $xr += $cw;
  20635. }
  20636. $ystart += $ch;
  20637. }
  20638. // restore original direction
  20639. $this->rtl = $tempRTL;
  20640. // restore previous settings
  20641. $this->setGraphicVars($gvars);
  20642. // set pointer to align the next text/objects
  20643. switch ($align)
  20644. {
  20645. case 'T' :
  20646. {
  20647. $this->y = $y;
  20648. $this->x = $this->img_rb_x;
  20649. break;
  20650. }
  20651. case 'M' :
  20652. {
  20653. $this->y = $y + round($h / 2);
  20654. $this->x = $this->img_rb_x;
  20655. break;
  20656. }
  20657. case 'B' :
  20658. {
  20659. $this->y = $this->img_rb_y;
  20660. $this->x = $this->img_rb_x;
  20661. break;
  20662. }
  20663. case 'N' :
  20664. {
  20665. $this->SetY($this->img_rb_y);
  20666. break;
  20667. }
  20668. default :
  20669. {
  20670. break;
  20671. }
  20672. }
  20673. $this->endlinex = $this->img_rb_x;
  20674. }
  20675. /**
  20676. * Returns an array containing current margins:
  20677. * <ul>
  20678. <li>$ret['left'] = left margin</li>
  20679. <li>$ret['right'] = right margin</li>
  20680. <li>$ret['top'] = top margin</li>
  20681. <li>$ret['bottom'] = bottom margin</li>
  20682. <li>$ret['header'] = header margin</li>
  20683. <li>$ret['footer'] = footer margin</li>
  20684. <li>$ret['cell'] = cell padding array</li>
  20685. <li>$ret['padding_left'] = cell left padding</li>
  20686. <li>$ret['padding_top'] = cell top padding</li>
  20687. <li>$ret['padding_right'] = cell right padding</li>
  20688. <li>$ret['padding_bottom'] = cell bottom padding</li>
  20689. * </ul>
  20690. * @return array containing all margins measures
  20691. * @access public
  20692. * @since 3.2.000 (2008-06-23)
  20693. */
  20694. public function getMargins()
  20695. {
  20696. $ret = array('left' => $this->lMargin, 'right' => $this->rMargin, 'top' => $this->tMargin,
  20697. 'bottom' => $this->bMargin, 'header' => $this->header_margin, 'footer' => $this->footer_margin,
  20698. 'cell' => $this->cell_padding, 'padding_left' => $this->cell_padding['L'],
  20699. 'padding_top' => $this->cell_padding['T'], 'padding_right' => $this->cell_padding['R'],
  20700. 'padding_bottom' => $this->cell_padding['B']);
  20701. return $ret;
  20702. }
  20703. /**
  20704. * Returns an array containing original margins:
  20705. * <ul>
  20706. <li>$ret['left'] = left margin</li>
  20707. <li>$ret['right'] = right margin</li>
  20708. * </ul>
  20709. * @return array containing all margins measures
  20710. * @access public
  20711. * @since 4.0.012 (2008-07-24)
  20712. */
  20713. public function getOriginalMargins()
  20714. {
  20715. $ret = array('left' => $this->original_lMargin, 'right' => $this->original_rMargin);
  20716. return $ret;
  20717. }
  20718. /**
  20719. * Returns the current font size.
  20720. * @return current font size
  20721. * @access public
  20722. * @since 3.2.000 (2008-06-23)
  20723. */
  20724. public function getFontSize()
  20725. {
  20726. return $this->FontSize;
  20727. }
  20728. /**
  20729. * Returns the current font size in points unit.
  20730. * @return current font size in points unit
  20731. * @access public
  20732. * @since 3.2.000 (2008-06-23)
  20733. */
  20734. public function getFontSizePt()
  20735. {
  20736. return $this->FontSizePt;
  20737. }
  20738. /**
  20739. * Returns the current font family name.
  20740. * @return string current font family name
  20741. * @access public
  20742. * @since 4.3.008 (2008-12-05)
  20743. */
  20744. public function getFontFamily()
  20745. {
  20746. return $this->FontFamily;
  20747. }
  20748. /**
  20749. * Returns the current font style.
  20750. * @return string current font style
  20751. * @access public
  20752. * @since 4.3.008 (2008-12-05)
  20753. */
  20754. public function getFontStyle()
  20755. {
  20756. return $this->FontStyle;
  20757. }
  20758. /**
  20759. * Extracts the CSS properties from a CSS string.
  20760. * @param string $cssdata string containing CSS definitions.
  20761. * @return An array where the keys are the CSS selectors and the values are the CSS properties.
  20762. * @author Nicola Asuni
  20763. * @since 5.1.000 (2010-05-25)
  20764. * @access protected
  20765. */
  20766. protected function extractCSSproperties($cssdata)
  20767. {
  20768. if (empty($cssdata))
  20769. {
  20770. return array();
  20771. }
  20772. // remove comments
  20773. $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
  20774. // remove newlines and multiple spaces
  20775. $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
  20776. // remove some spaces
  20777. $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
  20778. // remove empty blocks
  20779. $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
  20780. // replace media type parenthesis
  20781. $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1�', $cssdata);
  20782. $cssdata = preg_replace('/\}\}/si', '}�', $cssdata);
  20783. // trim string
  20784. $cssdata = trim($cssdata);
  20785. // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  20786. $cssblocks = array();
  20787. $matches = array();
  20788. if (preg_match_all('/@media[\s]+([^\�]*)�([^�]*)�/i', $cssdata, $matches) > 0)
  20789. {
  20790. foreach ($matches[1] as $key => $type)
  20791. {
  20792. $cssblocks[$type] = $matches[2][$key];
  20793. }
  20794. // remove media blocks
  20795. $cssdata = preg_replace('/@media[\s]+([^\�]*)�([^�]*)�/i', '', $cssdata);
  20796. }
  20797. // keep 'all' and 'print' media, other media types are discarded
  20798. if (isset($cssblocks['all']) and ! empty($cssblocks['all']))
  20799. {
  20800. $cssdata .= $cssblocks['all'];
  20801. }
  20802. if (isset($cssblocks['print']) and ! empty($cssblocks['print']))
  20803. {
  20804. $cssdata .= $cssblocks['print'];
  20805. }
  20806. // reset css blocks array
  20807. $cssblocks = array();
  20808. $matches = array();
  20809. // explode css data string into array
  20810. if (substr($cssdata, - 1) == '}')
  20811. {
  20812. // remove last parethesis
  20813. $cssdata = substr($cssdata, 0, - 1);
  20814. }
  20815. $matches = explode('}', $cssdata);
  20816. foreach ($matches as $key => $block)
  20817. {
  20818. // index 0 contains the CSS selector, index 1 contains CSS properties
  20819. $cssblocks[$key] = explode('{', $block);
  20820. if (! isset($cssblocks[$key][1]))
  20821. {
  20822. // remove empty definitions
  20823. unset($cssblocks[$key]);
  20824. }
  20825. }
  20826. // split groups of selectors (comma-separated list of selectors)
  20827. foreach ($cssblocks as $key => $block)
  20828. {
  20829. if (strpos($block[0], ',') > 0)
  20830. {
  20831. $selectors = explode(',', $block[0]);
  20832. foreach ($selectors as $sel)
  20833. {
  20834. $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
  20835. }
  20836. unset($cssblocks[$key]);
  20837. }
  20838. }
  20839. // covert array to selector => properties
  20840. $cssdata = array();
  20841. foreach ($cssblocks as $block)
  20842. {
  20843. $selector = $block[0];
  20844. // calculate selector's specificity
  20845. $matches = array();
  20846. $a = 0; // the declaration is not from is a 'style' attribute
  20847. $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
  20848. $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
  20849. $c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); // number of pseudo-classes
  20850. $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9\*]+/', ' ' . $selector, $matches)); // number of element names
  20851. $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
  20852. $specificity = $a . $b . $c . $d;
  20853. // add specificity to the beginning of the selector
  20854. $cssdata[$specificity . ' ' . $selector] = $block[1];
  20855. }
  20856. // sort selectors alphabetically to account for specificity
  20857. ksort($cssdata, SORT_STRING);
  20858. // return array
  20859. return $cssdata;
  20860. }
  20861. /**
  20862. * Returns true if the CSS selector is valid for the selected HTML tag
  20863. * @param array $dom array of HTML tags and properties
  20864. * @param int $key key of the current HTML tag
  20865. * @param string $selector CSS selector string
  20866. * @return true if the selector is valid, false otherwise
  20867. * @access protected
  20868. * @since 5.1.000 (2010-05-25)
  20869. */
  20870. protected function isValidCSSSelectorForTag($dom, $key, $selector)
  20871. {
  20872. $valid = false; // value to be returned
  20873. $tag = $dom[$key]['value'];
  20874. $class = array();
  20875. if (isset($dom[$key]['attribute']['class']) and ! empty($dom[$key]['attribute']['class']))
  20876. {
  20877. $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
  20878. }
  20879. $id = '';
  20880. if (isset($dom[$key]['attribute']['id']) and ! empty($dom[$key]['attribute']['id']))
  20881. {
  20882. $id = strtolower($dom[$key]['attribute']['id']);
  20883. }
  20884. $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
  20885. $matches = array();
  20886. if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0)
  20887. {
  20888. $parentop = array_pop($matches[1]);
  20889. $operator = $parentop[0];
  20890. $offset = $parentop[1];
  20891. $lasttag = array_pop($matches[2]);
  20892. $lasttag = strtolower(trim($lasttag[0]));
  20893. if (($lasttag == '*') or ($lasttag == $tag))
  20894. {
  20895. // the last element on selector is our tag or 'any tag'
  20896. $attrib = array_pop($matches[3]);
  20897. $attrib = strtolower(trim($attrib[0]));
  20898. if (! empty($attrib))
  20899. {
  20900. // check if matches class, id, attribute, pseudo-class or pseudo-element
  20901. switch ($attrib{0})
  20902. {
  20903. case '.' :
  20904. { // class
  20905. if (in_array(substr($attrib, 1), $class))
  20906. {
  20907. $valid = true;
  20908. }
  20909. break;
  20910. }
  20911. case '#' :
  20912. { // ID
  20913. if (substr($attrib, 1) == $id)
  20914. {
  20915. $valid = true;
  20916. }
  20917. break;
  20918. }
  20919. case '[' :
  20920. { // attribute
  20921. $attrmatch = array();
  20922. if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0)
  20923. {
  20924. $att = strtolower($attrmatch[1]);
  20925. $val = $attrmatch[3];
  20926. if (isset($dom[$key]['attribute'][$att]))
  20927. {
  20928. switch ($attrmatch[2])
  20929. {
  20930. case '=' :
  20931. {
  20932. if ($dom[$key]['attribute'][$att] == $val)
  20933. {
  20934. $valid = true;
  20935. }
  20936. break;
  20937. }
  20938. case '~=' :
  20939. {
  20940. if (in_array($val, explode(' ', $dom[$key]['attribute'][$att])))
  20941. {
  20942. $valid = true;
  20943. }
  20944. break;
  20945. }
  20946. case '^=' :
  20947. {
  20948. if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val)))
  20949. {
  20950. $valid = true;
  20951. }
  20952. break;
  20953. }
  20954. case '$=' :
  20955. {
  20956. if ($val == substr($dom[$key]['attribute'][$att], - strlen($val)))
  20957. {
  20958. $valid = true;
  20959. }
  20960. break;
  20961. }
  20962. case '*=' :
  20963. {
  20964. if (strpos($dom[$key]['attribute'][$att], $val) !== false)
  20965. {
  20966. $valid = true;
  20967. }
  20968. break;
  20969. }
  20970. case '|=' :
  20971. {
  20972. if ($dom[$key]['attribute'][$att] == $val)
  20973. {
  20974. $valid = true;
  20975. }
  20976. elseif (preg_match('/' . $val . '[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0)
  20977. {
  20978. $valid = true;
  20979. }
  20980. break;
  20981. }
  20982. default :
  20983. {
  20984. $valid = true;
  20985. }
  20986. }
  20987. }
  20988. }
  20989. break;
  20990. }
  20991. case ':' :
  20992. { // pseudo-class or pseudo-element
  20993. if ($attrib{1} == ':')
  20994. { // pseudo-element
  20995. // pseudo-elements are not supported!
  20996. // (::first-line, ::first-letter, ::before, ::after)
  20997. }
  20998. else
  20999. { // pseudo-class
  21000. // pseudo-classes are not supported!
  21001. // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked)
  21002. }
  21003. break;
  21004. }
  21005. } // end of switch
  21006. }
  21007. else
  21008. {
  21009. $valid = true;
  21010. }
  21011. if ($valid and ($offset > 0))
  21012. {
  21013. $valid = false;
  21014. // check remaining selector part
  21015. $selector = substr($selector, 0, $offset);
  21016. switch ($operator)
  21017. {
  21018. case ' ' :
  21019. { // descendant of an element
  21020. while ($dom[$key]['parent'] > 0)
  21021. {
  21022. if ($this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector))
  21023. {
  21024. $valid = true;
  21025. break;
  21026. }
  21027. else
  21028. {
  21029. $key = $dom[$key]['parent'];
  21030. }
  21031. }
  21032. break;
  21033. }
  21034. case '>' :
  21035. { // child of an element
  21036. $valid = $this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
  21037. break;
  21038. }
  21039. case '+' :
  21040. { // immediately preceded by an element
  21041. for($i = ($key - 1); $i > $dom[$key]['parent']; -- $i)
  21042. {
  21043. if ($dom[$i]['tag'] and $dom[$i]['opening'])
  21044. {
  21045. $valid = $this->isValidCSSSelectorForTag($dom, $i, $selector);
  21046. break;
  21047. }
  21048. }
  21049. break;
  21050. }
  21051. case '~' :
  21052. { // preceded by an element
  21053. for($i = ($key - 1); $i > $dom[$key]['parent']; -- $i)
  21054. {
  21055. if ($dom[$i]['tag'] and $dom[$i]['opening'])
  21056. {
  21057. if ($this->isValidCSSSelectorForTag($dom, $i, $selector))
  21058. {
  21059. break;
  21060. }
  21061. }
  21062. }
  21063. break;
  21064. }
  21065. }
  21066. }
  21067. }
  21068. }
  21069. return $valid;
  21070. }
  21071. /**
  21072. * Returns the styles that apply for the selected HTML tag.
  21073. * @param array $dom array of HTML tags and properties
  21074. * @param int $key key of the current HTML tag
  21075. * @param array $css array of CSS properties
  21076. * @return string containing CSS properties
  21077. * @access protected
  21078. * @since 5.1.000 (2010-05-25)
  21079. */
  21080. protected function getTagStyleFromCSS($dom, $key, $css)
  21081. {
  21082. $tagstyle = ''; // style to be returned
  21083. // get all styles that apply
  21084. foreach ($css as $selector => $style)
  21085. {
  21086. // remove specificity
  21087. $selector = substr($selector, strpos($selector, ' '));
  21088. // check if this selector apply to current tag
  21089. if ($this->isValidCSSSelectorForTag($dom, $key, $selector))
  21090. {
  21091. // apply style
  21092. $tagstyle .= ';' . $style;
  21093. }
  21094. }
  21095. if (isset($dom[$key]['attribute']['style']))
  21096. {
  21097. // attach inline style (latest properties have high priority)
  21098. $tagstyle .= ';' . $dom[$key]['attribute']['style'];
  21099. }
  21100. // remove multiple semicolons
  21101. $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
  21102. return $tagstyle;
  21103. }
  21104. /**
  21105. * Returns the border width from CSS property
  21106. * @param string $width border width
  21107. * @return int with in user units
  21108. * @access protected
  21109. * @since 5.7.000 (2010-08-02)
  21110. */
  21111. protected function getCSSBorderWidth($width)
  21112. {
  21113. if ($width == 'thin')
  21114. {
  21115. $width = (2 / $this->k);
  21116. }
  21117. elseif ($width == 'medium')
  21118. {
  21119. $width = (4 / $this->k);
  21120. }
  21121. elseif ($width == 'thick')
  21122. {
  21123. $width = (6 / $this->k);
  21124. }
  21125. else
  21126. {
  21127. $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
  21128. }
  21129. return $width;
  21130. }
  21131. /**
  21132. * Returns the border dash style from CSS property
  21133. * @param string $style border style to convert
  21134. * @return int sash style (return -1 in case of none or hidden border)
  21135. * @access protected
  21136. * @since 5.7.000 (2010-08-02)
  21137. */
  21138. protected function getCSSBorderDashStyle($style)
  21139. {
  21140. switch (strtolower($style))
  21141. {
  21142. case 'none' :
  21143. case 'hidden' :
  21144. {
  21145. $dash = - 1;
  21146. break;
  21147. }
  21148. case 'dotted' :
  21149. {
  21150. $dash = 1;
  21151. break;
  21152. }
  21153. case 'dashed' :
  21154. {
  21155. $dash = 3;
  21156. break;
  21157. }
  21158. case 'double' :
  21159. case 'groove' :
  21160. case 'ridge' :
  21161. case 'inset' :
  21162. case 'outset' :
  21163. case 'solid' :
  21164. default :
  21165. {
  21166. $dash = 0;
  21167. break;
  21168. }
  21169. }
  21170. return $dash;
  21171. }
  21172. /**
  21173. * Returns the border style array from CSS border properties
  21174. * @param string $cssborder border properties
  21175. * @return array containing border properties
  21176. * @access protected
  21177. * @since 5.7.000 (2010-08-02)
  21178. */
  21179. protected function getCSSBorderStyle($cssborder)
  21180. {
  21181. $bprop = preg_split('/[\s]+/', trim($cssborder));
  21182. $border = array(); // value to be returned
  21183. switch (count($bprop))
  21184. {
  21185. case 3 :
  21186. {
  21187. $width = $bprop[0];
  21188. $style = $bprop[1];
  21189. $color = $bprop[2];
  21190. break;
  21191. }
  21192. case 2 :
  21193. {
  21194. $width = 'medium';
  21195. $style = $bprop[0];
  21196. $color = $bprop[1];
  21197. break;
  21198. }
  21199. case 1 :
  21200. {
  21201. $width = 'medium';
  21202. $style = $bprop[0];
  21203. $color = 'black';
  21204. break;
  21205. }
  21206. default :
  21207. {
  21208. $width = 'medium';
  21209. $style = 'solid';
  21210. $color = 'black';
  21211. break;
  21212. }
  21213. }
  21214. if ($style == 'none')
  21215. {
  21216. return array();
  21217. }
  21218. $border['cap'] = 'square';
  21219. $border['join'] = 'miter';
  21220. $border['dash'] = $this->getCSSBorderDashStyle($style);
  21221. if ($border['dash'] < 0)
  21222. {
  21223. return array();
  21224. }
  21225. $border['width'] = $this->getCSSBorderWidth($width);
  21226. $border['color'] = $this->convertHTMLColorToDec($color);
  21227. return $border;
  21228. }
  21229. /**
  21230. * Get the internal Cell padding from CSS attribute.
  21231. * @param string $csspadding padding properties
  21232. * @param float $width width of the containing element
  21233. * @access public
  21234. * @since 5.9.000 (2010-10-04)
  21235. */
  21236. public function getCSSPadding($csspadding, $width = 0)
  21237. {
  21238. $padding = preg_split('/[\s]+/', trim($csspadding));
  21239. $cell_padding = array(); // value to be returned
  21240. switch (count($padding))
  21241. {
  21242. case 4 :
  21243. {
  21244. $cell_padding['T'] = $padding[0];
  21245. $cell_padding['R'] = $padding[1];
  21246. $cell_padding['B'] = $padding[2];
  21247. $cell_padding['L'] = $padding[3];
  21248. break;
  21249. }
  21250. case 3 :
  21251. {
  21252. $cell_padding['T'] = $padding[0];
  21253. $cell_padding['R'] = $padding[1];
  21254. $cell_padding['B'] = $padding[2];
  21255. $cell_padding['L'] = $padding[1];
  21256. break;
  21257. }
  21258. case 2 :
  21259. {
  21260. $cell_padding['T'] = $padding[0];
  21261. $cell_padding['R'] = $padding[1];
  21262. $cell_padding['B'] = $padding[0];
  21263. $cell_padding['L'] = $padding[1];
  21264. break;
  21265. }
  21266. case 1 :
  21267. {
  21268. $cell_padding['T'] = $padding[0];
  21269. $cell_padding['R'] = $padding[0];
  21270. $cell_padding['B'] = $padding[0];
  21271. $cell_padding['L'] = $padding[0];
  21272. break;
  21273. }
  21274. default :
  21275. {
  21276. return $this->cell_padding;
  21277. }
  21278. }
  21279. if ($width == 0)
  21280. {
  21281. $width = $this->w - $this->lMargin - $this->rMargin;
  21282. }
  21283. $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
  21284. $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
  21285. $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
  21286. $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
  21287. return $cell_padding;
  21288. }
  21289. /**
  21290. * Get the internal Cell margin from CSS attribute.
  21291. * @param string $cssmargin margin properties
  21292. * @param float $width width of the containing element
  21293. * @access public
  21294. * @since 5.9.000 (2010-10-04)
  21295. */
  21296. public function getCSSMargin($cssmargin, $width = 0)
  21297. {
  21298. $margin = preg_split('/[\s]+/', trim($cssmargin));
  21299. $cell_margin = array(); // value to be returned
  21300. switch (count($margin))
  21301. {
  21302. case 4 :
  21303. {
  21304. $cell_margin['T'] = $margin[0];
  21305. $cell_margin['R'] = $margin[1];
  21306. $cell_margin['B'] = $margin[2];
  21307. $cell_margin['L'] = $margin[3];
  21308. break;
  21309. }
  21310. case 3 :
  21311. {
  21312. $cell_margin['T'] = $margin[0];
  21313. $cell_margin['R'] = $margin[1];
  21314. $cell_margin['B'] = $margin[2];
  21315. $cell_margin['L'] = $margin[1];
  21316. break;
  21317. }
  21318. case 2 :
  21319. {
  21320. $cell_margin['T'] = $margin[0];
  21321. $cell_margin['R'] = $margin[1];
  21322. $cell_margin['B'] = $margin[0];
  21323. $cell_margin['L'] = $margin[1];
  21324. break;
  21325. }
  21326. case 1 :
  21327. {
  21328. $cell_margin['T'] = $margin[0];
  21329. $cell_margin['R'] = $margin[0];
  21330. $cell_margin['B'] = $margin[0];
  21331. $cell_margin['L'] = $margin[0];
  21332. break;
  21333. }
  21334. default :
  21335. {
  21336. return $this->cell_margin;
  21337. }
  21338. }
  21339. if ($width == 0)
  21340. {
  21341. $width = $this->w - $this->lMargin - $this->rMargin;
  21342. }
  21343. $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
  21344. $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
  21345. $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
  21346. $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
  21347. return $cell_margin;
  21348. }
  21349. /**
  21350. * Returns the letter-spacing value from CSS value
  21351. * @param string $spacing letter-spacing value
  21352. * @param float $parent font spacing (tracking/kerning) value of the parent element
  21353. * @return float quantity to increases or decreases the space between characters in a text.
  21354. * @access protected
  21355. * @since 5.9.000 (2010-10-02)
  21356. */
  21357. protected function getCSSFontSpacing($spacing, $parent = 0)
  21358. {
  21359. $val = 0; // value to be returned
  21360. $spacing = trim($spacing);
  21361. switch ($spacing)
  21362. {
  21363. case 'normal' :
  21364. {
  21365. $val = 0;
  21366. break;
  21367. }
  21368. case 'inherit' :
  21369. {
  21370. if ($parent == 'normal')
  21371. {
  21372. $val = 0;
  21373. }
  21374. else
  21375. {
  21376. $val = $parent;
  21377. }
  21378. break;
  21379. }
  21380. default :
  21381. {
  21382. $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
  21383. }
  21384. }
  21385. return $val;
  21386. }
  21387. /**
  21388. * Returns the percentage of font stretching from CSS value
  21389. * @param string $stretch stretch mode
  21390. * @param float $parent stretch value of the parent element
  21391. * @return float font stretching percentage
  21392. * @access protected
  21393. * @since 5.9.000 (2010-10-02)
  21394. */
  21395. protected function getCSSFontStretching($stretch, $parent = 100)
  21396. {
  21397. $val = 100; // value to be returned
  21398. $stretch = trim($stretch);
  21399. switch ($stretch)
  21400. {
  21401. case 'ultra-condensed' :
  21402. {
  21403. $val = 40;
  21404. break;
  21405. }
  21406. case 'extra-condensed' :
  21407. {
  21408. $val = 55;
  21409. break;
  21410. }
  21411. case 'condensed' :
  21412. {
  21413. $val = 70;
  21414. break;
  21415. }
  21416. case 'semi-condensed' :
  21417. {
  21418. $val = 85;
  21419. break;
  21420. }
  21421. case 'normal' :
  21422. {
  21423. $val = 100;
  21424. break;
  21425. }
  21426. case 'semi-expanded' :
  21427. {
  21428. $val = 115;
  21429. break;
  21430. }
  21431. case 'expanded' :
  21432. {
  21433. $val = 130;
  21434. break;
  21435. }
  21436. case 'extra-expanded' :
  21437. {
  21438. $val = 145;
  21439. break;
  21440. }
  21441. case 'ultra-expanded' :
  21442. {
  21443. $val = 160;
  21444. break;
  21445. }
  21446. case 'wider' :
  21447. {
  21448. $val = $parent + 10;
  21449. break;
  21450. }
  21451. case 'narrower' :
  21452. {
  21453. $val = $parent - 10;
  21454. break;
  21455. }
  21456. case 'inherit' :
  21457. {
  21458. if ($parent == 'normal')
  21459. {
  21460. $val = 100;
  21461. }
  21462. else
  21463. {
  21464. $val = $parent;
  21465. }
  21466. break;
  21467. }
  21468. default :
  21469. {
  21470. $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
  21471. }
  21472. }
  21473. return $val;
  21474. }
  21475. /**
  21476. * Returns the HTML DOM array.
  21477. * @param string $html html code
  21478. * @return array
  21479. * @access protected
  21480. * @since 3.2.000 (2008-06-20)
  21481. */
  21482. protected function getHtmlDomArray($html)
  21483. {
  21484. // array of CSS styles ( selector => properties).
  21485. $css = array();
  21486. // get CSS array defined at previous call
  21487. $matches = array();
  21488. if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0)
  21489. {
  21490. if (isset($matches[1][0]))
  21491. {
  21492. $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
  21493. }
  21494. $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
  21495. }
  21496. // extract external CSS files
  21497. $matches = array();
  21498. if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0)
  21499. {
  21500. foreach ($matches[1] as $key => $link)
  21501. {
  21502. $type = array();
  21503. if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type))
  21504. {
  21505. $type = array();
  21506. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
  21507. // get 'all' and 'print' media, other media types are discarded
  21508. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  21509. if (empty($type) or (isset($type[1]) and (($type[1] == 'all') or ($type[1] == 'print'))))
  21510. {
  21511. $type = array();
  21512. if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0)
  21513. {
  21514. // read CSS data file
  21515. $cssdata = file_get_contents(trim($type[1]));
  21516. $css = array_merge($css, $this->extractCSSproperties($cssdata));
  21517. }
  21518. }
  21519. }
  21520. }
  21521. }
  21522. // extract style tags
  21523. $matches = array();
  21524. if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0)
  21525. {
  21526. foreach ($matches[1] as $key => $media)
  21527. {
  21528. $type = array();
  21529. preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
  21530. // get 'all' and 'print' media, other media types are discarded
  21531. // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  21532. if (empty($type) or (isset($type[1]) and (($type[1] == 'all') or ($type[1] == 'print'))))
  21533. {
  21534. $cssdata = $matches[2][$key];
  21535. $css = array_merge($css, $this->extractCSSproperties($cssdata));
  21536. }
  21537. }
  21538. }
  21539. // create a special tag to contain the CSS array (used for table content)
  21540. $csstagarray = '<cssarray>' . htmlentities(serialize($css)) . '</cssarray>';
  21541. // remove head and style blocks
  21542. $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
  21543. $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
  21544. // define block tags
  21545. $blocktags = array('blockquote', 'br', 'dd', 'dl', 'div', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
  21546. 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'tcpdf', 'table', 'tr', 'td');
  21547. // define self-closing tags
  21548. $selfclosingtags = array('area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta');
  21549. // remove all unsupported tags (the line below lists all supported tags)
  21550. $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>');
  21551. //replace some blank characters
  21552. $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
  21553. $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);
  21554. $html = preg_replace('@(\r\n|\r)@', "\n", $html);
  21555. $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
  21556. $html = strtr($html, $repTable);
  21557. $offset = 0;
  21558. while (($offset < strlen($html)) and ($pos = strpos($html, '</pre>', $offset)) !== false)
  21559. {
  21560. $html_a = substr($html, 0, $offset);
  21561. $html_b = substr($html, $offset, ($pos - $offset + 6));
  21562. while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b))
  21563. {
  21564. // preserve newlines on <pre> tag
  21565. $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
  21566. }
  21567. while (preg_match("'<xre([^\>]*)>(.*?)" . $this->re_space['p'] . "(.*?)</pre>'" . $this->re_space['m'], $html_b))
  21568. {
  21569. // preserve spaces on <pre> tag
  21570. $html_b = preg_replace("'<xre([^\>]*)>(.*?)" . $this->re_space['p'] . "(.*?)</pre>'" . $this->re_space['m'], "<xre\\1>\\2&nbsp;\\3</pre>", $html_b);
  21571. }
  21572. $html = $html_a . $html_b . substr($html, $pos + 6);
  21573. $offset = strlen($html_a . $html_b);
  21574. }
  21575. $offset = 0;
  21576. while (($offset < strlen($html)) and ($pos = strpos($html, '</textarea>', $offset)) !== false)
  21577. {
  21578. $html_a = substr($html, 0, $offset);
  21579. $html_b = substr($html, $offset, ($pos - $offset + 11));
  21580. while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b))
  21581. {
  21582. // preserve newlines on <textarea> tag
  21583. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
  21584. $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
  21585. }
  21586. $html = $html_a . $html_b . substr($html, $pos + 11);
  21587. $offset = strlen($html_a . $html_b);
  21588. }
  21589. $html = preg_replace('/([\s]*)<option/si', '<option', $html);
  21590. $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
  21591. $offset = 0;
  21592. while (($offset < strlen($html)) and ($pos = strpos($html, '</option>', $offset)) !== false)
  21593. {
  21594. $html_a = substr($html, 0, $offset);
  21595. $html_b = substr($html, $offset, ($pos - $offset + 9));
  21596. while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b))
  21597. {
  21598. $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
  21599. $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
  21600. }
  21601. $html = $html_a . $html_b . substr($html, $pos + 9);
  21602. $offset = strlen($html_a . $html_b);
  21603. }
  21604. if (preg_match("'</select'si", $html))
  21605. {
  21606. $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
  21607. $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
  21608. }
  21609. $html = str_replace("\n", ' ', $html);
  21610. // restore textarea newlines
  21611. $html = str_replace('<TBR>', "\n", $html);
  21612. // remove extra spaces from code
  21613. $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
  21614. $html = preg_replace('/' . $this->re_space['p'] . '+<\/(td|th|li|dt|dd)>/' . $this->re_space['m'], '</\\1>', $html);
  21615. $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
  21616. $html = preg_replace('/' . $this->re_space['p'] . '+<(ul|ol|dl|br)/' . $this->re_space['m'], '<\\1', $html);
  21617. $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);
  21618. $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
  21619. $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
  21620. $html = preg_replace('/' . $this->re_space['p'] . '+<img/' . $this->re_space['m'], chr(32) . '<img', $html);
  21621. $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
  21622. $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
  21623. $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
  21624. $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1>&nbsp;</li>', $html);
  21625. $html = preg_replace('/<li([^\>]*)>' . $this->re_space['p'] . '*<img/' . $this->re_space['m'], '<li\\1><font size="1">&nbsp;</font><img', $html);
  21626. $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1>&nbsp;', $html); // preserve some spaces
  21627. $html = preg_replace('/[\s]<\/([^\>]*)>/', '&nbsp;</\\1>', $html); // preserve some spaces
  21628. $html = preg_replace('/' . $this->re_space['p'] . '+/' . $this->re_space['m'], chr(32), $html); // replace multiple spaces with a single space
  21629. // trim string
  21630. $html = $this->stringTrim($html);
  21631. // pattern for generic tag
  21632. $tagpattern = '/(<[^>]+>)/';
  21633. // explodes the string
  21634. $a = preg_split($tagpattern, $html, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  21635. // count elements
  21636. $maxel = count($a);
  21637. $elkey = 0;
  21638. $key = 0;
  21639. // create an array of elements
  21640. $dom = array();
  21641. $dom[$key] = array();
  21642. // set inheritable properties fot the first void element
  21643. // 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
  21644. $dom[$key]['tag'] = false;
  21645. $dom[$key]['block'] = false;
  21646. $dom[$key]['value'] = '';
  21647. $dom[$key]['parent'] = 0;
  21648. $dom[$key]['fontname'] = $this->FontFamily;
  21649. $dom[$key]['fontstyle'] = $this->FontStyle;
  21650. $dom[$key]['fontsize'] = $this->FontSizePt;
  21651. $dom[$key]['font-stretch'] = 100;
  21652. $dom[$key]['letter-spacing'] = 0;
  21653. $dom[$key]['stroke'] = $this->textstrokewidth;
  21654. $dom[$key]['fill'] = (($this->textrendermode % 2) == 0);
  21655. $dom[$key]['clip'] = ($this->textrendermode > 3);
  21656. $dom[$key]['line-height'] = $this->cell_height_ratio;
  21657. $dom[$key]['bgcolor'] = false;
  21658. $dom[$key]['fgcolor'] = $this->fgcolor; // color
  21659. $dom[$key]['strokecolor'] = $this->strokecolor;
  21660. $dom[$key]['align'] = '';
  21661. $dom[$key]['listtype'] = '';
  21662. $dom[$key]['text-indent'] = 0;
  21663. $dom[$key]['border'] = array();
  21664. $dom[$key]['dir'] = $this->rtl ? 'rtl' : 'ltr';
  21665. $thead = false; // true when we are inside the THEAD tag
  21666. ++ $key;
  21667. $level = array();
  21668. array_push($level, 0); // root
  21669. while ($elkey < $maxel)
  21670. {
  21671. $dom[$key] = array();
  21672. $element = $a[$elkey];
  21673. $dom[$key]['elkey'] = $elkey;
  21674. if (preg_match($tagpattern, $element))
  21675. {
  21676. // html tag
  21677. $element = substr($element, 1, - 1);
  21678. // get tag name
  21679. preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
  21680. $tagname = strtolower($tag[1]);
  21681. // check if we are inside a table header
  21682. if ($tagname == 'thead')
  21683. {
  21684. if ($element{0} == '/')
  21685. {
  21686. $thead = false;
  21687. }
  21688. else
  21689. {
  21690. $thead = true;
  21691. }
  21692. ++ $elkey;
  21693. continue;
  21694. }
  21695. $dom[$key]['tag'] = true;
  21696. $dom[$key]['value'] = $tagname;
  21697. if (in_array($dom[$key]['value'], $blocktags))
  21698. {
  21699. $dom[$key]['block'] = true;
  21700. }
  21701. else
  21702. {
  21703. $dom[$key]['block'] = false;
  21704. }
  21705. if ($element{0} == '/')
  21706. {
  21707. // *** closing html tag
  21708. $dom[$key]['opening'] = false;
  21709. $dom[$key]['parent'] = end($level);
  21710. array_pop($level);
  21711. $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
  21712. $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
  21713. $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
  21714. $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
  21715. $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
  21716. $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
  21717. $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
  21718. $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
  21719. $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
  21720. $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
  21721. $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
  21722. $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
  21723. $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
  21724. $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
  21725. if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype']))
  21726. {
  21727. $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
  21728. }
  21729. // set the number of columns in table tag
  21730. if (($dom[$key]['value'] == 'tr') and (! isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'])))
  21731. {
  21732. $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
  21733. }
  21734. if (($dom[$key]['value'] == 'td') or ($dom[$key]['value'] == 'th'))
  21735. {
  21736. $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
  21737. for($i = ($dom[$key]['parent'] + 1); $i < $key; ++ $i)
  21738. {
  21739. $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
  21740. }
  21741. $key = $i;
  21742. $parent_table = $dom[$dom[$dom[($dom[$key]['parent'])]['parent']]['parent']];
  21743. $parent_padding = 0;
  21744. $parent_spacing = 0;
  21745. if (isset($parent_table['attribute']['cellpadding']))
  21746. {
  21747. $parent_padding = $this->getHTMLUnitToUnits($parent_table['attribute']['cellpadding'], 1, 'px');
  21748. }
  21749. if (isset($parent_table['attribute']['cellspacing']))
  21750. {
  21751. $parent_spacing = $this->getHTMLUnitToUnits($parent_table['attribute']['cellspacing'], 1, 'px');
  21752. }
  21753. // mark nested tables
  21754. $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true" pcellpadding="' . $parent_padding . '" pcellspacing="' . $parent_spacing . '"', $dom[($dom[$key]['parent'])]['content']);
  21755. // remove thead sections from nested tables
  21756. $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
  21757. $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
  21758. }
  21759. // store header rows on a new table
  21760. if (($dom[$key]['value'] == 'tr') and ($dom[($dom[$key]['parent'])]['thead'] === true))
  21761. {
  21762. if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead']))
  21763. {
  21764. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
  21765. }
  21766. for($i = $dom[$key]['parent']; $i <= $key; ++ $i)
  21767. {
  21768. $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
  21769. }
  21770. if (! isset($dom[($dom[$key]['parent'])]['attribute']))
  21771. {
  21772. $dom[($dom[$key]['parent'])]['attribute'] = array();
  21773. }
  21774. // header elements must be always contained in a single page
  21775. $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
  21776. }
  21777. if (($dom[$key]['value'] == 'table') and (! $this->empty_string($dom[($dom[$key]['parent'])]['thead'])))
  21778. {
  21779. // remove the nobr attributes from the table header
  21780. $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
  21781. $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
  21782. }
  21783. }
  21784. else
  21785. {
  21786. // *** opening or self-closing html tag
  21787. $dom[$key]['opening'] = true;
  21788. $dom[$key]['parent'] = end($level);
  21789. if ((substr($element, - 1, 1) == '/') or (in_array($dom[$key]['value'], $selfclosingtags)))
  21790. {
  21791. // self-closing tag
  21792. $dom[$key]['self'] = true;
  21793. }
  21794. else
  21795. {
  21796. // opening tag
  21797. array_push($level, $key);
  21798. $dom[$key]['self'] = false;
  21799. }
  21800. // copy some values from parent
  21801. $parentkey = 0;
  21802. if ($key > 0)
  21803. {
  21804. $parentkey = $dom[$key]['parent'];
  21805. $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
  21806. $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
  21807. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
  21808. $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
  21809. $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
  21810. $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
  21811. $dom[$key]['fill'] = $dom[$parentkey]['fill'];
  21812. $dom[$key]['clip'] = $dom[$parentkey]['clip'];
  21813. $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
  21814. $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
  21815. $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
  21816. $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
  21817. $dom[$key]['align'] = $dom[$parentkey]['align'];
  21818. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  21819. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  21820. $dom[$key]['border'] = array();
  21821. $dom[$key]['dir'] = $dom[$parentkey]['dir'];
  21822. }
  21823. // get attributes
  21824. preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
  21825. $dom[$key]['attribute'] = array(); // reset attribute array
  21826. while (list($id, $name) = each($attr_array[1]))
  21827. {
  21828. $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
  21829. }
  21830. if (! empty($css))
  21831. {
  21832. // merge eternal CSS style to current style
  21833. $dom[$key]['attribute']['style'] = $this->getTagStyleFromCSS($dom, $key, $css);
  21834. }
  21835. // split style attributes
  21836. if (isset($dom[$key]['attribute']['style']) and ! empty($dom[$key]['attribute']['style']))
  21837. {
  21838. // get style attributes
  21839. preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
  21840. $dom[$key]['style'] = array(); // reset style attribute array
  21841. while (list($id, $name) = each($style_array[1]))
  21842. {
  21843. // in case of duplicate attribute the last replace the previous
  21844. $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
  21845. }
  21846. // --- get some style attributes ---
  21847. // text direction
  21848. if (isset($dom[$key]['style']['direction']))
  21849. {
  21850. $dom[$key]['dir'] = $dom[$key]['style']['direction'];
  21851. }
  21852. // font family
  21853. if (isset($dom[$key]['style']['font-family']))
  21854. {
  21855. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
  21856. }
  21857. // list-style-type
  21858. if (isset($dom[$key]['style']['list-style-type']))
  21859. {
  21860. $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
  21861. if ($dom[$key]['listtype'] == 'inherit')
  21862. {
  21863. $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
  21864. }
  21865. }
  21866. // text-indent
  21867. if (isset($dom[$key]['style']['text-indent']))
  21868. {
  21869. $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
  21870. if ($dom[$key]['text-indent'] == 'inherit')
  21871. {
  21872. $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
  21873. }
  21874. }
  21875. // font size
  21876. if (isset($dom[$key]['style']['font-size']))
  21877. {
  21878. $fsize = trim($dom[$key]['style']['font-size']);
  21879. switch ($fsize)
  21880. {
  21881. // absolute-size
  21882. case 'xx-small' :
  21883. {
  21884. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4;
  21885. break;
  21886. }
  21887. case 'x-small' :
  21888. {
  21889. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3;
  21890. break;
  21891. }
  21892. case 'small' :
  21893. {
  21894. $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2;
  21895. break;
  21896. }
  21897. case 'medium' :
  21898. {
  21899. $dom[$key]['fontsize'] = $dom[0]['fontsize'];
  21900. break;
  21901. }
  21902. case 'large' :
  21903. {
  21904. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 2;
  21905. break;
  21906. }
  21907. case 'x-large' :
  21908. {
  21909. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 4;
  21910. break;
  21911. }
  21912. case 'xx-large' :
  21913. {
  21914. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + 6;
  21915. break;
  21916. }
  21917. // relative-size
  21918. case 'smaller' :
  21919. {
  21920. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3;
  21921. break;
  21922. }
  21923. case 'larger' :
  21924. {
  21925. $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] + 3;
  21926. break;
  21927. }
  21928. default :
  21929. {
  21930. $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true);
  21931. }
  21932. }
  21933. }
  21934. // font-stretch
  21935. if (isset($dom[$key]['style']['font-stretch']))
  21936. {
  21937. $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
  21938. }
  21939. // letter-spacing
  21940. if (isset($dom[$key]['style']['letter-spacing']))
  21941. {
  21942. $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
  21943. }
  21944. // line-height
  21945. if (isset($dom[$key]['style']['line-height']))
  21946. {
  21947. $lineheight = trim($dom[$key]['style']['line-height']);
  21948. switch ($lineheight)
  21949. {
  21950. // A normal line height. This is default
  21951. case 'normal' :
  21952. {
  21953. $dom[$key]['line-height'] = $dom[0]['line-height'];
  21954. break;
  21955. }
  21956. default :
  21957. {
  21958. if (is_numeric($lineheight))
  21959. {
  21960. $lineheight = $lineheight * 100;
  21961. }
  21962. $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
  21963. }
  21964. }
  21965. }
  21966. // font style
  21967. if (isset($dom[$key]['style']['font-weight']) and (strtolower($dom[$key]['style']['font-weight']{0}) == 'b'))
  21968. {
  21969. $dom[$key]['fontstyle'] .= 'B';
  21970. }
  21971. if (isset($dom[$key]['style']['font-style']) and (strtolower($dom[$key]['style']['font-style']{0}) == 'i'))
  21972. {
  21973. $dom[$key]['fontstyle'] .= 'I';
  21974. }
  21975. // font color
  21976. if (isset($dom[$key]['style']['color']) and (! $this->empty_string($dom[$key]['style']['color'])))
  21977. {
  21978. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']);
  21979. }
  21980. elseif ($dom[$key]['value'] == 'a')
  21981. {
  21982. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  21983. }
  21984. // background color
  21985. if (isset($dom[$key]['style']['background-color']) and (! $this->empty_string($dom[$key]['style']['background-color'])))
  21986. {
  21987. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
  21988. }
  21989. // text-decoration
  21990. if (isset($dom[$key]['style']['text-decoration']))
  21991. {
  21992. $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
  21993. foreach ($decors as $dec)
  21994. {
  21995. $dec = trim($dec);
  21996. if (! $this->empty_string($dec))
  21997. {
  21998. if ($dec{0} == 'u')
  21999. {
  22000. // underline
  22001. $dom[$key]['fontstyle'] .= 'U';
  22002. }
  22003. elseif ($dec{0} == 'l')
  22004. {
  22005. // line-trough
  22006. $dom[$key]['fontstyle'] .= 'D';
  22007. }
  22008. elseif ($dec{0} == 'o')
  22009. {
  22010. // overline
  22011. $dom[$key]['fontstyle'] .= 'O';
  22012. }
  22013. }
  22014. }
  22015. }
  22016. elseif ($dom[$key]['value'] == 'a')
  22017. {
  22018. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  22019. }
  22020. // check for width attribute
  22021. if (isset($dom[$key]['style']['width']))
  22022. {
  22023. $dom[$key]['width'] = $dom[$key]['style']['width'];
  22024. }
  22025. // check for height attribute
  22026. if (isset($dom[$key]['style']['height']))
  22027. {
  22028. $dom[$key]['height'] = $dom[$key]['style']['height'];
  22029. }
  22030. // check for text alignment
  22031. if (isset($dom[$key]['style']['text-align']))
  22032. {
  22033. $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
  22034. }
  22035. // check for CSS border properties
  22036. if (isset($dom[$key]['style']['border']))
  22037. {
  22038. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
  22039. if (! empty($borderstyle))
  22040. {
  22041. $dom[$key]['border']['LTRB'] = $borderstyle;
  22042. }
  22043. }
  22044. if (isset($dom[$key]['style']['border-color']))
  22045. {
  22046. $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
  22047. if (isset($brd_colors[3]))
  22048. {
  22049. $dom[$key]['border']['L']['color'] = $this->convertHTMLColorToDec($brd_colors[3]);
  22050. }
  22051. if (isset($brd_colors[1]))
  22052. {
  22053. $dom[$key]['border']['R']['color'] = $this->convertHTMLColorToDec($brd_colors[1]);
  22054. }
  22055. if (isset($brd_colors[0]))
  22056. {
  22057. $dom[$key]['border']['T']['color'] = $this->convertHTMLColorToDec($brd_colors[0]);
  22058. }
  22059. if (isset($brd_colors[2]))
  22060. {
  22061. $dom[$key]['border']['B']['color'] = $this->convertHTMLColorToDec($brd_colors[2]);
  22062. }
  22063. }
  22064. if (isset($dom[$key]['style']['border-width']))
  22065. {
  22066. $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
  22067. if (isset($brd_widths[3]))
  22068. {
  22069. $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
  22070. }
  22071. if (isset($brd_widths[1]))
  22072. {
  22073. $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
  22074. }
  22075. if (isset($brd_widths[0]))
  22076. {
  22077. $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
  22078. }
  22079. if (isset($brd_widths[2]))
  22080. {
  22081. $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
  22082. }
  22083. }
  22084. if (isset($dom[$key]['style']['border-style']))
  22085. {
  22086. $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
  22087. if (isset($brd_styles[3]))
  22088. {
  22089. $dom[$key]['border']['L']['cap'] = 'square';
  22090. $dom[$key]['border']['L']['join'] = 'miter';
  22091. $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
  22092. if ($dom[$key]['border']['L']['dash'] < 0)
  22093. {
  22094. $dom[$key]['border']['L'] = array();
  22095. }
  22096. }
  22097. if (isset($brd_styles[1]))
  22098. {
  22099. $dom[$key]['border']['R']['cap'] = 'square';
  22100. $dom[$key]['border']['R']['join'] = 'miter';
  22101. $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
  22102. if ($dom[$key]['border']['R']['dash'] < 0)
  22103. {
  22104. $dom[$key]['border']['R'] = array();
  22105. }
  22106. }
  22107. if (isset($brd_styles[0]))
  22108. {
  22109. $dom[$key]['border']['T']['cap'] = 'square';
  22110. $dom[$key]['border']['T']['join'] = 'miter';
  22111. $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
  22112. if ($dom[$key]['border']['T']['dash'] < 0)
  22113. {
  22114. $dom[$key]['border']['T'] = array();
  22115. }
  22116. }
  22117. if (isset($brd_styles[2]))
  22118. {
  22119. $dom[$key]['border']['B']['cap'] = 'square';
  22120. $dom[$key]['border']['B']['join'] = 'miter';
  22121. $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
  22122. if ($dom[$key]['border']['B']['dash'] < 0)
  22123. {
  22124. $dom[$key]['border']['B'] = array();
  22125. }
  22126. }
  22127. }
  22128. $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
  22129. foreach ($cellside as $bsk => $bsv)
  22130. {
  22131. if (isset($dom[$key]['style']['border-' . $bsv]))
  22132. {
  22133. $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-' . $bsv]);
  22134. if (! empty($borderstyle))
  22135. {
  22136. $dom[$key]['border'][$bsk] = $borderstyle;
  22137. }
  22138. }
  22139. if (isset($dom[$key]['style']['border-' . $bsv . '-color']))
  22140. {
  22141. $dom[$key]['border'][$bsk]['color'] = $this->convertHTMLColorToDec($dom[$key]['style']['border-' . $bsv . '-color']);
  22142. }
  22143. if (isset($dom[$key]['style']['border-' . $bsv . '-width']))
  22144. {
  22145. $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-' . $bsv . '-width']);
  22146. }
  22147. if (isset($dom[$key]['style']['border-' . $bsv . '-style']))
  22148. {
  22149. $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-' . $bsv . '-style']);
  22150. if ($dom[$key]['border'][$bsk]['dash'] < 0)
  22151. {
  22152. $dom[$key]['border'][$bsk] = array();
  22153. }
  22154. }
  22155. }
  22156. // check for CSS padding properties
  22157. if (isset($dom[$key]['style']['padding']))
  22158. {
  22159. $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
  22160. }
  22161. else
  22162. {
  22163. $dom[$key]['padding'] = $this->cell_padding;
  22164. }
  22165. foreach ($cellside as $psk => $psv)
  22166. {
  22167. if (isset($dom[$key]['style']['padding-' . $psv]))
  22168. {
  22169. $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-' . $psv], 0, 'px', false);
  22170. }
  22171. }
  22172. // check for CSS margin properties
  22173. if (isset($dom[$key]['style']['margin']))
  22174. {
  22175. $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
  22176. }
  22177. else
  22178. {
  22179. $dom[$key]['margin'] = $this->cell_margin;
  22180. }
  22181. foreach ($cellside as $psk => $psv)
  22182. {
  22183. if (isset($dom[$key]['style']['margin-' . $psv]))
  22184. {
  22185. $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-' . $psv]), 0, 'px', false);
  22186. }
  22187. }
  22188. // page-break-inside
  22189. if (isset($dom[$key]['style']['page-break-inside']) and ($dom[$key]['style']['page-break-inside'] == 'avoid'))
  22190. {
  22191. $dom[$key]['attribute']['nobr'] = 'true';
  22192. }
  22193. // page-break-before
  22194. if (isset($dom[$key]['style']['page-break-before']))
  22195. {
  22196. if ($dom[$key]['style']['page-break-before'] == 'always')
  22197. {
  22198. $dom[$key]['attribute']['pagebreak'] = 'true';
  22199. }
  22200. elseif ($dom[$key]['style']['page-break-before'] == 'left')
  22201. {
  22202. $dom[$key]['attribute']['pagebreak'] = 'left';
  22203. }
  22204. elseif ($dom[$key]['style']['page-break-before'] == 'right')
  22205. {
  22206. $dom[$key]['attribute']['pagebreak'] = 'right';
  22207. }
  22208. }
  22209. // page-break-after
  22210. if (isset($dom[$key]['style']['page-break-after']))
  22211. {
  22212. if ($dom[$key]['style']['page-break-after'] == 'always')
  22213. {
  22214. $dom[$key]['attribute']['pagebreakafter'] = 'true';
  22215. }
  22216. elseif ($dom[$key]['style']['page-break-after'] == 'left')
  22217. {
  22218. $dom[$key]['attribute']['pagebreakafter'] = 'left';
  22219. }
  22220. elseif ($dom[$key]['style']['page-break-after'] == 'right')
  22221. {
  22222. $dom[$key]['attribute']['pagebreakafter'] = 'right';
  22223. }
  22224. }
  22225. }
  22226. if (isset($dom[$key]['attribute']['border']) and ($dom[$key]['attribute']['border'] != 0))
  22227. {
  22228. $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'] . ' solid black');
  22229. if (! empty($borderstyle))
  22230. {
  22231. $dom[$key]['border']['LTRB'] = $borderstyle;
  22232. }
  22233. }
  22234. // check for font tag
  22235. if ($dom[$key]['value'] == 'font')
  22236. {
  22237. // font family
  22238. if (isset($dom[$key]['attribute']['face']))
  22239. {
  22240. $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
  22241. }
  22242. // font size
  22243. if (isset($dom[$key]['attribute']['size']))
  22244. {
  22245. if ($key > 0)
  22246. {
  22247. if ($dom[$key]['attribute']['size']{0} == '+')
  22248. {
  22249. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] + intval(substr($dom[$key]['attribute']['size'], 1));
  22250. }
  22251. elseif ($dom[$key]['attribute']['size']{0} == '-')
  22252. {
  22253. $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
  22254. }
  22255. else
  22256. {
  22257. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  22258. }
  22259. }
  22260. else
  22261. {
  22262. $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
  22263. }
  22264. }
  22265. }
  22266. // force natural alignment for lists
  22267. if ((($dom[$key]['value'] == 'ul') or ($dom[$key]['value'] == 'ol') or ($dom[$key]['value'] == 'dl')) and (! isset($dom[$key]['align']) or $this->empty_string($dom[$key]['align']) or ($dom[$key]['align'] != 'J')))
  22268. {
  22269. if ($this->rtl)
  22270. {
  22271. $dom[$key]['align'] = 'R';
  22272. }
  22273. else
  22274. {
  22275. $dom[$key]['align'] = 'L';
  22276. }
  22277. }
  22278. if (($dom[$key]['value'] == 'small') or ($dom[$key]['value'] == 'sup') or ($dom[$key]['value'] == 'sub'))
  22279. {
  22280. if (! isset($dom[$key]['attribute']['size']) and ! isset($dom[$key]['style']['font-size']))
  22281. {
  22282. $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO;
  22283. }
  22284. }
  22285. if (($dom[$key]['value'] == 'strong') or ($dom[$key]['value'] == 'b'))
  22286. {
  22287. $dom[$key]['fontstyle'] .= 'B';
  22288. }
  22289. if (($dom[$key]['value'] == 'em') or ($dom[$key]['value'] == 'i'))
  22290. {
  22291. $dom[$key]['fontstyle'] .= 'I';
  22292. }
  22293. if ($dom[$key]['value'] == 'u')
  22294. {
  22295. $dom[$key]['fontstyle'] .= 'U';
  22296. }
  22297. if (($dom[$key]['value'] == 'del') or ($dom[$key]['value'] == 's') or ($dom[$key]['value'] == 'strike'))
  22298. {
  22299. $dom[$key]['fontstyle'] .= 'D';
  22300. }
  22301. if (! isset($dom[$key]['style']['text-decoration']) and ($dom[$key]['value'] == 'a'))
  22302. {
  22303. $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle;
  22304. }
  22305. if (($dom[$key]['value'] == 'pre') or ($dom[$key]['value'] == 'tt'))
  22306. {
  22307. $dom[$key]['fontname'] = $this->default_monospaced_font;
  22308. }
  22309. if (($dom[$key]['value']{0} == 'h') and (intval($dom[$key]['value']{1}) > 0) and (intval($dom[$key]['value']{1}) < 7))
  22310. {
  22311. // headings h1, h2, h3, h4, h5, h6
  22312. if (! isset($dom[$key]['attribute']['size']) and ! isset($dom[$key]['style']['font-size']))
  22313. {
  22314. $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
  22315. $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
  22316. }
  22317. if (! isset($dom[$key]['style']['font-weight']))
  22318. {
  22319. $dom[$key]['fontstyle'] .= 'B';
  22320. }
  22321. }
  22322. if (($dom[$key]['value'] == 'table'))
  22323. {
  22324. $dom[$key]['rows'] = 0; // number of rows
  22325. $dom[$key]['trids'] = array(); // IDs of TR elements
  22326. $dom[$key]['thead'] = ''; // table header rows
  22327. }
  22328. if (($dom[$key]['value'] == 'tr'))
  22329. {
  22330. $dom[$key]['cols'] = 0;
  22331. if ($thead)
  22332. {
  22333. $dom[$key]['thead'] = true;
  22334. // rows on thead block are printed as a separate table
  22335. }
  22336. else
  22337. {
  22338. $dom[$key]['thead'] = false;
  22339. // store the number of rows on table element
  22340. ++ $dom[($dom[$key]['parent'])]['rows'];
  22341. // store the TR elements IDs on table element
  22342. array_push($dom[($dom[$key]['parent'])]['trids'], $key);
  22343. }
  22344. }
  22345. if (($dom[$key]['value'] == 'th') or ($dom[$key]['value'] == 'td'))
  22346. {
  22347. if (isset($dom[$key]['attribute']['colspan']))
  22348. {
  22349. $colspan = intval($dom[$key]['attribute']['colspan']);
  22350. }
  22351. else
  22352. {
  22353. $colspan = 1;
  22354. }
  22355. $dom[$key]['attribute']['colspan'] = $colspan;
  22356. $dom[($dom[$key]['parent'])]['cols'] += $colspan;
  22357. }
  22358. // text direction
  22359. if (isset($dom[$key]['attribute']['dir']))
  22360. {
  22361. $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
  22362. }
  22363. // set foreground color attribute
  22364. if (isset($dom[$key]['attribute']['color']) and (! $this->empty_string($dom[$key]['attribute']['color'])))
  22365. {
  22366. $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
  22367. }
  22368. elseif (! isset($dom[$key]['style']['color']) and ($dom[$key]['value'] == 'a'))
  22369. {
  22370. $dom[$key]['fgcolor'] = $this->htmlLinkColorArray;
  22371. }
  22372. // set background color attribute
  22373. if (isset($dom[$key]['attribute']['bgcolor']) and (! $this->empty_string($dom[$key]['attribute']['bgcolor'])))
  22374. {
  22375. $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
  22376. }
  22377. // set stroke color attribute
  22378. if (isset($dom[$key]['attribute']['strokecolor']) and (! $this->empty_string($dom[$key]['attribute']['strokecolor'])))
  22379. {
  22380. $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']);
  22381. }
  22382. // check for width attribute
  22383. if (isset($dom[$key]['attribute']['width']))
  22384. {
  22385. $dom[$key]['width'] = $dom[$key]['attribute']['width'];
  22386. }
  22387. // check for height attribute
  22388. if (isset($dom[$key]['attribute']['height']))
  22389. {
  22390. $dom[$key]['height'] = $dom[$key]['attribute']['height'];
  22391. }
  22392. // check for text alignment
  22393. if (isset($dom[$key]['attribute']['align']) and (! $this->empty_string($dom[$key]['attribute']['align'])) and ($dom[$key]['value'] !== 'img'))
  22394. {
  22395. $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
  22396. }
  22397. // check for text rendering mode (the following attributes do not exist in HTML)
  22398. if (isset($dom[$key]['attribute']['stroke']))
  22399. {
  22400. // font stroke width
  22401. $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
  22402. }
  22403. if (isset($dom[$key]['attribute']['fill']))
  22404. {
  22405. // font fill
  22406. if ($dom[$key]['attribute']['fill'] == 'true')
  22407. {
  22408. $dom[$key]['fill'] = true;
  22409. }
  22410. else
  22411. {
  22412. $dom[$key]['fill'] = false;
  22413. }
  22414. }
  22415. if (isset($dom[$key]['attribute']['clip']))
  22416. {
  22417. // clipping mode
  22418. if ($dom[$key]['attribute']['clip'] == 'true')
  22419. {
  22420. $dom[$key]['clip'] = true;
  22421. }
  22422. else
  22423. {
  22424. $dom[$key]['clip'] = false;
  22425. }
  22426. }
  22427. } // end opening tag
  22428. }
  22429. else
  22430. {
  22431. // text
  22432. $dom[$key]['tag'] = false;
  22433. $dom[$key]['block'] = false;
  22434. $element = str_replace('$nbsp;', $this->unichr(160), $element);
  22435. $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
  22436. $dom[$key]['parent'] = end($level);
  22437. }
  22438. ++ $elkey;
  22439. ++ $key;
  22440. }
  22441. return $dom;
  22442. }
  22443. /**
  22444. * Returns the string used to find spaces
  22445. * @return string
  22446. * @access protected
  22447. * @author Nicola Asuni
  22448. * @since 4.8.024 (2010-01-15)
  22449. */
  22450. protected function getSpaceString()
  22451. {
  22452. $spacestr = chr(32);
  22453. if ($this->isUnicodeFont())
  22454. {
  22455. $spacestr = chr(0) . chr(32);
  22456. }
  22457. return $spacestr;
  22458. }
  22459. /**
  22460. * Prints a cell (rectangular area) with optional borders, background color and html text string.
  22461. * 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 />
  22462. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  22463. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  22464. * @param float $h Cell minimum height. The cell extends automatically if needed.
  22465. * @param float $x upper-left corner X coordinate
  22466. * @param float $y upper-left corner Y coordinate
  22467. * @param string $html html text to print. Default value: empty string.
  22468. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  22469. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL language)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  22470. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  22471. * @param boolean $fill Indicates if the cell background must be painted (true) or transparent (false).
  22472. * @param boolean $reseth if true reset the last cell height (default true).
  22473. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  22474. * @param boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
  22475. * @access public
  22476. * @uses MultiCell()
  22477. * @see Multicell(), writeHTML()
  22478. */
  22479. public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true)
  22480. {
  22481. return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0);
  22482. }
  22483. /**
  22484. * Allows to preserve some HTML formatting (limited support).<br />
  22485. * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
  22486. * 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
  22487. * @param string $html text to display
  22488. * @param boolean $ln if true add a new line after text (default = true)
  22489. * @param boolean $fill Indicates if the background must be painted (true) or transparent (false).
  22490. * @param boolean $reseth if true reset the last cell height (default false).
  22491. * @param boolean $cell if true add the current left (or right for RTL) padding to each Write (default false).
  22492. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  22493. * @access public
  22494. */
  22495. public function writeHTML($html, $ln = true, $fill = false, $reseth = false, $cell = false, $align = '')
  22496. {
  22497. $gvars = $this->getGraphicVars();
  22498. // store current values
  22499. $prev_cell_margin = $this->cell_margin;
  22500. $prev_cell_padding = $this->cell_padding;
  22501. $prevPage = $this->page;
  22502. $prevlMargin = $this->lMargin;
  22503. $prevrMargin = $this->rMargin;
  22504. $curfontname = $this->FontFamily;
  22505. $curfontstyle = $this->FontStyle;
  22506. $curfontsize = $this->FontSizePt;
  22507. $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
  22508. $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
  22509. $curfontstretcing = $this->font_stretching;
  22510. $curfontkerning = $this->font_spacing;
  22511. $this->newline = true;
  22512. $newline = true;
  22513. $startlinepage = $this->page;
  22514. $minstartliney = $this->y;
  22515. $maxbottomliney = 0;
  22516. $startlinex = $this->x;
  22517. $startliney = $this->y;
  22518. $yshift = 0;
  22519. $loop = 0;
  22520. $curpos = 0;
  22521. $this_method_vars = array();
  22522. $undo = false;
  22523. $fontaligned = false;
  22524. $reverse_dir = false; // true when the text direction is reversed
  22525. $this->premode = false;
  22526. if ($this->inxobj)
  22527. {
  22528. // we are inside an XObject template
  22529. $pask = count($this->xobjects[$this->xobjid]['annotations']);
  22530. }
  22531. elseif (isset($this->PageAnnots[$this->page]))
  22532. {
  22533. $pask = count($this->PageAnnots[$this->page]);
  22534. }
  22535. else
  22536. {
  22537. $pask = 0;
  22538. }
  22539. if ($this->inxobj)
  22540. {
  22541. // we are inside an XObject template
  22542. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  22543. }
  22544. elseif (! $this->InFooter)
  22545. {
  22546. if (isset($this->footerlen[$this->page]))
  22547. {
  22548. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  22549. }
  22550. else
  22551. {
  22552. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  22553. }
  22554. $startlinepos = $this->footerpos[$this->page];
  22555. }
  22556. else
  22557. {
  22558. // we are inside the footer
  22559. $startlinepos = $this->pagelen[$this->page];
  22560. }
  22561. $lalign = $align;
  22562. $plalign = $align;
  22563. if ($this->rtl)
  22564. {
  22565. $w = $this->x - $this->lMargin;
  22566. }
  22567. else
  22568. {
  22569. $w = $this->w - $this->rMargin - $this->x;
  22570. }
  22571. $w -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  22572. if ($cell)
  22573. {
  22574. if ($this->rtl)
  22575. {
  22576. $this->x -= $this->cell_padding['R'];
  22577. $this->lMargin += $this->cell_padding['R'];
  22578. }
  22579. else
  22580. {
  22581. $this->x += $this->cell_padding['L'];
  22582. $this->rMargin += $this->cell_padding['L'];
  22583. }
  22584. }
  22585. if ($this->customlistindent >= 0)
  22586. {
  22587. $this->listindent = $this->customlistindent;
  22588. }
  22589. else
  22590. {
  22591. $this->listindent = $this->GetStringWidth('0000');
  22592. }
  22593. $this->listindentlevel = 0;
  22594. // save previous states
  22595. $prev_cell_height_ratio = $this->cell_height_ratio;
  22596. $prev_listnum = $this->listnum;
  22597. $prev_listordered = $this->listordered;
  22598. $prev_listcount = $this->listcount;
  22599. $prev_lispacer = $this->lispacer;
  22600. $this->listnum = 0;
  22601. $this->listordered = array();
  22602. $this->listcount = array();
  22603. $this->lispacer = '';
  22604. if (($this->empty_string($this->lasth)) or ($reseth))
  22605. {
  22606. // reset row height
  22607. $this->resetLastH();
  22608. }
  22609. $dom = $this->getHtmlDomArray($html);
  22610. $maxel = count($dom);
  22611. $key = 0;
  22612. while ($key < $maxel)
  22613. {
  22614. if ($dom[$key]['tag'] and isset($dom[$key]['attribute']['pagebreak']))
  22615. {
  22616. // check for pagebreak
  22617. if (($dom[$key]['attribute']['pagebreak'] == 'true') or ($dom[$key]['attribute']['pagebreak'] == 'left') or ($dom[$key]['attribute']['pagebreak'] == 'right'))
  22618. {
  22619. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  22620. $this->checkPageBreak($this->PageBreakTrigger + 1);
  22621. }
  22622. if ((($dom[$key]['attribute']['pagebreak'] == 'left') and (((! $this->rtl) and (($this->page % 2) == 0)) or (($this->rtl) and (($this->page % 2) != 0)))) or (($dom[$key]['attribute']['pagebreak'] == 'right') and (((! $this->rtl) and (($this->page % 2) != 0)) or (($this->rtl) and (($this->page % 2) == 0)))))
  22623. {
  22624. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  22625. $this->checkPageBreak($this->PageBreakTrigger + 1);
  22626. }
  22627. }
  22628. if ($dom[$key]['tag'] and $dom[$key]['opening'] and isset($dom[$key]['attribute']['nobr']) and ($dom[$key]['attribute']['nobr'] == 'true'))
  22629. {
  22630. if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) and ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true'))
  22631. {
  22632. $dom[$key]['attribute']['nobr'] = false;
  22633. }
  22634. else
  22635. {
  22636. // store current object
  22637. $this->startTransaction();
  22638. // save this method vars
  22639. $this_method_vars['html'] = $html;
  22640. $this_method_vars['ln'] = $ln;
  22641. $this_method_vars['fill'] = $fill;
  22642. $this_method_vars['reseth'] = $reseth;
  22643. $this_method_vars['cell'] = $cell;
  22644. $this_method_vars['align'] = $align;
  22645. $this_method_vars['gvars'] = $gvars;
  22646. $this_method_vars['prevPage'] = $prevPage;
  22647. $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
  22648. $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
  22649. $this_method_vars['prevlMargin'] = $prevlMargin;
  22650. $this_method_vars['prevrMargin'] = $prevrMargin;
  22651. $this_method_vars['curfontname'] = $curfontname;
  22652. $this_method_vars['curfontstyle'] = $curfontstyle;
  22653. $this_method_vars['curfontsize'] = $curfontsize;
  22654. $this_method_vars['curfontascent'] = $curfontascent;
  22655. $this_method_vars['curfontdescent'] = $curfontdescent;
  22656. $this_method_vars['curfontstretcing'] = $curfontstretcing;
  22657. $this_method_vars['curfontkerning'] = $curfontkerning;
  22658. $this_method_vars['minstartliney'] = $minstartliney;
  22659. $this_method_vars['maxbottomliney'] = $maxbottomliney;
  22660. $this_method_vars['yshift'] = $yshift;
  22661. $this_method_vars['startlinepage'] = $startlinepage;
  22662. $this_method_vars['startlinepos'] = $startlinepos;
  22663. $this_method_vars['startlinex'] = $startlinex;
  22664. $this_method_vars['startliney'] = $startliney;
  22665. $this_method_vars['newline'] = $newline;
  22666. $this_method_vars['loop'] = $loop;
  22667. $this_method_vars['curpos'] = $curpos;
  22668. $this_method_vars['pask'] = $pask;
  22669. $this_method_vars['lalign'] = $lalign;
  22670. $this_method_vars['plalign'] = $plalign;
  22671. $this_method_vars['w'] = $w;
  22672. $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
  22673. $this_method_vars['prev_listnum'] = $prev_listnum;
  22674. $this_method_vars['prev_listordered'] = $prev_listordered;
  22675. $this_method_vars['prev_listcount'] = $prev_listcount;
  22676. $this_method_vars['prev_lispacer'] = $prev_lispacer;
  22677. $this_method_vars['fontaligned'] = $fontaligned;
  22678. $this_method_vars['key'] = $key;
  22679. $this_method_vars['dom'] = $dom;
  22680. }
  22681. }
  22682. // print THEAD block
  22683. if (($dom[$key]['value'] == 'tr') and isset($dom[$key]['thead']) and $dom[$key]['thead'])
  22684. {
  22685. if (isset($dom[$key]['parent']) and isset($dom[$dom[$key]['parent']]['thead']) and ! $this->empty_string($dom[$dom[$key]['parent']]['thead']))
  22686. {
  22687. $this->inthead = true;
  22688. // print table header (thead)
  22689. $this->writeHTML($this->thead, false, false, false, false, '');
  22690. // check if we are on a new page or on a new column
  22691. if (($this->y < $this->start_transaction_y) or ($this->checkPageBreak($this->lasth, '', false)))
  22692. {
  22693. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  22694. // restore previous object
  22695. $this->rollbackTransaction(true);
  22696. // restore previous values
  22697. foreach ($this_method_vars as $vkey => $vval)
  22698. {
  22699. $$vkey = $vval;
  22700. }
  22701. // disable table header
  22702. $tmp_thead = $this->thead;
  22703. $this->thead = '';
  22704. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  22705. $pre_y = $this->y;
  22706. if ((! $this->checkPageBreak($this->PageBreakTrigger + 1)) and ($this->y < $pre_y))
  22707. {
  22708. // fix for multicolumn mode
  22709. $startliney = $this->y;
  22710. }
  22711. $this->start_transaction_page = $this->page;
  22712. $this->start_transaction_y = $this->y;
  22713. // restore table header
  22714. $this->thead = $tmp_thead;
  22715. // fix table border properties
  22716. if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing']))
  22717. {
  22718. $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
  22719. }
  22720. else
  22721. {
  22722. $tmp_cellspacing = 0;
  22723. }
  22724. $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page;
  22725. $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column;
  22726. $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y + $tmp_cellspacing;
  22727. $xoffset = ($this->x - $dom[$dom[$key]['parent']]['borderposition']['x']);
  22728. $dom[$dom[$key]['parent']]['borderposition']['x'] += $xoffset;
  22729. $dom[$dom[$key]['parent']]['borderposition']['xmax'] += $xoffset;
  22730. // print table header (thead)
  22731. $this->writeHTML($this->thead, false, false, false, false, '');
  22732. }
  22733. }
  22734. // move $key index forward to skip THEAD block
  22735. while (($key < $maxel) and (! (($dom[$key]['tag'] and $dom[$key]['opening'] and ($dom[$key]['value'] == 'tr') and (! isset($dom[$key]['thead']) or ! $dom[$key]['thead'])) or ($dom[$key]['tag'] and (! $dom[$key]['opening']) and ($dom[$key]['value'] == 'table')))))
  22736. {
  22737. ++ $key;
  22738. }
  22739. }
  22740. if ($dom[$key]['tag'] or ($key == 0))
  22741. {
  22742. if ((($dom[$key]['value'] == 'table') or ($dom[$key]['value'] == 'tr')) and (isset($dom[$key]['align'])))
  22743. {
  22744. $dom[$key]['align'] = ($this->rtl) ? 'R' : 'L';
  22745. }
  22746. // vertically align image in line
  22747. if ((! $this->newline) and ($dom[$key]['value'] == 'img') and (isset($dom[$key]['height'])) and ($dom[$key]['height'] > 0))
  22748. {
  22749. // get image height
  22750. $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth, 'px');
  22751. // check for automatic line break
  22752. $autolinebreak = false;
  22753. if (isset($dom[$key]['width']) and ($dom[$key]['width'] > 0))
  22754. {
  22755. $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
  22756. if (($this->rtl and (($this->x - $imgw) < ($this->lMargin + $this->cell_padding['L']))) or (! $this->rtl and (($this->x + $imgw) > ($this->w - $this->rMargin - $this->cell_padding['R']))))
  22757. {
  22758. // add automatic line break
  22759. $autolinebreak = true;
  22760. $this->Ln('', $cell);
  22761. // go back to evaluate this line break
  22762. -- $key;
  22763. }
  22764. }
  22765. if (! $autolinebreak)
  22766. {
  22767. if (! $this->InFooter)
  22768. {
  22769. $pre_y = $this->y;
  22770. // check for page break
  22771. if ((! $this->checkPageBreak($imgh)) and ($this->y < $pre_y))
  22772. {
  22773. // fix for multicolumn mode
  22774. $startliney = $this->y;
  22775. }
  22776. }
  22777. if ($this->page > $startlinepage)
  22778. {
  22779. // fix line splitted over two pages
  22780. if (isset($this->footerlen[$startlinepage]))
  22781. {
  22782. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  22783. }
  22784. // line to be moved one page forward
  22785. $pagebuff = $this->getPageBuffer($startlinepage);
  22786. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  22787. $tstart = substr($pagebuff, 0, $startlinepos);
  22788. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  22789. // remove line from previous page
  22790. $this->setPageBuffer($startlinepage, $tstart . '' . $tend);
  22791. $pagebuff = $this->getPageBuffer($this->page);
  22792. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  22793. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  22794. // add line start to current page
  22795. $yshift = $minstartliney - $this->y;
  22796. if ($fontaligned)
  22797. {
  22798. $yshift += ($curfontsize / $this->k);
  22799. }
  22800. $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k));
  22801. $this->setPageBuffer($this->page, $tstart . "\nq\n" . $try . "\n" . $linebeg . "\nQ\n" . $tend);
  22802. // shift the annotations and links
  22803. if (isset($this->PageAnnots[$this->page]))
  22804. {
  22805. $next_pask = count($this->PageAnnots[$this->page]);
  22806. }
  22807. else
  22808. {
  22809. $next_pask = 0;
  22810. }
  22811. if (isset($this->PageAnnots[$startlinepage]))
  22812. {
  22813. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac)
  22814. {
  22815. if ($pak >= $pask)
  22816. {
  22817. $this->PageAnnots[$this->page][] = $pac;
  22818. unset($this->PageAnnots[$startlinepage][$pak]);
  22819. $npak = count($this->PageAnnots[$this->page]) - 1;
  22820. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  22821. }
  22822. }
  22823. }
  22824. $pask = $next_pask;
  22825. $startlinepos = $this->cntmrk[$this->page];
  22826. $startlinepage = $this->page;
  22827. $startliney = $this->y;
  22828. $this->newline = false;
  22829. }
  22830. $this->y += ((($curfontsize * $this->cell_height_ratio / $this->k) + $curfontascent - $curfontdescent) / 2) - $imgh;
  22831. $minstartliney = min($this->y, $minstartliney);
  22832. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  22833. }
  22834. }
  22835. elseif (isset($dom[$key]['fontname']) or isset($dom[$key]['fontstyle']) or isset($dom[$key]['fontsize']) or isset($dom[$key]['line-height']))
  22836. {
  22837. // account for different font size
  22838. $pfontname = $curfontname;
  22839. $pfontstyle = $curfontstyle;
  22840. $pfontsize = $curfontsize;
  22841. $fontname = isset($dom[$key]['fontname']) ? $dom[$key]['fontname'] : $curfontname;
  22842. $fontstyle = isset($dom[$key]['fontstyle']) ? $dom[$key]['fontstyle'] : $curfontstyle;
  22843. $fontsize = isset($dom[$key]['fontsize']) ? $dom[$key]['fontsize'] : $curfontsize;
  22844. $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
  22845. $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
  22846. if (($fontname != $curfontname) or ($fontstyle != $curfontstyle) or ($fontsize != $curfontsize) or ($this->cell_height_ratio != $dom[$key]['line-height']))
  22847. {
  22848. if ((! $this->newline) and ($key < ($maxel - 1)) and ((is_numeric($fontsize) and ($fontsize >= 0) and is_numeric($curfontsize) and ($curfontsize >= 0) and ($fontsize != $curfontsize)) or ($this->cell_height_ratio != $dom[$key]['line-height'])))
  22849. {
  22850. if ($this->page > $startlinepage)
  22851. {
  22852. // fix lines splitted over two pages
  22853. if (isset($this->footerlen[$startlinepage]))
  22854. {
  22855. $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  22856. }
  22857. // line to be moved one page forward
  22858. $pagebuff = $this->getPageBuffer($startlinepage);
  22859. $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
  22860. $tstart = substr($pagebuff, 0, $startlinepos);
  22861. $tend = substr($this->getPageBuffer($startlinepage), $curpos);
  22862. // remove line start from previous page
  22863. $this->setPageBuffer($startlinepage, $tstart . '' . $tend);
  22864. $pagebuff = $this->getPageBuffer($this->page);
  22865. $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
  22866. $tend = substr($pagebuff, $this->cntmrk[$this->page]);
  22867. // add line start to current page
  22868. $yshift = $minstartliney - $this->y;
  22869. $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k));
  22870. $this->setPageBuffer($this->page, $tstart . "\nq\n" . $try . "\n" . $linebeg . "\nQ\n" . $tend);
  22871. // shift the annotations and links
  22872. if (isset($this->PageAnnots[$this->page]))
  22873. {
  22874. $next_pask = count($this->PageAnnots[$this->page]);
  22875. }
  22876. else
  22877. {
  22878. $next_pask = 0;
  22879. }
  22880. if (isset($this->PageAnnots[$startlinepage]))
  22881. {
  22882. foreach ($this->PageAnnots[$startlinepage] as $pak => $pac)
  22883. {
  22884. if ($pak >= $pask)
  22885. {
  22886. $this->PageAnnots[$this->page][] = $pac;
  22887. unset($this->PageAnnots[$startlinepage][$pak]);
  22888. $npak = count($this->PageAnnots[$this->page]) - 1;
  22889. $this->PageAnnots[$this->page][$npak]['y'] -= $yshift;
  22890. }
  22891. }
  22892. }
  22893. $pask = $next_pask;
  22894. $startlinepos = $this->cntmrk[$this->page];
  22895. $startlinepage = $this->page;
  22896. $startliney = $this->y;
  22897. }
  22898. if (! isset($dom[$key]['line-height']))
  22899. {
  22900. $dom[$key]['line-height'] = $this->cell_height_ratio;
  22901. }
  22902. if (! $dom[$key]['block'])
  22903. {
  22904. $this->y += (((($curfontsize * $this->cell_height_ratio) - ($fontsize * $dom[$key]['line-height'])) / $this->k) + $curfontascent - $fontascent - $curfontdescent + $fontdescent) / 2;
  22905. if (($dom[$key]['value'] != 'sup') and ($dom[$key]['value'] != 'sub'))
  22906. {
  22907. $minstartliney = min($this->y, $minstartliney);
  22908. $maxbottomliney = max(($this->y + (($fontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  22909. }
  22910. }
  22911. $this->cell_height_ratio = $dom[$key]['line-height'];
  22912. $fontaligned = true;
  22913. }
  22914. $this->SetFont($fontname, $fontstyle, $fontsize);
  22915. // reset row height
  22916. $this->resetLastH();
  22917. $curfontname = $fontname;
  22918. $curfontstyle = $fontstyle;
  22919. $curfontsize = $fontsize;
  22920. $curfontascent = $fontascent;
  22921. $curfontdescent = $fontdescent;
  22922. }
  22923. }
  22924. // set text rendering mode
  22925. $textstroke = isset($dom[$key]['stroke']) ? $dom[$key]['stroke'] : $this->textstrokewidth;
  22926. $textfill = isset($dom[$key]['fill']) ? $dom[$key]['fill'] : (($this->textrendermode % 2) == 0);
  22927. $textclip = isset($dom[$key]['clip']) ? $dom[$key]['clip'] : ($this->textrendermode > 3);
  22928. $this->setTextRenderingMode($textstroke, $textfill, $textclip);
  22929. if (isset($dom[$key]['font-stretch']) and ($dom[$key]['font-stretch'] !== false))
  22930. {
  22931. $this->setFontStretching($dom[$key]['font-stretch']);
  22932. }
  22933. if (isset($dom[$key]['letter-spacing']) and ($dom[$key]['letter-spacing'] !== false))
  22934. {
  22935. $this->setFontSpacing($dom[$key]['letter-spacing']);
  22936. }
  22937. if (($plalign == 'J') and $dom[$key]['block'])
  22938. {
  22939. $plalign = '';
  22940. }
  22941. // get current position on page buffer
  22942. $curpos = $this->pagelen[$startlinepage];
  22943. if (isset($dom[$key]['bgcolor']) and ($dom[$key]['bgcolor'] !== false))
  22944. {
  22945. $this->SetFillColorArray($dom[$key]['bgcolor']);
  22946. $wfill = true;
  22947. }
  22948. else
  22949. {
  22950. $wfill = $fill | false;
  22951. }
  22952. if (isset($dom[$key]['fgcolor']) and ($dom[$key]['fgcolor'] !== false))
  22953. {
  22954. $this->SetTextColorArray($dom[$key]['fgcolor']);
  22955. }
  22956. if (isset($dom[$key]['strokecolor']) and ($dom[$key]['strokecolor'] !== false))
  22957. {
  22958. $this->SetDrawColorArray($dom[$key]['strokecolor']);
  22959. }
  22960. if (isset($dom[$key]['align']))
  22961. {
  22962. $lalign = $dom[$key]['align'];
  22963. }
  22964. if ($this->empty_string($lalign))
  22965. {
  22966. $lalign = $align;
  22967. }
  22968. }
  22969. // align lines
  22970. if ($this->newline and (strlen($dom[$key]['value']) > 0) and ($dom[$key]['value'] != 'td') and ($dom[$key]['value'] != 'th'))
  22971. {
  22972. $newline = true;
  22973. $fontaligned = false;
  22974. // we are at the beginning of a new line
  22975. if (isset($startlinex))
  22976. {
  22977. $yshift = $minstartliney - $startliney;
  22978. if (($yshift > 0) or ($this->page > $startlinepage))
  22979. {
  22980. $yshift = 0;
  22981. }
  22982. $t_x = 0;
  22983. // the last line must be shifted to be aligned as requested
  22984. $linew = abs($this->endlinex - $startlinex);
  22985. if ($this->inxobj)
  22986. {
  22987. // we are inside an XObject template
  22988. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  22989. if (isset($opentagpos))
  22990. {
  22991. $midpos = $opentagpos;
  22992. }
  22993. else
  22994. {
  22995. $midpos = 0;
  22996. }
  22997. if ($midpos > 0)
  22998. {
  22999. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  23000. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  23001. }
  23002. else
  23003. {
  23004. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  23005. $pend = '';
  23006. }
  23007. }
  23008. else
  23009. {
  23010. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  23011. if (isset($opentagpos) and isset($this->footerlen[$startlinepage]) and (! $this->InFooter))
  23012. {
  23013. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  23014. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  23015. }
  23016. elseif (isset($opentagpos))
  23017. {
  23018. $midpos = $opentagpos;
  23019. }
  23020. elseif (isset($this->footerlen[$startlinepage]) and (! $this->InFooter))
  23021. {
  23022. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  23023. $midpos = $this->footerpos[$startlinepage];
  23024. }
  23025. else
  23026. {
  23027. $midpos = 0;
  23028. }
  23029. if ($midpos > 0)
  23030. {
  23031. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  23032. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  23033. }
  23034. else
  23035. {
  23036. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  23037. $pend = '';
  23038. }
  23039. }
  23040. if ((isset($plalign) and ((($plalign == 'C') or ($plalign == 'J') or (($plalign == 'R') and (! $this->rtl)) or (($plalign == 'L') and ($this->rtl))))))
  23041. {
  23042. // calculate shifting amount
  23043. $tw = $w;
  23044. if (($plalign == 'J') and $this->isRTLTextDir() and ($this->num_columns > 1))
  23045. {
  23046. $tw += $this->cell_padding['R'];
  23047. }
  23048. if ($this->lMargin != $prevlMargin)
  23049. {
  23050. $tw += ($prevlMargin - $this->lMargin);
  23051. }
  23052. if ($this->rMargin != $prevrMargin)
  23053. {
  23054. $tw += ($prevrMargin - $this->rMargin);
  23055. }
  23056. $one_space_width = $this->GetStringWidth(chr(32));
  23057. $no = 0; // number of spaces on a line contained on a single block
  23058. if ($this->isRTLTextDir())
  23059. { // RTL
  23060. // remove left space if exist
  23061. $pos1 = $this->revstrpos($pmid, '[(');
  23062. if ($pos1 > 0)
  23063. {
  23064. $pos1 = intval($pos1);
  23065. if ($this->isUnicodeFont())
  23066. {
  23067. $pos2 = intval($this->revstrpos($pmid, '[(' . chr(0) . chr(32)));
  23068. $spacelen = 2;
  23069. }
  23070. else
  23071. {
  23072. $pos2 = intval($this->revstrpos($pmid, '[(' . chr(32)));
  23073. $spacelen = 1;
  23074. }
  23075. if ($pos1 == $pos2)
  23076. {
  23077. $pmid = substr($pmid, 0, ($pos1 + 2)) . substr($pmid, ($pos1 + 2 + $spacelen));
  23078. if (substr($pmid, $pos1, 4) == '[()]')
  23079. {
  23080. $linew -= $one_space_width;
  23081. }
  23082. elseif ($pos1 == strpos($pmid, '[('))
  23083. {
  23084. $no = 1;
  23085. }
  23086. }
  23087. }
  23088. }
  23089. else
  23090. { // LTR
  23091. // remove right space if exist
  23092. $pos1 = $this->revstrpos($pmid, ')]');
  23093. if ($pos1 > 0)
  23094. {
  23095. $pos1 = intval($pos1);
  23096. if ($this->isUnicodeFont())
  23097. {
  23098. $pos2 = intval($this->revstrpos($pmid, chr(0) . chr(32) . ')]')) + 2;
  23099. $spacelen = 2;
  23100. }
  23101. else
  23102. {
  23103. $pos2 = intval($this->revstrpos($pmid, chr(32) . ')]')) + 1;
  23104. $spacelen = 1;
  23105. }
  23106. if ($pos1 == $pos2)
  23107. {
  23108. $pmid = substr($pmid, 0, ($pos1 - $spacelen)) . substr($pmid, $pos1);
  23109. $linew -= $one_space_width;
  23110. }
  23111. }
  23112. }
  23113. $mdiff = ($tw - $linew);
  23114. if ($plalign == 'C')
  23115. {
  23116. if ($this->rtl)
  23117. {
  23118. $t_x = - ($mdiff / 2);
  23119. }
  23120. else
  23121. {
  23122. $t_x = ($mdiff / 2);
  23123. }
  23124. }
  23125. elseif ($plalign == 'R')
  23126. {
  23127. // right alignment on LTR document
  23128. $t_x = $mdiff;
  23129. }
  23130. elseif ($plalign == 'L')
  23131. {
  23132. // left alignment on RTL document
  23133. $t_x = - $mdiff;
  23134. }
  23135. elseif (($plalign == 'J') and ($plalign == $lalign))
  23136. {
  23137. // Justification
  23138. if ($this->isRTLTextDir())
  23139. {
  23140. // align text on the left
  23141. $t_x = - $mdiff;
  23142. }
  23143. $ns = 0; // number of spaces
  23144. $pmidtemp = $pmid;
  23145. // escape special characters
  23146. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  23147. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  23148. // search spaces
  23149. if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER))
  23150. {
  23151. $spacestr = $this->getSpaceString();
  23152. $maxkk = count($lnstring[1]) - 1;
  23153. for($kk = 0; $kk <= $maxkk; ++ $kk)
  23154. {
  23155. // restore special characters
  23156. $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
  23157. $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
  23158. // store number of spaces on the strings
  23159. $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
  23160. // count total spaces on line
  23161. $ns += $lnstring[2][$kk];
  23162. $lnstring[3][$kk] = $ns;
  23163. }
  23164. if ($ns == 0)
  23165. {
  23166. $ns = 1;
  23167. }
  23168. // calculate additional space to add to each existing space
  23169. $spacewidth = ($mdiff / ($ns - $no)) * $this->k;
  23170. $spacewidthu = - 1000 * ($mdiff + (($ns + $no) * $one_space_width)) / $ns / $this->FontSize;
  23171. if ($this->font_spacing != 0)
  23172. {
  23173. // fixed spacing mode
  23174. $osw = - 1000 * $this->font_spacing / $this->FontSize;
  23175. $spacewidthu += $osw;
  23176. }
  23177. $nsmax = $ns;
  23178. $ns = 0;
  23179. reset($lnstring);
  23180. $offset = 0;
  23181. $strcount = 0;
  23182. $prev_epsposbeg = 0;
  23183. $textpos = 0;
  23184. if ($this->isRTLTextDir())
  23185. {
  23186. $textpos = $this->wPt;
  23187. }
  23188. global $spacew;
  23189. while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1)
  23190. {
  23191. // check if we are inside a string section '[( ... )]'
  23192. $stroffset = strpos($pmid, '[(', $offset);
  23193. if (($stroffset !== false) and ($stroffset <= $strpiece[2][1]))
  23194. {
  23195. // set offset to the end of string section
  23196. $offset = strpos($pmid, ')]', $stroffset);
  23197. while (($offset !== false) and ($pmid{($offset - 1)} == '\\'))
  23198. {
  23199. $offset = strpos($pmid, ')]', ($offset + 1));
  23200. }
  23201. if ($offset === false)
  23202. {
  23203. $this->Error('HTML Justification: malformed PDF code.');
  23204. }
  23205. continue;
  23206. }
  23207. if ($this->isRTLTextDir())
  23208. {
  23209. $spacew = ($spacewidth * ($nsmax - $ns));
  23210. }
  23211. else
  23212. {
  23213. $spacew = ($spacewidth * $ns);
  23214. }
  23215. $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
  23216. $epsposbeg = strpos($pmid, 'q' . $this->epsmarker, $offset);
  23217. $epsposend = strpos($pmid, $this->epsmarker . 'Q', $offset) + strlen($this->epsmarker . 'Q');
  23218. if ((($epsposbeg > 0) and ($epsposend > 0) and ($offset > $epsposbeg) and ($offset < $epsposend)) or (($epsposbeg === false) and ($epsposend > 0) and ($offset < $epsposend)))
  23219. {
  23220. // shift EPS images
  23221. $trx = sprintf('1 0 0 1 %.3F 0 cm', $spacew);
  23222. $epsposbeg = strpos($pmid, 'q' . $this->epsmarker, ($prev_epsposbeg - 6));
  23223. $pmid_b = substr($pmid, 0, $epsposbeg);
  23224. $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
  23225. $pmid_e = substr($pmid, $epsposend);
  23226. $pmid = $pmid_b . "\nq\n" . $trx . "\n" . $pmid_m . "\nQ\n" . $pmid_e;
  23227. $offset = $epsposend;
  23228. continue;
  23229. }
  23230. $prev_epsposbeg = $epsposbeg;
  23231. $currentxpos = 0;
  23232. // shift blocks of code
  23233. switch ($strpiece[2][0])
  23234. {
  23235. case 'Td' :
  23236. case 'cm' :
  23237. case 'm' :
  23238. case 'l' :
  23239. {
  23240. // get current X position
  23241. preg_match('/([0-9\.\+\-]*)[\s](' . $strpiece[1][0] . ')[\s](' . $strpiece[2][0] . ')([\s]*)/x', $pmid, $xmatches);
  23242. $currentxpos = $xmatches[1];
  23243. $textpos = $currentxpos;
  23244. if (($strcount <= $maxkk) and ($strpiece[2][0] == 'Td'))
  23245. {
  23246. $ns = $lnstring[3][$strcount];
  23247. if ($this->isRTLTextDir())
  23248. {
  23249. $spacew = ($spacewidth * ($nsmax - $ns));
  23250. }
  23251. ++ $strcount;
  23252. }
  23253. // justify block
  23254. $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s](' . $strpiece[1][0] . ')[\s](' . $strpiece[2][0] . ')([\s]*)/x', create_function('$matches', 'global $spacew;
  23255. $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
  23256. return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
  23257. break;
  23258. }
  23259. case 're' :
  23260. {
  23261. // justify block
  23262. if (! $this->empty_string($this->lispacer))
  23263. {
  23264. $this->lispacer = '';
  23265. continue;
  23266. }
  23267. preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s](' . $strpiece[1][0] . ')[\s](re)([\s]*)/x', $pmid, $xmatches);
  23268. $currentxpos = $xmatches[1];
  23269. global $x_diff, $w_diff;
  23270. $x_diff = 0;
  23271. $w_diff = 0;
  23272. if ($this->isRTLTextDir())
  23273. { // RTL
  23274. if ($currentxpos < $textpos)
  23275. {
  23276. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
  23277. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  23278. }
  23279. else
  23280. {
  23281. if ($strcount > 0)
  23282. {
  23283. $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
  23284. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  23285. }
  23286. }
  23287. }
  23288. else
  23289. { // LTR
  23290. if ($currentxpos > $textpos)
  23291. {
  23292. if ($strcount > 0)
  23293. {
  23294. $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
  23295. }
  23296. $w_diff = ($spacewidth * $lnstring[2][$strcount]);
  23297. }
  23298. else
  23299. {
  23300. if ($strcount > 1)
  23301. {
  23302. $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
  23303. }
  23304. if ($strcount > 0)
  23305. {
  23306. $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
  23307. }
  23308. }
  23309. }
  23310. $pmid = preg_replace_callback('/(' . $xmatches[1] . ')[\s](' . $xmatches[2] . ')[\s](' . $xmatches[3] . ')[\s](' . $strpiece[1][0] . ')[\s](re)([\s]*)/x', create_function('$matches', 'global $x_diff, $w_diff;
  23311. $newx = sprintf("%.2F",(floatval($matches[1]) + $x_diff));
  23312. $neww = sprintf("%.2F",(floatval($matches[3]) + $w_diff));
  23313. return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
  23314. break;
  23315. }
  23316. case 'c' :
  23317. {
  23318. // get current X position
  23319. 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);
  23320. $currentxpos = $xmatches[1];
  23321. // justify block
  23322. $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', create_function('$matches', 'global $spacew;
  23323. $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
  23324. $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
  23325. $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
  23326. return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
  23327. break;
  23328. }
  23329. }
  23330. // shift the annotations and links
  23331. $cxpos = ($currentxpos / $this->k);
  23332. $lmpos = ($this->lMargin + $this->cell_padding['L'] + $this->feps);
  23333. if ($this->inxobj)
  23334. {
  23335. // we are inside an XObject template
  23336. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac)
  23337. {
  23338. if (($pac['y'] >= $minstartliney) and (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) and (($pac['x'] * $this->k) <= ($currentxpos + $this->feps)))
  23339. {
  23340. if ($cxpos > $lmpos)
  23341. {
  23342. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += ($spacew / $this->k);
  23343. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  23344. }
  23345. else
  23346. {
  23347. $this->xobjects[$this->xobjid]['annotations'][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  23348. }
  23349. break;
  23350. }
  23351. }
  23352. }
  23353. elseif (isset($this->PageAnnots[$this->page]))
  23354. {
  23355. foreach ($this->PageAnnots[$this->page] as $pak => $pac)
  23356. {
  23357. if (($pac['y'] >= $minstartliney) and (($pac['x'] * $this->k) >= ($currentxpos - $this->feps)) and (($pac['x'] * $this->k) <= ($currentxpos + $this->feps)))
  23358. {
  23359. if ($cxpos > $lmpos)
  23360. {
  23361. $this->PageAnnots[$this->page][$pak]['x'] += ($spacew / $this->k);
  23362. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  23363. }
  23364. else
  23365. {
  23366. $this->PageAnnots[$this->page][$pak]['w'] += (($spacewidth * $pac['numspaces']) / $this->k);
  23367. }
  23368. break;
  23369. }
  23370. }
  23371. }
  23372. } // end of while
  23373. // remove markers
  23374. $pmid = str_replace('x*#!#*x', '', $pmid);
  23375. if ($this->isUnicodeFont())
  23376. {
  23377. // multibyte characters
  23378. $spacew = $spacewidthu;
  23379. if ($this->font_stretching != 100)
  23380. {
  23381. // word spacing is affected by stretching
  23382. $spacew /= ($this->font_stretching / 100);
  23383. }
  23384. $pmidtemp = $pmid;
  23385. // escape special characters
  23386. $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
  23387. $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
  23388. $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x", create_function('$matches', 'global $spacew;
  23389. $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
  23390. $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
  23391. return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%.3F", $spacew)." (", $matches[1]).")]";'), $pmidtemp);
  23392. if ($this->inxobj)
  23393. {
  23394. // we are inside an XObject template
  23395. $this->xobjects[$this->xobjid]['outdata'] = $pstart . "\n" . $pmid . "\n" . $pend;
  23396. }
  23397. else
  23398. {
  23399. $this->setPageBuffer($startlinepage, $pstart . "\n" . $pmid . "\n" . $pend);
  23400. }
  23401. $endlinepos = strlen($pstart . "\n" . $pmid . "\n");
  23402. }
  23403. else
  23404. {
  23405. // non-unicode (single-byte characters)
  23406. if ($this->font_stretching != 100)
  23407. {
  23408. // word spacing (Tw) is affected by stretching
  23409. $spacewidth /= ($this->font_stretching / 100);
  23410. }
  23411. $rs = sprintf('%.3F Tw', $spacewidth);
  23412. $pmid = preg_replace("/\[\(/x", $rs . ' [(', $pmid);
  23413. if ($this->inxobj)
  23414. {
  23415. // we are inside an XObject template
  23416. $this->xobjects[$this->xobjid]['outdata'] = $pstart . "\n" . $pmid . "\nBT 0 Tw ET\n" . $pend;
  23417. }
  23418. else
  23419. {
  23420. $this->setPageBuffer($startlinepage, $pstart . "\n" . $pmid . "\nBT 0 Tw ET\n" . $pend);
  23421. }
  23422. $endlinepos = strlen($pstart . "\n" . $pmid . "\nBT 0 Tw ET\n");
  23423. }
  23424. }
  23425. } // end of J
  23426. } // end if $startlinex
  23427. if (($t_x != 0) or ($yshift < 0))
  23428. {
  23429. // shift the line
  23430. $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
  23431. $pstart .= "\nq\n" . $trx . "\n" . $pmid . "\nQ\n";
  23432. $endlinepos = strlen($pstart);
  23433. if ($this->inxobj)
  23434. {
  23435. // we are inside an XObject template
  23436. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $pend;
  23437. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac)
  23438. {
  23439. if ($pak >= $pask)
  23440. {
  23441. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  23442. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  23443. }
  23444. }
  23445. }
  23446. else
  23447. {
  23448. $this->setPageBuffer($startlinepage, $pstart . $pend);
  23449. // shift the annotations and links
  23450. if (isset($this->PageAnnots[$this->page]))
  23451. {
  23452. foreach ($this->PageAnnots[$this->page] as $pak => $pac)
  23453. {
  23454. if ($pak >= $pask)
  23455. {
  23456. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  23457. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  23458. }
  23459. }
  23460. }
  23461. }
  23462. $this->y -= $yshift;
  23463. }
  23464. }
  23465. $pbrk = $this->checkPageBreak($this->lasth);
  23466. $this->newline = false;
  23467. $startlinex = $this->x;
  23468. $startliney = $this->y;
  23469. if ($dom[$dom[$key]['parent']]['value'] == 'sup')
  23470. {
  23471. $startliney -= ((0.3 * $this->FontSizePt) / $this->k);
  23472. }
  23473. elseif ($dom[$dom[$key]['parent']]['value'] == 'sub')
  23474. {
  23475. $startliney -= (($this->FontSizePt / 0.7) / $this->k);
  23476. }
  23477. else
  23478. {
  23479. $minstartliney = $startliney;
  23480. $maxbottomliney = ($this->y + (($fontsize * $this->cell_height_ratio) / $this->k));
  23481. }
  23482. $startlinepage = $this->page;
  23483. if (isset($endlinepos) and (! $pbrk))
  23484. {
  23485. $startlinepos = $endlinepos;
  23486. }
  23487. else
  23488. {
  23489. if ($this->inxobj)
  23490. {
  23491. // we are inside an XObject template
  23492. $startlinepos = strlen($this->xobjects[$this->xobjid]['outdata']);
  23493. }
  23494. elseif (! $this->InFooter)
  23495. {
  23496. if (isset($this->footerlen[$this->page]))
  23497. {
  23498. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  23499. }
  23500. else
  23501. {
  23502. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  23503. }
  23504. $startlinepos = $this->footerpos[$this->page];
  23505. }
  23506. else
  23507. {
  23508. $startlinepos = $this->pagelen[$this->page];
  23509. }
  23510. }
  23511. unset($endlinepos);
  23512. $plalign = $lalign;
  23513. if (isset($this->PageAnnots[$this->page]))
  23514. {
  23515. $pask = count($this->PageAnnots[$this->page]);
  23516. }
  23517. else
  23518. {
  23519. $pask = 0;
  23520. }
  23521. if (! ($dom[$key]['tag'] and ! $dom[$key]['opening'] and ($dom[$key]['value'] == 'table') and ($this->emptypagemrk[$this->page] == $this->pagelen[$this->page])))
  23522. {
  23523. $this->SetFont($fontname, $fontstyle, $fontsize);
  23524. if ($wfill)
  23525. {
  23526. $this->SetFillColorArray($this->bgcolor);
  23527. }
  23528. }
  23529. } // end newline
  23530. if (isset($opentagpos))
  23531. {
  23532. unset($opentagpos);
  23533. }
  23534. if ($dom[$key]['tag'])
  23535. {
  23536. if ($dom[$key]['opening'])
  23537. {
  23538. // get text indentation (if any)
  23539. if (isset($dom[$key]['text-indent']) and $dom[$key]['block'])
  23540. {
  23541. $this->textindent = $dom[$key]['text-indent'];
  23542. $this->newline = true;
  23543. }
  23544. // table
  23545. if ($dom[$key]['value'] == 'table')
  23546. {
  23547. // available page width
  23548. if ($this->rtl)
  23549. {
  23550. $wtmp = $this->x - $this->lMargin;
  23551. }
  23552. else
  23553. {
  23554. $wtmp = $this->w - $this->rMargin - $this->x;
  23555. }
  23556. if (isset($dom[$key]['attribute']['cellspacing']))
  23557. {
  23558. $cellspacing = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
  23559. }
  23560. else
  23561. {
  23562. $cellspacing = 0;
  23563. }
  23564. // table width
  23565. if (isset($dom[$key]['width']))
  23566. {
  23567. $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
  23568. }
  23569. else
  23570. {
  23571. $table_width = $wtmp;
  23572. }
  23573. $table_width -= (2 * $cellspacing);
  23574. if (! $this->inthead)
  23575. {
  23576. $this->y += $cellspacing;
  23577. }
  23578. if ($this->rtl)
  23579. {
  23580. $cellspacingx = - $cellspacing;
  23581. }
  23582. else
  23583. {
  23584. $cellspacingx = $cellspacing;
  23585. }
  23586. // total table width without cellspaces
  23587. $table_columns_width = ($table_width - ($cellspacing * ($dom[$key]['cols'] - 1)));
  23588. // minimum column width
  23589. $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
  23590. // array of custom column widths
  23591. $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
  23592. }
  23593. // table row
  23594. if ($dom[$key]['value'] == 'tr')
  23595. {
  23596. // reset column counter
  23597. $colid = 0;
  23598. }
  23599. // table cell
  23600. if (($dom[$key]['value'] == 'td') or ($dom[$key]['value'] == 'th'))
  23601. {
  23602. $trid = $dom[$key]['parent'];
  23603. $table_el = $dom[$trid]['parent'];
  23604. if (! isset($dom[$table_el]['cols']))
  23605. {
  23606. $dom[$table_el]['cols'] = $dom[$trid]['cols'];
  23607. }
  23608. // store border info
  23609. $tdborder = 0;
  23610. if (isset($dom[$key]['border']) and ! empty($dom[$key]['border']))
  23611. {
  23612. $tdborder = $dom[$key]['border'];
  23613. }
  23614. $colspan = $dom[$key]['attribute']['colspan'];
  23615. $old_cell_padding = $this->cell_padding;
  23616. if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding']))
  23617. {
  23618. $current_cell_padding = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
  23619. }
  23620. else
  23621. {
  23622. $current_cell_padding = 0;
  23623. }
  23624. $this->SetCellPadding($current_cell_padding);
  23625. if (isset($dom[$key]['height']))
  23626. {
  23627. // minimum cell height
  23628. $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
  23629. }
  23630. else
  23631. {
  23632. $cellh = 0;
  23633. }
  23634. if (isset($dom[$key]['content']))
  23635. {
  23636. $cell_content = $dom[$key]['content'];
  23637. }
  23638. else
  23639. {
  23640. $cell_content = '&nbsp;';
  23641. }
  23642. $tagtype = $dom[$key]['value'];
  23643. $parentid = $key;
  23644. while (($key < $maxel) and (! (($dom[$key]['tag']) and (! $dom[$key]['opening']) and ($dom[$key]['value'] == $tagtype) and ($dom[$key]['parent'] == $parentid))))
  23645. {
  23646. // move $key index forward
  23647. ++ $key;
  23648. }
  23649. if (! isset($dom[$trid]['startpage']))
  23650. {
  23651. $dom[$trid]['startpage'] = $this->page;
  23652. }
  23653. else
  23654. {
  23655. $this->setPage($dom[$trid]['startpage']);
  23656. }
  23657. if (! isset($dom[$trid]['startcolumn']))
  23658. {
  23659. $dom[$trid]['startcolumn'] = $this->current_column;
  23660. }
  23661. elseif ($this->current_column != $dom[$trid]['startcolumn'])
  23662. {
  23663. $tmpx = $this->x;
  23664. $this->selectColumn($dom[$trid]['startcolumn']);
  23665. $this->x = $tmpx;
  23666. }
  23667. if (! isset($dom[$trid]['starty']))
  23668. {
  23669. $dom[$trid]['starty'] = $this->y;
  23670. }
  23671. else
  23672. {
  23673. $this->y = $dom[$trid]['starty'];
  23674. }
  23675. if (! isset($dom[$trid]['startx']))
  23676. {
  23677. $dom[$trid]['startx'] = $this->x;
  23678. $this->x += $cellspacingx;
  23679. }
  23680. else
  23681. {
  23682. $this->x += ($cellspacingx / 2);
  23683. }
  23684. if (isset($dom[$parentid]['attribute']['rowspan']))
  23685. {
  23686. $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
  23687. }
  23688. else
  23689. {
  23690. $rowspan = 1;
  23691. }
  23692. // skip row-spanned cells started on the previous rows
  23693. if (isset($dom[$table_el]['rowspans']))
  23694. {
  23695. $rsk = 0;
  23696. $rskmax = count($dom[$table_el]['rowspans']);
  23697. while ($rsk < $rskmax)
  23698. {
  23699. $trwsp = $dom[$table_el]['rowspans'][$rsk];
  23700. $rsstartx = $trwsp['startx'];
  23701. $rsendx = $trwsp['endx'];
  23702. // account for margin changes
  23703. if ($trwsp['startpage'] < $this->page)
  23704. {
  23705. if (($this->rtl) and ($this->pagedim[$this->page]['orm'] != $this->pagedim[$trwsp['startpage']]['orm']))
  23706. {
  23707. $dl = ($this->pagedim[$this->page]['orm'] - $this->pagedim[$trwsp['startpage']]['orm']);
  23708. $rsstartx -= $dl;
  23709. $rsendx -= $dl;
  23710. }
  23711. elseif ((! $this->rtl) and ($this->pagedim[$this->page]['olm'] != $this->pagedim[$trwsp['startpage']]['olm']))
  23712. {
  23713. $dl = ($this->pagedim[$this->page]['olm'] - $this->pagedim[$trwsp['startpage']]['olm']);
  23714. $rsstartx += $dl;
  23715. $rsendx += $dl;
  23716. }
  23717. }
  23718. if (($trwsp['rowspan'] > 0) and ($rsstartx > ($this->x - $cellspacing - $current_cell_padding - $this->feps)) and ($rsstartx < ($this->x + $cellspacing + $current_cell_padding + $this->feps)) and (($trwsp['starty'] < ($this->y - $this->feps)) or ($trwsp['startpage'] < $this->page) or ($trwsp['startcolumn'] < $this->current_column)))
  23719. {
  23720. // set the starting X position of the current cell
  23721. $this->x = $rsendx + $cellspacingx;
  23722. // increment column indicator
  23723. $colid += $trwsp['colspan'];
  23724. if (($trwsp['rowspan'] == 1) and (isset($dom[$trid]['endy'])) and (isset($dom[$trid]['endpage'])) and (isset($dom[$trid]['endcolumn'])) and ($trwsp['endpage'] == $dom[$trid]['endpage']) and ($trwsp['endcolumn'] == $dom[$trid]['endcolumn']))
  23725. {
  23726. // set ending Y position for row
  23727. $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  23728. $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
  23729. }
  23730. $rsk = 0;
  23731. }
  23732. else
  23733. {
  23734. ++ $rsk;
  23735. }
  23736. }
  23737. }
  23738. if (isset($dom[$parentid]['width']))
  23739. {
  23740. // user specified width
  23741. $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
  23742. $tmpcw = ($cellw / $colspan);
  23743. for($i = 0; $i < $colspan; ++ $i)
  23744. {
  23745. $table_colwidths[($colid + $i)] = $tmpcw;
  23746. }
  23747. }
  23748. else
  23749. {
  23750. // inherit column width
  23751. $cellw = 0;
  23752. for($i = 0; $i < $colspan; ++ $i)
  23753. {
  23754. $cellw += $table_colwidths[($colid + $i)];
  23755. }
  23756. }
  23757. $cellw += (($colspan - 1) * $cellspacing);
  23758. // increment column indicator
  23759. $colid += $colspan;
  23760. // add rowspan information to table element
  23761. if ($rowspan > 1)
  23762. {
  23763. $trsid = array_push($dom[$table_el]['rowspans'], array('trid' => $trid,
  23764. 'rowspan' => $rowspan, 'mrowspan' => $rowspan, 'colspan' => $colspan,
  23765. 'startpage' => $this->page, 'startcolumn' => $this->current_column,
  23766. 'startx' => $this->x, 'starty' => $this->y));
  23767. }
  23768. $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));
  23769. if ($rowspan > 1)
  23770. {
  23771. $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
  23772. }
  23773. // push background colors
  23774. if (isset($dom[$parentid]['bgcolor']) and ($dom[$parentid]['bgcolor'] !== false))
  23775. {
  23776. $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
  23777. }
  23778. // store border info
  23779. if (isset($tdborder) and ! empty($tdborder))
  23780. {
  23781. $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
  23782. }
  23783. $prevLastH = $this->lasth;
  23784. // store some info for multicolumn mode
  23785. if ($this->rtl)
  23786. {
  23787. $this->colxshift['x'] = $this->w - $this->x - $this->rMargin;
  23788. }
  23789. else
  23790. {
  23791. $this->colxshift['x'] = $this->x - $this->lMargin;
  23792. }
  23793. $this->colxshift['s'] = $cellspacing;
  23794. $this->colxshift['p'] = $current_cell_padding;
  23795. // ****** write the cell content ******
  23796. $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true);
  23797. // restore some values
  23798. $this->colxshift = array('x' => 0, 's' => 0, 'p' => 0);
  23799. $this->lasth = $prevLastH;
  23800. $this->cell_padding = $old_cell_padding;
  23801. $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x;
  23802. // update the end of row position
  23803. if ($rowspan <= 1)
  23804. {
  23805. if (isset($dom[$trid]['endy']))
  23806. {
  23807. if (($this->page == $dom[$trid]['endpage']) and ($this->current_column == $dom[$trid]['endcolumn']))
  23808. {
  23809. $dom[$trid]['endy'] = max($this->y, $dom[$trid]['endy']);
  23810. }
  23811. elseif (($this->page > $dom[$trid]['endpage']) or ($this->current_column > $dom[$trid]['endcolumn']))
  23812. {
  23813. $dom[$trid]['endy'] = $this->y;
  23814. }
  23815. }
  23816. else
  23817. {
  23818. $dom[$trid]['endy'] = $this->y;
  23819. }
  23820. if (isset($dom[$trid]['endpage']))
  23821. {
  23822. $dom[$trid]['endpage'] = max($this->page, $dom[$trid]['endpage']);
  23823. }
  23824. else
  23825. {
  23826. $dom[$trid]['endpage'] = $this->page;
  23827. }
  23828. if (isset($dom[$trid]['endcolumn']))
  23829. {
  23830. $dom[$trid]['endcolumn'] = max($this->current_column, $dom[$trid]['endcolumn']);
  23831. }
  23832. else
  23833. {
  23834. $dom[$trid]['endcolumn'] = $this->current_column;
  23835. }
  23836. }
  23837. else
  23838. {
  23839. // account for row-spanned cells
  23840. $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x;
  23841. $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y;
  23842. $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page;
  23843. $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column;
  23844. }
  23845. if (isset($dom[$table_el]['rowspans']))
  23846. {
  23847. // update endy and endpage on rowspanned cells
  23848. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp)
  23849. {
  23850. if ($trwsp['rowspan'] > 0)
  23851. {
  23852. if (isset($dom[$trid]['endpage']))
  23853. {
  23854. if (($trwsp['endpage'] == $dom[$trid]['endpage']) and ($trwsp['endcolumn'] == $dom[$trid]['endcolumn']))
  23855. {
  23856. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
  23857. }
  23858. elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) or ($trwsp['endcolumn'] < $dom[$trid]['endcolumn']))
  23859. {
  23860. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
  23861. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
  23862. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
  23863. }
  23864. else
  23865. {
  23866. $dom[$trid]['endy'] = $this->pagedim[$dom[$trid]['endpage']]['hk'] - $this->pagedim[$dom[$trid]['endpage']]['bm'];
  23867. }
  23868. }
  23869. }
  23870. }
  23871. }
  23872. $this->x += ($cellspacingx / 2);
  23873. }
  23874. else
  23875. {
  23876. // opening tag (or self-closing tag)
  23877. if (! isset($opentagpos))
  23878. {
  23879. if ($this->inxobj)
  23880. {
  23881. // we are inside an XObject template
  23882. $opentagpos = strlen($this->xobjects[$this->xobjid]['outdata']);
  23883. }
  23884. elseif (! $this->InFooter)
  23885. {
  23886. if (isset($this->footerlen[$this->page]))
  23887. {
  23888. $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
  23889. }
  23890. else
  23891. {
  23892. $this->footerpos[$this->page] = $this->pagelen[$this->page];
  23893. }
  23894. $opentagpos = $this->footerpos[$this->page];
  23895. }
  23896. }
  23897. $this->openHTMLTagHandler($dom, $key, $cell);
  23898. }
  23899. }
  23900. else
  23901. { // closing tag
  23902. $prev_numpages = $this->numpages;
  23903. $old_bordermrk = $this->bordermrk[$this->page];
  23904. $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
  23905. if ($this->bordermrk[$this->page] > $old_bordermrk)
  23906. {
  23907. $startlinepos += ($this->bordermrk[$this->page] - $old_bordermrk);
  23908. }
  23909. if ($prev_numpages > $this->numpages)
  23910. {
  23911. $startlinepage = $this->page;
  23912. }
  23913. }
  23914. }
  23915. elseif (strlen($dom[$key]['value']) > 0)
  23916. {
  23917. // print list-item
  23918. if (! $this->empty_string($this->lispacer) and ($this->lispacer != '^'))
  23919. {
  23920. $this->SetFont($pfontname, $pfontstyle, $pfontsize);
  23921. $this->resetLastH();
  23922. $minstartliney = $this->y;
  23923. $maxbottomliney = ($startliney + ($this->FontSize * $this->cell_height_ratio));
  23924. $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
  23925. $this->SetFont($curfontname, $curfontstyle, $curfontsize);
  23926. $this->resetLastH();
  23927. if (is_numeric($pfontsize) and ($pfontsize > 0) and is_numeric($curfontsize) and ($curfontsize > 0) and ($pfontsize != $curfontsize))
  23928. {
  23929. $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
  23930. $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
  23931. $this->y += ((($pfontsize - $curfontsize) * $this->cell_height_ratio / $this->k) + $pfontascent - $curfontascent - $pfontdescent + $curfontdescent) / 2;
  23932. $minstartliney = min($this->y, $minstartliney);
  23933. $maxbottomliney = max(($this->y + (($pfontsize * $this->cell_height_ratio) / $this->k)), $maxbottomliney);
  23934. }
  23935. }
  23936. // text
  23937. $this->htmlvspace = 0;
  23938. if ((! $this->premode) and $this->isRTLTextDir())
  23939. {
  23940. // reverse spaces order
  23941. $lsp = ''; // left spaces
  23942. $rsp = ''; // right spaces
  23943. if (preg_match('/^(' . $this->re_space['p'] . '+)/' . $this->re_space['m'], $dom[$key]['value'], $matches))
  23944. {
  23945. $lsp = $matches[1];
  23946. }
  23947. if (preg_match('/(' . $this->re_space['p'] . '+)$/' . $this->re_space['m'], $dom[$key]['value'], $matches))
  23948. {
  23949. $rsp = $matches[1];
  23950. }
  23951. $dom[$key]['value'] = $rsp . $this->stringTrim($dom[$key]['value']) . $lsp;
  23952. }
  23953. if ($newline)
  23954. {
  23955. if (! $this->premode)
  23956. {
  23957. $prelen = strlen($dom[$key]['value']);
  23958. if ($this->isRTLTextDir())
  23959. {
  23960. // right trim except non-breaking space
  23961. $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
  23962. }
  23963. else
  23964. {
  23965. // left trim except non-breaking space
  23966. $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
  23967. }
  23968. $postlen = strlen($dom[$key]['value']);
  23969. if (($postlen == 0) and ($prelen > 0))
  23970. {
  23971. $dom[$key]['trimmed_space'] = true;
  23972. }
  23973. }
  23974. $newline = false;
  23975. $firstblock = true;
  23976. }
  23977. else
  23978. {
  23979. $firstblock = false;
  23980. // replace empty multiple spaces string with a single space
  23981. $dom[$key]['value'] = preg_replace('/^' . $this->re_space['p'] . '+$/' . $this->re_space['m'], chr(32), $dom[$key]['value']);
  23982. }
  23983. $strrest = '';
  23984. if ($this->rtl)
  23985. {
  23986. $this->x -= $this->textindent;
  23987. }
  23988. else
  23989. {
  23990. $this->x += $this->textindent;
  23991. }
  23992. if (! isset($dom[$key]['trimmed_space']) or ! $dom[$key]['trimmed_space'])
  23993. {
  23994. if (! empty($this->HREF) and (isset($this->HREF['url'])))
  23995. {
  23996. // HTML <a> Link
  23997. $hrefcolor = '';
  23998. if (isset($dom[($dom[$key]['parent'])]['fgcolor']) and ($dom[($dom[$key]['parent'])]['fgcolor'] !== false))
  23999. {
  24000. $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
  24001. }
  24002. $hrefstyle = - 1;
  24003. if (isset($dom[($dom[$key]['parent'])]['fontstyle']) and ($dom[($dom[$key]['parent'])]['fontstyle'] !== false))
  24004. {
  24005. $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
  24006. }
  24007. $strrest = $this->addHtmlLink($this->HREF['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
  24008. }
  24009. else
  24010. {
  24011. $wadj = 0; // space to leave for block continuity
  24012. $adjblks = 0; // number of blocks
  24013. // check the next text blocks for continuity
  24014. $nkey = ($key + 1);
  24015. $write_block = true;
  24016. $tmp_fontname = $this->FontFamily;
  24017. $tmp_fontstyle = $this->FontStyle;
  24018. $tmp_fontsize = $this->FontSizePt;
  24019. while ($write_block and isset($dom[$nkey]))
  24020. {
  24021. if ($dom[$nkey]['tag'])
  24022. {
  24023. if ($dom[$nkey]['block'])
  24024. {
  24025. // end of block
  24026. $write_block = false;
  24027. }
  24028. $tmp_fontname = isset($dom[$nkey]['fontname']) ? $dom[$nkey]['fontname'] : $this->FontFamily;
  24029. $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ? $dom[$nkey]['fontstyle'] : $this->FontStyle;
  24030. $tmp_fontsize = isset($dom[$nkey]['fontsize']) ? $dom[$nkey]['fontsize'] : $this->FontSizePt;
  24031. }
  24032. else
  24033. {
  24034. $nextstr = preg_split('/' . $this->re_space['p'] . '+/' . $this->re_space['m'], $dom[$nkey]['value']);
  24035. if (isset($nextstr[0]))
  24036. {
  24037. $wadj += $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
  24038. ++ $adjblks;
  24039. }
  24040. if (isset($nextstr[1]))
  24041. {
  24042. $write_block = false;
  24043. }
  24044. }
  24045. ++ $nkey;
  24046. }
  24047. // check for reversed text direction
  24048. if (($wadj > 0) and (($this->rtl and ($this->tmprtl == 'L')) or (! $this->rtl and ($this->tmprtl == 'R'))))
  24049. {
  24050. // LTR text on RTL direction or RTL text on LTR direction
  24051. $reverse_dir = true;
  24052. $this->rtl = ! $this->rtl;
  24053. $revshift = ($this->GetStringWidth($dom[$key]['value']) + $wadj) + 0.000001; // add little quantity for rounding problems
  24054. if ($this->rtl)
  24055. {
  24056. $this->x += $revshift;
  24057. }
  24058. else
  24059. {
  24060. $this->x -= $revshift;
  24061. }
  24062. $xws = $this->x;
  24063. }
  24064. // ****** write only until the end of the line and get the rest ******
  24065. $strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
  24066. // restore default direction
  24067. if ($reverse_dir and ($wadj == 0))
  24068. {
  24069. $this->x = $xws;
  24070. $this->rtl = ! $this->rtl;
  24071. $reverse_dir = false;
  24072. }
  24073. }
  24074. }
  24075. $this->textindent = 0;
  24076. if (strlen($strrest) > 0)
  24077. {
  24078. // store the remaining string on the previous $key position
  24079. $this->newline = true;
  24080. if ($strrest == $dom[$key]['value'])
  24081. {
  24082. // used to avoid infinite loop
  24083. ++ $loop;
  24084. }
  24085. else
  24086. {
  24087. $loop = 0;
  24088. }
  24089. $dom[$key]['value'] = $strrest;
  24090. if ($cell)
  24091. {
  24092. if ($this->rtl)
  24093. {
  24094. $this->x -= $this->cell_padding['R'];
  24095. }
  24096. else
  24097. {
  24098. $this->x += $this->cell_padding['L'];
  24099. }
  24100. }
  24101. if ($loop < 3)
  24102. {
  24103. -- $key;
  24104. }
  24105. }
  24106. else
  24107. {
  24108. $loop = 0;
  24109. }
  24110. }
  24111. ++ $key;
  24112. 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'))
  24113. {
  24114. // check if we are on a new page or on a new column
  24115. if ((! $undo) and ($this->y < $this->start_transaction_y))
  24116. {
  24117. // we are on a new page or on a new column and the total object height is less than the available vertical space.
  24118. // restore previous object
  24119. $this->rollbackTransaction(true);
  24120. // restore previous values
  24121. foreach ($this_method_vars as $vkey => $vval)
  24122. {
  24123. $$vkey = $vval;
  24124. }
  24125. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  24126. $pre_y = $this->y;
  24127. if ((! $this->checkPageBreak($this->PageBreakTrigger + 1)) and ($this->y < $pre_y))
  24128. {
  24129. $startliney = $this->y;
  24130. }
  24131. $undo = true; // avoid infinite loop
  24132. }
  24133. else
  24134. {
  24135. $undo = false;
  24136. }
  24137. }
  24138. } // end for each $key
  24139. // align the last line
  24140. if (isset($startlinex))
  24141. {
  24142. $yshift = $minstartliney - $startliney;
  24143. if (($yshift > 0) or ($this->page > $startlinepage))
  24144. {
  24145. $yshift = 0;
  24146. }
  24147. $t_x = 0;
  24148. // the last line must be shifted to be aligned as requested
  24149. $linew = abs($this->endlinex - $startlinex);
  24150. if ($this->inxobj)
  24151. {
  24152. // we are inside an XObject template
  24153. $pstart = substr($this->xobjects[$this->xobjid]['outdata'], 0, $startlinepos);
  24154. if (isset($opentagpos))
  24155. {
  24156. $midpos = $opentagpos;
  24157. }
  24158. else
  24159. {
  24160. $midpos = 0;
  24161. }
  24162. if ($midpos > 0)
  24163. {
  24164. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos, ($midpos - $startlinepos));
  24165. $pend = substr($this->xobjects[$this->xobjid]['outdata'], $midpos);
  24166. }
  24167. else
  24168. {
  24169. $pmid = substr($this->xobjects[$this->xobjid]['outdata'], $startlinepos);
  24170. $pend = '';
  24171. }
  24172. }
  24173. else
  24174. {
  24175. $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
  24176. if (isset($opentagpos) and isset($this->footerlen[$startlinepage]) and (! $this->InFooter))
  24177. {
  24178. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  24179. $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
  24180. }
  24181. elseif (isset($opentagpos))
  24182. {
  24183. $midpos = $opentagpos;
  24184. }
  24185. elseif (isset($this->footerlen[$startlinepage]) and (! $this->InFooter))
  24186. {
  24187. $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
  24188. $midpos = $this->footerpos[$startlinepage];
  24189. }
  24190. else
  24191. {
  24192. $midpos = 0;
  24193. }
  24194. if ($midpos > 0)
  24195. {
  24196. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
  24197. $pend = substr($this->getPageBuffer($startlinepage), $midpos);
  24198. }
  24199. else
  24200. {
  24201. $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
  24202. $pend = '';
  24203. }
  24204. }
  24205. if ((isset($plalign) and ((($plalign == 'C') or (($plalign == 'R') and (! $this->rtl)) or (($plalign == 'L') and ($this->rtl))))))
  24206. {
  24207. // calculate shifting amount
  24208. $tw = $w;
  24209. if ($this->lMargin != $prevlMargin)
  24210. {
  24211. $tw += ($prevlMargin - $this->lMargin);
  24212. }
  24213. if ($this->rMargin != $prevrMargin)
  24214. {
  24215. $tw += ($prevrMargin - $this->rMargin);
  24216. }
  24217. $one_space_width = $this->GetStringWidth(chr(32));
  24218. $no = 0; // number of spaces on a line contained on a single block
  24219. if ($this->isRTLTextDir())
  24220. { // RTL
  24221. // remove left space if exist
  24222. $pos1 = $this->revstrpos($pmid, '[(');
  24223. if ($pos1 > 0)
  24224. {
  24225. $pos1 = intval($pos1);
  24226. if ($this->isUnicodeFont())
  24227. {
  24228. $pos2 = intval($this->revstrpos($pmid, '[(' . chr(0) . chr(32)));
  24229. $spacelen = 2;
  24230. }
  24231. else
  24232. {
  24233. $pos2 = intval($this->revstrpos($pmid, '[(' . chr(32)));
  24234. $spacelen = 1;
  24235. }
  24236. if ($pos1 == $pos2)
  24237. {
  24238. $pmid = substr($pmid, 0, ($pos1 + 2)) . substr($pmid, ($pos1 + 2 + $spacelen));
  24239. if (substr($pmid, $pos1, 4) == '[()]')
  24240. {
  24241. $linew -= $one_space_width;
  24242. }
  24243. elseif ($pos1 == strpos($pmid, '[('))
  24244. {
  24245. $no = 1;
  24246. }
  24247. }
  24248. }
  24249. }
  24250. else
  24251. { // LTR
  24252. // remove right space if exist
  24253. $pos1 = $this->revstrpos($pmid, ')]');
  24254. if ($pos1 > 0)
  24255. {
  24256. $pos1 = intval($pos1);
  24257. if ($this->isUnicodeFont())
  24258. {
  24259. $pos2 = intval($this->revstrpos($pmid, chr(0) . chr(32) . ')]')) + 2;
  24260. $spacelen = 2;
  24261. }
  24262. else
  24263. {
  24264. $pos2 = intval($this->revstrpos($pmid, chr(32) . ')]')) + 1;
  24265. $spacelen = 1;
  24266. }
  24267. if ($pos1 == $pos2)
  24268. {
  24269. $pmid = substr($pmid, 0, ($pos1 - $spacelen)) . substr($pmid, $pos1);
  24270. $linew -= $one_space_width;
  24271. }
  24272. }
  24273. }
  24274. $mdiff = ($tw - $linew);
  24275. if ($plalign == 'C')
  24276. {
  24277. if ($this->rtl)
  24278. {
  24279. $t_x = - ($mdiff / 2);
  24280. }
  24281. else
  24282. {
  24283. $t_x = ($mdiff / 2);
  24284. }
  24285. }
  24286. elseif ($plalign == 'R')
  24287. {
  24288. // right alignment on LTR document
  24289. $t_x = $mdiff;
  24290. }
  24291. elseif ($plalign == 'L')
  24292. {
  24293. // left alignment on RTL document
  24294. $t_x = - $mdiff;
  24295. }
  24296. } // end if startlinex
  24297. if (($t_x != 0) or ($yshift < 0))
  24298. {
  24299. // shift the line
  24300. $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
  24301. $pstart .= "\nq\n" . $trx . "\n" . $pmid . "\nQ\n";
  24302. $endlinepos = strlen($pstart);
  24303. if ($this->inxobj)
  24304. {
  24305. // we are inside an XObject template
  24306. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $pend;
  24307. foreach ($this->xobjects[$this->xobjid]['annotations'] as $pak => $pac)
  24308. {
  24309. if ($pak >= $pask)
  24310. {
  24311. $this->xobjects[$this->xobjid]['annotations'][$pak]['x'] += $t_x;
  24312. $this->xobjects[$this->xobjid]['annotations'][$pak]['y'] -= $yshift;
  24313. }
  24314. }
  24315. }
  24316. else
  24317. {
  24318. $this->setPageBuffer($startlinepage, $pstart . $pend);
  24319. // shift the annotations and links
  24320. if (isset($this->PageAnnots[$this->page]))
  24321. {
  24322. foreach ($this->PageAnnots[$this->page] as $pak => $pac)
  24323. {
  24324. if ($pak >= $pask)
  24325. {
  24326. $this->PageAnnots[$this->page][$pak]['x'] += $t_x;
  24327. $this->PageAnnots[$this->page][$pak]['y'] -= $yshift;
  24328. }
  24329. }
  24330. }
  24331. }
  24332. $this->y -= $yshift;
  24333. }
  24334. }
  24335. // restore previous values
  24336. $this->setGraphicVars($gvars);
  24337. if ($this->num_columns > 1)
  24338. {
  24339. $this->selectColumn();
  24340. }
  24341. elseif ($this->page > $prevPage)
  24342. {
  24343. $this->lMargin = $this->pagedim[$this->page]['olm'];
  24344. $this->rMargin = $this->pagedim[$this->page]['orm'];
  24345. }
  24346. // restore previous list state
  24347. $this->cell_height_ratio = $prev_cell_height_ratio;
  24348. $this->listnum = $prev_listnum;
  24349. $this->listordered = $prev_listordered;
  24350. $this->listcount = $prev_listcount;
  24351. $this->lispacer = $prev_lispacer;
  24352. if ($ln and (! ($cell and ($dom[$key - 1]['value'] == 'table'))))
  24353. {
  24354. $this->Ln($this->lasth);
  24355. if ($this->y < $maxbottomliney)
  24356. {
  24357. $this->y = $maxbottomliney;
  24358. }
  24359. }
  24360. unset($dom);
  24361. }
  24362. /**
  24363. * Process opening tags.
  24364. * @param array $dom html dom array
  24365. * @param int $key current element id
  24366. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  24367. * @access protected
  24368. */
  24369. protected function openHTMLTagHandler(&$dom, $key, $cell)
  24370. {
  24371. $tag = $dom[$key];
  24372. $parent = $dom[($dom[$key]['parent'])];
  24373. $firsttag = ($key == 1);
  24374. // check for text direction attribute
  24375. if (isset($tag['dir']))
  24376. {
  24377. $this->setTempRTL($tag['dir']);
  24378. }
  24379. else
  24380. {
  24381. $this->tmprtl = false;
  24382. }
  24383. if ($tag['block'])
  24384. {
  24385. $hbz = 0; // distance from y to line bottom
  24386. $hb = 0; // vertical space between block tags
  24387. // calculate vertical space for block tags
  24388. if (isset($this->tagvspaces[$tag['value']][0]['h']) and ($this->tagvspaces[$tag['value']][0]['h'] >= 0))
  24389. {
  24390. $cur_h = $this->tagvspaces[$tag['value']][0]['h'];
  24391. }
  24392. elseif (isset($tag['fontsize']))
  24393. {
  24394. $cur_h = ($tag['fontsize'] / $this->k) * $this->cell_height_ratio;
  24395. }
  24396. else
  24397. {
  24398. $cur_h = $this->FontSize * $this->cell_height_ratio;
  24399. }
  24400. if (isset($this->tagvspaces[$tag['value']][0]['n']))
  24401. {
  24402. $n = $this->tagvspaces[$tag['value']][0]['n'];
  24403. }
  24404. elseif (preg_match('/[h][0-9]/', $tag['value']) > 0)
  24405. {
  24406. $n = 0.6;
  24407. }
  24408. else
  24409. {
  24410. $n = 1;
  24411. }
  24412. $hb = ($n * $cur_h);
  24413. if (($this->htmlvspace <= 0) and ($n > 0))
  24414. {
  24415. if (isset($parent['fontsize']))
  24416. {
  24417. $hbz = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  24418. }
  24419. else
  24420. {
  24421. $hbz = $this->FontSize * $this->cell_height_ratio;
  24422. }
  24423. }
  24424. }
  24425. // Opening tag
  24426. switch ($tag['value'])
  24427. {
  24428. case 'table' :
  24429. {
  24430. $cp = 0;
  24431. $cs = 0;
  24432. $dom[$key]['rowspans'] = array();
  24433. if (! isset($dom[$key]['attribute']['nested']) or ($dom[$key]['attribute']['nested'] != 'true'))
  24434. {
  24435. // set table header
  24436. if (! $this->empty_string($dom[$key]['thead']))
  24437. {
  24438. // set table header
  24439. $this->thead = $dom[$key]['thead'];
  24440. if (! isset($this->theadMargins) or (empty($this->theadMargins)))
  24441. {
  24442. $this->theadMargins = array();
  24443. $this->theadMargins['cell_padding'] = $this->cell_padding;
  24444. $this->theadMargins['lmargin'] = $this->lMargin;
  24445. $this->theadMargins['rmargin'] = $this->rMargin;
  24446. $this->theadMargins['page'] = $this->page;
  24447. }
  24448. }
  24449. }
  24450. // store current margins and page
  24451. $dom[$key]['old_cell_padding'] = $this->cell_padding;
  24452. if (isset($tag['attribute']['cellpadding']))
  24453. {
  24454. $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
  24455. $this->SetCellPadding($pad);
  24456. }
  24457. if (isset($tag['attribute']['cellspacing']))
  24458. {
  24459. $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  24460. }
  24461. $prev_y = $this->y;
  24462. if ($this->checkPageBreak(((2 * $cp) + (2 * $cs) + $this->lasth), '', false) or ($this->y < $prev_y))
  24463. {
  24464. $this->inthead = true;
  24465. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  24466. $this->checkPageBreak($this->PageBreakTrigger + 1);
  24467. }
  24468. break;
  24469. }
  24470. case 'tr' :
  24471. {
  24472. // array of columns positions
  24473. $dom[$key]['cellpos'] = array();
  24474. break;
  24475. }
  24476. case 'hr' :
  24477. {
  24478. if ((isset($tag['height'])) and ($tag['height'] != ''))
  24479. {
  24480. $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
  24481. }
  24482. else
  24483. {
  24484. $hrHeight = $this->GetLineWidth();
  24485. }
  24486. $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
  24487. $x = $this->GetX();
  24488. $y = $this->GetY();
  24489. $wtmp = $this->w - $this->lMargin - $this->rMargin;
  24490. if ($cell)
  24491. {
  24492. $wtmp -= ($this->cell_padding['L'] + $this->cell_padding['R']);
  24493. }
  24494. if ((isset($tag['width'])) and ($tag['width'] != ''))
  24495. {
  24496. $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
  24497. }
  24498. else
  24499. {
  24500. $hrWidth = $wtmp;
  24501. }
  24502. $prevlinewidth = $this->GetLineWidth();
  24503. $this->SetLineWidth($hrHeight);
  24504. $this->Line($x, $y, $x + $hrWidth, $y);
  24505. $this->SetLineWidth($prevlinewidth);
  24506. $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, ! isset($dom[($key + 1)]));
  24507. break;
  24508. }
  24509. case 'a' :
  24510. {
  24511. if (array_key_exists('href', $tag['attribute']))
  24512. {
  24513. $this->HREF['url'] = $tag['attribute']['href'];
  24514. }
  24515. break;
  24516. }
  24517. case 'img' :
  24518. {
  24519. if (isset($tag['attribute']['src']))
  24520. {
  24521. // replace relative path with real server path
  24522. if (($tag['attribute']['src'][0] == '/') and ($_SERVER['DOCUMENT_ROOT'] != '/'))
  24523. {
  24524. $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']);
  24525. if (($findroot === false) or ($findroot > 1))
  24526. {
  24527. $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'] . $tag['attribute']['src'];
  24528. }
  24529. }
  24530. $tag['attribute']['src'] = urldecode($tag['attribute']['src']);
  24531. $type = $this->getImageFileType($tag['attribute']['src']);
  24532. $testscrtype = @parse_url($tag['attribute']['src']);
  24533. if (! isset($testscrtype['query']) or empty($testscrtype['query']))
  24534. {
  24535. // convert URL to server path
  24536. $tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']);
  24537. }
  24538. if (! isset($tag['width']))
  24539. {
  24540. $tag['width'] = 0;
  24541. }
  24542. if (! isset($tag['height']))
  24543. {
  24544. $tag['height'] = 0;
  24545. }
  24546. //if (!isset($tag['attribute']['align'])) {
  24547. // the only alignment supported is "bottom"
  24548. // further development is required for other modes.
  24549. $tag['attribute']['align'] = 'bottom';
  24550. //}
  24551. switch ($tag['attribute']['align'])
  24552. {
  24553. case 'top' :
  24554. {
  24555. $align = 'T';
  24556. break;
  24557. }
  24558. case 'middle' :
  24559. {
  24560. $align = 'M';
  24561. break;
  24562. }
  24563. case 'bottom' :
  24564. {
  24565. $align = 'B';
  24566. break;
  24567. }
  24568. default :
  24569. {
  24570. $align = 'B';
  24571. break;
  24572. }
  24573. }
  24574. $prevy = $this->y;
  24575. $xpos = $this->x;
  24576. // eliminate marker spaces
  24577. if (isset($dom[($key - 1)]))
  24578. {
  24579. if (($dom[($key - 1)]['value'] == ' ') or (isset($dom[($key - 1)]['trimmed_space'])))
  24580. {
  24581. $xpos -= $this->GetStringWidth(chr(32));
  24582. }
  24583. elseif ($this->rtl and $dom[($key - 1)]['value'] == ' ')
  24584. {
  24585. $xpos += (2 * $this->GetStringWidth(chr(32)));
  24586. }
  24587. }
  24588. $imglink = '';
  24589. if (isset($this->HREF['url']) and ! $this->empty_string($this->HREF['url']))
  24590. {
  24591. $imglink = $this->HREF['url'];
  24592. if ($imglink{0} == '#')
  24593. {
  24594. // convert url to internal link
  24595. $lnkdata = explode(',', $imglink);
  24596. if (isset($lnkdata[0]))
  24597. {
  24598. $page = intval(substr($lnkdata[0], 1));
  24599. if (empty($page) or ($page <= 0))
  24600. {
  24601. $page = $this->page;
  24602. }
  24603. if (isset($lnkdata[1]) and (strlen($lnkdata[1]) > 0))
  24604. {
  24605. $lnky = floatval($lnkdata[1]);
  24606. }
  24607. else
  24608. {
  24609. $lnky = 0;
  24610. }
  24611. $imglink = $this->AddLink();
  24612. $this->SetLink($imglink, $lnky, $page);
  24613. }
  24614. }
  24615. }
  24616. $border = 0;
  24617. if (isset($tag['border']) and ! empty($tag['border']))
  24618. {
  24619. // currently only support 1 (frame) or a combination of 'LTRB'
  24620. $border = $tag['border'];
  24621. }
  24622. $iw = '';
  24623. if (isset($tag['width']))
  24624. {
  24625. $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
  24626. }
  24627. $ih = '';
  24628. if (isset($tag['height']))
  24629. {
  24630. $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
  24631. }
  24632. if (($type == 'eps') or ($type == 'ai'))
  24633. {
  24634. $this->ImageEps($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true);
  24635. }
  24636. elseif ($type == 'svg')
  24637. {
  24638. $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true);
  24639. }
  24640. else
  24641. {
  24642. $this->Image($tag['attribute']['src'], $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
  24643. }
  24644. switch ($align)
  24645. {
  24646. case 'T' :
  24647. {
  24648. $this->y = $prevy;
  24649. break;
  24650. }
  24651. case 'M' :
  24652. {
  24653. $this->y = (($this->img_rb_y + $prevy - ($tag['fontsize'] / $this->k)) / 2);
  24654. break;
  24655. }
  24656. case 'B' :
  24657. {
  24658. $this->y = $this->img_rb_y - ($tag['fontsize'] / $this->k);
  24659. break;
  24660. }
  24661. }
  24662. }
  24663. break;
  24664. }
  24665. case 'dl' :
  24666. {
  24667. ++ $this->listnum;
  24668. if ($this->listnum == 1)
  24669. {
  24670. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  24671. }
  24672. else
  24673. {
  24674. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  24675. }
  24676. break;
  24677. }
  24678. case 'dt' :
  24679. {
  24680. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  24681. break;
  24682. }
  24683. case 'dd' :
  24684. {
  24685. if ($this->rtl)
  24686. {
  24687. $this->rMargin += $this->listindent;
  24688. }
  24689. else
  24690. {
  24691. $this->lMargin += $this->listindent;
  24692. }
  24693. ++ $this->listindentlevel;
  24694. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  24695. break;
  24696. }
  24697. case 'ul' :
  24698. case 'ol' :
  24699. {
  24700. ++ $this->listnum;
  24701. if ($tag['value'] == 'ol')
  24702. {
  24703. $this->listordered[$this->listnum] = true;
  24704. }
  24705. else
  24706. {
  24707. $this->listordered[$this->listnum] = false;
  24708. }
  24709. if (isset($tag['attribute']['start']))
  24710. {
  24711. $this->listcount[$this->listnum] = intval($tag['attribute']['start']) - 1;
  24712. }
  24713. else
  24714. {
  24715. $this->listcount[$this->listnum] = 0;
  24716. }
  24717. if ($this->rtl)
  24718. {
  24719. $this->rMargin += $this->listindent;
  24720. $this->x -= $this->listindent;
  24721. }
  24722. else
  24723. {
  24724. $this->lMargin += $this->listindent;
  24725. $this->x += $this->listindent;
  24726. }
  24727. ++ $this->listindentlevel;
  24728. if ($this->listnum == 1)
  24729. {
  24730. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  24731. }
  24732. else
  24733. {
  24734. $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
  24735. }
  24736. break;
  24737. }
  24738. case 'li' :
  24739. {
  24740. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  24741. if ($this->listordered[$this->listnum])
  24742. {
  24743. // ordered item
  24744. if (isset($parent['attribute']['type']) and ! $this->empty_string($parent['attribute']['type']))
  24745. {
  24746. $this->lispacer = $parent['attribute']['type'];
  24747. }
  24748. elseif (isset($parent['listtype']) and ! $this->empty_string($parent['listtype']))
  24749. {
  24750. $this->lispacer = $parent['listtype'];
  24751. }
  24752. elseif (isset($this->lisymbol) and ! $this->empty_string($this->lisymbol))
  24753. {
  24754. $this->lispacer = $this->lisymbol;
  24755. }
  24756. else
  24757. {
  24758. $this->lispacer = '#';
  24759. }
  24760. ++ $this->listcount[$this->listnum];
  24761. if (isset($tag['attribute']['value']))
  24762. {
  24763. $this->listcount[$this->listnum] = intval($tag['attribute']['value']);
  24764. }
  24765. }
  24766. else
  24767. {
  24768. // unordered item
  24769. if (isset($parent['attribute']['type']) and ! $this->empty_string($parent['attribute']['type']))
  24770. {
  24771. $this->lispacer = $parent['attribute']['type'];
  24772. }
  24773. elseif (isset($parent['listtype']) and ! $this->empty_string($parent['listtype']))
  24774. {
  24775. $this->lispacer = $parent['listtype'];
  24776. }
  24777. elseif (isset($this->lisymbol) and ! $this->empty_string($this->lisymbol))
  24778. {
  24779. $this->lispacer = $this->lisymbol;
  24780. }
  24781. else
  24782. {
  24783. $this->lispacer = '!';
  24784. }
  24785. }
  24786. break;
  24787. }
  24788. case 'blockquote' :
  24789. {
  24790. if ($this->rtl)
  24791. {
  24792. $this->rMargin += $this->listindent;
  24793. }
  24794. else
  24795. {
  24796. $this->lMargin += $this->listindent;
  24797. }
  24798. ++ $this->listindentlevel;
  24799. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  24800. break;
  24801. }
  24802. case 'br' :
  24803. {
  24804. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  24805. break;
  24806. }
  24807. case 'div' :
  24808. {
  24809. $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
  24810. break;
  24811. }
  24812. case 'p' :
  24813. {
  24814. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  24815. break;
  24816. }
  24817. case 'pre' :
  24818. {
  24819. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  24820. $this->premode = true;
  24821. break;
  24822. }
  24823. case 'sup' :
  24824. {
  24825. $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
  24826. break;
  24827. }
  24828. case 'sub' :
  24829. {
  24830. $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
  24831. break;
  24832. }
  24833. case 'h1' :
  24834. case 'h2' :
  24835. case 'h3' :
  24836. case 'h4' :
  24837. case 'h5' :
  24838. case 'h6' :
  24839. {
  24840. $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
  24841. break;
  24842. }
  24843. // Form fields (since 4.8.000 - 2009-09-07)
  24844. case 'form' :
  24845. {
  24846. if (isset($tag['attribute']['action']))
  24847. {
  24848. $this->form_action = $tag['attribute']['action'];
  24849. }
  24850. else
  24851. {
  24852. $this->form_action = K_PATH_URL . $_SERVER['SCRIPT_NAME'];
  24853. }
  24854. if (isset($tag['attribute']['enctype']))
  24855. {
  24856. $this->form_enctype = $tag['attribute']['enctype'];
  24857. }
  24858. else
  24859. {
  24860. $this->form_enctype = 'application/x-www-form-urlencoded';
  24861. }
  24862. if (isset($tag['attribute']['method']))
  24863. {
  24864. $this->form_mode = $tag['attribute']['method'];
  24865. }
  24866. else
  24867. {
  24868. $this->form_mode = 'post';
  24869. }
  24870. break;
  24871. }
  24872. case 'input' :
  24873. {
  24874. if (isset($tag['attribute']['name']) and ! $this->empty_string($tag['attribute']['name']))
  24875. {
  24876. $name = $tag['attribute']['name'];
  24877. }
  24878. else
  24879. {
  24880. break;
  24881. }
  24882. $prop = array();
  24883. $opt = array();
  24884. if (isset($tag['attribute']['readonly']) and ! $this->empty_string($tag['attribute']['readonly']))
  24885. {
  24886. $prop['readonly'] = true;
  24887. }
  24888. if (isset($tag['attribute']['value']) and ! $this->empty_string($tag['attribute']['value']))
  24889. {
  24890. $value = $tag['attribute']['value'];
  24891. }
  24892. if (isset($tag['attribute']['maxlength']) and ! $this->empty_string($tag['attribute']['maxlength']))
  24893. {
  24894. $opt['maxlen'] = intval($tag['attribute']['value']);
  24895. }
  24896. $h = $this->FontSize * $this->cell_height_ratio;
  24897. if (isset($tag['attribute']['size']) and ! $this->empty_string($tag['attribute']['size']))
  24898. {
  24899. $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
  24900. }
  24901. else
  24902. {
  24903. $w = $h;
  24904. }
  24905. if (isset($tag['attribute']['checked']) and (($tag['attribute']['checked'] == 'checked') or ($tag['attribute']['checked'] == 'true')))
  24906. {
  24907. $checked = true;
  24908. }
  24909. else
  24910. {
  24911. $checked = false;
  24912. }
  24913. switch ($tag['attribute']['type'])
  24914. {
  24915. case 'text' :
  24916. {
  24917. if (isset($value))
  24918. {
  24919. $opt['v'] = $value;
  24920. }
  24921. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  24922. break;
  24923. }
  24924. case 'password' :
  24925. {
  24926. if (isset($value))
  24927. {
  24928. $opt['v'] = $value;
  24929. }
  24930. $prop['password'] = 'true';
  24931. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  24932. break;
  24933. }
  24934. case 'checkbox' :
  24935. {
  24936. $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
  24937. break;
  24938. }
  24939. case 'radio' :
  24940. {
  24941. $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
  24942. break;
  24943. }
  24944. case 'submit' :
  24945. {
  24946. $w = $this->GetStringWidth($value) * 1.5;
  24947. $h *= 1.6;
  24948. $prop = array('lineWidth' => 1, 'borderStyle' => 'beveled',
  24949. 'fillColor' => array(196, 196, 196), 'strokeColor' => array(255, 255, 255));
  24950. $action = array();
  24951. $action['S'] = 'SubmitForm';
  24952. $action['F'] = $this->form_action;
  24953. if ($this->form_enctype != 'FDF')
  24954. {
  24955. $action['Flags'] = array('ExportFormat');
  24956. }
  24957. if ($this->form_mode == 'get')
  24958. {
  24959. $action['Flags'] = array('GetMethod');
  24960. }
  24961. $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
  24962. break;
  24963. }
  24964. case 'reset' :
  24965. {
  24966. $w = $this->GetStringWidth($value) * 1.5;
  24967. $h *= 1.6;
  24968. $prop = array('lineWidth' => 1, 'borderStyle' => 'beveled',
  24969. 'fillColor' => array(196, 196, 196), 'strokeColor' => array(255, 255, 255));
  24970. $this->Button($name, $w, $h, $value, array('S' => 'ResetForm'), $prop, $opt, '', '', false);
  24971. break;
  24972. }
  24973. case 'file' :
  24974. {
  24975. $prop['fileSelect'] = 'true';
  24976. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  24977. if (! isset($value))
  24978. {
  24979. $value = '*';
  24980. }
  24981. $w = $this->GetStringWidth($value) * 2;
  24982. $h *= 1.2;
  24983. $prop = array('lineWidth' => 1, 'borderStyle' => 'beveled',
  24984. 'fillColor' => array(196, 196, 196), 'strokeColor' => array(255, 255, 255));
  24985. $jsaction = 'var f=this.getField(\'' . $name . '\'); f.browseForFileToSubmit();';
  24986. $this->Button('FB_' . $name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  24987. break;
  24988. }
  24989. case 'hidden' :
  24990. {
  24991. if (isset($value))
  24992. {
  24993. $opt['v'] = $value;
  24994. }
  24995. $opt['f'] = array('invisible', 'hidden');
  24996. $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
  24997. break;
  24998. }
  24999. case 'image' :
  25000. {
  25001. // THIS TYPE MUST BE FIXED
  25002. if (isset($tag['attribute']['src']) and ! $this->empty_string($tag['attribute']['src']))
  25003. {
  25004. $img = $tag['attribute']['src'];
  25005. }
  25006. else
  25007. {
  25008. break;
  25009. }
  25010. $value = 'img';
  25011. //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
  25012. if (isset($tag['attribute']['onclick']) and ! empty($tag['attribute']['onclick']))
  25013. {
  25014. $jsaction = $tag['attribute']['onclick'];
  25015. }
  25016. else
  25017. {
  25018. $jsaction = '';
  25019. }
  25020. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  25021. break;
  25022. }
  25023. case 'button' :
  25024. {
  25025. $w = $this->GetStringWidth($value) * 1.5;
  25026. $h *= 1.6;
  25027. $prop = array('lineWidth' => 1, 'borderStyle' => 'beveled',
  25028. 'fillColor' => array(196, 196, 196), 'strokeColor' => array(255, 255, 255));
  25029. if (isset($tag['attribute']['onclick']) and ! empty($tag['attribute']['onclick']))
  25030. {
  25031. $jsaction = $tag['attribute']['onclick'];
  25032. }
  25033. else
  25034. {
  25035. $jsaction = '';
  25036. }
  25037. $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
  25038. break;
  25039. }
  25040. }
  25041. break;
  25042. }
  25043. case 'textarea' :
  25044. {
  25045. $prop = array();
  25046. $opt = array();
  25047. if (isset($tag['attribute']['readonly']) and ! $this->empty_string($tag['attribute']['readonly']))
  25048. {
  25049. $prop['readonly'] = true;
  25050. }
  25051. if (isset($tag['attribute']['name']) and ! $this->empty_string($tag['attribute']['name']))
  25052. {
  25053. $name = $tag['attribute']['name'];
  25054. }
  25055. else
  25056. {
  25057. break;
  25058. }
  25059. if (isset($tag['attribute']['value']) and ! $this->empty_string($tag['attribute']['value']))
  25060. {
  25061. $opt['v'] = $tag['attribute']['value'];
  25062. }
  25063. if (isset($tag['attribute']['cols']) and ! $this->empty_string($tag['attribute']['cols']))
  25064. {
  25065. $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
  25066. }
  25067. else
  25068. {
  25069. $w = 40;
  25070. }
  25071. if (isset($tag['attribute']['rows']) and ! $this->empty_string($tag['attribute']['rows']))
  25072. {
  25073. $h = intval($tag['attribute']['rows']) * $this->FontSize * $this->cell_height_ratio;
  25074. }
  25075. else
  25076. {
  25077. $h = 10;
  25078. }
  25079. $prop['multiline'] = 'true';
  25080. $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
  25081. break;
  25082. }
  25083. case 'select' :
  25084. {
  25085. $h = $this->FontSize * $this->cell_height_ratio;
  25086. if (isset($tag['attribute']['size']) and ! $this->empty_string($tag['attribute']['size']))
  25087. {
  25088. $h *= ($tag['attribute']['size'] + 1);
  25089. }
  25090. $prop = array();
  25091. $opt = array();
  25092. if (isset($tag['attribute']['name']) and ! $this->empty_string($tag['attribute']['name']))
  25093. {
  25094. $name = $tag['attribute']['name'];
  25095. }
  25096. else
  25097. {
  25098. break;
  25099. }
  25100. $w = 0;
  25101. if (isset($tag['attribute']['opt']) and ! $this->empty_string($tag['attribute']['opt']))
  25102. {
  25103. $options = explode('#!NwL!#', $tag['attribute']['opt']);
  25104. $values = array();
  25105. foreach ($options as $val)
  25106. {
  25107. if (strpos($val, '#!TaB!#') !== false)
  25108. {
  25109. $opts = explode('#!TaB!#', $val);
  25110. $values[] = $opts;
  25111. $w = max($w, $this->GetStringWidth($opts[1]));
  25112. }
  25113. else
  25114. {
  25115. $values[] = $val;
  25116. $w = max($w, $this->GetStringWidth($val));
  25117. }
  25118. }
  25119. }
  25120. else
  25121. {
  25122. break;
  25123. }
  25124. $w *= 2;
  25125. if (isset($tag['attribute']['multiple']) and ($tag['attribute']['multiple'] = 'multiple'))
  25126. {
  25127. $prop['multipleSelection'] = 'true';
  25128. $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  25129. }
  25130. else
  25131. {
  25132. $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
  25133. }
  25134. break;
  25135. }
  25136. case 'tcpdf' :
  25137. {
  25138. if (defined('K_TCPDF_CALLS_IN_HTML') and (K_TCPDF_CALLS_IN_HTML === true))
  25139. {
  25140. // Special tag used to call TCPDF methods
  25141. if (isset($tag['attribute']['method']))
  25142. {
  25143. $tcpdf_method = $tag['attribute']['method'];
  25144. if (method_exists($this, $tcpdf_method))
  25145. {
  25146. if (isset($tag['attribute']['params']) and (! empty($tag['attribute']['params'])))
  25147. {
  25148. $params = unserialize(urldecode($tag['attribute']['params']));
  25149. call_user_func_array(array($this, $tcpdf_method), $params);
  25150. }
  25151. else
  25152. {
  25153. $this->$tcpdf_method();
  25154. }
  25155. $this->newline = true;
  25156. }
  25157. }
  25158. }
  25159. break;
  25160. }
  25161. default :
  25162. {
  25163. break;
  25164. }
  25165. }
  25166. // define tags that support borders and background colors
  25167. $bordertags = array('blockquote', 'br', 'dd', 'dl', 'div', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
  25168. 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'tcpdf', 'table');
  25169. if (in_array($tag['value'], $bordertags))
  25170. {
  25171. // set border
  25172. $dom[$key]['borderposition'] = $this->getBorderStartPosition();
  25173. }
  25174. if ($dom[$key]['self'] and isset($dom[$key]['attribute']['pagebreakafter']))
  25175. {
  25176. $pba = $dom[$key]['attribute']['pagebreakafter'];
  25177. // check for pagebreak
  25178. if (($pba == 'true') or ($pba == 'left') or ($pba == 'right'))
  25179. {
  25180. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  25181. $this->checkPageBreak($this->PageBreakTrigger + 1);
  25182. }
  25183. if ((($pba == 'left') and (((! $this->rtl) and (($this->page % 2) == 0)) or (($this->rtl) and (($this->page % 2) != 0)))) or (($pba == 'right') and (((! $this->rtl) and (($this->page % 2) != 0)) or (($this->rtl) and (($this->page % 2) == 0)))))
  25184. {
  25185. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  25186. $this->checkPageBreak($this->PageBreakTrigger + 1);
  25187. }
  25188. }
  25189. }
  25190. /**
  25191. * Process closing tags.
  25192. * @param array $dom html dom array
  25193. * @param int $key current element id
  25194. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  25195. * @param int $maxbottomliney maximum y value of current line
  25196. * @access protected
  25197. */
  25198. protected function closeHTMLTagHandler(&$dom, $key, $cell, $maxbottomliney = 0)
  25199. {
  25200. $tag = $dom[$key];
  25201. $parent = $dom[($dom[$key]['parent'])];
  25202. $lasttag = ((! isset($dom[($key + 1)])) or ((! isset($dom[($key + 2)])) and ($dom[($key + 1)]['value'] == 'marker')));
  25203. $in_table_head = false;
  25204. // maximum x position (used to draw borders)
  25205. if ($this->rtl)
  25206. {
  25207. $xmax = $this->w;
  25208. }
  25209. else
  25210. {
  25211. $xmax = 0;
  25212. }
  25213. if ($tag['block'])
  25214. {
  25215. $hbz = 0; // distance from y to line bottom
  25216. $hb = 0; // vertical space between block tags
  25217. // calculate vertical space for block tags
  25218. if (isset($this->tagvspaces[$tag['value']][1]['h']) and ($this->tagvspaces[$tag['value']][1]['h'] >= 0))
  25219. {
  25220. $pre_h = $this->tagvspaces[$tag['value']][1]['h'];
  25221. }
  25222. elseif (isset($parent['fontsize']))
  25223. {
  25224. $pre_h = (($parent['fontsize'] / $this->k) * $this->cell_height_ratio);
  25225. }
  25226. else
  25227. {
  25228. $pre_h = $this->FontSize * $this->cell_height_ratio;
  25229. }
  25230. if (isset($this->tagvspaces[$tag['value']][1]['n']))
  25231. {
  25232. $n = $this->tagvspaces[$tag['value']][1]['n'];
  25233. }
  25234. elseif (preg_match('/[h][0-9]/', $tag['value']) > 0)
  25235. {
  25236. $n = 0.6;
  25237. }
  25238. else
  25239. {
  25240. $n = 1;
  25241. }
  25242. $hb = ($n * $pre_h);
  25243. if ($this->y < $maxbottomliney)
  25244. {
  25245. $hbz = ($maxbottomliney - $this->y);
  25246. }
  25247. }
  25248. // Closing tag
  25249. switch ($tag['value'])
  25250. {
  25251. case 'tr' :
  25252. {
  25253. $table_el = $dom[($dom[$key]['parent'])]['parent'];
  25254. if (! isset($parent['endy']))
  25255. {
  25256. $dom[($dom[$key]['parent'])]['endy'] = $this->y;
  25257. $parent['endy'] = $this->y;
  25258. }
  25259. if (! isset($parent['endpage']))
  25260. {
  25261. $dom[($dom[$key]['parent'])]['endpage'] = $this->page;
  25262. $parent['endpage'] = $this->page;
  25263. }
  25264. if (! isset($parent['endcolumn']))
  25265. {
  25266. $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column;
  25267. $parent['endcolumn'] = $this->current_column;
  25268. }
  25269. // update row-spanned cells
  25270. if (isset($dom[$table_el]['rowspans']))
  25271. {
  25272. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp)
  25273. {
  25274. $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
  25275. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0)
  25276. {
  25277. if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) and ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn']))
  25278. {
  25279. $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
  25280. }
  25281. elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) or ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn']))
  25282. {
  25283. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  25284. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  25285. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  25286. }
  25287. }
  25288. }
  25289. // report new endy and endpage to the rowspanned cells
  25290. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp)
  25291. {
  25292. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0)
  25293. {
  25294. $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
  25295. $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
  25296. $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
  25297. $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
  25298. $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
  25299. $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
  25300. }
  25301. }
  25302. // update remaining rowspanned cells
  25303. foreach ($dom[$table_el]['rowspans'] as $k => $trwsp)
  25304. {
  25305. if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0)
  25306. {
  25307. $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
  25308. $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
  25309. $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
  25310. }
  25311. }
  25312. }
  25313. $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
  25314. if ($this->num_columns > 1)
  25315. {
  25316. $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
  25317. }
  25318. $this->y = $dom[($dom[$key]['parent'])]['endy'];
  25319. if (isset($dom[$table_el]['attribute']['cellspacing']))
  25320. {
  25321. $cellspacing = $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
  25322. $this->y += $cellspacing;
  25323. }
  25324. $this->Ln(0, $cell);
  25325. if ($this->current_column == $parent['startcolumn'])
  25326. {
  25327. $this->x = $parent['startx'];
  25328. }
  25329. // account for booklet mode
  25330. if ($this->page > $parent['startpage'])
  25331. {
  25332. if (($this->rtl) and ($this->pagedim[$this->page]['orm'] != $this->pagedim[$parent['startpage']]['orm']))
  25333. {
  25334. $this->x -= ($this->pagedim[$this->page]['orm'] - $this->pagedim[$parent['startpage']]['orm']);
  25335. }
  25336. elseif ((! $this->rtl) and ($this->pagedim[$this->page]['olm'] != $this->pagedim[$parent['startpage']]['olm']))
  25337. {
  25338. $this->x += ($this->pagedim[$this->page]['olm'] - $this->pagedim[$parent['startpage']]['olm']);
  25339. }
  25340. }
  25341. break;
  25342. }
  25343. case 'tablehead' :
  25344. // closing tag used for the thead part
  25345. $in_table_head = true;
  25346. $this->inthead = false;
  25347. case 'table' :
  25348. {
  25349. $table_el = $parent;
  25350. // set default border
  25351. if (isset($table_el['attribute']['border']) and ($table_el['attribute']['border'] > 0))
  25352. {
  25353. // set default border
  25354. $border = array(
  25355. 'LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']),
  25356. 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  25357. }
  25358. else
  25359. {
  25360. $border = 0;
  25361. }
  25362. $default_border = $border;
  25363. if (isset($table_el['attribute']['cellspacing']))
  25364. {
  25365. $cellspacing = $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  25366. }
  25367. else
  25368. {
  25369. $cellspacing = 0;
  25370. }
  25371. // fix bottom line alignment of last line before page break
  25372. foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey)
  25373. {
  25374. // update row-spanned cells
  25375. if (isset($dom[($dom[$key]['parent'])]['rowspans']))
  25376. {
  25377. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp)
  25378. {
  25379. if ($trwsp['trid'] == $trkey)
  25380. {
  25381. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
  25382. }
  25383. if (isset($prevtrkey) and ($trwsp['trid'] == $prevtrkey) and ($trwsp['mrowspan'] >= 0))
  25384. {
  25385. $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
  25386. }
  25387. }
  25388. }
  25389. if (isset($prevtrkey) and ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage']))
  25390. {
  25391. $pgendy = $this->pagedim[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim[$dom[$prevtrkey]['endpage']]['bm'];
  25392. $dom[$prevtrkey]['endy'] = $pgendy;
  25393. // update row-spanned cells
  25394. if (isset($dom[($dom[$key]['parent'])]['rowspans']))
  25395. {
  25396. foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp)
  25397. {
  25398. if (($trwsp['trid'] == $trkey) and ($trwsp['mrowspan'] > 1) and ($trwsp['endpage'] == $dom[$prevtrkey]['endpage']))
  25399. {
  25400. $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
  25401. $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = - 1;
  25402. }
  25403. }
  25404. }
  25405. }
  25406. $prevtrkey = $trkey;
  25407. $table_el = $dom[($dom[$key]['parent'])];
  25408. }
  25409. // for each row
  25410. unset($xmax);
  25411. foreach ($table_el['trids'] as $j => $trkey)
  25412. {
  25413. $parent = $dom[$trkey];
  25414. if (! isset($xmax))
  25415. {
  25416. $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
  25417. }
  25418. // for each cell on the row
  25419. foreach ($parent['cellpos'] as $k => $cellpos)
  25420. {
  25421. if (isset($cellpos['rowspanid']) and ($cellpos['rowspanid'] >= 0))
  25422. {
  25423. $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
  25424. $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
  25425. $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
  25426. $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
  25427. $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
  25428. $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
  25429. $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
  25430. }
  25431. else
  25432. {
  25433. $endy = $parent['endy'];
  25434. $startpage = $parent['startpage'];
  25435. $endpage = $parent['endpage'];
  25436. $startcolumn = $parent['startcolumn'];
  25437. $endcolumn = $parent['endcolumn'];
  25438. }
  25439. if ($this->num_columns == 0)
  25440. {
  25441. $this->num_columns = 1;
  25442. }
  25443. if (isset($cellpos['border']))
  25444. {
  25445. $border = $cellpos['border'];
  25446. }
  25447. if (isset($cellpos['bgcolor']) and ($cellpos['bgcolor']) !== false)
  25448. {
  25449. $this->SetFillColorArray($cellpos['bgcolor']);
  25450. $fill = true;
  25451. }
  25452. else
  25453. {
  25454. $fill = false;
  25455. }
  25456. $x = $cellpos['startx'];
  25457. $y = $parent['starty'];
  25458. $starty = $y;
  25459. $w = abs($cellpos['endx'] - $cellpos['startx']);
  25460. // get border modes
  25461. $border_start = $this->getBorderMode($border, $position = 'start');
  25462. $border_end = $this->getBorderMode($border, $position = 'end');
  25463. $border_middle = $this->getBorderMode($border, $position = 'middle');
  25464. // design borders around HTML cells.
  25465. for($page = $startpage; $page <= $endpage; ++ $page)
  25466. { // for each page
  25467. $ccode = '';
  25468. $this->setPage($page);
  25469. if ($this->num_columns < 2)
  25470. {
  25471. // single-column mode
  25472. $this->x = $x;
  25473. $this->y = $this->tMargin;
  25474. }
  25475. // account for margin changes
  25476. if ($page > $startpage)
  25477. {
  25478. if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm']))
  25479. {
  25480. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  25481. }
  25482. elseif ((! $this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm']))
  25483. {
  25484. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  25485. }
  25486. }
  25487. if ($startpage == $endpage)
  25488. { // single page
  25489. $deltacol = 0;
  25490. $deltath = 0;
  25491. for($column = $startcolumn; $column <= $endcolumn; ++ $column)
  25492. { // for each column
  25493. $this->selectColumn($column);
  25494. if ($startcolumn == $endcolumn)
  25495. { // single column
  25496. $cborder = $border;
  25497. $h = $endy - $parent['starty'];
  25498. $this->y = $y;
  25499. $this->x = $x;
  25500. }
  25501. elseif ($column == $startcolumn)
  25502. { // first column
  25503. $cborder = $border_start;
  25504. $this->y = $starty;
  25505. $this->x = $x;
  25506. $h = $this->h - $this->y - $this->bMargin;
  25507. if ($this->rtl)
  25508. {
  25509. $deltacol = $this->x + $this->rMargin - $this->w;
  25510. }
  25511. else
  25512. {
  25513. $deltacol = $this->x - $this->lMargin;
  25514. }
  25515. }
  25516. elseif ($column == $endcolumn)
  25517. { // end column
  25518. $cborder = $border_end;
  25519. if (isset($this->columns[$column]['th']['\'' . $page . '\'']))
  25520. {
  25521. $this->y = $this->columns[$column]['th']['\'' . $page . '\''];
  25522. }
  25523. $this->x += $deltacol;
  25524. $h = $endy - $this->y;
  25525. }
  25526. else
  25527. { // middle column
  25528. $cborder = $border_middle;
  25529. if (isset($this->columns[$column]['th']['\'' . $page . '\'']))
  25530. {
  25531. $this->y = $this->columns[$column]['th']['\'' . $page . '\''];
  25532. }
  25533. $this->x += $deltacol;
  25534. $h = $this->h - $this->y - $this->bMargin;
  25535. }
  25536. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  25537. } // end for each column
  25538. }
  25539. elseif ($page == $startpage)
  25540. { // first page
  25541. $deltacol = 0;
  25542. $deltath = 0;
  25543. for($column = $startcolumn; $column < $this->num_columns; ++ $column)
  25544. { // for each column
  25545. $this->selectColumn($column);
  25546. if ($column == $startcolumn)
  25547. { // first column
  25548. $cborder = $border_start;
  25549. $this->y = $starty;
  25550. $this->x = $x;
  25551. $h = $this->h - $this->y - $this->bMargin;
  25552. if ($this->rtl)
  25553. {
  25554. $deltacol = $this->x + $this->rMargin - $this->w;
  25555. }
  25556. else
  25557. {
  25558. $deltacol = $this->x - $this->lMargin;
  25559. }
  25560. }
  25561. else
  25562. { // middle column
  25563. $cborder = $border_middle;
  25564. if (isset($this->columns[$column]['th']['\'' . $page . '\'']))
  25565. {
  25566. $this->y = $this->columns[$column]['th']['\'' . $page . '\''];
  25567. }
  25568. $this->x += $deltacol;
  25569. $h = $this->h - $this->y - $this->bMargin;
  25570. }
  25571. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  25572. } // end for each column
  25573. }
  25574. elseif ($page == $endpage)
  25575. { // last page
  25576. $deltacol = 0;
  25577. $deltath = 0;
  25578. for($column = 0; $column <= $endcolumn; ++ $column)
  25579. { // for each column
  25580. $this->selectColumn($column);
  25581. if ($column == $endcolumn)
  25582. { // end column
  25583. $cborder = $border_end;
  25584. if (isset($this->columns[$column]['th']['\'' . $page . '\'']))
  25585. {
  25586. $this->y = $this->columns[$column]['th']['\'' . $page . '\''];
  25587. }
  25588. $this->x += $deltacol;
  25589. $h = $endy - $this->y;
  25590. }
  25591. else
  25592. { // middle column
  25593. $cborder = $border_middle;
  25594. if (isset($this->columns[$column]['th']['\'' . $page . '\'']))
  25595. {
  25596. $this->y = $this->columns[$column]['th']['\'' . $page . '\''];
  25597. }
  25598. $this->x += $deltacol;
  25599. $h = $this->h - $this->y - $this->bMargin;
  25600. }
  25601. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  25602. } // end for each column
  25603. }
  25604. else
  25605. { // middle page
  25606. $deltacol = 0;
  25607. $deltath = 0;
  25608. for($column = 0; $column < $this->num_columns; ++ $column)
  25609. { // for each column
  25610. $this->selectColumn($column);
  25611. $cborder = $border_middle;
  25612. if (isset($this->columns[$column]['th']['\'' . $page . '\'']))
  25613. {
  25614. $this->y = $this->columns[$column]['th']['\'' . $page . '\''];
  25615. }
  25616. $this->x += $deltacol;
  25617. $h = $this->h - $this->y - $this->bMargin;
  25618. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  25619. } // end for each column
  25620. }
  25621. if ($cborder or $fill)
  25622. {
  25623. // draw border and fill
  25624. if ($this->inxobj)
  25625. {
  25626. // we are inside an XObject template
  25627. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false)
  25628. {
  25629. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  25630. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  25631. }
  25632. else
  25633. {
  25634. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  25635. }
  25636. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  25637. $pstart = substr($pagebuff, 0, $pagemark);
  25638. $pend = substr($pagebuff, $pagemark);
  25639. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $ccode . $pend;
  25640. $pagemark += strlen($ccode);
  25641. }
  25642. else
  25643. {
  25644. // draw border and fill
  25645. if (end($this->transfmrk[$this->page]) !== false)
  25646. {
  25647. $pagemarkkey = key($this->transfmrk[$this->page]);
  25648. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  25649. }
  25650. elseif ($this->InFooter)
  25651. {
  25652. $pagemark = &$this->footerpos[$this->page];
  25653. }
  25654. else
  25655. {
  25656. $pagemark = &$this->intmrk[$this->page];
  25657. }
  25658. $pagebuff = $this->getPageBuffer($this->page);
  25659. $pstart = substr($pagebuff, 0, $pagemark);
  25660. $pend = substr($pagebuff, $pagemark);
  25661. $this->setPageBuffer($this->page, $pstart . $ccode . $pend);
  25662. $pagemark += strlen($ccode);
  25663. }
  25664. }
  25665. } // end for each page
  25666. // restore default border
  25667. $border = $default_border;
  25668. } // end for each cell on the row
  25669. if (isset($table_el['attribute']['cellspacing']))
  25670. {
  25671. $cellspacing = $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
  25672. $this->y += $cellspacing;
  25673. }
  25674. $this->Ln(0, $cell);
  25675. $this->x = $parent['startx'];
  25676. if ($endpage > $startpage)
  25677. {
  25678. if (($this->rtl) and ($this->pagedim[$endpage]['orm'] != $this->pagedim[$startpage]['orm']))
  25679. {
  25680. $this->x += ($this->pagedim[$endpage]['orm'] - $this->pagedim[$startpage]['orm']);
  25681. }
  25682. elseif ((! $this->rtl) and ($this->pagedim[$endpage]['olm'] != $this->pagedim[$startpage]['olm']))
  25683. {
  25684. $this->x += ($this->pagedim[$endpage]['olm'] - $this->pagedim[$startpage]['olm']);
  25685. }
  25686. }
  25687. }
  25688. if (! $in_table_head)
  25689. { // we are not inside a thead section
  25690. $this->cell_padding = $table_el['old_cell_padding'];
  25691. // reset row height
  25692. $this->resetLastH();
  25693. if (($this->page == ($this->numpages - 1)) and ($this->pageopen[$this->numpages]) and ($this->emptypagemrk[$this->numpages] == $this->pagelen[$this->numpages]))
  25694. {
  25695. // remove last blank page
  25696. $this->deletePage($this->numpages);
  25697. }
  25698. if (isset($this->theadMargins['top']))
  25699. {
  25700. // restore top margin
  25701. $this->tMargin = $this->theadMargins['top'];
  25702. $this->pagedim[$this->page]['tm'] = $this->tMargin;
  25703. }
  25704. if (! isset($table_el['attribute']['nested']) or ($table_el['attribute']['nested'] != 'true'))
  25705. {
  25706. // reset main table header
  25707. $this->thead = '';
  25708. $this->theadMargins = array();
  25709. }
  25710. }
  25711. $parent = $table_el;
  25712. break;
  25713. }
  25714. case 'a' :
  25715. {
  25716. $this->HREF = '';
  25717. break;
  25718. }
  25719. case 'sup' :
  25720. {
  25721. $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent['fontsize']) / $this->k));
  25722. break;
  25723. }
  25724. case 'sub' :
  25725. {
  25726. $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k));
  25727. break;
  25728. }
  25729. case 'div' :
  25730. {
  25731. $this->addHTMLVertSpace($hbz, 0, $cell, false, $lasttag);
  25732. break;
  25733. }
  25734. case 'blockquote' :
  25735. {
  25736. if ($this->rtl)
  25737. {
  25738. $this->rMargin -= $this->listindent;
  25739. }
  25740. else
  25741. {
  25742. $this->lMargin -= $this->listindent;
  25743. }
  25744. -- $this->listindentlevel;
  25745. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  25746. break;
  25747. }
  25748. case 'p' :
  25749. {
  25750. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  25751. break;
  25752. }
  25753. case 'pre' :
  25754. {
  25755. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  25756. $this->premode = false;
  25757. break;
  25758. }
  25759. case 'dl' :
  25760. {
  25761. -- $this->listnum;
  25762. if ($this->listnum <= 0)
  25763. {
  25764. $this->listnum = 0;
  25765. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  25766. }
  25767. else
  25768. {
  25769. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  25770. }
  25771. $this->resetLastH();
  25772. break;
  25773. }
  25774. case 'dt' :
  25775. {
  25776. $this->lispacer = '';
  25777. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  25778. break;
  25779. }
  25780. case 'dd' :
  25781. {
  25782. $this->lispacer = '';
  25783. if ($this->rtl)
  25784. {
  25785. $this->rMargin -= $this->listindent;
  25786. }
  25787. else
  25788. {
  25789. $this->lMargin -= $this->listindent;
  25790. }
  25791. -- $this->listindentlevel;
  25792. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  25793. break;
  25794. }
  25795. case 'ul' :
  25796. case 'ol' :
  25797. {
  25798. -- $this->listnum;
  25799. $this->lispacer = '';
  25800. if ($this->rtl)
  25801. {
  25802. $this->rMargin -= $this->listindent;
  25803. }
  25804. else
  25805. {
  25806. $this->lMargin -= $this->listindent;
  25807. }
  25808. -- $this->listindentlevel;
  25809. if ($this->listnum <= 0)
  25810. {
  25811. $this->listnum = 0;
  25812. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  25813. }
  25814. else
  25815. {
  25816. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  25817. }
  25818. $this->resetLastH();
  25819. break;
  25820. }
  25821. case 'li' :
  25822. {
  25823. $this->lispacer = '';
  25824. $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
  25825. break;
  25826. }
  25827. case 'h1' :
  25828. case 'h2' :
  25829. case 'h3' :
  25830. case 'h4' :
  25831. case 'h5' :
  25832. case 'h6' :
  25833. {
  25834. $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
  25835. break;
  25836. }
  25837. // Form fields (since 4.8.000 - 2009-09-07)
  25838. case 'form' :
  25839. {
  25840. $this->form_action = '';
  25841. $this->form_enctype = 'application/x-www-form-urlencoded';
  25842. break;
  25843. }
  25844. default :
  25845. {
  25846. break;
  25847. }
  25848. }
  25849. // draw border and background (if any)
  25850. $this->drawHTMLTagBorder($parent, $xmax);
  25851. if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter']))
  25852. {
  25853. $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
  25854. // check for pagebreak
  25855. if (($pba == 'true') or ($pba == 'left') or ($pba == 'right'))
  25856. {
  25857. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  25858. $this->checkPageBreak($this->PageBreakTrigger + 1);
  25859. }
  25860. if ((($pba == 'left') and (((! $this->rtl) and (($this->page % 2) == 0)) or (($this->rtl) and (($this->page % 2) != 0)))) or (($pba == 'right') and (((! $this->rtl) and (($this->page % 2) != 0)) or (($this->rtl) and (($this->page % 2) == 0)))))
  25861. {
  25862. // add a page (or trig AcceptPageBreak() for multicolumn mode)
  25863. $this->checkPageBreak($this->PageBreakTrigger + 1);
  25864. }
  25865. }
  25866. $this->tmprtl = false;
  25867. }
  25868. /**
  25869. * Add vertical spaces if needed.
  25870. * @param string $hbz Distance between current y and line bottom.
  25871. * @param string $hb The height of the break.
  25872. * @param boolean $cell if true add the default left (or right if RTL) padding to each new line (default false).
  25873. * @param boolean $firsttag set to true when the tag is the first.
  25874. * @param boolean $lasttag set to true when the tag is the last.
  25875. * @access protected
  25876. */
  25877. protected function addHTMLVertSpace($hbz = 0, $hb = 0, $cell = false, $firsttag = false, $lasttag = false)
  25878. {
  25879. if ($firsttag)
  25880. {
  25881. $this->Ln(0, $cell);
  25882. $this->htmlvspace = 0;
  25883. return;
  25884. }
  25885. if ($lasttag)
  25886. {
  25887. $this->Ln($hbz, $cell);
  25888. $this->htmlvspace = 0;
  25889. return;
  25890. }
  25891. if ($hb < $this->htmlvspace)
  25892. {
  25893. $hd = 0;
  25894. }
  25895. else
  25896. {
  25897. $hd = $hb - $this->htmlvspace;
  25898. $this->htmlvspace = $hb;
  25899. }
  25900. $this->Ln(($hbz + $hd), $cell);
  25901. }
  25902. /**
  25903. * Return the starting coordinates to draw an html border
  25904. * @return array containing top-left border coordinates
  25905. * @access protected
  25906. * @since 5.7.000 (2010-08-03)
  25907. */
  25908. protected function getBorderStartPosition()
  25909. {
  25910. if ($this->rtl)
  25911. {
  25912. $xmax = $this->lMargin;
  25913. }
  25914. else
  25915. {
  25916. $xmax = $this->w - $this->rMargin;
  25917. }
  25918. return array('page' => $this->page, 'column' => $this->current_column, 'x' => $this->x, 'y' => $this->y,
  25919. 'xmax' => $xmax);
  25920. }
  25921. /**
  25922. * Draw an HTML block border and fill
  25923. * @param array $tag array of tag properties.
  25924. * @param int $xmax end X coordinate for border.
  25925. * @access protected
  25926. * @since 5.7.000 (2010-08-03)
  25927. */
  25928. protected function drawHTMLTagBorder($tag, $xmax)
  25929. {
  25930. if (! isset($tag['borderposition']))
  25931. {
  25932. // nothing to draw
  25933. return;
  25934. }
  25935. $prev_x = $this->x;
  25936. $prev_y = $this->y;
  25937. $prev_lasth = $this->lasth;
  25938. $border = 0;
  25939. $fill = false;
  25940. $this->lasth = 0;
  25941. if (isset($tag['border']) and ! empty($tag['border']))
  25942. {
  25943. // get border style
  25944. $border = $tag['border'];
  25945. if (! $this->empty_string($this->thead) and (! $this->inthead))
  25946. {
  25947. // border for table header
  25948. $border = $this->getBorderMode($border, $position = 'middle');
  25949. }
  25950. }
  25951. if (isset($tag['bgcolor']) and ($tag['bgcolor'] !== false))
  25952. {
  25953. // get background color
  25954. $old_bgcolor = $this->bgcolor;
  25955. $this->SetFillColorArray($tag['bgcolor']);
  25956. $fill = true;
  25957. }
  25958. if (! $border and ! $fill)
  25959. {
  25960. // nothing to draw
  25961. return;
  25962. }
  25963. if (isset($tag['attribute']['cellspacing']))
  25964. {
  25965. $cellspacing = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
  25966. }
  25967. else
  25968. {
  25969. $cellspacing = 0;
  25970. }
  25971. if (($tag['value'] != 'table') and (is_array($border)) and (! empty($border)))
  25972. {
  25973. // draw the border externally respect the sqare edge.
  25974. $border['mode'] = 'ext';
  25975. }
  25976. if ($this->rtl)
  25977. {
  25978. if ($xmax >= $tag['borderposition']['x'])
  25979. {
  25980. $xmax = $tag['borderposition']['xmax'];
  25981. }
  25982. $w = ($tag['borderposition']['x'] - $xmax);
  25983. }
  25984. else
  25985. {
  25986. if ($xmax <= $tag['borderposition']['x'])
  25987. {
  25988. $xmax = $tag['borderposition']['xmax'];
  25989. }
  25990. $w = ($xmax - $tag['borderposition']['x']);
  25991. }
  25992. if ($w <= 0)
  25993. {
  25994. return;
  25995. }
  25996. $w += $cellspacing;
  25997. $startpage = $tag['borderposition']['page'];
  25998. $startcolumn = $tag['borderposition']['column'];
  25999. $x = $tag['borderposition']['x'];
  26000. $y = $tag['borderposition']['y'];
  26001. $endpage = $this->page;
  26002. $starty = $tag['borderposition']['y'] - $cellspacing;
  26003. $currentY = $this->y;
  26004. $this->x = $x;
  26005. // get latest column
  26006. $endcolumn = $this->current_column;
  26007. if ($this->num_columns == 0)
  26008. {
  26009. $this->num_columns = 1;
  26010. }
  26011. // get border modes
  26012. $border_start = $this->getBorderMode($border, $position = 'start');
  26013. $border_end = $this->getBorderMode($border, $position = 'end');
  26014. $border_middle = $this->getBorderMode($border, $position = 'middle');
  26015. // design borders around HTML cells.
  26016. for($page = $startpage; $page <= $endpage; ++ $page)
  26017. { // for each page
  26018. $ccode = '';
  26019. $this->setPage($page);
  26020. if ($this->num_columns < 2)
  26021. {
  26022. // single-column mode
  26023. $this->x = $x;
  26024. $this->y = $this->tMargin;
  26025. }
  26026. // account for margin changes
  26027. if ($page > $startpage)
  26028. {
  26029. if (($this->rtl) and ($this->pagedim[$page]['orm'] != $this->pagedim[$startpage]['orm']))
  26030. {
  26031. $this->x -= ($this->pagedim[$page]['orm'] - $this->pagedim[$startpage]['orm']);
  26032. }
  26033. elseif ((! $this->rtl) and ($this->pagedim[$page]['olm'] != $this->pagedim[$startpage]['olm']))
  26034. {
  26035. $this->x += ($this->pagedim[$page]['olm'] - $this->pagedim[$startpage]['olm']);
  26036. }
  26037. }
  26038. if ($startpage == $endpage)
  26039. {
  26040. // single page
  26041. for($column = $startcolumn; $column <= $endcolumn; ++ $column)
  26042. { // for each column
  26043. $this->selectColumn($column);
  26044. if ($startcolumn == $endcolumn)
  26045. { // single column
  26046. $cborder = $border;
  26047. $h = ($currentY - $y) + $cellspacing;
  26048. $this->y = $starty;
  26049. }
  26050. elseif ($column == $startcolumn)
  26051. { // first column
  26052. $cborder = $border_start;
  26053. $this->y = $starty;
  26054. $h = $this->h - $this->y - $this->bMargin;
  26055. }
  26056. elseif ($column == $endcolumn)
  26057. { // end column
  26058. $cborder = $border_end;
  26059. $h = $currentY - $this->y;
  26060. }
  26061. else
  26062. { // middle column
  26063. $cborder = $border_middle;
  26064. $h = $this->h - $this->y - $this->bMargin;
  26065. }
  26066. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  26067. } // end for each column
  26068. }
  26069. elseif ($page == $startpage)
  26070. { // first page
  26071. for($column = $startcolumn; $column < $this->num_columns; ++ $column)
  26072. { // for each column
  26073. $this->selectColumn($column);
  26074. if ($column == $startcolumn)
  26075. { // first column
  26076. $cborder = $border_start;
  26077. $this->y = $starty;
  26078. $h = $this->h - $this->y - $this->bMargin;
  26079. }
  26080. else
  26081. { // middle column
  26082. $cborder = $border_middle;
  26083. $h = $this->h - $this->y - $this->bMargin;
  26084. }
  26085. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  26086. } // end for each column
  26087. }
  26088. elseif ($page == $endpage)
  26089. { // last page
  26090. for($column = 0; $column <= $endcolumn; ++ $column)
  26091. { // for each column
  26092. $this->selectColumn($column);
  26093. if ($column == $endcolumn)
  26094. {
  26095. // end column
  26096. $cborder = $border_end;
  26097. $h = $currentY - $this->y;
  26098. }
  26099. else
  26100. {
  26101. // middle column
  26102. $cborder = $border_middle;
  26103. $h = $this->h - $this->y - $this->bMargin;
  26104. }
  26105. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  26106. } // end for each column
  26107. }
  26108. else
  26109. { // middle page
  26110. for($column = 0; $column < $this->num_columns; ++ $column)
  26111. { // for each column
  26112. $this->selectColumn($column);
  26113. $cborder = $border_middle;
  26114. $h = $this->h - $this->y - $this->bMargin;
  26115. $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true) . "\n";
  26116. } // end for each column
  26117. }
  26118. if ($cborder or $fill)
  26119. {
  26120. // draw border and fill
  26121. if ($this->inxobj)
  26122. {
  26123. // we are inside an XObject template
  26124. if (end($this->xobjects[$this->xobjid]['transfmrk']) !== false)
  26125. {
  26126. $pagemarkkey = key($this->xobjects[$this->xobjid]['transfmrk']);
  26127. $pagemark = &$this->xobjects[$this->xobjid]['transfmrk'][$pagemarkkey];
  26128. }
  26129. else
  26130. {
  26131. $pagemark = &$this->xobjects[$this->xobjid]['intmrk'];
  26132. }
  26133. $pagebuff = $this->xobjects[$this->xobjid]['outdata'];
  26134. $pstart = substr($pagebuff, 0, $pagemark);
  26135. $pend = substr($pagebuff, $pagemark);
  26136. $this->xobjects[$this->xobjid]['outdata'] = $pstart . $ccode . $pend;
  26137. $pagemark += strlen($ccode);
  26138. }
  26139. else
  26140. {
  26141. if (end($this->transfmrk[$this->page]) !== false)
  26142. {
  26143. $pagemarkkey = key($this->transfmrk[$this->page]);
  26144. $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
  26145. }
  26146. elseif ($this->InFooter)
  26147. {
  26148. $pagemark = &$this->footerpos[$this->page];
  26149. }
  26150. else
  26151. {
  26152. $pagemark = &$this->intmrk[$this->page];
  26153. }
  26154. $pagebuff = $this->getPageBuffer($this->page);
  26155. $pstart = substr($pagebuff, 0, $this->bordermrk[$this->page]);
  26156. $pend = substr($pagebuff, $this->bordermrk[$this->page]);
  26157. $this->setPageBuffer($this->page, $pstart . $ccode . $pend);
  26158. $offsetlen = strlen($ccode);
  26159. $this->bordermrk[$this->page] += $offsetlen;
  26160. $this->cntmrk[$this->page] += $offsetlen;
  26161. $pagemark += $offsetlen;
  26162. }
  26163. }
  26164. } // end for each page
  26165. if (isset($old_bgcolor))
  26166. {
  26167. // restore background color
  26168. $this->SetFillColorArray($old_bgcolor);
  26169. }
  26170. // restore pointer position
  26171. $this->x = $prev_x;
  26172. $this->y = $prev_y;
  26173. $this->lasth = $prev_lasth;
  26174. }
  26175. /**
  26176. * Set the default bullet to be used as LI bullet symbol
  26177. * @param string $symbol character or string to be used (legal values are: '' = automatic, '!' = auto bullet, '#' = auto numbering, 'disc', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek')
  26178. * @access public
  26179. * @since 4.0.028 (2008-09-26)
  26180. */
  26181. public function setLIsymbol($symbol = '!')
  26182. {
  26183. $symbol = strtolower($symbol);
  26184. switch ($symbol)
  26185. {
  26186. case '!' :
  26187. case '#' :
  26188. case 'disc' :
  26189. case 'circle' :
  26190. case 'square' :
  26191. case '1' :
  26192. case 'decimal' :
  26193. case 'decimal-leading-zero' :
  26194. case 'i' :
  26195. case 'lower-roman' :
  26196. case 'I' :
  26197. case 'upper-roman' :
  26198. case 'a' :
  26199. case 'lower-alpha' :
  26200. case 'lower-latin' :
  26201. case 'A' :
  26202. case 'upper-alpha' :
  26203. case 'upper-latin' :
  26204. case 'lower-greek' :
  26205. {
  26206. $this->lisymbol = $symbol;
  26207. break;
  26208. }
  26209. default :
  26210. {
  26211. $this->lisymbol = '';
  26212. }
  26213. }
  26214. }
  26215. /**
  26216. * Set the booklet mode for double-sided pages.
  26217. * @param boolean $booklet true set the booklet mode on, false otherwise.
  26218. * @param float $inner Inner page margin.
  26219. * @param float $outer Outer page margin.
  26220. * @access public
  26221. * @since 4.2.000 (2008-10-29)
  26222. */
  26223. public function SetBooklet($booklet = true, $inner = -1, $outer = -1)
  26224. {
  26225. $this->booklet = $booklet;
  26226. if ($inner >= 0)
  26227. {
  26228. $this->lMargin = $inner;
  26229. }
  26230. if ($outer >= 0)
  26231. {
  26232. $this->rMargin = $outer;
  26233. }
  26234. }
  26235. /**
  26236. * Swap the left and right margins.
  26237. * @param boolean $reverse if true swap left and right margins.
  26238. * @access protected
  26239. * @since 4.2.000 (2008-10-29)
  26240. */
  26241. protected function swapMargins($reverse = true)
  26242. {
  26243. if ($reverse)
  26244. {
  26245. // swap left and right margins
  26246. $mtemp = $this->original_lMargin;
  26247. $this->original_lMargin = $this->original_rMargin;
  26248. $this->original_rMargin = $mtemp;
  26249. $deltam = $this->original_lMargin - $this->original_rMargin;
  26250. $this->lMargin += $deltam;
  26251. $this->rMargin -= $deltam;
  26252. }
  26253. }
  26254. /**
  26255. * Set the vertical spaces for HTML tags.
  26256. * The array must have the following structure (example):
  26257. * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
  26258. * The first array level contains the tag names,
  26259. * the second level contains 0 for opening tags or 1 for closing tags,
  26260. * the third level contains the vertical space unit (h) and the number spaces to add (n).
  26261. * If the h parameter is not specified, default values are used.
  26262. * @param array $tagvs array of tags and relative vertical spaces.
  26263. * @access public
  26264. * @since 4.2.001 (2008-10-30)
  26265. */
  26266. public function setHtmlVSpace($tagvs)
  26267. {
  26268. $this->tagvspaces = $tagvs;
  26269. }
  26270. /**
  26271. * Set custom width for list indentation.
  26272. * @param float $width width of the indentation. Use negative value to disable it.
  26273. * @access public
  26274. * @since 4.2.007 (2008-11-12)
  26275. */
  26276. public function setListIndentWidth($width)
  26277. {
  26278. return $this->customlistindent = floatval($width);
  26279. }
  26280. /**
  26281. * Set the top/bottom cell sides to be open or closed when the cell cross the page.
  26282. * @param boolean $isopen if true keeps the top/bottom border open for the cell sides that cross the page.
  26283. * @access public
  26284. * @since 4.2.010 (2008-11-14)
  26285. */
  26286. public function setOpenCell($isopen)
  26287. {
  26288. $this->opencell = $isopen;
  26289. }
  26290. /**
  26291. * Set the color and font style for HTML links.
  26292. * @param array $color RGB array of colors
  26293. * @param string $fontstyle additional font styles to add
  26294. * @access public
  26295. * @since 4.4.003 (2008-12-09)
  26296. */
  26297. public function setHtmlLinksStyle($color = array(0,0,255), $fontstyle = 'U')
  26298. {
  26299. $this->htmlLinkColorArray = $color;
  26300. $this->htmlLinkFontStyle = $fontstyle;
  26301. }
  26302. /**
  26303. * Convert HTML string containing value and unit of measure to user's units or points.
  26304. * @param string $htmlval string containing values and unit
  26305. * @param string $refsize reference value in points
  26306. * @param string $defaultunit default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
  26307. * @param boolean $point if true returns points, otherwise returns value in user's units
  26308. * @return float value in user's unit or point if $points=true
  26309. * @access public
  26310. * @since 4.4.004 (2008-12-10)
  26311. */
  26312. public function getHTMLUnitToUnits($htmlval, $refsize = 1, $defaultunit = 'px', $points = false)
  26313. {
  26314. $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
  26315. $retval = 0;
  26316. $value = 0;
  26317. $unit = 'px';
  26318. $k = $this->k;
  26319. if ($points)
  26320. {
  26321. $k = 1;
  26322. }
  26323. if (in_array($defaultunit, $supportedunits))
  26324. {
  26325. $unit = $defaultunit;
  26326. }
  26327. if (is_numeric($htmlval))
  26328. {
  26329. $value = floatval($htmlval);
  26330. }
  26331. elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum))
  26332. {
  26333. $value = floatval($mnum[1]);
  26334. if (preg_match('/([a-z%]+)/', $htmlval, $munit))
  26335. {
  26336. if (in_array($munit[1], $supportedunits))
  26337. {
  26338. $unit = $munit[1];
  26339. }
  26340. }
  26341. }
  26342. switch ($unit)
  26343. {
  26344. // percentage
  26345. case '%' :
  26346. {
  26347. $retval = (($value * $refsize) / 100);
  26348. break;
  26349. }
  26350. // relative-size
  26351. case 'em' :
  26352. {
  26353. $retval = ($value * $refsize);
  26354. break;
  26355. }
  26356. // height of lower case 'x' (about half the font-size)
  26357. case 'ex' :
  26358. {
  26359. $retval = $value * ($refsize / 2);
  26360. break;
  26361. }
  26362. // absolute-size
  26363. case 'in' :
  26364. {
  26365. $retval = ($value * $this->dpi) / $k;
  26366. break;
  26367. }
  26368. // centimeters
  26369. case 'cm' :
  26370. {
  26371. $retval = ($value / 2.54 * $this->dpi) / $k;
  26372. break;
  26373. }
  26374. // millimeters
  26375. case 'mm' :
  26376. {
  26377. $retval = ($value / 25.4 * $this->dpi) / $k;
  26378. break;
  26379. }
  26380. // one pica is 12 points
  26381. case 'pc' :
  26382. {
  26383. $retval = ($value * 12) / $k;
  26384. break;
  26385. }
  26386. // points
  26387. case 'pt' :
  26388. {
  26389. $retval = $value / $k;
  26390. break;
  26391. }
  26392. // pixels
  26393. case 'px' :
  26394. {
  26395. $retval = $this->pixelsToUnits($value);
  26396. break;
  26397. }
  26398. }
  26399. return $retval;
  26400. }
  26401. /**
  26402. * Returns the Roman representation of an integer number
  26403. * @param int number to convert
  26404. * @return string roman representation of the specified number
  26405. * @access public
  26406. * @since 4.4.004 (2008-12-10)
  26407. */
  26408. public function intToRoman($number)
  26409. {
  26410. $roman = '';
  26411. while ($number >= 1000)
  26412. {
  26413. $roman .= 'M';
  26414. $number -= 1000;
  26415. }
  26416. while ($number >= 900)
  26417. {
  26418. $roman .= 'CM';
  26419. $number -= 900;
  26420. }
  26421. while ($number >= 500)
  26422. {
  26423. $roman .= 'D';
  26424. $number -= 500;
  26425. }
  26426. while ($number >= 400)
  26427. {
  26428. $roman .= 'CD';
  26429. $number -= 400;
  26430. }
  26431. while ($number >= 100)
  26432. {
  26433. $roman .= 'C';
  26434. $number -= 100;
  26435. }
  26436. while ($number >= 90)
  26437. {
  26438. $roman .= 'XC';
  26439. $number -= 90;
  26440. }
  26441. while ($number >= 50)
  26442. {
  26443. $roman .= 'L';
  26444. $number -= 50;
  26445. }
  26446. while ($number >= 40)
  26447. {
  26448. $roman .= 'XL';
  26449. $number -= 40;
  26450. }
  26451. while ($number >= 10)
  26452. {
  26453. $roman .= 'X';
  26454. $number -= 10;
  26455. }
  26456. while ($number >= 9)
  26457. {
  26458. $roman .= 'IX';
  26459. $number -= 9;
  26460. }
  26461. while ($number >= 5)
  26462. {
  26463. $roman .= 'V';
  26464. $number -= 5;
  26465. }
  26466. while ($number >= 4)
  26467. {
  26468. $roman .= 'IV';
  26469. $number -= 4;
  26470. }
  26471. while ($number >= 1)
  26472. {
  26473. $roman .= 'I';
  26474. -- $number;
  26475. }
  26476. return $roman;
  26477. }
  26478. /**
  26479. * Output an HTML list bullet or ordered item symbol
  26480. * @param int $listdepth list nesting level
  26481. * @param string $listtype type of list
  26482. * @param float $size current font size
  26483. * @access protected
  26484. * @since 4.4.004 (2008-12-10)
  26485. */
  26486. protected function putHtmlListBullet($listdepth, $listtype = '', $size = 10)
  26487. {
  26488. $size /= $this->k;
  26489. $fill = '';
  26490. $color = $this->fgcolor;
  26491. $width = 0;
  26492. $textitem = '';
  26493. $tmpx = $this->x;
  26494. $lspace = $this->GetStringWidth(' ');
  26495. if ($listtype == '^')
  26496. {
  26497. // special symbol used for avoid justification of rect bullet
  26498. $this->lispacer = '';
  26499. return;
  26500. }
  26501. elseif ($listtype == '!')
  26502. {
  26503. // set default list type for unordered list
  26504. $deftypes = array('disc', 'circle', 'square');
  26505. $listtype = $deftypes[($listdepth - 1) % 3];
  26506. }
  26507. elseif ($listtype == '#')
  26508. {
  26509. // set default list type for ordered list
  26510. $listtype = 'decimal';
  26511. }
  26512. switch ($listtype)
  26513. {
  26514. // unordered types
  26515. case 'none' :
  26516. {
  26517. break;
  26518. }
  26519. case 'disc' :
  26520. {
  26521. $fill = 'F';
  26522. }
  26523. case 'circle' :
  26524. {
  26525. $fill .= 'D';
  26526. $r = $size / 6;
  26527. $lspace += (2 * $r);
  26528. if ($this->rtl)
  26529. {
  26530. $this->x += $lspace;
  26531. }
  26532. else
  26533. {
  26534. $this->x -= $lspace;
  26535. }
  26536. $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, $fill, array(
  26537. 'color' => $color), $color, 8);
  26538. break;
  26539. }
  26540. case 'square' :
  26541. {
  26542. $l = $size / 3;
  26543. $lspace += $l;
  26544. if ($this->rtl)
  26545. {
  26546. ;
  26547. $this->x += $lspace;
  26548. }
  26549. else
  26550. {
  26551. $this->x -= $lspace;
  26552. }
  26553. $this->Rect($this->x, ($this->y + (($this->lasth - $l) / 2)), $l, $l, 'F', array(), $color);
  26554. break;
  26555. }
  26556. // ordered types
  26557. // $this->listcount[$this->listnum];
  26558. // $textitem
  26559. case '1' :
  26560. case 'decimal' :
  26561. {
  26562. $textitem = $this->listcount[$this->listnum];
  26563. break;
  26564. }
  26565. case 'decimal-leading-zero' :
  26566. {
  26567. $textitem = sprintf('%02d', $this->listcount[$this->listnum]);
  26568. break;
  26569. }
  26570. case 'i' :
  26571. case 'lower-roman' :
  26572. {
  26573. $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum]));
  26574. break;
  26575. }
  26576. case 'I' :
  26577. case 'upper-roman' :
  26578. {
  26579. $textitem = $this->intToRoman($this->listcount[$this->listnum]);
  26580. break;
  26581. }
  26582. case 'a' :
  26583. case 'lower-alpha' :
  26584. case 'lower-latin' :
  26585. {
  26586. $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
  26587. break;
  26588. }
  26589. case 'A' :
  26590. case 'upper-alpha' :
  26591. case 'upper-latin' :
  26592. {
  26593. $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
  26594. break;
  26595. }
  26596. case 'lower-greek' :
  26597. {
  26598. $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1);
  26599. break;
  26600. }
  26601. /*
  26602. // Types to be implemented (special handling)
  26603. case 'hebrew': {
  26604. break;
  26605. }
  26606. case 'armenian': {
  26607. break;
  26608. }
  26609. case 'georgian': {
  26610. break;
  26611. }
  26612. case 'cjk-ideographic': {
  26613. break;
  26614. }
  26615. case 'hiragana': {
  26616. break;
  26617. }
  26618. case 'katakana': {
  26619. break;
  26620. }
  26621. case 'hiragana-iroha': {
  26622. break;
  26623. }
  26624. case 'katakana-iroha': {
  26625. break;
  26626. }
  26627. */
  26628. default :
  26629. {
  26630. $textitem = $this->listcount[$this->listnum];
  26631. }
  26632. }
  26633. if (! $this->empty_string($textitem))
  26634. {
  26635. // print ordered item
  26636. if ($this->rtl)
  26637. {
  26638. $textitem = '.' . $textitem;
  26639. }
  26640. else
  26641. {
  26642. $textitem = $textitem . '.';
  26643. }
  26644. $lspace += $this->GetStringWidth($textitem);
  26645. if ($this->rtl)
  26646. {
  26647. $this->x += $lspace;
  26648. }
  26649. else
  26650. {
  26651. $this->x -= $lspace;
  26652. }
  26653. $this->Write($this->lasth, $textitem, '', false, '', false, 0, false);
  26654. }
  26655. $this->x = $tmpx;
  26656. $this->lispacer = '^';
  26657. }
  26658. /**
  26659. * Returns current graphic variables as array.
  26660. * @return array of graphic variables
  26661. * @access protected
  26662. * @since 4.2.010 (2008-11-14)
  26663. */
  26664. protected function getGraphicVars()
  26665. {
  26666. $grapvars = array('FontFamily' => $this->FontFamily, 'FontStyle' => $this->FontStyle,
  26667. 'FontSizePt' => $this->FontSizePt, 'rMargin' => $this->rMargin, 'lMargin' => $this->lMargin,
  26668. 'cell_padding' => $this->cell_padding, 'cell_margin' => $this->cell_margin,
  26669. 'LineWidth' => $this->LineWidth, 'linestyleWidth' => $this->linestyleWidth,
  26670. 'linestyleCap' => $this->linestyleCap, 'linestyleJoin' => $this->linestyleJoin,
  26671. 'linestyleDash' => $this->linestyleDash, 'textrendermode' => $this->textrendermode,
  26672. 'textstrokewidth' => $this->textstrokewidth, 'DrawColor' => $this->DrawColor,
  26673. 'FillColor' => $this->FillColor, 'TextColor' => $this->TextColor, 'ColorFlag' => $this->ColorFlag,
  26674. 'bgcolor' => $this->bgcolor, 'fgcolor' => $this->fgcolor, 'htmlvspace' => $this->htmlvspace,
  26675. 'listindent' => $this->listindent, 'listindentlevel' => $this->listindentlevel,
  26676. 'listnum' => $this->listnum, 'listordered' => $this->listordered, 'listcount' => $this->listcount,
  26677. 'lispacer' => $this->lispacer, 'cell_height_ratio' => $this->cell_height_ratio,
  26678. 'font_stretching' => $this->font_stretching, 'font_spacing' => $this->font_spacing,
  26679. // extended
  26680. 'lasth' => $this->lasth, 'tMargin' => $this->tMargin, 'bMargin' => $this->bMargin,
  26681. 'AutoPageBreak' => $this->AutoPageBreak, 'PageBreakTrigger' => $this->PageBreakTrigger, 'x' => $this->x,
  26682. 'y' => $this->y, 'w' => $this->w, 'h' => $this->h, 'wPt' => $this->wPt, 'hPt' => $this->hPt,
  26683. 'fwPt' => $this->fwPt, 'fhPt' => $this->fhPt, 'page' => $this->page,
  26684. 'current_column' => $this->current_column, 'num_columns' => $this->num_columns);
  26685. return $grapvars;
  26686. }
  26687. /**
  26688. * Set graphic variables.
  26689. * @param array $gvars array of graphic variablesto restore
  26690. * @param boolean $extended if true restore extended graphic variables
  26691. * @access protected
  26692. * @since 4.2.010 (2008-11-14)
  26693. */
  26694. protected function setGraphicVars($gvars, $extended = false)
  26695. {
  26696. $this->FontFamily = $gvars['FontFamily'];
  26697. $this->FontStyle = $gvars['FontStyle'];
  26698. $this->FontSizePt = $gvars['FontSizePt'];
  26699. $this->rMargin = $gvars['rMargin'];
  26700. $this->lMargin = $gvars['lMargin'];
  26701. $this->cell_padding = $gvars['cell_padding'];
  26702. $this->cell_margin = $gvars['cell_margin'];
  26703. $this->LineWidth = $gvars['LineWidth'];
  26704. $this->linestyleWidth = $gvars['linestyleWidth'];
  26705. $this->linestyleCap = $gvars['linestyleCap'];
  26706. $this->linestyleJoin = $gvars['linestyleJoin'];
  26707. $this->linestyleDash = $gvars['linestyleDash'];
  26708. $this->textrendermode = $gvars['textrendermode'];
  26709. $this->textstrokewidth = $gvars['textstrokewidth'];
  26710. $this->DrawColor = $gvars['DrawColor'];
  26711. $this->FillColor = $gvars['FillColor'];
  26712. $this->TextColor = $gvars['TextColor'];
  26713. $this->ColorFlag = $gvars['ColorFlag'];
  26714. $this->bgcolor = $gvars['bgcolor'];
  26715. $this->fgcolor = $gvars['fgcolor'];
  26716. $this->htmlvspace = $gvars['htmlvspace'];
  26717. $this->listindent = $gvars['listindent'];
  26718. $this->listindentlevel = $gvars['listindentlevel'];
  26719. $this->listnum = $gvars['listnum'];
  26720. $this->listordered = $gvars['listordered'];
  26721. $this->listcount = $gvars['listcount'];
  26722. $this->lispacer = $gvars['lispacer'];
  26723. $this->cell_height_ratio = $gvars['cell_height_ratio'];
  26724. $this->font_stretching = $gvars['font_stretching'];
  26725. $this->font_spacing = $gvars['font_spacing'];
  26726. if ($extended)
  26727. {
  26728. // restore extended values
  26729. $this->lasth = $gvars['lasth'];
  26730. $this->tMargin = $gvars['tMargin'];
  26731. $this->bMargin = $gvars['bMargin'];
  26732. $this->AutoPageBreak = $gvars['AutoPageBreak'];
  26733. $this->PageBreakTrigger = $gvars['PageBreakTrigger'];
  26734. $this->x = $gvars['x'];
  26735. $this->y = $gvars['y'];
  26736. $this->w = $gvars['w'];
  26737. $this->h = $gvars['h'];
  26738. $this->wPt = $gvars['wPt'];
  26739. $this->hPt = $gvars['hPt'];
  26740. $this->fwPt = $gvars['fwPt'];
  26741. $this->fhPt = $gvars['fhPt'];
  26742. $this->page = $gvars['page'];
  26743. $this->current_column = $gvars['current_column'];
  26744. $this->num_columns = $gvars['num_columns'];
  26745. }
  26746. $this->_out('' . $this->linestyleWidth . ' ' . $this->linestyleCap . ' ' . $this->linestyleJoin . ' ' . $this->linestyleDash . ' ' . $this->DrawColor . ' ' . $this->FillColor . '');
  26747. if (! $this->empty_string($this->FontFamily))
  26748. {
  26749. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  26750. }
  26751. }
  26752. /**
  26753. * Returns a temporary filename for caching object on filesystem.
  26754. * @param string $prefix prefix to add to filename
  26755. * return string filename.
  26756. * @access protected
  26757. * @since 4.5.000 (2008-12-31)
  26758. */
  26759. protected function getObjFilename($name)
  26760. {
  26761. return tempnam(K_PATH_CACHE, $name . '_');
  26762. }
  26763. /**
  26764. * Writes data to a temporary file on filesystem.
  26765. * @param string $file file name
  26766. * @param mixed $data data to write on file
  26767. * @param boolean $append if true append data, false replace.
  26768. * @access protected
  26769. * @since 4.5.000 (2008-12-31)
  26770. */
  26771. protected function writeDiskCache($filename, $data, $append = false)
  26772. {
  26773. if ($append)
  26774. {
  26775. $fmode = 'ab+';
  26776. }
  26777. else
  26778. {
  26779. $fmode = 'wb+';
  26780. }
  26781. $f = @fopen($filename, $fmode);
  26782. if (! $f)
  26783. {
  26784. $this->Error('Unable to write cache file: ' . $filename);
  26785. }
  26786. else
  26787. {
  26788. fwrite($f, $data);
  26789. fclose($f);
  26790. }
  26791. // update file length (needed for transactions)
  26792. if (! isset($this->cache_file_length['_' . $filename]))
  26793. {
  26794. $this->cache_file_length['_' . $filename] = strlen($data);
  26795. }
  26796. else
  26797. {
  26798. $this->cache_file_length['_' . $filename] += strlen($data);
  26799. }
  26800. }
  26801. /**
  26802. * Read data from a temporary file on filesystem.
  26803. * @param string $file file name
  26804. * @return mixed retrieved data
  26805. * @access protected
  26806. * @since 4.5.000 (2008-12-31)
  26807. */
  26808. protected function readDiskCache($filename)
  26809. {
  26810. return file_get_contents($filename);
  26811. }
  26812. /**
  26813. * Set buffer content (always append data).
  26814. * @param string $data data
  26815. * @access protected
  26816. * @since 4.5.000 (2009-01-02)
  26817. */
  26818. protected function setBuffer($data)
  26819. {
  26820. $this->bufferlen += strlen($data);
  26821. if ($this->diskcache)
  26822. {
  26823. if (! isset($this->buffer) or $this->empty_string($this->buffer))
  26824. {
  26825. $this->buffer = $this->getObjFilename('buffer');
  26826. }
  26827. $this->writeDiskCache($this->buffer, $data, true);
  26828. }
  26829. else
  26830. {
  26831. $this->buffer .= $data;
  26832. }
  26833. }
  26834. /**
  26835. * Replace the buffer content
  26836. * @param string $data data
  26837. * @access protected
  26838. * @since 5.5.000 (2010-06-22)
  26839. */
  26840. protected function replaceBuffer($data)
  26841. {
  26842. $this->bufferlen = strlen($data);
  26843. if ($this->diskcache)
  26844. {
  26845. if (! isset($this->buffer) or $this->empty_string($this->buffer))
  26846. {
  26847. $this->buffer = $this->getObjFilename('buffer');
  26848. }
  26849. $this->writeDiskCache($this->buffer, $data, false);
  26850. }
  26851. else
  26852. {
  26853. $this->buffer = $data;
  26854. }
  26855. }
  26856. /**
  26857. * Get buffer content.
  26858. * @return string buffer content
  26859. * @access protected
  26860. * @since 4.5.000 (2009-01-02)
  26861. */
  26862. protected function getBuffer()
  26863. {
  26864. if ($this->diskcache)
  26865. {
  26866. return $this->readDiskCache($this->buffer);
  26867. }
  26868. else
  26869. {
  26870. return $this->buffer;
  26871. }
  26872. }
  26873. /**
  26874. * Set page buffer content.
  26875. * @param int $page page number
  26876. * @param string $data page data
  26877. * @param boolean $append if true append data, false replace.
  26878. * @access protected
  26879. * @since 4.5.000 (2008-12-31)
  26880. */
  26881. protected function setPageBuffer($page, $data, $append = false)
  26882. {
  26883. if ($this->diskcache)
  26884. {
  26885. if (! isset($this->pages[$page]))
  26886. {
  26887. $this->pages[$page] = $this->getObjFilename('page' . $page);
  26888. }
  26889. $this->writeDiskCache($this->pages[$page], $data, $append);
  26890. }
  26891. else
  26892. {
  26893. if ($append)
  26894. {
  26895. $this->pages[$page] .= $data;
  26896. }
  26897. else
  26898. {
  26899. $this->pages[$page] = $data;
  26900. }
  26901. }
  26902. if ($append and isset($this->pagelen[$page]))
  26903. {
  26904. $this->pagelen[$page] += strlen($data);
  26905. }
  26906. else
  26907. {
  26908. $this->pagelen[$page] = strlen($data);
  26909. }
  26910. }
  26911. /**
  26912. * Get page buffer content.
  26913. * @param int $page page number
  26914. * @return string page buffer content or false in case of error
  26915. * @access protected
  26916. * @since 4.5.000 (2008-12-31)
  26917. */
  26918. protected function getPageBuffer($page)
  26919. {
  26920. if ($this->diskcache)
  26921. {
  26922. return $this->readDiskCache($this->pages[$page]);
  26923. }
  26924. elseif (isset($this->pages[$page]))
  26925. {
  26926. return $this->pages[$page];
  26927. }
  26928. return false;
  26929. }
  26930. /**
  26931. * Set image buffer content.
  26932. * @param string $image image key
  26933. * @param array $data image data
  26934. * @access protected
  26935. * @since 4.5.000 (2008-12-31)
  26936. */
  26937. protected function setImageBuffer($image, $data)
  26938. {
  26939. if ($this->diskcache)
  26940. {
  26941. if (! isset($this->images[$image]))
  26942. {
  26943. $this->images[$image] = $this->getObjFilename('image' . $image);
  26944. }
  26945. $this->writeDiskCache($this->images[$image], serialize($data));
  26946. }
  26947. else
  26948. {
  26949. $this->images[$image] = $data;
  26950. }
  26951. if (! in_array($image, $this->imagekeys))
  26952. {
  26953. $this->imagekeys[] = $image;
  26954. ++ $this->numimages;
  26955. }
  26956. }
  26957. /**
  26958. * Set image buffer content for a specified sub-key.
  26959. * @param string $image image key
  26960. * @param string $key image sub-key
  26961. * @param array $data image data
  26962. * @access protected
  26963. * @since 4.5.000 (2008-12-31)
  26964. */
  26965. protected function setImageSubBuffer($image, $key, $data)
  26966. {
  26967. if (! isset($this->images[$image]))
  26968. {
  26969. $this->setImageBuffer($image, array());
  26970. }
  26971. if ($this->diskcache)
  26972. {
  26973. $tmpimg = $this->getImageBuffer($image);
  26974. $tmpimg[$key] = $data;
  26975. $this->writeDiskCache($this->images[$image], serialize($tmpimg));
  26976. }
  26977. else
  26978. {
  26979. $this->images[$image][$key] = $data;
  26980. }
  26981. }
  26982. /**
  26983. * Get image buffer content.
  26984. * @param string $image image key
  26985. * @return string image buffer content or false in case of error
  26986. * @access protected
  26987. * @since 4.5.000 (2008-12-31)
  26988. */
  26989. protected function getImageBuffer($image)
  26990. {
  26991. if ($this->diskcache and isset($this->images[$image]))
  26992. {
  26993. return unserialize($this->readDiskCache($this->images[$image]));
  26994. }
  26995. elseif (isset($this->images[$image]))
  26996. {
  26997. return $this->images[$image];
  26998. }
  26999. return false;
  27000. }
  27001. /**
  27002. * Set font buffer content.
  27003. * @param string $font font key
  27004. * @param array $data font data
  27005. * @access protected
  27006. * @since 4.5.000 (2009-01-02)
  27007. */
  27008. protected function setFontBuffer($font, $data)
  27009. {
  27010. if ($this->diskcache)
  27011. {
  27012. if (! isset($this->fonts[$font]))
  27013. {
  27014. $this->fonts[$font] = $this->getObjFilename('font');
  27015. }
  27016. $this->writeDiskCache($this->fonts[$font], serialize($data));
  27017. }
  27018. else
  27019. {
  27020. $this->fonts[$font] = $data;
  27021. }
  27022. if (! in_array($font, $this->fontkeys))
  27023. {
  27024. $this->fontkeys[] = $font;
  27025. // store object ID for current font
  27026. ++ $this->n;
  27027. $this->font_obj_ids[$font] = $this->n;
  27028. $this->setFontSubBuffer($font, 'n', $this->n);
  27029. }
  27030. }
  27031. /**
  27032. * Set font buffer content.
  27033. * @param string $font font key
  27034. * @param string $key font sub-key
  27035. * @param array $data font data
  27036. * @access protected
  27037. * @since 4.5.000 (2009-01-02)
  27038. */
  27039. protected function setFontSubBuffer($font, $key, $data)
  27040. {
  27041. if (! isset($this->fonts[$font]))
  27042. {
  27043. $this->setFontBuffer($font, array());
  27044. }
  27045. if ($this->diskcache)
  27046. {
  27047. $tmpfont = $this->getFontBuffer($font);
  27048. $tmpfont[$key] = $data;
  27049. $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
  27050. }
  27051. else
  27052. {
  27053. $this->fonts[$font][$key] = $data;
  27054. }
  27055. }
  27056. /**
  27057. * Get font buffer content.
  27058. * @param string $font font key
  27059. * @return string font buffer content or false in case of error
  27060. * @access protected
  27061. * @since 4.5.000 (2009-01-02)
  27062. */
  27063. protected function getFontBuffer($font)
  27064. {
  27065. if ($this->diskcache and isset($this->fonts[$font]))
  27066. {
  27067. return unserialize($this->readDiskCache($this->fonts[$font]));
  27068. }
  27069. elseif (isset($this->fonts[$font]))
  27070. {
  27071. return $this->fonts[$font];
  27072. }
  27073. return false;
  27074. }
  27075. /**
  27076. * Move a page to a previous position.
  27077. * @param int $frompage number of the source page
  27078. * @param int $topage number of the destination page (must be less than $frompage)
  27079. * @return true in case of success, false in case of error.
  27080. * @access public
  27081. * @since 4.5.000 (2009-01-02)
  27082. */
  27083. public function movePage($frompage, $topage)
  27084. {
  27085. if (($frompage > $this->numpages) or ($frompage <= $topage))
  27086. {
  27087. return false;
  27088. }
  27089. if ($frompage == $this->page)
  27090. {
  27091. // close the page before moving it
  27092. $this->endPage();
  27093. }
  27094. // move all page-related states
  27095. $tmppage = $this->pages[$frompage];
  27096. $tmppagedim = $this->pagedim[$frompage];
  27097. $tmppagelen = $this->pagelen[$frompage];
  27098. $tmpintmrk = $this->intmrk[$frompage];
  27099. $tmpbordermrk = $this->bordermrk[$frompage];
  27100. $tmpcntmrk = $this->cntmrk[$frompage];
  27101. if (isset($this->footerpos[$frompage]))
  27102. {
  27103. $tmpfooterpos = $this->footerpos[$frompage];
  27104. }
  27105. if (isset($this->footerlen[$frompage]))
  27106. {
  27107. $tmpfooterlen = $this->footerlen[$frompage];
  27108. }
  27109. if (isset($this->transfmrk[$frompage]))
  27110. {
  27111. $tmptransfmrk = $this->transfmrk[$frompage];
  27112. }
  27113. if (isset($this->PageAnnots[$frompage]))
  27114. {
  27115. $tmpannots = $this->PageAnnots[$frompage];
  27116. }
  27117. if (isset($this->newpagegroup[$frompage]))
  27118. {
  27119. $tmpnewpagegroup = $this->newpagegroup[$frompage];
  27120. }
  27121. for($i = $frompage; $i > $topage; -- $i)
  27122. {
  27123. $j = $i - 1;
  27124. // shift pages down
  27125. $this->pages[$i] = $this->pages[$j];
  27126. $this->pagedim[$i] = $this->pagedim[$j];
  27127. $this->pagelen[$i] = $this->pagelen[$j];
  27128. $this->intmrk[$i] = $this->intmrk[$j];
  27129. $this->bordermrk[$i] = $this->bordermrk[$j];
  27130. $this->cntmrk[$i] = $this->cntmrk[$j];
  27131. if (isset($this->footerpos[$j]))
  27132. {
  27133. $this->footerpos[$i] = $this->footerpos[$j];
  27134. }
  27135. elseif (isset($this->footerpos[$i]))
  27136. {
  27137. unset($this->footerpos[$i]);
  27138. }
  27139. if (isset($this->footerlen[$j]))
  27140. {
  27141. $this->footerlen[$i] = $this->footerlen[$j];
  27142. }
  27143. elseif (isset($this->footerlen[$i]))
  27144. {
  27145. unset($this->footerlen[$i]);
  27146. }
  27147. if (isset($this->transfmrk[$j]))
  27148. {
  27149. $this->transfmrk[$i] = $this->transfmrk[$j];
  27150. }
  27151. elseif (isset($this->transfmrk[$i]))
  27152. {
  27153. unset($this->transfmrk[$i]);
  27154. }
  27155. if (isset($this->PageAnnots[$j]))
  27156. {
  27157. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  27158. }
  27159. elseif (isset($this->PageAnnots[$i]))
  27160. {
  27161. unset($this->PageAnnots[$i]);
  27162. }
  27163. if (isset($this->newpagegroup[$j]))
  27164. {
  27165. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  27166. }
  27167. elseif (isset($this->newpagegroup[$i]))
  27168. {
  27169. unset($this->newpagegroup[$i]);
  27170. }
  27171. }
  27172. $this->pages[$topage] = $tmppage;
  27173. $this->pagedim[$topage] = $tmppagedim;
  27174. $this->pagelen[$topage] = $tmppagelen;
  27175. $this->intmrk[$topage] = $tmpintmrk;
  27176. $this->bordermrk[$topage] = $tmpbordermrk;
  27177. $this->cntmrk[$topage] = $tmpcntmrk;
  27178. if (isset($tmpfooterpos))
  27179. {
  27180. $this->footerpos[$topage] = $tmpfooterpos;
  27181. }
  27182. elseif (isset($this->footerpos[$topage]))
  27183. {
  27184. unset($this->footerpos[$topage]);
  27185. }
  27186. if (isset($tmpfooterlen))
  27187. {
  27188. $this->footerlen[$topage] = $tmpfooterlen;
  27189. }
  27190. elseif (isset($this->footerlen[$topage]))
  27191. {
  27192. unset($this->footerlen[$topage]);
  27193. }
  27194. if (isset($tmptransfmrk))
  27195. {
  27196. $this->transfmrk[$topage] = $tmptransfmrk;
  27197. }
  27198. elseif (isset($this->transfmrk[$topage]))
  27199. {
  27200. unset($this->transfmrk[$topage]);
  27201. }
  27202. if (isset($tmpannots))
  27203. {
  27204. $this->PageAnnots[$topage] = $tmpannots;
  27205. }
  27206. elseif (isset($this->PageAnnots[$topage]))
  27207. {
  27208. unset($this->PageAnnots[$topage]);
  27209. }
  27210. if (isset($tmpnewpagegroup))
  27211. {
  27212. $this->newpagegroup[$topage] = $tmpnewpagegroup;
  27213. }
  27214. elseif (isset($this->newpagegroup[$topage]))
  27215. {
  27216. unset($this->newpagegroup[$topage]);
  27217. }
  27218. // adjust outlines
  27219. $tmpoutlines = $this->outlines;
  27220. foreach ($tmpoutlines as $key => $outline)
  27221. {
  27222. if (($outline['p'] >= $topage) and ($outline['p'] < $frompage))
  27223. {
  27224. $this->outlines[$key]['p'] = $outline['p'] + 1;
  27225. }
  27226. elseif ($outline['p'] == $frompage)
  27227. {
  27228. $this->outlines[$key]['p'] = $topage;
  27229. }
  27230. }
  27231. // adjust links
  27232. $tmplinks = $this->links;
  27233. foreach ($tmplinks as $key => $link)
  27234. {
  27235. if (($link[0] >= $topage) and ($link[0] < $frompage))
  27236. {
  27237. $this->links[$key][0] = $link[0] + 1;
  27238. }
  27239. elseif ($link[0] == $frompage)
  27240. {
  27241. $this->links[$key][0] = $topage;
  27242. }
  27243. }
  27244. // adjust javascript
  27245. $tmpjavascript = $this->javascript;
  27246. global $jfrompage, $jtopage;
  27247. $jfrompage = $frompage;
  27248. $jtopage = $topage;
  27249. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', create_function('$matches', 'global $jfrompage, $jtopage;
  27250. $pagenum = intval($matches[3]) + 1;
  27251. if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
  27252. $newpage = ($pagenum + 1);
  27253. } elseif ($pagenum == $jfrompage) {
  27254. $newpage = $jtopage;
  27255. } else {
  27256. $newpage = $pagenum;
  27257. }
  27258. --$newpage;
  27259. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  27260. // return to last page
  27261. $this->lastPage(true);
  27262. return true;
  27263. }
  27264. /**
  27265. * Remove the specified page.
  27266. * @param int $page page to remove
  27267. * @return true in case of success, false in case of error.
  27268. * @access public
  27269. * @since 4.6.004 (2009-04-23)
  27270. */
  27271. public function deletePage($page)
  27272. {
  27273. if (($page < 1) or ($page > $this->numpages))
  27274. {
  27275. return false;
  27276. }
  27277. // delete current page
  27278. unset($this->pages[$page]);
  27279. unset($this->pagedim[$page]);
  27280. unset($this->pagelen[$page]);
  27281. unset($this->intmrk[$page]);
  27282. unset($this->bordermrk[$page]);
  27283. unset($this->cntmrk[$page]);
  27284. if (isset($this->footerpos[$page]))
  27285. {
  27286. unset($this->footerpos[$page]);
  27287. }
  27288. if (isset($this->footerlen[$page]))
  27289. {
  27290. unset($this->footerlen[$page]);
  27291. }
  27292. if (isset($this->transfmrk[$page]))
  27293. {
  27294. unset($this->transfmrk[$page]);
  27295. }
  27296. if (isset($this->PageAnnots[$page]))
  27297. {
  27298. unset($this->PageAnnots[$page]);
  27299. }
  27300. if (isset($this->newpagegroup[$page]))
  27301. {
  27302. unset($this->newpagegroup[$page]);
  27303. }
  27304. if (isset($this->pageopen[$page]))
  27305. {
  27306. unset($this->pageopen[$page]);
  27307. }
  27308. // update remaining pages
  27309. for($i = $page; $i < $this->numpages; ++ $i)
  27310. {
  27311. $j = $i + 1;
  27312. // shift pages
  27313. $this->pages[$i] = $this->pages[$j];
  27314. $this->pagedim[$i] = $this->pagedim[$j];
  27315. $this->pagelen[$i] = $this->pagelen[$j];
  27316. $this->intmrk[$i] = $this->intmrk[$j];
  27317. $this->bordermrk[$i] = $this->bordermrk[$j];
  27318. $this->cntmrk[$i] = $this->cntmrk[$j];
  27319. if (isset($this->footerpos[$j]))
  27320. {
  27321. $this->footerpos[$i] = $this->footerpos[$j];
  27322. }
  27323. elseif (isset($this->footerpos[$i]))
  27324. {
  27325. unset($this->footerpos[$i]);
  27326. }
  27327. if (isset($this->footerlen[$j]))
  27328. {
  27329. $this->footerlen[$i] = $this->footerlen[$j];
  27330. }
  27331. elseif (isset($this->footerlen[$i]))
  27332. {
  27333. unset($this->footerlen[$i]);
  27334. }
  27335. if (isset($this->transfmrk[$j]))
  27336. {
  27337. $this->transfmrk[$i] = $this->transfmrk[$j];
  27338. }
  27339. elseif (isset($this->transfmrk[$i]))
  27340. {
  27341. unset($this->transfmrk[$i]);
  27342. }
  27343. if (isset($this->PageAnnots[$j]))
  27344. {
  27345. $this->PageAnnots[$i] = $this->PageAnnots[$j];
  27346. }
  27347. elseif (isset($this->PageAnnots[$i]))
  27348. {
  27349. unset($this->PageAnnots[$i]);
  27350. }
  27351. if (isset($this->newpagegroup[$j]))
  27352. {
  27353. $this->newpagegroup[$i] = $this->newpagegroup[$j];
  27354. }
  27355. elseif (isset($this->newpagegroup[$i]))
  27356. {
  27357. unset($this->newpagegroup[$i]);
  27358. }
  27359. if (isset($this->pageopen[$j]))
  27360. {
  27361. $this->pageopen[$i] = $this->pageopen[$j];
  27362. }
  27363. elseif (isset($this->pageopen[$i]))
  27364. {
  27365. unset($this->pageopen[$i]);
  27366. }
  27367. }
  27368. // remove last page
  27369. unset($this->pages[$this->numpages]);
  27370. unset($this->pagedim[$this->numpages]);
  27371. unset($this->pagelen[$this->numpages]);
  27372. unset($this->intmrk[$this->numpages]);
  27373. unset($this->bordermrk[$this->numpages]);
  27374. unset($this->cntmrk[$this->numpages]);
  27375. if (isset($this->footerpos[$this->numpages]))
  27376. {
  27377. unset($this->footerpos[$this->numpages]);
  27378. }
  27379. if (isset($this->footerlen[$this->numpages]))
  27380. {
  27381. unset($this->footerlen[$this->numpages]);
  27382. }
  27383. if (isset($this->transfmrk[$this->numpages]))
  27384. {
  27385. unset($this->transfmrk[$this->numpages]);
  27386. }
  27387. if (isset($this->PageAnnots[$this->numpages]))
  27388. {
  27389. unset($this->PageAnnots[$this->numpages]);
  27390. }
  27391. if (isset($this->newpagegroup[$this->numpages]))
  27392. {
  27393. unset($this->newpagegroup[$this->numpages]);
  27394. }
  27395. if (isset($this->pageopen[$this->numpages]))
  27396. {
  27397. unset($this->pageopen[$this->numpages]);
  27398. }
  27399. -- $this->numpages;
  27400. $this->page = $this->numpages;
  27401. // adjust outlines
  27402. $tmpoutlines = $this->outlines;
  27403. foreach ($tmpoutlines as $key => $outline)
  27404. {
  27405. if ($outline['p'] > $page)
  27406. {
  27407. $this->outlines[$key]['p'] = $outline['p'] - 1;
  27408. }
  27409. elseif ($outline['p'] == $page)
  27410. {
  27411. unset($this->outlines[$key]);
  27412. }
  27413. }
  27414. // adjust links
  27415. $tmplinks = $this->links;
  27416. foreach ($tmplinks as $key => $link)
  27417. {
  27418. if ($link[0] > $page)
  27419. {
  27420. $this->links[$key][0] = $link[0] - 1;
  27421. }
  27422. elseif ($link[0] == $page)
  27423. {
  27424. unset($this->links[$key]);
  27425. }
  27426. }
  27427. // adjust javascript
  27428. $tmpjavascript = $this->javascript;
  27429. global $jpage;
  27430. $jpage = $page;
  27431. $this->javascript = preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', create_function('$matches', 'global $jpage;
  27432. $pagenum = intval($matches[3]) + 1;
  27433. if ($pagenum >= $jpage) {
  27434. $newpage = ($pagenum - 1);
  27435. } elseif ($pagenum == $jpage) {
  27436. $newpage = 1;
  27437. } else {
  27438. $newpage = $pagenum;
  27439. }
  27440. --$newpage;
  27441. return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
  27442. // return to last page
  27443. $this->lastPage(true);
  27444. return true;
  27445. }
  27446. /**
  27447. * Clone the specified page to a new page.
  27448. * @param int $page number of page to copy (0 = current page)
  27449. * @return true in case of success, false in case of error.
  27450. * @access public
  27451. * @since 4.9.015 (2010-04-20)
  27452. */
  27453. public function copyPage($page = 0)
  27454. {
  27455. if ($page == 0)
  27456. {
  27457. // default value
  27458. $page = $this->page;
  27459. }
  27460. if (($page < 1) or ($page > $this->numpages))
  27461. {
  27462. return false;
  27463. }
  27464. if ($page == $this->page)
  27465. {
  27466. // close the page before cloning it
  27467. $this->endPage();
  27468. }
  27469. // copy all page-related states
  27470. ++ $this->numpages;
  27471. $this->page = $this->numpages;
  27472. $this->pages[$this->page] = $this->pages[$page];
  27473. $this->pagedim[$this->page] = $this->pagedim[$page];
  27474. $this->pagelen[$this->page] = $this->pagelen[$page];
  27475. $this->intmrk[$this->page] = $this->intmrk[$page];
  27476. $this->bordermrk[$this->page] = $this->bordermrk[$page];
  27477. $this->cntmrk[$this->page] = $this->cntmrk[$page];
  27478. $this->pageopen[$this->page] = false;
  27479. if (isset($this->footerpos[$page]))
  27480. {
  27481. $this->footerpos[$this->page] = $this->footerpos[$page];
  27482. }
  27483. if (isset($this->footerlen[$page]))
  27484. {
  27485. $this->footerlen[$this->page] = $this->footerlen[$page];
  27486. }
  27487. if (isset($this->transfmrk[$page]))
  27488. {
  27489. $this->transfmrk[$this->page] = $this->transfmrk[$page];
  27490. }
  27491. if (isset($this->PageAnnots[$page]))
  27492. {
  27493. $this->PageAnnots[$this->page] = $this->PageAnnots[$page];
  27494. }
  27495. if (isset($this->newpagegroup[$page]))
  27496. {
  27497. $this->newpagegroup[$this->page] = $this->newpagegroup[$page];
  27498. }
  27499. // copy outlines
  27500. $tmpoutlines = $this->outlines;
  27501. foreach ($tmpoutlines as $key => $outline)
  27502. {
  27503. if ($outline['p'] == $page)
  27504. {
  27505. $this->outlines[] = array('t' => $outline['t'], 'l' => $outline['l'], 'y' => $outline['y'],
  27506. 'p' => $this->page);
  27507. }
  27508. }
  27509. // copy links
  27510. $tmplinks = $this->links;
  27511. foreach ($tmplinks as $key => $link)
  27512. {
  27513. if ($link[0] == $page)
  27514. {
  27515. $this->links[] = array($this->page, $link[1]);
  27516. }
  27517. }
  27518. // return to last page
  27519. $this->lastPage(true);
  27520. return true;
  27521. }
  27522. /**
  27523. * Output a Table of Content Index (TOC).
  27524. * Before calling this method you have to open the page using the addTOCPage() method.
  27525. * After calling this method you have to call endTOCPage() to close the TOC page.
  27526. * You can override this method to achieve different styles.
  27527. * @param int $page page number where this TOC should be inserted (leave empty for current page).
  27528. * @param string $numbersfont set the font for page numbers (please use monospaced font for better alignment).
  27529. * @param string $filler string used to fill the space between text and page number.
  27530. * @param string $toc_name name to use for TOC bookmark.
  27531. * @access public
  27532. * @author Nicola Asuni
  27533. * @since 4.5.000 (2009-01-02)
  27534. * @see addTOCPage(), endTOCPage(), addHTMLTOC()
  27535. */
  27536. public function addTOC($page = '', $numbersfont = '', $filler = '.', $toc_name = 'TOC')
  27537. {
  27538. $fontsize = $this->FontSizePt;
  27539. $fontfamily = $this->FontFamily;
  27540. $fontstyle = $this->FontStyle;
  27541. $w = $this->w - $this->lMargin - $this->rMargin;
  27542. $spacer = $this->GetStringWidth(chr(32)) * 4;
  27543. $page_first = $this->getPage();
  27544. $lmargin = $this->lMargin;
  27545. $rmargin = $this->rMargin;
  27546. $x_start = $this->GetX();
  27547. $current_page = $this->page;
  27548. $current_column = $this->current_column;
  27549. if ($this->empty_string($numbersfont))
  27550. {
  27551. $numbersfont = $this->default_monospaced_font;
  27552. }
  27553. if ($this->empty_string($filler))
  27554. {
  27555. $filler = ' ';
  27556. }
  27557. if ($this->empty_string($page))
  27558. {
  27559. $gap = ' ';
  27560. }
  27561. else
  27562. {
  27563. $gap = '';
  27564. if ($page < 1)
  27565. {
  27566. $page = 1;
  27567. }
  27568. }
  27569. foreach ($this->outlines as $key => $outline)
  27570. {
  27571. if ($this->rtl)
  27572. {
  27573. $aligntext = 'R';
  27574. $alignnum = 'L';
  27575. }
  27576. else
  27577. {
  27578. $aligntext = 'L';
  27579. $alignnum = 'R';
  27580. }
  27581. if ($outline['l'] == 0)
  27582. {
  27583. $this->SetFont($fontfamily, $fontstyle . 'B', $fontsize);
  27584. }
  27585. else
  27586. {
  27587. $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']);
  27588. }
  27589. // check for page break
  27590. $this->checkPageBreak(($this->FontSize * $this->cell_height_ratio));
  27591. // set margins and X position
  27592. if (($this->page == $current_page) and ($this->current_column == $current_column))
  27593. {
  27594. $this->lMargin = $lmargin;
  27595. $this->rMargin = $rmargin;
  27596. }
  27597. else
  27598. {
  27599. if ($this->current_column != $current_column)
  27600. {
  27601. if ($this->rtl)
  27602. {
  27603. $x_start = $this->w - $this->columns[$this->current_column]['x'];
  27604. }
  27605. else
  27606. {
  27607. $x_start = $this->columns[$this->current_column]['x'];
  27608. }
  27609. }
  27610. $lmargin = $this->lMargin;
  27611. $rmargin = $this->rMargin;
  27612. $current_page = $this->page;
  27613. $current_column = $this->current_column;
  27614. }
  27615. $this->SetX($x_start);
  27616. $indent = ($spacer * $outline['l']);
  27617. if ($this->rtl)
  27618. {
  27619. $this->rMargin += $indent;
  27620. $this->x -= $indent;
  27621. }
  27622. else
  27623. {
  27624. $this->lMargin += $indent;
  27625. $this->x += $indent;
  27626. }
  27627. $link = $this->AddLink();
  27628. $this->SetLink($link, $outline['y'], $outline['p']);
  27629. // write the text
  27630. $this->Write(0, $outline['t'], $link, 0, $aligntext, false, 0, false, false, 0);
  27631. $this->SetFont($numbersfont, $fontstyle, $fontsize);
  27632. if ($this->empty_string($page))
  27633. {
  27634. $pagenum = $outline['p'];
  27635. }
  27636. else
  27637. {
  27638. // placemark to be replaced with the correct number
  27639. $pagenum = '{#' . ($outline['p']) . '}';
  27640. if ($this->isUnicodeFont())
  27641. {
  27642. $pagenum = '{' . $pagenum . '}';
  27643. }
  27644. }
  27645. $numwidth = $this->GetStringWidth($pagenum);
  27646. if ($this->rtl)
  27647. {
  27648. $tw = $this->x - $this->lMargin;
  27649. }
  27650. else
  27651. {
  27652. $tw = $this->w - $this->rMargin - $this->x;
  27653. }
  27654. $fw = $tw - $numwidth - $this->GetStringWidth(chr(32));
  27655. $numfills = floor($fw / $this->GetStringWidth($filler));
  27656. if ($numfills > 0)
  27657. {
  27658. $rowfill = str_repeat($filler, $numfills);
  27659. }
  27660. else
  27661. {
  27662. $rowfill = '';
  27663. }
  27664. if ($this->rtl)
  27665. {
  27666. $pagenum = $pagenum . $gap . $rowfill . ' ';
  27667. }
  27668. else
  27669. {
  27670. $pagenum = ' ' . $rowfill . $gap . $pagenum;
  27671. }
  27672. // write the number
  27673. $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
  27674. }
  27675. $page_last = $this->getPage();
  27676. $numpages = $page_last - $page_first + 1;
  27677. if (! $this->empty_string($page))
  27678. {
  27679. for($p = $page_first; $p <= $page_last; ++ $p)
  27680. {
  27681. // get page data
  27682. $temppage = $this->getPageBuffer($p);
  27683. for($n = 1; $n <= $this->numpages; ++ $n)
  27684. {
  27685. // update page numbers
  27686. $k = '{#' . $n . '}';
  27687. $ku = '{' . $k . '}';
  27688. $alias_a = $this->_escape($k);
  27689. $alias_au = $this->_escape($ku);
  27690. if ($this->isunicode)
  27691. {
  27692. $alias_b = $this->_escape($this->UTF8ToLatin1($k));
  27693. $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
  27694. $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  27695. $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl));
  27696. }
  27697. if ($n >= $page)
  27698. {
  27699. $np = $n + $numpages;
  27700. }
  27701. else
  27702. {
  27703. $np = $n;
  27704. }
  27705. $ns = $this->formatTOCPageNumber($np);
  27706. $nu = $ns;
  27707. $sdiff = strlen($k) - strlen($ns) - 1;
  27708. $sdiffu = strlen($ku) - strlen($ns) - 1;
  27709. $sfill = str_repeat($filler, $sdiff);
  27710. $sfillu = str_repeat($filler, $sdiffu);
  27711. if ($this->rtl)
  27712. {
  27713. $ns = $ns . ' ' . $sfill;
  27714. $nu = $nu . ' ' . $sfillu;
  27715. }
  27716. else
  27717. {
  27718. $ns = $sfill . ' ' . $ns;
  27719. $nu = $sfillu . ' ' . $nu;
  27720. }
  27721. $nu = $this->UTF8ToUTF16BE($nu, false);
  27722. $temppage = str_replace($alias_au, $nu, $temppage);
  27723. if ($this->isunicode)
  27724. {
  27725. $temppage = str_replace($alias_bu, $nu, $temppage);
  27726. $temppage = str_replace($alias_cu, $nu, $temppage);
  27727. $temppage = str_replace($alias_b, $ns, $temppage);
  27728. $temppage = str_replace($alias_c, $ns, $temppage);
  27729. }
  27730. $temppage = str_replace($alias_a, $ns, $temppage);
  27731. }
  27732. // save changes
  27733. $this->setPageBuffer($p, $temppage);
  27734. }
  27735. // move pages
  27736. $this->Bookmark($toc_name, 0, 0, $page_first);
  27737. for($i = 0; $i < $numpages; ++ $i)
  27738. {
  27739. $this->movePage($page_last, $page);
  27740. }
  27741. }
  27742. }
  27743. /**
  27744. * Output a Table Of Content Index (TOC) using HTML templates.
  27745. * Before calling this method you have to open the page using the addTOCPage() method.
  27746. * After calling this method you have to call endTOCPage() to close the TOC page.
  27747. * @param int $page page number where this TOC should be inserted (leave empty for current page).
  27748. * @param string $toc_name name to use for TOC bookmark.
  27749. * @param array $templates array of html templates. Use: #TOC_DESCRIPTION# for bookmark title, #TOC_PAGE_NUMBER# for page number.
  27750. * @param boolean $correct_align if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
  27751. * @access public
  27752. * @author Nicola Asuni
  27753. * @since 5.0.001 (2010-05-06)
  27754. * @see addTOCPage(), endTOCPage(), addTOC()
  27755. */
  27756. public function addHTMLTOC($page = '', $toc_name = 'TOC', $templates = array(), $correct_align = true)
  27757. {
  27758. $prev_htmlLinkColorArray = $this->htmlLinkColorArray;
  27759. $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle;
  27760. // set new style for link
  27761. $this->htmlLinkColorArray = array();
  27762. $this->htmlLinkFontStyle = '';
  27763. $page_first = $this->getPage();
  27764. // get the font type used for numbers in each template
  27765. $current_font = $this->FontFamily;
  27766. foreach ($templates as $level => $html)
  27767. {
  27768. $dom = $this->getHtmlDomArray($html);
  27769. foreach ($dom as $key => $value)
  27770. {
  27771. if ($value['value'] == '#TOC_PAGE_NUMBER#')
  27772. {
  27773. $this->SetFont($dom[($key - 1)]['fontname']);
  27774. $templates['F' . $level] = $this->isUnicodeFont();
  27775. }
  27776. }
  27777. }
  27778. $this->SetFont($current_font);
  27779. foreach ($this->outlines as $key => $outline)
  27780. {
  27781. // get HTML template
  27782. $row = $templates[$outline['l']];
  27783. if ($this->empty_string($page))
  27784. {
  27785. $pagenum = $outline['p'];
  27786. }
  27787. else
  27788. {
  27789. // placemark to be replaced with the correct number
  27790. $pagenum = '{#' . ($outline['p']) . '}';
  27791. if ($templates['F' . $outline['l']])
  27792. {
  27793. $pagenum = '{' . $pagenum . '}';
  27794. }
  27795. }
  27796. // replace templates with current values
  27797. $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
  27798. $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
  27799. // add link to page
  27800. $row = '<a href="#' . $outline['p'] . ',' . $outline['y'] . '">' . $row . '</a>';
  27801. // write bookmark entry
  27802. $this->writeHTML($row, false, false, true, false, '');
  27803. }
  27804. // restore link styles
  27805. $this->htmlLinkColorArray = $prev_htmlLinkColorArray;
  27806. $this->htmlLinkFontStyle = $prev_htmlLinkFontStyle;
  27807. // move TOC page and replace numbers
  27808. $page_last = $this->getPage();
  27809. $numpages = $page_last - $page_first + 1;
  27810. if (! $this->empty_string($page))
  27811. {
  27812. for($p = $page_first; $p <= $page_last; ++ $p)
  27813. {
  27814. // get page data
  27815. $temppage = $this->getPageBuffer($p);
  27816. for($n = 1; $n <= $this->numpages; ++ $n)
  27817. {
  27818. // update page numbers
  27819. $k = '{#' . $n . '}';
  27820. $ku = '{' . $k . '}';
  27821. $alias_a = $this->_escape($k);
  27822. $alias_au = $this->_escape('{' . $k . '}');
  27823. if ($this->isunicode)
  27824. {
  27825. $alias_b = $this->_escape($this->UTF8ToLatin1($k));
  27826. $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
  27827. $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl));
  27828. $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl));
  27829. }
  27830. if ($n >= $page)
  27831. {
  27832. $np = $n + $numpages;
  27833. }
  27834. else
  27835. {
  27836. $np = $n;
  27837. }
  27838. $ns = $this->formatTOCPageNumber($np);
  27839. $nu = $ns;
  27840. if ($correct_align)
  27841. {
  27842. $sdiff = strlen($k) - strlen($ns);
  27843. $sdiffu = strlen($ku) - strlen($ns);
  27844. $sfill = str_repeat(' ', $sdiff);
  27845. $sfillu = str_repeat(' ', $sdiffu);
  27846. if ($this->rtl)
  27847. {
  27848. $ns = $ns . $sfill;
  27849. $nu = $nu . $sfillu;
  27850. }
  27851. else
  27852. {
  27853. $ns = $sfill . $ns;
  27854. $nu = $sfillu . $nu;
  27855. }
  27856. }
  27857. $nu = $this->UTF8ToUTF16BE($nu, false);
  27858. $temppage = str_replace($alias_au, $nu, $temppage);
  27859. if ($this->isunicode)
  27860. {
  27861. $temppage = str_replace($alias_bu, $nu, $temppage);
  27862. $temppage = str_replace($alias_cu, $nu, $temppage);
  27863. $temppage = str_replace($alias_b, $ns, $temppage);
  27864. $temppage = str_replace($alias_c, $ns, $temppage);
  27865. }
  27866. $temppage = str_replace($alias_a, $ns, $temppage);
  27867. }
  27868. // save changes
  27869. $this->setPageBuffer($p, $temppage);
  27870. }
  27871. // move pages
  27872. $this->Bookmark($toc_name, 0, 0, $page_first);
  27873. for($i = 0; $i < $numpages; ++ $i)
  27874. {
  27875. $this->movePage($page_last, $page);
  27876. }
  27877. }
  27878. }
  27879. /**
  27880. * Stores a copy of the current TCPDF object used for undo operation.
  27881. * @access public
  27882. * @since 4.5.029 (2009-03-19)
  27883. */
  27884. public function startTransaction()
  27885. {
  27886. if (isset($this->objcopy))
  27887. {
  27888. // remove previous copy
  27889. $this->commitTransaction();
  27890. }
  27891. // record current page number and Y position
  27892. $this->start_transaction_page = $this->page;
  27893. $this->start_transaction_y = $this->y;
  27894. // clone current object
  27895. $this->objcopy = $this->objclone($this);
  27896. }
  27897. /**
  27898. * Delete the copy of the current TCPDF object used for undo operation.
  27899. * @access public
  27900. * @since 4.5.029 (2009-03-19)
  27901. */
  27902. public function commitTransaction()
  27903. {
  27904. if (isset($this->objcopy))
  27905. {
  27906. $this->objcopy->_destroy(true, true);
  27907. unset($this->objcopy);
  27908. }
  27909. }
  27910. /**
  27911. * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
  27912. * @param boolean $self if true restores current class object to previous state without the need of reassignment via the returned value.
  27913. * @return TCPDF object.
  27914. * @access public
  27915. * @since 4.5.029 (2009-03-19)
  27916. */
  27917. public function rollbackTransaction($self = false)
  27918. {
  27919. if (isset($this->objcopy))
  27920. {
  27921. if (isset($this->objcopy->diskcache) and $this->objcopy->diskcache)
  27922. {
  27923. // truncate files to previous values
  27924. foreach ($this->objcopy->cache_file_length as $file => $length)
  27925. {
  27926. $file = substr($file, 1);
  27927. $handle = fopen($file, 'r+');
  27928. ftruncate($handle, $length);
  27929. }
  27930. }
  27931. $this->_destroy(true, true);
  27932. if ($self)
  27933. {
  27934. $objvars = get_object_vars($this->objcopy);
  27935. foreach ($objvars as $key => $value)
  27936. {
  27937. $this->$key = $value;
  27938. }
  27939. }
  27940. return $this->objcopy;
  27941. }
  27942. return $this;
  27943. }
  27944. /**
  27945. * Creates a copy of a class object
  27946. * @param object $object class object to be cloned
  27947. * @return cloned object
  27948. * @access public
  27949. * @since 4.5.029 (2009-03-19)
  27950. */
  27951. public function objclone($object)
  27952. {
  27953. return @clone ($object);
  27954. }
  27955. /**
  27956. * Determine whether a string is empty.
  27957. * @param string $str string to be checked
  27958. * @return boolean true if string is empty
  27959. * @access public
  27960. * @since 4.5.044 (2009-04-16)
  27961. */
  27962. public function empty_string($str)
  27963. {
  27964. return (is_null($str) or (is_string($str) and (strlen($str) == 0)));
  27965. }
  27966. /**
  27967. * Find position of last occurrence of a substring in a string
  27968. * @param string $haystack The string to search in.
  27969. * @param string $needle substring to search.
  27970. * @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
  27971. * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
  27972. * @access public
  27973. * @since 4.8.038 (2010-03-13)
  27974. */
  27975. public function revstrpos($haystack, $needle, $offset = 0)
  27976. {
  27977. $length = strlen($haystack);
  27978. $offset = ($offset > 0) ? ($length - $offset) : abs($offset);
  27979. $pos = strpos(strrev($haystack), strrev($needle), $offset);
  27980. return ($pos === false) ? false : ($length - $pos - strlen($needle));
  27981. }
  27982. // --- MULTI COLUMNS METHODS -----------------------
  27983. /**
  27984. * Set multiple columns of the same size
  27985. * @param int $numcols number of columns (set to zero to disable columns mode)
  27986. * @param int $width column width
  27987. * @param int $y column starting Y position (leave empty for current Y position)
  27988. * @access public
  27989. * @since 4.9.001 (2010-03-28)
  27990. */
  27991. public function setEqualColumns($numcols = 0, $width = 0, $y = '')
  27992. {
  27993. $this->columns = array();
  27994. if ($numcols < 2)
  27995. {
  27996. $numcols = 0;
  27997. $this->columns = array();
  27998. }
  27999. else
  28000. {
  28001. // maximum column width
  28002. $maxwidth = ($this->w - $this->original_lMargin - $this->original_rMargin) / $numcols;
  28003. if (($width == 0) or ($width > $maxwidth))
  28004. {
  28005. $width = $maxwidth;
  28006. }
  28007. if ($this->empty_string($y))
  28008. {
  28009. $y = $this->y;
  28010. }
  28011. // space between columns
  28012. $space = (($this->w - $this->original_lMargin - $this->original_rMargin - ($numcols * $width)) / ($numcols - 1));
  28013. // fill the columns array (with, space, starting Y position)
  28014. for($i = 0; $i < $numcols; ++ $i)
  28015. {
  28016. $this->columns[$i] = array('w' => $width, 's' => $space, 'y' => $y);
  28017. }
  28018. }
  28019. $this->num_columns = $numcols;
  28020. $this->current_column = 0;
  28021. $this->column_start_page = $this->page;
  28022. }
  28023. /**
  28024. * Set columns array.
  28025. * Each column is represented by and array with the following keys: (w = width, s = space between columns, y = column top position).
  28026. * @param array $columns
  28027. * @access public
  28028. * @since 4.9.001 (2010-03-28)
  28029. */
  28030. public function setColumnsArray($columns)
  28031. {
  28032. $this->columns = $columns;
  28033. $this->num_columns = count($columns);
  28034. $this->current_column = 0;
  28035. $this->column_start_page = $this->page;
  28036. }
  28037. /**
  28038. * Set position at a given column
  28039. * @param int $col column number (from 0 to getNumberOfColumns()-1); empty string = current column.
  28040. * @access public
  28041. * @since 4.9.001 (2010-03-28)
  28042. */
  28043. public function selectColumn($col = '')
  28044. {
  28045. if (is_string($col))
  28046. {
  28047. $col = $this->current_column;
  28048. }
  28049. elseif ($col >= $this->num_columns)
  28050. {
  28051. $col = 0;
  28052. }
  28053. $xshift = 0;
  28054. $enable_thead = false;
  28055. if ($this->num_columns > 1)
  28056. {
  28057. if ($col != $this->current_column)
  28058. {
  28059. // move Y pointer at the top of the column
  28060. if ($this->column_start_page == $this->page)
  28061. {
  28062. $this->y = $this->columns[$col]['y'];
  28063. }
  28064. else
  28065. {
  28066. $this->y = $this->tMargin;
  28067. }
  28068. // Avoid to write table headers more than once
  28069. if (($this->page > $this->maxselcol['page']) or (($this->page == $this->maxselcol['page']) and ($col > $this->maxselcol['column'])))
  28070. {
  28071. $enable_thead = true;
  28072. $this->maxselcol['page'] = $this->page;
  28073. $this->maxselcol['column'] = $col;
  28074. }
  28075. }
  28076. $xshift = $this->colxshift;
  28077. // set X position of the current column by case
  28078. $listindent = ($this->listindentlevel * $this->listindent);
  28079. $colpos = ($col * ($this->columns[$col]['w'] + $this->columns[$col]['s']));
  28080. if ($this->rtl)
  28081. {
  28082. $x = $this->w - $this->original_rMargin - $colpos;
  28083. $this->rMargin = ($this->w - $x + $listindent);
  28084. $this->lMargin = ($x - $this->columns[$col]['w']);
  28085. $this->x = $x - $listindent;
  28086. }
  28087. else
  28088. {
  28089. $x = $this->original_lMargin + $colpos;
  28090. $this->lMargin = ($x + $listindent);
  28091. $this->rMargin = ($this->w - $x - $this->columns[$col]['w']);
  28092. $this->x = $x + $listindent;
  28093. }
  28094. $this->columns[$col]['x'] = $x;
  28095. }
  28096. $this->current_column = $col;
  28097. // fix for HTML mode
  28098. $this->newline = true;
  28099. // print HTML table header (if any)
  28100. if ((! $this->empty_string($this->thead)) and (! $this->inthead))
  28101. {
  28102. if ($enable_thead)
  28103. {
  28104. // print table header
  28105. $this->writeHTML($this->thead, false, false, false, false, '');
  28106. $this->y += $xshift['s'];
  28107. // store end of header position
  28108. if (! isset($this->columns[$col]['th']))
  28109. {
  28110. $this->columns[$col]['th'] = array();
  28111. }
  28112. $this->columns[$col]['th']['\'' . $this->page . '\''] = $this->y;
  28113. $this->lasth = 0;
  28114. }
  28115. elseif (isset($this->columns[$col]['th']['\'' . $this->page . '\'']))
  28116. {
  28117. $this->y = $this->columns[$col]['th']['\'' . $this->page . '\''];
  28118. }
  28119. }
  28120. // account for an html table cell over multiple columns
  28121. if ($this->rtl)
  28122. {
  28123. $this->rMargin += $xshift['x'];
  28124. $this->x -= ($xshift['x'] + $xshift['p']);
  28125. }
  28126. else
  28127. {
  28128. $this->lMargin += $xshift['x'];
  28129. $this->x += $xshift['x'] + $xshift['p'];
  28130. }
  28131. }
  28132. /**
  28133. * Return the current column number
  28134. * @return int current column number
  28135. * @access public
  28136. * @since 5.5.011 (2010-07-08)
  28137. */
  28138. public function getColumn()
  28139. {
  28140. return $this->current_column;
  28141. }
  28142. /**
  28143. * Return the current number of columns.
  28144. * @return int number of columns
  28145. * @access public
  28146. * @since 5.8.018 (2010-08-25)
  28147. */
  28148. public function getNumberOfColumns()
  28149. {
  28150. return $this->num_columns;
  28151. }
  28152. /**
  28153. * Serialize an array of parameters to be used with TCPDF tag in HTML code.
  28154. * @param array $pararray parameters array
  28155. * @return sting containing serialized data
  28156. * @access public
  28157. * @since 4.9.006 (2010-04-02)
  28158. */
  28159. public function serializeTCPDFtagParameters($pararray)
  28160. {
  28161. return urlencode(serialize($pararray));
  28162. }
  28163. /**
  28164. * Set Text rendering mode.
  28165. * @param int $stroke outline size in user units (0 = disable).
  28166. * @param boolean $fill if true fills the text (default).
  28167. * @param boolean $clip if true activate clipping mode
  28168. * @access public
  28169. * @since 4.9.008 (2009-04-02)
  28170. */
  28171. public function setTextRenderingMode($stroke = 0, $fill = true, $clip = false)
  28172. {
  28173. // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
  28174. // convert text rendering parameters
  28175. if ($stroke < 0)
  28176. {
  28177. $stroke = 0;
  28178. }
  28179. if ($fill === true)
  28180. {
  28181. if ($stroke > 0)
  28182. {
  28183. if ($clip === true)
  28184. {
  28185. // Fill, then stroke text and add to path for clipping
  28186. $textrendermode = 6;
  28187. }
  28188. else
  28189. {
  28190. // Fill, then stroke text
  28191. $textrendermode = 2;
  28192. }
  28193. $textstrokewidth = $stroke;
  28194. }
  28195. else
  28196. {
  28197. if ($clip === true)
  28198. {
  28199. // Fill text and add to path for clipping
  28200. $textrendermode = 4;
  28201. }
  28202. else
  28203. {
  28204. // Fill text
  28205. $textrendermode = 0;
  28206. }
  28207. }
  28208. }
  28209. else
  28210. {
  28211. if ($stroke > 0)
  28212. {
  28213. if ($clip === true)
  28214. {
  28215. // Stroke text and add to path for clipping
  28216. $textrendermode = 5;
  28217. }
  28218. else
  28219. {
  28220. // Stroke text
  28221. $textrendermode = 1;
  28222. }
  28223. $textstrokewidth = $stroke;
  28224. }
  28225. else
  28226. {
  28227. if ($clip === true)
  28228. {
  28229. // Add text to path for clipping
  28230. $textrendermode = 7;
  28231. }
  28232. else
  28233. {
  28234. // Neither fill nor stroke text (invisible)
  28235. $textrendermode = 3;
  28236. }
  28237. }
  28238. }
  28239. $this->textrendermode = $textrendermode;
  28240. $this->textstrokewidth = $stroke * $this->k;
  28241. }
  28242. /**
  28243. * Returns an array of chars containing soft hyphens.
  28244. * @param array $word array of chars
  28245. * @param array $patterns Array of hypenation patterns.
  28246. * @param array $dictionary Array of words to be returned without applying the hyphenation algoritm.
  28247. * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  28248. * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  28249. * @param int $charmin Minimum word lenght to apply the hyphenation algoritm.
  28250. * @param int $charmax Maximum lenght of broken piece of word.
  28251. * @return array text with soft hyphens
  28252. * @author Nicola Asuni
  28253. * @since 4.9.012 (2010-04-12)
  28254. * @access protected
  28255. */
  28256. protected function hyphenateWord($word, $patterns, $dictionary = array(), $leftmin = 1, $rightmin = 2, $charmin = 1, $charmax = 8)
  28257. {
  28258. $hyphenword = array(); // hyphens positions
  28259. $numchars = count($word);
  28260. if ($numchars <= $charmin)
  28261. {
  28262. return $word;
  28263. }
  28264. $word_string = $this->UTF8ArrSubString($word);
  28265. // some words will be returned as-is
  28266. $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})(\]?)$/';
  28267. if (preg_match($pattern, $word_string) > 0)
  28268. {
  28269. // email
  28270. return $word;
  28271. }
  28272. $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})(\]?)$/';
  28273. if (preg_match($pattern, $word_string) > 0)
  28274. {
  28275. // URL
  28276. return $word;
  28277. }
  28278. if (isset($dictionary[$word_string]))
  28279. {
  28280. return $this->UTF8StringToArray($dictionary[$word_string]);
  28281. }
  28282. // suround word with '_' characters
  28283. $tmpword = array_merge(array(95), $word, array(95));
  28284. $tmpnumchars = $numchars + 2;
  28285. $maxpos = $tmpnumchars - $charmin;
  28286. for($pos = 0; $pos < $maxpos; ++ $pos)
  28287. {
  28288. $imax = min(($tmpnumchars - $pos), $charmax);
  28289. for($i = $charmin; $i <= $imax; ++ $i)
  28290. {
  28291. $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos + $i));
  28292. if (isset($patterns[$subword]))
  28293. {
  28294. $pattern = $this->UTF8StringToArray($patterns[$subword]);
  28295. $pattern_length = count($pattern);
  28296. $digits = 1;
  28297. for($j = 0; $j < $pattern_length; ++ $j)
  28298. {
  28299. // check if $pattern[$j] is a number
  28300. if (($pattern[$j] >= 48) and ($pattern[$j] <= 57))
  28301. {
  28302. if ($j == 0)
  28303. {
  28304. $zero = $pos - 1;
  28305. }
  28306. else
  28307. {
  28308. $zero = $pos + $j - $digits;
  28309. }
  28310. if (! isset($hyphenword[$zero]) or ($hyphenword[$zero] != $pattern[$j]))
  28311. {
  28312. $hyphenword[$zero] = $this->unichr($pattern[$j]);
  28313. }
  28314. ++ $digits;
  28315. }
  28316. }
  28317. }
  28318. }
  28319. }
  28320. $inserted = 0;
  28321. $maxpos = $numchars - $rightmin;
  28322. for($i = $leftmin; $i <= $maxpos; ++ $i)
  28323. {
  28324. if (isset($hyphenword[$i]) and (($hyphenword[$i] % 2) != 0))
  28325. {
  28326. // 173 = soft hyphen character
  28327. array_splice($word, $i + $inserted, 0, 173);
  28328. ++ $inserted;
  28329. }
  28330. }
  28331. return $word;
  28332. }
  28333. /**
  28334. * Returns an array of hyphenation patterns.
  28335. * @param string $file TEX file containing hypenation patterns. TEX pattrns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  28336. * @return array of hyphenation patterns
  28337. * @author Nicola Asuni
  28338. * @since 4.9.012 (2010-04-12)
  28339. * @access public
  28340. */
  28341. public function getHyphenPatternsFromTEX($file)
  28342. {
  28343. // TEX patterns are available at:
  28344. // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  28345. $data = file_get_contents($file);
  28346. $patterns = array();
  28347. // remove comments
  28348. $data = preg_replace('/\%[^\n]*/', '', $data);
  28349. // extract the patterns part
  28350. preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
  28351. $data = trim(substr($matches[0], 10, - 1));
  28352. // extract each pattern
  28353. $patterns_array = preg_split('/[\s]+/', $data);
  28354. // create new language array of patterns
  28355. $patterns = array();
  28356. foreach ($patterns_array as $val)
  28357. {
  28358. if (! $this->empty_string($val))
  28359. {
  28360. $val = trim($val);
  28361. $val = str_replace('\'', '\\\'', $val);
  28362. $key = preg_replace('/[0-9]+/', '', $val);
  28363. $patterns[$key] = $val;
  28364. }
  28365. }
  28366. return $patterns;
  28367. }
  28368. /**
  28369. * Returns text with soft hyphens.
  28370. * @param string $text text to process
  28371. * @param mixed $patterns Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  28372. * @param array $dictionary Array of words to be returned without applying the hyphenation algoritm.
  28373. * @param int $leftmin Minimum number of character to leave on the left of the word without applying the hyphens.
  28374. * @param int $rightmin Minimum number of character to leave on the right of the word without applying the hyphens.
  28375. * @param int $charmin Minimum word lenght to apply the hyphenation algoritm.
  28376. * @param int $charmax Maximum lenght of broken piece of word.
  28377. * @return array text with soft hyphens
  28378. * @author Nicola Asuni
  28379. * @since 4.9.012 (2010-04-12)
  28380. * @access public
  28381. */
  28382. public function hyphenateText($text, $patterns, $dictionary = array(), $leftmin = 1, $rightmin = 2, $charmin = 1, $charmax = 8)
  28383. {
  28384. $text = $this->unhtmlentities($text);
  28385. $word = array(); // last word
  28386. $txtarr = array(); // text to be returned
  28387. $intag = false; // true if we are inside an HTML tag
  28388. if (! is_array($patterns))
  28389. {
  28390. $patterns = $this->getHyphenPatternsFromTEX($patterns);
  28391. }
  28392. // get array of characters
  28393. $unichars = $this->UTF8StringToArray($text);
  28394. // for each char
  28395. foreach ($unichars as $char)
  28396. {
  28397. if ((! $intag) and $this->unicode->uni_type[$char] == 'L')
  28398. {
  28399. // letter character
  28400. $word[] = $char;
  28401. }
  28402. else
  28403. {
  28404. // other type of character
  28405. if (! $this->empty_string($word))
  28406. {
  28407. // hypenate the word
  28408. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  28409. $word = array();
  28410. }
  28411. $txtarr[] = $char;
  28412. if (chr($char) == '<')
  28413. {
  28414. // we are inside an HTML tag
  28415. $intag = true;
  28416. }
  28417. elseif ($intag and (chr($char) == '>'))
  28418. {
  28419. // end of HTML tag
  28420. $intag = false;
  28421. }
  28422. }
  28423. }
  28424. if (! $this->empty_string($word))
  28425. {
  28426. // hypenate the word
  28427. $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
  28428. }
  28429. // convert char array to string and return
  28430. return $this->UTF8ArrSubString($txtarr);
  28431. }
  28432. /**
  28433. * Enable/disable rasterization of vector images using ImageMagick library.
  28434. * @param boolean $mode if true enable rasterization, false otherwise.
  28435. * @access public
  28436. * @since 5.0.000 (2010-04-27)
  28437. */
  28438. public function setRasterizeVectorImages($mode)
  28439. {
  28440. $this->rasterize_vector_images = $mode;
  28441. }
  28442. /**
  28443. * Get the Path-Painting Operators.
  28444. * @param string $style Style of rendering. Possible values are:
  28445. * <ul>
  28446. * <li>S or D: Stroke the path.</li>
  28447. * <li>s or d: Close and stroke the path.</li>
  28448. * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
  28449. * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
  28450. * <li>B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  28451. * <li>B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  28452. * <li>b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  28453. * <li>b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  28454. * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
  28455. * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
  28456. * <li>n: End the path object without filling or stroking it.</li>
  28457. * </ul>
  28458. * @param string $default default style
  28459. * @param boolean $mode if true enable rasterization, false otherwise.
  28460. * @author Nicola Asuni
  28461. * @access protected
  28462. * @since 5.0.000 (2010-04-30)
  28463. */
  28464. protected function getPathPaintOperator($style, $default = 'S')
  28465. {
  28466. $op = '';
  28467. switch ($style)
  28468. {
  28469. case 'S' :
  28470. case 'D' :
  28471. {
  28472. $op = 'S';
  28473. break;
  28474. }
  28475. case 's' :
  28476. case 'd' :
  28477. {
  28478. $op = 's';
  28479. break;
  28480. }
  28481. case 'f' :
  28482. case 'F' :
  28483. {
  28484. $op = 'f';
  28485. break;
  28486. }
  28487. case 'f*' :
  28488. case 'F*' :
  28489. {
  28490. $op = 'f*';
  28491. break;
  28492. }
  28493. case 'B' :
  28494. case 'FD' :
  28495. case 'DF' :
  28496. {
  28497. $op = 'B';
  28498. break;
  28499. }
  28500. case 'B*' :
  28501. case 'F*D' :
  28502. case 'DF*' :
  28503. {
  28504. $op = 'B*';
  28505. break;
  28506. }
  28507. case 'b' :
  28508. case 'fd' :
  28509. case 'df' :
  28510. {
  28511. $op = 'b';
  28512. break;
  28513. }
  28514. case 'b*' :
  28515. case 'f*d' :
  28516. case 'df*' :
  28517. {
  28518. $op = 'b*';
  28519. break;
  28520. }
  28521. case 'CNZ' :
  28522. {
  28523. $op = 'W n';
  28524. break;
  28525. }
  28526. case 'CEO' :
  28527. {
  28528. $op = 'W* n';
  28529. break;
  28530. }
  28531. case 'n' :
  28532. {
  28533. $op = 'n';
  28534. break;
  28535. }
  28536. default :
  28537. {
  28538. if (! empty($default))
  28539. {
  28540. $op = $this->getPathPaintOperator($default, '');
  28541. }
  28542. else
  28543. {
  28544. $op = '';
  28545. }
  28546. }
  28547. }
  28548. return $op;
  28549. }
  28550. /**
  28551. * Enable or disable default option for font subsetting.
  28552. * @param boolean $enable if true enable font subsetting by default.
  28553. * @author Nicola Asuni
  28554. * @access public
  28555. * @since 5.3.002 (2010-06-07)
  28556. */
  28557. public function setFontSubsetting($enable = true)
  28558. {
  28559. $this->font_subsetting = $enable ? true : false;
  28560. }
  28561. /**
  28562. * Return the default option for font subsetting.
  28563. * @return boolean default font subsetting state.
  28564. * @author Nicola Asuni
  28565. * @access public
  28566. * @since 5.3.002 (2010-06-07)
  28567. */
  28568. public function getFontSubsetting()
  28569. {
  28570. return $this->font_subsetting;
  28571. }
  28572. /**
  28573. * Left trim the input string
  28574. * @param string $str string to trim
  28575. * @param string $replace string that replace spaces.
  28576. * @return left trimmed string
  28577. * @author Nicola Asuni
  28578. * @access public
  28579. * @since 5.8.000 (2010-08-11)
  28580. */
  28581. public function stringLeftTrim($str, $replace = '')
  28582. {
  28583. return preg_replace('/^' . $this->re_space['p'] . '+/' . $this->re_space['m'], $replace, $str);
  28584. }
  28585. /**
  28586. * Right trim the input string
  28587. * @param string $str string to trim
  28588. * @param string $replace string that replace spaces.
  28589. * @return right trimmed string
  28590. * @author Nicola Asuni
  28591. * @access public
  28592. * @since 5.8.000 (2010-08-11)
  28593. */
  28594. public function stringRightTrim($str, $replace = '')
  28595. {
  28596. return preg_replace('/' . $this->re_space['p'] . '+$/' . $this->re_space['m'], $replace, $str);
  28597. }
  28598. /**
  28599. * Trim the input string
  28600. * @param string $str string to trim
  28601. * @param string $replace string that replace spaces.
  28602. * @return trimmed string
  28603. * @author Nicola Asuni
  28604. * @access public
  28605. * @since 5.8.000 (2010-08-11)
  28606. */
  28607. public function stringTrim($str, $replace = '')
  28608. {
  28609. $str = $this->stringLeftTrim($str, $replace);
  28610. $str = $this->stringRightTrim($str, $replace);
  28611. return $str;
  28612. }
  28613. /**
  28614. * Return true if the current font is unicode type.
  28615. * @return true for unicode font, false otherwise.
  28616. * @author Nicola Asuni
  28617. * @access public
  28618. * @since 5.8.002 (2010-08-14)
  28619. */
  28620. public function isUnicodeFont()
  28621. {
  28622. return (($this->CurrentFont['type'] == 'TrueTypeUnicode') or ($this->CurrentFont['type'] == 'cidfont0'));
  28623. }
  28624. /**
  28625. * Return normalized font name
  28626. * @param string $fontfamily property string containing font family names
  28627. * @return string normalized font name
  28628. * @author Nicola Asuni
  28629. * @access public
  28630. * @since 5.8.004 (2010-08-17)
  28631. */
  28632. public function getFontFamilyName($fontfamily)
  28633. {
  28634. // remove spaces and symbols
  28635. $fontfamily = preg_replace('/[^a-z0-9\,]/', '', strtolower($fontfamily));
  28636. // extract all font names
  28637. $fontslist = preg_split('/[,]/', $fontfamily);
  28638. // find first valid font name
  28639. foreach ($fontslist as $font)
  28640. {
  28641. // replace font variations
  28642. $font = preg_replace('/italic$/', 'I', $font);
  28643. $font = preg_replace('/oblique$/', 'I', $font);
  28644. $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
  28645. // replace common family names and core fonts
  28646. $pattern = array();
  28647. $replacement = array();
  28648. $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
  28649. $replacement[] = 'times';
  28650. $pattern[] = '/^sansserif/';
  28651. $replacement[] = 'helvetica';
  28652. $pattern[] = '/^monospace/';
  28653. $replacement[] = 'courier';
  28654. $font = preg_replace($pattern, $replacement, $font);
  28655. if (in_array(strtolower($font), $this->fontlist) or in_array($font, $this->fontkeys))
  28656. {
  28657. return $font;
  28658. }
  28659. }
  28660. // return current font as default
  28661. return $this->CurrentFont['fontkey'];
  28662. }
  28663. /**
  28664. * Start a new XObject Template.
  28665. * 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).
  28666. * 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.
  28667. * Note: X,Y coordinates will be reset to 0,0.
  28668. * @param int $w Template width in user units (empty string or zero = page width less margins)
  28669. * @param int $h Template height in user units (empty string or zero = page height less margins)
  28670. * @return int the XObject Template ID in case of success or false in case of error.
  28671. * @author Nicola Asuni
  28672. * @access public
  28673. * @since 5.8.017 (2010-08-24)
  28674. * @see endTemplate(), printTemplate()
  28675. */
  28676. public function startTemplate($w = 0, $h = 0)
  28677. {
  28678. if ($this->inxobj)
  28679. {
  28680. // we are already inside an XObject template
  28681. return false;
  28682. }
  28683. $this->inxobj = true;
  28684. ++ $this->n;
  28685. // XObject ID
  28686. $this->xobjid = 'XT' . $this->n;
  28687. // object ID
  28688. $this->xobjects[$this->xobjid] = array('n' => $this->n);
  28689. // store current graphic state
  28690. $this->xobjects[$this->xobjid]['gvars'] = $this->getGraphicVars();
  28691. // initialize data
  28692. $this->xobjects[$this->xobjid]['intmrk'] = 0;
  28693. $this->xobjects[$this->xobjid]['transfmrk'] = array();
  28694. $this->xobjects[$this->xobjid]['outdata'] = '';
  28695. $this->xobjects[$this->xobjid]['xobjects'] = array();
  28696. $this->xobjects[$this->xobjid]['images'] = array();
  28697. $this->xobjects[$this->xobjid]['fonts'] = array();
  28698. $this->xobjects[$this->xobjid]['annotations'] = array();
  28699. // set new environment
  28700. $this->num_columns = 1;
  28701. $this->current_column = 0;
  28702. $this->SetAutoPageBreak(false);
  28703. if (($w === '') or ($w <= 0))
  28704. {
  28705. $w = $this->w - $this->lMargin - $this->rMargin;
  28706. }
  28707. if (($h === '') or ($h <= 0))
  28708. {
  28709. $h = $this->h - $this->tMargin - $this->bMargin;
  28710. }
  28711. $this->xobjects[$this->xobjid]['x'] = 0;
  28712. $this->xobjects[$this->xobjid]['y'] = 0;
  28713. $this->xobjects[$this->xobjid]['w'] = $w;
  28714. $this->xobjects[$this->xobjid]['h'] = $h;
  28715. $this->w = $w;
  28716. $this->h = $h;
  28717. $this->wPt = $this->w * $this->k;
  28718. $this->hPt = $this->h * $this->k;
  28719. $this->fwPt = $this->wPt;
  28720. $this->fhPt = $this->hPt;
  28721. $this->x = 0;
  28722. $this->y = 0;
  28723. $this->lMargin = 0;
  28724. $this->rMargin = 0;
  28725. $this->tMargin = 0;
  28726. $this->bMargin = 0;
  28727. return $this->xobjid;
  28728. }
  28729. /**
  28730. * End the current XObject Template started with startTemplate() and restore the previous graphic state.
  28731. * 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).
  28732. * 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.
  28733. * @return int the XObject Template ID in case of success or false in case of error.
  28734. * @author Nicola Asuni
  28735. * @access public
  28736. * @since 5.8.017 (2010-08-24)
  28737. * @see startTemplate(), printTemplate()
  28738. */
  28739. public function endTemplate()
  28740. {
  28741. if (! $this->inxobj)
  28742. {
  28743. // we are not inside a template
  28744. return false;
  28745. }
  28746. $this->inxobj = false;
  28747. // restore previous graphic state
  28748. $this->setGraphicVars($this->xobjects[$this->xobjid]['gvars'], true);
  28749. return $this->xobjid;
  28750. }
  28751. /**
  28752. * Print an XObject Template.
  28753. * You can print an XObject Template inside the currently opened Template.
  28754. * 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).
  28755. * 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.
  28756. * @param string $id The ID of XObject Template to print.
  28757. * @param int $x X position in user units (empty string = current x position)
  28758. * @param int $y Y position in user units (empty string = current y position)
  28759. * @param int $w Width in user units (zero = remaining page width)
  28760. * @param int $h Height in user units (zero = remaining page height)
  28761. * @param string $align Indicates the alignment of the pointer next to template insertion relative to template height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  28762. * @param string $palign Allows to center or align the template on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  28763. * @param boolean $fitonpage if true the template is resized to not exceed page dimensions.
  28764. * @author Nicola Asuni
  28765. * @access public
  28766. * @since 5.8.017 (2010-08-24)
  28767. * @see startTemplate(), endTemplate()
  28768. */
  28769. public function printTemplate($id, $x = '', $y = '', $w = 0, $h = 0, $align = '', $palign = '', $fitonpage = false)
  28770. {
  28771. if (! isset($this->xobjects[$id]))
  28772. {
  28773. $this->Error('The XObject Template \'' . $id . '\' doesn\'t exist!');
  28774. }
  28775. if ($this->inxobj)
  28776. {
  28777. if ($id == $this->xobjid)
  28778. {
  28779. // close current template
  28780. $this->endTemplate();
  28781. }
  28782. else
  28783. {
  28784. // use the template as resource for the template currently opened
  28785. $this->xobjects[$this->xobjid]['xobjects'][$id] = $this->xobjects[$id];
  28786. }
  28787. }
  28788. // set default values
  28789. if ($x === '')
  28790. {
  28791. $x = $this->x;
  28792. }
  28793. if ($y === '')
  28794. {
  28795. $y = $this->y;
  28796. }
  28797. // check page for no-write regions and adapt page margins if necessary
  28798. $this->checkPageRegions($h, $x, $y);
  28799. $ow = $this->xobjects[$id]['w'];
  28800. $oh = $this->xobjects[$id]['h'];
  28801. // calculate template width and height on document
  28802. if (($w <= 0) and ($h <= 0))
  28803. {
  28804. $w = $ow;
  28805. $h = $oh;
  28806. }
  28807. elseif ($w <= 0)
  28808. {
  28809. $w = $h * $ow / $oh;
  28810. }
  28811. elseif ($h <= 0)
  28812. {
  28813. $h = $w * $oh / $ow;
  28814. }
  28815. // fit the template on available space
  28816. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  28817. // set page alignment
  28818. $rb_y = $y + $h;
  28819. // set alignment
  28820. if ($this->rtl)
  28821. {
  28822. if ($palign == 'L')
  28823. {
  28824. $xt = $this->lMargin;
  28825. }
  28826. elseif ($palign == 'C')
  28827. {
  28828. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  28829. }
  28830. elseif ($palign == 'R')
  28831. {
  28832. $xt = $this->w - $this->rMargin - $w;
  28833. }
  28834. else
  28835. {
  28836. $xt = $x - $w;
  28837. }
  28838. $rb_x = $xt;
  28839. }
  28840. else
  28841. {
  28842. if ($palign == 'L')
  28843. {
  28844. $xt = $this->lMargin;
  28845. }
  28846. elseif ($palign == 'C')
  28847. {
  28848. $xt = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  28849. }
  28850. elseif ($palign == 'R')
  28851. {
  28852. $xt = $this->w - $this->rMargin - $w;
  28853. }
  28854. else
  28855. {
  28856. $xt = $x;
  28857. }
  28858. $rb_x = $xt + $w;
  28859. }
  28860. // print XObject Template + Transformation matrix
  28861. $this->StartTransform();
  28862. // translate and scale
  28863. $sx = ($w / $this->xobjects[$id]['w']);
  28864. $sy = ($h / $this->xobjects[$id]['h']);
  28865. $tm = array();
  28866. $tm[0] = $sx;
  28867. $tm[1] = 0;
  28868. $tm[2] = 0;
  28869. $tm[3] = $sy;
  28870. $tm[4] = $xt * $this->k;
  28871. $tm[5] = ($this->h - $h - $y) * $this->k;
  28872. $this->Transform($tm);
  28873. // set object
  28874. $this->_out('/' . $id . ' Do');
  28875. $this->StopTransform();
  28876. // add annotations
  28877. if (! empty($this->xobjects[$id]['annotations']))
  28878. {
  28879. foreach ($this->xobjects[$id]['annotations'] as $annot)
  28880. {
  28881. // transform original coordinates
  28882. $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1,
  28883. ($annot['x'] * $this->k), (- $annot['y'] * $this->k)));
  28884. $ax = ($coordlt[4] / $this->k);
  28885. $ay = ($this->h - $h - ($coordlt[5] / $this->k));
  28886. $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1,
  28887. (($annot['x'] + $annot['w']) * $this->k), ((- $annot['y'] - $annot['h']) * $this->k)));
  28888. $aw = ($coordrb[4] / $this->k) - $ax;
  28889. $ah = ($this->h - $h - ($coordrb[5] / $this->k)) - $ay;
  28890. $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
  28891. }
  28892. }
  28893. // set pointer to align the next text/objects
  28894. switch ($align)
  28895. {
  28896. case 'T' :
  28897. {
  28898. $this->y = $y;
  28899. $this->x = $rb_x;
  28900. break;
  28901. }
  28902. case 'M' :
  28903. {
  28904. $this->y = $y + round($h / 2);
  28905. $this->x = $rb_x;
  28906. break;
  28907. }
  28908. case 'B' :
  28909. {
  28910. $this->y = $rb_y;
  28911. $this->x = $rb_x;
  28912. break;
  28913. }
  28914. case 'N' :
  28915. {
  28916. $this->SetY($rb_y);
  28917. break;
  28918. }
  28919. default :
  28920. {
  28921. break;
  28922. }
  28923. }
  28924. }
  28925. /**
  28926. * Set the percentage of character stretching.
  28927. * @param int $perc percentage of stretching (100 = no stretching)
  28928. * @author Nicola Asuni
  28929. * @access public
  28930. * @since 5.9.000 (2010-09-29)
  28931. */
  28932. public function setFontStretching($perc = 100)
  28933. {
  28934. $this->font_stretching = $perc;
  28935. }
  28936. /**
  28937. * Get the percentage of character stretching.
  28938. * @return float stretching value
  28939. * @author Nicola Asuni
  28940. * @access public
  28941. * @since 5.9.000 (2010-09-29)
  28942. */
  28943. public function getFontStretching()
  28944. {
  28945. return $this->font_stretching;
  28946. }
  28947. /**
  28948. * Set the amount to increase or decrease the space between characters in a text.
  28949. * @param float $spacing amount to increase or decrease the space between characters in a text (0 = default spacing)
  28950. * @author Nicola Asuni
  28951. * @access public
  28952. * @since 5.9.000 (2010-09-29)
  28953. */
  28954. public function setFontSpacing($spacing = 0)
  28955. {
  28956. $this->font_spacing = $spacing;
  28957. }
  28958. /**
  28959. * Get the amount to increase or decrease the space between characters in a text.
  28960. * @return int font spacing (tracking/kerning) value
  28961. * @author Nicola Asuni
  28962. * @access public
  28963. * @since 5.9.000 (2010-09-29)
  28964. */
  28965. public function getFontSpacing()
  28966. {
  28967. return $this->font_spacing;
  28968. }
  28969. /**
  28970. * Return an array of no-write page regions
  28971. * @return array of no-write page regions
  28972. * @author Nicola Asuni
  28973. * @access public
  28974. * @since 5.9.003 (2010-10-13)
  28975. * @see setPageRegions(), addPageRegion()
  28976. */
  28977. public function getPageRegions()
  28978. {
  28979. return $this->page_regions;
  28980. }
  28981. /**
  28982. * Set no-write regions on page.
  28983. * 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.
  28984. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  28985. * You can set multiple regions for the same page.
  28986. * @param array $regions array of no-write regions. For each region you can define an array as follow: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). Omit this parameter to remove all regions.
  28987. * @author Nicola Asuni
  28988. * @access public
  28989. * @since 5.9.003 (2010-10-13)
  28990. * @see addPageRegion(), getPageRegions()
  28991. */
  28992. public function setPageRegions($regions = array())
  28993. {
  28994. // empty current regions array
  28995. $this->page_regions = array();
  28996. // add regions
  28997. foreach ($regions as $data)
  28998. {
  28999. $this->addPageRegion($data);
  29000. }
  29001. }
  29002. /**
  29003. * Add a single no-write region on selected page.
  29004. * 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.
  29005. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  29006. * You can set multiple regions for the same page.
  29007. * @param array $region array of a single no-write region array: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right).
  29008. * @author Nicola Asuni
  29009. * @access public
  29010. * @since 5.9.003 (2010-10-13)
  29011. * @see setPageRegions(), getPageRegions()
  29012. */
  29013. public function addPageRegion($region)
  29014. {
  29015. if (! isset($region['page']) or empty($region['page']))
  29016. {
  29017. $region['page'] = $this->page;
  29018. }
  29019. if (isset($region['xt']) and isset($region['xb']) and ($region['xt'] > 0) and ($region['xb'] > 0) and isset($region['yt']) and isset($region['yb']) and ($region['yt'] >= 0) and ($region['yt'] < $region['yb']) and isset($region['side']) and (($region['side'] == 'L') or ($region['side'] == 'R')))
  29020. {
  29021. $this->page_regions[] = $region;
  29022. }
  29023. }
  29024. /**
  29025. * Remove a single no-write region.
  29026. * @param int $key region key
  29027. * @author Nicola Asuni
  29028. * @access public
  29029. * @since 5.9.003 (2010-10-13)
  29030. * @see setPageRegions(), getPageRegions()
  29031. */
  29032. public function removePageRegion($key)
  29033. {
  29034. if (isset($this->page_regions[$key]))
  29035. {
  29036. unset($this->page_regions[$key]);
  29037. }
  29038. }
  29039. /**
  29040. * Check page for no-write regions and adapt current coordinates and page margins if necessary.
  29041. * 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.
  29042. * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
  29043. * @param float $h height of the text/image/object to print in user units
  29044. * @param float $x current X coordinate in user units
  29045. * @param float $y current Y coordinate in user units
  29046. * @author Nicola Asuni
  29047. * @access protected
  29048. * @since 5.9.003 (2010-10-13)
  29049. */
  29050. protected function checkPageRegions($h = 0, &$x = '', &$y = '')
  29051. {
  29052. // set default values
  29053. if ($x === '')
  29054. {
  29055. $x = &$this->x;
  29056. }
  29057. if ($y === '')
  29058. {
  29059. $y = &$this->y;
  29060. }
  29061. if (empty($this->page_regions))
  29062. {
  29063. // no page regions defined
  29064. return;
  29065. }
  29066. if (empty($h))
  29067. {
  29068. $h = ($this->FontSize * $this->cell_height_ratio) + $this->cell_padding['T'] + $this->cell_padding['B'];
  29069. }
  29070. if ($this->rtl)
  29071. {
  29072. $this->lMargin = $this->original_lMargin;
  29073. }
  29074. else
  29075. {
  29076. $this->rMargin = $this->original_rMargin;
  29077. }
  29078. if ($this->AutoPageBreak and ! $this->InFooter and (($y + $h) > $this->PageBreakTrigger))
  29079. {
  29080. // the content will be printed on a new page
  29081. return;
  29082. }
  29083. // adjust coordinates and page margins
  29084. foreach ($this->page_regions as $regid => $regdata)
  29085. {
  29086. if ($regdata['page'] == $this->page)
  29087. {
  29088. // check region boundaries
  29089. if (($y > ($regdata['yt'] - $h)) and ($y <= $regdata['yb']))
  29090. {
  29091. // Y is inside the region
  29092. $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
  29093. $yt = max($y, $regdata['yt']);
  29094. $yb = min(($yt + $h), $regdata['yb']);
  29095. $xt = (($yt - $regdata['yt']) * $minv) + $regdata['xt'];
  29096. $xb = (($yb - $regdata['yt']) * $minv) + $regdata['xt'];
  29097. if ($regdata['side'] == 'L')
  29098. { // left side
  29099. $new_margin = max($xt, $xb);
  29100. if ($this->lMargin < $new_margin)
  29101. {
  29102. if ($this->rtl)
  29103. {
  29104. // adjust left page margin
  29105. $this->lMargin = $new_margin;
  29106. }
  29107. if ($x < $new_margin)
  29108. {
  29109. // adjust x position
  29110. $x = $new_margin;
  29111. }
  29112. }
  29113. }
  29114. elseif ($regdata['side'] == 'R')
  29115. { // right side
  29116. $new_margin = min($xt, $xb);
  29117. if (($this->w - $this->rMargin) > $new_margin)
  29118. {
  29119. if (! $this->rtl)
  29120. {
  29121. // adjust right page margin
  29122. $this->rMargin = ($this->w - $new_margin);
  29123. }
  29124. if ($x > $new_margin)
  29125. {
  29126. // adjust x position
  29127. $x = $new_margin;
  29128. }
  29129. }
  29130. }
  29131. }
  29132. }
  29133. }
  29134. }
  29135. // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
  29136. // SVG METHODS
  29137. // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
  29138. /**
  29139. * Embedd a Scalable Vector Graphics (SVG) image.
  29140. * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
  29141. * @param string $file Name of the SVG file.
  29142. * @param float $x Abscissa of the upper-left corner.
  29143. * @param float $y Ordinate of the upper-left corner.
  29144. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  29145. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  29146. * @param mixed $link URL or identifier returned by AddLink().
  29147. * @param string $align Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul> If the alignment is an empty string, then the pointer will be restored on the starting SVG position.
  29148. * @param string $palign Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  29149. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  29150. * @param boolean $fitonpage if true the image is resized to not exceed page dimensions.
  29151. * @author Nicola Asuni
  29152. * @since 5.0.000 (2010-05-02)
  29153. * @access public
  29154. */
  29155. public function ImageSVG($file, $x = '', $y = '', $w = 0, $h = 0, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false)
  29156. {
  29157. if ($this->rasterize_vector_images and ($w > 0) and ($h > 0))
  29158. {
  29159. // convert SVG to raster image using GD or ImageMagick libraries
  29160. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  29161. }
  29162. $this->svgdir = dirname($file);
  29163. $svgdata = file_get_contents($file);
  29164. if ($svgdata === false)
  29165. {
  29166. $this->Error('SVG file not found: ' . $file);
  29167. }
  29168. if ($x === '')
  29169. {
  29170. $x = $this->x;
  29171. }
  29172. if ($y === '')
  29173. {
  29174. $y = $this->y;
  29175. }
  29176. // check page for no-write regions and adapt page margins if necessary
  29177. $this->checkPageRegions($x, $y);
  29178. $k = $this->k;
  29179. $ox = 0;
  29180. $oy = 0;
  29181. $ow = $w;
  29182. $oh = $h;
  29183. $aspect_ratio_align = 'xMidYMid';
  29184. $aspect_ratio_ms = 'meet';
  29185. $regs = array();
  29186. // get original image width and height
  29187. preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
  29188. if (isset($regs[1]) and ! empty($regs[1]))
  29189. {
  29190. $tmp = array();
  29191. if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp))
  29192. {
  29193. $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  29194. }
  29195. $tmp = array();
  29196. if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp))
  29197. {
  29198. $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit, false);
  29199. }
  29200. $tmp = array();
  29201. if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp))
  29202. {
  29203. $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  29204. }
  29205. $tmp = array();
  29206. if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp))
  29207. {
  29208. $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit, false);
  29209. }
  29210. $tmp = array();
  29211. $view_box = array();
  29212. if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp))
  29213. {
  29214. if (count($tmp) == 5)
  29215. {
  29216. array_shift($tmp);
  29217. foreach ($tmp as $key => $val)
  29218. {
  29219. $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  29220. }
  29221. $ox = $view_box[0];
  29222. $oy = $view_box[1];
  29223. }
  29224. // get aspect ratio
  29225. $tmp = array();
  29226. if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp))
  29227. {
  29228. $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
  29229. switch (count($aspect_ratio))
  29230. {
  29231. case 3 :
  29232. {
  29233. $aspect_ratio_align = $aspect_ratio[1];
  29234. $aspect_ratio_ms = $aspect_ratio[2];
  29235. break;
  29236. }
  29237. case 2 :
  29238. {
  29239. $aspect_ratio_align = $aspect_ratio[0];
  29240. $aspect_ratio_ms = $aspect_ratio[1];
  29241. break;
  29242. }
  29243. case 1 :
  29244. {
  29245. $aspect_ratio_align = $aspect_ratio[0];
  29246. $aspect_ratio_ms = 'meet';
  29247. break;
  29248. }
  29249. }
  29250. }
  29251. }
  29252. }
  29253. // calculate image width and height on document
  29254. if (($w <= 0) and ($h <= 0))
  29255. {
  29256. // convert image size to document unit
  29257. $w = $ow;
  29258. $h = $oh;
  29259. }
  29260. elseif ($w <= 0)
  29261. {
  29262. $w = $h * $ow / $oh;
  29263. }
  29264. elseif ($h <= 0)
  29265. {
  29266. $h = $w * $oh / $ow;
  29267. }
  29268. // fit the image on available space
  29269. $this->fitBlock($w, $h, $x, $y, $fitonpage);
  29270. if ($this->rasterize_vector_images)
  29271. {
  29272. // convert SVG to raster image using GD or ImageMagick libraries
  29273. return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
  29274. }
  29275. // set alignment
  29276. $this->img_rb_y = $y + $h;
  29277. // set alignment
  29278. if ($this->rtl)
  29279. {
  29280. if ($palign == 'L')
  29281. {
  29282. $ximg = $this->lMargin;
  29283. }
  29284. elseif ($palign == 'C')
  29285. {
  29286. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  29287. }
  29288. elseif ($palign == 'R')
  29289. {
  29290. $ximg = $this->w - $this->rMargin - $w;
  29291. }
  29292. else
  29293. {
  29294. $ximg = $x - $w;
  29295. }
  29296. $this->img_rb_x = $ximg;
  29297. }
  29298. else
  29299. {
  29300. if ($palign == 'L')
  29301. {
  29302. $ximg = $this->lMargin;
  29303. }
  29304. elseif ($palign == 'C')
  29305. {
  29306. $ximg = ($this->w + $this->lMargin - $this->rMargin - $w) / 2;
  29307. }
  29308. elseif ($palign == 'R')
  29309. {
  29310. $ximg = $this->w - $this->rMargin - $w;
  29311. }
  29312. else
  29313. {
  29314. $ximg = $x;
  29315. }
  29316. $this->img_rb_x = $ximg + $w;
  29317. }
  29318. // store current graphic vars
  29319. $gvars = $this->getGraphicVars();
  29320. // store SVG position and scale factors
  29321. $svgoffset_x = ($ximg - $ox) * $this->k;
  29322. $svgoffset_y = - ($y - $oy) * $this->k;
  29323. if (isset($view_box[2]) and ($view_box[2] > 0) and ($view_box[3] > 0))
  29324. {
  29325. $ow = $view_box[2];
  29326. $oh = $view_box[3];
  29327. }
  29328. $svgscale_x = $w / $ow;
  29329. $svgscale_y = $h / $oh;
  29330. // scaling and alignment
  29331. if ($aspect_ratio_align != 'none')
  29332. {
  29333. // store current scaling values
  29334. $svgscale_old_x = $svgscale_x;
  29335. $svgscale_old_y = $svgscale_y;
  29336. // force uniform scaling
  29337. if ($aspect_ratio_ms == 'slice')
  29338. {
  29339. // the entire viewport is covered by the viewBox
  29340. if ($svgscale_x > $svgscale_y)
  29341. {
  29342. $svgscale_y = $svgscale_x;
  29343. }
  29344. elseif ($svgscale_x < $svgscale_y)
  29345. {
  29346. $svgscale_x = $svgscale_y;
  29347. }
  29348. }
  29349. else
  29350. { // meet
  29351. // the entire viewBox is visible within the viewport
  29352. if ($svgscale_x < $svgscale_y)
  29353. {
  29354. $svgscale_y = $svgscale_x;
  29355. }
  29356. elseif ($svgscale_x > $svgscale_y)
  29357. {
  29358. $svgscale_x = $svgscale_y;
  29359. }
  29360. }
  29361. // correct X alignment
  29362. switch (substr($aspect_ratio_align, 1, 3))
  29363. {
  29364. case 'Min' :
  29365. {
  29366. // do nothing
  29367. break;
  29368. }
  29369. case 'Max' :
  29370. {
  29371. $svgoffset_x += (($w * $this->k) - ($ow * $this->k * $svgscale_x));
  29372. break;
  29373. }
  29374. default :
  29375. case 'Mid' :
  29376. {
  29377. $svgoffset_x += ((($w * $this->k) - ($ow * $this->k * $svgscale_x)) / 2);
  29378. break;
  29379. }
  29380. }
  29381. // correct Y alignment
  29382. switch (substr($aspect_ratio_align, 5))
  29383. {
  29384. case 'Min' :
  29385. {
  29386. // do nothing
  29387. break;
  29388. }
  29389. case 'Max' :
  29390. {
  29391. $svgoffset_y -= (($h * $this->k) - ($oh * $this->k * $svgscale_y));
  29392. break;
  29393. }
  29394. default :
  29395. case 'Mid' :
  29396. {
  29397. $svgoffset_y -= ((($h * $this->k) - ($oh * $this->k * $svgscale_y)) / 2);
  29398. break;
  29399. }
  29400. }
  29401. }
  29402. // store current page break mode
  29403. $page_break_mode = $this->AutoPageBreak;
  29404. $page_break_margin = $this->getBreakMargin();
  29405. $cell_padding = $this->cell_padding;
  29406. $this->SetCellPadding(0);
  29407. $this->SetAutoPageBreak(false);
  29408. // save the current graphic state
  29409. $this->_out('q' . $this->epsmarker);
  29410. // set initial clipping mask
  29411. $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
  29412. // scale and translate
  29413. $e = $ox * $this->k * (1 - $svgscale_x);
  29414. $f = ($this->h - $oy) * $this->k * (1 - $svgscale_y);
  29415. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $svgscale_x, 0, 0, $svgscale_y, $e + $svgoffset_x, $f + $svgoffset_y));
  29416. // creates a new XML parser to be used by the other XML functions
  29417. $this->parser = xml_parser_create('UTF-8');
  29418. // the following function allows to use parser inside object
  29419. xml_set_object($this->parser, $this);
  29420. // disable case-folding for this XML parser
  29421. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  29422. // sets the element handler functions for the XML parser
  29423. xml_set_element_handler($this->parser, 'startSVGElementHandler', 'endSVGElementHandler');
  29424. // sets the character data handler function for the XML parser
  29425. xml_set_character_data_handler($this->parser, 'segSVGContentHandler');
  29426. // start parsing an XML document
  29427. if (! xml_parse($this->parser, $svgdata))
  29428. {
  29429. $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));
  29430. $this->Error($error_message);
  29431. }
  29432. // free this XML parser
  29433. xml_parser_free($this->parser);
  29434. // restore previous graphic state
  29435. $this->_out($this->epsmarker . 'Q');
  29436. // restore graphic vars
  29437. $this->setGraphicVars($gvars);
  29438. $this->lasth = $gvars['lasth'];
  29439. if (! empty($border))
  29440. {
  29441. $bx = $this->x;
  29442. $by = $this->y;
  29443. $this->x = $ximg;
  29444. if ($this->rtl)
  29445. {
  29446. $this->x += $w;
  29447. }
  29448. $this->y = $y;
  29449. $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
  29450. $this->x = $bx;
  29451. $this->y = $by;
  29452. }
  29453. if ($link)
  29454. {
  29455. $this->Link($ximg, $y, $w, $h, $link, 0);
  29456. }
  29457. // set pointer to align the next text/objects
  29458. switch ($align)
  29459. {
  29460. case 'T' :
  29461. {
  29462. $this->y = $y;
  29463. $this->x = $this->img_rb_x;
  29464. break;
  29465. }
  29466. case 'M' :
  29467. {
  29468. $this->y = $y + round($h / 2);
  29469. $this->x = $this->img_rb_x;
  29470. break;
  29471. }
  29472. case 'B' :
  29473. {
  29474. $this->y = $this->img_rb_y;
  29475. $this->x = $this->img_rb_x;
  29476. break;
  29477. }
  29478. case 'N' :
  29479. {
  29480. $this->SetY($this->img_rb_y);
  29481. break;
  29482. }
  29483. default :
  29484. {
  29485. // restore pointer to starting position
  29486. $this->x = $gvars['x'];
  29487. $this->y = $gvars['y'];
  29488. $this->page = $gvars['page'];
  29489. $this->current_column = $gvars['current_column'];
  29490. $this->tMargin = $gvars['tMargin'];
  29491. $this->bMargin = $gvars['bMargin'];
  29492. $this->w = $gvars['w'];
  29493. $this->h = $gvars['h'];
  29494. $this->wPt = $gvars['wPt'];
  29495. $this->hPt = $gvars['hPt'];
  29496. $this->fwPt = $gvars['fwPt'];
  29497. $this->fhPt = $gvars['fhPt'];
  29498. break;
  29499. }
  29500. }
  29501. $this->endlinex = $this->img_rb_x;
  29502. // restore page break
  29503. $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
  29504. $this->cell_padding = $cell_padding;
  29505. }
  29506. /**
  29507. * Get the tranformation matrix from SVG transform attribute
  29508. * @param string transformation
  29509. * @return array of transformations
  29510. * @author Nicola Asuni
  29511. * @since 5.0.000 (2010-05-02)
  29512. * @access protected
  29513. */
  29514. protected function getSVGTransformMatrix($attribute)
  29515. {
  29516. // identity matrix
  29517. $tm = array(1, 0, 0, 1, 0, 0);
  29518. $transform = array();
  29519. if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0)
  29520. {
  29521. foreach ($transform as $key => $data)
  29522. {
  29523. if (! empty($data[2]))
  29524. {
  29525. $a = 1;
  29526. $b = 0;
  29527. $c = 0;
  29528. $d = 1;
  29529. $e = 0;
  29530. $f = 0;
  29531. $regs = array();
  29532. switch ($data[1])
  29533. {
  29534. case 'matrix' :
  29535. {
  29536. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs))
  29537. {
  29538. $a = $regs[1];
  29539. $b = $regs[2];
  29540. $c = $regs[3];
  29541. $d = $regs[4];
  29542. $e = $regs[5];
  29543. $f = $regs[6];
  29544. }
  29545. break;
  29546. }
  29547. case 'translate' :
  29548. {
  29549. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs))
  29550. {
  29551. $e = $regs[1];
  29552. $f = $regs[2];
  29553. }
  29554. elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs))
  29555. {
  29556. $e = $regs[1];
  29557. }
  29558. break;
  29559. }
  29560. case 'scale' :
  29561. {
  29562. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs))
  29563. {
  29564. $a = $regs[1];
  29565. $d = $regs[2];
  29566. }
  29567. elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs))
  29568. {
  29569. $a = $regs[1];
  29570. $d = $a;
  29571. }
  29572. break;
  29573. }
  29574. case 'rotate' :
  29575. {
  29576. if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs))
  29577. {
  29578. $ang = deg2rad($regs[1]);
  29579. $x = $regs[2];
  29580. $y = $regs[3];
  29581. $a = cos($ang);
  29582. $b = sin($ang);
  29583. $c = - $b;
  29584. $d = $a;
  29585. $e = ($x * (1 - $a)) - ($y * $c);
  29586. $f = ($y * (1 - $d)) - ($x * $b);
  29587. }
  29588. elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs))
  29589. {
  29590. $ang = deg2rad($regs[1]);
  29591. $a = cos($ang);
  29592. $b = sin($ang);
  29593. $c = - $b;
  29594. $d = $a;
  29595. $e = 0;
  29596. $f = 0;
  29597. }
  29598. break;
  29599. }
  29600. case 'skewX' :
  29601. {
  29602. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs))
  29603. {
  29604. $c = tan(deg2rad($regs[1]));
  29605. }
  29606. break;
  29607. }
  29608. case 'skewY' :
  29609. {
  29610. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs))
  29611. {
  29612. $b = tan(deg2rad($regs[1]));
  29613. }
  29614. break;
  29615. }
  29616. }
  29617. $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
  29618. }
  29619. }
  29620. }
  29621. return $tm;
  29622. }
  29623. /**
  29624. * Get the product of two SVG tranformation matrices
  29625. * @param array $ta first SVG tranformation matrix
  29626. * @param array $tb second SVG tranformation matrix
  29627. * @return transformation array
  29628. * @author Nicola Asuni
  29629. * @since 5.0.000 (2010-05-02)
  29630. * @access protected
  29631. */
  29632. protected function getTransformationMatrixProduct($ta, $tb)
  29633. {
  29634. $tm = array();
  29635. $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
  29636. $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
  29637. $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
  29638. $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
  29639. $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
  29640. $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
  29641. return $tm;
  29642. }
  29643. /**
  29644. * Convert SVG transformation matrix to PDF.
  29645. * @param array $tm original SVG transformation matrix
  29646. * @return array transformation matrix
  29647. * @access protected
  29648. * @since 5.0.000 (2010-05-02)
  29649. */
  29650. protected function convertSVGtMatrix($tm)
  29651. {
  29652. $a = $tm[0];
  29653. $b = - $tm[1];
  29654. $c = - $tm[2];
  29655. $d = $tm[3];
  29656. $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit, false) * $this->k;
  29657. $f = - $this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit, false) * $this->k;
  29658. $x = 0;
  29659. $y = $this->h * $this->k;
  29660. $e = ($x * (1 - $a)) - ($y * $c) + $e;
  29661. $f = ($y * (1 - $d)) - ($x * $b) + $f;
  29662. return array($a, $b, $c, $d, $e, $f);
  29663. }
  29664. /**
  29665. * Apply SVG graphic transformation matrix.
  29666. * @param array $tm original SVG transformation matrix
  29667. * @access protected
  29668. * @since 5.0.000 (2010-05-02)
  29669. */
  29670. protected function SVGTransform($tm)
  29671. {
  29672. $this->Transform($this->convertSVGtMatrix($tm));
  29673. }
  29674. /**
  29675. * Apply the requested SVG styles (*** TO BE COMPLETED ***)
  29676. * @param array $svgstyle array of SVG styles to apply
  29677. * @param array $prevsvgstyle array of previous SVG style
  29678. * @param int $x X origin of the bounding box
  29679. * @param int $y Y origin of the bounding box
  29680. * @param int $w width of the bounding box
  29681. * @param int $h height of the bounding box
  29682. * @param string $clip_function clip function
  29683. * @param array $clip_params array of parameters for clipping function
  29684. * @return object style
  29685. * @author Nicola Asuni
  29686. * @since 5.0.000 (2010-05-02)
  29687. * @access protected
  29688. */
  29689. protected function setSVGStyles($svgstyle, $prevsvgstyle, $x = 0, $y = 0, $w = 1, $h = 1, $clip_function = '', $clip_params = array())
  29690. {
  29691. $objstyle = '';
  29692. if (! isset($svgstyle['opacity']))
  29693. {
  29694. return $objstyle;
  29695. }
  29696. // clip-path
  29697. $regs = array();
  29698. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs))
  29699. {
  29700. $clip_path = $this->svgclippaths[$regs[1]];
  29701. foreach ($clip_path as $cp)
  29702. {
  29703. $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
  29704. }
  29705. }
  29706. // opacity
  29707. if ($svgstyle['opacity'] != 1)
  29708. {
  29709. $this->SetAlpha($svgstyle['opacity']);
  29710. }
  29711. // color
  29712. $fill_color = $this->convertHTMLColorToDec($svgstyle['color']);
  29713. $this->SetFillColorArray($fill_color);
  29714. // text color
  29715. $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']);
  29716. $this->SetTextColorArray($text_color);
  29717. // clip
  29718. if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs))
  29719. {
  29720. $top = (isset($regs[1]) ? $this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit, false) : 0);
  29721. $right = (isset($regs[2]) ? $this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit, false) : 0);
  29722. $bottom = (isset($regs[3]) ? $this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit, false) : 0);
  29723. $left = (isset($regs[4]) ? $this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit, false) : 0);
  29724. $cx = $x + $left;
  29725. $cy = $y + $top;
  29726. $cw = $w - $left - $right;
  29727. $ch = $h - $top - $bottom;
  29728. if ($svgstyle['clip-rule'] == 'evenodd')
  29729. {
  29730. $clip_rule = 'CNZ';
  29731. }
  29732. else
  29733. {
  29734. $clip_rule = 'CEO';
  29735. }
  29736. $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
  29737. }
  29738. // fill
  29739. $regs = array();
  29740. if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs))
  29741. {
  29742. // gradient
  29743. $gradient = $this->svggradients[$regs[1]];
  29744. if (isset($gradient['xref']))
  29745. {
  29746. // reference to another gradient definition
  29747. $newgradient = $this->svggradients[$gradient['xref']];
  29748. $newgradient['coords'] = $gradient['coords'];
  29749. $newgradient['mode'] = $gradient['mode'];
  29750. $newgradient['gradientUnits'] = $gradient['gradientUnits'];
  29751. if (isset($gradient['gradientTransform']))
  29752. {
  29753. $newgradient['gradientTransform'] = $gradient['gradientTransform'];
  29754. }
  29755. $gradient = $newgradient;
  29756. }
  29757. //save current Graphic State
  29758. $this->_out('q');
  29759. //set clipping area
  29760. if (! empty($clip_function) and method_exists($this, $clip_function))
  29761. {
  29762. $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
  29763. if (is_array($bbox) and (count($bbox) == 4))
  29764. {
  29765. list($x, $y, $w, $h) = $bbox;
  29766. }
  29767. }
  29768. if ($gradient['mode'] == 'measure')
  29769. {
  29770. if (isset($gradient['gradientTransform']) and ! empty($gradient['gradientTransform']))
  29771. {
  29772. $gtm = $gradient['gradientTransform'];
  29773. // apply transformation matrix
  29774. $xa = ($gtm[0] * $gradient['coords'][0]) + ($gtm[2] * $gradient['coords'][1]) + $gtm[4];
  29775. $ya = ($gtm[1] * $gradient['coords'][0]) + ($gtm[3] * $gradient['coords'][1]) + $gtm[5];
  29776. $xb = ($gtm[0] * $gradient['coords'][2]) + ($gtm[2] * $gradient['coords'][3]) + $gtm[4];
  29777. $yb = ($gtm[1] * $gradient['coords'][2]) + ($gtm[3] * $gradient['coords'][3]) + $gtm[5];
  29778. if (isset($gradient['coords'][4]))
  29779. {
  29780. $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) + pow(($gtm[1] * $gradient['coords'][4]), 2));
  29781. }
  29782. $gradient['coords'][0] = $xa;
  29783. $gradient['coords'][1] = $ya;
  29784. $gradient['coords'][2] = $xb;
  29785. $gradient['coords'][3] = $yb;
  29786. }
  29787. // convert SVG coordinates to user units
  29788. $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit, false);
  29789. $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit, false);
  29790. $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit, false);
  29791. $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit, false);
  29792. if (isset($gradient['coords'][4]))
  29793. {
  29794. $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit, false);
  29795. }
  29796. // shift units
  29797. if ($gradient['gradientUnits'] == 'objectBoundingBox')
  29798. {
  29799. // convert to SVG coordinate system
  29800. $gradient['coords'][0] += $x;
  29801. $gradient['coords'][1] += $y;
  29802. $gradient['coords'][2] += $x;
  29803. $gradient['coords'][3] += $y;
  29804. }
  29805. // calculate percentages
  29806. $gradient['coords'][0] = ($gradient['coords'][0] - $x) / $w;
  29807. $gradient['coords'][1] = ($gradient['coords'][1] - $y) / $h;
  29808. $gradient['coords'][2] = ($gradient['coords'][2] - $x) / $w;
  29809. $gradient['coords'][3] = ($gradient['coords'][3] - $y) / $h;
  29810. if (isset($gradient['coords'][4]))
  29811. {
  29812. $gradient['coords'][4] /= $w;
  29813. }
  29814. // fix values
  29815. foreach ($gradient['coords'] as $key => $val)
  29816. {
  29817. if ($val < 0)
  29818. {
  29819. $gradient['coords'][$key] = 0;
  29820. }
  29821. elseif ($val > 1)
  29822. {
  29823. $gradient['coords'][$key] = 1;
  29824. }
  29825. }
  29826. if (($gradient['type'] == 2) and ($gradient['coords'][0] == $gradient['coords'][2]) and ($gradient['coords'][1] == $gradient['coords'][3]))
  29827. {
  29828. // single color (no shading)
  29829. $gradient['coords'][0] = 1;
  29830. $gradient['coords'][1] = 0;
  29831. $gradient['coords'][2] = 0.999;
  29832. $gradient['coords'][3] = 0;
  29833. }
  29834. }
  29835. // swap Y coordinates
  29836. $tmp = $gradient['coords'][1];
  29837. $gradient['coords'][1] = $gradient['coords'][3];
  29838. $gradient['coords'][3] = $tmp;
  29839. // set transformation map for gradient
  29840. if (($gradient['type'] == 3) and ($gradient['mode'] == 'measure'))
  29841. {
  29842. // gradient is always circular
  29843. $cy = $this->h - $y - ($gradient['coords'][1] * ($w + $h));
  29844. $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w * $this->k, $w * $this->k, $x * $this->k, $cy * $this->k));
  29845. }
  29846. else
  29847. {
  29848. $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k));
  29849. }
  29850. if (count($gradient['stops']) > 1)
  29851. {
  29852. $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
  29853. }
  29854. }
  29855. elseif ($svgstyle['fill'] != 'none')
  29856. {
  29857. $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']);
  29858. if ($svgstyle['fill-opacity'] != 1)
  29859. {
  29860. $this->SetAlpha($svgstyle['fill-opacity']);
  29861. }
  29862. $this->SetFillColorArray($fill_color);
  29863. if ($svgstyle['fill-rule'] == 'evenodd')
  29864. {
  29865. $objstyle .= 'F*';
  29866. }
  29867. else
  29868. {
  29869. $objstyle .= 'F';
  29870. }
  29871. }
  29872. // stroke
  29873. if ($svgstyle['stroke'] != 'none')
  29874. {
  29875. $stroke_style = array('color' => $this->convertHTMLColorToDec($svgstyle['stroke']),
  29876. 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false),
  29877. 'cap' => $svgstyle['stroke-linecap'], 'join' => $svgstyle['stroke-linejoin']);
  29878. if (isset($svgstyle['stroke-dasharray']) and ! empty($svgstyle['stroke-dasharray']) and ($svgstyle['stroke-dasharray'] != 'none'))
  29879. {
  29880. $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
  29881. }
  29882. $this->SetLineStyle($stroke_style);
  29883. $objstyle .= 'D';
  29884. }
  29885. // font
  29886. $regs = array();
  29887. if (! empty($svgstyle['font']))
  29888. {
  29889. if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs))
  29890. {
  29891. $font_family = $this->getFontFamilyName($regs[1]);
  29892. }
  29893. else
  29894. {
  29895. $font_family = $svgstyle['font-family'];
  29896. }
  29897. if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs))
  29898. {
  29899. $font_size = trim($regs[1]);
  29900. }
  29901. else
  29902. {
  29903. $font_size = $svgstyle['font-size'];
  29904. }
  29905. if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs))
  29906. {
  29907. $font_style = trim($regs[1]);
  29908. }
  29909. else
  29910. {
  29911. $font_style = $svgstyle['font-style'];
  29912. }
  29913. if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs))
  29914. {
  29915. $font_weight = trim($regs[1]);
  29916. }
  29917. else
  29918. {
  29919. $font_weight = $svgstyle['font-weight'];
  29920. }
  29921. if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs))
  29922. {
  29923. $font_stretch = trim($regs[1]);
  29924. }
  29925. else
  29926. {
  29927. $font_stretch = $svgstyle['font-stretch'];
  29928. }
  29929. if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs))
  29930. {
  29931. $font_spacing = trim($regs[1]);
  29932. }
  29933. else
  29934. {
  29935. $font_spacing = $svgstyle['letter-spacing'];
  29936. }
  29937. }
  29938. else
  29939. {
  29940. $font_family = $this->getFontFamilyName($svgstyle['font-family']);
  29941. $font_size = $svgstyle['font-size'];
  29942. $font_style = $svgstyle['font-style'];
  29943. $font_weight = $svgstyle['font-weight'];
  29944. $font_stretch = $svgstyle['font-stretch'];
  29945. $font_spacing = $svgstyle['letter-spacing'];
  29946. }
  29947. $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit, false) * $this->k;
  29948. $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
  29949. $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
  29950. switch ($font_style)
  29951. {
  29952. case 'italic' :
  29953. {
  29954. $font_style = 'I';
  29955. break;
  29956. }
  29957. case 'oblique' :
  29958. {
  29959. $font_style = 'I';
  29960. break;
  29961. }
  29962. default :
  29963. case 'normal' :
  29964. {
  29965. $font_style = '';
  29966. break;
  29967. }
  29968. }
  29969. switch ($font_weight)
  29970. {
  29971. case 'bold' :
  29972. case 'bolder' :
  29973. {
  29974. $font_style .= 'B';
  29975. break;
  29976. }
  29977. }
  29978. switch ($svgstyle['text-decoration'])
  29979. {
  29980. case 'underline' :
  29981. {
  29982. $font_style .= 'U';
  29983. break;
  29984. }
  29985. case 'overline' :
  29986. {
  29987. $font_style .= 'O';
  29988. break;
  29989. }
  29990. case 'line-through' :
  29991. {
  29992. $font_style .= 'D';
  29993. break;
  29994. }
  29995. default :
  29996. case 'none' :
  29997. {
  29998. break;
  29999. }
  30000. }
  30001. $this->SetFont($font_family, $font_style, $font_size);
  30002. $this->setFontStretching($font_stretch);
  30003. $this->setFontSpacing($font_spacing);
  30004. return $objstyle;
  30005. }
  30006. /**
  30007. * Draws an SVG path
  30008. * @param string $d attribute d of the path SVG element
  30009. * @param string $style Style of rendering. Possible values are:
  30010. * <ul>
  30011. * <li>D or empty string: Draw (default).</li>
  30012. * <li>F: Fill.</li>
  30013. * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  30014. * <li>DF or FD: Draw and fill.</li>
  30015. * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
  30016. * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
  30017. * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
  30018. * </ul>
  30019. * @return array of container box measures (x, y, w, h)
  30020. * @author Nicola Asuni
  30021. * @since 5.0.000 (2010-05-02)
  30022. * @access protected
  30023. */
  30024. protected function SVGPath($d, $style = '')
  30025. {
  30026. // set fill/stroke style
  30027. $op = $this->getPathPaintOperator($style, '');
  30028. if (empty($op))
  30029. {
  30030. return;
  30031. }
  30032. $paths = array();
  30033. $d = str_replace('-', ' -', $d);
  30034. $d = str_replace('+', ' +', $d);
  30035. preg_match_all('/([a-zA-Z])[\s]*([^a-zA-Z\"]*)/si', $d, $paths, PREG_SET_ORDER);
  30036. $x = 0;
  30037. $y = 0;
  30038. $x1 = 0;
  30039. $y1 = 0;
  30040. $x2 = 0;
  30041. $y2 = 0;
  30042. $xmin = 2147483647;
  30043. $xmax = 0;
  30044. $ymin = 2147483647;
  30045. $ymax = 0;
  30046. $relcoord = false;
  30047. // draw curve pieces
  30048. foreach ($paths as $key => $val)
  30049. {
  30050. // get curve type
  30051. $cmd = trim($val[1]);
  30052. if (strtolower($cmd) == $cmd)
  30053. {
  30054. // use relative coordinated instead of absolute
  30055. $relcoord = true;
  30056. $xoffset = $x;
  30057. $yoffset = $y;
  30058. }
  30059. else
  30060. {
  30061. $relcoord = false;
  30062. $xoffset = 0;
  30063. $yoffset = 0;
  30064. }
  30065. $params = array();
  30066. if (isset($val[2]))
  30067. {
  30068. // get curve parameters
  30069. $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
  30070. $params = array();
  30071. foreach ($rawparams as $ck => $cp)
  30072. {
  30073. $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit, false);
  30074. }
  30075. }
  30076. switch (strtoupper($cmd))
  30077. {
  30078. case 'M' :
  30079. { // moveto
  30080. foreach ($params as $ck => $cp)
  30081. {
  30082. if (($ck % 2) == 0)
  30083. {
  30084. $x = $cp + $xoffset;
  30085. }
  30086. else
  30087. {
  30088. $y = $cp + $yoffset;
  30089. if ($ck == 1)
  30090. {
  30091. $this->_outPoint($x, $y);
  30092. }
  30093. else
  30094. {
  30095. $this->_outLine($x, $y);
  30096. }
  30097. $xmin = min($xmin, $x);
  30098. $ymin = min($ymin, $y);
  30099. $xmax = max($xmax, $x);
  30100. $ymax = max($ymax, $y);
  30101. if ($relcoord)
  30102. {
  30103. $xoffset = $x;
  30104. $yoffset = $y;
  30105. }
  30106. }
  30107. }
  30108. break;
  30109. }
  30110. case 'L' :
  30111. { // lineto
  30112. foreach ($params as $ck => $cp)
  30113. {
  30114. if (($ck % 2) == 0)
  30115. {
  30116. $x = $cp + $xoffset;
  30117. }
  30118. else
  30119. {
  30120. $y = $cp + $yoffset;
  30121. $this->_outLine($x, $y);
  30122. $xmin = min($xmin, $x);
  30123. $ymin = min($ymin, $y);
  30124. $xmax = max($xmax, $x);
  30125. $ymax = max($ymax, $y);
  30126. if ($relcoord)
  30127. {
  30128. $xoffset = $x;
  30129. $yoffset = $y;
  30130. }
  30131. }
  30132. }
  30133. break;
  30134. }
  30135. case 'H' :
  30136. { // horizontal lineto
  30137. foreach ($params as $ck => $cp)
  30138. {
  30139. $x = $cp + $xoffset;
  30140. $this->_outLine($x, $y);
  30141. $xmin = min($xmin, $x);
  30142. $xmax = max($xmax, $x);
  30143. if ($relcoord)
  30144. {
  30145. $xoffset = $x;
  30146. }
  30147. }
  30148. break;
  30149. }
  30150. case 'V' :
  30151. { // vertical lineto
  30152. foreach ($params as $ck => $cp)
  30153. {
  30154. $y = $cp + $yoffset;
  30155. $this->_outLine($x, $y);
  30156. $ymin = min($ymin, $y);
  30157. $ymax = max($ymax, $y);
  30158. if ($relcoord)
  30159. {
  30160. $yoffset = $y;
  30161. }
  30162. }
  30163. break;
  30164. }
  30165. case 'C' :
  30166. { // curveto
  30167. foreach ($params as $ck => $cp)
  30168. {
  30169. $params[$ck] = $cp;
  30170. if ((($ck + 1) % 6) == 0)
  30171. {
  30172. $x1 = $params[($ck - 5)] + $xoffset;
  30173. $y1 = $params[($ck - 4)] + $yoffset;
  30174. $x2 = $params[($ck - 3)] + $xoffset;
  30175. $y2 = $params[($ck - 2)] + $yoffset;
  30176. $x = $params[($ck - 1)] + $xoffset;
  30177. $y = $params[($ck)] + $yoffset;
  30178. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  30179. $xmin = min($xmin, $x, $x1, $x2);
  30180. $ymin = min($ymin, $y, $y1, $y2);
  30181. $xmax = max($xmax, $x, $x1, $x2);
  30182. $ymax = max($ymax, $y, $y1, $y2);
  30183. if ($relcoord)
  30184. {
  30185. $xoffset = $x;
  30186. $yoffset = $y;
  30187. }
  30188. }
  30189. }
  30190. break;
  30191. }
  30192. case 'S' :
  30193. { // shorthand/smooth curveto
  30194. foreach ($params as $ck => $cp)
  30195. {
  30196. $params[$ck] = $cp;
  30197. if ((($ck + 1) % 4) == 0)
  30198. {
  30199. if (($key > 0) and ((strtoupper($paths[($key - 1)][1]) == 'C') or (strtoupper($paths[($key - 1)][1]) == 'S')))
  30200. {
  30201. $x1 = (2 * $x) - $x2;
  30202. $y1 = (2 * $y) - $y2;
  30203. }
  30204. else
  30205. {
  30206. $x1 = $x;
  30207. $y1 = $y;
  30208. }
  30209. $x2 = $params[($ck - 3)] + $xoffset;
  30210. $y2 = $params[($ck - 2)] + $yoffset;
  30211. $x = $params[($ck - 1)] + $xoffset;
  30212. $y = $params[($ck)] + $yoffset;
  30213. $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
  30214. $xmin = min($xmin, $x, $x1, $x2);
  30215. $ymin = min($ymin, $y, $y1, $y2);
  30216. $xmax = max($xmax, $x, $x1, $x2);
  30217. $ymax = max($ymax, $y, $y1, $y2);
  30218. if ($relcoord)
  30219. {
  30220. $xoffset = $x;
  30221. $yoffset = $y;
  30222. }
  30223. }
  30224. }
  30225. break;
  30226. }
  30227. case 'Q' :
  30228. { // quadratic B�zier curveto
  30229. foreach ($params as $ck => $cp)
  30230. {
  30231. $params[$ck] = $cp;
  30232. if ((($ck + 1) % 4) == 0)
  30233. {
  30234. // convert quadratic points to cubic points
  30235. $x1 = $params[($ck - 3)] + $xoffset;
  30236. $y1 = $params[($ck - 2)] + $yoffset;
  30237. $xa = ($x + (2 * $x1)) / 3;
  30238. $ya = ($y + (2 * $y1)) / 3;
  30239. $x = $params[($ck - 1)] + $xoffset;
  30240. $y = $params[($ck)] + $yoffset;
  30241. $xb = ($x + (2 * $x1)) / 3;
  30242. $yb = ($y + (2 * $y1)) / 3;
  30243. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  30244. $xmin = min($xmin, $x, $xa, $xb);
  30245. $ymin = min($ymin, $y, $ya, $yb);
  30246. $xmax = max($xmax, $x, $xa, $xb);
  30247. $ymax = max($ymax, $y, $ya, $yb);
  30248. if ($relcoord)
  30249. {
  30250. $xoffset = $x;
  30251. $yoffset = $y;
  30252. }
  30253. }
  30254. }
  30255. break;
  30256. }
  30257. case 'T' :
  30258. { // shorthand/smooth quadratic B�zier curveto
  30259. foreach ($params as $ck => $cp)
  30260. {
  30261. $params[$ck] = $cp;
  30262. if (($ck % 2) != 0)
  30263. {
  30264. if (($key > 0) and ((strtoupper($paths[($key - 1)][1]) == 'Q') or (strtoupper($paths[($key - 1)][1]) == 'T')))
  30265. {
  30266. $x1 = (2 * $x) - $x1;
  30267. $y1 = (2 * $y) - $y1;
  30268. }
  30269. else
  30270. {
  30271. $x1 = $x;
  30272. $y1 = $y;
  30273. }
  30274. // convert quadratic points to cubic points
  30275. $xa = ($x + (2 * $x1)) / 3;
  30276. $ya = ($y + (2 * $y1)) / 3;
  30277. $x = $params[($ck - 1)] + $xoffset;
  30278. $y = $params[($ck)] + $yoffset;
  30279. $xb = ($x + (2 * $x1)) / 3;
  30280. $yb = ($y + (2 * $y1)) / 3;
  30281. $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
  30282. $xmin = min($xmin, $x, $x1, $x2);
  30283. $ymin = min($ymin, $y, $y1, $y2);
  30284. $xmax = max($xmax, $x, $x1, $x2);
  30285. $ymax = max($ymax, $y, $y1, $y2);
  30286. if ($relcoord)
  30287. {
  30288. $xoffset = $x;
  30289. $yoffset = $y;
  30290. }
  30291. }
  30292. }
  30293. break;
  30294. }
  30295. case 'A' :
  30296. { // elliptical arc
  30297. foreach ($params as $ck => $cp)
  30298. {
  30299. $params[$ck] = $cp;
  30300. if ((($ck + 1) % 7) == 0)
  30301. {
  30302. $x0 = $x;
  30303. $y0 = $y;
  30304. $rx = abs($params[($ck - 6)]);
  30305. $ry = abs($params[($ck - 5)]);
  30306. $ang = - $rawparams[($ck - 4)];
  30307. $angle = deg2rad($ang);
  30308. $fa = $rawparams[($ck - 3)]; // large-arc-flag
  30309. $fs = $rawparams[($ck - 2)]; // sweep-flag
  30310. $x = $params[($ck - 1)] + $xoffset;
  30311. $y = $params[$ck] + $yoffset;
  30312. $cos_ang = cos($angle);
  30313. $sin_ang = sin($angle);
  30314. $a = ($x0 - $x) / 2;
  30315. $b = ($y0 - $y) / 2;
  30316. $xa = ($a * $cos_ang) - ($b * $sin_ang);
  30317. $ya = ($a * $sin_ang) + ($b * $cos_ang);
  30318. $rx2 = $rx * $rx;
  30319. $ry2 = $ry * $ry;
  30320. $xa2 = $xa * $xa;
  30321. $ya2 = $ya * $ya;
  30322. $delta = ($xa2 / $rx2) + ($ya2 / $ry2);
  30323. if ($delta > 1)
  30324. {
  30325. $rx *= sqrt($delta);
  30326. $ry *= sqrt($delta);
  30327. $rx2 = $rx * $rx;
  30328. $ry2 = $ry * $ry;
  30329. }
  30330. $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
  30331. if ($numerator < 0)
  30332. {
  30333. $root = 0;
  30334. }
  30335. else
  30336. {
  30337. $root = sqrt($numerator / (($rx2 * $ya2) + ($ry2 * $xa2)));
  30338. }
  30339. if ($fa == $fs)
  30340. {
  30341. $root *= - 1;
  30342. }
  30343. $cax = $root * (($rx * $ya) / $ry);
  30344. $cay = - $root * (($ry * $xa) / $rx);
  30345. // coordinates of ellipse center
  30346. $cx = ($cax * $cos_ang) - ($cay * $sin_ang) + (($x0 + $x) / 2);
  30347. $cy = ($cax * $sin_ang) + ($cay * $cos_ang) + (($y0 + $y) / 2);
  30348. // get angles
  30349. $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
  30350. $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((- $xa - $cax) / $rx), ((- $ya - $cay) / $ry));
  30351. if (($fs == 0) and ($dang > 0))
  30352. {
  30353. $dang -= (2 * M_PI);
  30354. }
  30355. elseif (($fs == 1) and ($dang < 0))
  30356. {
  30357. $dang += (2 * M_PI);
  30358. }
  30359. $angf = $angs - $dang;
  30360. if (($fs == 1) and ($angs > $angf))
  30361. {
  30362. $tmp = $angs;
  30363. $angs = $angf;
  30364. $angf = $tmp;
  30365. }
  30366. $angs = rad2deg($angs);
  30367. $angf = rad2deg($angf);
  30368. $pie = false;
  30369. if ((isset($paths[($key + 1)][1])) and (trim($paths[($key + 1)][1]) == 'z'))
  30370. {
  30371. $pie = true;
  30372. }
  30373. $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2);
  30374. $this->_outPoint($x, $y);
  30375. $xmin = min($xmin, $x);
  30376. $ymin = min($ymin, $y);
  30377. $xmax = max($xmax, $x);
  30378. $ymax = max($ymax, $y);
  30379. if ($relcoord)
  30380. {
  30381. $xoffset = $x;
  30382. $yoffset = $y;
  30383. }
  30384. }
  30385. }
  30386. break;
  30387. }
  30388. case 'Z' :
  30389. {
  30390. $this->_out('h');
  30391. break;
  30392. }
  30393. }
  30394. } // end foreach
  30395. if (! empty($op))
  30396. {
  30397. $this->_out($op);
  30398. }
  30399. return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
  30400. }
  30401. /**
  30402. * Returns the angle in radiants between two vectors
  30403. * @param int $x1 X coordiante of first vector point
  30404. * @param int $y1 Y coordiante of first vector point
  30405. * @param int $x2 X coordiante of second vector point
  30406. * @param int $y2 Y coordiante of second vector point
  30407. * @author Nicola Asuni
  30408. * @since 5.0.000 (2010-05-04)
  30409. * @access protected
  30410. */
  30411. protected function getVectorsAngle($x1, $y1, $x2, $y2)
  30412. {
  30413. $dprod = ($x1 * $x2) + ($y1 * $y2);
  30414. $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
  30415. $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
  30416. $angle = acos($dprod / ($dist1 * $dist2));
  30417. if (is_nan($angle))
  30418. {
  30419. $angle = M_PI;
  30420. }
  30421. if ((($x1 * $y2) - ($x2 * $y1)) < 0)
  30422. {
  30423. $angle *= - 1;
  30424. }
  30425. return $angle;
  30426. }
  30427. /**
  30428. * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
  30429. * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  30430. * @param string $name The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  30431. * @param array $attribs The third parameter, attribs, contains an associative array with the element's attributes (if any). The keys of this array are the attribute names, the values are the attribute values. Attribute names are case-folded on the same criteria as element names. Attribute values are not case-folded. The original order of the attributes can be retrieved by walking through attribs the normal way, using each(). The first key in the array was the first attribute, and so on.
  30432. * @param array $ctm tranformation matrix for clipping mode (starting transformation matrix).
  30433. * @author Nicola Asuni
  30434. * @since 5.0.000 (2010-05-02)
  30435. * @access protected
  30436. */
  30437. protected function startSVGElementHandler($parser, $name, $attribs, $ctm = array())
  30438. {
  30439. // check if we are in clip mode
  30440. if ($this->svgclipmode)
  30441. {
  30442. $this->svgclippaths[$this->svgclipid][] = array('name' => $name, 'attribs' => $attribs,
  30443. 'tm' => $this->svgcliptm[$this->svgclipid]);
  30444. return;
  30445. }
  30446. if ($this->svgdefsmode and ! in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop')))
  30447. {
  30448. if (! isset($attribs['id']))
  30449. {
  30450. $attribs['id'] = 'DF_' . (count($this->svgdefs) + 1);
  30451. }
  30452. $this->svgdefs[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
  30453. return;
  30454. }
  30455. $clipping = false;
  30456. if ($parser == 'clip-path')
  30457. {
  30458. // set clipping mode
  30459. $clipping = true;
  30460. }
  30461. // get styling properties
  30462. $prev_svgstyle = $this->svgstyles[(count($this->svgstyles) - 1)]; // previous style
  30463. $svgstyle = $this->svgstyles[0]; // set default style
  30464. if (isset($attribs['style']) and ! $this->empty_string($attribs['style']))
  30465. {
  30466. // fix style for regular expression
  30467. $attribs['style'] = ';' . $attribs['style'];
  30468. }
  30469. foreach ($prev_svgstyle as $key => $val)
  30470. {
  30471. if (in_array($key, $this->svginheritprop))
  30472. {
  30473. // inherit previous value
  30474. $svgstyle[$key] = $val;
  30475. }
  30476. if (isset($attribs[$key]) and ! $this->empty_string($attribs[$key]))
  30477. {
  30478. // specific attribute settings
  30479. if ($attribs[$key] == 'inherit')
  30480. {
  30481. $svgstyle[$key] = $val;
  30482. }
  30483. else
  30484. {
  30485. $svgstyle[$key] = $attribs[$key];
  30486. }
  30487. }
  30488. elseif (isset($attribs['style']) and ! $this->empty_string($attribs['style']))
  30489. {
  30490. // CSS style syntax
  30491. $attrval = array();
  30492. if (preg_match('/[;\"\s]{1}' . $key . '[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) and isset($attrval[1]))
  30493. {
  30494. if ($attrval[1] == 'inherit')
  30495. {
  30496. $svgstyle[$key] = $val;
  30497. }
  30498. else
  30499. {
  30500. $svgstyle[$key] = $attrval[1];
  30501. }
  30502. }
  30503. }
  30504. }
  30505. // transformation matrix
  30506. if (! empty($ctm))
  30507. {
  30508. $tm = $ctm;
  30509. }
  30510. else
  30511. {
  30512. $tm = $this->svgstyles[(count($this->svgstyles) - 1)]['transfmatrix'];
  30513. }
  30514. if (isset($attribs['transform']) and ! empty($attribs['transform']))
  30515. {
  30516. $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform']));
  30517. }
  30518. $svgstyle['transfmatrix'] = $tm;
  30519. $invisible = false;
  30520. if (($svgstyle['visibility'] == 'hidden') or ($svgstyle['visibility'] == 'collapse') or ($svgstyle['display'] == 'none'))
  30521. {
  30522. // the current graphics element is invisible (nothing is painted)
  30523. $invisible = true;
  30524. }
  30525. // process tag
  30526. switch ($name)
  30527. {
  30528. case 'defs' :
  30529. {
  30530. $this->svgdefsmode = true;
  30531. break;
  30532. }
  30533. // clipPath
  30534. case 'clipPath' :
  30535. {
  30536. if ($invisible)
  30537. {
  30538. break;
  30539. }
  30540. $this->svgclipmode = true;
  30541. if (! isset($attribs['id']))
  30542. {
  30543. $attribs['id'] = 'CP_' . (count($this->svgcliptm) + 1);
  30544. }
  30545. $this->svgclipid = $attribs['id'];
  30546. $this->svgclippaths[$this->svgclipid] = array();
  30547. $this->svgcliptm[$this->svgclipid] = $tm;
  30548. break;
  30549. }
  30550. case 'svg' :
  30551. {
  30552. // start of SVG object
  30553. break;
  30554. }
  30555. case 'g' :
  30556. {
  30557. // group together related graphics elements
  30558. array_push($this->svgstyles, $svgstyle);
  30559. $this->StartTransform();
  30560. $this->setSVGStyles($svgstyle, $prev_svgstyle);
  30561. break;
  30562. }
  30563. case 'linearGradient' :
  30564. {
  30565. if (! isset($attribs['id']))
  30566. {
  30567. $attribs['id'] = 'GR_' . (count($this->svggradients) + 1);
  30568. }
  30569. $this->svggradientid = $attribs['id'];
  30570. $this->svggradients[$this->svggradientid] = array();
  30571. $this->svggradients[$this->svggradientid]['type'] = 2;
  30572. $this->svggradients[$this->svggradientid]['stops'] = array();
  30573. if (isset($attribs['gradientUnits']))
  30574. {
  30575. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  30576. }
  30577. else
  30578. {
  30579. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  30580. }
  30581. //$attribs['spreadMethod']
  30582. $x1 = (isset($attribs['x1']) ? $attribs['x1'] : 0);
  30583. $y1 = (isset($attribs['y1']) ? $attribs['y1'] : 0);
  30584. $x2 = (isset($attribs['x2']) ? $attribs['x2'] : 1);
  30585. $y2 = (isset($attribs['y2']) ? $attribs['y2'] : 0);
  30586. if (isset($attribs['x1']) and (substr($attribs['x1'], - 1) != '%'))
  30587. {
  30588. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  30589. }
  30590. else
  30591. {
  30592. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  30593. }
  30594. if (isset($attribs['gradientTransform']))
  30595. {
  30596. $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
  30597. }
  30598. $this->svggradients[$this->svggradientid]['coords'] = array($x1, $y1, $x2, $y2);
  30599. if (isset($attribs['xlink:href']) and ! empty($attribs['xlink:href']))
  30600. {
  30601. // gradient is defined on another place
  30602. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  30603. }
  30604. break;
  30605. }
  30606. case 'radialGradient' :
  30607. {
  30608. if (! isset($attribs['id']))
  30609. {
  30610. $attribs['id'] = 'GR_' . (count($this->svggradients) + 1);
  30611. }
  30612. $this->svggradientid = $attribs['id'];
  30613. $this->svggradients[$this->svggradientid] = array();
  30614. $this->svggradients[$this->svggradientid]['type'] = 3;
  30615. $this->svggradients[$this->svggradientid]['stops'] = array();
  30616. if (isset($attribs['gradientUnits']))
  30617. {
  30618. $this->svggradients[$this->svggradientid]['gradientUnits'] = $attribs['gradientUnits'];
  30619. }
  30620. else
  30621. {
  30622. $this->svggradients[$this->svggradientid]['gradientUnits'] = 'objectBoundingBox';
  30623. }
  30624. //$attribs['spreadMethod']
  30625. $cx = (isset($attribs['cx']) ? $attribs['cx'] : 0.5);
  30626. $cy = (isset($attribs['cy']) ? $attribs['cy'] : 0.5);
  30627. $fx = (isset($attribs['fx']) ? $attribs['fx'] : $cx);
  30628. $fy = (isset($attribs['fy']) ? $attribs['fy'] : $cy);
  30629. $r = (isset($attribs['r']) ? $attribs['r'] : 0.5);
  30630. if (isset($attribs['cx']) and (substr($attribs['cx'], - 1) != '%'))
  30631. {
  30632. $this->svggradients[$this->svggradientid]['mode'] = 'measure';
  30633. }
  30634. else
  30635. {
  30636. $this->svggradients[$this->svggradientid]['mode'] = 'percentage';
  30637. }
  30638. if (isset($attribs['gradientTransform']))
  30639. {
  30640. $this->svggradients[$this->svggradientid]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
  30641. }
  30642. $this->svggradients[$this->svggradientid]['coords'] = array($cx, $cy, $fx, $fy, $r);
  30643. if (isset($attribs['xlink:href']) and ! empty($attribs['xlink:href']))
  30644. {
  30645. // gradient is defined on another place
  30646. $this->svggradients[$this->svggradientid]['xref'] = substr($attribs['xlink:href'], 1);
  30647. }
  30648. break;
  30649. }
  30650. case 'stop' :
  30651. {
  30652. // gradient stops
  30653. if (substr($attribs['offset'], - 1) == '%')
  30654. {
  30655. $offset = floatval(substr($attribs['offset'], - 1)) / 100;
  30656. }
  30657. else
  30658. {
  30659. $offset = floatval($attribs['offset']);
  30660. if ($offset > 1)
  30661. {
  30662. $offset /= 100;
  30663. }
  30664. }
  30665. $stop_color = isset($svgstyle['stop-color']) ? $this->convertHTMLColorToDec($svgstyle['stop-color']) : 'black';
  30666. $opacity = isset($svgstyle['stop-opacity']) ? $svgstyle['stop-opacity'] : 1;
  30667. $this->svggradients[$this->svggradientid]['stops'][] = array('offset' => $offset,
  30668. 'color' => $stop_color, 'opacity' => $opacity);
  30669. break;
  30670. }
  30671. // paths
  30672. case 'path' :
  30673. {
  30674. if ($invisible)
  30675. {
  30676. break;
  30677. }
  30678. $d = trim($attribs['d']);
  30679. if ($clipping)
  30680. {
  30681. $this->SVGTransform($tm);
  30682. $this->SVGPath($d, 'CNZ');
  30683. }
  30684. else
  30685. {
  30686. $this->StartTransform();
  30687. $this->SVGTransform($tm);
  30688. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d,
  30689. 'CNZ'));
  30690. if (! empty($obstyle))
  30691. {
  30692. $this->SVGPath($d, $obstyle);
  30693. }
  30694. $this->StopTransform();
  30695. }
  30696. break;
  30697. }
  30698. // shapes
  30699. case 'rect' :
  30700. {
  30701. if ($invisible)
  30702. {
  30703. break;
  30704. }
  30705. $x = (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0);
  30706. $y = (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0);
  30707. $w = (isset($attribs['width']) ? $this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false) : 0);
  30708. $h = (isset($attribs['height']) ? $this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false) : 0);
  30709. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  30710. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : $rx);
  30711. if ($clipping)
  30712. {
  30713. $this->SVGTransform($tm);
  30714. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
  30715. }
  30716. else
  30717. {
  30718. $this->StartTransform();
  30719. $this->SVGTransform($tm);
  30720. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array(
  30721. $x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
  30722. if (! empty($obstyle))
  30723. {
  30724. $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
  30725. }
  30726. $this->StopTransform();
  30727. }
  30728. break;
  30729. }
  30730. case 'circle' :
  30731. {
  30732. if ($invisible)
  30733. {
  30734. break;
  30735. }
  30736. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : 0);
  30737. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : 0);
  30738. $r = (isset($attribs['r']) ? $this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit, false) : 0);
  30739. $x = $cx - $r;
  30740. $y = $cy - $r;
  30741. $w = 2 * $r;
  30742. $h = $w;
  30743. if ($clipping)
  30744. {
  30745. $this->SVGTransform($tm);
  30746. $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
  30747. }
  30748. else
  30749. {
  30750. $this->StartTransform();
  30751. $this->SVGTransform($tm);
  30752. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx,
  30753. $cy, $r, 0, 360, 'CNZ'));
  30754. if (! empty($obstyle))
  30755. {
  30756. $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
  30757. }
  30758. $this->StopTransform();
  30759. }
  30760. break;
  30761. }
  30762. case 'ellipse' :
  30763. {
  30764. if ($invisible)
  30765. {
  30766. break;
  30767. }
  30768. $cx = (isset($attribs['cx']) ? $this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit, false) : 0);
  30769. $cy = (isset($attribs['cy']) ? $this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit, false) : 0);
  30770. $rx = (isset($attribs['rx']) ? $this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit, false) : 0);
  30771. $ry = (isset($attribs['ry']) ? $this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit, false) : 0);
  30772. $x = $cx - $rx;
  30773. $y = $cy - $ry;
  30774. $w = 2 * $rx;
  30775. $h = 2 * $ry;
  30776. if ($clipping)
  30777. {
  30778. $this->SVGTransform($tm);
  30779. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
  30780. }
  30781. else
  30782. {
  30783. $this->StartTransform();
  30784. $this->SVGTransform($tm);
  30785. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx,
  30786. $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
  30787. if (! empty($obstyle))
  30788. {
  30789. $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
  30790. }
  30791. $this->StopTransform();
  30792. }
  30793. break;
  30794. }
  30795. case 'line' :
  30796. {
  30797. if ($invisible)
  30798. {
  30799. break;
  30800. }
  30801. $x1 = (isset($attribs['x1']) ? $this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit, false) : 0);
  30802. $y1 = (isset($attribs['y1']) ? $this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit, false) : 0);
  30803. $x2 = (isset($attribs['x2']) ? $this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit, false) : 0);
  30804. $y2 = (isset($attribs['y2']) ? $this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit, false) : 0);
  30805. $x = $x1;
  30806. $y = $y1;
  30807. $w = abs($x2 - $x1);
  30808. $h = abs($y2 - $y1);
  30809. if (! $clipping)
  30810. {
  30811. $this->StartTransform();
  30812. $this->SVGTransform($tm);
  30813. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1,
  30814. $y1, $x2, $y2));
  30815. $this->Line($x1, $y1, $x2, $y2);
  30816. $this->StopTransform();
  30817. }
  30818. break;
  30819. }
  30820. case 'polyline' :
  30821. case 'polygon' :
  30822. {
  30823. if ($invisible)
  30824. {
  30825. break;
  30826. }
  30827. $points = (isset($attribs['points']) ? $attribs['points'] : '0 0');
  30828. $points = trim($points);
  30829. // note that point may use a complex syntax not covered here
  30830. $points = preg_split('/[\,\s]+/si', $points);
  30831. if (count($points) < 4)
  30832. {
  30833. break;
  30834. }
  30835. $p = array();
  30836. $xmin = 2147483647;
  30837. $xmax = 0;
  30838. $ymin = 2147483647;
  30839. $ymax = 0;
  30840. foreach ($points as $key => $val)
  30841. {
  30842. $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit, false);
  30843. if (($key % 2) == 0)
  30844. {
  30845. // X coordinate
  30846. $xmin = min($xmin, $p[$key]);
  30847. $xmax = max($xmax, $p[$key]);
  30848. }
  30849. else
  30850. {
  30851. // Y coordinate
  30852. $ymin = min($ymin, $p[$key]);
  30853. $ymax = max($ymax, $p[$key]);
  30854. }
  30855. }
  30856. $x = $xmin;
  30857. $y = $ymin;
  30858. $w = ($xmax - $xmin);
  30859. $h = ($ymax - $ymin);
  30860. if ($name == 'polyline')
  30861. {
  30862. $this->StartTransform();
  30863. $this->SVGTransform($tm);
  30864. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p,
  30865. 'CNZ'));
  30866. $this->PolyLine($p, 'D', array(), array());
  30867. $this->StopTransform();
  30868. }
  30869. else
  30870. { // polygon
  30871. if ($clipping)
  30872. {
  30873. $this->SVGTransform($tm);
  30874. $this->Polygon($p, 'CNZ', array(), array(), true);
  30875. }
  30876. else
  30877. {
  30878. $this->StartTransform();
  30879. $this->SVGTransform($tm);
  30880. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array(
  30881. $p, 'CNZ'));
  30882. if (! empty($obstyle))
  30883. {
  30884. $this->Polygon($p, $obstyle, array(), array(), true);
  30885. }
  30886. $this->StopTransform();
  30887. }
  30888. }
  30889. break;
  30890. }
  30891. // image
  30892. case 'image' :
  30893. {
  30894. if ($invisible)
  30895. {
  30896. break;
  30897. }
  30898. if (! isset($attribs['xlink:href']) or empty($attribs['xlink:href']))
  30899. {
  30900. break;
  30901. }
  30902. $x = (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : 0);
  30903. $y = (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : 0);
  30904. $w = (isset($attribs['width']) ? $this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit, false) : 0);
  30905. $h = (isset($attribs['height']) ? $this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit, false) : 0);
  30906. $img = $attribs['xlink:href'];
  30907. if (! $clipping)
  30908. {
  30909. $this->StartTransform();
  30910. $this->SVGTransform($tm);
  30911. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
  30912. // fix image path
  30913. if (! $this->empty_string($this->svgdir) and (($img{0} == '.') or (basename($img) == $img)))
  30914. {
  30915. // replace relative path with full server path
  30916. $img = $this->svgdir . '/' . $img;
  30917. }
  30918. if (($img{0} == '/') and ($_SERVER['DOCUMENT_ROOT'] != '/'))
  30919. {
  30920. $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
  30921. if (($findroot === false) or ($findroot > 1))
  30922. {
  30923. // replace relative path with full server path
  30924. $img = $_SERVER['DOCUMENT_ROOT'] . $img;
  30925. }
  30926. }
  30927. $img = urldecode($img);
  30928. $testscrtype = @parse_url($img);
  30929. if (! isset($testscrtype['query']) or empty($testscrtype['query']))
  30930. {
  30931. // convert URL to server path
  30932. $img = str_replace(K_PATH_URL, K_PATH_MAIN, $img);
  30933. }
  30934. $this->Image($img, $x, $y, $w, $h);
  30935. $this->StopTransform();
  30936. }
  30937. break;
  30938. }
  30939. // text
  30940. case 'text' :
  30941. case 'tspan' :
  30942. {
  30943. $this->svgtextmode['invisible'] = $invisible;
  30944. if ($invisible)
  30945. {
  30946. break;
  30947. }
  30948. array_push($this->svgstyles, $svgstyle);
  30949. // only basic support - advanced features must be implemented
  30950. $x = (isset($attribs['x']) ? $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit, false) : $this->x);
  30951. $y = (isset($attribs['y']) ? $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit, false) : $this->y);
  30952. $svgstyle['text-color'] = $svgstyle['fill'];
  30953. $this->svgtext = '';
  30954. if (isset($svgstyle['text-anchor']))
  30955. {
  30956. $this->svgtextmode['text-anchor'] = $svgstyle['text-anchor'];
  30957. }
  30958. else
  30959. {
  30960. $this->svgtextmode['text-anchor'] = 'start';
  30961. }
  30962. if (isset($svgstyle['direction']))
  30963. {
  30964. if ($svgstyle['direction'] == 'rtl')
  30965. {
  30966. $this->svgtextmode['rtl'] = true;
  30967. }
  30968. else
  30969. {
  30970. $this->svgtextmode['rtl'] = false;
  30971. }
  30972. }
  30973. else
  30974. {
  30975. $this->svgtextmode['rtl'] = false;
  30976. }
  30977. if (isset($svgstyle['stroke']) and ($svgstyle['stroke'] != 'none') and isset($svgstyle['stroke-width']) and ($svgstyle['stroke-width'] > 0))
  30978. {
  30979. $this->svgtextmode['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit, false);
  30980. }
  30981. else
  30982. {
  30983. $this->svgtextmode['stroke'] = false;
  30984. }
  30985. $this->StartTransform();
  30986. $this->SVGTransform($tm);
  30987. $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
  30988. $this->x = $x;
  30989. $this->y = $y;
  30990. break;
  30991. }
  30992. // use
  30993. case 'use' :
  30994. {
  30995. if (isset($attribs['xlink:href']))
  30996. {
  30997. $use = $this->svgdefs[substr($attribs['xlink:href'], 1)];
  30998. if (isset($attribs['xlink:href']))
  30999. {
  31000. unset($attribs['xlink:href']);
  31001. }
  31002. if (isset($attribs['id']))
  31003. {
  31004. unset($attribs['id']);
  31005. }
  31006. $attribs = array_merge($use['attribs'], $attribs);
  31007. $this->startSVGElementHandler($parser, $use['name'], $use['attribs']);
  31008. }
  31009. break;
  31010. }
  31011. default :
  31012. {
  31013. break;
  31014. }
  31015. } // end of switch
  31016. }
  31017. /**
  31018. * Sets the closing SVG element handler function for the XML parser.
  31019. * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  31020. * @param string $name The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
  31021. * @author Nicola Asuni
  31022. * @since 5.0.000 (2010-05-02)
  31023. * @access protected
  31024. */
  31025. protected function endSVGElementHandler($parser, $name)
  31026. {
  31027. switch ($name)
  31028. {
  31029. case 'defs' :
  31030. {
  31031. $this->svgdefsmode = false;
  31032. break;
  31033. }
  31034. // clipPath
  31035. case 'clipPath' :
  31036. {
  31037. $this->svgclipmode = false;
  31038. break;
  31039. }
  31040. case 'g' :
  31041. {
  31042. // ungroup: remove last style from array
  31043. array_pop($this->svgstyles);
  31044. $this->StopTransform();
  31045. break;
  31046. }
  31047. case 'text' :
  31048. case 'tspan' :
  31049. {
  31050. if ($this->svgtextmode['invisible'])
  31051. {
  31052. // This implementation must be fixed to following the rule:
  31053. // 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.
  31054. break;
  31055. }
  31056. // print text
  31057. $text = $this->stringTrim($this->svgtext);
  31058. if ($this->svgtextmode['text-anchor'] != 'start')
  31059. {
  31060. $textlen = $this->GetStringWidth($text);
  31061. // check if string is RTL text
  31062. if ($this->svgtextmode['text-anchor'] == 'end')
  31063. {
  31064. if ($this->svgtextmode['rtl'])
  31065. {
  31066. $this->x += $textlen;
  31067. }
  31068. else
  31069. {
  31070. $this->x -= $textlen;
  31071. }
  31072. }
  31073. elseif ($this->svgtextmode['text-anchor'] == 'middle')
  31074. {
  31075. if ($this->svgtextmode['rtl'])
  31076. {
  31077. $this->x += ($textlen / 2);
  31078. }
  31079. else
  31080. {
  31081. $this->x -= ($textlen / 2);
  31082. }
  31083. }
  31084. }
  31085. $textrendermode = $this->textrendermode;
  31086. $textstrokewidth = $this->textstrokewidth;
  31087. $this->setTextRenderingMode($this->svgtextmode['stroke'], true, false);
  31088. $this->Cell(0, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
  31089. // restore previous rendering mode
  31090. $this->textrendermode = $textrendermode;
  31091. $this->textstrokewidth = $textstrokewidth;
  31092. $this->svgtext = '';
  31093. $this->StopTransform();
  31094. array_pop($this->svgstyles);
  31095. break;
  31096. }
  31097. default :
  31098. {
  31099. break;
  31100. }
  31101. }
  31102. }
  31103. /**
  31104. * Sets the character data handler function for the XML parser.
  31105. * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  31106. * @param string $data The second parameter, data, contains the character data as a string.
  31107. * @author Nicola Asuni
  31108. * @since 5.0.000 (2010-05-02)
  31109. * @access protected
  31110. */
  31111. protected function segSVGContentHandler($parser, $data)
  31112. {
  31113. $this->svgtext .= $data;
  31114. }
  31115. // --- END SVG METHODS -----------------------------
  31116. } // END OF TCPDF CLASS
  31117. //============================================================+
  31118. // END OF FILE
  31119. //============================================================+